[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <06e51df6-1da1-97fd-0765-a0efbece45c5@mellanox.com>
Date: Tue, 10 Dec 2019 23:25:43 +0000
From: Parav Pandit <parav@...lanox.com>
To: Shannon Nelson <snelson@...sando.io>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"davem@...emloft.net" <davem@...emloft.net>
Subject: Re: [PATCH net-next 2/2] ionic: support sr-iov operations
On 12/10/2019 4:54 PM, Shannon Nelson wrote:
> 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 <snelson@...sando.io>
> ---
> drivers/net/ethernet/pensando/ionic/ionic.h | 16 +-
> .../ethernet/pensando/ionic/ionic_bus_pci.c | 75 +++++++
> .../net/ethernet/pensando/ionic/ionic_dev.c | 61 ++++++
> .../net/ethernet/pensando/ionic/ionic_dev.h | 7 +
> .../net/ethernet/pensando/ionic/ionic_lif.c | 188 +++++++++++++++++-
> .../net/ethernet/pensando/ionic/ionic_lif.h | 6 +
> .../net/ethernet/pensando/ionic/ionic_main.c | 4 +
> 7 files changed, 349 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic.h b/drivers/net/ethernet/pensando/ionic/ionic.h
> index 98e102af7756..d4cf58da8d13 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic.h
> +++ b/drivers/net/ethernet/pensando/ionic/ionic.h
> @@ -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,6 +25,18 @@ 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;
> @@ -46,6 +58,8 @@ struct ionic {
> DECLARE_BITMAP(intrs, IONIC_INTR_CTRL_REGS_MAX);
> struct work_struct nb_work;
> struct notifier_block nb;
> + int num_vfs;
Please drop num_vfs and use pci_num_vf() in ionic_get_vf_config() and
other friend functions.
> + struct ionic_vf **vf;
> struct timer_list watchdog_timer;
> int watchdog_period;
> };
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
> index 9a9ab8cb2cb3..fe4efe12b50b 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
> @@ -274,11 +274,86 @@ static void ionic_remove(struct pci_dev *pdev)
> ionic_devlink_free(ionic);
> }
>
> +static int ionic_sriov_configure(struct pci_dev *pdev, int num_vfs)
> +{
> + struct ionic *ionic = pci_get_drvdata(pdev);
> + struct device *dev = ionic->dev;
> + unsigned int size;
> + int i, err = 0;
> +
> + if (!ionic_is_pf(ionic))
> + return -ENODEV;
> +
This check is already done by pci core kernel. No need for ionic driver
to do this. If SR-IOV capability is not enabled, it won't reach here.
> + if (num_vfs > 0) {
> + err = pci_enable_sriov(pdev, num_vfs);
> + if (err) {
> + dev_err(&pdev->dev, "Cannot enable SRIOV: %d\n", err);
> + return err;
> + }
> +
> + size = sizeof(struct ionic_vf *) * num_vfs;
> + ionic->vf = kzalloc(size, GFP_KERNEL);
Please use kcalloc()
> + if (!ionic->vf) {
> + pci_disable_sriov(pdev);
> + return -ENOMEM;
> + }
> +
> + for (i = 0; i < num_vfs; i++) {
> + struct ionic_vf *v;
> +
> + v = kzalloc(sizeof(*v), GFP_KERNEL);
> + if (!v) {
> + err = -ENOMEM;
> + num_vfs = 0;
> + goto remove_vfs;
> + }
> +
> + v->stats_pa = dma_map_single(dev, &v->stats,
> + sizeof(v->stats),
> + DMA_FROM_DEVICE);
> + if (dma_mapping_error(dev, v->stats_pa)) {
> + err = -ENODEV;
> + kfree(v);
> + ionic->vf[i] = NULL;
> + num_vfs = 0;
> + goto remove_vfs;
> + }
> +
> + ionic->vf[i] = v;
> + ionic->num_vfs++;
> + }
> +
> + return num_vfs;
> + }
> +
> +remove_vfs:
> + if (num_vfs == 0) {
> + if (err)
> + dev_err(&pdev->dev, "SRIOV setup failed: %d\n", err);
> +
> + pci_disable_sriov(pdev);
> +
> + for (i = 0; i < ionic->num_vfs; i++) {
> + dma_unmap_single(dev, ionic->vf[i]->stats_pa,
> + sizeof(struct ionic_lif_stats),
> + DMA_FROM_DEVICE);
> + kfree(ionic->vf[i]);
> + }
> +
> + kfree(ionic->vf);
> + ionic->vf = NULL;
> + ionic->num_vfs = 0;
> + }
> +
> + return err;
> +}
> +
> static struct pci_driver ionic_driver = {
> .name = IONIC_DRV_NAME,
> .id_table = ionic_id_table,
> .probe = ionic_probe,
> .remove = ionic_remove,
> + .sriov_configure = ionic_sriov_configure,
> };
Powered by blists - more mailing lists