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_relaxed(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;
250 req->resc_request.num_vlan_filters = VF_ACQUIRE_VLAN_FILTERS;
252 /* pf 2 vf bulletin board address */
253 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
255 /* Request physical port identifier */
256 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
257 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
259 /* Bulletin support for bulletin board with length > legacy length */
260 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
261 /* vlan filtering is supported */
262 req->vfdev_info.caps |= VF_CAP_SUPPORT_VLAN_FILTER;
264 /* add list termination tlv */
265 bnx2x_add_tlv(bp, req,
266 req->first_tlv.tl.length + sizeof(struct channel_tlv),
267 CHANNEL_TLV_LIST_END,
268 sizeof(struct channel_list_end_tlv));
270 /* output tlvs list */
271 bnx2x_dp_tlv_list(bp, req);
273 while (!resources_acquired) {
274 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
276 /* send acquire request */
277 rc = bnx2x_send_msg2pf(bp,
279 bp->vf2pf_mbox_mapping);
285 /* copy acquire response from buffer to bp */
286 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
290 /* test whether the PF accepted our request. If not, humble
291 * the request and try again.
293 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
294 DP(BNX2X_MSG_SP, "resources acquired\n");
295 resources_acquired = true;
296 } else if (bp->acquire_resp.hdr.status ==
297 PFVF_STATUS_NO_RESOURCE &&
298 attempts < VF_ACQUIRE_THRESH) {
300 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
302 /* humble our request */
303 req->resc_request.num_txqs =
304 min(req->resc_request.num_txqs,
305 bp->acquire_resp.resc.num_txqs);
306 req->resc_request.num_rxqs =
307 min(req->resc_request.num_rxqs,
308 bp->acquire_resp.resc.num_rxqs);
309 req->resc_request.num_sbs =
310 min(req->resc_request.num_sbs,
311 bp->acquire_resp.resc.num_sbs);
312 req->resc_request.num_mac_filters =
313 min(req->resc_request.num_mac_filters,
314 bp->acquire_resp.resc.num_mac_filters);
315 req->resc_request.num_vlan_filters =
316 min(req->resc_request.num_vlan_filters,
317 bp->acquire_resp.resc.num_vlan_filters);
318 req->resc_request.num_mc_filters =
319 min(req->resc_request.num_mc_filters,
320 bp->acquire_resp.resc.num_mc_filters);
322 /* Clear response buffer */
323 memset(&bp->vf2pf_mbox->resp, 0,
324 sizeof(union pfvf_tlvs));
326 /* Determine reason of PF failure of acquire process */
327 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
328 CHANNEL_TLV_FP_HSI_SUPPORT);
329 if (fp_hsi_resp && !fp_hsi_resp->is_supported)
330 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
332 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
333 bp->acquire_resp.hdr.status);
339 /* Retrieve physical port id (if possible) */
340 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
341 bnx2x_search_tlv_list(bp, resp,
342 CHANNEL_TLV_PHYS_PORT_ID);
343 if (phys_port_resp) {
344 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
345 bp->flags |= HAS_PHYS_PORT_ID;
348 /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
349 * If that's the case, we need to make certain required FW was
350 * supported by such a hypervisor [i.e., v0-v2].
352 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
353 CHANNEL_TLV_FP_HSI_SUPPORT);
354 if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
355 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
357 /* Since acquire succeeded on the PF side, we need to send a
358 * release message in order to allow future probes.
360 bnx2x_vfpf_finalize(bp, &req->first_tlv);
361 bnx2x_vfpf_release(bp);
368 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
369 bp->link_params.chip_id = bp->common.chip_id;
370 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
371 bp->common.int_block = INT_BLOCK_IGU;
372 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
376 bp->common.flash_size = 0;
378 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
379 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
380 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
381 bp->vlan_credit = bp->acquire_resp.resc.num_vlan_filters;
383 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
386 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
387 memcpy(bp->dev->dev_addr,
388 bp->acquire_resp.resc.current_mac_addr,
392 bnx2x_vfpf_finalize(bp, &req->first_tlv);
396 int bnx2x_vfpf_release(struct bnx2x *bp)
398 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
399 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
402 /* clear mailbox and prep first tlv */
403 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
405 if (bnx2x_get_vf_id(bp, &vf_id)) {
412 /* add list termination tlv */
413 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
414 sizeof(struct channel_list_end_tlv));
416 /* output tlvs list */
417 bnx2x_dp_tlv_list(bp, req);
419 /* send release request */
420 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
426 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
428 DP(BNX2X_MSG_SP, "vf released\n");
430 /* PF reports error */
431 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
437 bnx2x_vfpf_finalize(bp, &req->first_tlv);
442 /* Tell PF about SB addresses */
443 int bnx2x_vfpf_init(struct bnx2x *bp)
445 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
446 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
449 /* clear mailbox and prep first tlv */
450 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
453 for_each_eth_queue(bp, i)
454 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
457 /* statistics - requests only supports single queue for now */
458 req->stats_addr = bp->fw_stats_data_mapping +
459 offsetof(struct bnx2x_fw_stats_data, queue_stats);
461 req->stats_stride = sizeof(struct per_queue_stats);
463 /* add list termination tlv */
464 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
465 sizeof(struct channel_list_end_tlv));
467 /* output tlvs list */
468 bnx2x_dp_tlv_list(bp, req);
470 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
474 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
475 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
481 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
483 bnx2x_vfpf_finalize(bp, &req->first_tlv);
488 /* CLOSE VF - opposite to INIT_VF */
489 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
491 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
492 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
496 /* If we haven't got a valid VF id, there is no sense to
497 * continue with sending messages
499 if (bnx2x_get_vf_id(bp, &vf_id))
502 /* Close the queues */
503 for_each_queue(bp, i)
504 bnx2x_vfpf_teardown_queue(bp, i);
507 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
509 /* clear mailbox and prep first tlv */
510 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
514 /* add list termination tlv */
515 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
516 sizeof(struct channel_list_end_tlv));
518 /* output tlvs list */
519 bnx2x_dp_tlv_list(bp, req);
521 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
524 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
526 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
527 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
530 bnx2x_vfpf_finalize(bp, &req->first_tlv);
533 /* Disable HW interrupts, NAPI */
534 bnx2x_netif_stop(bp, 0);
535 /* Delete all NAPI objects */
536 bnx2x_del_all_napi(bp);
542 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
543 struct bnx2x_vf_queue *q)
545 u8 cl_id = vfq_cl_id(vf, q);
546 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
549 bnx2x_init_mac_obj(bp, &q->mac_obj,
550 cl_id, q->cid, func_id,
551 bnx2x_vf_sp(bp, vf, mac_rdata),
552 bnx2x_vf_sp_map(bp, vf, mac_rdata),
553 BNX2X_FILTER_MAC_PENDING,
555 BNX2X_OBJ_TYPE_RX_TX,
558 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
559 cl_id, q->cid, func_id,
560 bnx2x_vf_sp(bp, vf, vlan_rdata),
561 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
562 BNX2X_FILTER_VLAN_PENDING,
564 BNX2X_OBJ_TYPE_RX_TX,
567 bnx2x_init_vlan_mac_obj(bp, &q->vlan_mac_obj,
568 cl_id, q->cid, func_id,
569 bnx2x_vf_sp(bp, vf, vlan_mac_rdata),
570 bnx2x_vf_sp_map(bp, vf, vlan_mac_rdata),
571 BNX2X_FILTER_VLAN_MAC_PENDING,
573 BNX2X_OBJ_TYPE_RX_TX,
577 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
578 q->cid, func_id, func_id,
579 bnx2x_vf_sp(bp, vf, mcast_rdata),
580 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
581 BNX2X_FILTER_MCAST_PENDING,
583 BNX2X_OBJ_TYPE_RX_TX);
586 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
588 bnx2x_vf_sp(bp, vf, rss_rdata),
589 bnx2x_vf_sp_map(bp, vf, rss_rdata),
590 BNX2X_FILTER_RSS_CONF_PENDING,
592 BNX2X_OBJ_TYPE_RX_TX);
594 vf->leading_rss = cl_id;
595 q->is_leading = true;
596 q->sp_initialized = true;
599 /* ask the pf to open a queue for the vf */
600 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
603 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
604 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
605 u8 fp_idx = fp->index;
606 u16 tpa_agg_size = 0, flags = 0;
609 /* clear mailbox and prep first tlv */
610 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
612 /* select tpa mode to request */
613 if (fp->mode != TPA_MODE_DISABLED) {
614 flags |= VFPF_QUEUE_FLG_TPA;
615 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
616 if (fp->mode == TPA_MODE_GRO)
617 flags |= VFPF_QUEUE_FLG_TPA_GRO;
618 tpa_agg_size = TPA_AGG_SIZE;
622 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
624 /* calculate queue flags */
625 flags |= VFPF_QUEUE_FLG_STATS;
626 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
627 flags |= VFPF_QUEUE_FLG_VLAN;
630 req->vf_qid = fp_idx;
631 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
634 req->rxq.rcq_addr = fp->rx_comp_mapping;
635 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
636 req->rxq.rxq_addr = fp->rx_desc_mapping;
637 req->rxq.sge_addr = fp->rx_sge_mapping;
638 req->rxq.vf_sb = fp_idx;
639 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
640 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
641 req->rxq.mtu = bp->dev->mtu;
642 req->rxq.buf_sz = fp->rx_buf_size;
643 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
644 req->rxq.tpa_agg_sz = tpa_agg_size;
645 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
646 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
647 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
648 req->rxq.flags = flags;
649 req->rxq.drop_flags = 0;
650 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
651 req->rxq.stat_id = -1; /* No stats at the moment */
654 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
655 req->txq.vf_sb = fp_idx;
656 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
657 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
658 req->txq.flags = flags;
659 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
661 /* add list termination tlv */
662 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
663 sizeof(struct channel_list_end_tlv));
665 /* output tlvs list */
666 bnx2x_dp_tlv_list(bp, req);
668 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
670 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
673 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
674 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
675 fp_idx, resp->hdr.status);
679 bnx2x_vfpf_finalize(bp, &req->first_tlv);
684 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
686 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
687 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
690 /* clear mailbox and prep first tlv */
691 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
696 /* add list termination tlv */
697 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
698 sizeof(struct channel_list_end_tlv));
700 /* output tlvs list */
701 bnx2x_dp_tlv_list(bp, req);
703 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
706 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
711 /* PF failed the transaction */
712 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
713 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
719 bnx2x_vfpf_finalize(bp, &req->first_tlv);
724 /* request pf to add a mac for the vf */
725 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
727 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
728 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
729 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
732 /* clear mailbox and prep first tlv */
733 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
736 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
737 req->vf_qid = vf_qid;
738 req->n_mac_vlan_filters = 1;
740 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
742 req->filters[0].flags |= VFPF_Q_FILTER_SET;
744 /* sample bulletin board for new mac */
745 bnx2x_sample_bulletin(bp);
747 /* copy mac from device to request */
748 memcpy(req->filters[0].mac, addr, ETH_ALEN);
750 /* add list termination tlv */
751 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
752 sizeof(struct channel_list_end_tlv));
754 /* output tlvs list */
755 bnx2x_dp_tlv_list(bp, req);
757 /* send message to pf */
758 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
760 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
764 /* failure may mean PF was configured with a new mac for us */
765 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
767 "vfpf SET MAC failed. Check bulletin board for new posts\n");
769 /* copy mac from bulletin to device */
770 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
772 /* check if bulletin board was updated */
773 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
774 /* copy mac from device to request */
775 memcpy(req->filters[0].mac, bp->dev->dev_addr,
778 /* send message to pf */
779 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
780 bp->vf2pf_mbox_mapping);
782 /* no new info in bulletin */
787 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
788 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
792 bnx2x_vfpf_finalize(bp, &req->first_tlv);
797 /* request pf to config rss table for vf queues*/
798 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
799 struct bnx2x_config_rss_params *params)
801 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
802 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
805 /* clear mailbox and prep first tlv */
806 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
809 /* add list termination tlv */
810 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
811 sizeof(struct channel_list_end_tlv));
813 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
814 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
815 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
816 req->rss_key_size = T_ETH_RSS_KEY;
817 req->rss_result_mask = params->rss_result_mask;
819 /* flags handled individually for backward/forward compatibility */
820 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
821 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
822 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
823 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
824 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
825 req->rss_flags |= VFPF_RSS_SET_SRCH;
826 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
827 req->rss_flags |= VFPF_RSS_IPV4;
828 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
829 req->rss_flags |= VFPF_RSS_IPV4_TCP;
830 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
831 req->rss_flags |= VFPF_RSS_IPV4_UDP;
832 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
833 req->rss_flags |= VFPF_RSS_IPV6;
834 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
835 req->rss_flags |= VFPF_RSS_IPV6_TCP;
836 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
837 req->rss_flags |= VFPF_RSS_IPV6_UDP;
839 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
841 /* output tlvs list */
842 bnx2x_dp_tlv_list(bp, req);
844 /* send message to pf */
845 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
847 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
851 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
852 /* Since older drivers don't support this feature (and VF has
853 * no way of knowing other than failing this), don't propagate
854 * an error in this case.
857 "Failed to send rss message to PF over VF-PF channel [%d]\n",
861 bnx2x_vfpf_finalize(bp, &req->first_tlv);
866 int bnx2x_vfpf_set_mcast(struct net_device *dev)
868 struct bnx2x *bp = netdev_priv(dev);
869 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
870 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
872 struct netdev_hw_addr *ha;
874 if (bp->state != BNX2X_STATE_OPEN) {
875 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
879 /* clear mailbox and prep first tlv */
880 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
883 /* Get Rx mode requested */
884 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
886 /* We support PFVF_MAX_MULTICAST_PER_VF mcast addresses tops */
887 if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) {
889 "VF supports not more than %d multicast MAC addresses\n",
890 PFVF_MAX_MULTICAST_PER_VF);
895 netdev_for_each_mc_addr(ha, dev) {
896 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
898 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
902 req->n_multicast = i;
903 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
906 /* add list termination tlv */
907 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
908 sizeof(struct channel_list_end_tlv));
910 /* output tlvs list */
911 bnx2x_dp_tlv_list(bp, req);
912 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
914 BNX2X_ERR("Sending a message failed: %d\n", rc);
918 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
919 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
924 bnx2x_vfpf_finalize(bp, &req->first_tlv);
929 /* request pf to add a vlan for the vf */
930 int bnx2x_vfpf_update_vlan(struct bnx2x *bp, u16 vid, u8 vf_qid, bool add)
932 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
933 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
936 if (!(bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER)) {
937 DP(BNX2X_MSG_IOV, "HV does not support vlan filtering\n");
941 /* clear mailbox and prep first tlv */
942 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
945 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
946 req->vf_qid = vf_qid;
947 req->n_mac_vlan_filters = 1;
949 req->filters[0].flags = VFPF_Q_FILTER_VLAN_TAG_VALID;
952 req->filters[0].flags |= VFPF_Q_FILTER_SET;
954 /* sample bulletin board for hypervisor vlan */
955 bnx2x_sample_bulletin(bp);
957 if (bp->shadow_bulletin.content.valid_bitmap & 1 << VLAN_VALID) {
958 BNX2X_ERR("Hypervisor will decline the request, avoiding\n");
963 req->filters[0].vlan_tag = vid;
965 /* add list termination tlv */
966 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
967 sizeof(struct channel_list_end_tlv));
969 /* output tlvs list */
970 bnx2x_dp_tlv_list(bp, req);
972 /* send message to pf */
973 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
975 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
979 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
980 BNX2X_ERR("vfpf %s VLAN %d failed\n", add ? "add" : "del",
985 bnx2x_vfpf_finalize(bp, &req->first_tlv);
990 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
992 int mode = bp->rx_mode;
993 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
994 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
997 /* clear mailbox and prep first tlv */
998 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
1001 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
1003 /* Ignore everything accept MODE_NONE */
1004 if (mode == BNX2X_RX_MODE_NONE) {
1005 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
1007 /* Current PF driver will not look at the specific flags,
1008 * but they are required when working with older drivers on hv.
1010 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
1011 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
1012 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
1013 if (mode == BNX2X_RX_MODE_PROMISC)
1014 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
1017 if (bp->accept_any_vlan)
1018 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
1020 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
1023 /* add list termination tlv */
1024 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
1025 sizeof(struct channel_list_end_tlv));
1027 /* output tlvs list */
1028 bnx2x_dp_tlv_list(bp, req);
1030 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
1032 BNX2X_ERR("Sending a message failed: %d\n", rc);
1034 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1035 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
1039 bnx2x_vfpf_finalize(bp, &req->first_tlv);
1044 /* General service functions */
1045 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
1047 u32 addr = BAR_CSTRORM_INTMEM +
1048 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
1050 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
1053 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
1055 u32 addr = BAR_CSTRORM_INTMEM +
1056 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
1058 REG_WR8(bp, addr, 1);
1061 /* enable vf_pf mailbox (aka vf-pf-channel) */
1062 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
1064 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
1066 /* enable the mailbox in the FW */
1067 storm_memset_vf_mbx_ack(bp, abs_vfid);
1068 storm_memset_vf_mbx_valid(bp, abs_vfid);
1070 /* enable the VF access to the mailbox */
1071 bnx2x_vf_enable_access(bp, abs_vfid);
1074 /* this works only on !E1h */
1075 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
1076 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
1077 u32 vf_addr_lo, u32 len32)
1079 struct dmae_command dmae;
1081 if (CHIP_IS_E1x(bp)) {
1082 BNX2X_ERR("Chip revision does not support VFs\n");
1083 return DMAE_NOT_RDY;
1086 if (!bp->dmae_ready) {
1087 BNX2X_ERR("DMAE is not ready, can not copy\n");
1088 return DMAE_NOT_RDY;
1091 /* set opcode and fixed command fields */
1092 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1095 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1096 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1097 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1099 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1101 dmae.src_addr_lo = vf_addr_lo;
1102 dmae.src_addr_hi = vf_addr_hi;
1103 dmae.dst_addr_lo = U64_LO(pf_addr);
1104 dmae.dst_addr_hi = U64_HI(pf_addr);
1106 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1107 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1108 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1110 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1112 dmae.src_addr_lo = U64_LO(pf_addr);
1113 dmae.src_addr_hi = U64_HI(pf_addr);
1114 dmae.dst_addr_lo = vf_addr_lo;
1115 dmae.dst_addr_hi = vf_addr_hi;
1119 /* issue the command and wait for completion */
1120 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1123 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1124 struct bnx2x_virtf *vf)
1126 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1129 /* prepare response */
1130 type = mbx->first_tlv.tl.type;
1131 length = type == CHANNEL_TLV_ACQUIRE ?
1132 sizeof(struct pfvf_acquire_resp_tlv) :
1133 sizeof(struct pfvf_general_resp_tlv);
1134 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1135 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1136 sizeof(struct channel_list_end_tlv));
1139 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1140 struct bnx2x_virtf *vf,
1143 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1144 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1149 bnx2x_dp_tlv_list(bp, resp);
1150 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1151 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1153 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1156 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1157 mbx->first_tlv.resp_msg_offset;
1158 pf_addr = mbx->msg_mapping +
1159 offsetof(struct bnx2x_vf_mbx_msg, resp);
1161 /* Copy the response buffer. The first u64 is written afterwards, as
1162 * the vf is sensitive to the header being written
1164 vf_addr += sizeof(u64);
1165 pf_addr += sizeof(u64);
1166 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1169 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1171 BNX2X_ERR("Failed to copy response body to VF %d\n",
1175 vf_addr -= sizeof(u64);
1176 pf_addr -= sizeof(u64);
1179 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1181 /* copy the response header including status-done field,
1182 * must be last dmae, must be after FW is acked
1184 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1189 /* unlock channel mutex */
1190 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1193 BNX2X_ERR("Failed to copy response status to VF %d\n",
1200 bnx2x_vf_release(bp, vf);
1203 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1204 struct bnx2x_virtf *vf,
1207 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1208 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1211 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1212 struct bnx2x_virtf *vf,
1216 struct vfpf_port_phys_id_resp_tlv *port_id;
1218 if (!(bp->flags & HAS_PHYS_PORT_ID))
1221 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1222 sizeof(struct vfpf_port_phys_id_resp_tlv));
1224 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1225 (((u8 *)buffer) + *offset);
1226 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1228 /* Offset should continue representing the offset to the tail
1229 * of TLV data (outside this function scope)
1231 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1234 static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1235 struct bnx2x_virtf *vf,
1239 struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1241 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1242 sizeof(struct vfpf_fp_hsi_resp_tlv));
1244 fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1245 (((u8 *)buffer) + *offset);
1246 fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1248 /* Offset should continue representing the offset to the tail
1249 * of TLV data (outside this function scope)
1251 *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1254 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1255 struct bnx2x_vf_mbx *mbx, int vfop_status)
1258 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1259 struct pf_vf_resc *resc = &resp->resc;
1260 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1263 memset(resp, 0, sizeof(*resp));
1265 /* fill in pfdev info */
1266 resp->pfdev_info.chip_num = bp->common.chip_id;
1267 resp->pfdev_info.db_size = bp->db_size;
1268 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1269 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1271 PFVF_CAP_TPA_UPDATE |
1272 PFVF_CAP_VLAN_FILTER);
1273 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1274 sizeof(resp->pfdev_info.fw_ver));
1276 if (status == PFVF_STATUS_NO_RESOURCE ||
1277 status == PFVF_STATUS_SUCCESS) {
1278 /* set resources numbers, if status equals NO_RESOURCE these
1279 * are max possible numbers
1281 resc->num_rxqs = vf_rxq_count(vf) ? :
1282 bnx2x_vf_max_queue_cnt(bp, vf);
1283 resc->num_txqs = vf_txq_count(vf) ? :
1284 bnx2x_vf_max_queue_cnt(bp, vf);
1285 resc->num_sbs = vf_sb_count(vf);
1286 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1287 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
1288 resc->num_mc_filters = 0;
1290 if (status == PFVF_STATUS_SUCCESS) {
1291 /* fill in the allocated resources */
1292 struct pf_vf_bulletin_content *bulletin =
1293 BP_VF_BULLETIN(bp, vf->index);
1297 vfq_qzone_id(vf, vfq_get(vf, i));
1299 for_each_vf_sb(vf, i) {
1300 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1301 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1304 /* if a mac has been set for this vf, supply it */
1305 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1306 memcpy(resc->current_mac_addr, bulletin->mac,
1312 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"
1313 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1315 resp->pfdev_info.chip_num,
1316 resp->pfdev_info.db_size,
1317 resp->pfdev_info.indices_per_sb,
1318 resp->pfdev_info.pf_cap,
1322 resc->num_mac_filters,
1323 resc->num_vlan_filters,
1324 resc->num_mc_filters,
1325 resp->pfdev_info.fw_ver);
1327 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1328 for (i = 0; i < vf_rxq_count(vf); i++)
1329 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1330 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1331 for (i = 0; i < vf_sb_count(vf); i++)
1332 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1333 resc->hw_sbs[i].hw_sb_id,
1334 resc->hw_sbs[i].sb_qid);
1335 DP_CONT(BNX2X_MSG_IOV, "]\n");
1337 /* prepare response */
1338 length = sizeof(struct pfvf_acquire_resp_tlv);
1339 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1341 /* Handle possible VF requests for physical port identifiers.
1342 * 'length' should continue to indicate the offset of the first empty
1343 * place in the buffer (i.e., where next TLV should be inserted)
1345 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1346 CHANNEL_TLV_PHYS_PORT_ID))
1347 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1349 /* `New' vfs will want to know if fastpath HSI is supported, since
1350 * if that's not the case they could print into system log the fact
1351 * the driver version must be updated.
1353 bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1355 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1356 sizeof(struct channel_list_end_tlv));
1358 /* send the response */
1359 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1362 static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1363 struct vfpf_acquire_tlv *acquire)
1365 /* Windows driver does one of three things:
1366 * 1. Old driver doesn't have bulletin board address set.
1367 * 2. 'Middle' driver sends mc_num == 32.
1368 * 3. New driver sets the OS field.
1370 if (!acquire->bulletin_addr ||
1371 acquire->resc_request.num_mc_filters == 32 ||
1372 ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1379 static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1380 struct bnx2x_virtf *vf,
1381 struct bnx2x_vf_mbx *mbx)
1383 /* Linux drivers which correctly set the doorbell size also
1384 * send a physical port request
1386 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1387 CHANNEL_TLV_PHYS_PORT_ID))
1390 /* Issue does not exist in windows VMs */
1391 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1397 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1398 struct bnx2x_vf_mbx *mbx)
1401 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1403 /* log vfdef info */
1405 "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",
1406 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1407 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1408 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1409 acquire->resc_request.num_vlan_filters,
1410 acquire->resc_request.num_mc_filters);
1412 /* Prevent VFs with old drivers from loading, since they calculate
1413 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
1414 * while being upgraded.
1416 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1419 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1424 /* Verify the VF fastpath HSI can be supported by the loaded FW.
1425 * Linux vfs should be oblivious to changes between v0 and v2.
1427 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1428 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1430 vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
1432 if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1434 "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1435 vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1436 ETH_FP_HSI_VERSION);
1441 /* acquire the resources */
1442 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1444 /* store address of vf's bulletin board */
1445 vf->bulletin_map = acquire->bulletin_addr;
1446 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1447 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1449 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1451 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1454 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_VLAN_FILTER) {
1455 DP(BNX2X_MSG_IOV, "VF[%d] supports vlan filtering\n",
1457 vf->cfg_flags |= VF_CFG_VLAN_FILTER;
1459 vf->cfg_flags &= ~VF_CFG_VLAN_FILTER;
1464 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1467 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1468 struct bnx2x_vf_mbx *mbx)
1470 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1473 /* record ghost addresses from vf message */
1474 vf->fw_stat_map = init->stats_addr;
1475 vf->stats_stride = init->stats_stride;
1476 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1478 /* set VF multiqueue statistics collection mode */
1479 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1480 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1482 /* Update VF's view of link state */
1483 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1484 bnx2x_iov_link_update_vf(bp, vf->index);
1487 bnx2x_vf_mbx_resp(bp, vf, rc);
1490 /* convert MBX queue-flags to standard SP queue-flags */
1491 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1492 unsigned long *sp_q_flags)
1494 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1495 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1496 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1497 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1498 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1499 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1500 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1501 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1502 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1503 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1504 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1505 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1506 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1507 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1508 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1509 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1510 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1511 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1513 /* outer vlan removal is set according to PF's multi function mode */
1515 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1518 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1519 struct bnx2x_vf_mbx *mbx)
1521 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1522 struct bnx2x_vf_queue_construct_params qctor;
1526 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1527 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1528 setup_q->vf_qid, vf_rxq_count(vf));
1533 /* tx queues must be setup alongside rx queues thus if the rx queue
1534 * is not marked as valid there's nothing to do.
1536 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1537 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1538 unsigned long q_type = 0;
1540 struct bnx2x_queue_init_params *init_p;
1541 struct bnx2x_queue_setup_params *setup_p;
1543 if (bnx2x_vfq_is_leading(q))
1544 bnx2x_leading_vfq_init(bp, vf, q);
1546 /* re-init the VF operation context */
1548 sizeof(struct bnx2x_vf_queue_construct_params));
1549 setup_p = &qctor.prep_qsetup;
1550 init_p = &qctor.qstate.params.init;
1552 /* activate immediately */
1553 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1555 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1556 struct bnx2x_txq_setup_params *txq_params =
1557 &setup_p->txq_params;
1559 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1561 /* save sb resource index */
1562 q->sb_idx = setup_q->txq.vf_sb;
1565 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1566 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1568 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1571 /* tx setup - flags */
1572 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1575 /* tx setup - general, nothing */
1578 txq_params->dscr_map = setup_q->txq.txq_addr;
1579 txq_params->sb_cq_index = setup_q->txq.sb_index;
1580 txq_params->traffic_type = setup_q->txq.traffic_type;
1582 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1583 q->index, q->sb_idx);
1586 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1587 struct bnx2x_rxq_setup_params *rxq_params =
1588 &setup_p->rxq_params;
1590 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1592 /* Note: there is no support for different SBs
1595 q->sb_idx = setup_q->rxq.vf_sb;
1598 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1599 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1600 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1603 /* rx setup - flags */
1604 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1607 /* rx setup - general */
1608 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1611 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1612 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1613 rxq_params->sge_map = setup_q->rxq.sge_addr;
1614 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1615 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1616 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1617 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1618 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1619 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1620 rxq_params->cache_line_log =
1621 setup_q->rxq.cache_line_log;
1622 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1624 /* rx setup - multicast engine */
1625 if (bnx2x_vfq_is_leading(q)) {
1626 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1628 rxq_params->mcast_engine_id = mcast_id;
1629 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1632 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1633 q->index, q->sb_idx);
1635 /* complete the preparations */
1636 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1638 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1643 bnx2x_vf_mbx_resp(bp, vf, rc);
1646 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1647 struct bnx2x_virtf *vf,
1648 struct vfpf_set_q_filters_tlv *tlv,
1649 struct bnx2x_vf_mac_vlan_filters **pfl,
1653 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1655 fl = kzalloc(struct_size(fl, filters, tlv->n_mac_vlan_filters),
1660 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1661 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1663 if ((msg_filter->flags & type_flag) != type_flag)
1665 memset(&fl->filters[j], 0, sizeof(fl->filters[j]));
1666 if (type_flag & VFPF_Q_FILTER_DEST_MAC_VALID) {
1667 fl->filters[j].mac = msg_filter->mac;
1668 fl->filters[j].type |= BNX2X_VF_FILTER_MAC;
1670 if (type_flag & VFPF_Q_FILTER_VLAN_TAG_VALID) {
1671 fl->filters[j].vid = msg_filter->vlan_tag;
1672 fl->filters[j].type |= BNX2X_VF_FILTER_VLAN;
1674 fl->filters[j].add = !!(msg_filter->flags & VFPF_Q_FILTER_SET);
1686 static int bnx2x_vf_filters_contain(struct vfpf_set_q_filters_tlv *filters,
1691 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1692 if ((filters->filters[i].flags & flags) == flags)
1698 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1699 struct vfpf_q_mac_vlan_filter *filter)
1701 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1702 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1703 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1704 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1705 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1706 DP_CONT(msglvl, "\n");
1709 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1710 struct vfpf_set_q_filters_tlv *filters)
1714 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1715 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1716 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1717 &filters->filters[i]);
1719 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1720 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1722 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1723 for (i = 0; i < filters->n_multicast; i++)
1724 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1727 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1728 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1729 #define VFPF_VLAN_MAC_FILTER (VFPF_VLAN_FILTER | VFPF_MAC_FILTER)
1731 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1735 struct vfpf_set_q_filters_tlv *msg =
1736 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1738 /* check for any mac/vlan changes */
1739 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1740 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1742 /* build vlan-mac list */
1743 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1744 VFPF_VLAN_MAC_FILTER);
1750 /* set vlan-mac list */
1751 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1758 /* build mac list */
1761 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1768 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1775 /* build vlan list */
1778 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1785 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1794 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1795 unsigned long accept = 0;
1796 struct pf_vf_bulletin_content *bulletin =
1797 BP_VF_BULLETIN(bp, vf->index);
1799 /* Ignore VF requested mode; instead set a regular mode */
1800 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1801 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1802 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1803 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1806 /* any_vlan is not configured if HV is forcing VLAN
1807 * any_vlan is configured if
1808 * 1. VF does not support vlan filtering
1810 * 2. VF supports vlan filtering and explicitly requested it
1812 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)) &&
1813 (!(vf->cfg_flags & VF_CFG_VLAN_FILTER) ||
1814 msg->rx_mask & VFPF_RX_MASK_ACCEPT_ANY_VLAN))
1815 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1818 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1823 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1825 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1826 msg->n_multicast, false);
1832 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1833 vf->abs_vfid, msg->vf_qid, rc);
1837 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1838 struct bnx2x_virtf *vf,
1839 struct vfpf_set_q_filters_tlv *filters)
1841 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1844 /* if a mac was already set for this VF via the set vf mac ndo, we only
1845 * accept mac configurations of that mac. Why accept them at all?
1846 * because PF may have been unable to configure the mac at the time
1847 * since queue was not set up.
1849 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1850 struct vfpf_q_mac_vlan_filter *filter = NULL;
1853 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1854 if (!(filters->filters[i].flags &
1855 VFPF_Q_FILTER_DEST_MAC_VALID))
1858 /* once a mac was set by ndo can only accept
1862 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called [%d filters]\n",
1864 filters->n_mac_vlan_filters);
1869 filter = &filters->filters[i];
1872 /* ...and only the mac set by the ndo */
1874 !ether_addr_equal(filter->mac, bulletin->mac)) {
1875 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1887 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1888 struct bnx2x_virtf *vf,
1889 struct vfpf_set_q_filters_tlv *filters)
1891 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1894 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1895 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1896 /* search for vlan filters */
1898 if (bnx2x_vf_filters_contain(filters,
1899 VFPF_Q_FILTER_VLAN_TAG_VALID)) {
1900 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1908 if (filters->vf_qid > vf_rxq_count(vf)) {
1917 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1918 struct bnx2x_virtf *vf,
1919 struct bnx2x_vf_mbx *mbx)
1921 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1924 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1928 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1932 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1936 /* print q_filter message */
1937 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1939 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1941 bnx2x_vf_mbx_resp(bp, vf, rc);
1944 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1945 struct bnx2x_vf_mbx *mbx)
1947 int qid = mbx->msg->req.q_op.vf_qid;
1950 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1953 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1954 bnx2x_vf_mbx_resp(bp, vf, rc);
1957 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1958 struct bnx2x_vf_mbx *mbx)
1962 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1964 rc = bnx2x_vf_close(bp, vf);
1965 bnx2x_vf_mbx_resp(bp, vf, rc);
1968 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1969 struct bnx2x_vf_mbx *mbx)
1973 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1975 rc = bnx2x_vf_free(bp, vf);
1976 bnx2x_vf_mbx_resp(bp, vf, rc);
1979 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1980 struct bnx2x_vf_mbx *mbx)
1982 struct bnx2x_config_rss_params rss;
1983 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1986 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1987 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1988 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1994 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1996 /* set vfop params according to rss tlv */
1997 memcpy(rss.ind_table, rss_tlv->ind_table,
1998 T_ETH_INDIRECTION_TABLE_SIZE);
1999 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
2000 rss.rss_obj = &vf->rss_conf_obj;
2001 rss.rss_result_mask = rss_tlv->rss_result_mask;
2003 /* flags handled individually for backward/forward compatibility */
2005 rss.ramrod_flags = 0;
2007 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
2008 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
2009 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
2010 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
2011 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
2012 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
2013 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
2014 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
2015 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
2016 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
2017 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
2018 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
2019 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
2020 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
2021 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
2022 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
2023 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
2024 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
2026 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
2027 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
2028 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
2029 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
2030 BNX2X_ERR("about to hit a FW assert. aborting...\n");
2035 rc = bnx2x_vf_rss_update(bp, vf, &rss);
2037 bnx2x_vf_mbx_resp(bp, vf, rc);
2040 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
2041 struct vfpf_tpa_tlv *tpa_tlv)
2045 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
2046 U_ETH_MAX_SGES_FOR_PACKET) {
2048 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
2049 tpa_tlv->tpa_client_info.max_sges_for_packet,
2050 U_ETH_MAX_SGES_FOR_PACKET);
2053 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
2055 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
2056 tpa_tlv->tpa_client_info.max_tpa_queues,
2063 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
2064 struct bnx2x_vf_mbx *mbx)
2066 struct bnx2x_queue_update_tpa_params vf_op_params;
2067 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
2070 memset(&vf_op_params, 0, sizeof(vf_op_params));
2072 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
2075 vf_op_params.complete_on_both_clients =
2076 tpa_tlv->tpa_client_info.complete_on_both_clients;
2077 vf_op_params.dont_verify_thr =
2078 tpa_tlv->tpa_client_info.dont_verify_thr;
2079 vf_op_params.max_agg_sz =
2080 tpa_tlv->tpa_client_info.max_agg_size;
2081 vf_op_params.max_sges_pkt =
2082 tpa_tlv->tpa_client_info.max_sges_for_packet;
2083 vf_op_params.max_tpa_queues =
2084 tpa_tlv->tpa_client_info.max_tpa_queues;
2085 vf_op_params.sge_buff_sz =
2086 tpa_tlv->tpa_client_info.sge_buff_size;
2087 vf_op_params.sge_pause_thr_high =
2088 tpa_tlv->tpa_client_info.sge_pause_thr_high;
2089 vf_op_params.sge_pause_thr_low =
2090 tpa_tlv->tpa_client_info.sge_pause_thr_low;
2091 vf_op_params.tpa_mode =
2092 tpa_tlv->tpa_client_info.tpa_mode;
2093 vf_op_params.update_ipv4 =
2094 tpa_tlv->tpa_client_info.update_ipv4;
2095 vf_op_params.update_ipv6 =
2096 tpa_tlv->tpa_client_info.update_ipv6;
2098 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
2101 bnx2x_vf_mbx_resp(bp, vf, rc);
2104 /* dispatch request */
2105 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
2106 struct bnx2x_vf_mbx *mbx)
2110 if (vf->state == VF_LOST) {
2111 /* Just ack the FW and return if VFs are lost
2112 * in case of parity error. VFs are supposed to be timedout
2113 * on waiting for PF response.
2116 "VF 0x%x lost, not handling the request\n", vf->abs_vfid);
2118 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2122 /* check if tlv type is known */
2123 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
2124 /* Lock the per vf op mutex and note the locker's identity.
2125 * The unlock will take place in mbx response.
2127 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2129 /* switch on the opcode */
2130 switch (mbx->first_tlv.tl.type) {
2131 case CHANNEL_TLV_ACQUIRE:
2132 bnx2x_vf_mbx_acquire(bp, vf, mbx);
2134 case CHANNEL_TLV_INIT:
2135 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
2137 case CHANNEL_TLV_SETUP_Q:
2138 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
2140 case CHANNEL_TLV_SET_Q_FILTERS:
2141 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2143 case CHANNEL_TLV_TEARDOWN_Q:
2144 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2146 case CHANNEL_TLV_CLOSE:
2147 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2149 case CHANNEL_TLV_RELEASE:
2150 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2152 case CHANNEL_TLV_UPDATE_RSS:
2153 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2155 case CHANNEL_TLV_UPDATE_TPA:
2156 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2161 /* unknown TLV - this may belong to a VF driver from the future
2162 * - a version written after this PF driver was written, which
2163 * supports features unknown as of yet. Too bad since we don't
2164 * support them. Or this may be because someone wrote a crappy
2165 * VF driver and is sending garbage over the channel.
2167 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2168 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2170 for (i = 0; i < 20; i++)
2171 DP_CONT(BNX2X_MSG_IOV, "%x ",
2172 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2175 /* can we respond to VF (do we have an address for it?) */
2176 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2177 /* notify the VF that we do not support this request */
2178 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2180 /* can't send a response since this VF is unknown to us
2181 * just ack the FW to release the mailbox and unlock
2184 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2185 /* Firmware ack should be written before unlocking channel */
2186 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2190 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2191 struct vf_pf_event_data *vfpf_event)
2196 "vf pf event received: vfid %d, address_hi %x, address lo %x",
2197 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2198 /* Sanity checks consider removing later */
2200 /* check if the vf_id is valid */
2201 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2202 BNX2X_NR_VIRTFN(bp)) {
2203 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2204 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2208 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2210 /* Update VFDB with current message and schedule its handling */
2211 mutex_lock(&BP_VFDB(bp)->event_mutex);
2212 BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
2213 le32_to_cpu(vfpf_event->msg_addr_hi);
2214 BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
2215 le32_to_cpu(vfpf_event->msg_addr_lo);
2216 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2217 mutex_unlock(&BP_VFDB(bp)->event_mutex);
2219 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2222 /* handle new vf-pf messages */
2223 void bnx2x_vf_mbx(struct bnx2x *bp)
2225 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2233 mutex_lock(&vfdb->event_mutex);
2234 events = vfdb->event_occur;
2235 vfdb->event_occur = 0;
2236 mutex_unlock(&vfdb->event_mutex);
2238 for_each_vf(bp, vf_idx) {
2239 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2240 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2242 /* Handle VFs which have pending events */
2243 if (!(events & (1ULL << vf_idx)))
2247 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2248 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2249 mbx->first_tlv.resp_msg_offset);
2251 /* dmae to get the VF request */
2252 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2253 vf->abs_vfid, mbx->vf_addr_hi,
2255 sizeof(union vfpf_tlvs)/4);
2257 BNX2X_ERR("Failed to copy request VF %d\n",
2259 bnx2x_vf_release(bp, vf);
2263 /* process the VF message header */
2264 mbx->first_tlv = mbx->msg->req.first_tlv;
2266 /* Clean response buffer to refrain from falsely
2269 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2271 /* dispatch the request (will prepare the response) */
2272 bnx2x_vf_mbx_request(bp, vf, mbx);
2276 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2279 /* Older VFs contain a bug where they can't check CRC for bulletin
2280 * boards of length greater than legacy size.
2282 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2283 BULLETIN_CONTENT_LEGACY_SIZE;
2284 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2287 /* propagate local bulletin board to vf */
2288 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2290 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2291 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2292 vf * BULLETIN_CONTENT_SIZE;
2293 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2296 /* can only update vf after init took place */
2297 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2298 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2301 /* increment bulletin board version and compute crc */
2302 bulletin->version++;
2303 bnx2x_vf_bulletin_finalize(bulletin,
2304 (bnx2x_vf(bp, vf, cfg_flags) &
2305 VF_CFG_EXT_BULLETIN) ? true : false);
2307 /* propagate bulletin board via dmae to vm memory */
2308 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2309 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2310 U64_LO(vf_addr), bulletin->length / 4);