0c59c666681208cfbebe9abed44bee8934a52f46
[dpdk.git] / drivers / net / bnxt / bnxt.h
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 #ifndef _BNXT_H_
35 #define _BNXT_H_
36
37 #include <inttypes.h>
38 #include <stdbool.h>
39 #include <sys/queue.h>
40
41 #include <rte_ethdev.h>
42 #include <rte_memory.h>
43 #include <rte_lcore.h>
44 #include <rte_spinlock.h>
45
46 #include "bnxt_cpr.h"
47
48 #define BNXT_MAX_MTU            9000
49 #define VLAN_TAG_SIZE           4
50
51 enum bnxt_hw_context {
52         HW_CONTEXT_NONE     = 0,
53         HW_CONTEXT_IS_RSS   = 1,
54         HW_CONTEXT_IS_COS   = 2,
55         HW_CONTEXT_IS_LB    = 3,
56 };
57
58 struct bnxt_vlan_table_entry {
59         uint16_t                tpid;
60         uint16_t                vid;
61 } __attribute__((packed));
62
63 struct bnxt_child_vf_info {
64         void                    *req_buf;
65         struct bnxt_vlan_table_entry    *vlan_table;
66         STAILQ_HEAD(, bnxt_filter_info) filter;
67         uint32_t                func_cfg_flags;
68         uint32_t                l2_rx_mask;
69         uint16_t                fid;
70         bool                    random_mac;
71 };
72
73 struct bnxt_pf_info {
74 #define BNXT_FIRST_PF_FID       1
75 #define BNXT_MAX_VFS(bp)        (bp->pf.max_vfs)
76 #define BNXT_FIRST_VF_FID       128
77 #define BNXT_PF_RINGS_USED(bp)  bnxt_get_num_queues(bp)
78 #define BNXT_PF_RINGS_AVAIL(bp) (bp->pf.max_cp_rings - BNXT_PF_RINGS_USED(bp))
79         uint8_t                 port_id;
80         uint16_t                first_vf_id;
81         uint16_t                active_vfs;
82         uint16_t                max_vfs;
83         uint32_t                func_cfg_flags;
84         void                    *vf_req_buf;
85         phys_addr_t             vf_req_buf_dma_addr;
86         uint32_t                vf_req_fwd[8];
87         uint16_t                total_vnics;
88         struct bnxt_child_vf_info       *vf_info;
89 #define BNXT_EVB_MODE_NONE      0
90 #define BNXT_EVB_MODE_VEB       1
91 #define BNXT_EVB_MODE_VEPA      2
92         uint8_t                 evb_mode;
93 };
94
95 /* Max wait time is 10 * 100ms = 1s */
96 #define BNXT_LINK_WAIT_CNT      10
97 #define BNXT_LINK_WAIT_INTERVAL 100
98 struct bnxt_link_info {
99         uint32_t                phy_flags;
100         uint8_t                 mac_type;
101         uint8_t                 phy_link_status;
102         uint8_t                 loop_back;
103         uint8_t                 link_up;
104         uint8_t                 duplex;
105         uint8_t                 pause;
106         uint8_t                 force_pause;
107         uint8_t                 auto_pause;
108         uint8_t                 auto_mode;
109 #define PHY_VER_LEN             3
110         uint8_t                 phy_ver[PHY_VER_LEN];
111         uint16_t                link_speed;
112         uint16_t                support_speeds;
113         uint16_t                auto_link_speed;
114         uint16_t                auto_link_speed_mask;
115         uint32_t                preemphasis;
116 };
117
118 #define BNXT_COS_QUEUE_COUNT    8
119 struct bnxt_cos_queue_info {
120         uint8_t id;
121         uint8_t profile;
122 };
123
124 struct bnxt {
125         void                            *bar0;
126
127         struct rte_eth_dev              *eth_dev;
128         struct rte_pci_device           *pdev;
129
130         uint32_t                flags;
131 #define BNXT_FLAG_REGISTERED    (1 << 0)
132 #define BNXT_FLAG_VF            (1 << 1)
133 #define BNXT_PF(bp)             (!((bp)->flags & BNXT_FLAG_VF))
134 #define BNXT_VF(bp)             ((bp)->flags & BNXT_FLAG_VF)
135 #define BNXT_NPAR_ENABLED(bp)   ((bp)->port_partition_type)
136 #define BNXT_NPAR_PF(bp)        (BNXT_PF(bp) && BNXT_NPAR_ENABLED(bp))
137
138         unsigned int            rx_nr_rings;
139         unsigned int            rx_cp_nr_rings;
140         struct bnxt_rx_queue **rx_queues;
141
142         unsigned int            tx_nr_rings;
143         unsigned int            tx_cp_nr_rings;
144         struct bnxt_tx_queue **tx_queues;
145
146         /* Default completion ring */
147         struct bnxt_cp_ring_info        *def_cp_ring;
148         uint32_t                max_ring_grps;
149         struct bnxt_ring_grp_info       *grp_info;
150
151         unsigned int            nr_vnics;
152
153         struct bnxt_vnic_info   *vnic_info;
154         STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;
155
156         struct bnxt_filter_info *filter_info;
157         STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
158
159         /* VNIC pointer for flow filter (VMDq) pools */
160 #define MAX_FF_POOLS    ETH_64_POOLS
161         STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
162
163         struct bnxt_irq         *irq_tbl;
164
165 #define MAX_NUM_MAC_ADDR        32
166         uint8_t                 mac_addr[ETHER_ADDR_LEN];
167
168         uint16_t                        hwrm_cmd_seq;
169         void                            *hwrm_cmd_resp_addr;
170         phys_addr_t                     hwrm_cmd_resp_dma_addr;
171         rte_spinlock_t                  hwrm_lock;
172         uint16_t                        max_req_len;
173         uint16_t                        max_resp_len;
174
175         struct bnxt_link_info   link_info;
176         struct bnxt_cos_queue_info      cos_queue[BNXT_COS_QUEUE_COUNT];
177
178         uint16_t                fw_fid;
179         uint8_t                 dflt_mac_addr[ETHER_ADDR_LEN];
180         uint16_t                max_rsscos_ctx;
181         uint16_t                max_cp_rings;
182         uint16_t                max_tx_rings;
183         uint16_t                max_rx_rings;
184         uint16_t                max_l2_ctx;
185         uint16_t                max_vnics;
186         uint16_t                max_stat_ctx;
187         uint16_t                vlan;
188         struct bnxt_pf_info             pf;
189         uint8_t                 port_partition_type;
190         uint8_t                 dev_stopped;
191         uint32_t                fw_ver;
192 };
193
194 /*
195  * Response sent back to the caller after callback
196  */
197 enum rte_pmd_bnxt_mb_event_rsp {
198         RTE_PMD_BNXT_MB_EVENT_NOOP_ACK,  /**< skip mbox request and ACK */
199         RTE_PMD_BNXT_MB_EVENT_NOOP_NACK, /**< skip mbox request and NACK */
200         RTE_PMD_BNXT_MB_EVENT_PROCEED,  /**< proceed with mbox request  */
201         RTE_PMD_BNXT_MB_EVENT_MAX       /**< max value of this enum */
202 };
203
204 /* mailbox message types */
205 #define BNXT_VF_RESET                   0x01 /* VF requests reset */
206 #define BNXT_VF_SET_MAC_ADDR    0x02 /* VF requests PF to set MAC addr */
207 #define BNXT_VF_SET_VLAN                0x03 /* VF requests PF to set VLAN */
208 #define BNXT_VF_SET_MTU                 0x04 /* VF requests PF to set MTU */
209 #define BNXT_VF_SET_MRU                 0x05 /* VF requests PF to set MRU */
210
211 /*
212  * Data sent to the caller when the callback is executed.
213  */
214 struct rte_pmd_bnxt_mb_event_param {
215         uint16_t vf_id; /* Virtual Function number */
216         int     retval; /* return value */
217         void    *msg;   /* pointer to message */
218 };
219
220 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete);
221 int bnxt_rcv_msg_from_vf(struct bnxt *bp, uint16_t vf_id, void *msg);
222
223 #endif