Skip to content

Commit c4c2c7d

Browse files
jacob-kelleranguy11
authored andcommitted
ice: convert ice_for_each_vf to include VF entry iterator
The ice_for_each_vf macro is intended to be used to loop over all VFs. The current implementation relies on an iterator that is the index into the VF array in the PF structure. This forces all users to perform a look up themselves. This abstraction forces a lot of duplicate work on callers and leaks the interface implementation to the caller. Replace this with an implementation that includes the VF pointer the primary iterator. This version simplifies callers which just want to iterate over every VF, as they no longer need to perform their own lookup. The "i" iterator value is replaced with a new unsigned int "bkt" parameter, as this will match the necessary interface for replacing the VF array with a hash table. For now, the bkt is the VF ID, but in the future it will simply be the hash bucket index. Document that it should not be treated as a VF ID. This change aims to simplify switching from the array to a hash table. I considered alternative implementations such as an xarray but decided that the hash table was the simplest and most suitable implementation. I also looked at methods to hide the bkt iterator entirely, but I couldn't come up with a feasible solution that worked for hash table iterators. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 19281e8 commit c4c2c7d

File tree

8 files changed

+163
-152
lines changed

8 files changed

+163
-152
lines changed

drivers/net/ethernet/intel/ice/ice_eswitch.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ static void ice_eswitch_remap_rings_to_vectors(struct ice_pf *pf)
210210
static void
211211
ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
212212
{
213-
int i;
213+
struct ice_vf *vf;
214+
unsigned int bkt;
214215

215-
ice_for_each_vf(pf, i) {
216-
struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
217-
struct ice_vf *vf = &pf->vf[i];
216+
ice_for_each_vf(pf, bkt, vf) {
217+
struct ice_vsi *vsi = vf->repr->src_vsi;
218218

219219
/* Skip VFs that aren't configured */
220220
if (!vf->repr->dst)
@@ -238,11 +238,11 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
238238
{
239239
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
240240
int max_vsi_num = 0;
241-
int i;
241+
struct ice_vf *vf;
242+
unsigned int bkt;
242243

243-
ice_for_each_vf(pf, i) {
244-
struct ice_vsi *vsi = pf->vf[i].repr->src_vsi;
245-
struct ice_vf *vf = &pf->vf[i];
244+
ice_for_each_vf(pf, bkt, vf) {
245+
struct ice_vsi *vsi = vf->repr->src_vsi;
246246

247247
ice_remove_vsi_fltr(&pf->hw, vsi->idx);
248248
vf->repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
@@ -282,8 +282,8 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
282282
netif_keep_dst(vf->repr->netdev);
283283
}
284284

285-
ice_for_each_vf(pf, i) {
286-
struct ice_repr *repr = pf->vf[i].repr;
285+
ice_for_each_vf(pf, bkt, vf) {
286+
struct ice_repr *repr = vf->repr;
287287
struct ice_vsi *vsi = repr->src_vsi;
288288
struct metadata_dst *dst;
289289

@@ -417,10 +417,11 @@ ice_eswitch_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
417417
*/
418418
static void ice_eswitch_napi_del(struct ice_pf *pf)
419419
{
420-
int i;
420+
struct ice_vf *vf;
421+
unsigned int bkt;
421422

422-
ice_for_each_vf(pf, i)
423-
netif_napi_del(&pf->vf[i].repr->q_vector->napi);
423+
ice_for_each_vf(pf, bkt, vf)
424+
netif_napi_del(&vf->repr->q_vector->napi);
424425
}
425426

426427
/**
@@ -429,10 +430,11 @@ static void ice_eswitch_napi_del(struct ice_pf *pf)
429430
*/
430431
static void ice_eswitch_napi_enable(struct ice_pf *pf)
431432
{
432-
int i;
433+
struct ice_vf *vf;
434+
unsigned int bkt;
433435

434-
ice_for_each_vf(pf, i)
435-
napi_enable(&pf->vf[i].repr->q_vector->napi);
436+
ice_for_each_vf(pf, bkt, vf)
437+
napi_enable(&vf->repr->q_vector->napi);
436438
}
437439

438440
/**
@@ -441,10 +443,11 @@ static void ice_eswitch_napi_enable(struct ice_pf *pf)
441443
*/
442444
static void ice_eswitch_napi_disable(struct ice_pf *pf)
443445
{
444-
int i;
446+
struct ice_vf *vf;
447+
unsigned int bkt;
445448

446-
ice_for_each_vf(pf, i)
447-
napi_disable(&pf->vf[i].repr->q_vector->napi);
449+
ice_for_each_vf(pf, bkt, vf)
450+
napi_disable(&vf->repr->q_vector->napi);
448451
}
449452

450453
/**
@@ -613,16 +616,15 @@ int ice_eswitch_configure(struct ice_pf *pf)
613616
*/
614617
static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
615618
{
616-
struct ice_repr *repr;
617-
int i;
619+
struct ice_vf *vf;
620+
unsigned int bkt;
618621

619622
if (test_bit(ICE_DOWN, pf->state))
620623
return;
621624

622-
ice_for_each_vf(pf, i) {
623-
repr = pf->vf[i].repr;
624-
if (repr)
625-
ice_repr_start_tx_queues(repr);
625+
ice_for_each_vf(pf, bkt, vf) {
626+
if (vf->repr)
627+
ice_repr_start_tx_queues(vf->repr);
626628
}
627629
}
628630

@@ -632,16 +634,15 @@ static void ice_eswitch_start_all_tx_queues(struct ice_pf *pf)
632634
*/
633635
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf)
634636
{
635-
struct ice_repr *repr;
636-
int i;
637+
struct ice_vf *vf;
638+
unsigned int bkt;
637639

638640
if (test_bit(ICE_DOWN, pf->state))
639641
return;
640642

641-
ice_for_each_vf(pf, i) {
642-
repr = pf->vf[i].repr;
643-
if (repr)
644-
ice_repr_stop_tx_queues(repr);
643+
ice_for_each_vf(pf, bkt, vf) {
644+
if (vf->repr)
645+
ice_repr_stop_tx_queues(vf->repr);
645646
}
646647
}
647648

drivers/net/ethernet/intel/ice/ice_ethtool.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
316316
*/
317317
static bool ice_active_vfs(struct ice_pf *pf)
318318
{
319-
unsigned int i;
320-
321-
ice_for_each_vf(pf, i) {
322-
struct ice_vf *vf = &pf->vf[i];
319+
struct ice_vf *vf;
320+
unsigned int bkt;
323321

322+
ice_for_each_vf(pf, bkt, vf) {
324323
if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
325324
return true;
326325
}

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,14 @@ static irqreturn_t ice_eswitch_msix_clean_rings(int __always_unused irq, void *d
433433
{
434434
struct ice_q_vector *q_vector = (struct ice_q_vector *)data;
435435
struct ice_pf *pf = q_vector->vsi->back;
436-
int i;
436+
struct ice_vf *vf;
437+
unsigned int bkt;
437438

438439
if (!q_vector->tx.tx_ring && !q_vector->rx.rx_ring)
439440
return IRQ_HANDLED;
440441

441-
ice_for_each_vf(pf, i)
442-
napi_schedule(&pf->vf[i].repr->q_vector->napi);
442+
ice_for_each_vf(pf, bkt, vf)
443+
napi_schedule(&vf->repr->q_vector->napi);
443444

444445
return IRQ_HANDLED;
445446
}
@@ -1342,11 +1343,10 @@ ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id)
13421343
*/
13431344
static int ice_get_vf_ctrl_res(struct ice_pf *pf, struct ice_vsi *vsi)
13441345
{
1345-
int i;
1346-
1347-
ice_for_each_vf(pf, i) {
1348-
struct ice_vf *vf = &pf->vf[i];
1346+
struct ice_vf *vf;
1347+
unsigned int bkt;
13491348

1349+
ice_for_each_vf(pf, bkt, vf) {
13501350
if (vf != vsi->vf && vf->ctrl_vsi_idx != ICE_NO_VSI)
13511351
return pf->vsi[vf->ctrl_vsi_idx]->base_vector;
13521352
}
@@ -2891,11 +2891,10 @@ void ice_napi_del(struct ice_vsi *vsi)
28912891
*/
28922892
static void ice_free_vf_ctrl_res(struct ice_pf *pf, struct ice_vsi *vsi)
28932893
{
2894-
int i;
2895-
2896-
ice_for_each_vf(pf, i) {
2897-
struct ice_vf *vf = &pf->vf[i];
2894+
struct ice_vf *vf;
2895+
unsigned int bkt;
28982896

2897+
ice_for_each_vf(pf, bkt, vf) {
28992898
if (vf != vsi->vf && vf->ctrl_vsi_idx != ICE_NO_VSI)
29002899
return;
29012900
}

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
505505
{
506506
struct ice_hw *hw = &pf->hw;
507507
struct ice_vsi *vsi;
508-
unsigned int i;
508+
struct ice_vf *vf;
509+
unsigned int bkt;
509510

510511
dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type);
511512

@@ -520,8 +521,8 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
520521
ice_vc_notify_reset(pf);
521522

522523
/* Disable VFs until reset is completed */
523-
ice_for_each_vf(pf, i)
524-
ice_set_vf_state_qs_dis(&pf->vf[i]);
524+
ice_for_each_vf(pf, bkt, vf)
525+
ice_set_vf_state_qs_dis(vf);
525526

526527
if (ice_is_eswitch_mode_switchdev(pf)) {
527528
if (reset_type != ICE_RESET_PFR)
@@ -1666,7 +1667,8 @@ static void ice_handle_mdd_event(struct ice_pf *pf)
16661667
{
16671668
struct device *dev = ice_pf_to_dev(pf);
16681669
struct ice_hw *hw = &pf->hw;
1669-
unsigned int i;
1670+
struct ice_vf *vf;
1671+
unsigned int bkt;
16701672
u32 reg;
16711673

16721674
if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
@@ -1754,47 +1756,45 @@ static void ice_handle_mdd_event(struct ice_pf *pf)
17541756
/* Check to see if one of the VFs caused an MDD event, and then
17551757
* increment counters and set print pending
17561758
*/
1757-
ice_for_each_vf(pf, i) {
1758-
struct ice_vf *vf = &pf->vf[i];
1759-
1760-
reg = rd32(hw, VP_MDET_TX_PQM(i));
1759+
ice_for_each_vf(pf, bkt, vf) {
1760+
reg = rd32(hw, VP_MDET_TX_PQM(vf->vf_id));
17611761
if (reg & VP_MDET_TX_PQM_VALID_M) {
1762-
wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1762+
wr32(hw, VP_MDET_TX_PQM(vf->vf_id), 0xFFFF);
17631763
vf->mdd_tx_events.count++;
17641764
set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
17651765
if (netif_msg_tx_err(pf))
17661766
dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1767-
i);
1767+
vf->vf_id);
17681768
}
17691769

1770-
reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1770+
reg = rd32(hw, VP_MDET_TX_TCLAN(vf->vf_id));
17711771
if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1772-
wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1772+
wr32(hw, VP_MDET_TX_TCLAN(vf->vf_id), 0xFFFF);
17731773
vf->mdd_tx_events.count++;
17741774
set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
17751775
if (netif_msg_tx_err(pf))
17761776
dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1777-
i);
1777+
vf->vf_id);
17781778
}
17791779

1780-
reg = rd32(hw, VP_MDET_TX_TDPU(i));
1780+
reg = rd32(hw, VP_MDET_TX_TDPU(vf->vf_id));
17811781
if (reg & VP_MDET_TX_TDPU_VALID_M) {
1782-
wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1782+
wr32(hw, VP_MDET_TX_TDPU(vf->vf_id), 0xFFFF);
17831783
vf->mdd_tx_events.count++;
17841784
set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
17851785
if (netif_msg_tx_err(pf))
17861786
dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1787-
i);
1787+
vf->vf_id);
17881788
}
17891789

1790-
reg = rd32(hw, VP_MDET_RX(i));
1790+
reg = rd32(hw, VP_MDET_RX(vf->vf_id));
17911791
if (reg & VP_MDET_RX_VALID_M) {
1792-
wr32(hw, VP_MDET_RX(i), 0xFFFF);
1792+
wr32(hw, VP_MDET_RX(vf->vf_id), 0xFFFF);
17931793
vf->mdd_rx_events.count++;
17941794
set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
17951795
if (netif_msg_rx_err(pf))
17961796
dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1797-
i);
1797+
vf->vf_id);
17981798

17991799
/* Since the queue is disabled on VF Rx MDD events, the
18001800
* PF can be configured to reset the VF through ethtool
@@ -1805,9 +1805,9 @@ static void ice_handle_mdd_event(struct ice_pf *pf)
18051805
* reset, so print the event prior to reset.
18061806
*/
18071807
ice_print_vf_rx_mdd_event(vf);
1808-
mutex_lock(&pf->vf[i].cfg_lock);
1809-
ice_reset_vf(&pf->vf[i], false);
1810-
mutex_unlock(&pf->vf[i].cfg_lock);
1808+
mutex_lock(&vf->cfg_lock);
1809+
ice_reset_vf(vf, false);
1810+
mutex_unlock(&vf->cfg_lock);
18111811
}
18121812
}
18131813
}

drivers/net/ethernet/intel/ice/ice_repr.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,11 @@ static void ice_repr_rem(struct ice_vf *vf)
338338
*/
339339
void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
340340
{
341-
int i;
342-
343-
ice_for_each_vf(pf, i) {
344-
struct ice_vf *vf = &pf->vf[i];
341+
struct ice_vf *vf;
342+
unsigned int bkt;
345343

344+
ice_for_each_vf(pf, bkt, vf)
346345
ice_repr_rem(vf);
347-
}
348346
}
349347

350348
/**
@@ -353,12 +351,11 @@ void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
353351
*/
354352
int ice_repr_add_for_all_vfs(struct ice_pf *pf)
355353
{
354+
struct ice_vf *vf;
355+
unsigned int bkt;
356356
int err;
357-
int i;
358-
359-
ice_for_each_vf(pf, i) {
360-
struct ice_vf *vf = &pf->vf[i];
361357

358+
ice_for_each_vf(pf, bkt, vf) {
362359
err = ice_repr_add(vf);
363360
if (err)
364361
goto err;

drivers/net/ethernet/intel/ice/ice_virtchnl_fdir.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,15 +1572,15 @@ ice_vc_del_fdir_fltr_post(struct ice_vf *vf, struct ice_vf_fdir_ctx *ctx,
15721572
*/
15731573
void ice_flush_fdir_ctx(struct ice_pf *pf)
15741574
{
1575-
int i;
1575+
struct ice_vf *vf;
1576+
unsigned int bkt;
15761577

15771578
if (!test_and_clear_bit(ICE_FD_VF_FLUSH_CTX, pf->state))
15781579
return;
15791580

1580-
ice_for_each_vf(pf, i) {
1581+
ice_for_each_vf(pf, bkt, vf) {
15811582
struct device *dev = ice_pf_to_dev(pf);
15821583
enum virtchnl_fdir_prgm_status status;
1583-
struct ice_vf *vf = &pf->vf[i];
15841584
struct ice_vf_fdir_ctx *ctx;
15851585
unsigned long flags;
15861586
int ret;

0 commit comments

Comments
 (0)