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