4 * Copyright(c) Broadcom Limited.
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 Broadcom Corporation 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.
38 #include <rte_ethdev.h>
39 #include <rte_malloc.h>
40 #include <rte_cycles.h>
43 #include "bnxt_hwrm.h"
45 #define DRV_MODULE_NAME "bnxt"
46 static const char bnxt_version[] =
47 "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
49 static struct rte_pci_id bnxt_pci_id_map[] = {
50 #define RTE_PCI_DEV_ID_DECL_BNXT(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
51 #include "rte_pci_dev_ids.h"
55 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
57 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
59 rte_free(eth_dev->data->mac_addrs);
60 bnxt_free_hwrm_resources(bp);
67 static struct eth_dev_ops bnxt_dev_ops = {
68 .dev_close = bnxt_dev_close_op,
71 static bool bnxt_vf_pciid(uint16_t id)
73 if (id == BROADCOM_DEV_ID_57304_VF ||
74 id == BROADCOM_DEV_ID_57406_VF)
79 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
82 struct bnxt *bp = eth_dev->data->dev_private;
84 /* enable device (incl. PCI PM wakeup), and bus-mastering */
85 if (!eth_dev->pci_dev->mem_resource[0].addr) {
87 "Cannot find PCI device base address, aborting\n");
89 goto init_err_disable;
92 bp->eth_dev = eth_dev;
93 bp->pdev = eth_dev->pci_dev;
95 bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
97 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
99 goto init_err_release;
113 bnxt_dev_init(struct rte_eth_dev *eth_dev)
115 static int version_printed;
119 if (version_printed++ == 0)
120 RTE_LOG(INFO, PMD, "%s", bnxt_version);
122 if (eth_dev->pci_dev->addr.function >= 2 &&
123 eth_dev->pci_dev->addr.function < 4) {
124 RTE_LOG(ERR, PMD, "Function not enabled %x:\n",
125 eth_dev->pci_dev->addr.function);
130 rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
131 bp = eth_dev->data->dev_private;
133 if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
134 bp->flags |= BNXT_FLAG_VF;
136 rc = bnxt_init_board(eth_dev);
139 "Board initialization failed rc: %x\n", rc);
142 eth_dev->dev_ops = &bnxt_dev_ops;
143 /* eth_dev->rx_pkt_burst = &bnxt_recv_pkts; */
144 /* eth_dev->tx_pkt_burst = &bnxt_xmit_pkts; */
146 rc = bnxt_alloc_hwrm_resources(bp);
149 "hwrm resource allocation failure rc: %x\n", rc);
152 rc = bnxt_hwrm_ver_get(bp);
155 bnxt_hwrm_queue_qportcfg(bp);
157 /* Get the MAX capabilities for this function */
158 rc = bnxt_hwrm_func_qcaps(bp);
160 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
163 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
164 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR, 0);
165 if (eth_dev->data->mac_addrs == NULL) {
167 "Failed to alloc %u bytes needed to store MAC addr tbl",
168 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR);
172 /* Copy the permanent MAC from the qcap response address now. */
174 memcpy(bp->mac_addr, bp->pf.mac_addr, sizeof(bp->mac_addr));
176 memcpy(bp->mac_addr, bp->vf.mac_addr, sizeof(bp->mac_addr));
177 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
182 bnxt_dev_close_op(eth_dev);
188 bnxt_dev_uninit(struct rte_eth_dev *eth_dev __rte_unused) {
192 static struct eth_driver bnxt_rte_pmd = {
194 .name = "rte_" DRV_MODULE_NAME "_pmd",
195 .id_table = bnxt_pci_id_map,
196 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
198 .eth_dev_init = bnxt_dev_init,
199 .eth_dev_uninit = bnxt_dev_uninit,
200 .dev_private_size = sizeof(struct bnxt),
203 static int bnxt_rte_pmd_init(const char *name, const char *params __rte_unused)
205 RTE_LOG(INFO, PMD, "bnxt_rte_pmd_init() called for %s\n", name);
206 rte_eth_driver_register(&bnxt_rte_pmd);
210 static struct rte_driver bnxt_pmd_drv = {
213 .init = bnxt_rte_pmd_init,
216 PMD_REGISTER_DRIVER(bnxt_pmd_drv);