1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef BNX2X_SRIOV_H
20#define BNX2X_SRIOV_H
21
22#include "bnx2x_vfpf.h"
23#include "bnx2x.h"
24
25enum sample_bulletin_result {
26 PFVF_BULLETIN_UNCHANGED,
27 PFVF_BULLETIN_UPDATED,
28 PFVF_BULLETIN_CRC_ERR
29};
30
31#ifdef CONFIG_BNX2X_SRIOV
32
33extern struct workqueue_struct *bnx2x_iov_wq;
34
35
36
37
38#define BNX2X_VF_MAX_QUEUES 16
39#define BNX2X_VF_MAX_TPA_AGG_QUEUES 8
40
41struct bnx2x_sriov {
42 u32 first_vf_in_pf;
43
44
45 int pos;
46 int nres;
47 u32 cap;
48 u16 ctrl;
49 u16 total;
50 u16 initial;
51 u16 nr_virtfn;
52 u16 offset;
53 u16 stride;
54 u32 pgsz;
55 u8 link;
56};
57
58
59struct bnx2x_vf_bar {
60 u64 bar;
61 u32 size;
62};
63
64struct bnx2x_vf_bar_info {
65 struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
66 u8 nr_bars;
67};
68
69
70struct bnx2x_vf_queue {
71 struct eth_context *cxt;
72
73
74 struct bnx2x_vlan_mac_obj mac_obj;
75
76
77 struct bnx2x_vlan_mac_obj vlan_obj;
78 atomic_t vlan_count;
79 unsigned long accept_flags;
80
81
82 struct bnx2x_queue_sp_obj sp_obj;
83
84 u32 cid;
85 u16 index;
86 u16 sb_idx;
87 bool is_leading;
88 bool sp_initialized;
89};
90
91
92
93
94struct bnx2x_vf_queue_construct_params {
95 struct bnx2x_queue_state_params qstate;
96 struct bnx2x_queue_setup_params prep_qsetup;
97};
98
99
100struct bnx2x_virtf;
101
102
103
104struct bnx2x_vf_mac_vlan_filter {
105 int type;
106#define BNX2X_VF_FILTER_MAC 1
107#define BNX2X_VF_FILTER_VLAN 2
108
109 bool add;
110 u8 *mac;
111 u16 vid;
112};
113
114struct bnx2x_vf_mac_vlan_filters {
115 int count;
116 struct bnx2x_vf_mac_vlan_filter filters[];
117};
118
119
120struct bnx2x_virtf {
121 u16 cfg_flags;
122#define VF_CFG_STATS 0x0001
123#define VF_CFG_FW_FC 0x0002
124#define VF_CFG_TPA 0x0004
125#define VF_CFG_INT_SIMD 0x0008
126#define VF_CACHE_LINE 0x0010
127#define VF_CFG_VLAN 0x0020
128#define VF_CFG_STATS_COALESCE 0x0040
129
130 u8 state;
131#define VF_FREE 0
132#define VF_ACQUIRED 1
133#define VF_ENABLED 2
134#define VF_RESET 3
135
136 bool flr_clnup_stage;
137
138
139 dma_addr_t fw_stat_map;
140 u16 stats_stride;
141 dma_addr_t spq_map;
142 dma_addr_t bulletin_map;
143
144
145
146
147
148
149
150
151
152
153
154
155 struct vf_pf_resc_request alloc_resc;
156#define vf_rxq_count(vf) ((vf)->alloc_resc.num_rxqs)
157#define vf_txq_count(vf) ((vf)->alloc_resc.num_txqs)
158#define vf_sb_count(vf) ((vf)->alloc_resc.num_sbs)
159#define vf_mac_rules_cnt(vf) ((vf)->alloc_resc.num_mac_filters)
160#define vf_vlan_rules_cnt(vf) ((vf)->alloc_resc.num_vlan_filters)
161#define vf_mc_rules_cnt(vf) ((vf)->alloc_resc.num_mc_filters)
162
163#define vf_vlan_rules_visible_cnt(vf) (vf_vlan_rules_cnt(vf) - 1)
164
165 u8 sb_count;
166 u8 igu_base_id;
167
168 struct bnx2x_vf_queue *vfqs;
169#define LEADING_IDX 0
170#define bnx2x_vfq_is_leading(vfq) ((vfq)->index == LEADING_IDX)
171#define bnx2x_vfq(vf, nr, var) ((vf)->vfqs[(nr)].var)
172#define bnx2x_leading_vfq(vf, var) ((vf)->vfqs[LEADING_IDX].var)
173
174 u8 index;
175 u8 abs_vfid;
176 u8 sp_cl_id;
177 u32 error;
178
179
180 unsigned int bus;
181 unsigned int devfn;
182
183
184 struct bnx2x_vf_bar bars[PCI_SRIOV_NUM_BARS];
185
186
187 unsigned long filter_state;
188
189
190
191
192 int leading_rss;
193
194
195 int mcast_list_len;
196 struct bnx2x_mcast_obj mcast_obj;
197
198
199 struct bnx2x_rss_config_obj rss_conf_obj;
200
201
202 struct mutex op_mutex;
203 enum channel_tlvs op_current;
204};
205
206#define BNX2X_NR_VIRTFN(bp) ((bp)->vfdb->sriov.nr_virtfn)
207
208#define for_each_vf(bp, var) \
209 for ((var) = 0; (var) < BNX2X_NR_VIRTFN(bp); (var)++)
210
211#define for_each_vfq(vf, var) \
212 for ((var) = 0; (var) < vf_rxq_count(vf); (var)++)
213
214#define for_each_vf_sb(vf, var) \
215 for ((var) = 0; (var) < vf_sb_count(vf); (var)++)
216
217#define is_vf_multi(vf) (vf_rxq_count(vf) > 1)
218
219#define HW_VF_HANDLE(bp, abs_vfid) \
220 (u16)(BP_ABS_FUNC((bp)) | (1<<3) | ((u16)(abs_vfid) << 4))
221
222#define FW_PF_MAX_HANDLE 8
223
224#define FW_VF_HANDLE(abs_vfid) \
225 (abs_vfid + FW_PF_MAX_HANDLE)
226
227
228void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
229 enum channel_tlvs tlv);
230
231void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
232 enum channel_tlvs expected_tlv);
233
234
235
236
237
238
239
240
241#define MBX_MSG_ALIGN 8
242#define MBX_MSG_ALIGNED_SIZE (roundup(sizeof(struct bnx2x_vf_mbx_msg), \
243 MBX_MSG_ALIGN))
244
245struct bnx2x_vf_mbx_msg {
246 union vfpf_tlvs req;
247 union pfvf_tlvs resp;
248};
249
250struct bnx2x_vf_mbx {
251 struct bnx2x_vf_mbx_msg *msg;
252 dma_addr_t msg_mapping;
253
254
255 u32 vf_addr_lo;
256 u32 vf_addr_hi;
257
258 struct vfpf_first_tlv first_tlv;
259};
260
261struct bnx2x_vf_sp {
262 union {
263 struct eth_classify_rules_ramrod_data e2;
264 } mac_rdata;
265
266 union {
267 struct eth_classify_rules_ramrod_data e2;
268 } vlan_rdata;
269
270 union {
271 struct eth_filter_rules_ramrod_data e2;
272 } rx_mode_rdata;
273
274 union {
275 struct eth_multicast_rules_ramrod_data e2;
276 } mcast_rdata;
277
278 union {
279 struct client_init_ramrod_data init_data;
280 struct client_update_ramrod_data update_data;
281 } q_data;
282
283 union {
284 struct eth_rss_update_ramrod_data e2;
285 } rss_rdata;
286};
287
288struct hw_dma {
289 void *addr;
290 dma_addr_t mapping;
291 size_t size;
292};
293
294struct bnx2x_vfdb {
295#define BP_VFDB(bp) ((bp)->vfdb)
296
297 struct bnx2x_virtf *vfs;
298#define BP_VF(bp, idx) (&((bp)->vfdb->vfs[(idx)]))
299#define bnx2x_vf(bp, idx, var) ((bp)->vfdb->vfs[(idx)].var)
300
301
302 struct bnx2x_vf_queue *vfqs;
303
304
305 struct hw_dma context[BNX2X_VF_CIDS/ILT_PAGE_CIDS];
306#define BP_VF_CXT_PAGE(bp, i) (&(bp)->vfdb->context[(i)])
307
308
309 struct bnx2x_sriov sriov;
310 struct hw_dma mbx_dma;
311#define BP_VF_MBX_DMA(bp) (&((bp)->vfdb->mbx_dma))
312 struct bnx2x_vf_mbx mbxs[BNX2X_MAX_NUM_OF_VFS];
313#define BP_VF_MBX(bp, vfid) (&((bp)->vfdb->mbxs[(vfid)]))
314
315 struct hw_dma bulletin_dma;
316#define BP_VF_BULLETIN_DMA(bp) (&((bp)->vfdb->bulletin_dma))
317#define BP_VF_BULLETIN(bp, vf) \
318 (((struct pf_vf_bulletin_content *)(BP_VF_BULLETIN_DMA(bp)->addr)) \
319 + (vf))
320
321 struct hw_dma sp_dma;
322#define bnx2x_vf_sp(bp, vf, field) ((bp)->vfdb->sp_dma.addr + \
323 (vf)->index * sizeof(struct bnx2x_vf_sp) + \
324 offsetof(struct bnx2x_vf_sp, field))
325#define bnx2x_vf_sp_map(bp, vf, field) ((bp)->vfdb->sp_dma.mapping + \
326 (vf)->index * sizeof(struct bnx2x_vf_sp) + \
327 offsetof(struct bnx2x_vf_sp, field))
328
329#define FLRD_VFS_DWORDS (BNX2X_MAX_NUM_OF_VFS / 32)
330 u32 flrd_vfs[FLRD_VFS_DWORDS];
331
332
333 u16 vf_sbs_pool;
334 u16 first_vf_igu_entry;
335
336
337 struct mutex event_mutex;
338 u64 event_occur;
339};
340
341
342static inline struct bnx2x_vf_queue *vfq_get(struct bnx2x_virtf *vf, u8 index)
343{
344 return &(vf->vfqs[index]);
345}
346
347
348static inline u8 vf_igu_sb(struct bnx2x_virtf *vf, u16 sb_idx)
349{
350 return vf->igu_base_id + sb_idx;
351}
352
353static inline u8 vf_hc_qzone(struct bnx2x_virtf *vf, u16 sb_idx)
354{
355 return vf_igu_sb(vf, sb_idx);
356}
357
358static u8 vfq_cl_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
359{
360 return vf->igu_base_id + q->index;
361}
362
363static inline u8 vfq_stat_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
364{
365 if (vf->cfg_flags & VF_CFG_STATS_COALESCE)
366 return vf->leading_rss;
367 else
368 return vfq_cl_id(vf, q);
369}
370
371static inline u8 vfq_qzone_id(struct bnx2x_virtf *vf, struct bnx2x_vf_queue *q)
372{
373 return vfq_cl_id(vf, q);
374}
375
376
377int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line);
378int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, int num_vfs_param);
379void bnx2x_iov_remove_one(struct bnx2x *bp);
380void bnx2x_iov_free_mem(struct bnx2x *bp);
381int bnx2x_iov_alloc_mem(struct bnx2x *bp);
382int bnx2x_iov_nic_init(struct bnx2x *bp);
383int bnx2x_iov_chip_cleanup(struct bnx2x *bp);
384void bnx2x_iov_init_dq(struct bnx2x *bp);
385void bnx2x_iov_init_dmae(struct bnx2x *bp);
386void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
387 struct bnx2x_queue_sp_obj **q_obj);
388int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem);
389void bnx2x_iov_adjust_stats_req(struct bnx2x *bp);
390void bnx2x_iov_storm_stats_update(struct bnx2x *bp);
391
392void bnx2x_vf_mbx(struct bnx2x *bp);
393void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
394 struct vf_pf_event_data *vfpf_event);
395void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid);
396
397
398typedef u8 bnx2x_mac_addr_t[ETH_ALEN];
399
400
401int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
402 struct vf_pf_resc_request *resc);
403
404int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
405 dma_addr_t *sb_map);
406
407
408void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
409 struct bnx2x_queue_init_params *init_params,
410 struct bnx2x_queue_setup_params *setup_params,
411 u16 q_idx, u16 sb_idx);
412
413void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
414 struct bnx2x_queue_init_params *init_params,
415 struct bnx2x_queue_setup_params *setup_params,
416 u16 q_idx, u16 sb_idx);
417
418void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
419 struct bnx2x_virtf *vf,
420 struct bnx2x_vf_queue *q,
421 struct bnx2x_vf_queue_construct_params *p,
422 unsigned long q_type);
423
424int bnx2x_vf_mac_vlan_config_list(struct bnx2x *bp, struct bnx2x_virtf *vf,
425 struct bnx2x_vf_mac_vlan_filters *filters,
426 int qid, bool drv_only);
427
428int bnx2x_vf_queue_setup(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid,
429 struct bnx2x_vf_queue_construct_params *qctor);
430
431int bnx2x_vf_queue_teardown(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid);
432
433int bnx2x_vf_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf,
434 bnx2x_mac_addr_t *mcasts, int mc_num, bool drv_only);
435
436int bnx2x_vf_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf,
437 int qid, unsigned long accept_flags);
438
439int bnx2x_vf_close(struct bnx2x *bp, struct bnx2x_virtf *vf);
440
441int bnx2x_vf_free(struct bnx2x *bp, struct bnx2x_virtf *vf);
442
443int bnx2x_vf_rss_update(struct bnx2x *bp, struct bnx2x_virtf *vf,
444 struct bnx2x_config_rss_params *rss);
445
446int bnx2x_vf_tpa_update(struct bnx2x *bp, struct bnx2x_virtf *vf,
447 struct vfpf_tpa_tlv *tlv,
448 struct bnx2x_queue_update_tpa_params *params);
449
450
451
452
453
454
455int bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf);
456int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid);
457u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf);
458
459
460
461
462int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid);
463void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid);
464
465
466void bnx2x_vf_handle_flr_event(struct bnx2x *bp);
467
468bool bnx2x_tlv_supported(u16 tlvtype);
469
470u32 bnx2x_crc_vf_bulletin(struct bnx2x *bp,
471 struct pf_vf_bulletin_content *bulletin);
472int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf);
473
474enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp);
475
476
477int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count);
478int bnx2x_vfpf_release(struct bnx2x *bp);
479int bnx2x_vfpf_release(struct bnx2x *bp);
480int bnx2x_vfpf_init(struct bnx2x *bp);
481void bnx2x_vfpf_close_vf(struct bnx2x *bp);
482int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
483 bool is_leading);
484int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set);
485int bnx2x_vfpf_config_rss(struct bnx2x *bp,
486 struct bnx2x_config_rss_params *params);
487int bnx2x_vfpf_set_mcast(struct net_device *dev);
488int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp);
489
490static inline void bnx2x_vf_fill_fw_str(struct bnx2x *bp, char *buf,
491 size_t buf_len)
492{
493 strlcpy(buf, bp->acquire_resp.pfdev_info.fw_ver, buf_len);
494}
495
496static inline int bnx2x_vf_ustorm_prods_offset(struct bnx2x *bp,
497 struct bnx2x_fastpath *fp)
498{
499 return PXP_VF_ADDR_USDM_QUEUES_START +
500 bp->acquire_resp.resc.hw_qid[fp->index] *
501 sizeof(struct ustorm_queue_zone_data);
502}
503
504enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp);
505void bnx2x_timer_sriov(struct bnx2x *bp);
506void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp);
507void bnx2x_vf_pci_dealloc(struct bnx2x *bp);
508int bnx2x_vf_pci_alloc(struct bnx2x *bp);
509int bnx2x_enable_sriov(struct bnx2x *bp);
510void bnx2x_disable_sriov(struct bnx2x *bp);
511static inline int bnx2x_vf_headroom(struct bnx2x *bp)
512{
513 return bp->vfdb->sriov.nr_virtfn * BNX2X_CIDS_PER_VF;
514}
515void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp);
516int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs);
517void bnx2x_iov_channel_down(struct bnx2x *bp);
518
519void bnx2x_iov_task(struct work_struct *work);
520
521void bnx2x_schedule_iov_task(struct bnx2x *bp, enum bnx2x_iov_flag flag);
522
523#else
524
525static inline void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
526 struct bnx2x_queue_sp_obj **q_obj) {}
527static inline void bnx2x_vf_handle_flr_event(struct bnx2x *bp) {}
528static inline int bnx2x_iov_eq_sp_event(struct bnx2x *bp,
529 union event_ring_elem *elem) {return 1; }
530static inline void bnx2x_vf_mbx(struct bnx2x *bp) {}
531static inline void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
532 struct vf_pf_event_data *vfpf_event) {}
533static inline int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line) {return line; }
534static inline void bnx2x_iov_init_dq(struct bnx2x *bp) {}
535static inline int bnx2x_iov_alloc_mem(struct bnx2x *bp) {return 0; }
536static inline void bnx2x_iov_free_mem(struct bnx2x *bp) {}
537static inline int bnx2x_iov_chip_cleanup(struct bnx2x *bp) {return 0; }
538static inline void bnx2x_iov_init_dmae(struct bnx2x *bp) {}
539static inline int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
540 int num_vfs_param) {return 0; }
541static inline void bnx2x_iov_remove_one(struct bnx2x *bp) {}
542static inline int bnx2x_enable_sriov(struct bnx2x *bp) {return 0; }
543static inline void bnx2x_disable_sriov(struct bnx2x *bp) {}
544static inline int bnx2x_vfpf_acquire(struct bnx2x *bp,
545 u8 tx_count, u8 rx_count) {return 0; }
546static inline int bnx2x_vfpf_release(struct bnx2x *bp) {return 0; }
547static inline int bnx2x_vfpf_init(struct bnx2x *bp) {return 0; }
548static inline void bnx2x_vfpf_close_vf(struct bnx2x *bp) {}
549static inline int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp, bool is_leading) {return 0; }
550static inline int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr,
551 u8 vf_qid, bool set) {return 0; }
552static inline int bnx2x_vfpf_config_rss(struct bnx2x *bp,
553 struct bnx2x_config_rss_params *params) {return 0; }
554static inline int bnx2x_vfpf_set_mcast(struct net_device *dev) {return 0; }
555static inline int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp) {return 0; }
556static inline int bnx2x_iov_nic_init(struct bnx2x *bp) {return 0; }
557static inline int bnx2x_vf_headroom(struct bnx2x *bp) {return 0; }
558static inline void bnx2x_iov_adjust_stats_req(struct bnx2x *bp) {}
559static inline void bnx2x_vf_fill_fw_str(struct bnx2x *bp, char *buf,
560 size_t buf_len) {}
561static inline int bnx2x_vf_ustorm_prods_offset(struct bnx2x *bp,
562 struct bnx2x_fastpath *fp) {return 0; }
563static inline enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp)
564{
565 return PFVF_BULLETIN_UNCHANGED;
566}
567static inline void bnx2x_timer_sriov(struct bnx2x *bp) {}
568
569static inline void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
570{
571 return NULL;
572}
573
574static inline void bnx2x_vf_pci_dealloc(struct bnx2x *bp) {}
575static inline int bnx2x_vf_pci_alloc(struct bnx2x *bp) {return 0; }
576static inline void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) {}
577static inline int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs) {return 0; }
578static inline void bnx2x_iov_channel_down(struct bnx2x *bp) {}
579
580static inline void bnx2x_iov_task(struct work_struct *work) {}
581static inline void bnx2x_schedule_iov_task(struct bnx2x *bp, enum bnx2x_iov_flag flag) {}
582
583#endif
584#endif
585