1 /* bnx2x_vfpf.c: Broadcom Everest network driver.
3 * Copyright 2009-2013 Broadcom Corporation
5 * Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2, available
8 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
10 * Notwithstanding the above, under no circumstances may you combine this
11 * software in any way with any other Broadcom software provided under a
12 * license other than the GPL, without Broadcom's express prior written
15 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
16 * Written by: Shmulik Ravid
17 * Ariel Elior <ariel.elior@qlogic.com>
21 #include "bnx2x_cmn.h"
22 #include <linux/crc32.h>
24 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
26 /* place a given tlv on the tlv buffer at a given offset */
27 static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
28 u16 offset, u16 type, u16 length)
30 struct channel_tlv *tl =
31 (struct channel_tlv *)(tlvs_list + offset);
37 /* Clear the mailbox and init the header of the first tlv */
38 static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
41 mutex_lock(&bp->vf2pf_mutex);
43 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
47 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
49 /* init type and length */
50 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
52 /* init first tlv header */
53 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
56 /* releases the mailbox */
57 static void bnx2x_vfpf_finalize(struct bnx2x *bp,
58 struct vfpf_first_tlv *first_tlv)
60 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
63 mutex_unlock(&bp->vf2pf_mutex);
66 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
67 static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
68 enum channel_tlvs req_tlv)
70 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
73 if (tlv->type == req_tlv)
77 BNX2X_ERR("Found TLV with length 0\n");
81 tlvs_list += tlv->length;
82 tlv = (struct channel_tlv *)tlvs_list;
83 } while (tlv->type != CHANNEL_TLV_LIST_END);
85 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
90 /* list the types and lengths of the tlvs on the buffer */
91 static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
94 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
96 while (tlv->type != CHANNEL_TLV_LIST_END) {
98 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
99 tlv->type, tlv->length);
101 /* advance to next tlv */
102 tlvs_list += tlv->length;
104 /* cast general tlv list pointer to channel tlv header*/
105 tlv = (struct channel_tlv *)tlvs_list;
109 /* break condition for this loop */
110 if (i > MAX_TLVS_IN_LIST) {
111 WARN(true, "corrupt tlvs");
116 /* output last tlv */
117 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
118 tlv->type, tlv->length);
121 /* test whether we support a tlv type */
122 bool bnx2x_tlv_supported(u16 tlvtype)
124 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
127 static inline int bnx2x_pfvf_status_codes(int rc)
131 return PFVF_STATUS_SUCCESS;
133 return PFVF_STATUS_NO_RESOURCE;
135 return PFVF_STATUS_FAILURE;
139 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
141 struct cstorm_vf_zone_data __iomem *zone_data =
142 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
143 int tout = 100, interval = 100; /* wait for 10 seconds */
146 BNX2X_ERR("done was non zero before message to pf was sent\n");
151 /* if PF indicated channel is down avoid sending message. Return success
152 * so calling flow can continue
154 bnx2x_sample_bulletin(bp);
155 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
156 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
157 *done = PFVF_STATUS_SUCCESS;
161 /* Write message address */
162 writel(U64_LO(msg_mapping),
163 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
164 writel(U64_HI(msg_mapping),
165 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
167 /* make sure the address is written before FW accesses it */
170 /* Trigger the PF FW */
171 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
173 /* Wait for PF to complete */
174 while ((tout >= 0) && (!*done)) {
178 /* progress indicator - HV can take its own sweet time in
181 DP_CONT(BNX2X_MSG_IOV, ".");
185 BNX2X_ERR("PF response has timed out\n");
188 DP(BNX2X_MSG_SP, "Got a response from PF\n");
192 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
195 int tout = 10, interval = 100; /* Wait for 1 sec */
198 /* pxp traps vf read of doorbells and returns me reg value */
199 me_reg = readl(bp->doorbells);
200 if (GOOD_ME_REG(me_reg))
205 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
207 } while (tout-- > 0);
209 if (!GOOD_ME_REG(me_reg)) {
210 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
214 DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
216 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
221 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
223 int rc = 0, attempts = 0;
224 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
225 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
226 struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
228 bool resources_acquired = false;
230 /* clear mailbox and prep first tlv */
231 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
233 if (bnx2x_get_vf_id(bp, &vf_id)) {
238 req->vfdev_info.vf_id = vf_id;
239 req->vfdev_info.vf_os = 0;
241 req->resc_request.num_rxqs = rx_count;
242 req->resc_request.num_txqs = tx_count;
243 req->resc_request.num_sbs = bp->igu_sb_cnt;
244 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
245 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
247 /* pf 2 vf bulletin board address */
248 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
250 /* Request physical port identifier */
251 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
252 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
254 /* Bulletin support for bulletin board with length > legacy length */
255 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
257 /* add list termination tlv */
258 bnx2x_add_tlv(bp, req,
259 req->first_tlv.tl.length + sizeof(struct channel_tlv),
260 CHANNEL_TLV_LIST_END,
261 sizeof(struct channel_list_end_tlv));
263 /* output tlvs list */
264 bnx2x_dp_tlv_list(bp, req);
266 while (!resources_acquired) {
267 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
269 /* send acquire request */
270 rc = bnx2x_send_msg2pf(bp,
272 bp->vf2pf_mbox_mapping);
278 /* copy acquire response from buffer to bp */
279 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
283 /* test whether the PF accepted our request. If not, humble
284 * the request and try again.
286 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
287 DP(BNX2X_MSG_SP, "resources acquired\n");
288 resources_acquired = true;
289 } else if (bp->acquire_resp.hdr.status ==
290 PFVF_STATUS_NO_RESOURCE &&
291 attempts < VF_ACQUIRE_THRESH) {
293 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
295 /* humble our request */
296 req->resc_request.num_txqs =
297 min(req->resc_request.num_txqs,
298 bp->acquire_resp.resc.num_txqs);
299 req->resc_request.num_rxqs =
300 min(req->resc_request.num_rxqs,
301 bp->acquire_resp.resc.num_rxqs);
302 req->resc_request.num_sbs =
303 min(req->resc_request.num_sbs,
304 bp->acquire_resp.resc.num_sbs);
305 req->resc_request.num_mac_filters =
306 min(req->resc_request.num_mac_filters,
307 bp->acquire_resp.resc.num_mac_filters);
308 req->resc_request.num_vlan_filters =
309 min(req->resc_request.num_vlan_filters,
310 bp->acquire_resp.resc.num_vlan_filters);
311 req->resc_request.num_mc_filters =
312 min(req->resc_request.num_mc_filters,
313 bp->acquire_resp.resc.num_mc_filters);
315 /* Clear response buffer */
316 memset(&bp->vf2pf_mbox->resp, 0,
317 sizeof(union pfvf_tlvs));
319 /* PF reports error */
320 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
321 bp->acquire_resp.hdr.status);
327 /* Retrieve physical port id (if possible) */
328 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
329 bnx2x_search_tlv_list(bp, resp,
330 CHANNEL_TLV_PHYS_PORT_ID);
331 if (phys_port_resp) {
332 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
333 bp->flags |= HAS_PHYS_PORT_ID;
337 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
338 bp->link_params.chip_id = bp->common.chip_id;
339 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
340 bp->common.int_block = INT_BLOCK_IGU;
341 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
345 bp->common.flash_size = 0;
347 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
348 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
349 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
350 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
353 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
354 memcpy(bp->dev->dev_addr,
355 bp->acquire_resp.resc.current_mac_addr,
359 bnx2x_vfpf_finalize(bp, &req->first_tlv);
363 int bnx2x_vfpf_release(struct bnx2x *bp)
365 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
366 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
369 /* clear mailbox and prep first tlv */
370 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
372 if (bnx2x_get_vf_id(bp, &vf_id)) {
379 /* add list termination tlv */
380 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
381 sizeof(struct channel_list_end_tlv));
383 /* output tlvs list */
384 bnx2x_dp_tlv_list(bp, req);
386 /* send release request */
387 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
393 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
395 DP(BNX2X_MSG_SP, "vf released\n");
397 /* PF reports error */
398 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
404 bnx2x_vfpf_finalize(bp, &req->first_tlv);
409 /* Tell PF about SB addresses */
410 int bnx2x_vfpf_init(struct bnx2x *bp)
412 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
413 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
416 /* clear mailbox and prep first tlv */
417 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
420 for_each_eth_queue(bp, i)
421 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
424 /* statistics - requests only supports single queue for now */
425 req->stats_addr = bp->fw_stats_data_mapping +
426 offsetof(struct bnx2x_fw_stats_data, queue_stats);
428 req->stats_stride = sizeof(struct per_queue_stats);
430 /* add list termination tlv */
431 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
432 sizeof(struct channel_list_end_tlv));
434 /* output tlvs list */
435 bnx2x_dp_tlv_list(bp, req);
437 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
441 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
442 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
448 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
450 bnx2x_vfpf_finalize(bp, &req->first_tlv);
455 /* CLOSE VF - opposite to INIT_VF */
456 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
458 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
459 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
463 /* If we haven't got a valid VF id, there is no sense to
464 * continue with sending messages
466 if (bnx2x_get_vf_id(bp, &vf_id))
469 /* Close the queues */
470 for_each_queue(bp, i)
471 bnx2x_vfpf_teardown_queue(bp, i);
474 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
476 /* clear mailbox and prep first tlv */
477 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
481 /* add list termination tlv */
482 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
483 sizeof(struct channel_list_end_tlv));
485 /* output tlvs list */
486 bnx2x_dp_tlv_list(bp, req);
488 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
491 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
493 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
494 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
497 bnx2x_vfpf_finalize(bp, &req->first_tlv);
500 /* Disable HW interrupts, NAPI */
501 bnx2x_netif_stop(bp, 0);
502 /* Delete all NAPI objects */
503 bnx2x_del_all_napi(bp);
509 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
510 struct bnx2x_vf_queue *q)
512 u8 cl_id = vfq_cl_id(vf, q);
513 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
516 bnx2x_init_mac_obj(bp, &q->mac_obj,
517 cl_id, q->cid, func_id,
518 bnx2x_vf_sp(bp, vf, mac_rdata),
519 bnx2x_vf_sp_map(bp, vf, mac_rdata),
520 BNX2X_FILTER_MAC_PENDING,
522 BNX2X_OBJ_TYPE_RX_TX,
525 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
526 cl_id, q->cid, func_id,
527 bnx2x_vf_sp(bp, vf, vlan_rdata),
528 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
529 BNX2X_FILTER_VLAN_PENDING,
531 BNX2X_OBJ_TYPE_RX_TX,
535 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
536 q->cid, func_id, func_id,
537 bnx2x_vf_sp(bp, vf, mcast_rdata),
538 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
539 BNX2X_FILTER_MCAST_PENDING,
541 BNX2X_OBJ_TYPE_RX_TX);
544 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
546 bnx2x_vf_sp(bp, vf, rss_rdata),
547 bnx2x_vf_sp_map(bp, vf, rss_rdata),
548 BNX2X_FILTER_RSS_CONF_PENDING,
550 BNX2X_OBJ_TYPE_RX_TX);
552 vf->leading_rss = cl_id;
553 q->is_leading = true;
554 q->sp_initialized = true;
557 /* ask the pf to open a queue for the vf */
558 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
561 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
562 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
563 u8 fp_idx = fp->index;
564 u16 tpa_agg_size = 0, flags = 0;
567 /* clear mailbox and prep first tlv */
568 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
570 /* select tpa mode to request */
571 if (!fp->disable_tpa) {
572 flags |= VFPF_QUEUE_FLG_TPA;
573 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
574 if (fp->mode == TPA_MODE_GRO)
575 flags |= VFPF_QUEUE_FLG_TPA_GRO;
576 tpa_agg_size = TPA_AGG_SIZE;
580 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
582 /* calculate queue flags */
583 flags |= VFPF_QUEUE_FLG_STATS;
584 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
585 flags |= VFPF_QUEUE_FLG_VLAN;
586 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
589 req->vf_qid = fp_idx;
590 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
593 req->rxq.rcq_addr = fp->rx_comp_mapping;
594 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
595 req->rxq.rxq_addr = fp->rx_desc_mapping;
596 req->rxq.sge_addr = fp->rx_sge_mapping;
597 req->rxq.vf_sb = fp_idx;
598 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
599 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
600 req->rxq.mtu = bp->dev->mtu;
601 req->rxq.buf_sz = fp->rx_buf_size;
602 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
603 req->rxq.tpa_agg_sz = tpa_agg_size;
604 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
605 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
606 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
607 req->rxq.flags = flags;
608 req->rxq.drop_flags = 0;
609 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
610 req->rxq.stat_id = -1; /* No stats at the moment */
613 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
614 req->txq.vf_sb = fp_idx;
615 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
616 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
617 req->txq.flags = flags;
618 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
620 /* add list termination tlv */
621 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
622 sizeof(struct channel_list_end_tlv));
624 /* output tlvs list */
625 bnx2x_dp_tlv_list(bp, req);
627 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
629 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
632 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
633 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
634 fp_idx, resp->hdr.status);
638 bnx2x_vfpf_finalize(bp, &req->first_tlv);
643 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
645 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
646 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
649 /* clear mailbox and prep first tlv */
650 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
655 /* add list termination tlv */
656 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
657 sizeof(struct channel_list_end_tlv));
659 /* output tlvs list */
660 bnx2x_dp_tlv_list(bp, req);
662 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
665 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
670 /* PF failed the transaction */
671 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
672 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
678 bnx2x_vfpf_finalize(bp, &req->first_tlv);
683 /* request pf to add a mac for the vf */
684 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
686 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
687 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
688 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
691 /* clear mailbox and prep first tlv */
692 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
695 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
696 req->vf_qid = vf_qid;
697 req->n_mac_vlan_filters = 1;
699 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
701 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
703 /* sample bulletin board for new mac */
704 bnx2x_sample_bulletin(bp);
706 /* copy mac from device to request */
707 memcpy(req->filters[0].mac, addr, ETH_ALEN);
709 /* add list termination tlv */
710 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
711 sizeof(struct channel_list_end_tlv));
713 /* output tlvs list */
714 bnx2x_dp_tlv_list(bp, req);
716 /* send message to pf */
717 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
719 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
723 /* failure may mean PF was configured with a new mac for us */
724 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
726 "vfpf SET MAC failed. Check bulletin board for new posts\n");
728 /* copy mac from bulletin to device */
729 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
731 /* check if bulletin board was updated */
732 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
733 /* copy mac from device to request */
734 memcpy(req->filters[0].mac, bp->dev->dev_addr,
737 /* send message to pf */
738 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
739 bp->vf2pf_mbox_mapping);
741 /* no new info in bulletin */
746 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
747 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
751 bnx2x_vfpf_finalize(bp, &req->first_tlv);
756 /* request pf to config rss table for vf queues*/
757 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
758 struct bnx2x_config_rss_params *params)
760 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
761 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
764 /* clear mailbox and prep first tlv */
765 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
768 /* add list termination tlv */
769 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
770 sizeof(struct channel_list_end_tlv));
772 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
773 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
774 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
775 req->rss_key_size = T_ETH_RSS_KEY;
776 req->rss_result_mask = params->rss_result_mask;
778 /* flags handled individually for backward/forward compatability */
779 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
780 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
781 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
782 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
783 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
784 req->rss_flags |= VFPF_RSS_SET_SRCH;
785 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
786 req->rss_flags |= VFPF_RSS_IPV4;
787 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
788 req->rss_flags |= VFPF_RSS_IPV4_TCP;
789 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
790 req->rss_flags |= VFPF_RSS_IPV4_UDP;
791 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
792 req->rss_flags |= VFPF_RSS_IPV6;
793 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
794 req->rss_flags |= VFPF_RSS_IPV6_TCP;
795 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
796 req->rss_flags |= VFPF_RSS_IPV6_UDP;
798 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
800 /* output tlvs list */
801 bnx2x_dp_tlv_list(bp, req);
803 /* send message to pf */
804 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
806 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
810 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
811 /* Since older drivers don't support this feature (and VF has
812 * no way of knowing other than failing this), don't propagate
813 * an error in this case.
816 "Failed to send rss message to PF over VF-PF channel [%d]\n",
820 bnx2x_vfpf_finalize(bp, &req->first_tlv);
825 int bnx2x_vfpf_set_mcast(struct net_device *dev)
827 struct bnx2x *bp = netdev_priv(dev);
828 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
829 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
831 struct netdev_hw_addr *ha;
833 if (bp->state != BNX2X_STATE_OPEN) {
834 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
838 /* clear mailbox and prep first tlv */
839 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
842 /* Get Rx mode requested */
843 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
845 netdev_for_each_mc_addr(ha, dev) {
846 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
848 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
852 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
855 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
857 "VF supports not more than %d multicast MAC addresses\n",
858 PFVF_MAX_MULTICAST_PER_VF);
862 req->n_multicast = i;
863 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
866 /* add list termination tlv */
867 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
868 sizeof(struct channel_list_end_tlv));
870 /* output tlvs list */
871 bnx2x_dp_tlv_list(bp, req);
872 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
874 BNX2X_ERR("Sending a message failed: %d\n", rc);
878 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
879 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
884 bnx2x_vfpf_finalize(bp, &req->first_tlv);
889 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
891 int mode = bp->rx_mode;
892 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
893 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
896 /* clear mailbox and prep first tlv */
897 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
900 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
902 /* Ignore everything accept MODE_NONE */
903 if (mode == BNX2X_RX_MODE_NONE) {
904 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
906 /* Current PF driver will not look at the specific flags,
907 * but they are required when working with older drivers on hv.
909 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
910 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
911 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
914 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
917 /* add list termination tlv */
918 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
919 sizeof(struct channel_list_end_tlv));
921 /* output tlvs list */
922 bnx2x_dp_tlv_list(bp, req);
924 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
926 BNX2X_ERR("Sending a message failed: %d\n", rc);
928 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
929 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
933 bnx2x_vfpf_finalize(bp, &req->first_tlv);
938 /* General service functions */
939 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
941 u32 addr = BAR_CSTRORM_INTMEM +
942 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
944 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
947 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
949 u32 addr = BAR_CSTRORM_INTMEM +
950 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
952 REG_WR8(bp, addr, 1);
955 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
960 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
963 /* enable vf_pf mailbox (aka vf-pf-channel) */
964 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
966 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
968 /* enable the mailbox in the FW */
969 storm_memset_vf_mbx_ack(bp, abs_vfid);
970 storm_memset_vf_mbx_valid(bp, abs_vfid);
972 /* enable the VF access to the mailbox */
973 bnx2x_vf_enable_access(bp, abs_vfid);
976 /* this works only on !E1h */
977 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
978 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
979 u32 vf_addr_lo, u32 len32)
981 struct dmae_command dmae;
983 if (CHIP_IS_E1x(bp)) {
984 BNX2X_ERR("Chip revision does not support VFs\n");
988 if (!bp->dmae_ready) {
989 BNX2X_ERR("DMAE is not ready, can not copy\n");
993 /* set opcode and fixed command fields */
994 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
997 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
998 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
999 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1001 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1003 dmae.src_addr_lo = vf_addr_lo;
1004 dmae.src_addr_hi = vf_addr_hi;
1005 dmae.dst_addr_lo = U64_LO(pf_addr);
1006 dmae.dst_addr_hi = U64_HI(pf_addr);
1008 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1009 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1010 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1012 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1014 dmae.src_addr_lo = U64_LO(pf_addr);
1015 dmae.src_addr_hi = U64_HI(pf_addr);
1016 dmae.dst_addr_lo = vf_addr_lo;
1017 dmae.dst_addr_hi = vf_addr_hi;
1021 /* issue the command and wait for completion */
1022 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1025 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1026 struct bnx2x_virtf *vf)
1028 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1031 /* prepare response */
1032 type = mbx->first_tlv.tl.type;
1033 length = type == CHANNEL_TLV_ACQUIRE ?
1034 sizeof(struct pfvf_acquire_resp_tlv) :
1035 sizeof(struct pfvf_general_resp_tlv);
1036 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1037 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1038 sizeof(struct channel_list_end_tlv));
1041 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1042 struct bnx2x_virtf *vf,
1045 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1046 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1051 bnx2x_dp_tlv_list(bp, resp);
1052 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1053 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1055 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1058 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1059 mbx->first_tlv.resp_msg_offset;
1060 pf_addr = mbx->msg_mapping +
1061 offsetof(struct bnx2x_vf_mbx_msg, resp);
1063 /* Copy the response buffer. The first u64 is written afterwards, as
1064 * the vf is sensitive to the header being written
1066 vf_addr += sizeof(u64);
1067 pf_addr += sizeof(u64);
1068 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1071 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1073 BNX2X_ERR("Failed to copy response body to VF %d\n",
1077 vf_addr -= sizeof(u64);
1078 pf_addr -= sizeof(u64);
1081 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1084 /* copy the response header including status-done field,
1085 * must be last dmae, must be after FW is acked
1087 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1092 /* unlock channel mutex */
1093 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1096 BNX2X_ERR("Failed to copy response status to VF %d\n",
1103 bnx2x_vf_release(bp, vf);
1106 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1107 struct bnx2x_virtf *vf,
1110 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1111 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1114 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1115 struct bnx2x_virtf *vf,
1119 struct vfpf_port_phys_id_resp_tlv *port_id;
1121 if (!(bp->flags & HAS_PHYS_PORT_ID))
1124 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1125 sizeof(struct vfpf_port_phys_id_resp_tlv));
1127 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1128 (((u8 *)buffer) + *offset);
1129 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1131 /* Offset should continue representing the offset to the tail
1132 * of TLV data (outside this function scope)
1134 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1137 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1138 struct bnx2x_vf_mbx *mbx, int vfop_status)
1141 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1142 struct pf_vf_resc *resc = &resp->resc;
1143 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1146 memset(resp, 0, sizeof(*resp));
1148 /* fill in pfdev info */
1149 resp->pfdev_info.chip_num = bp->common.chip_id;
1150 resp->pfdev_info.db_size = bp->db_size;
1151 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1152 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1154 PFVF_CAP_TPA_UPDATE);
1155 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1156 sizeof(resp->pfdev_info.fw_ver));
1158 if (status == PFVF_STATUS_NO_RESOURCE ||
1159 status == PFVF_STATUS_SUCCESS) {
1160 /* set resources numbers, if status equals NO_RESOURCE these
1161 * are max possible numbers
1163 resc->num_rxqs = vf_rxq_count(vf) ? :
1164 bnx2x_vf_max_queue_cnt(bp, vf);
1165 resc->num_txqs = vf_txq_count(vf) ? :
1166 bnx2x_vf_max_queue_cnt(bp, vf);
1167 resc->num_sbs = vf_sb_count(vf);
1168 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1169 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
1170 resc->num_mc_filters = 0;
1172 if (status == PFVF_STATUS_SUCCESS) {
1173 /* fill in the allocated resources */
1174 struct pf_vf_bulletin_content *bulletin =
1175 BP_VF_BULLETIN(bp, vf->index);
1179 vfq_qzone_id(vf, vfq_get(vf, i));
1181 for_each_vf_sb(vf, i) {
1182 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1183 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1186 /* if a mac has been set for this vf, supply it */
1187 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1188 memcpy(resc->current_mac_addr, bulletin->mac,
1194 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"
1195 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1197 resp->pfdev_info.chip_num,
1198 resp->pfdev_info.db_size,
1199 resp->pfdev_info.indices_per_sb,
1200 resp->pfdev_info.pf_cap,
1204 resc->num_mac_filters,
1205 resc->num_vlan_filters,
1206 resc->num_mc_filters,
1207 resp->pfdev_info.fw_ver);
1209 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1210 for (i = 0; i < vf_rxq_count(vf); i++)
1211 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1212 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1213 for (i = 0; i < vf_sb_count(vf); i++)
1214 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1215 resc->hw_sbs[i].hw_sb_id,
1216 resc->hw_sbs[i].sb_qid);
1217 DP_CONT(BNX2X_MSG_IOV, "]\n");
1219 /* prepare response */
1220 length = sizeof(struct pfvf_acquire_resp_tlv);
1221 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1223 /* Handle possible VF requests for physical port identifiers.
1224 * 'length' should continue to indicate the offset of the first empty
1225 * place in the buffer (i.e., where next TLV should be inserted)
1227 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1228 CHANNEL_TLV_PHYS_PORT_ID))
1229 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1231 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1232 sizeof(struct channel_list_end_tlv));
1234 /* send the response */
1235 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1238 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1239 struct bnx2x_vf_mbx *mbx)
1242 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1244 /* log vfdef info */
1246 "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",
1247 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1248 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1249 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1250 acquire->resc_request.num_vlan_filters,
1251 acquire->resc_request.num_mc_filters);
1253 /* acquire the resources */
1254 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1256 /* store address of vf's bulletin board */
1257 vf->bulletin_map = acquire->bulletin_addr;
1258 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1259 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1261 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1263 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1267 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1270 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1271 struct bnx2x_vf_mbx *mbx)
1273 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1276 /* record ghost addresses from vf message */
1277 vf->spq_map = init->spq_addr;
1278 vf->fw_stat_map = init->stats_addr;
1279 vf->stats_stride = init->stats_stride;
1280 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1282 /* set VF multiqueue statistics collection mode */
1283 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1284 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1286 /* Update VF's view of link state */
1287 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1288 bnx2x_iov_link_update_vf(bp, vf->index);
1291 bnx2x_vf_mbx_resp(bp, vf, rc);
1294 /* convert MBX queue-flags to standard SP queue-flags */
1295 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1296 unsigned long *sp_q_flags)
1298 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1299 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1300 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1301 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1302 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1303 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1304 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1305 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1306 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1307 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1308 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1309 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1310 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1311 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1312 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1313 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1314 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1315 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1317 /* outer vlan removal is set according to PF's multi function mode */
1319 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1322 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1323 struct bnx2x_vf_mbx *mbx)
1325 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1326 struct bnx2x_vf_queue_construct_params qctor;
1330 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1331 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1332 setup_q->vf_qid, vf_rxq_count(vf));
1337 /* tx queues must be setup alongside rx queues thus if the rx queue
1338 * is not marked as valid there's nothing to do.
1340 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1341 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1342 unsigned long q_type = 0;
1344 struct bnx2x_queue_init_params *init_p;
1345 struct bnx2x_queue_setup_params *setup_p;
1347 if (bnx2x_vfq_is_leading(q))
1348 bnx2x_leading_vfq_init(bp, vf, q);
1350 /* re-init the VF operation context */
1352 sizeof(struct bnx2x_vf_queue_construct_params));
1353 setup_p = &qctor.prep_qsetup;
1354 init_p = &qctor.qstate.params.init;
1356 /* activate immediately */
1357 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1359 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1360 struct bnx2x_txq_setup_params *txq_params =
1361 &setup_p->txq_params;
1363 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1365 /* save sb resource index */
1366 q->sb_idx = setup_q->txq.vf_sb;
1369 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1370 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1372 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1375 /* tx setup - flags */
1376 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1379 /* tx setup - general, nothing */
1382 txq_params->dscr_map = setup_q->txq.txq_addr;
1383 txq_params->sb_cq_index = setup_q->txq.sb_index;
1384 txq_params->traffic_type = setup_q->txq.traffic_type;
1386 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1387 q->index, q->sb_idx);
1390 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1391 struct bnx2x_rxq_setup_params *rxq_params =
1392 &setup_p->rxq_params;
1394 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1396 /* Note: there is no support for different SBs
1399 q->sb_idx = setup_q->rxq.vf_sb;
1402 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1403 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1404 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1407 /* rx setup - flags */
1408 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1411 /* rx setup - general */
1412 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1415 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1416 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1417 rxq_params->sge_map = setup_q->rxq.sge_addr;
1418 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1419 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1420 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1421 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1422 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1423 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1424 rxq_params->cache_line_log =
1425 setup_q->rxq.cache_line_log;
1426 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1428 /* rx setup - multicast engine */
1429 if (bnx2x_vfq_is_leading(q)) {
1430 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1432 rxq_params->mcast_engine_id = mcast_id;
1433 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1436 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1437 q->index, q->sb_idx);
1439 /* complete the preparations */
1440 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1442 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1447 bnx2x_vf_mbx_resp(bp, vf, rc);
1450 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1451 struct bnx2x_virtf *vf,
1452 struct vfpf_set_q_filters_tlv *tlv,
1453 struct bnx2x_vf_mac_vlan_filters **pfl,
1457 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1460 fsz = tlv->n_mac_vlan_filters *
1461 sizeof(struct bnx2x_vf_mac_vlan_filter) +
1462 sizeof(struct bnx2x_vf_mac_vlan_filters);
1464 fl = kzalloc(fsz, GFP_KERNEL);
1468 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1469 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1471 if ((msg_filter->flags & type_flag) != type_flag)
1473 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1474 fl->filters[j].mac = msg_filter->mac;
1475 fl->filters[j].type = BNX2X_VF_FILTER_MAC;
1477 fl->filters[j].vid = msg_filter->vlan_tag;
1478 fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
1480 fl->filters[j].add =
1481 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1493 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1494 struct vfpf_q_mac_vlan_filter *filter)
1496 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1497 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1498 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1499 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1500 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1501 DP_CONT(msglvl, "\n");
1504 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1505 struct vfpf_set_q_filters_tlv *filters)
1509 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1510 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1511 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1512 &filters->filters[i]);
1514 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1515 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1517 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1518 for (i = 0; i < filters->n_multicast; i++)
1519 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1522 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1523 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1525 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1529 struct vfpf_set_q_filters_tlv *msg =
1530 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1532 /* check for any mac/vlan changes */
1533 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1534 /* build mac list */
1535 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1537 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1545 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1552 /* build vlan list */
1555 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1562 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1570 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1571 unsigned long accept = 0;
1572 struct pf_vf_bulletin_content *bulletin =
1573 BP_VF_BULLETIN(bp, vf->index);
1575 /* Ignore VF requested mode; instead set a regular mode */
1576 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1577 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1578 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1579 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1582 /* A packet arriving the vf's mac should be accepted
1583 * with any vlan, unless a vlan has already been
1586 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
1587 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1590 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1595 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1597 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1598 msg->n_multicast, false);
1604 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1605 vf->abs_vfid, msg->vf_qid, rc);
1609 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1610 struct bnx2x_virtf *vf,
1611 struct vfpf_set_q_filters_tlv *filters)
1613 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1616 /* if a mac was already set for this VF via the set vf mac ndo, we only
1617 * accept mac configurations of that mac. Why accept them at all?
1618 * because PF may have been unable to configure the mac at the time
1619 * since queue was not set up.
1621 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1622 /* once a mac was set by ndo can only accept a single mac... */
1623 if (filters->n_mac_vlan_filters > 1) {
1624 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1630 /* ...and only the mac set by the ndo */
1631 if (filters->n_mac_vlan_filters == 1 &&
1632 !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
1633 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1645 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1646 struct bnx2x_virtf *vf,
1647 struct vfpf_set_q_filters_tlv *filters)
1649 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1652 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1653 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1656 /* search for vlan filters */
1657 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1658 if (filters->filters[i].flags &
1659 VFPF_Q_FILTER_VLAN_TAG_VALID) {
1660 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1669 if (filters->vf_qid > vf_rxq_count(vf)) {
1678 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1679 struct bnx2x_virtf *vf,
1680 struct bnx2x_vf_mbx *mbx)
1682 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1685 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1689 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1693 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1697 /* print q_filter message */
1698 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1700 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1702 bnx2x_vf_mbx_resp(bp, vf, rc);
1705 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1706 struct bnx2x_vf_mbx *mbx)
1708 int qid = mbx->msg->req.q_op.vf_qid;
1711 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1714 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1715 bnx2x_vf_mbx_resp(bp, vf, rc);
1718 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1719 struct bnx2x_vf_mbx *mbx)
1723 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1725 rc = bnx2x_vf_close(bp, vf);
1726 bnx2x_vf_mbx_resp(bp, vf, rc);
1729 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1730 struct bnx2x_vf_mbx *mbx)
1734 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1736 rc = bnx2x_vf_free(bp, vf);
1737 bnx2x_vf_mbx_resp(bp, vf, rc);
1740 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1741 struct bnx2x_vf_mbx *mbx)
1743 struct bnx2x_config_rss_params rss;
1744 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1747 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1748 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1749 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1755 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1757 /* set vfop params according to rss tlv */
1758 memcpy(rss.ind_table, rss_tlv->ind_table,
1759 T_ETH_INDIRECTION_TABLE_SIZE);
1760 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
1761 rss.rss_obj = &vf->rss_conf_obj;
1762 rss.rss_result_mask = rss_tlv->rss_result_mask;
1764 /* flags handled individually for backward/forward compatability */
1766 rss.ramrod_flags = 0;
1768 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1769 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
1770 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1771 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
1772 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1773 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
1774 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1775 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
1776 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1777 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
1778 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1779 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
1780 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1781 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
1782 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1783 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
1784 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1785 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
1787 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1788 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1789 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1790 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1791 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1796 rc = bnx2x_vf_rss_update(bp, vf, &rss);
1798 bnx2x_vf_mbx_resp(bp, vf, rc);
1801 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
1802 struct vfpf_tpa_tlv *tpa_tlv)
1806 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
1807 U_ETH_MAX_SGES_FOR_PACKET) {
1809 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
1810 tpa_tlv->tpa_client_info.max_sges_for_packet,
1811 U_ETH_MAX_SGES_FOR_PACKET);
1814 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
1816 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
1817 tpa_tlv->tpa_client_info.max_tpa_queues,
1824 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
1825 struct bnx2x_vf_mbx *mbx)
1827 struct bnx2x_queue_update_tpa_params vf_op_params;
1828 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
1831 memset(&vf_op_params, 0, sizeof(vf_op_params));
1833 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
1836 vf_op_params.complete_on_both_clients =
1837 tpa_tlv->tpa_client_info.complete_on_both_clients;
1838 vf_op_params.dont_verify_thr =
1839 tpa_tlv->tpa_client_info.dont_verify_thr;
1840 vf_op_params.max_agg_sz =
1841 tpa_tlv->tpa_client_info.max_agg_size;
1842 vf_op_params.max_sges_pkt =
1843 tpa_tlv->tpa_client_info.max_sges_for_packet;
1844 vf_op_params.max_tpa_queues =
1845 tpa_tlv->tpa_client_info.max_tpa_queues;
1846 vf_op_params.sge_buff_sz =
1847 tpa_tlv->tpa_client_info.sge_buff_size;
1848 vf_op_params.sge_pause_thr_high =
1849 tpa_tlv->tpa_client_info.sge_pause_thr_high;
1850 vf_op_params.sge_pause_thr_low =
1851 tpa_tlv->tpa_client_info.sge_pause_thr_low;
1852 vf_op_params.tpa_mode =
1853 tpa_tlv->tpa_client_info.tpa_mode;
1854 vf_op_params.update_ipv4 =
1855 tpa_tlv->tpa_client_info.update_ipv4;
1856 vf_op_params.update_ipv6 =
1857 tpa_tlv->tpa_client_info.update_ipv6;
1859 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
1862 bnx2x_vf_mbx_resp(bp, vf, rc);
1865 /* dispatch request */
1866 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1867 struct bnx2x_vf_mbx *mbx)
1871 /* check if tlv type is known */
1872 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1873 /* Lock the per vf op mutex and note the locker's identity.
1874 * The unlock will take place in mbx response.
1876 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1878 /* switch on the opcode */
1879 switch (mbx->first_tlv.tl.type) {
1880 case CHANNEL_TLV_ACQUIRE:
1881 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1883 case CHANNEL_TLV_INIT:
1884 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1886 case CHANNEL_TLV_SETUP_Q:
1887 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1889 case CHANNEL_TLV_SET_Q_FILTERS:
1890 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1892 case CHANNEL_TLV_TEARDOWN_Q:
1893 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1895 case CHANNEL_TLV_CLOSE:
1896 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1898 case CHANNEL_TLV_RELEASE:
1899 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1901 case CHANNEL_TLV_UPDATE_RSS:
1902 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
1904 case CHANNEL_TLV_UPDATE_TPA:
1905 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
1910 /* unknown TLV - this may belong to a VF driver from the future
1911 * - a version written after this PF driver was written, which
1912 * supports features unknown as of yet. Too bad since we don't
1913 * support them. Or this may be because someone wrote a crappy
1914 * VF driver and is sending garbage over the channel.
1916 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
1917 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
1919 for (i = 0; i < 20; i++)
1920 DP_CONT(BNX2X_MSG_IOV, "%x ",
1921 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1924 /* can we respond to VF (do we have an address for it?) */
1925 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
1926 /* notify the VF that we do not support this request */
1927 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
1929 /* can't send a response since this VF is unknown to us
1930 * just ack the FW to release the mailbox and unlock
1933 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1934 /* Firmware ack should be written before unlocking channel */
1936 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1940 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
1941 struct vf_pf_event_data *vfpf_event)
1946 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1947 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1948 /* Sanity checks consider removing later */
1950 /* check if the vf_id is valid */
1951 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1952 BNX2X_NR_VIRTFN(bp)) {
1953 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1954 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1958 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1960 /* Update VFDB with current message and schedule its handling */
1961 mutex_lock(&BP_VFDB(bp)->event_mutex);
1962 BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
1963 BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
1964 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
1965 mutex_unlock(&BP_VFDB(bp)->event_mutex);
1967 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
1970 /* handle new vf-pf messages */
1971 void bnx2x_vf_mbx(struct bnx2x *bp)
1973 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
1981 mutex_lock(&vfdb->event_mutex);
1982 events = vfdb->event_occur;
1983 vfdb->event_occur = 0;
1984 mutex_unlock(&vfdb->event_mutex);
1986 for_each_vf(bp, vf_idx) {
1987 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
1988 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
1990 /* Handle VFs which have pending events */
1991 if (!(events & (1ULL << vf_idx)))
1995 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
1996 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
1997 mbx->first_tlv.resp_msg_offset);
1999 /* dmae to get the VF request */
2000 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2001 vf->abs_vfid, mbx->vf_addr_hi,
2003 sizeof(union vfpf_tlvs)/4);
2005 BNX2X_ERR("Failed to copy request VF %d\n",
2007 bnx2x_vf_release(bp, vf);
2011 /* process the VF message header */
2012 mbx->first_tlv = mbx->msg->req.first_tlv;
2014 /* Clean response buffer to refrain from falsely
2017 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2019 /* dispatch the request (will prepare the response) */
2020 bnx2x_vf_mbx_request(bp, vf, mbx);
2024 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2027 /* Older VFs contain a bug where they can't check CRC for bulletin
2028 * boards of length greater than legacy size.
2030 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2031 BULLETIN_CONTENT_LEGACY_SIZE;
2032 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2035 /* propagate local bulletin board to vf */
2036 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2038 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2039 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2040 vf * BULLETIN_CONTENT_SIZE;
2041 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2044 /* can only update vf after init took place */
2045 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2046 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2049 /* increment bulletin board version and compute crc */
2050 bulletin->version++;
2051 bnx2x_vf_bulletin_finalize(bulletin,
2052 (bnx2x_vf(bp, vf, cfg_flags) &
2053 VF_CFG_EXT_BULLETIN) ? true : false);
2055 /* propagate bulletin board via dmae to vm memory */
2056 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2057 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2058 U64_LO(vf_addr), bulletin->length / 4);