4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_ethdev.h>
35 #include <rte_cycles.h>
36 #include <rte_malloc.h>
37 #include <rte_alarm.h>
40 #include "lio_23xx_vf.h"
41 #include "lio_ethdev.h"
44 * \brief Identify the LIO device and to map the BAR address space
45 * @param lio_dev lio device
48 lio_chip_specific_setup(struct lio_device *lio_dev)
50 struct rte_pci_device *pdev = lio_dev->pci_dev;
51 uint32_t dev_id = pdev->id.device_id;
56 case LIO_CN23XX_VF_VID:
57 lio_dev->chip_id = LIO_CN23XX_VF_VID;
58 ret = cn23xx_vf_setup_device(lio_dev);
63 lio_dev_err(lio_dev, "Unsupported Chip\n");
67 lio_dev_info(lio_dev, "DEVICE : %s\n", s);
73 lio_first_time_init(struct lio_device *lio_dev,
74 struct rte_pci_device *pdev)
78 PMD_INIT_FUNC_TRACE();
80 /* set dpdk specific pci device pointer */
81 lio_dev->pci_dev = pdev;
83 /* Identify the LIO type and set device ops */
84 if (lio_chip_specific_setup(lio_dev)) {
85 lio_dev_err(lio_dev, "Chip specific setup failed\n");
89 dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf;
91 lio_dev->max_tx_queues = dpdk_queues;
92 lio_dev->max_rx_queues = dpdk_queues;
98 lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
100 PMD_INIT_FUNC_TRACE();
102 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
105 rte_free(eth_dev->data->mac_addrs);
106 eth_dev->data->mac_addrs = NULL;
112 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
114 struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
115 struct lio_device *lio_dev = LIO_DEV(eth_dev);
117 PMD_INIT_FUNC_TRACE();
119 /* Primary does the initialization. */
120 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
123 rte_eth_copy_pci_info(eth_dev, pdev);
124 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
126 if (pdev->mem_resource[0].addr) {
127 lio_dev->hw_addr = pdev->mem_resource[0].addr;
129 PMD_INIT_LOG(ERR, "ERROR: Failed to map BAR0\n");
133 lio_dev->eth_dev = eth_dev;
134 /* set lio device print string */
135 snprintf(lio_dev->dev_string, sizeof(lio_dev->dev_string),
136 "%s[%02x:%02x.%x]", pdev->driver->driver.name,
137 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
139 lio_dev->port_id = eth_dev->data->port_id;
141 if (lio_first_time_init(lio_dev, pdev)) {
142 lio_dev_err(lio_dev, "Device init failed\n");
146 eth_dev->data->mac_addrs = rte_zmalloc("lio", ETHER_ADDR_LEN, 0);
147 if (eth_dev->data->mac_addrs == NULL) {
149 "MAC addresses memory allocation failed\n");
156 /* Set of PCI devices this driver supports */
157 static const struct rte_pci_id pci_id_liovf_map[] = {
158 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
159 { .vendor_id = 0, /* sentinel */ }
162 static struct eth_driver rte_liovf_pmd = {
164 .id_table = pci_id_liovf_map,
165 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
166 .probe = rte_eth_dev_pci_probe,
167 .remove = rte_eth_dev_pci_remove,
169 .eth_dev_init = lio_eth_dev_init,
170 .eth_dev_uninit = lio_eth_dev_uninit,
171 .dev_private_size = sizeof(struct lio_device),
174 RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
175 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
176 RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");