1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_malloc.h>
7 #include "nitrox_device.h"
8 #include "nitrox_hal.h"
9 #include "nitrox_sym.h"
11 #define PCI_VENDOR_ID_CAVIUM 0x177d
12 #define NITROX_V_PCI_VF_DEV_ID 0x13
14 TAILQ_HEAD(ndev_list, nitrox_device);
15 static struct ndev_list ndev_list = TAILQ_HEAD_INITIALIZER(ndev_list);
17 static struct nitrox_device *
18 ndev_allocate(struct rte_pci_device *pdev)
20 struct nitrox_device *ndev;
22 ndev = rte_zmalloc_socket("nitrox device", sizeof(*ndev),
24 pdev->device.numa_node);
28 TAILQ_INSERT_TAIL(&ndev_list, ndev, next);
33 ndev_init(struct nitrox_device *ndev, struct rte_pci_device *pdev)
35 enum nitrox_vf_mode vf_mode;
38 ndev->bar_addr = pdev->mem_resource[0].addr;
39 vf_mode = vf_get_vf_config_mode(ndev->bar_addr);
40 ndev->nr_queues = vf_config_mode_to_nr_queues(vf_mode);
43 static struct nitrox_device *
44 find_ndev(struct rte_pci_device *pdev)
46 struct nitrox_device *ndev;
48 TAILQ_FOREACH(ndev, &ndev_list, next)
49 if (ndev->pdev == pdev)
56 ndev_release(struct nitrox_device *ndev)
61 TAILQ_REMOVE(&ndev_list, ndev, next);
66 nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
67 struct rte_pci_device *pdev)
69 struct nitrox_device *ndev;
72 /* Nitrox CSR space */
73 if (!pdev->mem_resource[0].addr)
76 ndev = ndev_allocate(pdev);
80 ndev_init(ndev, pdev);
81 err = nitrox_sym_pmd_create(ndev);
91 nitrox_pci_remove(struct rte_pci_device *pdev)
93 struct nitrox_device *ndev;
96 ndev = find_ndev(pdev);
100 err = nitrox_sym_pmd_destroy(ndev);
108 static struct rte_pci_id pci_id_nitrox_map[] = {
111 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, NITROX_V_PCI_VF_DEV_ID)
116 static struct rte_pci_driver nitrox_pmd = {
117 .id_table = pci_id_nitrox_map,
118 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
119 .probe = nitrox_pci_probe,
120 .remove = nitrox_pci_remove,
123 RTE_PMD_REGISTER_PCI(nitrox, nitrox_pmd);
124 RTE_PMD_REGISTER_PCI_TABLE(nitrox, pci_id_nitrox_map);