Skip to contentSkip to conversation

ice: managing MSI-X in driver

PATCH Superseded Michal Swiatkowski 5 participants 20 messages Oct 28, 2024 – Nov 5, 2024

Subsystems (7)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover ice: managing MSI-X in driver

Hi,

It is another try to allow user to manage amount of MSI-X used for each feature in ice. First was via devlink resources API, it wasn't accepted in upstream. Also static MSI-X allocation using devlink resources isn't really user friendly.

This try is using more dynamic way. "Dynamic" across whole kernel when platform supports it and "dynamic" across the driver when not.

To achieve that reuse global devlink parameter pf_msix_max and pf_msix_min. It fits how ice hardware counts MSI-X. In case of ice amount of MSI-X reported on PCI is a whole MSI-X for the card (with MSI-X for VFs also). Having pf_msix_max allow user to statically set how many MSI-X he wants on PF and how many should be reserved for VFs.

pf_msix_min is used to set minimum number of MSI-X with which ice driver should probe correctly.

Meaning of this field in case of dynamic vs static allocation:
- on system with dynamic MSI-X allocation support
* alloc pf_msix_min as static, rest will be allocated dynamically
- on system without dynamic MSI-X allocation support
* try alloc pf_msix_max as static, minimum acceptable result is pf_msix_min

As Jesse and Piotr suggested pf_msix_max and pf_msix_min can (an probably should) be stored in NVM. This patchset isn't implementing that.

Dynamic (kernel or driver) way means that splitting MSI-X across the RDMA and eth in case there is a MSI-X shortage isn't correct. Can work when dynamic is only on driver site, but can't when dynamic is on kernel site.

Let's remove this code and move to MSI-X allocation feature by feature. If there is no more MSI-X for a feature, a feature is working with less MSI-X or it is turned off.

There is a regression here. With MSI-X splitting user can run RDMA and eth even on system with not enough MSI-X. Now only eth will work. RDMA can be turned on by changing number of PF queues (lowering) and reprobe RDMA driver.

Example:
72 CPU number, eth, RDMA and flow director (1 MSI-X), 1 MSI-X for OICR on PF, and 1 more for RDMA. Card is using 1 + 72 + 1 + 72 + 1 = 147.

We set pf_msix_min = 2, pf_msix_max = 128

OICR: 1
eth: 72
flow director: 1
RDMA: 128 - 74 = 54

We can change number of queues on pf to 36 and do devlink reinit

OICR: 1
eth: 36
RDMA: 73
flow director: 1

We can also (implemented in "ice: enable_rdma devlink param") turned RDMA off.

OICR: 1
eth: 72
RDMA: 0 (turned off)
flow director: 1

After this changes we have a static base vector for SRIOV (SIOV probably in the feature). Last patch from this series is simplifying managing VF MSI-X code based on static vector.

Now changing queues using ethtool is also changing MSI-X. If there is enough MSI-X it is always one to one. When there is not enough there will be more queues than MSI-X. There is a lack of ability to set how many queues should be used per MSI-X. Maybe we should introduce another ethtool param for it? Sth like queues_per_vector?

v5 --> v6: [5]
* set default MSI-X max value based on needs instead of const define (patch 3)

v4 --> v5: [4]
* count combined queues in ethtool for case the vectors aren't mapped 1:1 to queues (patch 1)
* change min_t to min where the casting isn't needed (and can hide problems) (patch 4)
* load msix_max and msix_min value after devlink reload; it accidentally wasn't added after removing loading in probe path to mitigate error from devl_para_driverinit...() (patch 2)
* add documentation in develink/ice for new parameters (patch 2)

v3 --> v4: [3]
* drop unnecessary text in devlink validation comments
* assume that devl_param_driverinit...() shouldn't return error in normal execution path

v2 --> v3: [2]
* move flow director init before RDMA init
* fix unrolling RDMA MSI-X allocation
* add comment in commit message about lowering control RDMA MSI-X amount

v1 --> v2: [1]
* change permanent MSI-X cmode parameters to driverinit
* remove locking during devlink parameter registration (it is now locked for whole init/deinit part)

[5] https://lore.kernel.org/netdev/[email protected]/T/#t
[4] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[1] https://lore.kernel.org/netdev/[email protected]/

Michal Swiatkowski (9):
ice: count combined queues using Rx/Tx count
ice: devlink PF MSI-X max and min parameter
ice: remove splitting MSI-X between features
ice: get rid of num_lan_msix field
ice, irdma: move interrupts code to irdma
ice: treat dyn_allowed only as suggestion
ice: enable_rdma devlink param
ice: simplify VF MSI-X managing
ice: init flow director before RDMA

 Documentation/networking/devlink/ice.rst      |  11 +
 drivers/infiniband/hw/irdma/hw.c              |   2 -
 drivers/infiniband/hw/irdma/main.c            |  46 ++-
 drivers/infiniband/hw/irdma/main.h            |   3 +
 .../net/ethernet/intel/ice/devlink/devlink.c  | 102 ++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  21 +-
 drivers/net/ethernet/intel/ice/ice_base.c     |  10 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c  |   9 +-
 drivers/net/ethernet/intel/ice/ice_idc.c      |  64 +---
 drivers/net/ethernet/intel/ice/ice_irq.c      | 275 ++++++------------
 drivers/net/ethernet/intel/ice/ice_irq.h      |  13 +-
 drivers/net/ethernet/intel/ice/ice_lib.c      |  35 ++-
 drivers/net/ethernet/intel/ice/ice_main.c     |   6 +-
 drivers/net/ethernet/intel/ice/ice_sriov.c    | 154 +---------
 include/linux/net/intel/iidc.h                |   2 +
 15 files changed, 328 insertions(+), 425 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v6 1/9 ice: count combined queues using Rx/Tx count

Previous implementation assumes that there is 1:1 matching between vectors and queues. It isn't always true.

Get minimum value from Rx/Tx queues to determine combined queues number.

---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -2
index b552439fc1f9..c2f53946f1c3 100644
@@ -3818,8 +3818,7 @@ static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
 	ice_for_each_q_vector(vsi, q_idx) {
 		struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
 
-		if (q_vector->rx.rx_ring && q_vector->tx.tx_ring)
-			combined++;
+		combined += min(q_vector->num_ring_tx, q_vector->num_ring_rx);
 	}
 
 	return combined;
Signature · 1 line
2.42.0
#2 lore raw

PATCH v6 2/9 ice: devlink PF MSI-X max and min parameter

In reply to Michal Swiatkowski

Use generic devlink PF MSI-X parameter to allow user to change MSI-X range.

Add notes about this parameters into ice devlink documentation.

---
 Documentation/networking/devlink/ice.rst      | 11 +++
 .../net/ethernet/intel/ice/devlink/devlink.c  | 83 ++++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  7 ++
 drivers/net/ethernet/intel/ice/ice_irq.c      |  7 ++
 4 files changed, 107 insertions(+), 1 deletion(-)
Documentation/networking/devlink/ice.rst +11 -0
index e3972d03cea0..792e9f8c846a 100644
@@ -69,6 +69,17 @@ Parameters
 
        To verify that value has been set:
        $ devlink dev param show pci/0000:16:00.0 name tx_scheduling_layers
+   * - ``msix_vec_per_pf_max``
+     - driverinit
+     - Set the max MSI-X that can be used by the PF, rest can be utilized for
+       SRIOV. The range is from min value set in msix_vec_per_pf_min to
+       2k/number of ports.
+   * - ``msix_vec_per_pf_min``
+     - driverinit
+     - Set the min MSI-X that will be used by the PF. This value inform how many
+       MSI-X will be allocated statically. The range is from 2 to value set
+       in msix_vec_per_pf_max.
+
 .. list-table:: Driver specific parameters implemented
     :widths: 5 5 90
 
