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"
10 #define PCI_VENDOR_ID_CAVIUM 0x177d
11 #define NITROX_V_PCI_VF_DEV_ID 0x13
13 TAILQ_HEAD(ndev_list, nitrox_device);
14 static struct ndev_list ndev_list = TAILQ_HEAD_INITIALIZER(ndev_list);
16 static struct nitrox_device *
17 ndev_allocate(struct rte_pci_device *pdev)
19 struct nitrox_device *ndev;
21 ndev = rte_zmalloc_socket("nitrox device", sizeof(*ndev),
23 pdev->device.numa_node);
27 TAILQ_INSERT_TAIL(&ndev_list, ndev, next);
32 ndev_init(struct nitrox_device *ndev, struct rte_pci_device *pdev)
34 enum nitrox_vf_mode vf_mode;
37 ndev->bar_addr = pdev->mem_resource[0].addr;
38 vf_mode = vf_get_vf_config_mode(ndev->bar_addr);
39 ndev->nr_queues = vf_config_mode_to_nr_queues(vf_mode);
42 static struct nitrox_device *
43 find_ndev(struct rte_pci_device *pdev)
45 struct nitrox_device *ndev;
47 TAILQ_FOREACH(ndev, &ndev_list, next)
48 if (ndev->pdev == pdev)
55 ndev_release(struct nitrox_device *ndev)
60 TAILQ_REMOVE(&ndev_list, ndev, next);
65 nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
66 struct rte_pci_device *pdev)
68 struct nitrox_device *ndev;
70 /* Nitrox CSR space */
71 if (!pdev->mem_resource[0].addr)
74 ndev = ndev_allocate(pdev);
78 ndev_init(ndev, pdev);
83 nitrox_pci_remove(struct rte_pci_device *pdev)
85 struct nitrox_device *ndev;
87 ndev = find_ndev(pdev);
95 static struct rte_pci_id pci_id_nitrox_map[] = {
98 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, NITROX_V_PCI_VF_DEV_ID)
103 static struct rte_pci_driver nitrox_pmd = {
104 .id_table = pci_id_nitrox_map,
105 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
106 .probe = nitrox_pci_probe,
107 .remove = nitrox_pci_remove,
110 RTE_PMD_REGISTER_PCI(nitrox, nitrox_pmd);
111 RTE_PMD_REGISTER_PCI_TABLE(nitrox, pci_id_nitrox_map);