[net-next,7/9] octeon_ep: add SRIOV VF creation

Message ID 20221107072524.9485-8-vburru@marvell.com
State New
Headers
Series octeon_ep: Update PF mailbox for VF |

Commit Message

Veerasenareddy Burru Nov. 7, 2022, 7:25 a.m. UTC
  Add support to create SRIOV VFs.

Signed-off-by: Veerasenareddy Burru <vburru@marvell.com>
Signed-off-by: Sathesh Edara <sedara@marvell.com>
---
 .../ethernet/marvell/octeon_ep/octep_main.c   | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
  

Comments

Leon Romanovsky Nov. 7, 2022, 8:13 a.m. UTC | #1
On Sun, Nov 06, 2022 at 11:25:21PM -0800, Veerasenareddy Burru wrote:
> Add support to create SRIOV VFs.
> 
> Signed-off-by: Veerasenareddy Burru <vburru@marvell.com>
> Signed-off-by: Sathesh Edara <sedara@marvell.com>
> ---
>  .../ethernet/marvell/octeon_ep/octep_main.c   | 50 +++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index ad5553854467..fa0f3d597eb1 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -1236,11 +1236,61 @@ static void octep_remove(struct pci_dev *pdev)
>  	pci_disable_device(pdev);
>  }
>  
> +static int octep_sriov_disable(struct octep_device *oct)
> +{
> +	struct pci_dev *pdev = oct->pdev;
> +
> +	if (pci_vfs_assigned(oct->pdev)) {
> +		dev_warn(&pdev->dev, "Can't disable SRIOV while VFs are assigned\n");
> +		return -EPERM;
> +	}

I think that PCI core should prevent this.

Thanks
  

Patch

diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index ad5553854467..fa0f3d597eb1 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -1236,11 +1236,61 @@  static void octep_remove(struct pci_dev *pdev)
 	pci_disable_device(pdev);
 }
 
+static int octep_sriov_disable(struct octep_device *oct)
+{
+	struct pci_dev *pdev = oct->pdev;
+
+	if (pci_vfs_assigned(oct->pdev)) {
+		dev_warn(&pdev->dev, "Can't disable SRIOV while VFs are assigned\n");
+		return -EPERM;
+	}
+
+	pci_disable_sriov(pdev);
+	CFG_GET_ACTIVE_VFS(oct->conf) = 0;
+
+	return 0;
+}
+
+static int octep_sriov_enable(struct octep_device *oct, int num_vfs)
+{
+	struct pci_dev *pdev = oct->pdev;
+	int err;
+
+	err = pci_enable_sriov(pdev, num_vfs);
+	if (err) {
+		dev_warn(&pdev->dev, "Failed to enable SRIOV err=%d\n", err);
+		return err;
+	}
+	CFG_GET_ACTIVE_VFS(oct->conf) = num_vfs;
+
+	return num_vfs;
+}
+
+static int octep_sriov_configure(struct pci_dev *pdev, int num_vfs)
+{
+	struct octep_device *oct = pci_get_drvdata(pdev);
+	int max_nvfs;
+
+	if (num_vfs == 0)
+		return octep_sriov_disable(oct);
+
+	max_nvfs = CFG_GET_MAX_VFS(oct->conf);
+
+	if (num_vfs > max_nvfs) {
+		dev_err(&pdev->dev, "Invalid VF count Max supported VFs = %d\n",
+			max_nvfs);
+		return -EINVAL;
+	}
+
+	return octep_sriov_enable(oct, num_vfs);
+}
+
 static struct pci_driver octep_driver = {
 	.name = OCTEP_DRV_NAME,
 	.id_table = octep_pci_id_tbl,
 	.probe = octep_probe,
 	.remove = octep_remove,
+	.sriov_configure = octep_sriov_configure,
 };
 
 /**