net: ena: allow setting the hash function without changing the key
authorSameeh Jubran <sameehj@amazon.com>
Sun, 3 May 2020 09:52:12 +0000 (09:52 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 3 May 2020 22:59:29 +0000 (15:59 -0700)
Current code does not allow setting the hash function without
changing the key. This commit enables it.

To achieve this we separate ena_com_get_hash_function() to 2 functions:
ena_com_get_hash_function() - which gets only the hash function, and
ena_com_get_hash_key() - which gets only the hash key.

Also return 0 instead of rc at the end of ena_get_rxfh() since all
previous operations succeeded.

Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amazon/ena/ena_com.c
drivers/net/ethernet/amazon/ena/ena_com.h
drivers/net/ethernet/amazon/ena/ena_ethtool.c

index 66edc86c41c9437aff568f742c1173c79c0cf19c..d428d0606166c168be1bb2f51c51dff71223e391 100644 (file)
@@ -2338,13 +2338,10 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
 }
 
 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
-                             enum ena_admin_hash_functions *func,
-                             u8 *key)
+                             enum ena_admin_hash_functions *func)
 {
        struct ena_rss *rss = &ena_dev->rss;
        struct ena_admin_get_feat_resp get_resp;
-       struct ena_admin_feature_rss_flow_hash_control *hash_key =
-               rss->hash_key;
        int rc;
 
        if (unlikely(!func))
@@ -2364,6 +2361,14 @@ int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
 
        *func = rss->hash_func;
 
+       return 0;
+}
+
+int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key)
+{
+       struct ena_admin_feature_rss_flow_hash_control *hash_key =
+               ena_dev->rss.hash_key;
+
        if (key)
                memcpy(key, hash_key->key, (size_t)(hash_key->keys_num) << 2);
 
index 469f298199a7b9a7c67ed4934ad6a503c40a1803..e2e2fd1dc8202d306ca55cd6036285c95a5e28e7 100644 (file)
@@ -695,13 +695,11 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
  */
 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
 
-/* ena_com_get_hash_function - Retrieve the hash function and the hash key
- * from the device.
+/* ena_com_get_hash_function - Retrieve the hash function from the device.
  * @ena_dev: ENA communication layer struct
  * @func: hash function
- * @key: hash key
  *
- * Retrieve the hash function and the hash key from the device.
+ * Retrieve the hash function from the device.
  *
  * @note: If the caller called ena_com_fill_hash_function but didn't flash
  * it to the device, the new configuration will be lost.
@@ -709,9 +707,20 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
  * @return: 0 on Success and negative value otherwise.
  */
 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
-                             enum ena_admin_hash_functions *func,
-                             u8 *key);
+                             enum ena_admin_hash_functions *func);
 
+/* ena_com_get_hash_key - Retrieve the hash key
+ * @ena_dev: ENA communication layer struct
+ * @key: hash key
+ *
+ * Retrieve the hash key.
+ *
+ * @note: If the caller called ena_com_fill_hash_key but didn't flash
+ * it to the device, the new configuration will be lost.
+ *
+ * @return: 0 on Success and negative value otherwise.
+ */
+int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
 /* ena_com_fill_hash_ctrl - Fill RSS hash control
  * @ena_dev: ENA communication layer struct.
  * @proto: The protocol to configure.
index 9cc28b4b262789eb6d16fcba9b438a0178f45bf8..0c3a2f14387e9ae8e5ae672e8aa1fc4cd50e1871 100644 (file)
@@ -672,7 +672,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
        /* We call this function in order to check if the device
         * supports getting/setting the hash function.
         */
-       rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func, key);
+       rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func);
        if (rc) {
                if (rc == -EOPNOTSUPP) {
                        key = NULL;
@@ -683,6 +683,10 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
                return rc;
        }
 
+       rc = ena_com_get_hash_key(adapter->ena_dev, key);
+       if (rc)
+               return rc;
+
        switch (ena_func) {
        case ENA_ADMIN_TOEPLITZ:
                func = ETH_RSS_HASH_TOP;
@@ -699,7 +703,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
        if (hfunc)
                *hfunc = func;
 
-       return rc;
+       return 0;
 }
 
 static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
@@ -707,7 +711,7 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
 {
        struct ena_adapter *adapter = netdev_priv(netdev);
        struct ena_com_dev *ena_dev = adapter->ena_dev;
-       enum ena_admin_hash_functions func;
+       enum ena_admin_hash_functions func = 0;
        int rc, i;
 
        if (indir) {
@@ -746,7 +750,7 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
                return -EOPNOTSUPP;
        }
 
-       if (key) {
+       if (key || func) {
                rc = ena_com_fill_hash_function(ena_dev, func, key,
                                                ENA_HASH_KEY_SIZE,
                                                0xFFFFFFFF);