blob: c3d27b5a713af532f76f538b9462c4412981fdcd [file] [log] [blame]
Ariel Elior1ab44342013-01-01 05:22:23 +00001/* bnx2x_sriov.h: Broadcom Everest network driver.
2 *
3 * Copyright 2009-2012 Broadcom Corporation
4 *
5 * Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2, available
8 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
9 *
10 * Notwithstanding the above, under no circumstances may you combine this
11 * software in any way with any other Broadcom software provided under a
12 * license other than the GPL, without Broadcom's express prior written
13 * consent.
14 *
15 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16 * Written by: Shmulik Ravid <shmulikr@broadcom.com>
17 * Ariel Elior <ariele@broadcom.com>
18 */
19#ifndef BNX2X_SRIOV_H
20#define BNX2X_SRIOV_H
21
Ariel Elior8ca5e172013-01-01 05:22:34 +000022#include "bnx2x_vfpf.h"
23#include "bnx2x_cmn.h"
24
Ariel Elior290ca2b2013-01-01 05:22:31 +000025/* The bnx2x device structure holds vfdb structure described below.
26 * The VF array is indexed by the relative vfid.
27 */
Ariel Elior8ca5e172013-01-01 05:22:34 +000028#define BNX2X_VF_MAX_QUEUES 16
Ariel Elior290ca2b2013-01-01 05:22:31 +000029struct bnx2x_sriov {
30 u32 first_vf_in_pf;
31
32 /* standard SRIOV capability fields, mostly for debugging */
33 int pos; /* capability position */
34 int nres; /* number of resources */
35 u32 cap; /* SR-IOV Capabilities */
36 u16 ctrl; /* SR-IOV Control */
37 u16 total; /* total VFs associated with the PF */
38 u16 initial; /* initial VFs associated with the PF */
39 u16 nr_virtfn; /* number of VFs available */
40 u16 offset; /* first VF Routing ID offset */
41 u16 stride; /* following VF stride */
42 u32 pgsz; /* page size for BAR alignment */
43 u8 link; /* Function Dependency Link */
44};
45
46/* bars */
47struct bnx2x_vf_bar {
48 u64 bar;
49 u32 size;
50};
51
52/* vf queue (used both for rx or tx) */
53struct bnx2x_vf_queue {
54 struct eth_context *cxt;
55
56 /* MACs object */
57 struct bnx2x_vlan_mac_obj mac_obj;
58
59 /* VLANs object */
60 struct bnx2x_vlan_mac_obj vlan_obj;
61 atomic_t vlan_count; /* 0 means vlan-0 is set ~ untagged */
62
63 /* Queue Slow-path State object */
64 struct bnx2x_queue_sp_obj sp_obj;
65
66 u32 cid;
67 u16 index;
68 u16 sb_idx;
69};
70
71/* struct bnx2x_vfop_qctor_params - prepare queue construction parameters:
72 * q-init, q-setup and SB index
73 */
74struct bnx2x_vfop_qctor_params {
75 struct bnx2x_queue_state_params qstate;
76 struct bnx2x_queue_setup_params prep_qsetup;
77};
78
79/* VFOP parameters (one copy per VF) */
80union bnx2x_vfop_params {
81 struct bnx2x_vlan_mac_ramrod_params vlan_mac;
82 struct bnx2x_rx_mode_ramrod_params rx_mode;
83 struct bnx2x_mcast_ramrod_params mcast;
84 struct bnx2x_config_rss_params rss;
85 struct bnx2x_vfop_qctor_params qctor;
86};
87
88/* forward */
89struct bnx2x_virtf;
Ariel Eliorfd1fc792013-01-01 05:22:33 +000090
91/* VFOP definitions */
92typedef void (*vfop_handler_t)(struct bnx2x *bp, struct bnx2x_virtf *vf);
93
94/* VFOP queue filters command additional arguments */
95struct bnx2x_vfop_filter {
96 struct list_head link;
97 int type;
98#define BNX2X_VFOP_FILTER_MAC 1
99#define BNX2X_VFOP_FILTER_VLAN 2
100
101 bool add;
102 u8 *mac;
103 u16 vid;
104};
105
106struct bnx2x_vfop_filters {
107 int add_cnt;
108 struct list_head head;
109 struct bnx2x_vfop_filter filters[];
110};
111
112/* transient list allocated, built and saved until its
113 * passed to the SP-VERBs layer.
114 */
115struct bnx2x_vfop_args_mcast {
116 int mc_num;
117 struct bnx2x_mcast_list_elem *mc;
118};
119
120struct bnx2x_vfop_args_qctor {
121 int qid;
122 u16 sb_idx;
123};
124
125struct bnx2x_vfop_args_qdtor {
126 int qid;
127 struct eth_context *cxt;
128};
129
130struct bnx2x_vfop_args_defvlan {
131 int qid;
132 bool enable;
133 u16 vid;
134 u8 prio;
135};
136
137struct bnx2x_vfop_args_qx {
138 int qid;
139 bool en_add;
140};
141
142struct bnx2x_vfop_args_filters {
143 struct bnx2x_vfop_filters *multi_filter;
144 atomic_t *credit; /* non NULL means 'don't consume credit' */
145};
146
147union bnx2x_vfop_args {
148 struct bnx2x_vfop_args_mcast mc_list;
149 struct bnx2x_vfop_args_qctor qctor;
150 struct bnx2x_vfop_args_qdtor qdtor;
151 struct bnx2x_vfop_args_defvlan defvlan;
152 struct bnx2x_vfop_args_qx qx;
153 struct bnx2x_vfop_args_filters filters;
154};
155
156struct bnx2x_vfop {
157 struct list_head link;
158 int rc; /* return code */
159 int state; /* next state */
160 union bnx2x_vfop_args args; /* extra arguments */
161 union bnx2x_vfop_params *op_p; /* ramrod params */
162
163 /* state machine callbacks */
164 vfop_handler_t transition;
165 vfop_handler_t done;
166};
167
Ariel Elior290ca2b2013-01-01 05:22:31 +0000168/* vf context */
169struct bnx2x_virtf {
170 u16 cfg_flags;
171#define VF_CFG_STATS 0x0001
172#define VF_CFG_FW_FC 0x0002
173#define VF_CFG_TPA 0x0004
174#define VF_CFG_INT_SIMD 0x0008
175#define VF_CACHE_LINE 0x0010
176
177 u8 state;
178#define VF_FREE 0 /* VF ready to be acquired holds no resc */
179#define VF_ACQUIRED 1 /* VF aquired, but not initalized */
180#define VF_ENABLED 2 /* VF Enabled */
181#define VF_RESET 3 /* VF FLR'd, pending cleanup */
182
183 /* non 0 during flr cleanup */
184 u8 flr_clnup_stage;
185#define VF_FLR_CLN 1 /* reclaim resources and do 'final cleanup'
186 * sans the end-wait
187 */
188#define VF_FLR_ACK 2 /* ACK flr notification */
189#define VF_FLR_EPILOG 3 /* wait for VF remnants to dissipate in the HW
190 * ~ final cleanup' end wait
191 */
192
193 /* dma */
194 dma_addr_t fw_stat_map; /* valid iff VF_CFG_STATS */
195 dma_addr_t spq_map;
196 dma_addr_t bulletin_map;
197
198 /* Allocated resources counters. Before the VF is acquired, the
199 * counters hold the following values:
200 *
201 * - xxq_count = 0 as the queues memory is not allocated yet.
202 *
203 * - sb_count = The number of status blocks configured for this VF in
204 * the IGU CAM. Initially read during probe.
205 *
206 * - xx_rules_count = The number of rules statically and equally
207 * allocated for each VF, during PF load.
208 */
209 struct vf_pf_resc_request alloc_resc;
210#define vf_rxq_count(vf) ((vf)->alloc_resc.num_rxqs)
211#define vf_txq_count(vf) ((vf)->alloc_resc.num_txqs)
212#define vf_sb_count(vf) ((vf)->alloc_resc.num_sbs)
213#define vf_mac_rules_cnt(vf) ((vf)->alloc_resc.num_mac_filters)
214#define vf_vlan_rules_cnt(vf) ((vf)->alloc_resc.num_vlan_filters)
215#define vf_mc_rules_cnt(vf) ((vf)->alloc_resc.num_mc_filters)
216
217 u8 sb_count; /* actual number of SBs */
218 u8 igu_base_id; /* base igu status block id */
219
220 struct bnx2x_vf_queue *vfqs;
221#define bnx2x_vfq(vf, nr, var) ((vf)->vfqs[(nr)].var)
222
223 u8 index; /* index in the vf array */
224 u8 abs_vfid;
225 u8 sp_cl_id;
226 u32 error; /* 0 means all's-well */
227
228 /* BDF */
229 unsigned int bus;
230 unsigned int devfn;
231
232 /* bars */
233 struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
234
235 /* set-mac ramrod state 1-pending, 0-done */
236 unsigned long filter_state;
237
238 /* leading rss client id ~~ the client id of the first rxq, must be
239 * set for each txq.
240 */
241 int leading_rss;
242
243 /* MCAST object */
244 struct bnx2x_mcast_obj mcast_obj;
245
246 /* RSS configuration object */
247 struct bnx2x_rss_config_obj rss_conf_obj;
248
249 /* slow-path operations */
250 atomic_t op_in_progress;
251 int op_rc;
252 bool op_wait_blocking;
253 struct list_head op_list_head;
254 union bnx2x_vfop_params op_params;
255 struct mutex op_mutex; /* one vfop at a time mutex */
256 enum channel_tlvs op_current;
257};
258
259#define BNX2X_NR_VIRTFN(bp) ((bp)->vfdb->sriov.nr_virtfn)
260
261#define for_each_vf(bp, var) \
262 for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
263
Ariel Elior8ca5e172013-01-01 05:22:34 +0000264#define for_each_vfq(vf, var) \
265 for ((var) = 0; (var) < vf_rxq_count(vf); (var)++)
266
267#define for_each_vf_sb(vf, var) \
268 for ((var) = 0; (var) < vf_sb_count(vf); (var)++)
269
Ariel Eliorb93288d2013-01-01 05:22:35 +0000270#define is_vf_multi(vf) (vf_rxq_count(vf) > 1)
271
Ariel Eliorb56e9672013-01-01 05:22:32 +0000272#define HW_VF_HANDLE(bp, abs_vfid) \
273 (u16)(BP_ABS_FUNC((bp)) | (1<<3) | ((u16)(abs_vfid) << 4))
274
275#define FW_PF_MAX_HANDLE 8
276
277#define FW_VF_HANDLE(abs_vfid) \
278 (abs_vfid + FW_PF_MAX_HANDLE)
279
Ariel Elior8ca5e172013-01-01 05:22:34 +0000280/* locking and unlocking the channel mutex */
281void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
282 enum channel_tlvs tlv);
283
284void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
285 enum channel_tlvs expected_tlv);
286
Ariel Eliorb56e9672013-01-01 05:22:32 +0000287/* VF mail box (aka vf-pf channel) */
288
289/* a container for the bi-directional vf<-->pf messages.
290 * The actual response will be placed according to the offset parameter
291 * provided in the request
292 */
293
294#define MBX_MSG_ALIGN 8
295#define MBX_MSG_ALIGNED_SIZE (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
296 MBX_MSG_ALIGN))
297
Ariel Elior1ab44342013-01-01 05:22:23 +0000298struct bnx2x_vf_mbx_msg {
299 union vfpf_tlvs req;
300 union pfvf_tlvs resp;
301};
302
Ariel Elior290ca2b2013-01-01 05:22:31 +0000303struct bnx2x_vf_mbx {
304 struct bnx2x_vf_mbx_msg *msg;
305 dma_addr_t msg_mapping;
306
307 /* VF GPA address */
308 u32 vf_addr_lo;
309 u32 vf_addr_hi;
310
311 struct vfpf_first_tlv first_tlv; /* saved VF request header */
312
313 u8 flags;
314#define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
315 * more then one pending msg
316 */
317};
318
Ariel Eliorb56e9672013-01-01 05:22:32 +0000319struct bnx2x_vf_sp {
320 union {
321 struct eth_classify_rules_ramrod_data e2;
322 } mac_rdata;
323
324 union {
325 struct eth_classify_rules_ramrod_data e2;
326 } vlan_rdata;
327
328 union {
329 struct eth_filter_rules_ramrod_data e2;
330 } rx_mode_rdata;
331
332 union {
333 struct eth_multicast_rules_ramrod_data e2;
334 } mcast_rdata;
335
336 union {
337 struct client_init_ramrod_data init_data;
338 struct client_update_ramrod_data update_data;
339 } q_data;
340};
341
Ariel Elior290ca2b2013-01-01 05:22:31 +0000342struct hw_dma {
343 void *addr;
344 dma_addr_t mapping;
345 size_t size;
346};
347
348struct bnx2x_vfdb {
349#define BP_VFDB(bp) ((bp)->vfdb)
350 /* vf array */
351 struct bnx2x_virtf *vfs;
352#define BP_VF(bp, idx) (&((bp)->vfdb->vfs[(idx)]))
353#define bnx2x_vf(bp, idx, var) ((bp)->vfdb->vfs[(idx)].var)
354
355 /* queue array - for all vfs */
356 struct bnx2x_vf_queue *vfqs;
357
358 /* vf HW contexts */
359 struct hw_dma context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
360#define BP_VF_CXT_PAGE(bp, i) (&(bp)->vfdb->context[(i)])
361
362 /* SR-IOV information */
363 struct bnx2x_sriov sriov;
364 struct hw_dma mbx_dma;
365#define BP_VF_MBX_DMA(bp) (&((bp)->vfdb->mbx_dma))
366 struct bnx2x_vf_mbx mbxs[BNX2X_MAX_NUM_OF_VFS];
367#define BP_VF_MBX(bp, vfid) (&((bp)->vfdb->mbxs[(vfid)]))
368
369 struct hw_dma sp_dma;
370#define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
371 (vf)->index * sizeof(struct bnx2x_vf_sp) + \
372 offsetof(struct bnx2x_vf_sp, field))
373#define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
374 (vf)->index * sizeof(struct bnx2x_vf_sp) + \
375 offsetof(struct bnx2x_vf_sp, field))
376
377#define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
378 u32 flrd_vfs[FLRD_VFS_DWORDS];
379};
380
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000381/* queue access */
382static inline struct bnx2x_vf_queue *vfq_get(struct bnx2x_virtf *vf, u8 index)
383{
384 return &(vf->vfqs[index]);
385}
386
Ariel Elior8ca5e172013-01-01 05:22:34 +0000387static inline bool vfq_is_leading(struct bnx2x_vf_queue *vfq)
388{
389 return (vfq->index == 0);
390}
391
392/* FW ids */
Ariel Eliorb56e9672013-01-01 05:22:32 +0000393static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
394{
395 return vf->igu_base_id + sb_idx;
396}
397
Ariel Elior8ca5e172013-01-01 05:22:34 +0000398static inline u8 vf_hc_qzone(struct bnx2x_virtf *vf, u16 sb_idx)
399{
400 return vf_igu_sb(vf, sb_idx);
401}
402
403static u8 vfq_cl_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
404{
405 return vf->igu_base_id + q->index;
406}
407
408static inline u8 vfq_qzone_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
409{
410 return vfq_cl_id(vf, q);
411}
412
Ariel Elior290ca2b2013-01-01 05:22:31 +0000413/* global iov routines */
414int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
415int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
416void bnx2x_iov_remove_one(struct bnx2x *bp);
Ariel Eliorb56e9672013-01-01 05:22:32 +0000417void bnx2x_iov_free_mem(struct bnx2x *bp);
418int bnx2x_iov_alloc_mem(struct bnx2x *bp);
419int bnx2x_iov_nic_init(struct bnx2x *bp);
420void bnx2x_iov_init_dq(struct bnx2x *bp);
421void bnx2x_iov_init_dmae(struct bnx2x *bp);
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000422void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
423 struct bnx2x_queue_sp_obj **q_obj);
424void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work);
425int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem);
Ariel Elior67c431a2013-01-01 05:22:36 +0000426void bnx2x_iov_adjust_stats_req(struct bnx2x *bp);
427void bnx2x_iov_storm_stats_update(struct bnx2x *bp);
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000428void bnx2x_iov_sp_task(struct bnx2x *bp);
429/* global vf mailbox routines */
430void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event);
Ariel Eliorb56e9672013-01-01 05:22:32 +0000431void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
Ariel Elior8ca5e172013-01-01 05:22:34 +0000432/* acquire */
433int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
Ariel Eliorb93288d2013-01-01 05:22:35 +0000434 struct vf_pf_resc_request *resc);
435/* init */
436int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
437 dma_addr_t *sb_map);
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000438static inline struct bnx2x_vfop *bnx2x_vfop_cur(struct bnx2x *bp,
439 struct bnx2x_virtf *vf)
440{
441 WARN(!mutex_is_locked(&vf->op_mutex), "about to access vf op linked list but mutex was not locked!");
442 WARN_ON(list_empty(&vf->op_list_head));
443 return list_first_entry(&vf->op_list_head, struct bnx2x_vfop, link);
444}
445
Ariel Elior290ca2b2013-01-01 05:22:31 +0000446int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
Ariel Elior8ca5e172013-01-01 05:22:34 +0000447u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf);
Ariel Eliorb56e9672013-01-01 05:22:32 +0000448/* VF FLR helpers */
449int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
450void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
Ariel Eliorbe1f1ffa2013-01-01 05:22:24 +0000451void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
452 u16 length);
453void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
454 u16 type, u16 length);
455void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list);
Ariel Eliorfd1fc792013-01-01 05:22:33 +0000456
457bool bnx2x_tlv_supported(u16 tlvtype);
458
Ariel Elior1ab44342013-01-01 05:22:23 +0000459#endif /* bnx2x_sriov.h */