Skip to content

Commit 43f4466

Browse files
iveceraanguy11
authored andcommitted
i40e: Add helper to access main VSI
Add simple helper i40e_pf_get_main_vsi(pf) to access main VSI that replaces pattern 'pf->vsi[pf->lan_vsi]' Reviewed-by: Michal Schmidt <mschmidt@redhat.com> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> Signed-off-by: Ivan Vecera <ivecera@redhat.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent 7033ada commit 43f4466

9 files changed

Lines changed: 116 additions & 83 deletions

File tree

drivers/net/ethernet/intel/i40e/i40e.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,17 @@ i40e_pf_get_vsi_by_seid(struct i40e_pf *pf, u16 seid)
13721372
return NULL;
13731373
}
13741374

1375+
/**
1376+
* i40e_pf_get_main_vsi - get pointer to main VSI
1377+
* @pf: pointer to a PF
1378+
*
1379+
* Return: pointer to main VSI or NULL if it does not exist
1380+
**/
1381+
static inline struct i40e_vsi *i40e_pf_get_main_vsi(struct i40e_pf *pf)
1382+
{
1383+
return (pf->lan_vsi != I40E_NO_VSI) ? pf->vsi[pf->lan_vsi] : NULL;
1384+
}
1385+
13751386
/**
13761387
* i40e_pf_get_veb_by_seid - find VEB by SEID
13771388
* @pf: pointer to a PF

drivers/net/ethernet/intel/i40e/i40e_client.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)
107107
**/
108108
void i40e_notify_client_of_l2_param_changes(struct i40e_pf *pf)
109109
{
110+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
110111
struct i40e_client_instance *cdev = pf->cinst;
111-
struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
112112
struct i40e_params params;
113113

114114
if (!cdev || !cdev->client)
@@ -333,9 +333,9 @@ static int i40e_register_auxiliary_dev(struct i40e_info *ldev, const char *name)
333333
**/
334334
static void i40e_client_add_instance(struct i40e_pf *pf)
335335
{
336+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
336337
struct i40e_client_instance *cdev = NULL;
337338
struct netdev_hw_addr *mac = NULL;
338-
struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
339339

340340
cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
341341
if (!cdev)
@@ -399,9 +399,9 @@ void i40e_client_del_instance(struct i40e_pf *pf)
399399
**/
400400
void i40e_client_subtask(struct i40e_pf *pf)
401401
{
402-
struct i40e_client *client;
402+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
403403
struct i40e_client_instance *cdev;
404-
struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
404+
struct i40e_client *client;
405405
int ret = 0;
406406

407407
if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state))
@@ -665,8 +665,8 @@ static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
665665
bool is_vf, u32 vf_id,
666666
u32 flag, u32 valid_flag)
667667
{
668+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(ldev->pf);
668669
struct i40e_pf *pf = ldev->pf;
669-
struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
670670
struct i40e_vsi_context ctxt;
671671
bool update = true;
672672
int err;

drivers/net/ethernet/intel/i40e/i40e_ddp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ static int i40e_ddp_load(struct net_device *netdev, const u8 *data, size_t size,
407407
**/
408408
static int i40e_ddp_restore(struct i40e_pf *pf)
409409
{
410+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
411+
struct net_device *netdev = vsi->netdev;
410412
struct i40e_ddp_old_profile_list *entry;
411-
struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev;
412413
int status = 0;
413414

414415
if (!list_empty(&pf->ddp_old_prof)) {

drivers/net/ethernet/intel/i40e/i40e_debugfs.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
5353
size_t count, loff_t *ppos)
5454
{
5555
struct i40e_pf *pf = filp->private_data;
56+
struct i40e_vsi *main_vsi;
5657
int bytes_not_copied;
5758
int buf_size = 256;
5859
char *buf;
@@ -68,8 +69,8 @@ static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
6869
if (!buf)
6970
return -ENOSPC;
7071

71-
len = snprintf(buf, buf_size, "%s: %s\n",
72-
pf->vsi[pf->lan_vsi]->netdev->name,
72+
main_vsi = i40e_pf_get_main_vsi(pf);
73+
len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name,
7374
i40e_dbg_command_buf);
7475

7576
bytes_not_copied = copy_to_user(buffer, buf, len);
@@ -786,7 +787,8 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
786787
cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
787788
if (cnt == 0) {
788789
/* default to PF VSI */
789-
vsi_seid = pf->vsi[pf->lan_vsi]->seid;
790+
vsi = i40e_pf_get_main_vsi(pf);
791+
vsi_seid = vsi->seid;
790792
} else if (vsi_seid < 0) {
791793
dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
792794
vsi_seid);
@@ -1030,7 +1032,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
10301032
goto command_write_done;
10311033
}
10321034

1033-
vsi = pf->vsi[pf->lan_vsi];
1035+
vsi = i40e_pf_get_main_vsi(pf);
10341036
switch_id =
10351037
le16_to_cpu(vsi->info.switch_id) &
10361038
I40E_AQ_VSI_SW_ID_MASK;
@@ -1380,6 +1382,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
13801382
dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
13811383
i40e_get_current_fd_count(pf));
13821384
} else if (strncmp(cmd_buf, "lldp", 4) == 0) {
1385+
/* Get main VSI */
1386+
struct i40e_vsi *main_vsi = i40e_pf_get_main_vsi(pf);
1387+
13831388
if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
13841389
int ret;
13851390

@@ -1391,10 +1396,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
13911396
goto command_write_done;
13921397
}
13931398
ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1394-
pf->hw.mac.addr,
1395-
ETH_P_LLDP, 0,
1396-
pf->vsi[pf->lan_vsi]->seid,
1397-
0, true, NULL, NULL);
1399+
pf->hw.mac.addr, ETH_P_LLDP, 0,
1400+
main_vsi->seid, 0, true, NULL,
1401+
NULL);
13981402
if (ret) {
13991403
dev_info(&pf->pdev->dev,
14001404
"%s: Add Control Packet Filter AQ command failed =0x%x\n",
@@ -1409,10 +1413,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
14091413
int ret;
14101414

14111415
ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
1412-
pf->hw.mac.addr,
1413-
ETH_P_LLDP, 0,
1414-
pf->vsi[pf->lan_vsi]->seid,
1415-
0, false, NULL, NULL);
1416+
pf->hw.mac.addr, ETH_P_LLDP, 0,
1417+
main_vsi->seid, 0, false, NULL,
1418+
NULL);
14161419
if (ret) {
14171420
dev_info(&pf->pdev->dev,
14181421
"%s: Remove Control Packet Filter AQ command failed =0x%x\n",
@@ -1639,6 +1642,7 @@ static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
16391642
size_t count, loff_t *ppos)
16401643
{
16411644
struct i40e_pf *pf = filp->private_data;
1645+
struct i40e_vsi *main_vsi;
16421646
int bytes_not_copied;
16431647
int buf_size = 256;
16441648
char *buf;
@@ -1654,8 +1658,8 @@ static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
16541658
if (!buf)
16551659
return -ENOSPC;
16561660

1657-
len = snprintf(buf, buf_size, "%s: %s\n",
1658-
pf->vsi[pf->lan_vsi]->netdev->name,
1661+
main_vsi = i40e_pf_get_main_vsi(pf);
1662+
len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name,
16591663
i40e_dbg_netdev_ops_buf);
16601664

16611665
bytes_not_copied = copy_to_user(buffer, buf, len);

drivers/net/ethernet/intel/i40e/i40e_ethtool.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,7 @@ static void i40e_get_ringparam(struct net_device *netdev,
20292029
{
20302030
struct i40e_netdev_priv *np = netdev_priv(netdev);
20312031
struct i40e_pf *pf = np->vsi->back;
2032-
struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
2032+
struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
20332033

20342034
ring->rx_max_pending = i40e_get_max_num_descriptors(pf);
20352035
ring->tx_max_pending = i40e_get_max_num_descriptors(pf);
@@ -3370,6 +3370,7 @@ static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
33703370
struct i40e_rx_flow_userdef userdef = {0};
33713371
struct i40e_fdir_filter *rule = NULL;
33723372
struct hlist_node *node2;
3373+
struct i40e_vsi *vsi;
33733374
u64 input_set;
33743375
u16 index;
33753376

@@ -3493,9 +3494,8 @@ static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
34933494
fsp->flow_type |= FLOW_EXT;
34943495
}
34953496

3496-
if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
3497-
struct i40e_vsi *vsi;
3498-
3497+
vsi = i40e_pf_get_main_vsi(pf);
3498+
if (rule->dest_vsi != vsi->id) {
34993499
vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
35003500
if (vsi && vsi->type == I40E_VSI_SRIOV) {
35013501
/* VFs are zero-indexed by the driver, but ethtool

0 commit comments

Comments
 (0)