diff mbox series

[V2,mlx5-next,06/14] vdpa/mlx5: Use mlx5_vf_get_core_dev() to get PF device

Message ID 20211019105838.227569-7-yishaih@nvidia.com (mailing list archive)
State New, archived
Headers show
Series Add mlx5 live migration driver | expand

Commit Message

Yishai Hadas Oct. 19, 2021, 10:58 a.m. UTC
Use mlx5_vf_get_core_dev() to get PF device instead of accessing
directly the PF data structure from the VF one.

The mlx5_vf_get_core_dev() API in its turn uses the generic PCI API
(i.e. pci_iov_get_pf_drvdata) to get it.

Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Max Gurtovoy Oct. 19, 2021, 11:16 a.m. UTC | #1
On 10/19/2021 1:58 PM, Yishai Hadas wrote:
> Use mlx5_vf_get_core_dev() to get PF device instead of accessing
> directly the PF data structure from the VF one.
>
> The mlx5_vf_get_core_dev() API in its turn uses the generic PCI API
> (i.e. pci_iov_get_pf_drvdata) to get it.
>
> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 27 +++++++++++++++++++++------
>   1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 5c7d2a953dbd..97b8917bc34d 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -1445,7 +1445,10 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
>   	size_t read;
>   	u8 mac[ETH_ALEN];
>   
> -	pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
> +	pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev);
> +	if (!pfmdev)
> +		return status;
> +
>   	switch (cmd) {

Yishai/Jason,

I think this patch breaks VPDA over SF.

Did you verify it ?

-Max.
Yishai Hadas Oct. 20, 2021, 8:58 a.m. UTC | #2
On 10/19/2021 2:16 PM, Max Gurtovoy wrote:
>
> On 10/19/2021 1:58 PM, Yishai Hadas wrote:
>> Use mlx5_vf_get_core_dev() to get PF device instead of accessing
>> directly the PF data structure from the VF one.
>>
>> The mlx5_vf_get_core_dev() API in its turn uses the generic PCI API
>> (i.e. pci_iov_get_pf_drvdata) to get it.
>>
>> Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
>> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>> ---
>>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 27 +++++++++++++++++++++------
>>   1 file changed, 21 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
>> b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index 5c7d2a953dbd..97b8917bc34d 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -1445,7 +1445,10 @@ static virtio_net_ctrl_ack 
>> handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
>>       size_t read;
>>       u8 mac[ETH_ALEN];
>>   -    pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
>> +    pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev);
>> +    if (!pfmdev)
>> +        return status;
>> +
>>       switch (cmd) {
>
> Yishai/Jason,
>
> I think this patch breaks VPDA over SF.
>
> Did you verify it ?
>

It seems that you are right, the SF use case requires some different 
handling/path compared to VF.

As this patch is orthogonal to what we try to achieve in this series, we 
may apparently drop it from V3 and let vdpa/mlx5 people come with a 
complete tested patch for both cases on top.

Thanks,
Yishai
diff mbox series

Patch

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 5c7d2a953dbd..97b8917bc34d 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1445,7 +1445,10 @@  static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 	size_t read;
 	u8 mac[ETH_ALEN];
 
-	pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
+	pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev);
+	if (!pfmdev)
+		return status;
+
 	switch (cmd) {
 	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
 		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)mac, ETH_ALEN);
@@ -1479,6 +1482,7 @@  static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 		break;
 	}
 
+	mlx5_vf_put_core_dev(pfmdev);
 	return status;
 }
 
@@ -2261,8 +2265,11 @@  static void mlx5_vdpa_free(struct vdpa_device *vdev)
 	free_resources(ndev);
 	mlx5_vdpa_destroy_mr(mvdev);
 	if (!is_zero_ether_addr(ndev->config.mac)) {
-		pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
-		mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
+		pfmdev = mlx5_vf_get_core_dev(mvdev->mdev->pdev);
+		if (pfmdev) {
+			mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
+			mlx5_vf_put_core_dev(pfmdev);
+		}
 	}
 	mlx5_vdpa_free_resources(&ndev->mvdev);
 	mutex_destroy(&ndev->reslock);
@@ -2449,8 +2456,11 @@  static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
 		goto err_mtu;
 
 	if (!is_zero_ether_addr(config->mac)) {
-		pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
+		pfmdev = mlx5_vf_get_core_dev(mdev->pdev);
+		if (!pfmdev)
+			goto err_mtu;
 		err = mlx5_mpfs_add_mac(pfmdev, config->mac);
+		mlx5_vf_put_core_dev(pfmdev);
 		if (err)
 			goto err_mtu;
 
@@ -2497,8 +2507,13 @@  static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
 err_res:
 	mlx5_vdpa_free_resources(&ndev->mvdev);
 err_mpfs:
-	if (!is_zero_ether_addr(config->mac))
-		mlx5_mpfs_del_mac(pfmdev, config->mac);
+	if (!is_zero_ether_addr(config->mac)) {
+		pfmdev = mlx5_vf_get_core_dev(mdev->pdev);
+		if (pfmdev) {
+			mlx5_mpfs_del_mac(pfmdev, config->mac);
+			mlx5_vf_put_core_dev(pfmdev);
+		}
+	}
 err_mtu:
 	mutex_destroy(&ndev->reslock);
 	put_device(&mvdev->vdev.dev);