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