Imported Upstream version 16.07-rc2
[deb_dpdk.git] / drivers / net / bnx2x / bnx2x_vfpf.h
1 /*
2  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
3  *
4  * Copyright (c) 2015 QLogic Corporation.
5  * All rights reserved.
6  * www.qlogic.com
7  *
8  * See LICENSE.bnx2x_pmd for copyright and licensing details.
9  */
10
11 #ifndef BNX2X_VFPF_H
12 #define BNX2X_VFPF_H
13
14 #include "ecore_sp.h"
15
16 #define VLAN_HLEN 4
17
18 struct vf_resource_query {
19         uint8_t num_rxqs;
20         uint8_t num_txqs;
21         uint8_t num_sbs;
22         uint8_t num_mac_filters;
23         uint8_t num_vlan_filters;
24         uint8_t num_mc_filters;
25 };
26
27 #define BNX2X_VF_STATUS_SUCCESS         1
28 #define BNX2X_VF_STATUS_FAILURE         2
29 #define BNX2X_VF_STATUS_NO_RESOURCES    4
30 #define BNX2X_VF_BULLETIN_TRIES         5
31
32 #define BNX2X_VF_Q_FLAG_CACHE_ALIGN     0x0008
33 #define BNX2X_VF_Q_FLAG_STATS           0x0010
34 #define BNX2X_VF_Q_FLAG_OV              0x0020
35 #define BNX2X_VF_Q_FLAG_VLAN            0x0040
36 #define BNX2X_VF_Q_FLAG_COS             0x0080
37 #define BNX2X_VF_Q_FLAG_HC              0x0100
38 #define BNX2X_VF_Q_FLAG_DHC             0x0200
39 #define BNX2X_VF_Q_FLAG_LEADING_RSS     0x0400
40
41 #define TLV_BUFFER_SIZE                 1024
42
43 /* general tlv header (used for both vf->pf request and pf->vf response) */
44 struct channel_tlv {
45         uint16_t type;
46         uint16_t length;
47 };
48
49 struct vf_first_tlv {
50         uint16_t type;
51         uint16_t length;
52         uint32_t reply_offset;
53 };
54
55 struct tlv_buffer_size {
56         uint8_t tlv_buffer[TLV_BUFFER_SIZE];
57 };
58
59 /* tlv struct for all PF replies except acquire */
60 struct vf_common_reply_tlv {
61         uint16_t type;
62         uint16_t length;
63         uint8_t status;
64         uint8_t pad[3];
65 };
66
67 /* used to terminate and pad a tlv list */
68 struct channel_list_end_tlv {
69         uint16_t type;
70         uint16_t length;
71         uint32_t pad;
72 };
73
74 /* Acquire */
75 struct vf_acquire_tlv {
76         struct vf_first_tlv first_tlv;
77
78         uint8_t vf_id;
79         uint8_t pad[3];
80
81         struct vf_resource_query res_query;
82
83         uint64_t bulletin_addr;
84 };
85
86 /* simple operation request on queue */
87 struct vf_q_op_tlv {
88         struct vf_first_tlv     first_tlv;
89         uint8_t vf_qid;
90         uint8_t pad[3];
91 };
92
93 /* receive side scaling tlv */
94 struct vf_rss_tlv {
95         struct vf_first_tlv     first_tlv;
96         uint32_t                rss_flags;
97         uint8_t                 rss_result_mask;
98         uint8_t                 ind_table_size;
99         uint8_t                 rss_key_size;
100         uint8_t                 pad;
101         uint8_t                 ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
102         uint32_t                rss_key[T_ETH_RSS_KEY]; /* hash values */
103 };
104
105 struct vf_resc {
106 #define BNX2X_VF_MAX_QUEUES_PER_VF         16
107 #define BNX2X_VF_MAX_SBS_PER_VF            16
108         uint16_t hw_sbs[BNX2X_VF_MAX_SBS_PER_VF];
109         uint8_t hw_qid[BNX2X_VF_MAX_QUEUES_PER_VF];
110         uint8_t num_rxqs;
111         uint8_t num_txqs;
112         uint8_t num_sbs;
113         uint8_t num_mac_filters;
114         uint8_t num_vlan_filters;
115         uint8_t num_mc_filters;
116         uint8_t permanent_mac_addr[ETH_ALEN];
117         struct ether_addr current_mac_addr;
118         uint16_t pf_link_speed;
119         uint32_t pf_link_supported;
120 };
121
122 /* tlv struct holding reply for acquire */
123 struct vf_acquire_resp_tlv {
124         uint16_t type;
125         uint16_t length;
126         uint8_t status;
127         uint8_t pad1[3];
128         uint32_t chip_num;
129         uint8_t pad2[4];
130         char fw_ver[32];
131         uint16_t db_size;
132         uint8_t pad3[2];
133         struct vf_resc resc;
134 };
135
136 /* Init VF */
137 struct vf_init_tlv {
138         struct vf_first_tlv first_tlv;
139         uint64_t sb_addr[BNX2X_VF_MAX_SBS_PER_VF];
140         uint64_t spq_addr;
141         uint64_t stats_addr;
142         uint16_t stats_step;
143         uint32_t flags;
144         uint32_t pad[2];
145 };
146
147 struct vf_rxq_params {
148         /* physical addresses */
149         uint64_t rcq_addr;
150         uint64_t rcq_np_addr;
151         uint64_t rxq_addr;
152         uint64_t pad1;
153
154         /* sb + hc info */
155         uint8_t  vf_sb_id;
156         uint8_t  sb_cq_index;
157         uint16_t hc_rate;       /* desired interrupts per sec. */
158         /* rx buffer info */
159         uint16_t mtu;
160         uint16_t buf_sz;
161         uint16_t flags;         /* for BNX2X_VF_Q_FLAG_X flags */
162         uint16_t stat_id;       /* valid if BNX2X_VF_Q_FLAG_STATS */
163
164         uint8_t pad2[5];
165
166         uint8_t drop_flags;
167         uint8_t cache_line_log; /* BNX2X_VF_Q_FLAG_CACHE_ALIGN */
168         uint8_t pad3;
169 };
170
171 struct vf_txq_params {
172         /* physical addresses */
173         uint64_t txq_addr;
174
175         /* sb + hc info */
176         uint8_t  vf_sb_id;      /* index in hw_sbs[] */
177         uint8_t  sb_index;      /* Index in the SB */
178         uint16_t hc_rate;       /* desired interrupts per sec. */
179         uint32_t flags;         /* for BNX2X_VF_Q_FLAG_X flags */
180         uint16_t stat_id;       /* valid if BNX2X_VF_Q_FLAG_STATS */
181         uint8_t  traffic_type;  /* see in setup_context() */
182         uint8_t  pad;
183 };
184
185 /* Setup Queue */
186 struct vf_setup_q_tlv {
187         struct vf_first_tlv first_tlv;
188
189         struct vf_rxq_params rxq;
190         struct vf_txq_params txq;
191
192         uint8_t vf_qid;                 /* index in hw_qid[] */
193         uint8_t param_valid;
194         #define VF_RXQ_VALID            0x01
195         #define VF_TXQ_VALID            0x02
196         uint8_t pad[2];
197 };
198
199 /* Set Queue Filters */
200 struct vf_q_mac_vlan_filter {
201         uint32_t flags;
202         #define BNX2X_VF_Q_FILTER_DEST_MAC_VALID        0x01
203         #define BNX2X_VF_Q_FILTER_VLAN_TAG_VALID        0x02
204         #define BNX2X_VF_Q_FILTER_SET_MAC               0x100   /* set/clear */
205         uint8_t  mac[ETH_ALEN];
206         uint16_t vlan_tag;
207 };
208
209
210 #define _UP_ETH_ALEN    (6)
211
212 /* configure queue filters */
213 struct vf_set_q_filters_tlv {
214         struct vf_first_tlv first_tlv;
215
216         uint32_t flags;
217         #define BNX2X_VF_MAC_VLAN_CHANGED       0x01
218         #define BNX2X_VF_MULTICAST_CHANGED      0x02
219         #define BNX2X_VF_RX_MASK_CHANGED        0x04
220
221         uint8_t vf_qid;                 /* index in hw_qid[] */
222         uint8_t mac_filters_cnt;
223         uint8_t multicast_cnt;
224         uint8_t pad;
225
226         #define VF_MAX_MAC_FILTERS                      16
227         #define VF_MAX_VLAN_FILTERS                     16
228         #define VF_MAX_FILTERS                  (VF_MAX_MAC_FILTERS +\
229                                                         VF_MAX_VLAN_FILTERS)
230         struct vf_q_mac_vlan_filter filters[VF_MAX_FILTERS];
231
232         #define VF_MAX_MULTICAST_PER_VF                 32
233         uint8_t  multicast[VF_MAX_MULTICAST_PER_VF][_UP_ETH_ALEN];
234         unsigned long rx_mask;
235 };
236
237
238 /* close VF (disable VF) */
239 struct vf_close_tlv {
240         struct vf_first_tlv     first_tlv;
241         uint16_t                vf_id;  /* for debug */
242         uint8_t pad[2];
243 };
244
245 /* rlease the VF's acquired resources */
246 struct vf_release_tlv {
247         struct vf_first_tlv   first_tlv;
248         uint16_t                vf_id;  /* for debug */
249         uint8_t pad[2];
250 };
251
252 union query_tlvs {
253         struct vf_first_tlv             first_tlv;
254         struct vf_acquire_tlv           acquire;
255         struct vf_init_tlv              init;
256         struct vf_close_tlv             close;
257         struct vf_q_op_tlv              q_op;
258         struct vf_setup_q_tlv           setup_q;
259         struct vf_set_q_filters_tlv     set_q_filters;
260         struct vf_release_tlv           release;
261         struct vf_rss_tlv               update_rss;
262         struct channel_list_end_tlv     list_end;
263         struct tlv_buffer_size          tlv_buf_size;
264 };
265
266 union resp_tlvs {
267         struct vf_common_reply_tlv      common_reply;
268         struct vf_acquire_resp_tlv      acquire_resp;
269         struct channel_list_end_tlv     list_end;
270         struct tlv_buffer_size          tlv_buf_size;
271 };
272
273 /* struct allocated by VF driver, PF sends updates to VF via bulletin */
274 struct bnx2x_vf_bulletin {
275         uint32_t crc;                   /* crc of structure to ensure is not in
276                                          * mid-update
277                                          */
278         uint16_t version;
279         uint16_t length;
280
281         uint64_t valid_bitmap;  /* bitmap indicating wich fields
282                                          * hold valid values
283                                          */
284
285 #define MAC_ADDR_VALID          0       /* alert the vf that a new mac address
286                                          * is available for it
287                                          */
288 #define VLAN_VALID              1       /* when set, the vf should no access the
289                                          * vf channel
290                                          */
291 #define CHANNEL_DOWN            2       /* vf channel is disabled. VFs are not
292                                          * to attempt to send messages on the
293                                          * channel after this bit is set
294                                          */
295         uint8_t mac[ETH_ALEN];
296         uint8_t mac_pad[2];
297
298         uint16_t vlan;
299         uint8_t vlan_pad[6];
300 };
301
302 #define MAX_TLVS_IN_LIST 50
303 enum channel_tlvs {
304         BNX2X_VF_TLV_NONE, /* ends tlv sequence */
305         BNX2X_VF_TLV_ACQUIRE,
306         BNX2X_VF_TLV_INIT,
307         BNX2X_VF_TLV_SETUP_Q,
308         BNX2X_VF_TLV_SET_Q_FILTERS,
309         BNX2X_VF_TLV_ACTIVATE_Q,
310         BNX2X_VF_TLV_DEACTIVATE_Q,
311         BNX2X_VF_TLV_TEARDOWN_Q,
312         BNX2X_VF_TLV_CLOSE,
313         BNX2X_VF_TLV_RELEASE,
314         BNX2X_VF_TLV_UPDATE_RSS_OLD,
315         BNX2X_VF_TLV_PF_RELEASE_VF,
316         BNX2X_VF_TLV_LIST_END,
317         BNX2X_VF_TLV_FLR,
318         BNX2X_VF_TLV_PF_SET_MAC,
319         BNX2X_VF_TLV_PF_SET_VLAN,
320         BNX2X_VF_TLV_UPDATE_RSS,
321         BNX2X_VF_TLV_PHYS_PORT_ID,
322         BNX2X_VF_TLV_MAX
323 };
324
325 struct bnx2x_vf_mbx_msg {
326         union query_tlvs query[BNX2X_VF_MAX_QUEUES_PER_VF];
327         union resp_tlvs resp;
328 };
329
330 void bnx2x_add_tlv(void *tlvs_list, uint16_t offset, uint16_t type, uint16_t length);
331 int bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set);
332 int bnx2x_vf_config_rss(struct bnx2x_softc *sc, struct ecore_config_rss_params *params);
333
334 #endif /* BNX2X_VFPF_H */