New upstream version 16.11.5
[deb_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 <sys/queue.h>
39
40 #include <rte_ethdev.h>
41 #include <rte_memory.h>
42 #include <rte_lcore.h>
43 #include <rte_spinlock.h>
44
45 #include "bnxt_cpr.h"
46
47 #define BNXT_MAX_MTU            9000
48 #define VLAN_TAG_SIZE           4
49
50 enum bnxt_hw_context {
51         HW_CONTEXT_NONE     = 0,
52         HW_CONTEXT_IS_RSS   = 1,
53         HW_CONTEXT_IS_COS   = 2,
54         HW_CONTEXT_IS_LB    = 3,
55 };
56
57 struct bnxt_vf_info {
58         uint16_t                fw_fid;
59         uint8_t                 mac_addr[ETHER_ADDR_LEN];
60         uint16_t                max_rsscos_ctx;
61         uint16_t                max_cp_rings;
62         uint16_t                max_tx_rings;
63         uint16_t                max_rx_rings;
64         uint16_t                max_l2_ctx;
65         uint16_t                max_vnics;
66         uint16_t                vlan;
67         struct bnxt_pf_info     *pf;
68 };
69
70 struct bnxt_pf_info {
71 #define BNXT_FIRST_PF_FID       1
72 #define BNXT_MAX_VFS(bp)        (bp->pf.max_vfs)
73 #define BNXT_FIRST_VF_FID       128
74 #define BNXT_PF_RINGS_USED(bp)  bnxt_get_num_queues(bp)
75 #define BNXT_PF_RINGS_AVAIL(bp) (bp->pf.max_cp_rings - BNXT_PF_RINGS_USED(bp))
76         uint32_t                fw_fid;
77         uint8_t                 port_id;
78         uint8_t                 mac_addr[ETHER_ADDR_LEN];
79         uint16_t                max_rsscos_ctx;
80         uint16_t                max_cp_rings;
81         uint16_t                max_tx_rings;
82         uint16_t                max_rx_rings;
83         uint16_t                max_l2_ctx;
84         uint16_t                max_vnics;
85         uint16_t                first_vf_id;
86         uint16_t                active_vfs;
87         uint16_t                max_vfs;
88         void                    *vf_req_buf;
89         phys_addr_t             vf_req_buf_dma_addr;
90         uint32_t                vf_req_fwd[8];
91         struct bnxt_vf_info     *vf;
92 };
93
94 /* Max wait time is 10 * 100ms = 1s */
95 #define BNXT_LINK_WAIT_CNT      10
96 #define BNXT_LINK_WAIT_INTERVAL 100
97 struct bnxt_link_info {
98         uint32_t                phy_flags;
99         uint8_t                 mac_type;
100         uint8_t                 phy_link_status;
101         uint8_t                 loop_back;
102         uint8_t                 link_up;
103         uint8_t                 duplex;
104         uint8_t                 pause;
105         uint8_t                 force_pause;
106         uint8_t                 auto_pause;
107         uint8_t                 auto_mode;
108 #define PHY_VER_LEN             3
109         uint8_t                 phy_ver[PHY_VER_LEN];
110         uint16_t                link_speed;
111         uint16_t                support_speeds;
112         uint16_t                auto_link_speed;
113         uint16_t                force_link_speed;
114         uint16_t                auto_link_speed_mask;
115         uint32_t                preemphasis;
116         uint8_t                 phy_type;
117         uint8_t                 media_type;
118 };
119
120 #define BNXT_COS_QUEUE_COUNT    8
121 struct bnxt_cos_queue_info {
122         uint8_t id;
123         uint8_t profile;
124 };
125
126 struct bnxt {
127         void                            *bar0;
128
129         struct rte_eth_dev              *eth_dev;
130         struct rte_pci_device           *pdev;
131
132         uint32_t                flags;
133 #define BNXT_FLAG_REGISTERED    (1 << 0)
134 #define BNXT_FLAG_VF            (1 << 1)
135 #define BNXT_PF(bp)             (!((bp)->flags & BNXT_FLAG_VF))
136 #define BNXT_VF(bp)             ((bp)->flags & BNXT_FLAG_VF)
137 #define BNXT_NPAR_ENABLED(bp)   ((bp)->port_partition_type)
138 #define BNXT_NPAR_PF(bp)        (BNXT_PF(bp) && BNXT_NPAR_ENABLED(bp))
139
140         unsigned int            rx_nr_rings;
141         unsigned int            rx_cp_nr_rings;
142         struct bnxt_rx_queue **rx_queues;
143
144         unsigned int            tx_nr_rings;
145         unsigned int            tx_cp_nr_rings;
146         struct bnxt_tx_queue **tx_queues;
147
148         /* Default completion ring */
149         struct bnxt_cp_ring_info        *def_cp_ring;
150         uint32_t                max_ring_grps;
151         struct bnxt_ring_grp_info       *grp_info;
152
153         unsigned int            nr_vnics;
154
155         struct bnxt_vnic_info   *vnic_info;
156         STAILQ_HEAD(, bnxt_vnic_info)   free_vnic_list;
157
158         struct bnxt_filter_info *filter_info;
159         STAILQ_HEAD(, bnxt_filter_info) free_filter_list;
160
161         /* VNIC pointer for flow filter (VMDq) pools */
162 #define MAX_FF_POOLS    ETH_64_POOLS
163         STAILQ_HEAD(, bnxt_vnic_info)   ff_pool[MAX_FF_POOLS];
164
165         struct bnxt_irq         *irq_tbl;
166
167 #define MAX_NUM_MAC_ADDR        32
168         uint8_t                 mac_addr[ETHER_ADDR_LEN];
169
170         uint16_t                        hwrm_cmd_seq;
171         void                            *hwrm_cmd_resp_addr;
172         phys_addr_t                     hwrm_cmd_resp_dma_addr;
173         rte_spinlock_t                  hwrm_lock;
174         uint16_t                        max_req_len;
175         uint16_t                        max_resp_len;
176
177         struct bnxt_link_info   link_info;
178         struct bnxt_cos_queue_info      cos_queue[BNXT_COS_QUEUE_COUNT];
179
180         struct bnxt_pf_info             pf;
181         struct bnxt_vf_info             vf;
182         uint8_t                 port_partition_type;
183         uint8_t                 dev_stopped;
184 };
185
186 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete);
187
188 #endif