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