1 /* bnx2x_vfpf.c: QLogic Everest network driver.
3 * Copyright 2009-2013 Broadcom Corporation
4 * Copyright 2014 QLogic Corporation
7 * Unless you and QLogic execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2, available
10 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
12 * Notwithstanding the above, under no circumstances may you combine this
13 * software in any way with any other QLogic software provided under a
14 * license other than the GPL, without QLogic's express prior written
17 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
18 * Written by: Shmulik Ravid
19 * Ariel Elior <ariel.elior@qlogic.com>
23 #include "bnx2x_cmn.h"
24 #include <linux/crc32.h>
26 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
28 /* place a given tlv on the tlv buffer at a given offset */
29 static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
30 u16 offset, u16 type, u16 length)
32 struct channel_tlv *tl =
33 (struct channel_tlv *)(tlvs_list + offset);
39 /* Clear the mailbox and init the header of the first tlv */
40 static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
43 mutex_lock(&bp->vf2pf_mutex);
45 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
49 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
51 /* init type and length */
52 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
54 /* init first tlv header */
55 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
58 /* releases the mailbox */
59 static void bnx2x_vfpf_finalize(struct bnx2x *bp,
60 struct vfpf_first_tlv *first_tlv)
62 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
65 mutex_unlock(&bp->vf2pf_mutex);
68 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
69 static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
70 enum channel_tlvs req_tlv)
72 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
75 if (tlv->type == req_tlv)
79 BNX2X_ERR("Found TLV with length 0\n");
83 tlvs_list += tlv->length;
84 tlv = (struct channel_tlv *)tlvs_list;
85 } while (tlv->type != CHANNEL_TLV_LIST_END);
87 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
92 /* list the types and lengths of the tlvs on the buffer */
93 static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
96 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
98 while (tlv->type != CHANNEL_TLV_LIST_END) {
100 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
101 tlv->type, tlv->length);
103 /* advance to next tlv */
104 tlvs_list += tlv->length;
106 /* cast general tlv list pointer to channel tlv header*/
107 tlv = (struct channel_tlv *)tlvs_list;
111 /* break condition for this loop */
112 if (i > MAX_TLVS_IN_LIST) {
113 WARN(true, "corrupt tlvs");
118 /* output last tlv */
119 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
120 tlv->type, tlv->length);
123 /* test whether we support a tlv type */
124 bool bnx2x_tlv_supported(u16 tlvtype)
126 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
129 static inline int bnx2x_pfvf_status_codes(int rc)
133 return PFVF_STATUS_SUCCESS;
135 return PFVF_STATUS_NO_RESOURCE;
137 return PFVF_STATUS_FAILURE;
141 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
143 struct cstorm_vf_zone_data __iomem *zone_data =
144 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
145 int tout = 100, interval = 100; /* wait for 10 seconds */
148 BNX2X_ERR("done was non zero before message to pf was sent\n");
153 /* if PF indicated channel is down avoid sending message. Return success
154 * so calling flow can continue
156 bnx2x_sample_bulletin(bp);
157 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
158 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
159 *done = PFVF_STATUS_SUCCESS;
163 /* Write message address */
164 writel(U64_LO(msg_mapping),
165 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
166 writel(U64_HI(msg_mapping),
167 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
169 /* make sure the address is written before FW accesses it */
172 /* Trigger the PF FW */
173 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
175 /* Wait for PF to complete */
176 while ((tout >= 0) && (!*done)) {
180 /* progress indicator - HV can take its own sweet time in
183 DP_CONT(BNX2X_MSG_IOV, ".");
187 BNX2X_ERR("PF response has timed out\n");
190 DP(BNX2X_MSG_SP, "Got a response from PF\n");
194 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
197 int tout = 10, interval = 100; /* Wait for 1 sec */
200 /* pxp traps vf read of doorbells and returns me reg value */
201 me_reg = readl(bp->doorbells);
202 if (GOOD_ME_REG(me_reg))
207 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
209 } while (tout-- > 0);
211 if (!GOOD_ME_REG(me_reg)) {
212 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
216 DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
218 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
223 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
225 int rc = 0, attempts = 0;
226 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
227 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
228 struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
229 struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
231 bool resources_acquired = false;
233 /* clear mailbox and prep first tlv */
234 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
236 if (bnx2x_get_vf_id(bp, &vf_id)) {
241 req->vfdev_info.vf_id = vf_id;
242 req->vfdev_info.vf_os = 0;
243 req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
245 req->resc_request.num_rxqs = rx_count;
246 req->resc_request.num_txqs = tx_count;
247 req->resc_request.num_sbs = bp->igu_sb_cnt;
248 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
249 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
251 /* pf 2 vf bulletin board address */
252 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
254 /* Request physical port identifier */
255 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
256 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
258 /* Bulletin support for bulletin board with length > legacy length */
259 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
261 /* add list termination tlv */
262 bnx2x_add_tlv(bp, req,
263 req->first_tlv.tl.length + sizeof(struct channel_tlv),
264 CHANNEL_TLV_LIST_END,
265 sizeof(struct channel_list_end_tlv));
267 /* output tlvs list */
268 bnx2x_dp_tlv_list(bp, req);
270 while (!resources_acquired) {
271 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
273 /* send acquire request */
274 rc = bnx2x_send_msg2pf(bp,
276 bp->vf2pf_mbox_mapping);
282 /* copy acquire response from buffer to bp */
283 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
287 /* test whether the PF accepted our request. If not, humble
288 * the request and try again.
290 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
291 DP(BNX2X_MSG_SP, "resources acquired\n");
292 resources_acquired = true;
293 } else if (bp->acquire_resp.hdr.status ==
294 PFVF_STATUS_NO_RESOURCE &&
295 attempts < VF_ACQUIRE_THRESH) {
297 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
299 /* humble our request */
300 req->resc_request.num_txqs =
301 min(req->resc_request.num_txqs,
302 bp->acquire_resp.resc.num_txqs);
303 req->resc_request.num_rxqs =
304 min(req->resc_request.num_rxqs,
305 bp->acquire_resp.resc.num_rxqs);
306 req->resc_request.num_sbs =
307 min(req->resc_request.num_sbs,
308 bp->acquire_resp.resc.num_sbs);
309 req->resc_request.num_mac_filters =
310 min(req->resc_request.num_mac_filters,
311 bp->acquire_resp.resc.num_mac_filters);
312 req->resc_request.num_vlan_filters =
313 min(req->resc_request.num_vlan_filters,
314 bp->acquire_resp.resc.num_vlan_filters);
315 req->resc_request.num_mc_filters =
316 min(req->resc_request.num_mc_filters,
317 bp->acquire_resp.resc.num_mc_filters);
319 /* Clear response buffer */
320 memset(&bp->vf2pf_mbox->resp, 0,
321 sizeof(union pfvf_tlvs));
323 /* Determine reason of PF failure of acquire process */
324 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
325 CHANNEL_TLV_FP_HSI_SUPPORT);
326 if (fp_hsi_resp && !fp_hsi_resp->is_supported)
327 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
329 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
330 bp->acquire_resp.hdr.status);
336 /* Retrieve physical port id (if possible) */
337 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
338 bnx2x_search_tlv_list(bp, resp,
339 CHANNEL_TLV_PHYS_PORT_ID);
340 if (phys_port_resp) {
341 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
342 bp->flags |= HAS_PHYS_PORT_ID;
345 /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
346 * If that's the case, we need to make certain required FW was
347 * supported by such a hypervisor [i.e., v0-v2].
349 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
350 CHANNEL_TLV_FP_HSI_SUPPORT);
351 if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
352 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
354 /* Since acquire succeeded on the PF side, we need to send a
355 * release message in order to allow future probes.
357 bnx2x_vfpf_finalize(bp, &req->first_tlv);
358 bnx2x_vfpf_release(bp);
365 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
366 bp->link_params.chip_id = bp->common.chip_id;
367 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
368 bp->common.int_block = INT_BLOCK_IGU;
369 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
373 bp->common.flash_size = 0;
375 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
376 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
377 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
378 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
381 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
382 memcpy(bp->dev->dev_addr,
383 bp->acquire_resp.resc.current_mac_addr,
387 bnx2x_vfpf_finalize(bp, &req->first_tlv);
391 int bnx2x_vfpf_release(struct bnx2x *bp)
393 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
394 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
397 /* clear mailbox and prep first tlv */
398 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
400 if (bnx2x_get_vf_id(bp, &vf_id)) {
407 /* add list termination tlv */
408 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
409 sizeof(struct channel_list_end_tlv));
411 /* output tlvs list */
412 bnx2x_dp_tlv_list(bp, req);
414 /* send release request */
415 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
421 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
423 DP(BNX2X_MSG_SP, "vf released\n");
425 /* PF reports error */
426 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
432 bnx2x_vfpf_finalize(bp, &req->first_tlv);
437 /* Tell PF about SB addresses */
438 int bnx2x_vfpf_init(struct bnx2x *bp)
440 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
441 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
444 /* clear mailbox and prep first tlv */
445 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
448 for_each_eth_queue(bp, i)
449 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
452 /* statistics - requests only supports single queue for now */
453 req->stats_addr = bp->fw_stats_data_mapping +
454 offsetof(struct bnx2x_fw_stats_data, queue_stats);
456 req->stats_stride = sizeof(struct per_queue_stats);
458 /* add list termination tlv */
459 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
460 sizeof(struct channel_list_end_tlv));
462 /* output tlvs list */
463 bnx2x_dp_tlv_list(bp, req);
465 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
469 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
470 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
476 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
478 bnx2x_vfpf_finalize(bp, &req->first_tlv);
483 /* CLOSE VF - opposite to INIT_VF */
484 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
486 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
487 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
491 /* If we haven't got a valid VF id, there is no sense to
492 * continue with sending messages
494 if (bnx2x_get_vf_id(bp, &vf_id))
497 /* Close the queues */
498 for_each_queue(bp, i)
499 bnx2x_vfpf_teardown_queue(bp, i);
502 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
504 /* clear mailbox and prep first tlv */
505 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
509 /* add list termination tlv */
510 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
511 sizeof(struct channel_list_end_tlv));
513 /* output tlvs list */
514 bnx2x_dp_tlv_list(bp, req);
516 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
519 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
521 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
522 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
525 bnx2x_vfpf_finalize(bp, &req->first_tlv);
528 /* Disable HW interrupts, NAPI */
529 bnx2x_netif_stop(bp, 0);
530 /* Delete all NAPI objects */
531 bnx2x_del_all_napi(bp);
537 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
538 struct bnx2x_vf_queue *q)
540 u8 cl_id = vfq_cl_id(vf, q);
541 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
544 bnx2x_init_mac_obj(bp, &q->mac_obj,
545 cl_id, q->cid, func_id,
546 bnx2x_vf_sp(bp, vf, mac_rdata),
547 bnx2x_vf_sp_map(bp, vf, mac_rdata),
548 BNX2X_FILTER_MAC_PENDING,
550 BNX2X_OBJ_TYPE_RX_TX,
553 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
554 cl_id, q->cid, func_id,
555 bnx2x_vf_sp(bp, vf, vlan_rdata),
556 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
557 BNX2X_FILTER_VLAN_PENDING,
559 BNX2X_OBJ_TYPE_RX_TX,
563 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
564 q->cid, func_id, func_id,
565 bnx2x_vf_sp(bp, vf, mcast_rdata),
566 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
567 BNX2X_FILTER_MCAST_PENDING,
569 BNX2X_OBJ_TYPE_RX_TX);
572 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
574 bnx2x_vf_sp(bp, vf, rss_rdata),
575 bnx2x_vf_sp_map(bp, vf, rss_rdata),
576 BNX2X_FILTER_RSS_CONF_PENDING,
578 BNX2X_OBJ_TYPE_RX_TX);
580 vf->leading_rss = cl_id;
581 q->is_leading = true;
582 q->sp_initialized = true;
585 /* ask the pf to open a queue for the vf */
586 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
589 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
590 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
591 u8 fp_idx = fp->index;
592 u16 tpa_agg_size = 0, flags = 0;
595 /* clear mailbox and prep first tlv */
596 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
598 /* select tpa mode to request */
599 if (fp->mode != TPA_MODE_DISABLED) {
600 flags |= VFPF_QUEUE_FLG_TPA;
601 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
602 if (fp->mode == TPA_MODE_GRO)
603 flags |= VFPF_QUEUE_FLG_TPA_GRO;
604 tpa_agg_size = TPA_AGG_SIZE;
608 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
610 /* calculate queue flags */
611 flags |= VFPF_QUEUE_FLG_STATS;
612 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
613 flags |= VFPF_QUEUE_FLG_VLAN;
616 req->vf_qid = fp_idx;
617 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
620 req->rxq.rcq_addr = fp->rx_comp_mapping;
621 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
622 req->rxq.rxq_addr = fp->rx_desc_mapping;
623 req->rxq.sge_addr = fp->rx_sge_mapping;
624 req->rxq.vf_sb = fp_idx;
625 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
626 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
627 req->rxq.mtu = bp->dev->mtu;
628 req->rxq.buf_sz = fp->rx_buf_size;
629 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
630 req->rxq.tpa_agg_sz = tpa_agg_size;
631 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
632 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
633 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
634 req->rxq.flags = flags;
635 req->rxq.drop_flags = 0;
636 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
637 req->rxq.stat_id = -1; /* No stats at the moment */
640 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
641 req->txq.vf_sb = fp_idx;
642 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
643 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
644 req->txq.flags = flags;
645 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
647 /* add list termination tlv */
648 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
649 sizeof(struct channel_list_end_tlv));
651 /* output tlvs list */
652 bnx2x_dp_tlv_list(bp, req);
654 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
656 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
659 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
660 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
661 fp_idx, resp->hdr.status);
665 bnx2x_vfpf_finalize(bp, &req->first_tlv);
670 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
672 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
673 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
676 /* clear mailbox and prep first tlv */
677 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
682 /* add list termination tlv */
683 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
684 sizeof(struct channel_list_end_tlv));
686 /* output tlvs list */
687 bnx2x_dp_tlv_list(bp, req);
689 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
692 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
697 /* PF failed the transaction */
698 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
699 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
705 bnx2x_vfpf_finalize(bp, &req->first_tlv);
710 /* request pf to add a mac for the vf */
711 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
713 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
714 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
715 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
718 /* clear mailbox and prep first tlv */
719 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
722 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
723 req->vf_qid = vf_qid;
724 req->n_mac_vlan_filters = 1;
726 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
728 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
730 /* sample bulletin board for new mac */
731 bnx2x_sample_bulletin(bp);
733 /* copy mac from device to request */
734 memcpy(req->filters[0].mac, addr, ETH_ALEN);
736 /* add list termination tlv */
737 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
738 sizeof(struct channel_list_end_tlv));
740 /* output tlvs list */
741 bnx2x_dp_tlv_list(bp, req);
743 /* send message to pf */
744 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
746 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
750 /* failure may mean PF was configured with a new mac for us */
751 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
753 "vfpf SET MAC failed. Check bulletin board for new posts\n");
755 /* copy mac from bulletin to device */
756 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
758 /* check if bulletin board was updated */
759 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
760 /* copy mac from device to request */
761 memcpy(req->filters[0].mac, bp->dev->dev_addr,
764 /* send message to pf */
765 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
766 bp->vf2pf_mbox_mapping);
768 /* no new info in bulletin */
773 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
774 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
778 bnx2x_vfpf_finalize(bp, &req->first_tlv);
783 /* request pf to config rss table for vf queues*/
784 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
785 struct bnx2x_config_rss_params *params)
787 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
788 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
791 /* clear mailbox and prep first tlv */
792 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
795 /* add list termination tlv */
796 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
797 sizeof(struct channel_list_end_tlv));
799 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
800 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
801 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
802 req->rss_key_size = T_ETH_RSS_KEY;
803 req->rss_result_mask = params->rss_result_mask;
805 /* flags handled individually for backward/forward compatibility */
806 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
807 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
808 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
809 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
810 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
811 req->rss_flags |= VFPF_RSS_SET_SRCH;
812 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
813 req->rss_flags |= VFPF_RSS_IPV4;
814 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
815 req->rss_flags |= VFPF_RSS_IPV4_TCP;
816 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
817 req->rss_flags |= VFPF_RSS_IPV4_UDP;
818 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
819 req->rss_flags |= VFPF_RSS_IPV6;
820 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
821 req->rss_flags |= VFPF_RSS_IPV6_TCP;
822 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
823 req->rss_flags |= VFPF_RSS_IPV6_UDP;
825 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
827 /* output tlvs list */
828 bnx2x_dp_tlv_list(bp, req);
830 /* send message to pf */
831 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
833 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
837 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
838 /* Since older drivers don't support this feature (and VF has
839 * no way of knowing other than failing this), don't propagate
840 * an error in this case.
843 "Failed to send rss message to PF over VF-PF channel [%d]\n",
847 bnx2x_vfpf_finalize(bp, &req->first_tlv);
852 int bnx2x_vfpf_set_mcast(struct net_device *dev)
854 struct bnx2x *bp = netdev_priv(dev);
855 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
856 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
858 struct netdev_hw_addr *ha;
860 if (bp->state != BNX2X_STATE_OPEN) {
861 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
865 /* clear mailbox and prep first tlv */
866 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
869 /* Get Rx mode requested */
870 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
872 netdev_for_each_mc_addr(ha, dev) {
873 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
875 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
879 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
882 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
884 "VF supports not more than %d multicast MAC addresses\n",
885 PFVF_MAX_MULTICAST_PER_VF);
889 req->n_multicast = i;
890 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
893 /* add list termination tlv */
894 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
895 sizeof(struct channel_list_end_tlv));
897 /* output tlvs list */
898 bnx2x_dp_tlv_list(bp, req);
899 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
901 BNX2X_ERR("Sending a message failed: %d\n", rc);
905 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
906 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
911 bnx2x_vfpf_finalize(bp, &req->first_tlv);
916 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
918 int mode = bp->rx_mode;
919 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
920 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
923 /* clear mailbox and prep first tlv */
924 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
927 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
929 /* Ignore everything accept MODE_NONE */
930 if (mode == BNX2X_RX_MODE_NONE) {
931 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
933 /* Current PF driver will not look at the specific flags,
934 * but they are required when working with older drivers on hv.
936 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
937 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
938 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
941 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
944 /* add list termination tlv */
945 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
946 sizeof(struct channel_list_end_tlv));
948 /* output tlvs list */
949 bnx2x_dp_tlv_list(bp, req);
951 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
953 BNX2X_ERR("Sending a message failed: %d\n", rc);
955 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
956 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
960 bnx2x_vfpf_finalize(bp, &req->first_tlv);
965 /* General service functions */
966 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
968 u32 addr = BAR_CSTRORM_INTMEM +
969 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
971 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
974 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
976 u32 addr = BAR_CSTRORM_INTMEM +
977 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
979 REG_WR8(bp, addr, 1);
982 /* enable vf_pf mailbox (aka vf-pf-channel) */
983 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
985 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
987 /* enable the mailbox in the FW */
988 storm_memset_vf_mbx_ack(bp, abs_vfid);
989 storm_memset_vf_mbx_valid(bp, abs_vfid);
991 /* enable the VF access to the mailbox */
992 bnx2x_vf_enable_access(bp, abs_vfid);
995 /* this works only on !E1h */
996 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
997 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
998 u32 vf_addr_lo, u32 len32)
1000 struct dmae_command dmae;
1002 if (CHIP_IS_E1x(bp)) {
1003 BNX2X_ERR("Chip revision does not support VFs\n");
1004 return DMAE_NOT_RDY;
1007 if (!bp->dmae_ready) {
1008 BNX2X_ERR("DMAE is not ready, can not copy\n");
1009 return DMAE_NOT_RDY;
1012 /* set opcode and fixed command fields */
1013 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1016 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1017 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1018 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1020 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1022 dmae.src_addr_lo = vf_addr_lo;
1023 dmae.src_addr_hi = vf_addr_hi;
1024 dmae.dst_addr_lo = U64_LO(pf_addr);
1025 dmae.dst_addr_hi = U64_HI(pf_addr);
1027 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1028 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1029 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1031 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1033 dmae.src_addr_lo = U64_LO(pf_addr);
1034 dmae.src_addr_hi = U64_HI(pf_addr);
1035 dmae.dst_addr_lo = vf_addr_lo;
1036 dmae.dst_addr_hi = vf_addr_hi;
1040 /* issue the command and wait for completion */
1041 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1044 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1045 struct bnx2x_virtf *vf)
1047 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1050 /* prepare response */
1051 type = mbx->first_tlv.tl.type;
1052 length = type == CHANNEL_TLV_ACQUIRE ?
1053 sizeof(struct pfvf_acquire_resp_tlv) :
1054 sizeof(struct pfvf_general_resp_tlv);
1055 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1056 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1057 sizeof(struct channel_list_end_tlv));
1060 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1061 struct bnx2x_virtf *vf,
1064 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1065 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1070 bnx2x_dp_tlv_list(bp, resp);
1071 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1072 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1074 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1077 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1078 mbx->first_tlv.resp_msg_offset;
1079 pf_addr = mbx->msg_mapping +
1080 offsetof(struct bnx2x_vf_mbx_msg, resp);
1082 /* Copy the response buffer. The first u64 is written afterwards, as
1083 * the vf is sensitive to the header being written
1085 vf_addr += sizeof(u64);
1086 pf_addr += sizeof(u64);
1087 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1090 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1092 BNX2X_ERR("Failed to copy response body to VF %d\n",
1096 vf_addr -= sizeof(u64);
1097 pf_addr -= sizeof(u64);
1100 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1103 /* copy the response header including status-done field,
1104 * must be last dmae, must be after FW is acked
1106 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1111 /* unlock channel mutex */
1112 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1115 BNX2X_ERR("Failed to copy response status to VF %d\n",
1122 bnx2x_vf_release(bp, vf);
1125 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1126 struct bnx2x_virtf *vf,
1129 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1130 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1133 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1134 struct bnx2x_virtf *vf,
1138 struct vfpf_port_phys_id_resp_tlv *port_id;
1140 if (!(bp->flags & HAS_PHYS_PORT_ID))
1143 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1144 sizeof(struct vfpf_port_phys_id_resp_tlv));
1146 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1147 (((u8 *)buffer) + *offset);
1148 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1150 /* Offset should continue representing the offset to the tail
1151 * of TLV data (outside this function scope)
1153 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1156 static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1157 struct bnx2x_virtf *vf,
1161 struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1163 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1164 sizeof(struct vfpf_fp_hsi_resp_tlv));
1166 fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1167 (((u8 *)buffer) + *offset);
1168 fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1170 /* Offset should continue representing the offset to the tail
1171 * of TLV data (outside this function scope)
1173 *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1176 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1177 struct bnx2x_vf_mbx *mbx, int vfop_status)
1180 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1181 struct pf_vf_resc *resc = &resp->resc;
1182 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1185 memset(resp, 0, sizeof(*resp));
1187 /* fill in pfdev info */
1188 resp->pfdev_info.chip_num = bp->common.chip_id;
1189 resp->pfdev_info.db_size = bp->db_size;
1190 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1191 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1193 PFVF_CAP_TPA_UPDATE);
1194 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1195 sizeof(resp->pfdev_info.fw_ver));
1197 if (status == PFVF_STATUS_NO_RESOURCE ||
1198 status == PFVF_STATUS_SUCCESS) {
1199 /* set resources numbers, if status equals NO_RESOURCE these
1200 * are max possible numbers
1202 resc->num_rxqs = vf_rxq_count(vf) ? :
1203 bnx2x_vf_max_queue_cnt(bp, vf);
1204 resc->num_txqs = vf_txq_count(vf) ? :
1205 bnx2x_vf_max_queue_cnt(bp, vf);
1206 resc->num_sbs = vf_sb_count(vf);
1207 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1208 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
1209 resc->num_mc_filters = 0;
1211 if (status == PFVF_STATUS_SUCCESS) {
1212 /* fill in the allocated resources */
1213 struct pf_vf_bulletin_content *bulletin =
1214 BP_VF_BULLETIN(bp, vf->index);
1218 vfq_qzone_id(vf, vfq_get(vf, i));
1220 for_each_vf_sb(vf, i) {
1221 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1222 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1225 /* if a mac has been set for this vf, supply it */
1226 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1227 memcpy(resc->current_mac_addr, bulletin->mac,
1233 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"
1234 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1236 resp->pfdev_info.chip_num,
1237 resp->pfdev_info.db_size,
1238 resp->pfdev_info.indices_per_sb,
1239 resp->pfdev_info.pf_cap,
1243 resc->num_mac_filters,
1244 resc->num_vlan_filters,
1245 resc->num_mc_filters,
1246 resp->pfdev_info.fw_ver);
1248 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1249 for (i = 0; i < vf_rxq_count(vf); i++)
1250 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1251 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1252 for (i = 0; i < vf_sb_count(vf); i++)
1253 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1254 resc->hw_sbs[i].hw_sb_id,
1255 resc->hw_sbs[i].sb_qid);
1256 DP_CONT(BNX2X_MSG_IOV, "]\n");
1258 /* prepare response */
1259 length = sizeof(struct pfvf_acquire_resp_tlv);
1260 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1262 /* Handle possible VF requests for physical port identifiers.
1263 * 'length' should continue to indicate the offset of the first empty
1264 * place in the buffer (i.e., where next TLV should be inserted)
1266 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1267 CHANNEL_TLV_PHYS_PORT_ID))
1268 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1270 /* `New' vfs will want to know if fastpath HSI is supported, since
1271 * if that's not the case they could print into system log the fact
1272 * the driver version must be updated.
1274 bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1276 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1277 sizeof(struct channel_list_end_tlv));
1279 /* send the response */
1280 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1283 static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1284 struct vfpf_acquire_tlv *acquire)
1286 /* Windows driver does one of three things:
1287 * 1. Old driver doesn't have bulletin board address set.
1288 * 2. 'Middle' driver sends mc_num == 32.
1289 * 3. New driver sets the OS field.
1291 if (!acquire->bulletin_addr ||
1292 acquire->resc_request.num_mc_filters == 32 ||
1293 ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1300 static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1301 struct bnx2x_virtf *vf,
1302 struct bnx2x_vf_mbx *mbx)
1304 /* Linux drivers which correctly set the doorbell size also
1305 * send a physical port request
1307 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1308 CHANNEL_TLV_PHYS_PORT_ID))
1311 /* Issue does not exist in windows VMs */
1312 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1318 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1319 struct bnx2x_vf_mbx *mbx)
1322 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1324 /* log vfdef info */
1326 "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",
1327 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1328 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1329 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1330 acquire->resc_request.num_vlan_filters,
1331 acquire->resc_request.num_mc_filters);
1333 /* Prevent VFs with old drivers from loading, since they calculate
1334 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
1335 * while being upgraded.
1337 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1340 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1345 /* Verify the VF fastpath HSI can be supported by the loaded FW.
1346 * Linux vfs should be oblivious to changes between v0 and v2.
1348 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1349 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1351 vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
1353 if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1355 "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1356 vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1357 ETH_FP_HSI_VERSION);
1362 /* acquire the resources */
1363 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1365 /* store address of vf's bulletin board */
1366 vf->bulletin_map = acquire->bulletin_addr;
1367 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1368 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1370 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1372 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1377 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1380 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1381 struct bnx2x_vf_mbx *mbx)
1383 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1386 /* record ghost addresses from vf message */
1387 vf->spq_map = init->spq_addr;
1388 vf->fw_stat_map = init->stats_addr;
1389 vf->stats_stride = init->stats_stride;
1390 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1392 /* set VF multiqueue statistics collection mode */
1393 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1394 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1396 /* Update VF's view of link state */
1397 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1398 bnx2x_iov_link_update_vf(bp, vf->index);
1401 bnx2x_vf_mbx_resp(bp, vf, rc);
1404 /* convert MBX queue-flags to standard SP queue-flags */
1405 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1406 unsigned long *sp_q_flags)
1408 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1409 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1410 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1411 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1412 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1413 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1414 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1415 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1416 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1417 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1418 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1419 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1420 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1421 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1422 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1423 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1424 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1425 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1427 /* outer vlan removal is set according to PF's multi function mode */
1429 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1432 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1433 struct bnx2x_vf_mbx *mbx)
1435 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1436 struct bnx2x_vf_queue_construct_params qctor;
1440 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1441 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1442 setup_q->vf_qid, vf_rxq_count(vf));
1447 /* tx queues must be setup alongside rx queues thus if the rx queue
1448 * is not marked as valid there's nothing to do.
1450 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1451 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1452 unsigned long q_type = 0;
1454 struct bnx2x_queue_init_params *init_p;
1455 struct bnx2x_queue_setup_params *setup_p;
1457 if (bnx2x_vfq_is_leading(q))
1458 bnx2x_leading_vfq_init(bp, vf, q);
1460 /* re-init the VF operation context */
1462 sizeof(struct bnx2x_vf_queue_construct_params));
1463 setup_p = &qctor.prep_qsetup;
1464 init_p = &qctor.qstate.params.init;
1466 /* activate immediately */
1467 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1469 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1470 struct bnx2x_txq_setup_params *txq_params =
1471 &setup_p->txq_params;
1473 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1475 /* save sb resource index */
1476 q->sb_idx = setup_q->txq.vf_sb;
1479 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1480 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1482 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1485 /* tx setup - flags */
1486 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1489 /* tx setup - general, nothing */
1492 txq_params->dscr_map = setup_q->txq.txq_addr;
1493 txq_params->sb_cq_index = setup_q->txq.sb_index;
1494 txq_params->traffic_type = setup_q->txq.traffic_type;
1496 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1497 q->index, q->sb_idx);
1500 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1501 struct bnx2x_rxq_setup_params *rxq_params =
1502 &setup_p->rxq_params;
1504 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1506 /* Note: there is no support for different SBs
1509 q->sb_idx = setup_q->rxq.vf_sb;
1512 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1513 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1514 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1517 /* rx setup - flags */
1518 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1521 /* rx setup - general */
1522 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1525 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1526 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1527 rxq_params->sge_map = setup_q->rxq.sge_addr;
1528 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1529 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1530 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1531 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1532 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1533 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1534 rxq_params->cache_line_log =
1535 setup_q->rxq.cache_line_log;
1536 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1538 /* rx setup - multicast engine */
1539 if (bnx2x_vfq_is_leading(q)) {
1540 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1542 rxq_params->mcast_engine_id = mcast_id;
1543 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1546 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1547 q->index, q->sb_idx);
1549 /* complete the preparations */
1550 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1552 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1557 bnx2x_vf_mbx_resp(bp, vf, rc);
1560 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1561 struct bnx2x_virtf *vf,
1562 struct vfpf_set_q_filters_tlv *tlv,
1563 struct bnx2x_vf_mac_vlan_filters **pfl,
1567 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1570 fsz = tlv->n_mac_vlan_filters *
1571 sizeof(struct bnx2x_vf_mac_vlan_filter) +
1572 sizeof(struct bnx2x_vf_mac_vlan_filters);
1574 fl = kzalloc(fsz, GFP_KERNEL);
1578 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1579 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1581 if ((msg_filter->flags & type_flag) != type_flag)
1583 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1584 fl->filters[j].mac = msg_filter->mac;
1585 fl->filters[j].type = BNX2X_VF_FILTER_MAC;
1587 fl->filters[j].vid = msg_filter->vlan_tag;
1588 fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
1590 fl->filters[j].add =
1591 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1603 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1604 struct vfpf_q_mac_vlan_filter *filter)
1606 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1607 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1608 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1609 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1610 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1611 DP_CONT(msglvl, "\n");
1614 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1615 struct vfpf_set_q_filters_tlv *filters)
1619 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1620 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1621 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1622 &filters->filters[i]);
1624 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1625 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1627 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1628 for (i = 0; i < filters->n_multicast; i++)
1629 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1632 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1633 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1635 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1639 struct vfpf_set_q_filters_tlv *msg =
1640 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1642 /* check for any mac/vlan changes */
1643 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1644 /* build mac list */
1645 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1647 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1655 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1662 /* build vlan list */
1665 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1672 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1680 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1681 unsigned long accept = 0;
1682 struct pf_vf_bulletin_content *bulletin =
1683 BP_VF_BULLETIN(bp, vf->index);
1685 /* Ignore VF requested mode; instead set a regular mode */
1686 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1687 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1688 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1689 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1692 /* A packet arriving the vf's mac should be accepted
1693 * with any vlan, unless a vlan has already been
1696 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
1697 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1700 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1705 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1707 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1708 msg->n_multicast, false);
1714 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1715 vf->abs_vfid, msg->vf_qid, rc);
1719 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1720 struct bnx2x_virtf *vf,
1721 struct vfpf_set_q_filters_tlv *filters)
1723 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1726 /* if a mac was already set for this VF via the set vf mac ndo, we only
1727 * accept mac configurations of that mac. Why accept them at all?
1728 * because PF may have been unable to configure the mac at the time
1729 * since queue was not set up.
1731 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1732 /* once a mac was set by ndo can only accept a single mac... */
1733 if (filters->n_mac_vlan_filters > 1) {
1734 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1740 /* ...and only the mac set by the ndo */
1741 if (filters->n_mac_vlan_filters == 1 &&
1742 !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
1743 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1755 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1756 struct bnx2x_virtf *vf,
1757 struct vfpf_set_q_filters_tlv *filters)
1759 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1762 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1763 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1766 /* search for vlan filters */
1767 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1768 if (filters->filters[i].flags &
1769 VFPF_Q_FILTER_VLAN_TAG_VALID) {
1770 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1779 if (filters->vf_qid > vf_rxq_count(vf)) {
1788 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1789 struct bnx2x_virtf *vf,
1790 struct bnx2x_vf_mbx *mbx)
1792 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1795 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1799 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1803 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1807 /* print q_filter message */
1808 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1810 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1812 bnx2x_vf_mbx_resp(bp, vf, rc);
1815 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1816 struct bnx2x_vf_mbx *mbx)
1818 int qid = mbx->msg->req.q_op.vf_qid;
1821 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1824 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1825 bnx2x_vf_mbx_resp(bp, vf, rc);
1828 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1829 struct bnx2x_vf_mbx *mbx)
1833 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1835 rc = bnx2x_vf_close(bp, vf);
1836 bnx2x_vf_mbx_resp(bp, vf, rc);
1839 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1840 struct bnx2x_vf_mbx *mbx)
1844 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1846 rc = bnx2x_vf_free(bp, vf);
1847 bnx2x_vf_mbx_resp(bp, vf, rc);
1850 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1851 struct bnx2x_vf_mbx *mbx)
1853 struct bnx2x_config_rss_params rss;
1854 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1857 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1858 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1859 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1865 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1867 /* set vfop params according to rss tlv */
1868 memcpy(rss.ind_table, rss_tlv->ind_table,
1869 T_ETH_INDIRECTION_TABLE_SIZE);
1870 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
1871 rss.rss_obj = &vf->rss_conf_obj;
1872 rss.rss_result_mask = rss_tlv->rss_result_mask;
1874 /* flags handled individually for backward/forward compatibility */
1876 rss.ramrod_flags = 0;
1878 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1879 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
1880 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1881 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
1882 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1883 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
1884 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1885 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
1886 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1887 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
1888 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1889 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
1890 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1891 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
1892 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1893 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
1894 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1895 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
1897 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1898 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1899 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1900 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1901 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1906 rc = bnx2x_vf_rss_update(bp, vf, &rss);
1908 bnx2x_vf_mbx_resp(bp, vf, rc);
1911 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
1912 struct vfpf_tpa_tlv *tpa_tlv)
1916 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
1917 U_ETH_MAX_SGES_FOR_PACKET) {
1919 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
1920 tpa_tlv->tpa_client_info.max_sges_for_packet,
1921 U_ETH_MAX_SGES_FOR_PACKET);
1924 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
1926 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
1927 tpa_tlv->tpa_client_info.max_tpa_queues,
1934 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
1935 struct bnx2x_vf_mbx *mbx)
1937 struct bnx2x_queue_update_tpa_params vf_op_params;
1938 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
1941 memset(&vf_op_params, 0, sizeof(vf_op_params));
1943 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
1946 vf_op_params.complete_on_both_clients =
1947 tpa_tlv->tpa_client_info.complete_on_both_clients;
1948 vf_op_params.dont_verify_thr =
1949 tpa_tlv->tpa_client_info.dont_verify_thr;
1950 vf_op_params.max_agg_sz =
1951 tpa_tlv->tpa_client_info.max_agg_size;
1952 vf_op_params.max_sges_pkt =
1953 tpa_tlv->tpa_client_info.max_sges_for_packet;
1954 vf_op_params.max_tpa_queues =
1955 tpa_tlv->tpa_client_info.max_tpa_queues;
1956 vf_op_params.sge_buff_sz =
1957 tpa_tlv->tpa_client_info.sge_buff_size;
1958 vf_op_params.sge_pause_thr_high =
1959 tpa_tlv->tpa_client_info.sge_pause_thr_high;
1960 vf_op_params.sge_pause_thr_low =
1961 tpa_tlv->tpa_client_info.sge_pause_thr_low;
1962 vf_op_params.tpa_mode =
1963 tpa_tlv->tpa_client_info.tpa_mode;
1964 vf_op_params.update_ipv4 =
1965 tpa_tlv->tpa_client_info.update_ipv4;
1966 vf_op_params.update_ipv6 =
1967 tpa_tlv->tpa_client_info.update_ipv6;
1969 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
1972 bnx2x_vf_mbx_resp(bp, vf, rc);
1975 /* dispatch request */
1976 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1977 struct bnx2x_vf_mbx *mbx)
1981 /* check if tlv type is known */
1982 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1983 /* Lock the per vf op mutex and note the locker's identity.
1984 * The unlock will take place in mbx response.
1986 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1988 /* switch on the opcode */
1989 switch (mbx->first_tlv.tl.type) {
1990 case CHANNEL_TLV_ACQUIRE:
1991 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1993 case CHANNEL_TLV_INIT:
1994 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1996 case CHANNEL_TLV_SETUP_Q:
1997 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1999 case CHANNEL_TLV_SET_Q_FILTERS:
2000 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2002 case CHANNEL_TLV_TEARDOWN_Q:
2003 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2005 case CHANNEL_TLV_CLOSE:
2006 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2008 case CHANNEL_TLV_RELEASE:
2009 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2011 case CHANNEL_TLV_UPDATE_RSS:
2012 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2014 case CHANNEL_TLV_UPDATE_TPA:
2015 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2020 /* unknown TLV - this may belong to a VF driver from the future
2021 * - a version written after this PF driver was written, which
2022 * supports features unknown as of yet. Too bad since we don't
2023 * support them. Or this may be because someone wrote a crappy
2024 * VF driver and is sending garbage over the channel.
2026 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2027 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2029 for (i = 0; i < 20; i++)
2030 DP_CONT(BNX2X_MSG_IOV, "%x ",
2031 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2034 /* can we respond to VF (do we have an address for it?) */
2035 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2036 /* notify the VF that we do not support this request */
2037 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2039 /* can't send a response since this VF is unknown to us
2040 * just ack the FW to release the mailbox and unlock
2043 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2044 /* Firmware ack should be written before unlocking channel */
2046 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2050 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2051 struct vf_pf_event_data *vfpf_event)
2056 "vf pf event received: vfid %d, address_hi %x, address lo %x",
2057 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2058 /* Sanity checks consider removing later */
2060 /* check if the vf_id is valid */
2061 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2062 BNX2X_NR_VIRTFN(bp)) {
2063 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2064 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2068 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2070 /* Update VFDB with current message and schedule its handling */
2071 mutex_lock(&BP_VFDB(bp)->event_mutex);
2072 BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
2073 BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
2074 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2075 mutex_unlock(&BP_VFDB(bp)->event_mutex);
2077 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2080 /* handle new vf-pf messages */
2081 void bnx2x_vf_mbx(struct bnx2x *bp)
2083 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2091 mutex_lock(&vfdb->event_mutex);
2092 events = vfdb->event_occur;
2093 vfdb->event_occur = 0;
2094 mutex_unlock(&vfdb->event_mutex);
2096 for_each_vf(bp, vf_idx) {
2097 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2098 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2100 /* Handle VFs which have pending events */
2101 if (!(events & (1ULL << vf_idx)))
2105 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2106 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2107 mbx->first_tlv.resp_msg_offset);
2109 /* dmae to get the VF request */
2110 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2111 vf->abs_vfid, mbx->vf_addr_hi,
2113 sizeof(union vfpf_tlvs)/4);
2115 BNX2X_ERR("Failed to copy request VF %d\n",
2117 bnx2x_vf_release(bp, vf);
2121 /* process the VF message header */
2122 mbx->first_tlv = mbx->msg->req.first_tlv;
2124 /* Clean response buffer to refrain from falsely
2127 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2129 /* dispatch the request (will prepare the response) */
2130 bnx2x_vf_mbx_request(bp, vf, mbx);
2134 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2137 /* Older VFs contain a bug where they can't check CRC for bulletin
2138 * boards of length greater than legacy size.
2140 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2141 BULLETIN_CONTENT_LEGACY_SIZE;
2142 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2145 /* propagate local bulletin board to vf */
2146 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2148 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2149 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2150 vf * BULLETIN_CONTENT_SIZE;
2151 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2154 /* can only update vf after init took place */
2155 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2156 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2159 /* increment bulletin board version and compute crc */
2160 bulletin->version++;
2161 bnx2x_vf_bulletin_finalize(bulletin,
2162 (bnx2x_vf(bp, vf, cfg_flags) &
2163 VF_CFG_EXT_BULLETIN) ? true : false);
2165 /* propagate bulletin board via dmae to vm memory */
2166 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2167 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2168 U64_LO(vf_addr), bulletin->length / 4);