Skip to contentSkip to conversation

ice: minor cleanups for VF IRQ logic

PATCH Superseded Jacob Keller 1 participant 4 messages Mar 19, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ice: minor cleanups for VF IRQ logic

While working on implementing Scalable IOV support for the ice driver, I found a few minor gotchas in the VF logic where the existing code is not ready to handle Scalable VFs.

First, the recent support to allow programming the VF MSI-X count initialized some values in ice_sriov.c in the for loop for creating VFs using the sriov_numvfs interface. We will need to initialize these values for Scalable VFs as well, and this should belong in ice_initialize_vf_entry().

Second, when programming the VF IRQs in response to virtchnl commands, the current virtchnl logic hardcodes the assumption that hardware IRQ indexes are VF relative. This is true for Single Root IOV, but is not true for Scalable IOV where the interrupts come from the PF space. Cleanup the logic to look up the IRQ index from the q_vector, making this flow more agnostic of the VF functionality type.

Neither of these changes is critical for current SR-IOV support, but they do prepare the way for Scalable IOV VF support. I'd rather have these cleanups already taken care now instead of carrying them until the Scalable IOV code is submitted.

Jacob Keller (2):
ice: set vf->num_msix in ice_initialize_vf_entry()
ice: look up VF MSI-X index from q_vector->irq.index

 drivers/net/ethernet/intel/ice/ice_base.c     |  6 ++++++
 drivers/net/ethernet/intel/ice/ice_sriov.c    |  5 -----
 drivers/net/ethernet/intel/ice/ice_vf_lib.c   |  5 ++++-
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 12 +++++-------
 4 files changed, 15 insertions(+), 13 deletions(-)

base-commit: 237bb5f7f7f55ec5f773469a974c61a49c298625

Signature · 1 line
2.44.0.53.g0f9d4d28b7e6
#1 lore raw

PATCH 1/2 ice: set vf->num_msix in ice_initialize_vf_entry()

Commit fe1c5ca2fe76 ("ice: implement num_msix field per VF") updated the driver to allow for per-VF MSI-X configuration. The initial defaults were set in ice_create_vf_entries(). This logic is better placed in ice_initialize_vf_entry(). Indeed, that function already sets vf->num_vf_qs, as well as initializes the allow list via calling ice_vc_set_default_allowlist().

Move this logic into ice_initialize_vf_entry(). This makes the code clear, and ensures that these VF fields will be initialized properly for both SR-IOV VFs and the upcoming Scalable IOV VFs.

---
 drivers/net/ethernet/intel/ice/ice_sriov.c  | 5 -----
 drivers/net/ethernet/intel/ice/ice_vf_lib.c | 5 ++++-
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_sriov.c +0 -5
index 65e1986af777..5e9521876617 100644
@@ -831,11 +831,6 @@ static int ice_create_vf_entries(struct ice_pf *pf, u16 num_vfs)
 
 		pci_dev_get(vfdev);
 
-		/* set default number of MSI-X */
-		vf->num_msix = pf->vfs.num_msix_per;
-		vf->num_vf_qs = pf->vfs.num_qps_per;
-		ice_vc_set_default_allowlist(vf);
-
 		hash_add_rcu(vfs->table, &vf->entry, vf_id);
 	}
 
drivers/net/ethernet/intel/ice/ice_vf_lib.c +4 -1
index 21d26e19338a..c51e2482cad2 100644
@@ -992,10 +992,13 @@ void ice_initialize_vf_entry(struct ice_vf *vf)
 
 	/* assign default capabilities */
 	vf->spoofchk = true;
-	vf->num_vf_qs = vfs->num_qps_per;
 	ice_vc_set_default_allowlist(vf);
 	ice_virtchnl_set_dflt_ops(vf);
 
+	/* set default number of MSI-X */
+	vf->num_msix = vfs->num_msix_per;
+	vf->num_vf_qs = vfs->num_qps_per;
+
 	/* ctrl_vsi_idx will be set to a valid value only when iAVF
 	 * creates its first fdir rule.
 	 */
Signature · 1 line
2.44.0.53.g0f9d4d28b7e6
#2 lore raw

PATCH 2/2 ice: look up VF MSI-X index from q_vector->irq.index

In reply to Jacob Keller

The ice physical function driver needs to configure the association of queues and interrupts on behalf of its virtual functions. This is done over virtchnl by the VF sending messages during its initialization phase. These messages contain a vector_id which the VF wants to associate with a given queue. This ID is relative to the VF space, where 0 indicates the control IRQ for non-queue interrupts.

When programming the mapping, the PF driver currently passes this vector_id directly to the low level functions for programming. This works for SR-IOV, because the hardware uses the VF-based indexing for interrupts.

The future Scalable IOV work does not use VF-based indexing, as the interrupts are used from the PF space and mapped via VFIO into the VM. Thus, the interrupt indexes used on the PF are PF-based. To handle this, the driver will need to be able to locate the proper index for programming the hardware registers. For standard IRQs allocated from the PF area, this would just be the irq.index field.

This field is currently unused for SR-IOV. When initializing the queue vectors for ICE_VSI_VF, populate the irq.index field appropriately. Replace the direct use of the vector_id parameter passed from VF with the q_vector->irq.index when programming the queues.

Now that we lookup the vector_id from the q_vector structure, we no longer need to pass the value as a parameter in ice_cfg_interrupt. Also notice that this function returns an int, but then is cast to the virtchnl error enumeration, virtchnl_status_code. Update the return type to indicate it does not return an integer error code. We can't use normal error codes here because the return values are passed across the virtchnl interface.

