Commit b1f1b46f authored by Ivan Vecera's avatar Ivan Vecera Committed by Tony Nguyen

i40e: Introduce and use macros for iterating VSIs and VEBs

Introduce i40e_for_each_vsi() and i40e_for_each_veb() helper
macros and use them to iterate relevant arrays.

Replace pattern:
for (i = 0; i < pf->num_alloc_vsi; i++)
by:
i40e_for_each_vsi(pf, i, vsi)

and pattern:
for (i = 0; i < I40E_MAX_VEB; i++)
by
i40e_for_each_veb(pf, i, veb)

These macros also check if array item pf->vsi[i] or pf->veb[i]
are not NULL and skip such items so we can remove redundant
checks from loop bodies.
Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: default avatarIvan Vecera <ivecera@redhat.com>
Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel)
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 7e6cec7d
......@@ -686,6 +686,54 @@ struct i40e_pf {
struct list_head ddp_old_prof;
};
/**
* __i40e_pf_next_vsi - get next valid VSI
* @pf: pointer to the PF struct
* @idx: pointer to start position number
*
* Find and return next non-NULL VSI pointer in pf->vsi array and
* updates idx position. Returns NULL if no VSI is found.
**/
static __always_inline struct i40e_vsi *
__i40e_pf_next_vsi(struct i40e_pf *pf, int *idx)
{
while (*idx < pf->num_alloc_vsi) {
if (pf->vsi[*idx])
return pf->vsi[*idx];
(*idx)++;
}
return NULL;
}
#define i40e_pf_for_each_vsi(_pf, _i, _vsi) \
for (_i = 0, _vsi = __i40e_pf_next_vsi(_pf, &_i); \
_vsi; \
_i++, _vsi = __i40e_pf_next_vsi(_pf, &_i))
/**
* __i40e_pf_next_veb - get next valid VEB
* @pf: pointer to the PF struct
* @idx: pointer to start position number
*
* Find and return next non-NULL VEB pointer in pf->veb array and
* updates idx position. Returns NULL if no VEB is found.
**/
static __always_inline struct i40e_veb *
__i40e_pf_next_veb(struct i40e_pf *pf, int *idx)
{
while (*idx < I40E_MAX_VEB) {
if (pf->veb[*idx])
return pf->veb[*idx];
(*idx)++;
}
return NULL;
}
#define i40e_pf_for_each_veb(_pf, _i, _veb) \
for (_i = 0, _veb = __i40e_pf_next_veb(_pf, &_i); \
_veb; \
_i++, _veb = __i40e_pf_next_veb(_pf, &_i))
/**
* i40e_mac_to_hkey - Convert a 6-byte MAC Address to a u64 hash key
* @macaddr: the MAC Address as the base key
......@@ -1120,14 +1168,12 @@ struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id);
static inline struct i40e_vsi *
i40e_find_vsi_by_type(struct i40e_pf *pf, u16 type)
{
struct i40e_vsi *vsi;
int i;
for (i = 0; i < pf->num_alloc_vsi; i++) {
struct i40e_vsi *vsi = pf->vsi[i];
if (vsi && vsi->type == type)
i40e_pf_for_each_vsi(pf, i, vsi)
if (vsi->type == type)
return vsi;
}
return NULL;
}
......
......@@ -947,16 +947,16 @@ static int i40e_dcbnl_vsi_del_app(struct i40e_vsi *vsi,
static void i40e_dcbnl_del_app(struct i40e_pf *pf,
struct i40e_dcb_app_priority_table *app)
{
struct i40e_vsi *vsi;
int v, err;
for (v = 0; v < pf->num_alloc_vsi; v++) {
if (pf->vsi[v] && pf->vsi[v]->netdev) {
err = i40e_dcbnl_vsi_del_app(pf->vsi[v], app);
i40e_pf_for_each_vsi(pf, v, vsi)
if (vsi->netdev) {
err = i40e_dcbnl_vsi_del_app(vsi, app);
dev_dbg(&pf->pdev->dev, "Deleting app for VSI seid=%d err=%d sel=%d proto=0x%x prio=%d\n",
pf->vsi[v]->seid, err, app->selector,
vsi->seid, err, app->selector,
app->protocolid, app->priority);
}
}
}
/**
......
......@@ -24,14 +24,18 @@ enum ring_type {
**/
static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
{
struct i40e_vsi *vsi;
int i;
if (seid < 0)
if (seid < 0) {
dev_info(&pf->pdev->dev, "%d: bad seid\n", seid);
else
for (i = 0; i < pf->num_alloc_vsi; i++)
if (pf->vsi[i] && (pf->vsi[i]->seid == seid))
return pf->vsi[i];
return NULL;
}
i40e_pf_for_each_vsi(pf, i, vsi)
if (vsi->seid == seid)
return vsi;
return NULL;
}
......@@ -43,11 +47,13 @@ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
**/
static struct i40e_veb *i40e_dbg_find_veb(struct i40e_pf *pf, int seid)
{
struct i40e_veb *veb;
int i;
for (i = 0; i < I40E_MAX_VEB; i++)
if (pf->veb[i] && pf->veb[i]->seid == seid)
return pf->veb[i];
i40e_pf_for_each_veb(pf, i, veb)
if (veb->seid == seid)
return veb;
return NULL;
}
......@@ -653,12 +659,11 @@ static void i40e_dbg_dump_desc(int cnt, int vsi_seid, int ring_id, int desc_n,
**/
static void i40e_dbg_dump_vsi_no_seid(struct i40e_pf *pf)
{
struct i40e_vsi *vsi;
int i;
for (i = 0; i < pf->num_alloc_vsi; i++)
if (pf->vsi[i])
dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n",
i, pf->vsi[i]->seid);
i40e_pf_for_each_vsi(pf, i, vsi)
dev_info(&pf->pdev->dev, "dump vsi[%d]: %d\n", i, vsi->seid);
}
/**
......@@ -718,11 +723,8 @@ static void i40e_dbg_dump_veb_all(struct i40e_pf *pf)
struct i40e_veb *veb;
int i;
for (i = 0; i < I40E_MAX_VEB; i++) {
veb = pf->veb[i];
if (veb)
i40e_dbg_dump_veb_seid(pf, veb->seid);
}
i40e_pf_for_each_veb(pf, i, veb)
i40e_dbg_dump_veb_seid(pf, veb->seid);
}
/**
......@@ -873,9 +875,10 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
goto command_write_done;
}
for (i = 0; i < I40E_MAX_VEB; i++)
if (pf->veb[i] && pf->veb[i]->seid == uplink_seid)
i40e_pf_for_each_veb(pf, i, veb)
if (veb->seid == uplink_seid)
break;
if (i >= I40E_MAX_VEB && uplink_seid != 0 &&
uplink_seid != pf->mac_seid) {
dev_info(&pf->pdev->dev,
......@@ -892,7 +895,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
dev_info(&pf->pdev->dev, "add relay failed\n");
} else if (strncmp(cmd_buf, "del relay", 9) == 0) {
struct i40e_veb *veb;
int i;
cnt = sscanf(&cmd_buf[9], "%i", &veb_seid);
if (cnt != 1) {
dev_info(&pf->pdev->dev,
......@@ -906,9 +911,10 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
}
/* find the veb */
for (i = 0; i < I40E_MAX_VEB; i++)
if (pf->veb[i] && pf->veb[i]->seid == veb_seid)
i40e_pf_for_each_veb(pf, i, veb)
if (veb->seid == veb_seid)
break;
if (i >= I40E_MAX_VEB) {
dev_info(&pf->pdev->dev,
"del relay: relay %d not found\n", veb_seid);
......@@ -916,7 +922,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
}
dev_info(&pf->pdev->dev, "deleting relay %d\n", veb_seid);
i40e_veb_release(pf->veb[i]);
i40e_veb_release(veb);
} else if (strncmp(cmd_buf, "add pvid", 8) == 0) {
unsigned int v;
int ret;
......@@ -1251,8 +1257,8 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
if (cnt == 0) {
int i;
for (i = 0; i < pf->num_alloc_vsi; i++)
i40e_vsi_reset_stats(pf->vsi[i]);
i40e_pf_for_each_vsi(pf, i, vsi)
i40e_vsi_reset_stats(vsi);
dev_info(&pf->pdev->dev, "vsi clear stats called for all vsi's\n");
} else if (cnt == 1) {
vsi = i40e_dbg_find_vsi(pf, vsi_seid);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment