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);
64 * Device configuration and status function
67 static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
68 struct rte_eth_dev_info *dev_info)
70 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
71 uint16_t max_vnics, i, j, vpool, vrxq;
74 dev_info->max_mac_addrs = MAX_NUM_MAC_ADDR;
75 dev_info->max_hash_mac_addrs = 0;
79 dev_info->max_rx_queues = bp->pf.max_rx_rings;
80 dev_info->max_tx_queues = bp->pf.max_tx_rings;
81 dev_info->max_vfs = bp->pf.active_vfs;
82 dev_info->reta_size = bp->pf.max_rsscos_ctx;
83 max_vnics = bp->pf.max_vnics;
85 dev_info->max_rx_queues = bp->vf.max_rx_rings;
86 dev_info->max_tx_queues = bp->vf.max_tx_rings;
87 dev_info->reta_size = bp->vf.max_rsscos_ctx;
88 max_vnics = bp->vf.max_vnics;
91 /* Fast path specifics */
92 dev_info->min_rx_bufsize = 1;
93 dev_info->max_rx_pktlen = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
95 dev_info->rx_offload_capa = 0;
96 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_IPV4_CKSUM |
97 DEV_TX_OFFLOAD_TCP_CKSUM |
98 DEV_TX_OFFLOAD_UDP_CKSUM |
99 DEV_TX_OFFLOAD_TCP_TSO;
102 dev_info->default_rxconf = (struct rte_eth_rxconf) {
108 .rx_free_thresh = 32,
112 dev_info->default_txconf = (struct rte_eth_txconf) {
118 .tx_free_thresh = 32,
120 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
121 ETH_TXQ_FLAGS_NOOFFLOADS,
126 * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
127 * need further investigation.
131 vpool = 64; /* ETH_64_POOLS */
132 vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
133 for (i = 0; i < 4; vpool >>= 1, i++) {
134 if (max_vnics > vpool) {
135 for (j = 0; j < 5; vrxq >>= 1, j++) {
136 if (dev_info->max_rx_queues > vrxq) {
142 /* Not enough resources to support VMDq */
146 /* Not enough resources to support VMDq */
150 dev_info->max_vmdq_pools = vpool;
151 dev_info->vmdq_queue_num = vrxq;
153 dev_info->vmdq_pool_base = 0;
154 dev_info->vmdq_queue_base = 0;
157 /* Configure the device based on the configuration provided */
158 static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
160 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
163 bp->rx_queues = (void *)eth_dev->data->rx_queues;
164 bp->tx_queues = (void *)eth_dev->data->tx_queues;
166 /* Inherit new configurations */
167 bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
168 bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
169 bp->rx_cp_nr_rings = bp->rx_nr_rings;
170 bp->tx_cp_nr_rings = bp->tx_nr_rings;
172 if (eth_dev->data->dev_conf.rxmode.jumbo_frame)
174 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len -
175 ETHER_HDR_LEN - ETHER_CRC_LEN - VLAN_TAG_SIZE;
176 rc = bnxt_set_hwrm_link_config(bp, true);
184 static struct eth_dev_ops bnxt_dev_ops = {
185 .dev_infos_get = bnxt_dev_info_get_op,
186 .dev_close = bnxt_dev_close_op,
187 .dev_configure = bnxt_dev_configure_op,
190 static bool bnxt_vf_pciid(uint16_t id)
192 if (id == BROADCOM_DEV_ID_57304_VF ||
193 id == BROADCOM_DEV_ID_57406_VF)
198 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
201 struct bnxt *bp = eth_dev->data->dev_private;
203 /* enable device (incl. PCI PM wakeup), and bus-mastering */
204 if (!eth_dev->pci_dev->mem_resource[0].addr) {
206 "Cannot find PCI device base address, aborting\n");
208 goto init_err_disable;
211 bp->eth_dev = eth_dev;
212 bp->pdev = eth_dev->pci_dev;
214 bp->bar0 = (void *)eth_dev->pci_dev->mem_resource[0].addr;
216 RTE_LOG(ERR, PMD, "Cannot map device registers, aborting\n");
218 goto init_err_release;
232 bnxt_dev_init(struct rte_eth_dev *eth_dev)
234 static int version_printed;
238 if (version_printed++ == 0)
239 RTE_LOG(INFO, PMD, "%s", bnxt_version);
241 if (eth_dev->pci_dev->addr.function >= 2 &&
242 eth_dev->pci_dev->addr.function < 4) {
243 RTE_LOG(ERR, PMD, "Function not enabled %x:\n",
244 eth_dev->pci_dev->addr.function);
249 rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
250 bp = eth_dev->data->dev_private;
252 if (bnxt_vf_pciid(eth_dev->pci_dev->id.device_id))
253 bp->flags |= BNXT_FLAG_VF;
255 rc = bnxt_init_board(eth_dev);
258 "Board initialization failed rc: %x\n", rc);
261 eth_dev->dev_ops = &bnxt_dev_ops;
262 /* eth_dev->rx_pkt_burst = &bnxt_recv_pkts; */
263 /* eth_dev->tx_pkt_burst = &bnxt_xmit_pkts; */
265 rc = bnxt_alloc_hwrm_resources(bp);
268 "hwrm resource allocation failure rc: %x\n", rc);
271 rc = bnxt_hwrm_ver_get(bp);
274 bnxt_hwrm_queue_qportcfg(bp);
276 /* Get the MAX capabilities for this function */
277 rc = bnxt_hwrm_func_qcaps(bp);
279 RTE_LOG(ERR, PMD, "hwrm query capability failure rc: %x\n", rc);
282 eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
283 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR, 0);
284 if (eth_dev->data->mac_addrs == NULL) {
286 "Failed to alloc %u bytes needed to store MAC addr tbl",
287 ETHER_ADDR_LEN * MAX_NUM_MAC_ADDR);
291 /* Copy the permanent MAC from the qcap response address now. */
293 memcpy(bp->mac_addr, bp->pf.mac_addr, sizeof(bp->mac_addr));
295 memcpy(bp->mac_addr, bp->vf.mac_addr, sizeof(bp->mac_addr));
296 memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
298 rc = bnxt_hwrm_func_driver_register(bp, 0,
302 "Failed to register driver");
308 DRV_MODULE_NAME " found at mem %" PRIx64 ", node addr %pM\n",
309 eth_dev->pci_dev->mem_resource[0].phys_addr,
310 eth_dev->pci_dev->mem_resource[0].addr);
315 eth_dev->driver->eth_dev_uninit(eth_dev);
321 bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
322 struct bnxt *bp = eth_dev->data->dev_private;
325 if (eth_dev->data->mac_addrs)
326 rte_free(eth_dev->data->mac_addrs);
327 rc = bnxt_hwrm_func_driver_unregister(bp, 0);
328 bnxt_free_hwrm_resources(bp);
332 static struct eth_driver bnxt_rte_pmd = {
334 .name = "rte_" DRV_MODULE_NAME "_pmd",
335 .id_table = bnxt_pci_id_map,
336 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
338 .eth_dev_init = bnxt_dev_init,
339 .eth_dev_uninit = bnxt_dev_uninit,
340 .dev_private_size = sizeof(struct bnxt),
343 static int bnxt_rte_pmd_init(const char *name, const char *params __rte_unused)
345 RTE_LOG(INFO, PMD, "bnxt_rte_pmd_init() called for %s\n", name);
346 rte_eth_driver_register(&bnxt_rte_pmd);
350 static struct rte_driver bnxt_pmd_drv = {
353 .init = bnxt_rte_pmd_init,
356 PMD_REGISTER_DRIVER(bnxt_pmd_drv);