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>
20 #include <linux_compat.h>
23 #include "bnx2x_cmn.h"
25 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
27 /* place a given tlv on the tlv buffer at a given offset */
28 static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
29 uint16_t offset, uint16_t type, uint16_t length)
31 struct channel_tlv *tl =
32 (struct channel_tlv *)(tlvs_list + offset);
38 /* Clear the mailbox and init the header of the first tlv */
39 static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
40 uint16_t type, uint16_t length)
42 qlock(&bp->vf2pf_mutex);
44 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
48 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
50 /* init type and length */
51 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
53 /* init first tlv header */
54 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
57 /* releases the mailbox */
58 static void bnx2x_vfpf_finalize(struct bnx2x *bp,
59 struct vfpf_first_tlv *first_tlv)
61 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
64 qunlock(&bp->vf2pf_mutex);
67 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
68 static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
69 enum channel_tlvs req_tlv)
71 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
74 if (tlv->type == req_tlv)
78 BNX2X_ERR("Found TLV with length 0\n");
82 tlvs_list += tlv->length;
83 tlv = (struct channel_tlv *)tlvs_list;
84 } while (tlv->type != CHANNEL_TLV_LIST_END);
86 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
91 /* list the types and lengths of the tlvs on the buffer */
92 static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
95 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
97 while (tlv->type != CHANNEL_TLV_LIST_END) {
99 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
100 tlv->type, tlv->length);
102 /* advance to next tlv */
103 tlvs_list += tlv->length;
105 /* cast general tlv list pointer to channel tlv header*/
106 tlv = (struct channel_tlv *)tlvs_list;
110 /* break condition for this loop */
111 if (i > MAX_TLVS_IN_LIST) {
112 warn(true, "corrupt tlvs");
117 /* output last tlv */
118 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
119 tlv->type, tlv->length);
122 /* test whether we support a tlv type */
123 bool bnx2x_tlv_supported(uint16_t tlvtype)
125 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
128 static inline int bnx2x_pfvf_status_codes(int rc)
132 return PFVF_STATUS_SUCCESS;
134 return PFVF_STATUS_NO_RESOURCE;
136 return PFVF_STATUS_FAILURE;
140 static int bnx2x_send_msg2pf(struct bnx2x *bp, uint8_t *done,
141 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 write32(U64_LO(msg_mapping),
165 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
166 write32(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 write8(1, &zone_data->trigger.vf_pf_channel.addr_valid);
175 /* Wait for PF to complete */
176 while ((tout >= 0) && (!*done)) {
177 kthread_usleep(1000 * interval);
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, uint32_t *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 = read32(bp->doorbells);
202 if (GOOD_ME_REG(me_reg))
205 kthread_usleep(1000 * interval);
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, uint8_t tx_count, uint8_t rx_count)
225 int rc = 0, attempts = 0;
226 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
227 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
228 struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
229 struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
231 bool resources_acquired = false;
233 /* clear mailbox and prep first tlv */
234 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
236 if (bnx2x_get_vf_id(bp, &vf_id)) {
241 req->vfdev_info.vf_id = vf_id;
242 req->vfdev_info.vf_os = 0;
243 req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
245 req->resc_request.num_rxqs = rx_count;
246 req->resc_request.num_txqs = tx_count;
247 req->resc_request.num_sbs = bp->igu_sb_cnt;
248 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
249 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
251 /* pf 2 vf bulletin board address */
252 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
254 /* Request physical port identifier */
255 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
256 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
258 /* Bulletin support for bulletin board with length > legacy length */
259 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
261 /* add list termination tlv */
262 bnx2x_add_tlv(bp, req,
263 req->first_tlv.tl.length + sizeof(struct channel_tlv),
264 CHANNEL_TLV_LIST_END,
265 sizeof(struct channel_list_end_tlv));
267 /* output tlvs list */
268 bnx2x_dp_tlv_list(bp, req);
270 while (!resources_acquired) {
271 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
273 /* send acquire request */
274 rc = bnx2x_send_msg2pf(bp,
276 bp->vf2pf_mbox_mapping);
282 /* copy acquire response from buffer to bp */
283 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
287 /* test whether the PF accepted our request. If not, humble
288 * the request and try again.
290 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
291 DP(BNX2X_MSG_SP, "resources acquired\n");
292 resources_acquired = true;
293 } else if (bp->acquire_resp.hdr.status ==
294 PFVF_STATUS_NO_RESOURCE &&
295 attempts < VF_ACQUIRE_THRESH) {
297 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
299 /* humble our request */
300 req->resc_request.num_txqs =
301 MIN(req->resc_request.num_txqs,
302 bp->acquire_resp.resc.num_txqs);
303 req->resc_request.num_rxqs =
304 MIN(req->resc_request.num_rxqs,
305 bp->acquire_resp.resc.num_rxqs);
306 req->resc_request.num_sbs =
307 MIN(req->resc_request.num_sbs,
308 bp->acquire_resp.resc.num_sbs);
309 req->resc_request.num_mac_filters =
310 MIN(req->resc_request.num_mac_filters,
311 bp->acquire_resp.resc.num_mac_filters);
312 req->resc_request.num_vlan_filters =
313 MIN(req->resc_request.num_vlan_filters,
314 bp->acquire_resp.resc.num_vlan_filters);
315 req->resc_request.num_mc_filters =
316 MIN(req->resc_request.num_mc_filters,
317 bp->acquire_resp.resc.num_mc_filters);
319 /* Clear response buffer */
320 memset(&bp->vf2pf_mbox->resp, 0,
321 sizeof(union pfvf_tlvs));
323 /* Determine reason of PF failure of acquire process */
324 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
325 CHANNEL_TLV_FP_HSI_SUPPORT);
326 if (fp_hsi_resp && !fp_hsi_resp->is_supported)
327 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
329 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
330 bp->acquire_resp.hdr.status);
336 /* Retrieve physical port id (if possible) */
337 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
338 bnx2x_search_tlv_list(bp, resp,
339 CHANNEL_TLV_PHYS_PORT_ID);
340 if (phys_port_resp) {
341 memcpy(bp->phys_port_id, phys_port_resp->id, Eaddrlen);
342 bp->flags |= HAS_PHYS_PORT_ID;
345 /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
346 * If that's the case, we need to make certain required FW was
347 * supported by such a hypervisor [i.e., v0-v2].
349 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
350 CHANNEL_TLV_FP_HSI_SUPPORT);
351 if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
352 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
354 /* Since acquire succeeded on the PF side, we need to send a
355 * release message in order to allow future probes.
357 bnx2x_vfpf_finalize(bp, &req->first_tlv);
358 bnx2x_vfpf_release(bp);
365 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
366 bp->link_params.chip_id = bp->common.chip_id;
367 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
368 bp->common.int_block = INT_BLOCK_IGU;
369 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
373 bp->common.flash_size = 0;
375 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
376 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
377 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
378 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
381 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
382 memcpy(bp->dev->dev_addr,
383 bp->acquire_resp.resc.current_mac_addr,
387 bnx2x_vfpf_finalize(bp, &req->first_tlv);
391 int bnx2x_vfpf_release(struct bnx2x *bp)
393 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
394 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
397 /* clear mailbox and prep first tlv */
398 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
400 if (bnx2x_get_vf_id(bp, &vf_id)) {
407 /* add list termination tlv */
408 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
409 sizeof(struct channel_list_end_tlv));
411 /* output tlvs list */
412 bnx2x_dp_tlv_list(bp, req);
414 /* send release request */
415 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
421 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
423 DP(BNX2X_MSG_SP, "vf released\n");
425 /* PF reports error */
426 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
432 bnx2x_vfpf_finalize(bp, &req->first_tlv);
437 /* Tell PF about SB addresses */
438 int bnx2x_vfpf_init(struct bnx2x *bp)
440 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
441 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
444 /* clear mailbox and prep first tlv */
445 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
448 for_each_eth_queue(bp, i)
449 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
452 /* statistics - requests only supports single queue for now */
453 req->stats_addr = bp->fw_stats_data_mapping +
454 offsetof(struct bnx2x_fw_stats_data, queue_stats);
456 req->stats_stride = sizeof(struct per_queue_stats);
458 /* add list termination tlv */
459 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
460 sizeof(struct channel_list_end_tlv));
462 /* output tlvs list */
463 bnx2x_dp_tlv_list(bp, req);
465 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
469 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
470 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
476 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
478 bnx2x_vfpf_finalize(bp, &req->first_tlv);
483 /* CLOSE VF - opposite to INIT_VF */
484 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
486 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
487 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
491 /* If we haven't got a valid VF id, there is no sense to
492 * continue with sending messages
494 if (bnx2x_get_vf_id(bp, &vf_id))
497 /* Close the queues */
498 for_each_queue(bp, i)
499 bnx2x_vfpf_teardown_queue(bp, i);
502 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
504 /* clear mailbox and prep first tlv */
505 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
509 /* add list termination tlv */
510 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
511 sizeof(struct channel_list_end_tlv));
513 /* output tlvs list */
514 bnx2x_dp_tlv_list(bp, req);
516 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
519 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
521 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
522 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
525 bnx2x_vfpf_finalize(bp, &req->first_tlv);
528 /* Disable HW interrupts, NAPI */
529 bnx2x_netif_stop(bp, 0);
530 /* Delete all NAPI objects */
531 bnx2x_del_all_napi(bp);
537 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
538 struct bnx2x_vf_queue *q)
540 uint8_t cl_id = vfq_cl_id(vf, q);
541 uint8_t func_id = FW_VF_HANDLE(vf->abs_vfid);
544 bnx2x_init_mac_obj(bp, &q->mac_obj,
545 cl_id, q->cid, func_id,
546 bnx2x_vf_sp(bp, vf, mac_rdata),
547 bnx2x_vf_sp_map(bp, vf, mac_rdata),
548 BNX2X_FILTER_MAC_PENDING,
550 BNX2X_OBJ_TYPE_RX_TX,
553 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
554 cl_id, q->cid, func_id,
555 bnx2x_vf_sp(bp, vf, vlan_rdata),
556 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
557 BNX2X_FILTER_VLAN_PENDING,
559 BNX2X_OBJ_TYPE_RX_TX,
563 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
564 q->cid, func_id, func_id,
565 bnx2x_vf_sp(bp, vf, mcast_rdata),
566 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
567 BNX2X_FILTER_MCAST_PENDING,
569 BNX2X_OBJ_TYPE_RX_TX);
572 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
574 bnx2x_vf_sp(bp, vf, rss_rdata),
575 bnx2x_vf_sp_map(bp, vf, rss_rdata),
576 BNX2X_FILTER_RSS_CONF_PENDING,
578 BNX2X_OBJ_TYPE_RX_TX);
580 vf->leading_rss = cl_id;
581 q->is_leading = true;
582 q->sp_initialized = true;
585 /* ask the pf to open a queue for the vf */
586 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
589 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
590 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
591 uint8_t fp_idx = fp->index;
592 uint16_t tpa_agg_size = 0, flags = 0;
595 /* clear mailbox and prep first tlv */
596 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
598 /* select tpa mode to request */
599 if (!fp->disable_tpa) {
600 flags |= VFPF_QUEUE_FLG_TPA;
601 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
602 if (fp->mode == TPA_MODE_GRO)
603 flags |= VFPF_QUEUE_FLG_TPA_GRO;
604 tpa_agg_size = TPA_AGG_SIZE;
608 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
610 /* calculate queue flags */
611 flags |= VFPF_QUEUE_FLG_STATS;
612 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
613 flags |= VFPF_QUEUE_FLG_VLAN;
616 req->vf_qid = fp_idx;
617 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
620 req->rxq.rcq_addr = fp->rx_comp_mapping;
621 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
622 req->rxq.rxq_addr = fp->rx_desc_mapping;
623 req->rxq.sge_addr = fp->rx_sge_mapping;
624 req->rxq.vf_sb = fp_idx;
625 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
626 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
627 req->rxq.mtu = bp->dev->mtu;
628 req->rxq.buf_sz = fp->rx_buf_size;
629 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
630 req->rxq.tpa_agg_sz = tpa_agg_size;
631 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
632 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
633 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
634 req->rxq.flags = flags;
635 req->rxq.drop_flags = 0;
636 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
637 req->rxq.stat_id = -1; /* No stats at the moment */
640 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
641 req->txq.vf_sb = fp_idx;
642 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
643 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
644 req->txq.flags = flags;
645 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
647 /* add list termination tlv */
648 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
649 sizeof(struct channel_list_end_tlv));
651 /* output tlvs list */
652 bnx2x_dp_tlv_list(bp, req);
654 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
656 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
659 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
660 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
661 fp_idx, resp->hdr.status);
665 bnx2x_vfpf_finalize(bp, &req->first_tlv);
670 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
672 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
673 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
676 /* clear mailbox and prep first tlv */
677 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
682 /* add list termination tlv */
683 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
684 sizeof(struct channel_list_end_tlv));
686 /* output tlvs list */
687 bnx2x_dp_tlv_list(bp, req);
689 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
692 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
697 /* PF failed the transaction */
698 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
699 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
705 bnx2x_vfpf_finalize(bp, &req->first_tlv);
710 /* request pf to add a mac for the vf */
711 int bnx2x_vfpf_config_mac(struct bnx2x *bp, uint8_t *addr, uint8_t vf_qid,
714 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
715 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
716 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
719 /* clear mailbox and prep first tlv */
720 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
723 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
724 req->vf_qid = vf_qid;
725 req->n_mac_vlan_filters = 1;
727 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
729 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
731 /* sample bulletin board for new mac */
732 bnx2x_sample_bulletin(bp);
734 /* copy mac from device to request */
735 memcpy(req->filters[0].mac, addr, Eaddrlen);
737 /* add list termination tlv */
738 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
739 sizeof(struct channel_list_end_tlv));
741 /* output tlvs list */
742 bnx2x_dp_tlv_list(bp, req);
744 /* send message to pf */
745 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
747 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
751 /* failure may mean PF was configured with a new mac for us */
752 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
754 "vfpf SET MAC failed. Check bulletin board for new posts\n");
756 /* copy mac from bulletin to device */
757 memcpy(bp->dev->dev_addr, bulletin.mac, Eaddrlen);
759 /* check if bulletin board was updated */
760 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
761 /* copy mac from device to request */
762 memcpy(req->filters[0].mac, bp->dev->dev_addr,
765 /* send message to pf */
766 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
767 bp->vf2pf_mbox_mapping);
769 /* no new info in bulletin */
774 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
775 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
779 bnx2x_vfpf_finalize(bp, &req->first_tlv);
784 /* request pf to config rss table for vf queues*/
785 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
786 struct bnx2x_config_rss_params *params)
788 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
789 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
792 /* clear mailbox and prep first tlv */
793 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
796 /* add list termination tlv */
797 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
798 sizeof(struct channel_list_end_tlv));
800 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
801 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
802 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
803 req->rss_key_size = T_ETH_RSS_KEY;
804 req->rss_result_mask = params->rss_result_mask;
806 /* flags handled individually for backward/forward compatability */
807 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
808 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
809 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
810 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
811 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
812 req->rss_flags |= VFPF_RSS_SET_SRCH;
813 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
814 req->rss_flags |= VFPF_RSS_IPV4;
815 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
816 req->rss_flags |= VFPF_RSS_IPV4_TCP;
817 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
818 req->rss_flags |= VFPF_RSS_IPV4_UDP;
819 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
820 req->rss_flags |= VFPF_RSS_IPV6;
821 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
822 req->rss_flags |= VFPF_RSS_IPV6_TCP;
823 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
824 req->rss_flags |= VFPF_RSS_IPV6_UDP;
826 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
828 /* output tlvs list */
829 bnx2x_dp_tlv_list(bp, req);
831 /* send message to pf */
832 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
834 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
838 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
839 /* Since older drivers don't support this feature (and VF has
840 * no way of knowing other than failing this), don't propagate
841 * an error in this case.
844 "Failed to send rss message to PF over VF-PF channel [%d]\n",
848 bnx2x_vfpf_finalize(bp, &req->first_tlv);
853 int bnx2x_vfpf_set_mcast(struct ether *dev)
855 struct bnx2x *bp = netdev_priv(dev);
856 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
857 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
859 struct netdev_hw_addr *ha;
861 if (bp->state != BNX2X_STATE_OPEN) {
862 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
866 /* clear mailbox and prep first tlv */
867 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
870 /* Get Rx mode requested */
871 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
873 netdev_for_each_mc_addr(ha, dev) {
874 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
876 memcpy(req->multicast[i], bnx2x_mc_addr(ha), Eaddrlen);
880 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
883 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
885 "VF supports not more than %d multicast MAC addresses\n",
886 PFVF_MAX_MULTICAST_PER_VF);
890 req->n_multicast = i;
891 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
894 /* add list termination tlv */
895 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
896 sizeof(struct channel_list_end_tlv));
898 /* output tlvs list */
899 bnx2x_dp_tlv_list(bp, req);
900 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
902 BNX2X_ERR("Sending a message failed: %d\n", rc);
906 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
907 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
912 bnx2x_vfpf_finalize(bp, &req->first_tlv);
917 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
919 int mode = bp->rx_mode;
920 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
921 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
924 /* clear mailbox and prep first tlv */
925 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
928 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
930 /* Ignore everything accept MODE_NONE */
931 if (mode == BNX2X_RX_MODE_NONE) {
932 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
934 /* Current PF driver will not look at the specific flags,
935 * but they are required when working with older drivers on hv.
937 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
938 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
939 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
942 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
945 /* add list termination tlv */
946 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
947 sizeof(struct channel_list_end_tlv));
949 /* output tlvs list */
950 bnx2x_dp_tlv_list(bp, req);
952 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
954 BNX2X_ERR("Sending a message failed: %d\n", rc);
956 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
957 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
961 bnx2x_vfpf_finalize(bp, &req->first_tlv);
966 /* General service functions */
967 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, uint16_t abs_fid)
969 uint32_t addr = BAR_CSTRORM_INTMEM +
970 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
972 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
975 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, uint16_t abs_fid)
977 uint32_t addr = BAR_CSTRORM_INTMEM +
978 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
980 REG_WR8(bp, addr, 1);
983 /* enable vf_pf mailbox (aka vf-pf-channel) */
984 void bnx2x_vf_enable_mbx(struct bnx2x *bp, uint8_t abs_vfid)
986 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
988 /* enable the mailbox in the FW */
989 storm_memset_vf_mbx_ack(bp, abs_vfid);
990 storm_memset_vf_mbx_valid(bp, abs_vfid);
992 /* enable the VF access to the mailbox */
993 bnx2x_vf_enable_access(bp, abs_vfid);
996 /* this works only on !E1h */
997 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, uint8_t from_vf,
998 dma_addr_t pf_addr, uint8_t vfid,
1000 uint32_t vf_addr_lo, uint32_t len32)
1002 struct dmae_command dmae;
1004 if (CHIP_IS_E1x(bp)) {
1005 BNX2X_ERR("Chip revision does not support VFs\n");
1006 return DMAE_NOT_RDY;
1009 if (!bp->dmae_ready) {
1010 BNX2X_ERR("DMAE is not ready, can not copy\n");
1011 return DMAE_NOT_RDY;
1014 /* set opcode and fixed command fields */
1015 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1018 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1019 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1020 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1022 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1024 dmae.src_addr_lo = vf_addr_lo;
1025 dmae.src_addr_hi = vf_addr_hi;
1026 dmae.dst_addr_lo = U64_LO(pf_addr);
1027 dmae.dst_addr_hi = U64_HI(pf_addr);
1029 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1030 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1031 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1033 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1035 dmae.src_addr_lo = U64_LO(pf_addr);
1036 dmae.src_addr_hi = U64_HI(pf_addr);
1037 dmae.dst_addr_lo = vf_addr_lo;
1038 dmae.dst_addr_hi = vf_addr_hi;
1042 /* issue the command and wait for completion */
1043 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1046 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1047 struct bnx2x_virtf *vf)
1049 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1050 uint16_t length, type;
1052 /* prepare response */
1053 type = mbx->first_tlv.tl.type;
1054 length = type == CHANNEL_TLV_ACQUIRE ?
1055 sizeof(struct pfvf_acquire_resp_tlv) :
1056 sizeof(struct pfvf_general_resp_tlv);
1057 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1058 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1059 sizeof(struct channel_list_end_tlv));
1062 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1063 struct bnx2x_virtf *vf,
1066 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1067 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1072 bnx2x_dp_tlv_list(bp, resp);
1073 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1074 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1076 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1079 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1080 mbx->first_tlv.resp_msg_offset;
1081 pf_addr = mbx->msg_mapping +
1082 offsetof(struct bnx2x_vf_mbx_msg, resp);
1084 /* Copy the response buffer. The first u64 is written afterwards, as
1085 * the vf is sensitive to the header being written
1087 vf_addr += sizeof(uint64_t);
1088 pf_addr += sizeof(uint64_t);
1089 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1092 (sizeof(union pfvf_tlvs) - sizeof(uint64_t))/4);
1094 BNX2X_ERR("Failed to copy response body to VF %d\n",
1098 vf_addr -= sizeof(uint64_t);
1099 pf_addr -= sizeof(uint64_t);
1102 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1105 /* copy the response header including status-done field,
1106 * must be last dmae, must be after FW is acked
1108 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1111 sizeof(uint64_t)/4);
1113 /* unlock channel mutex */
1114 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1117 BNX2X_ERR("Failed to copy response status to VF %d\n",
1124 bnx2x_vf_release(bp, vf);
1127 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1128 struct bnx2x_virtf *vf,
1131 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1132 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1135 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1136 struct bnx2x_virtf *vf,
1140 struct vfpf_port_phys_id_resp_tlv *port_id;
1142 if (!(bp->flags & HAS_PHYS_PORT_ID))
1145 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1146 sizeof(struct vfpf_port_phys_id_resp_tlv));
1148 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1149 (((uint8_t *)buffer) + *offset);
1150 memcpy(port_id->id, bp->phys_port_id, Eaddrlen);
1152 /* Offset should continue representing the offset to the tail
1153 * of TLV data (outside this function scope)
1155 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1158 static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1159 struct bnx2x_virtf *vf,
1163 struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1165 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1166 sizeof(struct vfpf_fp_hsi_resp_tlv));
1168 fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1169 (((uint8_t *)buffer) + *offset);
1170 fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1172 /* Offset should continue representing the offset to the tail
1173 * of TLV data (outside this function scope)
1175 *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1178 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1179 struct bnx2x_vf_mbx *mbx, int vfop_status)
1182 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1183 struct pf_vf_resc *resc = &resp->resc;
1184 uint8_t status = bnx2x_pfvf_status_codes(vfop_status);
1187 memset(resp, 0, sizeof(*resp));
1189 /* fill in pfdev info */
1190 resp->pfdev_info.chip_num = bp->common.chip_id;
1191 resp->pfdev_info.db_size = bp->db_size;
1192 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1193 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1195 PFVF_CAP_TPA_UPDATE);
1196 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1197 sizeof(resp->pfdev_info.fw_ver));
1199 if (status == PFVF_STATUS_NO_RESOURCE ||
1200 status == PFVF_STATUS_SUCCESS) {
1201 /* set resources numbers, if status equals NO_RESOURCE these
1202 * are max possible numbers
1204 resc->num_rxqs = vf_rxq_count(vf) ? :
1205 bnx2x_vf_max_queue_cnt(bp, vf);
1206 resc->num_txqs = vf_txq_count(vf) ? :
1207 bnx2x_vf_max_queue_cnt(bp, vf);
1208 resc->num_sbs = vf_sb_count(vf);
1209 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1210 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
1211 resc->num_mc_filters = 0;
1213 if (status == PFVF_STATUS_SUCCESS) {
1214 /* fill in the allocated resources */
1215 struct pf_vf_bulletin_content *bulletin =
1216 BP_VF_BULLETIN(bp, vf->index);
1220 vfq_qzone_id(vf, vfq_get(vf, i));
1222 for_each_vf_sb(vf, i) {
1223 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1224 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1227 /* if a mac has been set for this vf, supply it */
1228 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1229 memcpy(resc->current_mac_addr, bulletin->mac,
1235 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"
1236 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1238 resp->pfdev_info.chip_num,
1239 resp->pfdev_info.db_size,
1240 resp->pfdev_info.indices_per_sb,
1241 resp->pfdev_info.pf_cap,
1245 resc->num_mac_filters,
1246 resc->num_vlan_filters,
1247 resc->num_mc_filters,
1248 resp->pfdev_info.fw_ver);
1250 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1251 for (i = 0; i < vf_rxq_count(vf); i++)
1252 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1253 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1254 for (i = 0; i < vf_sb_count(vf); i++)
1255 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1256 resc->hw_sbs[i].hw_sb_id,
1257 resc->hw_sbs[i].sb_qid);
1258 DP_CONT(BNX2X_MSG_IOV, "]\n");
1260 /* prepare response */
1261 length = sizeof(struct pfvf_acquire_resp_tlv);
1262 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1264 /* Handle possible VF requests for physical port identifiers.
1265 * 'length' should continue to indicate the offset of the first empty
1266 * place in the buffer (i.e., where next TLV should be inserted)
1268 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1269 CHANNEL_TLV_PHYS_PORT_ID))
1270 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1272 /* `New' vfs will want to know if fastpath HSI is supported, since
1273 * if that's not the case they could print into system log the fact
1274 * the driver version must be updated.
1276 bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1278 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1279 sizeof(struct channel_list_end_tlv));
1281 /* send the response */
1282 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1285 static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1286 struct vfpf_acquire_tlv *acquire)
1288 /* Windows driver does one of three things:
1289 * 1. Old driver doesn't have bulletin board address set.
1290 * 2. 'Middle' driver sends mc_num == 32.
1291 * 3. New driver sets the OS field.
1293 if (!acquire->bulletin_addr ||
1294 acquire->resc_request.num_mc_filters == 32 ||
1295 ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1302 static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1303 struct bnx2x_virtf *vf,
1304 struct bnx2x_vf_mbx *mbx)
1306 /* Linux drivers which correctly set the doorbell size also
1307 * send a physical port request
1309 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1310 CHANNEL_TLV_PHYS_PORT_ID))
1313 /* Issue does not exist in windows VMs */
1314 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1320 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1321 struct bnx2x_vf_mbx *mbx)
1324 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1326 /* log vfdef info */
1328 "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",
1329 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1330 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1331 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1332 acquire->resc_request.num_vlan_filters,
1333 acquire->resc_request.num_mc_filters);
1335 /* Prevent VFs with old drivers from loading, since they calculate
1336 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
1337 * while being upgraded.
1339 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1342 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1347 /* Verify the VF fastpath HSI can be supported by the loaded FW.
1348 * Linux vfs should be oblivious to changes between v0 and v2.
1350 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1351 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1353 vf->fp_hsi = MAX_T(uint8_t, acquire->vfdev_info.fp_hsi_ver,
1355 if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1357 "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1358 vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1359 ETH_FP_HSI_VERSION);
1364 /* acquire the resources */
1365 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1367 /* store address of vf's bulletin board */
1368 vf->bulletin_map = acquire->bulletin_addr;
1369 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1370 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1372 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1374 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1379 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1382 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1383 struct bnx2x_vf_mbx *mbx)
1385 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1388 /* record ghost addresses from vf message */
1389 vf->spq_map = init->spq_addr;
1390 vf->fw_stat_map = init->stats_addr;
1391 vf->stats_stride = init->stats_stride;
1392 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1394 /* set VF multiqueue statistics collection mode */
1395 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1396 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1398 /* Update VF's view of link state */
1399 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1400 bnx2x_iov_link_update_vf(bp, vf->index);
1403 bnx2x_vf_mbx_resp(bp, vf, rc);
1406 /* convert MBX queue-flags to standard SP queue-flags */
1407 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, uint32_t mbx_q_flags,
1408 unsigned long *sp_q_flags)
1410 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1411 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1412 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1413 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1414 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1415 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1416 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1417 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1418 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1419 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1420 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1421 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1422 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1423 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1424 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1425 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1426 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1427 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1429 /* outer vlan removal is set according to PF's multi function mode */
1431 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1434 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1435 struct bnx2x_vf_mbx *mbx)
1437 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1438 struct bnx2x_vf_queue_construct_params qctor;
1442 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1443 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1444 setup_q->vf_qid, vf_rxq_count(vf));
1449 /* tx queues must be setup alongside rx queues thus if the rx queue
1450 * is not marked as valid there's nothing to do.
1452 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1453 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1454 unsigned long q_type = 0;
1456 struct bnx2x_queue_init_params *init_p;
1457 struct bnx2x_queue_setup_params *setup_p;
1459 if (bnx2x_vfq_is_leading(q))
1460 bnx2x_leading_vfq_init(bp, vf, q);
1462 /* re-init the VF operation context */
1464 sizeof(struct bnx2x_vf_queue_construct_params));
1465 setup_p = &qctor.prep_qsetup;
1466 init_p = &qctor.qstate.params.init;
1468 /* activate immediately */
1469 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1471 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1472 struct bnx2x_txq_setup_params *txq_params =
1473 &setup_p->txq_params;
1475 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1477 /* save sb resource index */
1478 q->sb_idx = setup_q->txq.vf_sb;
1481 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1482 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1484 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1487 /* tx setup - flags */
1488 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1491 /* tx setup - general, nothing */
1494 txq_params->dscr_map = setup_q->txq.txq_addr;
1495 txq_params->sb_cq_index = setup_q->txq.sb_index;
1496 txq_params->traffic_type = setup_q->txq.traffic_type;
1498 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1499 q->index, q->sb_idx);
1502 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1503 struct bnx2x_rxq_setup_params *rxq_params =
1504 &setup_p->rxq_params;
1506 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1508 /* Note: there is no support for different SBs
1511 q->sb_idx = setup_q->rxq.vf_sb;
1514 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1515 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1516 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1519 /* rx setup - flags */
1520 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1523 /* rx setup - general */
1524 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1527 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1528 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1529 rxq_params->sge_map = setup_q->rxq.sge_addr;
1530 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1531 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1532 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1533 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1534 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1535 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1536 rxq_params->cache_line_log =
1537 setup_q->rxq.cache_line_log;
1538 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1540 /* rx setup - multicast engine */
1541 if (bnx2x_vfq_is_leading(q)) {
1542 uint8_t mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1544 rxq_params->mcast_engine_id = mcast_id;
1545 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1548 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1549 q->index, q->sb_idx);
1551 /* complete the preparations */
1552 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1554 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1559 bnx2x_vf_mbx_resp(bp, vf, rc);
1562 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1563 struct bnx2x_virtf *vf,
1564 struct vfpf_set_q_filters_tlv *tlv,
1565 struct bnx2x_vf_mac_vlan_filters **pfl,
1569 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1572 fsz = tlv->n_mac_vlan_filters *
1573 sizeof(struct bnx2x_vf_mac_vlan_filter) +
1574 sizeof(struct bnx2x_vf_mac_vlan_filters);
1576 fl = kzmalloc(fsz, MEM_WAIT);
1580 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1581 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1583 if ((msg_filter->flags & type_flag) != type_flag)
1585 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1586 fl->filters[j].mac = msg_filter->mac;
1587 fl->filters[j].type = BNX2X_VF_FILTER_MAC;
1589 fl->filters[j].vid = msg_filter->vlan_tag;
1590 fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
1592 fl->filters[j].add =
1593 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1605 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1606 struct vfpf_q_mac_vlan_filter *filter)
1608 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1609 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1610 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1611 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1612 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1613 DP_CONT(msglvl, "\n");
1616 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1617 struct vfpf_set_q_filters_tlv *filters)
1621 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1622 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1623 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1624 &filters->filters[i]);
1626 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1627 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1629 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1630 for (i = 0; i < filters->n_multicast; i++)
1631 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1634 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1635 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1637 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1641 struct vfpf_set_q_filters_tlv *msg =
1642 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1644 /* check for any mac/vlan changes */
1645 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1646 /* build mac list */
1647 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1649 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1657 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1664 /* build vlan list */
1667 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1674 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1682 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1683 unsigned long accept = 0;
1684 struct pf_vf_bulletin_content *bulletin =
1685 BP_VF_BULLETIN(bp, vf->index);
1687 /* Ignore VF requested mode; instead set a regular mode */
1688 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1689 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1690 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1691 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1694 /* A packet arriving the vf's mac should be accepted
1695 * with any vlan, unless a vlan has already been
1698 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
1699 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1702 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1707 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1709 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1710 msg->n_multicast, false);
1716 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1717 vf->abs_vfid, msg->vf_qid, rc);
1721 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1722 struct bnx2x_virtf *vf,
1723 struct vfpf_set_q_filters_tlv *filters)
1725 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1728 /* if a mac was already set for this VF via the set vf mac ndo, we only
1729 * accept mac configurations of that mac. Why accept them at all?
1730 * because PF may have been unable to configure the mac at the time
1731 * since queue was not set up.
1733 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1734 /* once a mac was set by ndo can only accept a single mac... */
1735 if (filters->n_mac_vlan_filters > 1) {
1736 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1742 /* ...and only the mac set by the ndo */
1743 if (filters->n_mac_vlan_filters == 1 &&
1744 !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
1745 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1757 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1758 struct bnx2x_virtf *vf,
1759 struct vfpf_set_q_filters_tlv *filters)
1761 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1764 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1765 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1768 /* search for vlan filters */
1769 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1770 if (filters->filters[i].flags &
1771 VFPF_Q_FILTER_VLAN_TAG_VALID) {
1772 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1781 if (filters->vf_qid > vf_rxq_count(vf)) {
1790 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1791 struct bnx2x_virtf *vf,
1792 struct bnx2x_vf_mbx *mbx)
1794 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1797 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1801 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1805 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1809 /* print q_filter message */
1810 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1812 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1814 bnx2x_vf_mbx_resp(bp, vf, rc);
1817 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1818 struct bnx2x_vf_mbx *mbx)
1820 int qid = mbx->msg->req.q_op.vf_qid;
1823 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1826 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1827 bnx2x_vf_mbx_resp(bp, vf, rc);
1830 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1831 struct bnx2x_vf_mbx *mbx)
1835 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1837 rc = bnx2x_vf_close(bp, vf);
1838 bnx2x_vf_mbx_resp(bp, vf, rc);
1841 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1842 struct bnx2x_vf_mbx *mbx)
1846 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1848 rc = bnx2x_vf_free(bp, vf);
1849 bnx2x_vf_mbx_resp(bp, vf, rc);
1852 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1853 struct bnx2x_vf_mbx *mbx)
1855 struct bnx2x_config_rss_params rss;
1856 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1859 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1860 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1861 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1867 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1869 /* set vfop params according to rss tlv */
1870 memcpy(rss.ind_table, rss_tlv->ind_table,
1871 T_ETH_INDIRECTION_TABLE_SIZE);
1872 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
1873 rss.rss_obj = &vf->rss_conf_obj;
1874 rss.rss_result_mask = rss_tlv->rss_result_mask;
1876 /* flags handled individually for backward/forward compatability */
1878 rss.ramrod_flags = 0;
1880 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1881 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
1882 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1883 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
1884 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1885 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
1886 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1887 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
1888 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1889 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
1890 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1891 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
1892 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1893 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
1894 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1895 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
1896 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1897 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
1899 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1900 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1901 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1902 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1903 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1908 rc = bnx2x_vf_rss_update(bp, vf, &rss);
1910 bnx2x_vf_mbx_resp(bp, vf, rc);
1913 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
1914 struct vfpf_tpa_tlv *tpa_tlv)
1918 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
1919 U_ETH_MAX_SGES_FOR_PACKET) {
1921 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
1922 tpa_tlv->tpa_client_info.max_sges_for_packet,
1923 U_ETH_MAX_SGES_FOR_PACKET);
1926 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
1928 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
1929 tpa_tlv->tpa_client_info.max_tpa_queues,
1936 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
1937 struct bnx2x_vf_mbx *mbx)
1939 struct bnx2x_queue_update_tpa_params vf_op_params;
1940 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
1943 memset(&vf_op_params, 0, sizeof(vf_op_params));
1945 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
1948 vf_op_params.complete_on_both_clients =
1949 tpa_tlv->tpa_client_info.complete_on_both_clients;
1950 vf_op_params.dont_verify_thr =
1951 tpa_tlv->tpa_client_info.dont_verify_thr;
1952 vf_op_params.max_agg_sz =
1953 tpa_tlv->tpa_client_info.max_agg_size;
1954 vf_op_params.max_sges_pkt =
1955 tpa_tlv->tpa_client_info.max_sges_for_packet;
1956 vf_op_params.max_tpa_queues =
1957 tpa_tlv->tpa_client_info.max_tpa_queues;
1958 vf_op_params.sge_buff_sz =
1959 tpa_tlv->tpa_client_info.sge_buff_size;
1960 vf_op_params.sge_pause_thr_high =
1961 tpa_tlv->tpa_client_info.sge_pause_thr_high;
1962 vf_op_params.sge_pause_thr_low =
1963 tpa_tlv->tpa_client_info.sge_pause_thr_low;
1964 vf_op_params.tpa_mode =
1965 tpa_tlv->tpa_client_info.tpa_mode;
1966 vf_op_params.update_ipv4 =
1967 tpa_tlv->tpa_client_info.update_ipv4;
1968 vf_op_params.update_ipv6 =
1969 tpa_tlv->tpa_client_info.update_ipv6;
1971 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
1974 bnx2x_vf_mbx_resp(bp, vf, rc);
1977 /* dispatch request */
1978 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1979 struct bnx2x_vf_mbx *mbx)
1983 /* check if tlv type is known */
1984 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1985 /* Lock the per vf op mutex and note the locker's identity.
1986 * The unlock will take place in mbx response.
1988 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1990 /* switch on the opcode */
1991 switch (mbx->first_tlv.tl.type) {
1992 case CHANNEL_TLV_ACQUIRE:
1993 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1995 case CHANNEL_TLV_INIT:
1996 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1998 case CHANNEL_TLV_SETUP_Q:
1999 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
2001 case CHANNEL_TLV_SET_Q_FILTERS:
2002 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2004 case CHANNEL_TLV_TEARDOWN_Q:
2005 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2007 case CHANNEL_TLV_CLOSE:
2008 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2010 case CHANNEL_TLV_RELEASE:
2011 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2013 case CHANNEL_TLV_UPDATE_RSS:
2014 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2016 case CHANNEL_TLV_UPDATE_TPA:
2017 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2022 /* unknown TLV - this may belong to a VF driver from the future
2023 * - a version written after this PF driver was written, which
2024 * supports features unknown as of yet. Too bad since we don't
2025 * support them. Or this may be because someone wrote a crappy
2026 * VF driver and is sending garbage over the channel.
2028 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2029 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2031 for (i = 0; i < 20; i++)
2032 DP_CONT(BNX2X_MSG_IOV, "%x ",
2033 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2036 /* can we respond to VF (do we have an address for it?) */
2037 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2038 /* notify the VF that we do not support this request */
2039 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2041 /* can't send a response since this VF is unknown to us
2042 * just ack the FW to release the mailbox and unlock
2045 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2046 /* Firmware ack should be written before unlocking channel */
2048 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2052 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2053 struct vf_pf_event_data *vfpf_event)
2058 "vf pf event received: vfid %d, address_hi %x, address lo %x",
2059 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2060 /* Sanity checks consider removing later */
2062 /* check if the vf_id is valid */
2063 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2064 BNX2X_NR_VIRTFN(bp)) {
2065 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2066 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2070 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2072 /* Update VFDB with current message and schedule its handling */
2073 qlock(&BP_VFDB(bp)->event_mutex);
2074 BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
2075 BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
2076 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2077 qunlock(&BP_VFDB(bp)->event_mutex);
2079 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2082 /* handle new vf-pf messages */
2083 void bnx2x_vf_mbx(struct bnx2x *bp)
2085 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2093 qlock(&vfdb->event_mutex);
2094 events = vfdb->event_occur;
2095 vfdb->event_occur = 0;
2096 qunlock(&vfdb->event_mutex);
2098 for_each_vf(bp, vf_idx) {
2099 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2100 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2102 /* Handle VFs which have pending events */
2103 if (!(events & (1ULL << vf_idx)))
2107 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2108 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2109 mbx->first_tlv.resp_msg_offset);
2111 /* dmae to get the VF request */
2112 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2113 vf->abs_vfid, mbx->vf_addr_hi,
2115 sizeof(union vfpf_tlvs)/4);
2117 BNX2X_ERR("Failed to copy request VF %d\n",
2119 bnx2x_vf_release(bp, vf);
2123 /* process the VF message header */
2124 mbx->first_tlv = mbx->msg->req.first_tlv;
2126 /* Clean response buffer to refrain from falsely
2129 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2131 /* dispatch the request (will prepare the response) */
2132 bnx2x_vf_mbx_request(bp, vf, mbx);
2136 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2139 /* Older VFs contain a bug where they can't check CRC for bulletin
2140 * boards of length greater than legacy size.
2142 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2143 BULLETIN_CONTENT_LEGACY_SIZE;
2144 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2147 /* propagate local bulletin board to vf */
2148 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2150 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2151 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2152 vf * BULLETIN_CONTENT_SIZE;
2153 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2156 /* can only update vf after init took place */
2157 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2158 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2161 /* increment bulletin board version and compute crc */
2162 bulletin->version++;
2163 bnx2x_vf_bulletin_finalize(bulletin,
2164 (bnx2x_vf(bp, vf, cfg_flags) &
2165 VF_CFG_EXT_BULLETIN) ? true : false);
2167 /* propagate bulletin board via dmae to vm memory */
2168 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2169 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2170 U64_LO(vf_addr), bulletin->length / 4);