i40e: rework the functions to configure RSS with similar parameters
authorHelin Zhang <helin.zhang@intel.com>
Wed, 21 Oct 2015 23:56:22 +0000 (19:56 -0400)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Wed, 25 Nov 2015 18:05:58 +0000 (10:05 -0800)
Adjust the RSS configure functions so that there is a generic way to
hook to ethtool hooks.

Change-ID: If446e34fcfaf1bc3320d9d319829a095b5976e67
Signed-off-by: Helin Zhang <helin.zhang@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e.h
drivers/net/ethernet/intel/i40e/i40e_ethtool.c
drivers/net/ethernet/intel/i40e/i40e_main.c

index ca07a7b7642e8ae22b4d62f5629cccf5c406b2e7..f6b747cf94d6ee07b744a94551f3918b46c2a2dd 100644 (file)
@@ -187,6 +187,7 @@ struct i40e_lump_tracking {
 #define I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR (I40E_FDIR_BUFFER_HEAD_ROOM * 4)
 
 #define I40E_HKEY_ARRAY_SIZE ((I40E_PFQF_HKEY_MAX_INDEX + 1) * 4)
+#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
 
 enum i40e_fd_stat_idx {
        I40E_FD_STAT_ATR,
index a89da8a220921a83433ba233f15e651bec676431..f26c0d16e43e4bb6054ae11275115a9901c4d1ec 100644 (file)
@@ -2584,7 +2584,6 @@ static int i40e_set_channels(struct net_device *dev,
                return -EINVAL;
 }
 
-#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
 /**
  * i40e_get_rxfh_key_size - get the RSS hash key size
  * @netdev: network interface device structure
index 9c0a381cf4200659aface3c796f850fea9d60dd3..9fe68024d9711f5780b7d77faefd62f956e90303 100644 (file)
@@ -55,6 +55,8 @@ static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
 static int i40e_setup_misc_vector(struct i40e_pf *pf);
 static void i40e_determine_queue_usage(struct i40e_pf *pf);
 static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
+static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
+                             u16 rss_table_size, u16 rss_size);
 static void i40e_fdir_sb_setup(struct i40e_pf *pf);
 static int i40e_veb_get_bw_info(struct i40e_veb *veb);
 
@@ -7797,7 +7799,8 @@ static int i40e_setup_misc_vector(struct i40e_pf *pf)
  * @vsi: vsi structure
  * @seed: RSS hash seed
  **/
-static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed)
+static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
+                             u8 *lut, u16 lut_size)
 {
        struct i40e_aqc_get_set_rss_key_data rss_key;
        struct i40e_pf *pf = vsi->back;
@@ -7850,49 +7853,79 @@ static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
 {
        u8 seed[I40E_HKEY_ARRAY_SIZE];
        struct i40e_pf *pf = vsi->back;
+       u8 *lut;
+       int ret;
+
+       if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
+               return 0;
+
+       lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
+       if (!lut)
+               return -ENOMEM;
 
+       i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
        netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
        vsi->rss_size = min_t(int, pf->rss_size, vsi->num_queue_pairs);
+       ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
+       kfree(lut);
 
-       if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
-               return i40e_config_rss_aq(vsi, seed);
-
-       return 0;
+       return ret;
 }
 
 /**
  * i40e_config_rss_reg - Prepare for RSS if used
- * @pf: board private structure
+ * @vsi: Pointer to vsi structure
  * @seed: RSS hash seed
+ * @lut: Lookup table
+ * @lut_size: Lookup table size
+ *
+ * Returns 0 on success, negative on failure
  **/
-static int i40e_config_rss_reg(struct i40e_pf *pf, const u8 *seed)
+static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
+                              const u8 *lut, u16 lut_size)
 {
-       struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
+       struct i40e_pf *pf = vsi->back;
        struct i40e_hw *hw = &pf->hw;
-       u32 *seed_dw = (u32 *)seed;
-       u32 current_queue = 0;
-       u32 lut = 0;
-       int i, j;
+       u8 i;
 
        /* Fill out hash function seed */
-       for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
-               wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
+       if (seed) {
+               u32 *seed_dw = (u32 *)seed;
 
-       for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
-               lut = 0;
-               for (j = 0; j < 4; j++) {
-                       if (current_queue == vsi->rss_size)
-                               current_queue = 0;
-                       lut |= ((current_queue) << (8 * j));
-                       current_queue++;
-               }
-               wr32(&pf->hw, I40E_PFQF_HLUT(i), lut);
+               for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
+                       wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
+       }
+
+       if (lut) {
+               u32 *lut_dw = (u32 *)lut;
+
+               if (lut_size != I40E_HLUT_ARRAY_SIZE)
+                       return -EINVAL;
+
+               for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
+                       wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
        }
        i40e_flush(hw);
 
        return 0;
 }
 
+/**
+ * i40e_fill_rss_lut - Fill the RSS lookup table with default values
+ * @pf: Pointer to board private structure
+ * @lut: Lookup table
+ * @rss_table_size: Lookup table size
+ * @rss_size: Range of queue number for hashing
+ */
+static void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
+                             u16 rss_table_size, u16 rss_size)
+{
+       u16 i;
+
+       for (i = 0; i < rss_table_size; i++)
+               lut[i] = i % rss_size;
+}
+
 /**
  * i40e_config_rss - Prepare for RSS if used
  * @pf: board private structure
@@ -7901,9 +7934,11 @@ static int i40e_config_rss(struct i40e_pf *pf)
 {
        struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
        u8 seed[I40E_HKEY_ARRAY_SIZE];
+       u8 *lut;
        struct i40e_hw *hw = &pf->hw;
        u32 reg_val;
        u64 hena;
+       int ret;
 
        netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
 
@@ -7924,10 +7959,20 @@ static int i40e_config_rss(struct i40e_pf *pf)
                        (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
        wr32(hw, I40E_PFQF_CTL_0, reg_val);
 
+       lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
+       if (!lut)
+               return -ENOMEM;
+
+       i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
+
        if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
-               return i40e_config_rss_aq(pf->vsi[pf->lan_vsi], seed);
+               ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
        else
-               return i40e_config_rss_reg(pf, seed);
+               ret = i40e_config_rss_reg(vsi, seed, lut, vsi->rss_table_size);
+
+       kfree(lut);
+
+       return ret;
 }
 
 /**