Thursday, June 14, 2018 11:35 AM, Adrien Mazarguil:
> Subject: [PATCH v2 3/7] net/mlx5: split PCI from generic probing code
> 
> All the generic probing code needs is an IB device. While this device is
> currently supplied by a PCI lookup, other methods will be added soon.
> 
> This patch divides the original function, which has become huge over time, as
> follows:
> 
> 1. PCI-specific (mlx5_pci_probe()).
> 2. All ports of a Verbs device (mlx5_dev_spawn()).
> 3. A given port of a Verbs device (mlx5_dev_spawn_one()).
> 
> (Patch based on prior work from Yuanhan Liu)
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarg...@6wind.com>
> --
> v2 changes:
> 
> - Fixed device naming. A port suffix is now appended only if several IB
>   ports happen to be detected.
> - Added separate message to distinguish missing kernel drivers from other
>   initialization errors, as it was confusing.

[...]

> +/**
> + * DPDK callback to register a PCI device.
> + *
> + * This function creates an Ethernet device for each port of a given
> + * PCI device.
> + *
> + * @param[in] pci_drv
> + *   PCI driver structure (mlx5_driver).
> + * @param[in] pci_dev
> + *   PCI device information.
> + *
> + * @return
> + *   0 on success, a negative errno value otherwise and rte_errno is set.
> + */
> +static int
> +mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
> +            struct rte_pci_device *pci_dev) {
> +     struct ibv_device **ibv_list;
> +     struct rte_eth_dev **eth_list = NULL;
> +     int vf;
> +     int ret;
> +
> +     assert(pci_drv == &mlx5_driver);
> +     switch (pci_dev->id.device_id) {
> +     case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
> +     case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
> +     case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
> +     case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
> +             vf = 1;
> +             break;
> +     default:
> +             vf = 0;
> +     }

Even though I couldn't find any functional bug, I think it is logically more 
correct to determine if pci device is vf after we know this is Mellanox device. 
Meaning the above block should be ...

> +     errno = 0;
> +     ibv_list = mlx5_glue->get_device_list(&ret);
> +     if (!ibv_list) {
> +             rte_errno = errno ? errno : ENOSYS;
> +             DRV_LOG(ERR, "cannot list devices, is ib_uverbs loaded?");
>               return -rte_errno;
>       }
> -     return 0;
> +     while (ret-- > 0) {
> +             struct rte_pci_addr pci_addr;
> +
> +             DRV_LOG(DEBUG, "checking device \"%s\"", ibv_list[ret]-
> >name);
> +             if (mlx5_ibv_device_to_pci_addr(ibv_list[ret], &pci_addr))
> +                     continue;
> +             if (pci_dev->addr.domain != pci_addr.domain ||
> +                 pci_dev->addr.bus != pci_addr.bus ||
> +                 pci_dev->addr.devid != pci_addr.devid ||
> +                 pci_dev->addr.function != pci_addr.function)
> +                     continue;
> +             DRV_LOG(INFO, "PCI information matches, using device
> \"%s\"",
> +                     ibv_list[ret]->name);
> +             break;
> +     }

Here. 

> +     if (ret >= 0)
> +             eth_list = mlx5_dev_spawn(&pci_dev->device, ibv_list[ret],
> vf);
> +     mlx5_glue->free_device_list(ibv_list);
> +     if (!ret) {
> +             DRV_LOG(WARNING,
> +                     "no Verbs device matches PCI device " PCI_PRI_FMT
> ","
> +                     " are kernel drivers loaded?",
> +                     pci_dev->addr.domain, pci_dev->addr.bus,
> +                     pci_dev->addr.devid, pci_dev->addr.function);
> +             rte_errno = ENOENT;
> +             ret = -rte_errno;
> +     } else if (!eth_list || !*eth_list) {
> +             DRV_LOG(ERR,
> +                     "probe of PCI device " PCI_PRI_FMT " aborted after"
> +                     " encountering an error: %s",
> +                     pci_dev->addr.domain, pci_dev->addr.bus,
> +                     pci_dev->addr.devid, pci_dev->addr.function,
> +                     strerror(rte_errno));
> +             ret = -rte_errno;
> +     } else {
> +             for (ret = 0; eth_list[ret]; ++ret) {
> +                     rte_eth_copy_pci_info(eth_list[ret], pci_dev);
> +                     rte_eth_dev_probing_finish(eth_list[ret]);
> +             }
> +             ret = 0;
> +     }
> +     free(eth_list);
> +     return ret;
>  }
> 
>  static const struct rte_pci_id mlx5_pci_id_map[] = {
> --
> 2.11.0

Reply via email to