drivers/net/ethernet/intel/ice/devlink/devlink.c +82 -1

129 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice.h +7 -0
index 7997745686b3..c6cd7e993ed8 100644
@@ -543,6 +543,12 @@ struct ice_agg_node {
 	u8 valid;
 };
 
+struct ice_pf_msix {
+	u16 cur;
+	u16 min;
+	u16 max;
+};
+
 struct ice_pf {
 	struct pci_dev *pdev;
 	struct ice_adapter *adapter;
@@ -613,6 +619,7 @@ struct ice_pf {
 	struct msi_map ll_ts_irq;	/* LL_TS interrupt MSIX vector */
 	u16 max_pf_txqs;	/* Total Tx queues PF wide */
 	u16 max_pf_rxqs;	/* Total Rx queues PF wide */
+	struct ice_pf_msix msix;
 	u16 num_lan_msix;	/* Total MSIX vectors for base driver */
 	u16 num_lan_tx;		/* num LAN Tx queues setup */
 	u16 num_lan_rx;		/* num LAN Rx queues setup */
drivers/net/ethernet/intel/ice/ice_irq.c +7 -0
index ad82ff7d1995..0659b96b9b8c 100644
@@ -254,6 +254,13 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
 	int total_vectors = pf->hw.func_caps.common_cap.num_msix_vectors;
 	int vectors, max_vectors;
 
+	/* load default PF MSI-X range */
+	if (!pf->msix.min)
+		pf->msix.min = ICE_MIN_MSIX;
+
+	if (!pf->msix.max)
+		pf->msix.max = total_vectors / 2;
+
 	vectors = ice_ena_msix_range(pf);
 
 	if (vectors < 0)
Signature · 1 line
2.42.0
#3 lore raw

Re: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter

Quoted 156 lines · Michal Swiatkowski

Use generic devlink PF MSI-X parameter to allow user to change MSI-X range.

Add notes about this parameters into ice devlink documentation.

---
 Documentation/networking/devlink/ice.rst      | 11 +++
 .../net/ethernet/intel/ice/devlink/devlink.c  | 83 ++++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  7 ++
 drivers/net/ethernet/intel/ice/ice_irq.c      |  7 ++
 4 files changed, 107 insertions(+), 1 deletion(-)
Documentation/networking/devlink/ice.rst +11 -0
index e3972d03cea0..792e9f8c846a 100644
@@ -69,6 +69,17 @@ Parameters
 
        To verify that value has been set:
        $ devlink dev param show pci/0000:16:00.0 name tx_scheduling_layers
+   * - ``msix_vec_per_pf_max``
+     - driverinit
+     - Set the max MSI-X that can be used by the PF, rest can be utilized for
+       SRIOV. The range is from min value set in msix_vec_per_pf_min to
+       2k/number of ports.
+   * - ``msix_vec_per_pf_min``
+     - driverinit
+     - Set the min MSI-X that will be used by the PF. This value inform how many
+       MSI-X will be allocated statically. The range is from 2 to value set
+       in msix_vec_per_pf_max.
+
 .. list-table:: Driver specific parameters implemented
     :widths: 5 5 90
 
drivers/net/ethernet/intel/ice/devlink/devlink.c +71 -1
index d1b9ccec5e05..29c1fec4fa93 100644
@@ -1198,6 +1198,25 @@ static int ice_devlink_set_parent(struct devlink_rate *devlink_rate,
        return status;
 }
 
+static void ice_set_min_max_msix(struct ice_pf *pf)
+{
+       struct devlink *devlink = priv_to_devlink(pf);
+       union devlink_param_value val;
+       int err;
+
+       err = devl_param_driverinit_value_get(devlink,
+                                             DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
+                                             &val);
+       if (!err)
+               pf->msix.min = val.vu16;
+
+       err = devl_param_driverinit_value_get(devlink,
+                                             DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
+                                             &val);
+       if (!err)
+               pf->msix.max = val.vu16;
+}
+
 /**
  * ice_devlink_reinit_up - do reinit of the given PF
  * @pf: pointer to the PF struct
@@ -1207,6 +1226,9 @@ static int ice_devlink_reinit_up(struct ice_pf *pf)
        struct ice_vsi *vsi = ice_get_main_vsi(pf);
        int err;
 
+       /* load MSI-X values */
+       ice_set_min_max_msix(pf);
+
        err = ice_init_hw(&pf->hw);
        if (err) {
                dev_err(ice_pf_to_dev(pf), "ice_init_hw failed: %d\n", err);
@@ -1526,6 +1548,37 @@ static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id,
        return 0;
 }
 
+static int
+ice_devlink_msix_max_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 > pf->hw.func_caps.common_cap.num_msix_vectors ||
+           val.vu16 < pf->msix.min) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int
+ice_devlink_msix_min_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 <= ICE_MIN_MSIX || val.vu16 > pf->msix.max) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 enum ice_param_id {
        ICE_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
        ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS,
@@ -1543,6 +1596,15 @@ static const struct devlink_param ice_dvl_rdma_params[] = {
                              ice_devlink_enable_iw_validate),
 };
 
