ionic: add sriov support
Subsystems (3)
v3 cover ionic: add sriov support
Set up the basic support for enabling SR-IOV devices in the ionic driver. Since most of the management work happens in the NIC firmware, the driver becomes mostly a pass-through for the network stack commands that want to control and configure the VFs.
v2: use pci_num_vf() and kcalloc()
remove checks for vf too big
add locking for the VF operations
disable VFs in ionic_remove() if they are still running
v3: added check in probe for pre-existing VFs
split out the alloc and dealloc of vf structs to better deal
with pre-existing VFs (left enabled on remove)
restored the checks for vf too big because of a potential
case where VFs are already enabled but driver failed to alloc the vf structs
Shannon Nelson (2):
ionic: ionic_if bits for sr-iov support
ionic: support sr-iov operations
drivers/net/ethernet/pensando/ionic/ionic.h | 17 +- .../ethernet/pensando/ionic/ionic_bus_pci.c | 101 ++++++++ .../net/ethernet/pensando/ionic/ionic_dev.c | 58 +++++ .../net/ethernet/pensando/ionic/ionic_dev.h | 7 + .../net/ethernet/pensando/ionic/ionic_if.h | 97 ++++++++ .../net/ethernet/pensando/ionic/ionic_lif.c | 222 +++++++++++++++++- .../net/ethernet/pensando/ionic/ionic_lif.h | 6 + .../net/ethernet/pensando/ionic/ionic_main.c | 4 + 8 files changed, 504 insertions(+), 8 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/2 ionic: ionic_if bits for sr-iov support
Adds new AdminQ calls and their related structs for supporting PF controls on VFs:
CMD_OPCODE_VF_GETATTR CMD_OPCODE_VF_SETATTR
--- .../net/ethernet/pensando/ionic/ionic_if.h | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_if.h +97 -0
@@ -51,6 +51,10 @@ enum ionic_cmd_opcode {IONIC_CMD_RDMA_CREATE_CQ =52 ,IONIC_CMD_RDMA_CREATE_ADMINQ =53 , +/* SR/IOV commands */ +IONIC_CMD_VF_GETATTR =60 , +IONIC_CMD_VF_SETATTR =61 , +/* QoS commands */ IONIC_CMD_QOS_CLASS_IDENTIFY =240 , IONIC_CMD_QOS_CLASS_INIT = 241,
@@ -1639,6 +1643,93 @@ enum ionic_qos_sched_type { IONIC_QOS_SCHED_TYPE_DWRR = 1, /* Deficit weighted round-robin */ }; +enum ionic_vf_attr { +IONIC_VF_ATTR_SPOOFCHK =1 , +IONIC_VF_ATTR_TRUST =2 , +IONIC_VF_ATTR_MAC =3 , +IONIC_VF_ATTR_LINKSTATE =4 , +IONIC_VF_ATTR_VLAN =5 , +IONIC_VF_ATTR_RATE =6 , +IONIC_VF_ATTR_STATSADDR =7 , +}; + +/** +* VF link status +*/ +enum ionic_vf_link_status { +IONIC_VF_LINK_STATUS_AUTO =0 ,/* link state of the uplink */ +IONIC_VF_LINK_STATUS_UP =1 ,/* link is always up */ +IONIC_VF_LINK_STATUS_DOWN =2 ,/* link is always down */ +}; + +/** +* struct ionic_vf_setattr_cmd - Set VF attributes on the NIC +* @opcode: Opcode +* @index: VF index +* @attr: Attribute type (enum ionic_vf_attr) +* macaddr mac address +* vlanid vlan ID +* maxrate max Tx rate in Mbps +* spoofchk enable address spoof checking +* trust enable VF trust +* linkstate set link up or down +* stats_pa set DMA address for VF stats +*/ +struct ionic_vf_setattr_cmd { +u8 opcode; +u8 attr; +__le16 vf_index; +union { +u8 macaddr[6 ]; +__le16 vlanid; +__le32 maxrate; +u8 spoofchk; +u8 trust; +u8 linkstate; +__le64 stats_pa; +u8 pad[60 ]; + }; +}; + +struct ionic_vf_setattr_comp { +u8 status; +u8 attr; +__le16 vf_index; +__le16 comp_index; +u8 rsvd[9 ]; +u8 color; +}; + +/** +* struct ionic_vf_getattr_cmd - Get VF attributes from the NIC +* @opcode: Opcode +* @index: VF index +* @attr: Attribute type (enum ionic_vf_attr) +*/ +struct ionic_vf_getattr_cmd { +u8 opcode; +u8 attr; +__le16 vf_index; +u8 rsvd[60 ]; +}; + +struct ionic_vf_getattr_comp { +u8 status; +u8 attr; +__le16 vf_index; +union { +u8 macaddr[6 ]; +__le16 vlanid; +__le32 maxrate; +u8 spoofchk; +u8 trust; +u8 linkstate; +__le64 stats_pa; +u8 pad[11 ]; + }; +u8 color; +}; +/** * union ionic_qos_config - Qos configuration structure * @flags: Configuration flags
@@ -2289,6 +2380,9 @@ union ionic_dev_cmd {struct ionic_port_getattr_cmd port_getattr;struct ionic_port_setattr_cmd port_setattr; +struct ionic_vf_setattr_cmd vf_setattr; +struct ionic_vf_getattr_cmd vf_getattr; +struct ionic_lif_identify_cmd lif_identify;struct ionic_lif_init_cmd lif_init;struct ionic_lif_reset_cmd lif_reset;
@@ -2318,6 +2412,9 @@ union ionic_dev_cmd_comp {struct ionic_port_getattr_comp port_getattr;struct ionic_port_setattr_comp port_setattr; +struct ionic_vf_setattr_comp vf_setattr; +struct ionic_vf_getattr_comp vf_getattr; +struct ionic_lif_identify_comp lif_identify;struct ionic_lif_init_comp lif_init;ionic_lif_reset_comp lif_reset;
Signature · 1 line
2.17.1
PATCH v3 2/2 ionic: support sr-iov operations
In reply to Shannon NelsonAdd the netdev ops for managing VFs. Since most of the management work happens in the NIC firmware, the driver becomes mostly a pass-through for the network stack commands that want to control and configure the VFs.
We also tweak ionic_station_set() a little to allow for the VFs that start off with a zero'd mac address.
--- drivers/net/ethernet/pensando/ionic/ionic.h | 17 +- .../ethernet/pensando/ionic/ionic_bus_pci.c | 101 ++++++++ .../net/ethernet/pensando/ionic/ionic_dev.c | 58 +++++ .../net/ethernet/pensando/ionic/ionic_dev.h | 7 + .../net/ethernet/pensando/ionic/ionic_lif.c | 222 +++++++++++++++++- .../net/ethernet/pensando/ionic/ionic_main.c | 4 + 6 files changed, 401 insertions(+), 8 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic.h +16 -1
@@ -12,7 +12,7 @@ struct ionic_lif;#define IONIC_DRV_NAME "ionic"#define IONIC_DRV_DESCRIPTION "Pensando Ethernet NIC Driver" -#define IONIC_DRV_VERSION "0.18.0-k" +#define IONIC_DRV_VERSION "0.20.0-k"#define PCI_VENDOR_ID_PENSANDO 0x1dd8
@@ -25,12 +25,25 @@ struct ionic_lif;#define DEVCMD_TIMEOUT 10 +struct ionic_vf { +u16 index; +u8 macaddr[6 ]; +__le32 maxrate; +__le16 vlanid; +u8 spoofchk; +u8 trusted; +u8 linkstate; +dma_addr_t stats_pa; +struct ionic_lif_stats stats; +}; +struct ionic {struct pci_dev *pdev;struct device *dev;struct devlink_port dl_port;struct ionic_dev idev;struct mutex dev_cmd_lock;/* lock for dev_cmd operations */ +struct rw_semaphore vf_op_lock;/* lock for VF operations */ struct dentry *dentry;struct ionic_dev_bar bars[IONIC_BARS_MAX ];unsigned int num_bars;
@@ -46,6 +59,8 @@ struct ionic {DECLARE_BITMAP (intrs,IONIC_INTR_CTRL_REGS_MAX );struct work_struct nb_work;struct notifier_block nb; +unsigned int num_vfs; +struct ionic_vf **vf;struct timer_list watchdog_timer;int watchdog_period; };
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +101 -0
129 lines not on this page · raw message
drivers/net/ethernet/pensando/ionic/ionic_dev.c +58 -0
64 lines not on this page · raw message
drivers/net/ethernet/pensando/ionic/ionic_dev.h +7 -0
@@ -113,6 +113,12 @@ static_assert(sizeof(struct ionic_rxq_desc) == 16);static_assert (sizeof (struct ionic_rxq_sg_desc ) ==128 );static_assert (sizeof (struct ionic_rxq_comp ) ==16 ); +/* SR/IOV */ +static_assert (sizeof (struct ionic_vf_setattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_setattr_comp ) ==16 ); +static_assert (sizeof (struct ionic_vf_getattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_getattr_comp ) ==16 ); +struct ionic_devinfo {u8 asic_type;u8 asic_rev;
@@ -275,6 +281,7 @@ 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_pause (struct ionic_dev *idev,u8 pause_type); +int ionic_set_vf_config (struct ionic *ionic,int vf,u8 attr,u8 *data);void ionic_dev_cmd_lif_identify (struct ionic_dev *idev,u8 type,u8 ver);void ionic_dev_cmd_lif_init (struct ionic_dev *idev,u16 lif_index,dma_addr_t addr);
drivers/net/ethernet/pensando/ionic/ionic_lif.c +215 -7
245 lines not on this page · raw message
drivers/net/ethernet/pensando/ionic/ionic_main.c +4 -0
@@ -165,6 +165,10 @@ static const char *ionic_opcode_to_str(enum ionic_cmd_opcode opcode)return "IONIC_CMD_FW_DOWNLOAD" ;case IONIC_CMD_FW_CONTROL :return "IONIC_CMD_FW_CONTROL" ; +case IONIC_CMD_VF_GETATTR : +return "IONIC_CMD_VF_GETATTR" ; +case IONIC_CMD_VF_SETATTR : +return "IONIC_CMD_VF_SETATTR" ;default :return "DEVCMD_UNKNOWN" ; }
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 2/2] ionic: support sr-iov operations
Quoted 44 lines · Shannon Nelson
Add the netdev ops for managing VFs. Since most of the management work happens in the NIC firmware, the driver becomes mostly a pass-through for the network stack commands that want to control and configure the VFs.
We also tweak
ionic_station_set()a little to allow for the VFs that start off with a zero'd mac address.Signed-off-by Shannon Nelson <[email protected]>--- drivers/net/ethernet/pensando/ionic/ionic.h | 17 +- .../ethernet/pensando/ionic/ionic_bus_pci.c | 101 ++++++++ .../net/ethernet/pensando/ionic/ionic_dev.c | 58 +++++ .../net/ethernet/pensando/ionic/ionic_dev.h | 7 + .../net/ethernet/pensando/ionic/ionic_lif.c | 222 +++++++++++++++++- .../net/ethernet/pensando/ionic/ionic_main.c | 4 + 6 files changed, 401 insertions(+), 8 deletions(-)drivers/net/ethernet/pensando/ionic/ionic.h +10
-1@@ -12,7 +12,7 @@ struct ionic_lif;#define IONIC_DRV_NAME "ionic"#define IONIC_DRV_DESCRIPTION "Pensando Ethernet NIC Driver" -#define IONIC_DRV_VERSION "0.18.0-k" +#define IONIC_DRV_VERSION "0.20.0-k"#define PCI_VENDOR_ID_PENSANDO 0x1dd8@@ -25,12 +25,25 @@ struct ionic_lif;#define DEVCMD_TIMEOUT 10 +struct ionic_vf { +u16 index; +u8 macaddr[6 ]; +__le32 maxrate; +__le16 vlanid; +u8 spoofchk; +u8 trusted; +u8 linkstate; +dma_addr_t stats_pa;
drivers/net/ethernet/pensando/ionic/ionic.h struct ionic_lif; · line 46
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic.h +4
-0+struct ionic_lif_stats stats; +}; +struct ionic {struct pci_dev *pdev;struct device *dev;struct devlink_port dl_port;struct ionic_dev idev;struct mutex dev_cmd_lock;/* lock for dev_cmd operations */ +struct rw_semaphore vf_op_lock;/* lock for VF operations */
It is better to place this semaphore adjucent to other related VF fields you have below as they are all used together.
drivers/net/ethernet/pensando/ionic/ionic.h struct ionic { · line 62
Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic.h +1
-0struct dentry *dentry;struct ionic_dev_bar bars[IONIC_BARS_MAX ];unsigned int num_bars;@@ -46,6 +59,8 @@ struct ionic {DECLARE_BITMAP (intrs,IONIC_INTR_CTRL_REGS_MAX );struct work_struct nb_work;struct notifier_block nb; +unsigned int num_vfs;
If you intent to store this, store is as 'int' because that is what is coming from sriov_configure() at the moment.
But it sholdn't be stored. More below.
Quoted 9 lines
drivers/net/ethernet/pensando/ionic/ionic.h +1
-0+struct ionic_vf **vf;struct timer_list watchdog_timer;int watchdog_period; };drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0
-0
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 112
Quoted 9 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +6
-0@@ -104,10 +104,101 @@ void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page)iounmap (page); } +static void ionic_vf_dealloc (struct ionic *ionic) +{ +struct ionic_vf *v; +int i; + +for (i = ionic->num_vfs -1 ; i >=0 ; i--) {
Here you are checking for >= 0, so it must be 'int'.
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +7
-0+ v = ionic->vf[i]; +dma_unmap_single (ionic->dev, v->stats_pa, +sizeof (v->stats),DMA_FROM_DEVICE ); +kfree (v); + ionic->vf[i] =NULL ; + } +
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 129
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +10
-0+ ionic->num_vfs =0 ; +kfree (ionic->vf); + ionic->vf =NULL ; +} + +static int ionic_vf_alloc (struct ionic *ionic,int num_vfs) +{ +struct ionic_vf *v; +int err, i; +
int err;
int i;
Quoted 48 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +48
-0+ ionic->vf =kcalloc (num_vfs,sizeof (struct ionic_vf *),GFP_KERNEL ); +if (!ionic->vf) +return -ENOMEM ; + +for (i =0 ; i < num_vfs; i++) { + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) { + err = -ENOMEM ; + goto err_out; + } + + v->stats_pa =dma_map_single (ionic->dev, &v->stats, +sizeof (v->stats),DMA_FROM_DEVICE ); +if (dma_mapping_error (ionic->dev, v->stats_pa)) { + err = -ENODEV ; +kfree (v); + ionic->vf[i] =NULL ; + goto err_out; + } + + ionic->vf[i] = v; + ionic->num_vfs++; + } + +return 0 ; + +err_out: +ionic_vf_dealloc (ionic); +return err; +} + +static int ionic_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +struct ionic *ionic =pci_get_drvdata (pdev); +struct device *dev = ionic->dev; +int ret =0 ; + +down_write (&ionic->vf_op_lock); + +if (num_vfs >0 ) { + ret =pci_enable_sriov (pdev, num_vfs); +if (ret) { +dev_err (dev,"Cannot enable SRIOV: %d\n" , ret); + goto out; + } + + ret =ionic_vf_alloc (ionic, num_vfs); +if (ret) {
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 187
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +10
-0+dev_err (dev,"Cannot alloc VFs: %d\n" , ret); +pci_disable_sriov (pdev); + goto out; + } + + ret = num_vfs; + goto out; + } + +if (num_vfs ==0 ) {
It should be the else of num_vfs > 0.
Quoted 18 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +10
-0+pci_disable_sriov (pdev); +ionic_vf_dealloc (ionic); + } + +out: +up_write (&ionic->vf_op_lock); +return ret; +} +static int ionic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {struct device *dev = &pdev->dev;struct ionic *ionic; +int num_vfs;int err; ionic =ionic_devlink_alloc (dev);
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 213
Quoted 5 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1
-0@@ -118,6 +209,7 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ionic->dev = dev;pci_set_drvdata (pdev, ionic);mutex_init (&ionic->dev_cmd_lock); +init_rwsem (&ionic->vf_op_lock);
Better to initialize below before reading num_vfs, so all VF config code is adjcent to each other.
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1
-0/* Query system for DMA addressing limitation for the device. */ err =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (IONIC_ADDR_LEN ));@@ -206,6 +298,14 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_out_free_lifs; } + num_vfs =pci_num_vf (pdev);
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 311
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +7
-0+if (num_vfs) { +dev_info (dev,"%d VFs found already enabled\n" , num_vfs); + err =ionic_vf_alloc (ionic, num_vfs); +if (err) +dev_err (dev,"Cannot enable existing VFs: %d\n" , err); + } + err =ionic_lifs_register (ionic);if (err) {dev_err (dev,"Cannot register LIFs: %d, aborting\n" , err);
There should be error unwinding to perform vf_dealloc() where lifs_register or other functions fail in the probe sequence. Otherwise its memory leak bug.
Quoted 109 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1
-0@@ -279,6 +379,7 @@ static struct pci_driver ionic_driver = { .id_table = ionic_id_table, .probe = ionic_probe, .remove = ionic_remove, + .sriov_configure = ionic_sriov_configure, };int ionic_bus_register_driver (void )drivers/net/ethernet/pensando/ionic/ionic_dev.c +58
-0@@ -286,6 +286,64 @@ void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type)ionic_dev_cmd_go (idev, &cmd); } +/* VF commands */ +int ionic_set_vf_config (struct ionic *ionic,int vf,u8 attr,u8 *data) +{ +union ionic_dev_cmd cmd = { + .vf_setattr.opcode =IONIC_CMD_VF_SETATTR , + .vf_setattr.attr = attr, + .vf_setattr.vf_index = vf, + }; +int err; + +switch (attr) { +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); +ionic_dev_cmd_go (&ionic->idev, &cmd); + err =ionic_dev_cmd_wait (ionic,DEVCMD_TIMEOUT ); +mutex_unlock (&ionic->dev_cmd_lock); + +return err; +} +/* LIF commands */ void ionic_dev_cmd_lif_identify (struct ionic_dev *idev,u8 type,u8 ver) {drivers/net/ethernet/pensando/ionic/ionic_dev.h +7
-0@@ -113,6 +113,12 @@ static_assert(sizeof(struct ionic_rxq_desc) == 16);static_assert (sizeof (struct ionic_rxq_sg_desc ) ==128 );static_assert (sizeof (struct ionic_rxq_comp ) ==16 ); +/* SR/IOV */ +static_assert (sizeof (struct ionic_vf_setattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_setattr_comp ) ==16 ); +static_assert (sizeof (struct ionic_vf_getattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_getattr_comp ) ==16 ); +struct ionic_devinfo {u8 asic_type;u8 asic_rev;@@ -275,6 +281,7 @@ 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_pause (struct ionic_dev *idev,u8 pause_type); +int ionic_set_vf_config (struct ionic *ionic,int vf,u8 attr,u8 *data);void ionic_dev_cmd_lif_identify (struct ionic_dev *idev,u8 type,u8 ver);void ionic_dev_cmd_lif_init (struct ionic_dev *idev,u16 lif_index,dma_addr_t addr);drivers/net/ethernet/pensando/ionic/ionic_lif.c +0
-0@@ -1616,6 +1616,202 @@ int ionic_stop(struct net_device *netdev)return err; }
drivers/net/ethernet/pensando/ionic/ionic_lif.c int ionic_stop(struct net_device *netdev) · line 1627
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_lif.c +9
-0+static int ionic_get_vf_config (struct net_device *netdev, +int vf,struct ifla_vf_info *ivf) +{ +struct ionic_lif *lif =netdev_priv (netdev); +struct ionic *ionic = lif->ionic; + +if (vf >= ionic->num_vfs) +return -EINVAL ; +
Move this check as below after vf_op_lock as
if (vf >= pci_num_vfs(pci_dev)
return -EINVAL;
Similarly for other friends function below.
Re: [PATCH v3 net-next 2/2] ionic: support sr-iov operations
Quoted 49 lines · Parav Pandit
Quoted 48 lines · Shannon Nelson
Add the netdev ops for managing VFs. Since most of the management work happens in the NIC firmware, the driver becomes mostly a pass-through for the network stack commands that want to control and configure the VFs.
We also tweak
ionic_station_set()a little to allow for the VFs that start off with a zero'd mac address.Signed-off-by Shannon Nelson <[email protected]>--- drivers/net/ethernet/pensando/ionic/ionic.h | 17 +- .../ethernet/pensando/ionic/ionic_bus_pci.c | 101 ++++++++ .../net/ethernet/pensando/ionic/ionic_dev.c | 58 +++++ .../net/ethernet/pensando/ionic/ionic_dev.h | 7 + .../net/ethernet/pensando/ionic/ionic_lif.c | 222 +++++++++++++++++- .../net/ethernet/pensando/ionic/ionic_main.c | 4 + 6 files changed, 401 insertions(+), 8 deletions(-)drivers/net/ethernet/pensando/ionic/ionic.h +13
-1@@ -12,7 +12,7 @@ struct ionic_lif;#define IONIC_DRV_NAME "ionic"#define IONIC_DRV_DESCRIPTION "Pensando Ethernet NIC Driver" -#define IONIC_DRV_VERSION "0.18.0-k" +#define IONIC_DRV_VERSION "0.20.0-k"#define PCI_VENDOR_ID_PENSANDO 0x1dd8@@ -25,12 +25,25 @@ struct ionic_lif;#define DEVCMD_TIMEOUT 10 +struct ionic_vf { +u16 index; +u8 macaddr[6 ]; +__le32 maxrate; +__le16 vlanid; +u8 spoofchk; +u8 trusted; +u8 linkstate; +dma_addr_t stats_pa; +struct ionic_lif_stats stats; +}; +struct ionic {
Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic.h struct ionic_lif; · line 46
Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic.h +1
-0struct pci_dev *pdev;struct device *dev;struct devlink_port dl_port;struct ionic_dev idev;struct mutex dev_cmd_lock;/* lock for dev_cmd operations */ +struct rw_semaphore vf_op_lock;/* lock for VF operations */ It is better to place this semaphore adjucent to other related VF fields you have below as they are all used together.
Sure
Quoted 11 lines
drivers/net/ethernet/pensando/ionic/ionic.h struct ionic { · line 62
Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic.h +1
-0struct dentry *dentry;struct ionic_dev_bar bars[IONIC_BARS_MAX ];unsigned int num_bars;@@ -46,6 +59,8 @@ struct ionic {DECLARE_BITMAP (intrs,IONIC_INTR_CTRL_REGS_MAX );struct work_struct nb_work;struct notifier_block nb; +unsigned int num_vfs;If you intent to store this, store is as 'int' because that is what is coming from
sriov_configure()at the moment.
But it sholdn't be stored. More below.
I've worked out a way that we can both be happy - thanks.
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/pensando/ionic/ionic.h +1
-0+struct ionic_vf **vf;struct timer_list watchdog_timer;int watchdog_period; };drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0
-0@@ -104,10 +104,101 @@ void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page)iounmap (page); }
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 112
Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +6
-0+static void ionic_vf_dealloc (struct ionic *ionic) +{ +struct ionic_vf *v; +int i; + +for (i = ionic->num_vfs -1 ; i >=0 ; i--) {Here you are checking for >= 0, so it must be 'int'.
Yep
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +11
-0+ v = ionic->vf[i]; +dma_unmap_single (ionic->dev, v->stats_pa, +sizeof (v->stats),DMA_FROM_DEVICE ); +kfree (v); + ionic->vf[i] =NULL ; + } + + ionic->num_vfs =0 ; +kfree (ionic->vf); + ionic->vf =NULL ; +}
Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 129
Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +6
-0+ +static int ionic_vf_alloc (struct ionic *ionic,int num_vfs) +{ +struct ionic_vf *v; +int err, i; +int err;
int i;
Sure
Quoted 52 lines
Quoted 52 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +51
-0+ ionic->vf =kcalloc (num_vfs,sizeof (struct ionic_vf *),GFP_KERNEL ); +if (!ionic->vf) +return -ENOMEM ; + +for (i =0 ; i < num_vfs; i++) { + v =kzalloc (sizeof (*v),GFP_KERNEL ); +if (!v) { + err = -ENOMEM ; + goto err_out; + } + + v->stats_pa =dma_map_single (ionic->dev, &v->stats, +sizeof (v->stats),DMA_FROM_DEVICE ); +if (dma_mapping_error (ionic->dev, v->stats_pa)) { + err = -ENODEV ; +kfree (v); + ionic->vf[i] =NULL ; + goto err_out; + } + + ionic->vf[i] = v; + ionic->num_vfs++; + } + +return 0 ; + +err_out: +ionic_vf_dealloc (ionic); +return err; +} + +static int ionic_sriov_configure (struct pci_dev *pdev,int num_vfs) +{ +struct ionic *ionic =pci_get_drvdata (pdev); +struct device *dev = ionic->dev; +int ret =0 ; + +down_write (&ionic->vf_op_lock); + +if (num_vfs >0 ) { + ret =pci_enable_sriov (pdev, num_vfs); +if (ret) { +dev_err (dev,"Cannot enable SRIOV: %d\n" , ret); + goto out; + } + + ret =ionic_vf_alloc (ionic, num_vfs); +if (ret) { +dev_err (dev,"Cannot alloc VFs: %d\n" , ret); +pci_disable_sriov (pdev); + goto out;
Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c void ionic_bus_unmap_dbpage(struct ionic *ionic, void __iomem *page) · line 187
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +7
-0+ } + + ret = num_vfs; + goto out; + } + +if (num_vfs ==0 ) {It should be the else of
num_vfs> 0.
Done
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +10
-0+pci_disable_sriov (pdev); +ionic_vf_dealloc (ionic); + } + +out: +up_write (&ionic->vf_op_lock); +return ret; +} +static int ionic_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {struct device *dev = &pdev->dev;struct ionic *ionic; +int num_vfs;int err;
Quoted 9 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 213
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1
-0ionic =ionic_devlink_alloc (dev);@@ -118,6 +209,7 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ionic->dev = dev;pci_set_drvdata (pdev, ionic);mutex_init (&ionic->dev_cmd_lock); +init_rwsem (&ionic->vf_op_lock);Better to initialize below before reading
num_vfs, so all VF config code is adjcent to each other.
I normally like to prep my locks early, but fine.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +0
-0/* Query system for DMA addressing limitation for the device. */ err =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (IONIC_ADDR_LEN ));@@ -206,6 +298,14 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_out_free_lifs; }
Quoted 14 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 311
Quoted 11 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +8
-0+ num_vfs =pci_num_vf (pdev); +if (num_vfs) { +dev_info (dev,"%d VFs found already enabled\n" , num_vfs); + err =ionic_vf_alloc (ionic, num_vfs); +if (err) +dev_err (dev,"Cannot enable existing VFs: %d\n" , err); + } + err =ionic_lifs_register (ionic);if (err) {dev_err (dev,"Cannot register LIFs: %d, aborting\n" , err);There should be error unwinding to perform
vf_dealloc()wherelifs_registeror other functions fail in the probe sequence. Otherwise its memory leak bug.
Yep
Quoted 122 lines
Quoted 110 lines
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c +1
-0@@ -279,6 +379,7 @@ static struct pci_driver ionic_driver = { .id_table = ionic_id_table, .probe = ionic_probe, .remove = ionic_remove, + .sriov_configure = ionic_sriov_configure, };int ionic_bus_register_driver (void )drivers/net/ethernet/pensando/ionic/ionic_dev.c +58
-0@@ -286,6 +286,64 @@ void ionic_dev_cmd_port_pause(struct ionic_dev *idev, u8 pause_type)ionic_dev_cmd_go (idev, &cmd); } +/* VF commands */ +int ionic_set_vf_config (struct ionic *ionic,int vf,u8 attr,u8 *data) +{ +union ionic_dev_cmd cmd = { + .vf_setattr.opcode =IONIC_CMD_VF_SETATTR , + .vf_setattr.attr = attr, + .vf_setattr.vf_index = vf, + }; +int err; + +switch (attr) { +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); +ionic_dev_cmd_go (&ionic->idev, &cmd); + err =ionic_dev_cmd_wait (ionic,DEVCMD_TIMEOUT ); +mutex_unlock (&ionic->dev_cmd_lock); + +return err; +} +/* LIF commands */ void ionic_dev_cmd_lif_identify (struct ionic_dev *idev,u8 type,u8 ver) {drivers/net/ethernet/pensando/ionic/ionic_dev.h +7
-0@@ -113,6 +113,12 @@ static_assert(sizeof(struct ionic_rxq_desc) == 16);static_assert (sizeof (struct ionic_rxq_sg_desc ) ==128 );static_assert (sizeof (struct ionic_rxq_comp ) ==16 ); +/* SR/IOV */ +static_assert (sizeof (struct ionic_vf_setattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_setattr_comp ) ==16 ); +static_assert (sizeof (struct ionic_vf_getattr_cmd ) ==64 ); +static_assert (sizeof (struct ionic_vf_getattr_comp ) ==16 ); +struct ionic_devinfo {u8 asic_type;u8 asic_rev;@@ -275,6 +281,7 @@ 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_pause (struct ionic_dev *idev,u8 pause_type); +int ionic_set_vf_config (struct ionic *ionic,int vf,u8 attr,u8 *data);void ionic_dev_cmd_lif_identify (struct ionic_dev *idev,u8 type,u8 ver);void ionic_dev_cmd_lif_init (struct ionic_dev *idev,u16 lif_index,dma_addr_t addr);drivers/net/ethernet/pensando/ionic/ionic_lif.c +0
-0@@ -1616,6 +1616,202 @@ int ionic_stop(struct net_device *netdev)return err; }drivers/net/ethernet/pensando/ionic/ionic_lif.c int ionic_stop(struct net_device *netdev) · line 1627
Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_lif.c +9
-0+static int ionic_get_vf_config (struct net_device *netdev, +int vf,struct ifla_vf_info *ivf) +{ +struct ionic_lif *lif =netdev_priv (netdev); +struct ionic *ionic = lif->ionic; + +if (vf >= ionic->num_vfs) +return -EINVAL ; +Move this check as below after
vf_op_lockas
Quoted 4 lines
if (vf >=
pci_num_vfs(pci_dev)return -EINVAL;Similarly for other friends function below.
Done.
Thanks for your time, now that the holidays are over I'll have an updated patch out soon.
sln