4 * Copyright(c) 2014-2015 Chelsio Communications.
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 Chelsio Communications 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 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 <sys/queue.h>
42 #include <netinet/in.h>
44 #include <rte_byteorder.h>
45 #include <rte_common.h>
46 #include <rte_cycles.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
55 #include <rte_tailq.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_atomic.h>
61 #include <rte_malloc.h>
62 #include <rte_random.h>
68 * Macros needed to support the PCI Device ID Table ...
70 #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
71 static struct rte_pci_id cxgb4_pci_tbl[] = {
72 #define CH_PCI_DEVICE_ID_FUNCTION 0x4
74 #define PCI_VENDOR_ID_CHELSIO 0x1425
76 #define CH_PCI_ID_TABLE_ENTRY(devid) \
77 { RTE_PCI_DEVICE(PCI_VENDOR_ID_CHELSIO, (devid)) }
79 #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
84 *... and the PCI ID Table itself ...
86 #include "t4_pci_id_tbl.h"
88 static struct eth_dev_ops cxgbe_eth_dev_ops = {
93 * It returns 0 on success.
95 static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
97 struct rte_pci_device *pci_dev;
98 struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
99 struct adapter *adapter = NULL;
100 char name[RTE_ETH_NAME_MAX_LEN];
105 eth_dev->dev_ops = &cxgbe_eth_dev_ops;
107 /* for secondary processes, we don't initialise any further as primary
108 * has already done this work.
110 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
113 pci_dev = eth_dev->pci_dev;
114 snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
115 adapter = rte_zmalloc(name, sizeof(*adapter), 0);
119 adapter->use_unpacked_mode = 1;
120 adapter->regs = (void *)pci_dev->mem_resource[0].addr;
121 if (!adapter->regs) {
122 dev_err(adapter, "%s: cannot map device registers\n", __func__);
124 goto out_free_adapter;
126 adapter->pdev = pci_dev;
127 adapter->eth_dev = eth_dev;
128 pi->adapter = adapter;
130 err = cxgbe_probe(adapter);
132 dev_err(adapter, "%s: cxgbe probe failed with err %d\n",
139 static struct eth_driver rte_cxgbe_pmd = {
141 .name = "rte_cxgbe_pmd",
142 .id_table = cxgb4_pci_tbl,
143 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
145 .eth_dev_init = eth_cxgbe_dev_init,
146 .dev_private_size = sizeof(struct port_info),
150 * Driver initialization routine.
151 * Invoked once at EAL init time.
152 * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
154 static int rte_cxgbe_pmd_init(const char *name __rte_unused,
155 const char *params __rte_unused)
159 rte_eth_driver_register(&rte_cxgbe_pmd);
163 static struct rte_driver rte_cxgbe_driver = {
164 .name = "cxgbe_driver",
166 .init = rte_cxgbe_pmd_init,
169 PMD_REGISTER_DRIVER(rte_cxgbe_driver);