提交 36197d82 编写于 作者: S Shannon Nelson 提交者: David S. Miller

ionic: replace set_vf data with union

This (ab)use of a data buffer made some static code checkers
rather itchy, so we replace the a generic data buffer with
the union in the struct ionic_vf_setattr_cmd.

Fixes: fbb39807 ("ionic: support sr-iov operations")
Signed-off-by: NShannon Nelson <snelson@pensando.io>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 ec8ee714
...@@ -109,8 +109,8 @@ void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) ...@@ -109,8 +109,8 @@ void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page)
static void ionic_vf_dealloc_locked(struct ionic *ionic) static void ionic_vf_dealloc_locked(struct ionic *ionic)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_STATSADDR };
struct ionic_vf *v; struct ionic_vf *v;
dma_addr_t dma = 0;
int i; int i;
if (!ionic->vfs) if (!ionic->vfs)
...@@ -120,9 +120,8 @@ static void ionic_vf_dealloc_locked(struct ionic *ionic) ...@@ -120,9 +120,8 @@ static void ionic_vf_dealloc_locked(struct ionic *ionic)
v = &ionic->vfs[i]; v = &ionic->vfs[i];
if (v->stats_pa) { if (v->stats_pa) {
(void)ionic_set_vf_config(ionic, i, vfc.stats_pa = 0;
IONIC_VF_ATTR_STATSADDR, (void)ionic_set_vf_config(ionic, i, &vfc);
(u8 *)&dma);
dma_unmap_single(ionic->dev, v->stats_pa, dma_unmap_single(ionic->dev, v->stats_pa,
sizeof(v->stats), DMA_FROM_DEVICE); sizeof(v->stats), DMA_FROM_DEVICE);
v->stats_pa = 0; v->stats_pa = 0;
...@@ -143,6 +142,7 @@ static void ionic_vf_dealloc(struct ionic *ionic) ...@@ -143,6 +142,7 @@ static void ionic_vf_dealloc(struct ionic *ionic)
static int ionic_vf_alloc(struct ionic *ionic, int num_vfs) static int ionic_vf_alloc(struct ionic *ionic, int num_vfs)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_STATSADDR };
struct ionic_vf *v; struct ionic_vf *v;
int err = 0; int err = 0;
int i; int i;
...@@ -166,9 +166,10 @@ static int ionic_vf_alloc(struct ionic *ionic, int num_vfs) ...@@ -166,9 +166,10 @@ static int ionic_vf_alloc(struct ionic *ionic, int num_vfs)
} }
ionic->num_vfs++; ionic->num_vfs++;
/* ignore failures from older FW, we just won't get stats */ /* ignore failures from older FW, we just won't get stats */
(void)ionic_set_vf_config(ionic, i, IONIC_VF_ATTR_STATSADDR, vfc.stats_pa = cpu_to_le64(v->stats_pa);
(u8 *)&v->stats_pa); (void)ionic_set_vf_config(ionic, i, &vfc);
} }
out: out:
......
...@@ -417,54 +417,17 @@ void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type) ...@@ -417,54 +417,17 @@ void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type)
} }
/* VF commands */ /* VF commands */
int ionic_set_vf_config(struct ionic *ionic, int vf, u8 attr, u8 *data) int ionic_set_vf_config(struct ionic *ionic, int vf,
struct ionic_vf_setattr_cmd *vfc)
{ {
union ionic_dev_cmd cmd = { union ionic_dev_cmd cmd = {
.vf_setattr.opcode = IONIC_CMD_VF_SETATTR, .vf_setattr.opcode = IONIC_CMD_VF_SETATTR,
.vf_setattr.attr = attr, .vf_setattr.attr = vfc->attr,
.vf_setattr.vf_index = cpu_to_le16(vf), .vf_setattr.vf_index = cpu_to_le16(vf),
}; };
int err; int err;
switch (attr) { memcpy(cmd.vf_setattr.pad, vfc->pad, sizeof(vfc->pad));
case IONIC_VF_ATTR_SPOOFCHK:
cmd.vf_setattr.spoofchk = *data;
dev_dbg(ionic->dev, "%s: vf %d spoof %d\n",
__func__, vf, *data);
break;
case IONIC_VF_ATTR_TRUST:
cmd.vf_setattr.trust = *data;
dev_dbg(ionic->dev, "%s: vf %d trust %d\n",
__func__, vf, *data);
break;
case IONIC_VF_ATTR_LINKSTATE:
cmd.vf_setattr.linkstate = *data;
dev_dbg(ionic->dev, "%s: vf %d linkstate %d\n",
__func__, vf, *data);
break;
case IONIC_VF_ATTR_MAC:
ether_addr_copy(cmd.vf_setattr.macaddr, data);
dev_dbg(ionic->dev, "%s: vf %d macaddr %pM\n",
__func__, vf, data);
break;
case IONIC_VF_ATTR_VLAN:
cmd.vf_setattr.vlanid = cpu_to_le16(*(u16 *)data);
dev_dbg(ionic->dev, "%s: vf %d vlan %d\n",
__func__, vf, *(u16 *)data);
break;
case IONIC_VF_ATTR_RATE:
cmd.vf_setattr.maxrate = cpu_to_le32(*(u32 *)data);
dev_dbg(ionic->dev, "%s: vf %d maxrate %d\n",
__func__, vf, *(u32 *)data);
break;
case IONIC_VF_ATTR_STATSADDR:
cmd.vf_setattr.stats_pa = cpu_to_le64(*(u64 *)data);
dev_dbg(ionic->dev, "%s: vf %d stats_pa 0x%08llx\n",
__func__, vf, *(u64 *)data);
break;
default:
return -EINVAL;
}
mutex_lock(&ionic->dev_cmd_lock); mutex_lock(&ionic->dev_cmd_lock);
ionic_dev_cmd_go(&ionic->idev, &cmd); ionic_dev_cmd_go(&ionic->idev, &cmd);
......
...@@ -318,7 +318,8 @@ void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, u8 an_enable); ...@@ -318,7 +318,8 @@ void ionic_dev_cmd_port_autoneg(struct ionic_dev *idev, u8 an_enable);
void ionic_dev_cmd_port_fec(struct ionic_dev *idev, u8 fec_type); void ionic_dev_cmd_port_fec(struct ionic_dev *idev, u8 fec_type);
void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type); void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type);
int ionic_set_vf_config(struct ionic *ionic, int vf, u8 attr, u8 *data); int ionic_set_vf_config(struct ionic *ionic, int vf,
struct ionic_vf_setattr_cmd *vfc);
int ionic_dev_cmd_vf_getattr(struct ionic *ionic, int vf, u8 attr, int ionic_dev_cmd_vf_getattr(struct ionic *ionic, int vf, u8 attr,
struct ionic_vf_getattr_comp *comp); struct ionic_vf_getattr_comp *comp);
void ionic_dev_cmd_queue_identify(struct ionic_dev *idev, void ionic_dev_cmd_queue_identify(struct ionic_dev *idev,
......
...@@ -2299,6 +2299,7 @@ static int ionic_get_vf_stats(struct net_device *netdev, int vf, ...@@ -2299,6 +2299,7 @@ static int ionic_get_vf_stats(struct net_device *netdev, int vf,
static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_MAC };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
int ret; int ret;
...@@ -2314,7 +2315,11 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) ...@@ -2314,7 +2315,11 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, IONIC_VF_ATTR_MAC, mac); ether_addr_copy(vfc.macaddr, mac);
dev_dbg(ionic->dev, "%s: vf %d macaddr %pM\n",
__func__, vf, vfc.macaddr);
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
ether_addr_copy(ionic->vfs[vf].macaddr, mac); ether_addr_copy(ionic->vfs[vf].macaddr, mac);
} }
...@@ -2326,6 +2331,7 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) ...@@ -2326,6 +2331,7 @@ static int ionic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
u8 qos, __be16 proto) u8 qos, __be16 proto)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_VLAN };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
int ret; int ret;
...@@ -2348,8 +2354,11 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, ...@@ -2348,8 +2354,11 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, vfc.vlanid = cpu_to_le16(vlan);
IONIC_VF_ATTR_VLAN, (u8 *)&vlan); dev_dbg(ionic->dev, "%s: vf %d vlan %d\n",
__func__, vf, le16_to_cpu(vfc.vlanid));
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
ionic->vfs[vf].vlanid = cpu_to_le16(vlan); ionic->vfs[vf].vlanid = cpu_to_le16(vlan);
} }
...@@ -2361,6 +2370,7 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, ...@@ -2361,6 +2370,7 @@ static int ionic_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
static int ionic_set_vf_rate(struct net_device *netdev, int vf, static int ionic_set_vf_rate(struct net_device *netdev, int vf,
int tx_min, int tx_max) int tx_min, int tx_max)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_RATE };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
int ret; int ret;
...@@ -2377,8 +2387,11 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf, ...@@ -2377,8 +2387,11 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf,
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, vfc.maxrate = cpu_to_le32(tx_max);
IONIC_VF_ATTR_RATE, (u8 *)&tx_max); dev_dbg(ionic->dev, "%s: vf %d maxrate %d\n",
__func__, vf, le32_to_cpu(vfc.maxrate));
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
lif->ionic->vfs[vf].maxrate = cpu_to_le32(tx_max); lif->ionic->vfs[vf].maxrate = cpu_to_le32(tx_max);
} }
...@@ -2389,9 +2402,9 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf, ...@@ -2389,9 +2402,9 @@ static int ionic_set_vf_rate(struct net_device *netdev, int vf,
static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set) static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_SPOOFCHK };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
u8 data = set; /* convert to u8 for config */
int ret; int ret;
if (!netif_device_present(netdev)) if (!netif_device_present(netdev))
...@@ -2402,10 +2415,13 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set) ...@@ -2402,10 +2415,13 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set)
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, vfc.spoofchk = set;
IONIC_VF_ATTR_SPOOFCHK, &data); dev_dbg(ionic->dev, "%s: vf %d spoof %d\n",
__func__, vf, vfc.spoofchk);
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
ionic->vfs[vf].spoofchk = data; ionic->vfs[vf].spoofchk = set;
} }
up_write(&ionic->vf_op_lock); up_write(&ionic->vf_op_lock);
...@@ -2414,9 +2430,9 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set) ...@@ -2414,9 +2430,9 @@ static int ionic_set_vf_spoofchk(struct net_device *netdev, int vf, bool set)
static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set) static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_TRUST };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
u8 data = set; /* convert to u8 for config */
int ret; int ret;
if (!netif_device_present(netdev)) if (!netif_device_present(netdev))
...@@ -2427,10 +2443,13 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set) ...@@ -2427,10 +2443,13 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set)
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, vfc.trust = set;
IONIC_VF_ATTR_TRUST, &data); dev_dbg(ionic->dev, "%s: vf %d trust %d\n",
__func__, vf, vfc.trust);
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
ionic->vfs[vf].trusted = data; ionic->vfs[vf].trusted = set;
} }
up_write(&ionic->vf_op_lock); up_write(&ionic->vf_op_lock);
...@@ -2439,20 +2458,21 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set) ...@@ -2439,20 +2458,21 @@ static int ionic_set_vf_trust(struct net_device *netdev, int vf, bool set)
static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set) static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set)
{ {
struct ionic_vf_setattr_cmd vfc = { .attr = IONIC_VF_ATTR_LINKSTATE };
struct ionic_lif *lif = netdev_priv(netdev); struct ionic_lif *lif = netdev_priv(netdev);
struct ionic *ionic = lif->ionic; struct ionic *ionic = lif->ionic;
u8 data; u8 vfls;
int ret; int ret;
switch (set) { switch (set) {
case IFLA_VF_LINK_STATE_ENABLE: case IFLA_VF_LINK_STATE_ENABLE:
data = IONIC_VF_LINK_STATUS_UP; vfls = IONIC_VF_LINK_STATUS_UP;
break; break;
case IFLA_VF_LINK_STATE_DISABLE: case IFLA_VF_LINK_STATE_DISABLE:
data = IONIC_VF_LINK_STATUS_DOWN; vfls = IONIC_VF_LINK_STATUS_DOWN;
break; break;
case IFLA_VF_LINK_STATE_AUTO: case IFLA_VF_LINK_STATE_AUTO:
data = IONIC_VF_LINK_STATUS_AUTO; vfls = IONIC_VF_LINK_STATUS_AUTO;
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -2466,8 +2486,11 @@ static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set) ...@@ -2466,8 +2486,11 @@ static int ionic_set_vf_link_state(struct net_device *netdev, int vf, int set)
if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) { if (vf >= pci_num_vf(ionic->pdev) || !ionic->vfs) {
ret = -EINVAL; ret = -EINVAL;
} else { } else {
ret = ionic_set_vf_config(ionic, vf, vfc.linkstate = vfls;
IONIC_VF_ATTR_LINKSTATE, &data); dev_dbg(ionic->dev, "%s: vf %d linkstate %d\n",
__func__, vf, vfc.linkstate);
ret = ionic_set_vf_config(ionic, vf, &vfc);
if (!ret) if (!ret)
ionic->vfs[vf].linkstate = set; ionic->vfs[vf].linkstate = set;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册