This prepares the virtchnl logic for configuring interrupts to support the upcoming Scalable IOV VFs, without breaking existing SR-IOV functionality.

---
 drivers/net/ethernet/intel/ice/ice_base.c     |  6 ++++++
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 12 +++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/ice/ice_base.c +6 -0
index 662fc395edcc..013b3509028a 100644
@@ -122,6 +122,12 @@ static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, u16 v_idx)
 
 	if (vsi->type == ICE_VSI_VF) {
 		q_vector->reg_idx = ice_calc_vf_reg_idx(vsi->vf, q_vector);
+		/* The index value is used to configure the hardware when
+		 * programming the Tx and Rx queues. It is relative to each VF
+		 * but must account for the non-queue vectors associated with
+		 * that VF.
+		 */
+		q_vector->irq.index = v_idx + ICE_NONQ_VECS_VF;
 		goto out;
 	} else if (vsi->type == ICE_VSI_CTRL && vsi->vf) {
 		struct ice_vsi *ctrl_vsi = ice_get_vf_ctrl_vsi(pf, vsi);
drivers/net/ethernet/intel/ice/ice_virtchnl.c +5 -7
index 1ff9818b4c84..2d20cfc97647 100644
@@ -1505,13 +1505,12 @@ static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
  * ice_cfg_interrupt
  * @vf: pointer to the VF info
  * @vsi: the VSI being configured
- * @vector_id: vector ID
  * @map: vector map for mapping vectors to queues
  * @q_vector: structure for interrupt vector
  * configure the IRQ to queue map
  */
-static int
-ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
+static enum virtchnl_status_code
+ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi,
 		  struct virtchnl_vector_map *map,
 		  struct ice_q_vector *q_vector)
 {
@@ -1531,7 +1530,7 @@ ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
 		q_vector->num_ring_rx++;
 		q_vector->rx.itr_idx = map->rxitr_idx;
 		vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
-		ice_cfg_rxq_interrupt(vsi, vsi_q_id, vector_id,
+		ice_cfg_rxq_interrupt(vsi, vsi_q_id, q_vector->irq.index,
 				      q_vector->rx.itr_idx);
 	}
 
@@ -1545,7 +1544,7 @@ ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi, u16 vector_id,
 		q_vector->num_ring_tx++;
 		q_vector->tx.itr_idx = map->txitr_idx;
 		vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
-		ice_cfg_txq_interrupt(vsi, vsi_q_id, vector_id,
+		ice_cfg_txq_interrupt(vsi, vsi_q_id, q_vector->irq.index,
 				      q_vector->tx.itr_idx);
 	}
 
@@ -1619,8 +1618,7 @@ static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
 		}
 
 		/* lookout for the invalid queue index */
-		v_ret = (enum virtchnl_status_code)
-			ice_cfg_interrupt(vf, vsi, vector_id, map, q_vector);
+		v_ret = ice_cfg_interrupt(vf, vsi, map, q_vector);
 		if (v_ret)
 			goto error_param;
 	}
Signature · 1 line
2.44.0.53.g0f9d4d28b7e6
#3 lore raw
In reply to Jacob Keller
Quoted 17 lines · Jacob Keller

While working on implementing Scalable IOV support for the ice driver, I found a few minor gotchas in the VF logic where the existing code is not ready to handle Scalable VFs.

First, the recent support to allow programming the VF MSI-X count initialized some values in ice_sriov.c in the for loop for creating VFs using the sriov_numvfs interface. We will need to initialize these values for Scalable VFs as well, and this should belong in ice_initialize_vf_entry().

Second, when programming the VF IRQs in response to virtchnl commands, the current virtchnl logic hardcodes the assumption that hardware IRQ indexes are VF relative. This is true for Single Root IOV, but is not true for Scalable IOV where the interrupts come from the PF space. Cleanup the logic to look up the IRQ index from the q_vector, making this flow more agnostic of the VF functionality type.

Quoted 9 lines

Neither of these changes is critical for current SR-IOV support, but they do prepare the way for Scalable IOV VF support. I'd rather have these cleanups already taken care now instead of carrying them until the Scalable IOV code is submitted.

Jacob Keller (2):
ice: set vf->num_msix in ice_initialize_vf_entry()
ice: look up VF MSI-X index from q_vector->irq.index

Please ignore for now. This has a conflict with the recent work to refactor how MSI-X resources are tracked, and results in trying to free a vector that was never allocated. It worked on an older driver, but when I rebased to the next-queue it causes this:

[  492.930839] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 1
[  492.938804] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 2
[  492.946763] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 3
[  492.954722] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 4
[  492.962663] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 5
[  492.970582] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 6
[  492.978524] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 7
[  492.986463] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 8
[  492.994413] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 9
[  493.002361] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 10
[  493.010383] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 11
[  493.018416] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 12
[  493.026458] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 13
[  493.034988] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 14
[  493.043311] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at
index 15
[  493.051543] ice 0000:b8:00.0: Failed to get MSIX interrupt entry at

index 16

I will need to re-evaluate how we can get the proper index here.

Quoted 8 lines
 drivers/net/ethernet/intel/ice/ice_base.c     |  6 ++++++
 drivers/net/ethernet/intel/ice/ice_sriov.c    |  5 -----
 drivers/net/ethernet/intel/ice/ice_vf_lib.c   |  5 ++++-
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 12 +++++-------
 4 files changed, 15 insertions(+), 13 deletions(-)

base-commit: 237bb5f7f7f55ec5f773469a974c61a49c298625