net/bnxt: add driver for Broadcom NetXtreme-C devices
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <inttypes.h>
35 #include <stdbool.h>
36
37 #include <rte_dev.h>
38 #include <rte_ethdev.h>
39 #include <rte_malloc.h>
40 #include <rte_cycles.h>
41
42 #define DRV_MODULE_NAME         "bnxt"
43 static const char bnxt_version[] =
44         "Broadcom Cumulus driver " DRV_MODULE_NAME "\n";
45
46 static struct rte_pci_id bnxt_pci_id_map[] = {
47 #define RTE_PCI_DEV_ID_DECL_BNXT(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
48 #include "rte_pci_dev_ids.h"
49         {.device_id = 0},
50 };
51
52 /*
53  * Initialization
54  */
55
56 static int
57 bnxt_dev_init(struct rte_eth_dev *eth_dev)
58 {
59         static int version_printed;
60         int rc;
61
62         if (version_printed++ == 0)
63                 RTE_LOG(INFO, PMD, "%s", bnxt_version);
64
65         if (eth_dev->pci_dev->addr.function >= 2 &&
66                         eth_dev->pci_dev->addr.function < 4) {
67                 RTE_LOG(ERR, PMD, "Function not enabled %x:\n",
68                         eth_dev->pci_dev->addr.function);
69                 rc = -ENOMEM;
70                 goto error;
71         }
72
73         rte_eth_copy_pci_info(eth_dev, eth_dev->pci_dev);
74         rc = -EPERM;
75
76 error:
77         return rc;
78 }
79
80 static int
81 bnxt_dev_uninit(struct rte_eth_dev *eth_dev __rte_unused) {
82         return 0;
83 }
84
85 static struct eth_driver bnxt_rte_pmd = {
86         .pci_drv = {
87                     .name = "rte_" DRV_MODULE_NAME "_pmd",
88                     .id_table = bnxt_pci_id_map,
89                     .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
90                     },
91         .eth_dev_init = bnxt_dev_init,
92         .eth_dev_uninit = bnxt_dev_uninit,
93         .dev_private_size = 32 /* this must be non-zero apparently */,
94 };
95
96 static int bnxt_rte_pmd_init(const char *name, const char *params __rte_unused)
97 {
98         RTE_LOG(INFO, PMD, "bnxt_rte_pmd_init() called for %s\n", name);
99         rte_eth_driver_register(&bnxt_rte_pmd);
100         return 0;
101 }
102
103 static struct rte_driver bnxt_pmd_drv = {
104         .name = "eth_bnxt",
105         .type = PMD_PDEV,
106         .init = bnxt_rte_pmd_init,
107 };
108
109 PMD_REGISTER_DRIVER(bnxt_pmd_drv);