+static const struct devlink_param ice_dvl_msix_params[] = {
+       DEVLINK_PARAM_GENERIC(MSIX_VEC_PER_PF_MAX,
+                             BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
+                             NULL, NULL, ice_devlink_msix_max_pf_validate),
+       DEVLINK_PARAM_GENERIC(MSIX_VEC_PER_PF_MIN,
+                             BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
+                             NULL, NULL, ice_devlink_msix_min_pf_validate),
+};
+
 static const struct devlink_param ice_dvl_sched_params[] = {
        DEVLINK_PARAM_DRIVER(ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS,
                             "tx_scheduling_layers",
@@ -1644,6 +1706,7 @@ void ice_devlink_unregister(struct ice_pf *pf)
 int ice_devlink_register_params(struct ice_pf *pf)
 {
        struct devlink *devlink = priv_to_devlink(pf);
+       union devlink_param_value value;
        struct ice_hw *hw = &pf->hw;
        int status;
 
@@ -1652,11 +1715,27 @@ int ice_devlink_register_params(struct ice_pf *pf)
        if (status)
                return status;
 
+       status = devl_params_register(devlink, ice_dvl_msix_params,
+                                     ARRAY_SIZE(ice_dvl_msix_params));
+       if (status)
+               return status;
+
        if (hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
                status = devl_params_register(devlink, ice_dvl_sched_params,
                                              ARRAY_SIZE(ice_dvl_sched_params));
+       if (status)
+               return status;
 
-       return status;
+       value.vu16 = pf->msix.max;

drivers/net/ethernet/intel/ice/devlink/devlink.c int ice_devlink_register_params(struct ice_pf *pf) · line 1739

Quoted 10 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +9 -0
+       devl_param_driverinit_value_set(devlink,
+                                       DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
+                                       value);
+       value.vu16 = pf->msix.min;
+       devl_param_driverinit_value_set(devlink,
+                                       DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
+                                       value);
+
+       return 0;
 }

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

Michal

#4 lore raw

Re: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter

Quoted 165 lines · Michal Schmidt
Quoted 163 lines · Michal Swiatkowski

Use generic devlink PF MSI-X parameter to allow user to change MSI-X range.

Add notes about this parameters into ice devlink documentation.

---
 Documentation/networking/devlink/ice.rst      | 11 +++
 .../net/ethernet/intel/ice/devlink/devlink.c  | 83 ++++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  7 ++
 drivers/net/ethernet/intel/ice/ice_irq.c      |  7 ++
 4 files changed, 107 insertions(+), 1 deletion(-)
Documentation/networking/devlink/ice.rst +11 -0
index e3972d03cea0..792e9f8c846a 100644
@@ -69,6 +69,17 @@ Parameters
 
        To verify that value has been set:
        $ devlink dev param show pci/0000:16:00.0 name tx_scheduling_layers
+   * - ``msix_vec_per_pf_max``
+     - driverinit
+     - Set the max MSI-X that can be used by the PF, rest can be utilized for
+       SRIOV. The range is from min value set in msix_vec_per_pf_min to
+       2k/number of ports.
+   * - ``msix_vec_per_pf_min``
+     - driverinit
+     - Set the min MSI-X that will be used by the PF. This value inform how many
+       MSI-X will be allocated statically. The range is from 2 to value set
+       in msix_vec_per_pf_max.
+
 .. list-table:: Driver specific parameters implemented
     :widths: 5 5 90
 
drivers/net/ethernet/intel/ice/devlink/devlink.c +78 -1
index d1b9ccec5e05..29c1fec4fa93 100644
@@ -1198,6 +1198,25 @@ static int ice_devlink_set_parent(struct devlink_rate *devlink_rate,
        return status;
 }
 
+static void ice_set_min_max_msix(struct ice_pf *pf)
+{
+       struct devlink *devlink = priv_to_devlink(pf);
+       union devlink_param_value val;
+       int err;
+
+       err = devl_param_driverinit_value_get(devlink,
+                                             DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
+                                             &val);
+       if (!err)
+               pf->msix.min = val.vu16;
+
+       err = devl_param_driverinit_value_get(devlink,
+                                             DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
+                                             &val);
+       if (!err)
+               pf->msix.max = val.vu16;
+}
+
 /**
  * ice_devlink_reinit_up - do reinit of the given PF
  * @pf: pointer to the PF struct
@@ -1207,6 +1226,9 @@ static int ice_devlink_reinit_up(struct ice_pf *pf)
        struct ice_vsi *vsi = ice_get_main_vsi(pf);
        int err;
 
+       /* load MSI-X values */
+       ice_set_min_max_msix(pf);
+
        err = ice_init_hw(&pf->hw);
        if (err) {
                dev_err(ice_pf_to_dev(pf), "ice_init_hw failed: %d\n", err);
@@ -1526,6 +1548,37 @@ static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id,
        return 0;
 }
 
+static int
+ice_devlink_msix_max_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 > pf->hw.func_caps.common_cap.num_msix_vectors ||
+           val.vu16 < pf->msix.min) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int
+ice_devlink_msix_min_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 <= ICE_MIN_MSIX || val.vu16 > pf->msix.max) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 enum ice_param_id {
        ICE_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
        ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS,
@@ -1543,6 +1596,15 @@ static const struct devlink_param ice_dvl_rdma_params[] = {
                              ice_devlink_enable_iw_validate),
 };
 
+static const struct devlink_param ice_dvl_msix_params[] = {
+       DEVLINK_PARAM_GENERIC(MSIX_VEC_PER_PF_MAX,
+                             BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
+                             NULL, NULL, ice_devlink_msix_max_pf_validate),
+       DEVLINK_PARAM_GENERIC(MSIX_VEC_PER_PF_MIN,
+                             BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
+                             NULL, NULL, ice_devlink_msix_min_pf_validate),
+};
+
 static const struct devlink_param ice_dvl_sched_params[] = {
        DEVLINK_PARAM_DRIVER(ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS,
                             "tx_scheduling_layers",
@@ -1644,6 +1706,7 @@ void ice_devlink_unregister(struct ice_pf *pf)
 int ice_devlink_register_params(struct ice_pf *pf)
 {
        struct devlink *devlink = priv_to_devlink(pf);
+       union devlink_param_value value;
        struct ice_hw *hw = &pf->hw;
        int status;
 
@@ -1652,11 +1715,27 @@ int ice_devlink_register_params(struct ice_pf *pf)
        if (status)
                return status;
 
+       status = devl_params_register(devlink, ice_dvl_msix_params,
+                                     ARRAY_SIZE(ice_dvl_msix_params));
+       if (status)
+               return status;
+
        if (hw->func_caps.common_cap.tx_sched_topo_comp_mode_en)
                status = devl_params_register(devlink, ice_dvl_sched_params,
                                              ARRAY_SIZE(ice_dvl_sched_params));
+       if (status)
+               return status;
 
-       return status;
+       value.vu16 = pf->msix.max;
+       devl_param_driverinit_value_set(devlink,
+                                       DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
+                                       value);
+       value.vu16 = pf->msix.min;
+       devl_param_driverinit_value_set(devlink,
+                                       DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
+                                       value);
Quoted 9 lines

drivers/net/ethernet/intel/ice/devlink/devlink.c int ice_devlink_register_params(struct ice_pf *pf) · line 1739

Quoted 3 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +2 -0
+
+       return 0;
 }

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

I will change it.

Quoted 2 lines

Michal

#5 lore raw

RE: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter

From: Michal Swiatkowski

Quoted 1 line

Sent: 04 November 2024 07:03

...

Quoted 6 lines
Quoted 4 lines

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

I will change it.

You also need a pretty good reason to use u16 anywhere at all. Just because the domain of the value is small doesn't mean the best type isn't [unsigned] int.

Any arithmetic (particularly on non x86) is likely to increase the code size above any perceived data saving.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#6 lore raw

Small Integers: Big Penalty (was: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter)

Dear David, dear Michal,

Am 04.11.24 um 09:51 schrieb David Laight:

Quoted 8 lines

From: Michal Swiatkowski

Quoted 1 line

Sent: 04 November 2024 07:03

...

Quoted 5 lines
Quoted 4 lines

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

Quoted 8 lines
Quoted 1 line

I will change it.

You also need a pretty good reason to use u16 anywhere at all. Just because the domain of the value is small doesn't mean the best type isn't [unsigned] int.

Any arithmetic (particularly on non x86) is likely to increase the code size above any perceived data saving.

In 2012 Scott Duplichan wrote *Small Integers: Big Penalty* [1]. Of course you always should measure yourself.

Kind regards,

Paul

[1]: https://notabs.org/coding/smallIntsBigPenalty.htm

#7 lore raw

Re: [Intel-wired-lan] Small Integers: Big Penalty

[Cc: [email protected] (550 #5.1.0 Address rejected.)]

Am 04.11.24 um 10:09 schrieb Paul Menzel:

Quoted 30 lines

Dear David, dear Michal,

Am 04.11.24 um 09:51 schrieb David Laight:

Quoted 8 lines

From: Michal Swiatkowski

Quoted 1 line

Sent: 04 November 2024 07:03

...

Quoted 5 lines
Quoted 4 lines

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

Quoted 8 lines
Quoted 1 line

I will change it.

You also need a pretty good reason to use u16 anywhere at all. Just because the domain of the value is small doesn't mean the best type isn't [unsigned] int.

Any arithmetic (particularly on non x86) is likely to increase the code size above any perceived data saving.

In 2012 Scott Duplichan wrote *Small Integers: Big Penalty* [1]. Of course you always should measure yourself.

Kind regards,

Paul

[1]: https://notabs.org/coding/smallIntsBigPenalty.htm

#8 lore raw

Re: [Intel-wired-lan] Small Integers: Big Penalty

Quoted 27 lines · Paul Menzel

[Cc: [email protected] (550 #5.1.0 Address rejected.)]

Am 04.11.24 um 10:09 schrieb Paul Menzel:

Quoted 24 lines

Dear David, dear Michal,

Am 04.11.24 um 09:51 schrieb David Laight:

Quoted 8 lines

From: Michal Swiatkowski

Quoted 1 line

Sent: 04 November 2024 07:03

...

Quoted 5 lines
Quoted 4 lines

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

Quoted 8 lines
Quoted 1 line

I will change it.

You also need a pretty good reason to use u16 anywhere at all. Just because the domain of the value is small doesn't mean the best type isn't [unsigned] int.

Any arithmetic (particularly on non x86) is likely to increase the code size above any perceived data saving.

In 2012 Scott Duplichan wrote *Small Integers: Big Penalty* [1]. Of course you always should measure yourself.

Yeah, I chose it, because previously it was stored in u16. I will change it to u32 too, as it is stored in structure that doesn't really need to be small.

Thanks for comments and link to the article.
Michal

Quoted 7 lines
Quoted 7 lines

Kind regards,

Paul

[1]: https://notabs.org/coding/smallIntsBigPenalty.htm

#9 lore raw

RE: [Intel-wired-lan] Small Integers: Big Penalty

Quoted 44 lines

-----Original Message-----
From: Michal Swiatkowski <[email protected]>
Sent: Monday, November 4, 2024 3:25 AM
To: Paul Menzel <[email protected]>
Cc: David Laight <[email protected]>; Drewek, Wojciech <[email protected]>; Szycik, Marcin <[email protected]>; [email protected]; Knitter, Konrad <[email protected]>; Chmielewski, Pawel <[email protected]>; [email protected]; intel- [email protected]; [email protected]; Samudrala, Sridhar <[email protected]>; Keller, Jacob E <[email protected]>; [email protected]; Kitszel, Przemyslaw <[email protected]>
Subject: Re: [Intel-wired-lan] Small Integers: Big Penalty

Quoted 27 lines · Paul Menzel

[Cc: [email protected] (550 #5.1.0 Address rejected.)]

Am 04.11.24 um 10:09 schrieb Paul Menzel:

Quoted 24 lines

Dear David, dear Michal,

Am 04.11.24 um 09:51 schrieb David Laight:

Quoted 8 lines

From: Michal Swiatkowski

Quoted 1 line

Sent: 04 November 2024 07:03

...

Quoted 5 lines
Quoted 4 lines

The type of the devlink parameters msix_vec_per_pf_{min,max} is specified as u32, so you must use value.vu32 everywhere you work with them, not vu16.

Quoted 8 lines
Quoted 1 line

I will change it.

You also need a pretty good reason to use u16 anywhere at all. Just because the domain of the value is small doesn't mean the best type isn't [unsigned] int.

Any arithmetic (particularly on non x86) is likely to increase the code size above any perceived data saving.

In 2012 Scott Duplichan wrote *Small Integers: Big Penalty* [1]. Of course you always should measure yourself.

Quoted 7 lines

Yeah, I chose it, because previously it was stored in u16. I will change it to u32 too, as it is stored in structure that doesn't really need to be small.

Thanks for comments and link to the article.
Michal

Yea.. ice driver code has a bad habit of using smaller size values in structures when its unnecessary.

#10 lore raw

Re: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter

In reply to Michal Swiatkowski
Quoted 15 lines · Michal Swiatkowski

Use generic devlink PF MSI-X parameter to allow user to change MSI-X range.

Add notes about this parameters into ice devlink documentation.

---
 Documentation/networking/devlink/ice.rst      | 11 +++
 .../net/ethernet/intel/ice/devlink/devlink.c  | 83 ++++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  7 ++
 drivers/net/ethernet/intel/ice/ice_irq.c      |  7 ++
 4 files changed, 107 insertions(+), 1 deletion(-)

...

Quoted 18 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +14 -0
@@ -1526,6 +1548,37 @@ static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id,
        return 0;
 }
 
+static int
+ice_devlink_msix_max_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 > pf->hw.func_caps.common_cap.num_msix_vectors ||
+           val.vu16 < pf->msix.min) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;

drivers/net/ethernet/intel/ice/devlink/devlink.c static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id, · line 1574

Quoted 10 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +10 -0
+}
+
+static int
+ice_devlink_msix_min_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 <= ICE_MIN_MSIX || val.vu16 > pf->msix.max) {

Shouldn't this be "<" instead of "<=" ?

Michal

#11 lore raw

Re: [Intel-wired-lan] [iwl-next v6 2/9] ice: devlink PF MSI-X max and min parameter

Quoted 40 lines · Michal Schmidt
Quoted 15 lines · Michal Swiatkowski

Use generic devlink PF MSI-X parameter to allow user to change MSI-X range.

Add notes about this parameters into ice devlink documentation.

---
 Documentation/networking/devlink/ice.rst      | 11 +++
 .../net/ethernet/intel/ice/devlink/devlink.c  | 83 ++++++++++++++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  7 ++
 drivers/net/ethernet/intel/ice/ice_irq.c      |  7 ++
 4 files changed, 107 insertions(+), 1 deletion(-)

...

Quoted 22 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +18 -0
@@ -1526,6 +1548,37 @@ static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id,
        return 0;
 }
 
+static int
+ice_devlink_msix_max_pf_validate(struct devlink *devlink, u32 id,
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 > pf->hw.func_caps.common_cap.num_msix_vectors ||
+           val.vu16 < pf->msix.min) {
+               NL_SET_ERR_MSG_MOD(extack, "Value is invalid");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int
+ice_devlink_msix_min_pf_validate(struct devlink *devlink, u32 id,
Quoted 9 lines

drivers/net/ethernet/intel/ice/devlink/devlink.c static int ice_devlink_local_fwd_validate(struct devlink *devlink, u32 id, · line 1574

Quoted 6 lines
drivers/net/ethernet/intel/ice/devlink/devlink.c +6 -0
+                                union devlink_param_value val,
+                                struct netlink_ext_ack *extack)
+{
+       struct ice_pf *pf = devlink_priv(devlink);
+
+       if (val.vu16 <= ICE_MIN_MSIX || val.vu16 > pf->msix.max) {

Shouldn't this be "<" instead of "<=" ?

Yeah, will fix.

Quoted 2 lines

Michal

#12 lore raw

PATCH v6 3/9 ice: remove splitting MSI-X between features

In reply to Michal Swiatkowski

With dynamic approach to alloc MSI-X there is no sense to statically split MSI-X between PF features.

Splitting was also calculating needed MSI-X. Move this part to separate function and use as max value.

Remove ICE_ESWITCH_MSIX, as there is no need for additional MSI-X for switchdev.

---
 drivers/net/ethernet/intel/ice/ice.h     |   2 -
 drivers/net/ethernet/intel/ice/ice_irq.c | 172 +++--------------------
 2 files changed, 16 insertions(+), 158 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +0 -2
index c6cd7e993ed8..3a771a25b97b 100644
@@ -98,8 +98,6 @@
 #define ICE_MIN_MSIX		(ICE_MIN_LAN_TXRX_MSIX + ICE_MIN_LAN_OICR_MSIX)
 #define ICE_FDIR_MSIX		2
 #define ICE_RDMA_NUM_AEQ_MSIX	4
-#define ICE_MIN_RDMA_MSIX	2
-#define ICE_ESWITCH_MSIX	1
 #define ICE_NO_VSI		0xffff
 #define ICE_VSI_MAP_CONTIG	0
 #define ICE_VSI_MAP_SCATTER	1
drivers/net/ethernet/intel/ice/ice_irq.c +16 -156

188 lines not on this page · raw message

Signature · 1 line
2.42.0
#13 lore raw

PATCH v6 4/9 ice: get rid of num_lan_msix field

In reply to Michal Swiatkowski

Remove the field to allow having more queues than MSI-X on VSI. As default the number will be the same, but if there won't be more MSI-X available VSI can run with at least one MSI-X.

---
 drivers/net/ethernet/intel/ice/ice.h         |  1 -
 drivers/net/ethernet/intel/ice/ice_base.c    | 10 ++++----
 drivers/net/ethernet/intel/ice/ice_ethtool.c |  6 ++---
 drivers/net/ethernet/intel/ice/ice_irq.c     | 11 ++++-----
 drivers/net/ethernet/intel/ice/ice_lib.c     | 25 +++++++++++---------
 5 files changed, 24 insertions(+), 29 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +0 -1
index 3a771a25b97b..1e1e6abde304 100644
@@ -618,7 +618,6 @@ struct ice_pf {
 	u16 max_pf_txqs;	/* Total Tx queues PF wide */
 	u16 max_pf_rxqs;	/* Total Rx queues PF wide */
 	struct ice_pf_msix msix;
-	u16 num_lan_msix;	/* Total MSIX vectors for base driver */
 	u16 num_lan_tx;		/* num LAN Tx queues setup */
 	u16 num_lan_rx;		/* num LAN Rx queues setup */
 	u16 next_vsi;		/* Next free slot in pf->vsi[] - 0-based! */
drivers/net/ethernet/intel/ice/ice_base.c +4 -6
index 3a8e156d7d86..626f0a26d2c6 100644
@@ -797,13 +797,11 @@ int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
 	return 0;
 
 err_out:
-	while (v_idx--)
-		ice_free_q_vector(vsi, v_idx);
 
-	dev_err(dev, "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
-		vsi->num_q_vectors, vsi->vsi_num, err);
-	vsi->num_q_vectors = 0;
-	return err;
+	dev_info(dev, "Failed to allocate %d q_vectors for VSI %d, new value %d",
+		 vsi->num_q_vectors, vsi->vsi_num, v_idx);
+	vsi->num_q_vectors = v_idx;
+	return v_idx ? 0 : err;
 }
 
 /**
drivers/net/ethernet/intel/ice/ice_ethtool.c +2 -4
index c2f53946f1c3..5d001fe95753 100644
@@ -3789,8 +3789,7 @@ ice_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info)
  */
 static int ice_get_max_txq(struct ice_pf *pf)
 {
-	return min3(pf->num_lan_msix, (u16)num_online_cpus(),
-		    (u16)pf->hw.func_caps.common_cap.num_txq);
+	return min(num_online_cpus(), pf->hw.func_caps.common_cap.num_txq);
 }
 
 /**
@@ -3799,8 +3798,7 @@ static int ice_get_max_txq(struct ice_pf *pf)
  */
 static int ice_get_max_rxq(struct ice_pf *pf)
 {
-	return min3(pf->num_lan_msix, (u16)num_online_cpus(),
-		    (u16)pf->hw.func_caps.common_cap.num_rxq);
+	return min(num_online_cpus(), pf->hw.func_caps.common_cap.num_rxq);
 }
 
 /**
drivers/net/ethernet/intel/ice/ice_irq.c +4 -7
index 4a50a6dc817e..1a7d446ab5f1 100644
@@ -108,7 +108,7 @@ void ice_clear_interrupt_scheme(struct ice_pf *pf)
 int ice_init_interrupt_scheme(struct ice_pf *pf)
 {
 	int total_vectors = pf->hw.func_caps.common_cap.num_msix_vectors;
-	int vectors, max_vectors;
+	int vectors;
 
 	/* load default PF MSI-X range */
 	if (!pf->msix.min)
@@ -118,20 +118,17 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
 		pf->msix.max = min(total_vectors,
 				   ice_get_default_msix_amount(pf));
 
-	if (pci_msix_can_alloc_dyn(pf->pdev)) {
+	if (pci_msix_can_alloc_dyn(pf->pdev))
 		vectors = pf->msix.min;
-		max_vectors = total_vectors;
-	} else {
+	else
 		vectors = pf->msix.max;
-		max_vectors = vectors;
-	}
 
 	vectors = pci_alloc_irq_vectors(pf->pdev, pf->msix.min, vectors,
 					PCI_IRQ_MSIX);
 	if (vectors < pf->msix.min)
 		return -ENOMEM;
 
-	ice_init_irq_tracker(pf, max_vectors, vectors);
+	ice_init_irq_tracker(pf, pf->msix.max, vectors);
 
 	return 0;
 }
drivers/net/ethernet/intel/ice/ice_lib.c +14 -11
index 01220e21cc81..bf88785c0c8a 100644
@@ -157,6 +157,16 @@ static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
 	}
 }
 
+static u16 ice_get_rxq_count(struct ice_pf *pf)
+{
+	return min(ice_get_avail_rxq_count(pf), num_online_cpus());
+}
+
+static u16 ice_get_txq_count(struct ice_pf *pf)
+{
+	return min(ice_get_avail_txq_count(pf), num_online_cpus());
+}
+
 /**
  * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
  * @vsi: the VSI being configured
@@ -178,9 +188,7 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
 			vsi->alloc_txq = vsi->req_txq;
 			vsi->num_txq = vsi->req_txq;
 		} else {
-			vsi->alloc_txq = min3(pf->num_lan_msix,
-					      ice_get_avail_txq_count(pf),
-					      (u16)num_online_cpus());
+			vsi->alloc_txq = ice_get_txq_count(pf);
 		}
 
 		pf->num_lan_tx = vsi->alloc_txq;
@@ -193,17 +201,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
 				vsi->alloc_rxq = vsi->req_rxq;
 				vsi->num_rxq = vsi->req_rxq;
 			} else {
-				vsi->alloc_rxq = min3(pf->num_lan_msix,
-						      ice_get_avail_rxq_count(pf),
-						      (u16)num_online_cpus());
+				vsi->alloc_rxq = ice_get_rxq_count(pf);
 			}
 		}
 
 		pf->num_lan_rx = vsi->alloc_rxq;
 
-		vsi->num_q_vectors = min_t(int, pf->num_lan_msix,
-					   max_t(int, vsi->alloc_rxq,
-						 vsi->alloc_txq));
+		vsi->num_q_vectors = max(vsi->alloc_rxq, vsi->alloc_txq);
 		break;
 	case ICE_VSI_SF:
 		vsi->alloc_txq = 1;
@@ -1173,12 +1177,11 @@ static void ice_set_rss_vsi_ctx(struct ice_vsi_ctx *ctxt, struct ice_vsi *vsi)
 static void
 ice_chnl_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
 {
-	struct ice_pf *pf = vsi->back;
 	u16 qcount, qmap;
 	u8 offset = 0;
 	int pow;
 
-	qcount = min_t(int, vsi->num_rxq, pf->num_lan_msix);
+	qcount = vsi->num_rxq;
 
 	pow = order_base_2(qcount);
 	qmap = FIELD_PREP(ICE_AQ_VSI_TC_Q_OFFSET_M, offset);
Signature · 1 line
2.42.0
#14 lore raw

PATCH v6 5/9 ice, irdma: move interrupts code to irdma

In reply to Michal Swiatkowski

Move responsibility of MSI-X requesting for RDMA feature from ice driver to irdma driver. It is done to allow simple fallback when there is not enough MSI-X available.

Change amount of MSI-X used for control from 4 to 1, as it isn't needed to have more than one MSI-X for this purpose.

---
 drivers/infiniband/hw/irdma/hw.c         |  2 -
 drivers/infiniband/hw/irdma/main.c       | 46 ++++++++++++++++-
 drivers/infiniband/hw/irdma/main.h       |  3 ++
 drivers/net/ethernet/intel/ice/ice.h     |  1 -
 drivers/net/ethernet/intel/ice/ice_idc.c | 64 ++++++------------------
 drivers/net/ethernet/intel/ice/ice_irq.c |  3 +-
 include/linux/net/intel/iidc.h           |  2 +
 7 files changed, 65 insertions(+), 56 deletions(-)
drivers/infiniband/hw/irdma/hw.c +0 -2
index ad50b77282f8..69ce1862eabe 100644
@@ -498,8 +498,6 @@ static int irdma_save_msix_info(struct irdma_pci_f *rf)
 	iw_qvlist->num_vectors = rf->msix_count;
 	if (rf->msix_count <= num_online_cpus())
 		rf->msix_shared = true;
-	else if (rf->msix_count > num_online_cpus() + 1)
-		rf->msix_count = num_online_cpus() + 1;
 
 	pmsix = rf->msix_entries;
 	for (i = 0, ceq_idx = 0; i < rf->msix_count; i++, iw_qvinfo++) {
drivers/infiniband/hw/irdma/main.c +44 -2

77 lines not on this page · raw message

drivers/infiniband/hw/irdma/main.h +3 -0
index 9f0ed6e84471..ef9a9b79d711 100644
@@ -117,6 +117,9 @@ extern struct auxiliary_driver i40iw_auxiliary_drv;
 
 #define IRDMA_IRQ_NAME_STR_LEN (64)
 
+#define IRDMA_NUM_AEQ_MSIX	1
+#define IRDMA_MIN_MSIX		2
+
 enum init_completion_state {
 	INVALID_STATE = 0,
 	INITIAL_STATE,
drivers/net/ethernet/intel/ice/ice.h +0 -1
index 1e1e6abde304..a5d55843ef5c 100644
@@ -97,7 +97,6 @@
 #define ICE_MIN_LAN_OICR_MSIX	1
 #define ICE_MIN_MSIX		(ICE_MIN_LAN_TXRX_MSIX + ICE_MIN_LAN_OICR_MSIX)
 #define ICE_FDIR_MSIX		2
-#define ICE_RDMA_NUM_AEQ_MSIX	4
 #define ICE_NO_VSI		0xffff
 #define ICE_VSI_MAP_CONTIG	0
 #define ICE_VSI_MAP_SCATTER	1
drivers/net/ethernet/intel/ice/ice_idc.c +14 -50

101 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_irq.c +2 -1
index 1a7d446ab5f1..80c9ee2e64c1 100644
@@ -84,11 +84,12 @@ static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf, bool dyn_only)
 	return entry;
 }
 
+#define ICE_RDMA_AEQ_MSIX 1
 static int ice_get_default_msix_amount(struct ice_pf *pf)
 {
 	return ICE_MIN_LAN_OICR_MSIX + num_online_cpus() +
 	       (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? ICE_FDIR_MSIX : 0) +
-	       (ice_is_rdma_ena(pf) ? num_online_cpus() + ICE_RDMA_NUM_AEQ_MSIX : 0);
+	       (ice_is_rdma_ena(pf) ? num_online_cpus() + ICE_RDMA_AEQ_MSIX : 0);
 }
 
 /**
include/linux/net/intel/iidc.h +2 -0
index 1c1332e4df26..13274c3def66 100644
@@ -78,6 +78,8 @@ int ice_del_rdma_qset(struct ice_pf *pf, struct iidc_rdma_qset_params *qset);
 int ice_rdma_request_reset(struct ice_pf *pf, enum iidc_reset_type reset_type);
 int ice_rdma_update_vsi_filter(struct ice_pf *pf, u16 vsi_id, bool enable);
 void ice_get_qos_params(struct ice_pf *pf, struct iidc_qos_params *qos);
+int ice_alloc_rdma_qvector(struct ice_pf *pf, struct msix_entry *entry);
+void ice_free_rdma_qvector(struct ice_pf *pf, struct msix_entry *entry);
 
 /* Structure representing auxiliary driver tailored information about the core
  * PCI dev, each auxiliary driver using the IIDC interface will have an
Signature · 1 line
2.42.0
#15 lore raw

PATCH v6 6/9 ice: treat dyn_allowed only as suggestion

In reply to Michal Swiatkowski

It can be needed to have some MSI-X allocated as static and rest as dynamic. For example on PF VSI. We want to always have minimum one MSI-X on it, because of that it is allocated as a static one, rest can be dynamic if it is supported.

Change the ice_get_irq_res() to allow using static entries if they are free even if caller wants dynamic one.

Adjust limit values to the new approach. Min and max in limit means the values that are valid, so decrease max and num_static by one.

Set vsi::irq_dyn_alloc if dynamic allocation is supported.

---
 drivers/net/ethernet/intel/ice/ice_irq.c | 25 ++++++++++++------------
 drivers/net/ethernet/intel/ice/ice_lib.c |  2 ++
 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/net/ethernet/intel/ice/ice_irq.c +13 -12
index 80c9ee2e64c1..d466d29b2ef1 100644
@@ -45,7 +45,7 @@ static void ice_free_irq_res(struct ice_pf *pf, u16 index)
 /**
  * ice_get_irq_res - get an interrupt resource
  * @pf: board private structure
- * @dyn_only: force entry to be dynamically allocated
+ * @dyn_allowed: allow entry to be dynamically allocated
  *
  * Allocate new irq entry in the free slot of the tracker. Since xarray
  * is used, always allocate new entry at the lowest possible index. Set
@@ -53,11 +53,12 @@ static void ice_free_irq_res(struct ice_pf *pf, u16 index)
  *
  * Returns allocated irq entry or NULL on failure.
  */
-static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf, bool dyn_only)
+static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf,
+					     bool dyn_allowed)
 {
-	struct xa_limit limit = { .max = pf->irq_tracker.num_entries,
+	struct xa_limit limit = { .max = pf->irq_tracker.num_entries - 1,
 				  .min = 0 };
-	unsigned int num_static = pf->irq_tracker.num_static;
+	unsigned int num_static = pf->irq_tracker.num_static - 1;
 	struct ice_irq_entry *entry;
 	unsigned int index;
 	int ret;
@@ -66,9 +67,9 @@ static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf, bool dyn_only)
 	if (!entry)
 		return NULL;
 
-	/* skip preallocated entries if the caller says so */
-	if (dyn_only)
-		limit.min = num_static;
+	/* only already allocated if the caller says so */
+	if (!dyn_allowed)
+		limit.max = num_static;
 
 	ret = xa_alloc(&pf->irq_tracker.entries, &index, entry, limit,
 		       GFP_KERNEL);
@@ -78,7 +79,7 @@ static struct ice_irq_entry *ice_get_irq_res(struct ice_pf *pf, bool dyn_only)
 		entry = NULL;
 	} else {
 		entry->index = index;
-		entry->dynamic = index >= num_static;
+		entry->dynamic = index > num_static;
 	}
 
 	return entry;
@@ -137,7 +138,7 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
 /**
  * ice_alloc_irq - Allocate new interrupt vector
  * @pf: board private structure
- * @dyn_only: force dynamic allocation of the interrupt
+ * @dyn_allowed: allow dynamic allocation of the interrupt
  *
  * Allocate new interrupt vector for a given owner id.
  * return struct msi_map with interrupt details and track
@@ -150,20 +151,20 @@ int ice_init_interrupt_scheme(struct ice_pf *pf)
  * interrupt will be allocated with pci_msix_alloc_irq_at.
  *
  * Some callers may only support dynamically allocated interrupts.
- * This is indicated with dyn_only flag.
+ * This is indicated with dyn_allowed flag.
  *
  * On failure, return map with negative .index. The caller
  * is expected to check returned map index.
  *
  */
-struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_only)
+struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_allowed)
 {
 	int sriov_base_vector = pf->sriov_base_vector;
 	struct msi_map map = { .index = -ENOENT };
 	struct device *dev = ice_pf_to_dev(pf);
 	struct ice_irq_entry *entry;
 
-	entry = ice_get_irq_res(pf, dyn_only);
+	entry = ice_get_irq_res(pf, dyn_allowed);
 	if (!entry)
 		return map;
 
drivers/net/ethernet/intel/ice/ice_lib.c +2 -0
index bf88785c0c8a..e833c25dc970 100644
@@ -571,6 +571,8 @@ ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_channel *ch)
 			return -ENOMEM;
 	}
 
+	vsi->irq_dyn_alloc = pci_msix_can_alloc_dyn(vsi->back->pdev);
+
 	switch (vsi->type) {
 	case ICE_VSI_PF:
 	case ICE_VSI_SF:
Signature · 1 line
2.42.0
#16 lore raw

PATCH v6 7/9 ice: enable_rdma devlink param

In reply to Michal Swiatkowski

Implement enable_rdma devlink parameter to allow user to turn RDMA feature on and off.

It is useful when there is no enough interrupts and user doesn't need RDMA feature.

---
 .../net/ethernet/intel/ice/devlink/devlink.c  | 19 +++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_lib.c      |  8 +++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/devlink/devlink.c +19 -0
index 29c1fec4fa93..04daeb831f84 100644
@@ -1579,6 +1579,19 @@ ice_devlink_msix_min_pf_validate(struct devlink *devlink, u32 id,
 	return 0;
 }
 
+static int ice_devlink_enable_rdma_validate(struct devlink *devlink, u32 id,
+					    union devlink_param_value val,
+					    struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = devlink_priv(devlink);
+	bool new_state = val.vbool;
+
+	if (new_state && !test_bit(ICE_FLAG_RDMA_ENA, pf->flags))
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
 enum ice_param_id {
 	ICE_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
 	ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS,
@@ -1594,6 +1607,8 @@ static const struct devlink_param ice_dvl_rdma_params[] = {
 			      ice_devlink_enable_iw_get,
 			      ice_devlink_enable_iw_set,
 			      ice_devlink_enable_iw_validate),
+	DEVLINK_PARAM_GENERIC(ENABLE_RDMA, BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
+			      NULL, NULL, ice_devlink_enable_rdma_validate),
 };
 
 static const struct devlink_param ice_dvl_msix_params[] = {
@@ -1734,6 +1749,10 @@ int ice_devlink_register_params(struct ice_pf *pf)
 	devl_param_driverinit_value_set(devlink,
 					DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
 					value);
+	value.vbool = test_bit(ICE_FLAG_RDMA_ENA, pf->flags);
+	devl_param_driverinit_value_set(devlink,
+					DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
+					value);
 
 	return 0;
 }
drivers/net/ethernet/intel/ice/ice_lib.c +7 -1
index e833c25dc970..c0dc1f48f5d6 100644
@@ -833,7 +833,13 @@ bool ice_is_safe_mode(struct ice_pf *pf)
  */
 bool ice_is_rdma_ena(struct ice_pf *pf)
 {
-	return test_bit(ICE_FLAG_RDMA_ENA, pf->flags);
+	union devlink_param_value value;
+	int err;
+
+	err = devl_param_driverinit_value_get(priv_to_devlink(pf),
+					      DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
+					      &value);
+	return err ? test_bit(ICE_FLAG_RDMA_ENA, pf->flags) : value.vbool;
 }
 
 /**
Signature · 1 line
2.42.0
#17 lore raw

PATCH v6 8/9 ice: simplify VF MSI-X managing

In reply to Michal Swiatkowski

After implementing pf->msix.max field, base vector for other use cases (like VFs) can be fixed. This simplify code when changing MSI-X amount on particular VF, because there is no need to move a base vector.

A fixed base vector allows to reserve vectors from the beginning instead of from the end, which is also simpler in code.

Store total and rest value in the same struct as max and min for PF. Move tracking vectors from ice_sriov.c to ice_irq.c as it can be also use for other none PF use cases (SIOV).

---
 drivers/net/ethernet/intel/ice/ice.h       |  10 +-
 drivers/net/ethernet/intel/ice/ice_irq.c   |  75 +++++++---
 drivers/net/ethernet/intel/ice/ice_irq.h   |  13 +-
 drivers/net/ethernet/intel/ice/ice_sriov.c | 154 ++-------------------
 4 files changed, 79 insertions(+), 173 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +3 -7
index a5d55843ef5c..c65c3ac3ae77 100644
@@ -544,6 +544,8 @@ struct ice_pf_msix {
 	u16 cur;
 	u16 min;
 	u16 max;
+	u16 total;
+	u16 rest;
 };
 
 struct ice_pf {
@@ -560,13 +562,7 @@ struct ice_pf {
 	/* OS reserved IRQ details */
 	struct msix_entry *msix_entries;
 	struct ice_irq_tracker irq_tracker;
-	/* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
-	 * number of MSIX vectors needed for all SR-IOV VFs from the number of
-	 * MSIX vectors allowed on this PF.
-	 */
-	u16 sriov_base_vector;
-	unsigned long *sriov_irq_bm;	/* bitmap to track irq usage */
-	u16 sriov_irq_size;		/* size of the irq_bm bitmap */
+	struct ice_virt_irq_tracker virt_irq_tracker;
 
 	u16 ctrl_vsi_idx;		/* control VSI index in pf->vsi array */
 
drivers/net/ethernet/intel/ice/ice_irq.c +53 -22

127 lines not on this page · raw message

drivers/net/ethernet/intel/ice/ice_irq.h +12 -1
index f35efc08575e..d5e0fdd9b535 100644
@@ -15,11 +15,22 @@ struct ice_irq_tracker {
 	u16 num_static;	/* preallocated entries */
 };
 
+struct ice_virt_irq_tracker {
+	unsigned long *bm;	/* bitmap to track irq usage */
+	u16 num_entries;
+	/* First MSIX vector used by SR-IOV VFs. Calculated by subtracting the
+	 * number of MSIX vectors needed for all SR-IOV VFs from the number of
+	 * MSIX vectors allowed on this PF.
+	 */
+	u16 base;
+};
+
 int ice_init_interrupt_scheme(struct ice_pf *pf);
 void ice_clear_interrupt_scheme(struct ice_pf *pf);
 
 struct msi_map ice_alloc_irq(struct ice_pf *pf, bool dyn_only);
 void ice_free_irq(struct ice_pf *pf, struct msi_map map);
-int ice_get_max_used_msix_vector(struct ice_pf *pf);
 
+int ice_virt_get_irqs(struct ice_pf *pf, u16 needed);
+void ice_virt_free_irqs(struct ice_pf *pf, u16 index, u16 irqs);
 #endif
drivers/net/ethernet/intel/ice/ice_sriov.c +11 -143

264 lines not on this page · raw message

Signature · 1 line
2.42.0
#18 lore raw

PATCH v6 9/9 ice: init flow director before RDMA

In reply to Michal Swiatkowski

Flow director needs only one MSI-X. Load it before RDMA to save MSI-X for it.

---
 drivers/net/ethernet/intel/ice/ice_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +4 -2
index f3dd300a7dad..b819e7f9d97d 100644
@@ -5168,11 +5168,12 @@ int ice_load(struct ice_pf *pf)
 
 	ice_napi_add(vsi);
 
+	ice_init_features(pf);
+
 	err = ice_init_rdma(pf);
 	if (err)
 		goto err_init_rdma;
 
-	ice_init_features(pf);
 	ice_service_task_restart(pf);
 
 	clear_bit(ICE_DOWN, pf->state);
@@ -5180,6 +5181,7 @@ int ice_load(struct ice_pf *pf)
 	return 0;
 
 err_init_rdma:
+	ice_deinit_features(pf);
 	ice_tc_indir_block_unregister(vsi);
 err_tc_indir_block_register:
 	ice_unregister_netdev(vsi);
@@ -5203,8 +5205,8 @@ void ice_unload(struct ice_pf *pf)
 
 	devl_assert_locked(priv_to_devlink(pf));
 
-	ice_deinit_features(pf);
 	ice_deinit_rdma(pf);
+	ice_deinit_features(pf);
 	ice_tc_indir_block_unregister(vsi);
 	ice_unregister_netdev(vsi);
 	ice_devlink_destroy_pf_port(pf);
Signature · 1 line
2.42.0
Reviewed-by on the v6 series
#19 lore raw
In reply to Michal Swiatkowski
Quoted 110 lines · Michal Swiatkowski

Hi,

It is another try to allow user to manage amount of MSI-X used for each feature in ice. First was via devlink resources API, it wasn't accepted in upstream. Also static MSI-X allocation using devlink resources isn't really user friendly.

This try is using more dynamic way. "Dynamic" across whole kernel when platform supports it and "dynamic" across the driver when not.

To achieve that reuse global devlink parameter pf_msix_max and pf_msix_min. It fits how ice hardware counts MSI-X. In case of ice amount of MSI-X reported on PCI is a whole MSI-X for the card (with MSI-X for VFs also). Having pf_msix_max allow user to statically set how many MSI-X he wants on PF and how many should be reserved for VFs.

pf_msix_min is used to set minimum number of MSI-X with which ice driver should probe correctly.

Meaning of this field in case of dynamic vs static allocation:
- on system with dynamic MSI-X allocation support
* alloc pf_msix_min as static, rest will be allocated dynamically
- on system without dynamic MSI-X allocation support
* try alloc pf_msix_max as static, minimum acceptable result is pf_msix_min

As Jesse and Piotr suggested pf_msix_max and pf_msix_min can (an probably should) be stored in NVM. This patchset isn't implementing that.

Dynamic (kernel or driver) way means that splitting MSI-X across the RDMA and eth in case there is a MSI-X shortage isn't correct. Can work when dynamic is only on driver site, but can't when dynamic is on kernel site.

Let's remove this code and move to MSI-X allocation feature by feature. If there is no more MSI-X for a feature, a feature is working with less MSI-X or it is turned off.

There is a regression here. With MSI-X splitting user can run RDMA and eth even on system with not enough MSI-X. Now only eth will work. RDMA can be turned on by changing number of PF queues (lowering) and reprobe RDMA driver.

Example:
72 CPU number, eth, RDMA and flow director (1 MSI-X), 1 MSI-X for OICR on PF, and 1 more for RDMA. Card is using 1 + 72 + 1 + 72 + 1 = 147.

We set pf_msix_min = 2, pf_msix_max = 128

OICR: 1
eth: 72
flow director: 1
RDMA: 128 - 74 = 54

We can change number of queues on pf to 36 and do devlink reinit

OICR: 1
eth: 36
RDMA: 73
flow director: 1

We can also (implemented in "ice: enable_rdma devlink param") turned RDMA off.

OICR: 1
eth: 72
RDMA: 0 (turned off)
flow director: 1

After this changes we have a static base vector for SRIOV (SIOV probably in the feature). Last patch from this series is simplifying managing VF MSI-X code based on static vector.

Now changing queues using ethtool is also changing MSI-X. If there is enough MSI-X it is always one to one. When there is not enough there will be more queues than MSI-X. There is a lack of ability to set how many queues should be used per MSI-X. Maybe we should introduce another ethtool param for it? Sth like queues_per_vector?

v5 --> v6: [5]
* set default MSI-X max value based on needs instead of const define (patch 3)

v4 --> v5: [4]
* count combined queues in ethtool for case the vectors aren't mapped 1:1 to queues (patch 1)
* change min_t to min where the casting isn't needed (and can hide problems) (patch 4)
* load msix_max and msix_min value after devlink reload; it accidentally wasn't added after removing loading in probe path to mitigate error from devl_para_driverinit...() (patch 2)
* add documentation in develink/ice for new parameters (patch 2)

v3 --> v4: [3]
* drop unnecessary text in devlink validation comments
* assume that devl_param_driverinit...() shouldn't return error in normal execution path

v2 --> v3: [2]
* move flow director init before RDMA init
* fix unrolling RDMA MSI-X allocation
* add comment in commit message about lowering control RDMA MSI-X amount

v1 --> v2: [1]
* change permanent MSI-X cmode parameters to driverinit
* remove locking during devlink parameter registration (it is now locked for whole init/deinit part)

Quoted 6 lines

[5] https://lore.kernel.org/netdev/[email protected]/T/#t
[4] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[1] https://lore.kernel.org/netdev/[email protected]/

This version looks good to me! A lot of great simplification here too.

Thanks,
Jake

Quoted 28 lines

Michal Swiatkowski (9):
ice: count combined queues using Rx/Tx count
ice: devlink PF MSI-X max and min parameter
ice: remove splitting MSI-X between features
ice: get rid of num_lan_msix field
ice, irdma: move interrupts code to irdma
ice: treat dyn_allowed only as suggestion
ice: enable_rdma devlink param
ice: simplify VF MSI-X managing
ice: init flow director before RDMA

 Documentation/networking/devlink/ice.rst      |  11 +
 drivers/infiniband/hw/irdma/hw.c              |   2 -
 drivers/infiniband/hw/irdma/main.c            |  46 ++-
 drivers/infiniband/hw/irdma/main.h            |   3 +
 .../net/ethernet/intel/ice/devlink/devlink.c  | 102 ++++++-
 drivers/net/ethernet/intel/ice/ice.h          |  21 +-
 drivers/net/ethernet/intel/ice/ice_base.c     |  10 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c  |   9 +-
 drivers/net/ethernet/intel/ice/ice_idc.c      |  64 +---
 drivers/net/ethernet/intel/ice/ice_irq.c      | 275 ++++++------------
 drivers/net/ethernet/intel/ice/ice_irq.h      |  13 +-
 drivers/net/ethernet/intel/ice/ice_lib.c      |  35 ++-
 drivers/net/ethernet/intel/ice/ice_main.c     |   6 +-
 drivers/net/ethernet/intel/ice/ice_sriov.c    | 154 +---------
 include/linux/net/intel/iidc.h                |   2 +
 15 files changed, 328 insertions(+), 425 deletions(-)