1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "bnx2x.h"
23#include "bnx2x_cmn.h"
24#include <linux/crc32.h>
25
26static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
27
28
29static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
30 u16 offset, u16 type, u16 length)
31{
32 struct channel_tlv *tl =
33 (struct channel_tlv *)(tlvs_list + offset);
34
35 tl->type = type;
36 tl->length = length;
37}
38
39
40static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
41 u16 type, u16 length)
42{
43 mutex_lock(&bp->vf2pf_mutex);
44
45 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
46 type);
47
48
49 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
50
51
52 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
53
54
55 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
56}
57
58
59static void bnx2x_vfpf_finalize(struct bnx2x *bp,
60 struct vfpf_first_tlv *first_tlv)
61{
62 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
63 first_tlv->tl.type);
64
65 mutex_unlock(&bp->vf2pf_mutex);
66}
67
68
69static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
70 enum channel_tlvs req_tlv)
71{
72 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
73
74 do {
75 if (tlv->type == req_tlv)
76 return tlv;
77
78 if (!tlv->length) {
79 BNX2X_ERR("Found TLV with length 0\n");
80 return NULL;
81 }
82
83 tlvs_list += tlv->length;
84 tlv = (struct channel_tlv *)tlvs_list;
85 } while (tlv->type != CHANNEL_TLV_LIST_END);
86
87 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
88
89 return NULL;
90}
91
92
93static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
94{
95 int i = 1;
96 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
97
98 while (tlv->type != CHANNEL_TLV_LIST_END) {
99
100 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
101 tlv->type, tlv->length);
102
103
104 tlvs_list += tlv->length;
105
106
107 tlv = (struct channel_tlv *)tlvs_list;
108
109 i++;
110
111
112 if (i > MAX_TLVS_IN_LIST) {
113 WARN(true, "corrupt tlvs");
114 return;
115 }
116 }
117
118
119 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
120 tlv->type, tlv->length);
121}
122
123
124bool bnx2x_tlv_supported(u16 tlvtype)
125{
126 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
127}
128
129static inline int bnx2x_pfvf_status_codes(int rc)
130{
131 switch (rc) {
132 case 0:
133 return PFVF_STATUS_SUCCESS;
134 case -ENOMEM:
135 return PFVF_STATUS_NO_RESOURCE;
136 default:
137 return PFVF_STATUS_FAILURE;
138 }
139}
140
141static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
142{
143 struct cstorm_vf_zone_data __iomem *zone_data =
144 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
145 int tout = 100, interval = 100;
146
147 if (*done) {
148 BNX2X_ERR("done was non zero before message to pf was sent\n");
149 WARN_ON(true);
150 return -EINVAL;
151 }
152
153
154
155
156 bnx2x_sample_bulletin(bp);
157 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
158 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
159 *done = PFVF_STATUS_SUCCESS;
160 return -EINVAL;
161 }
162
163
164 writel(U64_LO(msg_mapping),
165 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
166 writel(U64_HI(msg_mapping),
167 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
168
169
170 wmb();
171
172
173 writeb_relaxed(1, &zone_data->trigger.vf_pf_channel.addr_valid);
174
175 mmiowb();
176
177
178 while ((tout >= 0) && (!*done)) {
179 msleep(interval);
180 tout -= 1;
181
182
183
184
185 DP_CONT(BNX2X_MSG_IOV, ".");
186 }
187
188 if (!*done) {
189 BNX2X_ERR("PF response has timed out\n");
190 return -EAGAIN;
191 }
192 DP(BNX2X_MSG_SP, "Got a response from PF\n");
193 return 0;
194}
195
196static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
197{
198 u32 me_reg;
199 int tout = 10, interval = 100;
200
201 do {
202
203 me_reg = readl(bp->doorbells);
204 if (GOOD_ME_REG(me_reg))
205 break;
206
207 msleep(interval);
208
209 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
210 me_reg);
211 } while (tout-- > 0);
212
213 if (!GOOD_ME_REG(me_reg)) {
214 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
215 return -EINVAL;
216 }
217
218 DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
219
220 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
221
222 return 0;
223}
224
225int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
226{
227 int rc = 0, attempts = 0;
228 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
229 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
230 struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
231 struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
232 u32 vf_id;
233 bool resources_acquired = false;
234
235
236 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
237
238 if (bnx2x_get_vf_id(bp, &vf_id)) {
239 rc = -EAGAIN;
240 goto out;
241 }
242
243 req->vfdev_info.vf_id = vf_id;
244 req->vfdev_info.vf_os = 0;
245 req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
246
247 req->resc_request.num_rxqs = rx_count;
248 req->resc_request.num_txqs = tx_count;
249 req->resc_request.num_sbs = bp->igu_sb_cnt;
250 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
251 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
252 req->resc_request.num_vlan_filters = VF_ACQUIRE_VLAN_FILTERS;
253
254
255 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
256
257
258 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
259 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
260
261
262 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
263
264 req->vfdev_info.caps |= VF_CAP_SUPPORT_VLAN_FILTER;
265
266
267 bnx2x_add_tlv(bp, req,
268 req->first_tlv.tl.length + sizeof(struct channel_tlv),
269 CHANNEL_TLV_LIST_END,
270 sizeof(struct channel_list_end_tlv));
271
272
273 bnx2x_dp_tlv_list(bp, req);
274
275 while (!resources_acquired) {
276 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
277
278
279 rc = bnx2x_send_msg2pf(bp,
280 &resp->hdr.status,
281 bp->vf2pf_mbox_mapping);
282
283
284 if (rc)
285 goto out;
286
287
288 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
289
290 attempts++;
291
292
293
294
295 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
296 DP(BNX2X_MSG_SP, "resources acquired\n");
297 resources_acquired = true;
298 } else if (bp->acquire_resp.hdr.status ==
299 PFVF_STATUS_NO_RESOURCE &&
300 attempts < VF_ACQUIRE_THRESH) {
301 DP(BNX2X_MSG_SP,
302 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
303
304
305 req->resc_request.num_txqs =
306 min(req->resc_request.num_txqs,
307 bp->acquire_resp.resc.num_txqs);
308 req->resc_request.num_rxqs =
309 min(req->resc_request.num_rxqs,
310 bp->acquire_resp.resc.num_rxqs);
311 req->resc_request.num_sbs =
312 min(req->resc_request.num_sbs,
313 bp->acquire_resp.resc.num_sbs);
314 req->resc_request.num_mac_filters =
315 min(req->resc_request.num_mac_filters,
316 bp->acquire_resp.resc.num_mac_filters);
317 req->resc_request.num_vlan_filters =
318 min(req->resc_request.num_vlan_filters,
319 bp->acquire_resp.resc.num_vlan_filters);
320 req->resc_request.num_mc_filters =
321 min(req->resc_request.num_mc_filters,
322 bp->acquire_resp.resc.num_mc_filters);
323
324
325 memset(&bp->vf2pf_mbox->resp, 0,
326 sizeof(union pfvf_tlvs));
327 } else {
328
329 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
330 CHANNEL_TLV_FP_HSI_SUPPORT);
331 if (fp_hsi_resp && !fp_hsi_resp->is_supported)
332 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
333 else
334 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
335 bp->acquire_resp.hdr.status);
336 rc = -EAGAIN;
337 goto out;
338 }
339 }
340
341
342 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
343 bnx2x_search_tlv_list(bp, resp,
344 CHANNEL_TLV_PHYS_PORT_ID);
345 if (phys_port_resp) {
346 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
347 bp->flags |= HAS_PHYS_PORT_ID;
348 }
349
350
351
352
353
354 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
355 CHANNEL_TLV_FP_HSI_SUPPORT);
356 if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
357 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
358
359
360
361
362 bnx2x_vfpf_finalize(bp, &req->first_tlv);
363 bnx2x_vfpf_release(bp);
364
365 rc = -EINVAL;
366 goto out;
367 }
368
369
370 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
371 bp->link_params.chip_id = bp->common.chip_id;
372 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
373 bp->common.int_block = INT_BLOCK_IGU;
374 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
375 bp->igu_dsb_id = -1;
376 bp->mf_ov = 0;
377 bp->mf_mode = 0;
378 bp->common.flash_size = 0;
379 bp->flags |=
380 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
381 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
382 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
383 bp->vlan_credit = bp->acquire_resp.resc.num_vlan_filters;
384
385 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
386 sizeof(bp->fw_ver));
387
388 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
389 memcpy(bp->dev->dev_addr,
390 bp->acquire_resp.resc.current_mac_addr,
391 ETH_ALEN);
392
393out:
394 bnx2x_vfpf_finalize(bp, &req->first_tlv);
395 return rc;
396}
397
398int bnx2x_vfpf_release(struct bnx2x *bp)
399{
400 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
401 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
402 u32 rc, vf_id;
403
404
405 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
406
407 if (bnx2x_get_vf_id(bp, &vf_id)) {
408 rc = -EAGAIN;
409 goto out;
410 }
411
412 req->vf_id = vf_id;
413
414
415 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
416 sizeof(struct channel_list_end_tlv));
417
418
419 bnx2x_dp_tlv_list(bp, req);
420
421
422 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
423
424 if (rc)
425
426 goto out;
427
428 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
429
430 DP(BNX2X_MSG_SP, "vf released\n");
431 } else {
432
433 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
434 resp->hdr.status);
435 rc = -EAGAIN;
436 goto out;
437 }
438out:
439 bnx2x_vfpf_finalize(bp, &req->first_tlv);
440
441 return rc;
442}
443
444
445int bnx2x_vfpf_init(struct bnx2x *bp)
446{
447 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
448 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
449 int rc, i;
450
451
452 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
453
454
455 for_each_eth_queue(bp, i)
456 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
457 status_blk_mapping);
458
459
460 req->stats_addr = bp->fw_stats_data_mapping +
461 offsetof(struct bnx2x_fw_stats_data, queue_stats);
462
463 req->stats_stride = sizeof(struct per_queue_stats);
464
465
466 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
467 sizeof(struct channel_list_end_tlv));
468
469
470 bnx2x_dp_tlv_list(bp, req);
471
472 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
473 if (rc)
474 goto out;
475
476 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
477 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
478 resp->hdr.status);
479 rc = -EAGAIN;
480 goto out;
481 }
482
483 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
484out:
485 bnx2x_vfpf_finalize(bp, &req->first_tlv);
486
487 return rc;
488}
489
490
491void bnx2x_vfpf_close_vf(struct bnx2x *bp)
492{
493 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
494 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
495 int i, rc;
496 u32 vf_id;
497
498
499
500
501 if (bnx2x_get_vf_id(bp, &vf_id))
502 goto free_irq;
503
504
505 for_each_queue(bp, i)
506 bnx2x_vfpf_teardown_queue(bp, i);
507
508
509 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
510
511
512 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
513
514 req->vf_id = vf_id;
515
516
517 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
518 sizeof(struct channel_list_end_tlv));
519
520
521 bnx2x_dp_tlv_list(bp, req);
522
523 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
524
525 if (rc)
526 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
527
528 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
529 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
530 resp->hdr.status);
531
532 bnx2x_vfpf_finalize(bp, &req->first_tlv);
533
534free_irq:
535
536 bnx2x_netif_stop(bp, 0);
537
538 bnx2x_del_all_napi(bp);
539
540
541 bnx2x_free_irq(bp);
542}
543
544static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
545 struct bnx2x_vf_queue *q)
546{
547 u8 cl_id = vfq_cl_id(vf, q);
548 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
549
550
551 bnx2x_init_mac_obj(bp, &q->mac_obj,
552 cl_id, q->cid, func_id,
553 bnx2x_vf_sp(bp, vf, mac_rdata),
554 bnx2x_vf_sp_map(bp, vf, mac_rdata),
555 BNX2X_FILTER_MAC_PENDING,
556 &vf->filter_state,
557 BNX2X_OBJ_TYPE_RX_TX,
558 &vf->vf_macs_pool);
559
560 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
561 cl_id, q->cid, func_id,
562 bnx2x_vf_sp(bp, vf, vlan_rdata),
563 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
564 BNX2X_FILTER_VLAN_PENDING,
565 &vf->filter_state,
566 BNX2X_OBJ_TYPE_RX_TX,
567 &vf->vf_vlans_pool);
568
569 bnx2x_init_vlan_mac_obj(bp, &q->vlan_mac_obj,
570 cl_id, q->cid, func_id,
571 bnx2x_vf_sp(bp, vf, vlan_mac_rdata),
572 bnx2x_vf_sp_map(bp, vf, vlan_mac_rdata),
573 BNX2X_FILTER_VLAN_MAC_PENDING,
574 &vf->filter_state,
575 BNX2X_OBJ_TYPE_RX_TX,
576 &vf->vf_macs_pool,
577 &vf->vf_vlans_pool);
578
579 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
580 q->cid, func_id, func_id,
581 bnx2x_vf_sp(bp, vf, mcast_rdata),
582 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
583 BNX2X_FILTER_MCAST_PENDING,
584 &vf->filter_state,
585 BNX2X_OBJ_TYPE_RX_TX);
586
587
588 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
589 func_id, func_id,
590 bnx2x_vf_sp(bp, vf, rss_rdata),
591 bnx2x_vf_sp_map(bp, vf, rss_rdata),
592 BNX2X_FILTER_RSS_CONF_PENDING,
593 &vf->filter_state,
594 BNX2X_OBJ_TYPE_RX_TX);
595
596 vf->leading_rss = cl_id;
597 q->is_leading = true;
598 q->sp_initialized = true;
599}
600
601
602int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
603 bool is_leading)
604{
605 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
606 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
607 u8 fp_idx = fp->index;
608 u16 tpa_agg_size = 0, flags = 0;
609 int rc;
610
611
612 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
613
614
615 if (fp->mode != TPA_MODE_DISABLED) {
616 flags |= VFPF_QUEUE_FLG_TPA;
617 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
618 if (fp->mode == TPA_MODE_GRO)
619 flags |= VFPF_QUEUE_FLG_TPA_GRO;
620 tpa_agg_size = TPA_AGG_SIZE;
621 }
622
623 if (is_leading)
624 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
625
626
627 flags |= VFPF_QUEUE_FLG_STATS;
628 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
629 flags |= VFPF_QUEUE_FLG_VLAN;
630
631
632 req->vf_qid = fp_idx;
633 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
634
635
636 req->rxq.rcq_addr = fp->rx_comp_mapping;
637 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
638 req->rxq.rxq_addr = fp->rx_desc_mapping;
639 req->rxq.sge_addr = fp->rx_sge_mapping;
640 req->rxq.vf_sb = fp_idx;
641 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
642 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
643 req->rxq.mtu = bp->dev->mtu;
644 req->rxq.buf_sz = fp->rx_buf_size;
645 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
646 req->rxq.tpa_agg_sz = tpa_agg_size;
647 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
648 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
649 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
650 req->rxq.flags = flags;
651 req->rxq.drop_flags = 0;
652 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
653 req->rxq.stat_id = -1;
654
655
656 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
657 req->txq.vf_sb = fp_idx;
658 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
659 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
660 req->txq.flags = flags;
661 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
662
663
664 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
665 sizeof(struct channel_list_end_tlv));
666
667
668 bnx2x_dp_tlv_list(bp, req);
669
670 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
671 if (rc)
672 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
673 fp_idx);
674
675 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
676 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
677 fp_idx, resp->hdr.status);
678 rc = -EINVAL;
679 }
680
681 bnx2x_vfpf_finalize(bp, &req->first_tlv);
682
683 return rc;
684}
685
686static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
687{
688 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
689 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
690 int rc;
691
692
693 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
694 sizeof(*req));
695
696 req->vf_qid = qidx;
697
698
699 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
700 sizeof(struct channel_list_end_tlv));
701
702
703 bnx2x_dp_tlv_list(bp, req);
704
705 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
706
707 if (rc) {
708 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
709 rc);
710 goto out;
711 }
712
713
714 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
715 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
716 resp->hdr.status);
717 rc = -EINVAL;
718 }
719
720out:
721 bnx2x_vfpf_finalize(bp, &req->first_tlv);
722
723 return rc;
724}
725
726
727int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
728{
729 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
730 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
731 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
732 int rc = 0;
733
734
735 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
736 sizeof(*req));
737
738 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
739 req->vf_qid = vf_qid;
740 req->n_mac_vlan_filters = 1;
741
742 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
743 if (set)
744 req->filters[0].flags |= VFPF_Q_FILTER_SET;
745
746
747 bnx2x_sample_bulletin(bp);
748
749
750 memcpy(req->filters[0].mac, addr, ETH_ALEN);
751
752
753 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
754 sizeof(struct channel_list_end_tlv));
755
756
757 bnx2x_dp_tlv_list(bp, req);
758
759
760 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
761 if (rc) {
762 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
763 goto out;
764 }
765
766
767 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
768 DP(BNX2X_MSG_IOV,
769 "vfpf SET MAC failed. Check bulletin board for new posts\n");
770
771
772 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
773
774
775 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
776
777 memcpy(req->filters[0].mac, bp->dev->dev_addr,
778 ETH_ALEN);
779
780
781 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
782 bp->vf2pf_mbox_mapping);
783 } else {
784
785 break;
786 }
787 }
788
789 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
790 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
791 rc = -EINVAL;
792 }
793out:
794 bnx2x_vfpf_finalize(bp, &req->first_tlv);
795
796 return rc;
797}
798
799
800int bnx2x_vfpf_config_rss(struct bnx2x *bp,
801 struct bnx2x_config_rss_params *params)
802{
803 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
804 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
805 int rc = 0;
806
807
808 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
809 sizeof(*req));
810
811
812 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
813 sizeof(struct channel_list_end_tlv));
814
815 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
816 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
817 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
818 req->rss_key_size = T_ETH_RSS_KEY;
819 req->rss_result_mask = params->rss_result_mask;
820
821
822 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
823 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
824 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
825 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
826 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
827 req->rss_flags |= VFPF_RSS_SET_SRCH;
828 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
829 req->rss_flags |= VFPF_RSS_IPV4;
830 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
831 req->rss_flags |= VFPF_RSS_IPV4_TCP;
832 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
833 req->rss_flags |= VFPF_RSS_IPV4_UDP;
834 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
835 req->rss_flags |= VFPF_RSS_IPV6;
836 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
837 req->rss_flags |= VFPF_RSS_IPV6_TCP;
838 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
839 req->rss_flags |= VFPF_RSS_IPV6_UDP;
840
841 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
842
843
844 bnx2x_dp_tlv_list(bp, req);
845
846
847 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
848 if (rc) {
849 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
850 goto out;
851 }
852
853 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
854
855
856
857
858 DP(BNX2X_MSG_IOV,
859 "Failed to send rss message to PF over VF-PF channel [%d]\n",
860 resp->hdr.status);
861 }
862out:
863 bnx2x_vfpf_finalize(bp, &req->first_tlv);
864
865 return rc;
866}
867
868int bnx2x_vfpf_set_mcast(struct net_device *dev)
869{
870 struct bnx2x *bp = netdev_priv(dev);
871 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
872 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
873 int rc = 0, i = 0;
874 struct netdev_hw_addr *ha;
875
876 if (bp->state != BNX2X_STATE_OPEN) {
877 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
878 return -EINVAL;
879 }
880
881
882 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
883 sizeof(*req));
884
885
886 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
887
888
889 if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) {
890 DP(NETIF_MSG_IFUP,
891 "VF supports not more than %d multicast MAC addresses\n",
892 PFVF_MAX_MULTICAST_PER_VF);
893 rc = -EINVAL;
894 goto out;
895 }
896
897 netdev_for_each_mc_addr(ha, dev) {
898 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
899 bnx2x_mc_addr(ha));
900 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
901 i++;
902 }
903
904 req->n_multicast = i;
905 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
906 req->vf_qid = 0;
907
908
909 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
910 sizeof(struct channel_list_end_tlv));
911
912
913 bnx2x_dp_tlv_list(bp, req);
914 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
915 if (rc) {
916 BNX2X_ERR("Sending a message failed: %d\n", rc);
917 goto out;
918 }
919
920 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
921 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
922 resp->hdr.status);
923 rc = -EINVAL;
924 }
925out:
926 bnx2x_vfpf_finalize(bp, &req->first_tlv);
927
928 return rc;
929}
930
931
932int bnx2x_vfpf_update_vlan(struct bnx2x *bp, u16 vid, u8 vf_qid, bool add)
933{
934 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
935 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
936 int rc = 0;
937
938 if (!(bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER)) {
939 DP(BNX2X_MSG_IOV, "HV does not support vlan filtering\n");
940 return 0;
941 }
942
943
944 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
945 sizeof(*req));
946
947 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
948 req->vf_qid = vf_qid;
949 req->n_mac_vlan_filters = 1;
950
951 req->filters[0].flags = VFPF_Q_FILTER_VLAN_TAG_VALID;
952
953 if (add)
954 req->filters[0].flags |= VFPF_Q_FILTER_SET;
955
956
957 bnx2x_sample_bulletin(bp);
958
959 if (bp->shadow_bulletin.content.valid_bitmap & 1 << VLAN_VALID) {
960 BNX2X_ERR("Hypervisor will dicline the request, avoiding\n");
961 rc = -EINVAL;
962 goto out;
963 }
964
965 req->filters[0].vlan_tag = vid;
966
967
968 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
969 sizeof(struct channel_list_end_tlv));
970
971
972 bnx2x_dp_tlv_list(bp, req);
973
974
975 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
976 if (rc) {
977 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
978 goto out;
979 }
980
981 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
982 BNX2X_ERR("vfpf %s VLAN %d failed\n", add ? "add" : "del",
983 vid);
984 rc = -EINVAL;
985 }
986out:
987 bnx2x_vfpf_finalize(bp, &req->first_tlv);
988
989 return rc;
990}
991
992int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
993{
994 int mode = bp->rx_mode;
995 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
996 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
997 int rc;
998
999
1000 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
1001 sizeof(*req));
1002
1003 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
1004
1005
1006 if (mode == BNX2X_RX_MODE_NONE) {
1007 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
1008 } else {
1009
1010
1011
1012 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
1013 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
1014 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
1015 if (mode == BNX2X_RX_MODE_PROMISC)
1016 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
1017 }
1018
1019 if (bp->accept_any_vlan)
1020 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
1021
1022 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
1023 req->vf_qid = 0;
1024
1025
1026 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
1027 sizeof(struct channel_list_end_tlv));
1028
1029
1030 bnx2x_dp_tlv_list(bp, req);
1031
1032 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
1033 if (rc)
1034 BNX2X_ERR("Sending a message failed: %d\n", rc);
1035
1036 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1037 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
1038 rc = -EINVAL;
1039 }
1040
1041 bnx2x_vfpf_finalize(bp, &req->first_tlv);
1042
1043 return rc;
1044}
1045
1046
1047static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
1048{
1049 u32 addr = BAR_CSTRORM_INTMEM +
1050 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
1051
1052 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
1053}
1054
1055static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
1056{
1057 u32 addr = BAR_CSTRORM_INTMEM +
1058 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
1059
1060 REG_WR8(bp, addr, 1);
1061}
1062
1063
1064void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
1065{
1066 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
1067
1068
1069 storm_memset_vf_mbx_ack(bp, abs_vfid);
1070 storm_memset_vf_mbx_valid(bp, abs_vfid);
1071
1072
1073 bnx2x_vf_enable_access(bp, abs_vfid);
1074}
1075
1076
1077static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
1078 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
1079 u32 vf_addr_lo, u32 len32)
1080{
1081 struct dmae_command dmae;
1082
1083 if (CHIP_IS_E1x(bp)) {
1084 BNX2X_ERR("Chip revision does not support VFs\n");
1085 return DMAE_NOT_RDY;
1086 }
1087
1088 if (!bp->dmae_ready) {
1089 BNX2X_ERR("DMAE is not ready, can not copy\n");
1090 return DMAE_NOT_RDY;
1091 }
1092
1093
1094 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1095
1096 if (from_vf) {
1097 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1098 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1099 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1100
1101 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1102
1103 dmae.src_addr_lo = vf_addr_lo;
1104 dmae.src_addr_hi = vf_addr_hi;
1105 dmae.dst_addr_lo = U64_LO(pf_addr);
1106 dmae.dst_addr_hi = U64_HI(pf_addr);
1107 } else {
1108 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1109 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1110 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1111
1112 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1113
1114 dmae.src_addr_lo = U64_LO(pf_addr);
1115 dmae.src_addr_hi = U64_HI(pf_addr);
1116 dmae.dst_addr_lo = vf_addr_lo;
1117 dmae.dst_addr_hi = vf_addr_hi;
1118 }
1119 dmae.len = len32;
1120
1121
1122 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1123}
1124
1125static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1126 struct bnx2x_virtf *vf)
1127{
1128 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1129 u16 length, type;
1130
1131
1132 type = mbx->first_tlv.tl.type;
1133 length = type == CHANNEL_TLV_ACQUIRE ?
1134 sizeof(struct pfvf_acquire_resp_tlv) :
1135 sizeof(struct pfvf_general_resp_tlv);
1136 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1137 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1138 sizeof(struct channel_list_end_tlv));
1139}
1140
1141static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1142 struct bnx2x_virtf *vf,
1143 int vf_rc)
1144{
1145 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1146 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1147 dma_addr_t pf_addr;
1148 u64 vf_addr;
1149 int rc;
1150
1151 bnx2x_dp_tlv_list(bp, resp);
1152 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1153 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1154
1155 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1156
1157
1158 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1159 mbx->first_tlv.resp_msg_offset;
1160 pf_addr = mbx->msg_mapping +
1161 offsetof(struct bnx2x_vf_mbx_msg, resp);
1162
1163
1164
1165
1166 vf_addr += sizeof(u64);
1167 pf_addr += sizeof(u64);
1168 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1169 U64_HI(vf_addr),
1170 U64_LO(vf_addr),
1171 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1172 if (rc) {
1173 BNX2X_ERR("Failed to copy response body to VF %d\n",
1174 vf->abs_vfid);
1175 goto mbx_error;
1176 }
1177 vf_addr -= sizeof(u64);
1178 pf_addr -= sizeof(u64);
1179
1180
1181 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1182 mmiowb();
1183
1184
1185
1186
1187 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1188 U64_HI(vf_addr),
1189 U64_LO(vf_addr),
1190 sizeof(u64)/4);
1191
1192
1193 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1194
1195 if (rc) {
1196 BNX2X_ERR("Failed to copy response status to VF %d\n",
1197 vf->abs_vfid);
1198 goto mbx_error;
1199 }
1200 return;
1201
1202mbx_error:
1203 bnx2x_vf_release(bp, vf);
1204}
1205
1206static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1207 struct bnx2x_virtf *vf,
1208 int rc)
1209{
1210 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1211 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1212}
1213
1214static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1215 struct bnx2x_virtf *vf,
1216 void *buffer,
1217 u16 *offset)
1218{
1219 struct vfpf_port_phys_id_resp_tlv *port_id;
1220
1221 if (!(bp->flags & HAS_PHYS_PORT_ID))
1222 return;
1223
1224 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1225 sizeof(struct vfpf_port_phys_id_resp_tlv));
1226
1227 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1228 (((u8 *)buffer) + *offset);
1229 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1230
1231
1232
1233
1234 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1235}
1236
1237static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1238 struct bnx2x_virtf *vf,
1239 void *buffer,
1240 u16 *offset)
1241{
1242 struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1243
1244 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1245 sizeof(struct vfpf_fp_hsi_resp_tlv));
1246
1247 fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1248 (((u8 *)buffer) + *offset);
1249 fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1250
1251
1252
1253
1254 *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1255}
1256
1257static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1258 struct bnx2x_vf_mbx *mbx, int vfop_status)
1259{
1260 int i;
1261 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1262 struct pf_vf_resc *resc = &resp->resc;
1263 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1264 u16 length;
1265
1266 memset(resp, 0, sizeof(*resp));
1267
1268
1269 resp->pfdev_info.chip_num = bp->common.chip_id;
1270 resp->pfdev_info.db_size = bp->db_size;
1271 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1272 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1273 PFVF_CAP_TPA |
1274 PFVF_CAP_TPA_UPDATE |
1275 PFVF_CAP_VLAN_FILTER);
1276 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1277 sizeof(resp->pfdev_info.fw_ver));
1278
1279 if (status == PFVF_STATUS_NO_RESOURCE ||
1280 status == PFVF_STATUS_SUCCESS) {
1281
1282
1283
1284 resc->num_rxqs = vf_rxq_count(vf) ? :
1285 bnx2x_vf_max_queue_cnt(bp, vf);
1286 resc->num_txqs = vf_txq_count(vf) ? :
1287 bnx2x_vf_max_queue_cnt(bp, vf);
1288 resc->num_sbs = vf_sb_count(vf);
1289 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1290 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
1291 resc->num_mc_filters = 0;
1292
1293 if (status == PFVF_STATUS_SUCCESS) {
1294
1295 struct pf_vf_bulletin_content *bulletin =
1296 BP_VF_BULLETIN(bp, vf->index);
1297
1298 for_each_vfq(vf, i)
1299 resc->hw_qid[i] =
1300 vfq_qzone_id(vf, vfq_get(vf, i));
1301
1302 for_each_vf_sb(vf, i) {
1303 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1304 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1305 }
1306
1307
1308 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1309 memcpy(resc->current_mac_addr, bulletin->mac,
1310 ETH_ALEN);
1311 }
1312 }
1313 }
1314
1315 DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n"
1316 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1317 vf->abs_vfid,
1318 resp->pfdev_info.chip_num,
1319 resp->pfdev_info.db_size,
1320 resp->pfdev_info.indices_per_sb,
1321 resp->pfdev_info.pf_cap,
1322 resc->num_rxqs,
1323 resc->num_txqs,
1324 resc->num_sbs,
1325 resc->num_mac_filters,
1326 resc->num_vlan_filters,
1327 resc->num_mc_filters,
1328 resp->pfdev_info.fw_ver);
1329
1330 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1331 for (i = 0; i < vf_rxq_count(vf); i++)
1332 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1333 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1334 for (i = 0; i < vf_sb_count(vf); i++)
1335 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1336 resc->hw_sbs[i].hw_sb_id,
1337 resc->hw_sbs[i].sb_qid);
1338 DP_CONT(BNX2X_MSG_IOV, "]\n");
1339
1340
1341 length = sizeof(struct pfvf_acquire_resp_tlv);
1342 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1343
1344
1345
1346
1347
1348 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1349 CHANNEL_TLV_PHYS_PORT_ID))
1350 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1351
1352
1353
1354
1355
1356 bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1357
1358 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1359 sizeof(struct channel_list_end_tlv));
1360
1361
1362 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1363}
1364
1365static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1366 struct vfpf_acquire_tlv *acquire)
1367{
1368
1369
1370
1371
1372
1373 if (!acquire->bulletin_addr ||
1374 acquire->resc_request.num_mc_filters == 32 ||
1375 ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1376 VF_OS_WINDOWS))
1377 return true;
1378
1379 return false;
1380}
1381
1382static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1383 struct bnx2x_virtf *vf,
1384 struct bnx2x_vf_mbx *mbx)
1385{
1386
1387
1388
1389 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1390 CHANNEL_TLV_PHYS_PORT_ID))
1391 return 0;
1392
1393
1394 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1395 return 0;
1396
1397 return -EOPNOTSUPP;
1398}
1399
1400static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1401 struct bnx2x_vf_mbx *mbx)
1402{
1403 int rc;
1404 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1405
1406
1407 DP(BNX2X_MSG_IOV,
1408 "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n",
1409 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1410 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1411 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1412 acquire->resc_request.num_vlan_filters,
1413 acquire->resc_request.num_mc_filters);
1414
1415
1416
1417
1418
1419 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1420 if (rc) {
1421 DP(BNX2X_MSG_IOV,
1422 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1423 vf->abs_vfid);
1424 goto out;
1425 }
1426
1427
1428
1429
1430 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1431 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1432 else
1433 vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
1434 ETH_FP_HSI_VER_2);
1435 if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1436 DP(BNX2X_MSG_IOV,
1437 "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1438 vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1439 ETH_FP_HSI_VERSION);
1440 rc = -EINVAL;
1441 goto out;
1442 }
1443
1444
1445 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1446
1447
1448 vf->bulletin_map = acquire->bulletin_addr;
1449 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1450 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1451 vf->abs_vfid);
1452 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1453 } else {
1454 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1455 }
1456
1457 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_VLAN_FILTER) {
1458 DP(BNX2X_MSG_IOV, "VF[%d] supports vlan filtering\n",
1459 vf->abs_vfid);
1460 vf->cfg_flags |= VF_CFG_VLAN_FILTER;
1461 } else {
1462 vf->cfg_flags &= ~VF_CFG_VLAN_FILTER;
1463 }
1464
1465out:
1466
1467 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1468}
1469
1470static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1471 struct bnx2x_vf_mbx *mbx)
1472{
1473 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1474 int rc;
1475
1476
1477 vf->fw_stat_map = init->stats_addr;
1478 vf->stats_stride = init->stats_stride;
1479 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1480
1481
1482 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1483 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1484
1485
1486 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1487 bnx2x_iov_link_update_vf(bp, vf->index);
1488
1489
1490 bnx2x_vf_mbx_resp(bp, vf, rc);
1491}
1492
1493
1494static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1495 unsigned long *sp_q_flags)
1496{
1497 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1498 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1499 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1500 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1501 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1502 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1503 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1504 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1505 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1506 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1507 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1508 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1509 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1510 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1511 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1512 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1513 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1514 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1515
1516
1517 if (IS_MF_SD(bp))
1518 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1519}
1520
1521static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1522 struct bnx2x_vf_mbx *mbx)
1523{
1524 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1525 struct bnx2x_vf_queue_construct_params qctor;
1526 int rc = 0;
1527
1528
1529 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1530 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1531 setup_q->vf_qid, vf_rxq_count(vf));
1532 rc = -EINVAL;
1533 goto response;
1534 }
1535
1536
1537
1538
1539 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1540 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1541 unsigned long q_type = 0;
1542
1543 struct bnx2x_queue_init_params *init_p;
1544 struct bnx2x_queue_setup_params *setup_p;
1545
1546 if (bnx2x_vfq_is_leading(q))
1547 bnx2x_leading_vfq_init(bp, vf, q);
1548
1549
1550 memset(&qctor, 0 ,
1551 sizeof(struct bnx2x_vf_queue_construct_params));
1552 setup_p = &qctor.prep_qsetup;
1553 init_p = &qctor.qstate.params.init;
1554
1555
1556 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1557
1558 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1559 struct bnx2x_txq_setup_params *txq_params =
1560 &setup_p->txq_params;
1561
1562 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1563
1564
1565 q->sb_idx = setup_q->txq.vf_sb;
1566
1567
1568 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1569 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1570
1571 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1572 &init_p->tx.flags);
1573
1574
1575 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1576 &setup_p->flags);
1577
1578
1579
1580
1581 txq_params->dscr_map = setup_q->txq.txq_addr;
1582 txq_params->sb_cq_index = setup_q->txq.sb_index;
1583 txq_params->traffic_type = setup_q->txq.traffic_type;
1584
1585 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1586 q->index, q->sb_idx);
1587 }
1588
1589 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1590 struct bnx2x_rxq_setup_params *rxq_params =
1591 &setup_p->rxq_params;
1592
1593 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1594
1595
1596
1597
1598 q->sb_idx = setup_q->rxq.vf_sb;
1599
1600
1601 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1602 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1603 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1604 &init_p->rx.flags);
1605
1606
1607 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1608 &setup_p->flags);
1609
1610
1611 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1612
1613
1614 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1615 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1616 rxq_params->sge_map = setup_q->rxq.sge_addr;
1617 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1618 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1619 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1620 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1621 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1622 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1623 rxq_params->cache_line_log =
1624 setup_q->rxq.cache_line_log;
1625 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1626
1627
1628 if (bnx2x_vfq_is_leading(q)) {
1629 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1630
1631 rxq_params->mcast_engine_id = mcast_id;
1632 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1633 }
1634
1635 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1636 q->index, q->sb_idx);
1637 }
1638
1639 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1640
1641 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1642 if (rc)
1643 goto response;
1644 }
1645response:
1646 bnx2x_vf_mbx_resp(bp, vf, rc);
1647}
1648
1649static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1650 struct bnx2x_virtf *vf,
1651 struct vfpf_set_q_filters_tlv *tlv,
1652 struct bnx2x_vf_mac_vlan_filters **pfl,
1653 u32 type_flag)
1654{
1655 int i, j;
1656 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1657 size_t fsz;
1658
1659 fsz = tlv->n_mac_vlan_filters *
1660 sizeof(struct bnx2x_vf_mac_vlan_filter) +
1661 sizeof(struct bnx2x_vf_mac_vlan_filters);
1662
1663 fl = kzalloc(fsz, GFP_KERNEL);
1664 if (!fl)
1665 return -ENOMEM;
1666
1667 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1668 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1669
1670 if ((msg_filter->flags & type_flag) != type_flag)
1671 continue;
1672 memset(&fl->filters[j], 0, sizeof(fl->filters[j]));
1673 if (type_flag & VFPF_Q_FILTER_DEST_MAC_VALID) {
1674 fl->filters[j].mac = msg_filter->mac;
1675 fl->filters[j].type |= BNX2X_VF_FILTER_MAC;
1676 }
1677 if (type_flag & VFPF_Q_FILTER_VLAN_TAG_VALID) {
1678 fl->filters[j].vid = msg_filter->vlan_tag;
1679 fl->filters[j].type |= BNX2X_VF_FILTER_VLAN;
1680 }
1681 fl->filters[j].add = !!(msg_filter->flags & VFPF_Q_FILTER_SET);
1682 fl->count++;
1683 j++;
1684 }
1685 if (!fl->count)
1686 kfree(fl);
1687 else
1688 *pfl = fl;
1689
1690 return 0;
1691}
1692
1693static int bnx2x_vf_filters_contain(struct vfpf_set_q_filters_tlv *filters,
1694 u32 flags)
1695{
1696 int i, cnt = 0;
1697
1698 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1699 if ((filters->filters[i].flags & flags) == flags)
1700 cnt++;
1701
1702 return cnt;
1703}
1704
1705static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1706 struct vfpf_q_mac_vlan_filter *filter)
1707{
1708 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1709 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1710 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1711 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1712 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1713 DP_CONT(msglvl, "\n");
1714}
1715
1716static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1717 struct vfpf_set_q_filters_tlv *filters)
1718{
1719 int i;
1720
1721 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1722 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1723 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1724 &filters->filters[i]);
1725
1726 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1727 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1728
1729 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1730 for (i = 0; i < filters->n_multicast; i++)
1731 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1732}
1733
1734#define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1735#define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1736#define VFPF_VLAN_MAC_FILTER (VFPF_VLAN_FILTER | VFPF_MAC_FILTER)
1737
1738static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1739{
1740 int rc = 0;
1741
1742 struct vfpf_set_q_filters_tlv *msg =
1743 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1744
1745
1746 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1747 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1748
1749
1750 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1751 VFPF_VLAN_MAC_FILTER);
1752 if (rc)
1753 goto op_err;
1754
1755 if (fl) {
1756
1757
1758 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1759 msg->vf_qid,
1760 false);
1761 if (rc)
1762 goto op_err;
1763 }
1764
1765
1766 fl = NULL;
1767
1768 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1769 VFPF_MAC_FILTER);
1770 if (rc)
1771 goto op_err;
1772
1773 if (fl) {
1774
1775 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1776 msg->vf_qid,
1777 false);
1778 if (rc)
1779 goto op_err;
1780 }
1781
1782
1783 fl = NULL;
1784
1785 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1786 VFPF_VLAN_FILTER);
1787 if (rc)
1788 goto op_err;
1789
1790 if (fl) {
1791
1792 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1793 msg->vf_qid,
1794 false);
1795 if (rc)
1796 goto op_err;
1797 }
1798
1799 }
1800
1801 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1802 unsigned long accept = 0;
1803 struct pf_vf_bulletin_content *bulletin =
1804 BP_VF_BULLETIN(bp, vf->index);
1805
1806
1807 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1808 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1809 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1810 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1811 }
1812
1813
1814
1815
1816
1817
1818
1819 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)) &&
1820 (!(vf->cfg_flags & VF_CFG_VLAN_FILTER) ||
1821 msg->rx_mask & VFPF_RX_MASK_ACCEPT_ANY_VLAN))
1822 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1823
1824
1825 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1826 if (rc)
1827 goto op_err;
1828 }
1829
1830 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1831
1832 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1833 msg->n_multicast, false);
1834 if (rc)
1835 goto op_err;
1836 }
1837op_err:
1838 if (rc)
1839 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1840 vf->abs_vfid, msg->vf_qid, rc);
1841 return rc;
1842}
1843
1844static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1845 struct bnx2x_virtf *vf,
1846 struct vfpf_set_q_filters_tlv *filters)
1847{
1848 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1849 int rc = 0;
1850
1851
1852
1853
1854
1855
1856 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1857 struct vfpf_q_mac_vlan_filter *filter = NULL;
1858 int i;
1859
1860 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1861 if (!(filters->filters[i].flags &
1862 VFPF_Q_FILTER_DEST_MAC_VALID))
1863 continue;
1864
1865
1866
1867
1868 if (filter) {
1869 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called [%d filters]\n",
1870 vf->abs_vfid,
1871 filters->n_mac_vlan_filters);
1872 rc = -EPERM;
1873 goto response;
1874 }
1875
1876 filter = &filters->filters[i];
1877 }
1878
1879
1880 if (filter &&
1881 !ether_addr_equal(filter->mac, bulletin->mac)) {
1882 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1883 vf->abs_vfid);
1884
1885 rc = -EPERM;
1886 goto response;
1887 }
1888 }
1889
1890response:
1891 return rc;
1892}
1893
1894static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1895 struct bnx2x_virtf *vf,
1896 struct vfpf_set_q_filters_tlv *filters)
1897{
1898 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1899 int rc = 0;
1900
1901
1902 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1903
1904
1905 if (bnx2x_vf_filters_contain(filters,
1906 VFPF_Q_FILTER_VLAN_TAG_VALID)) {
1907 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1908 vf->abs_vfid);
1909 rc = -EPERM;
1910 goto response;
1911 }
1912 }
1913
1914
1915 if (filters->vf_qid > vf_rxq_count(vf)) {
1916 rc = -EPERM;
1917 goto response;
1918 }
1919
1920response:
1921 return rc;
1922}
1923
1924static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1925 struct bnx2x_virtf *vf,
1926 struct bnx2x_vf_mbx *mbx)
1927{
1928 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1929 int rc;
1930
1931 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1932 if (rc)
1933 goto response;
1934
1935 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1936 if (rc)
1937 goto response;
1938
1939 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1940 vf->abs_vfid,
1941 filters->vf_qid);
1942
1943
1944 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1945
1946 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1947response:
1948 bnx2x_vf_mbx_resp(bp, vf, rc);
1949}
1950
1951static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1952 struct bnx2x_vf_mbx *mbx)
1953{
1954 int qid = mbx->msg->req.q_op.vf_qid;
1955 int rc;
1956
1957 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1958 vf->abs_vfid, qid);
1959
1960 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1961 bnx2x_vf_mbx_resp(bp, vf, rc);
1962}
1963
1964static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1965 struct bnx2x_vf_mbx *mbx)
1966{
1967 int rc;
1968
1969 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1970
1971 rc = bnx2x_vf_close(bp, vf);
1972 bnx2x_vf_mbx_resp(bp, vf, rc);
1973}
1974
1975static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1976 struct bnx2x_vf_mbx *mbx)
1977{
1978 int rc;
1979
1980 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1981
1982 rc = bnx2x_vf_free(bp, vf);
1983 bnx2x_vf_mbx_resp(bp, vf, rc);
1984}
1985
1986static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1987 struct bnx2x_vf_mbx *mbx)
1988{
1989 struct bnx2x_config_rss_params rss;
1990 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1991 int rc = 0;
1992
1993 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1994 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1995 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1996 vf->index);
1997 rc = -EINVAL;
1998 goto mbx_resp;
1999 }
2000
2001 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
2002
2003
2004 memcpy(rss.ind_table, rss_tlv->ind_table,
2005 T_ETH_INDIRECTION_TABLE_SIZE);
2006 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
2007 rss.rss_obj = &vf->rss_conf_obj;
2008 rss.rss_result_mask = rss_tlv->rss_result_mask;
2009
2010
2011 rss.rss_flags = 0;
2012 rss.ramrod_flags = 0;
2013
2014 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
2015 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
2016 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
2017 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
2018 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
2019 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
2020 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
2021 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
2022 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
2023 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
2024 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
2025 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
2026 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
2027 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
2028 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
2029 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
2030 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
2031 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
2032
2033 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
2034 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
2035 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
2036 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
2037 BNX2X_ERR("about to hit a FW assert. aborting...\n");
2038 rc = -EINVAL;
2039 goto mbx_resp;
2040 }
2041
2042 rc = bnx2x_vf_rss_update(bp, vf, &rss);
2043mbx_resp:
2044 bnx2x_vf_mbx_resp(bp, vf, rc);
2045}
2046
2047static int bnx2x_validate_tpa_params(struct bnx2x *bp,
2048 struct vfpf_tpa_tlv *tpa_tlv)
2049{
2050 int rc = 0;
2051
2052 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
2053 U_ETH_MAX_SGES_FOR_PACKET) {
2054 rc = -EINVAL;
2055 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
2056 tpa_tlv->tpa_client_info.max_sges_for_packet,
2057 U_ETH_MAX_SGES_FOR_PACKET);
2058 }
2059
2060 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
2061 rc = -EINVAL;
2062 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
2063 tpa_tlv->tpa_client_info.max_tpa_queues,
2064 MAX_AGG_QS(bp));
2065 }
2066
2067 return rc;
2068}
2069
2070static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
2071 struct bnx2x_vf_mbx *mbx)
2072{
2073 struct bnx2x_queue_update_tpa_params vf_op_params;
2074 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
2075 int rc = 0;
2076
2077 memset(&vf_op_params, 0, sizeof(vf_op_params));
2078
2079 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
2080 goto mbx_resp;
2081
2082 vf_op_params.complete_on_both_clients =
2083 tpa_tlv->tpa_client_info.complete_on_both_clients;
2084 vf_op_params.dont_verify_thr =
2085 tpa_tlv->tpa_client_info.dont_verify_thr;
2086 vf_op_params.max_agg_sz =
2087 tpa_tlv->tpa_client_info.max_agg_size;
2088 vf_op_params.max_sges_pkt =
2089 tpa_tlv->tpa_client_info.max_sges_for_packet;
2090 vf_op_params.max_tpa_queues =
2091 tpa_tlv->tpa_client_info.max_tpa_queues;
2092 vf_op_params.sge_buff_sz =
2093 tpa_tlv->tpa_client_info.sge_buff_size;
2094 vf_op_params.sge_pause_thr_high =
2095 tpa_tlv->tpa_client_info.sge_pause_thr_high;
2096 vf_op_params.sge_pause_thr_low =
2097 tpa_tlv->tpa_client_info.sge_pause_thr_low;
2098 vf_op_params.tpa_mode =
2099 tpa_tlv->tpa_client_info.tpa_mode;
2100 vf_op_params.update_ipv4 =
2101 tpa_tlv->tpa_client_info.update_ipv4;
2102 vf_op_params.update_ipv6 =
2103 tpa_tlv->tpa_client_info.update_ipv6;
2104
2105 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
2106
2107mbx_resp:
2108 bnx2x_vf_mbx_resp(bp, vf, rc);
2109}
2110
2111
2112static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
2113 struct bnx2x_vf_mbx *mbx)
2114{
2115 int i;
2116
2117
2118 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
2119
2120
2121
2122 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2123
2124
2125 switch (mbx->first_tlv.tl.type) {
2126 case CHANNEL_TLV_ACQUIRE:
2127 bnx2x_vf_mbx_acquire(bp, vf, mbx);
2128 return;
2129 case CHANNEL_TLV_INIT:
2130 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
2131 return;
2132 case CHANNEL_TLV_SETUP_Q:
2133 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
2134 return;
2135 case CHANNEL_TLV_SET_Q_FILTERS:
2136 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2137 return;
2138 case CHANNEL_TLV_TEARDOWN_Q:
2139 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2140 return;
2141 case CHANNEL_TLV_CLOSE:
2142 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2143 return;
2144 case CHANNEL_TLV_RELEASE:
2145 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2146 return;
2147 case CHANNEL_TLV_UPDATE_RSS:
2148 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2149 return;
2150 case CHANNEL_TLV_UPDATE_TPA:
2151 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2152 return;
2153 }
2154
2155 } else {
2156
2157
2158
2159
2160
2161
2162 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2163 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2164 vf->state);
2165 for (i = 0; i < 20; i++)
2166 DP_CONT(BNX2X_MSG_IOV, "%x ",
2167 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2168 }
2169
2170
2171 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2172
2173 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2174 } else {
2175
2176
2177
2178
2179 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2180
2181 mmiowb();
2182 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2183 }
2184}
2185
2186void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2187 struct vf_pf_event_data *vfpf_event)
2188{
2189 u8 vf_idx;
2190
2191 DP(BNX2X_MSG_IOV,
2192 "vf pf event received: vfid %d, address_hi %x, address lo %x",
2193 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2194
2195
2196
2197 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2198 BNX2X_NR_VIRTFN(bp)) {
2199 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2200 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2201 return;
2202 }
2203
2204 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2205
2206
2207 mutex_lock(&BP_VFDB(bp)->event_mutex);
2208 BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
2209 le32_to_cpu(vfpf_event->msg_addr_hi);
2210 BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
2211 le32_to_cpu(vfpf_event->msg_addr_lo);
2212 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2213 mutex_unlock(&BP_VFDB(bp)->event_mutex);
2214
2215 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2216}
2217
2218
2219void bnx2x_vf_mbx(struct bnx2x *bp)
2220{
2221 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2222 u64 events;
2223 u8 vf_idx;
2224 int rc;
2225
2226 if (!vfdb)
2227 return;
2228
2229 mutex_lock(&vfdb->event_mutex);
2230 events = vfdb->event_occur;
2231 vfdb->event_occur = 0;
2232 mutex_unlock(&vfdb->event_mutex);
2233
2234 for_each_vf(bp, vf_idx) {
2235 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2236 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2237
2238
2239 if (!(events & (1ULL << vf_idx)))
2240 continue;
2241
2242 DP(BNX2X_MSG_IOV,
2243 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2244 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2245 mbx->first_tlv.resp_msg_offset);
2246
2247
2248 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2249 vf->abs_vfid, mbx->vf_addr_hi,
2250 mbx->vf_addr_lo,
2251 sizeof(union vfpf_tlvs)/4);
2252 if (rc) {
2253 BNX2X_ERR("Failed to copy request VF %d\n",
2254 vf->abs_vfid);
2255 bnx2x_vf_release(bp, vf);
2256 return;
2257 }
2258
2259
2260 mbx->first_tlv = mbx->msg->req.first_tlv;
2261
2262
2263
2264
2265 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2266
2267
2268 bnx2x_vf_mbx_request(bp, vf, mbx);
2269 }
2270}
2271
2272void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2273 bool support_long)
2274{
2275
2276
2277
2278 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2279 BULLETIN_CONTENT_LEGACY_SIZE;
2280 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2281}
2282
2283
2284int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2285{
2286 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2287 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2288 vf * BULLETIN_CONTENT_SIZE;
2289 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2290 int rc;
2291
2292
2293 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2294 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2295 return 0;
2296
2297
2298 bulletin->version++;
2299 bnx2x_vf_bulletin_finalize(bulletin,
2300 (bnx2x_vf(bp, vf, cfg_flags) &
2301 VF_CFG_EXT_BULLETIN) ? true : false);
2302
2303
2304 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2305 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2306 U64_LO(vf_addr), bulletin->length / 4);
2307 return rc;
2308}
2309