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;
227 struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
229 bool resources_acquired = false;
231 /* clear mailbox and prep first tlv */
232 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
234 if (bnx2x_get_vf_id(bp, &vf_id)) {
239 req->vfdev_info.vf_id = vf_id;
240 req->vfdev_info.vf_os = 0;
241 req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
243 req->resc_request.num_rxqs = rx_count;
244 req->resc_request.num_txqs = tx_count;
245 req->resc_request.num_sbs = bp->igu_sb_cnt;
246 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
247 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
249 /* pf 2 vf bulletin board address */
250 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
252 /* Request physical port identifier */
253 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
254 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
256 /* Bulletin support for bulletin board with length > legacy length */
257 req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
259 /* add list termination tlv */
260 bnx2x_add_tlv(bp, req,
261 req->first_tlv.tl.length + sizeof(struct channel_tlv),
262 CHANNEL_TLV_LIST_END,
263 sizeof(struct channel_list_end_tlv));
265 /* output tlvs list */
266 bnx2x_dp_tlv_list(bp, req);
268 while (!resources_acquired) {
269 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
271 /* send acquire request */
272 rc = bnx2x_send_msg2pf(bp,
274 bp->vf2pf_mbox_mapping);
280 /* copy acquire response from buffer to bp */
281 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
285 /* test whether the PF accepted our request. If not, humble
286 * the request and try again.
288 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
289 DP(BNX2X_MSG_SP, "resources acquired\n");
290 resources_acquired = true;
291 } else if (bp->acquire_resp.hdr.status ==
292 PFVF_STATUS_NO_RESOURCE &&
293 attempts < VF_ACQUIRE_THRESH) {
295 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
297 /* humble our request */
298 req->resc_request.num_txqs =
299 min(req->resc_request.num_txqs,
300 bp->acquire_resp.resc.num_txqs);
301 req->resc_request.num_rxqs =
302 min(req->resc_request.num_rxqs,
303 bp->acquire_resp.resc.num_rxqs);
304 req->resc_request.num_sbs =
305 min(req->resc_request.num_sbs,
306 bp->acquire_resp.resc.num_sbs);
307 req->resc_request.num_mac_filters =
308 min(req->resc_request.num_mac_filters,
309 bp->acquire_resp.resc.num_mac_filters);
310 req->resc_request.num_vlan_filters =
311 min(req->resc_request.num_vlan_filters,
312 bp->acquire_resp.resc.num_vlan_filters);
313 req->resc_request.num_mc_filters =
314 min(req->resc_request.num_mc_filters,
315 bp->acquire_resp.resc.num_mc_filters);
317 /* Clear response buffer */
318 memset(&bp->vf2pf_mbox->resp, 0,
319 sizeof(union pfvf_tlvs));
321 /* Determine reason of PF failure of acquire process */
322 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
323 CHANNEL_TLV_FP_HSI_SUPPORT);
324 if (fp_hsi_resp && !fp_hsi_resp->is_supported)
325 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
327 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
328 bp->acquire_resp.hdr.status);
334 /* Retrieve physical port id (if possible) */
335 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
336 bnx2x_search_tlv_list(bp, resp,
337 CHANNEL_TLV_PHYS_PORT_ID);
338 if (phys_port_resp) {
339 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
340 bp->flags |= HAS_PHYS_PORT_ID;
343 /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
344 * If that's the case, we need to make certain required FW was
345 * supported by such a hypervisor [i.e., v0-v2].
347 fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
348 CHANNEL_TLV_FP_HSI_SUPPORT);
349 if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
350 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
352 /* Since acquire succeeded on the PF side, we need to send a
353 * release message in order to allow future probes.
355 bnx2x_vfpf_finalize(bp, &req->first_tlv);
356 bnx2x_vfpf_release(bp);
363 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
364 bp->link_params.chip_id = bp->common.chip_id;
365 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
366 bp->common.int_block = INT_BLOCK_IGU;
367 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
371 bp->common.flash_size = 0;
373 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
374 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
375 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
376 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
379 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
380 memcpy(bp->dev->dev_addr,
381 bp->acquire_resp.resc.current_mac_addr,
385 bnx2x_vfpf_finalize(bp, &req->first_tlv);
389 int bnx2x_vfpf_release(struct bnx2x *bp)
391 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
392 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
395 /* clear mailbox and prep first tlv */
396 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
398 if (bnx2x_get_vf_id(bp, &vf_id)) {
405 /* add list termination tlv */
406 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
407 sizeof(struct channel_list_end_tlv));
409 /* output tlvs list */
410 bnx2x_dp_tlv_list(bp, req);
412 /* send release request */
413 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
419 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
421 DP(BNX2X_MSG_SP, "vf released\n");
423 /* PF reports error */
424 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
430 bnx2x_vfpf_finalize(bp, &req->first_tlv);
435 /* Tell PF about SB addresses */
436 int bnx2x_vfpf_init(struct bnx2x *bp)
438 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
439 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
442 /* clear mailbox and prep first tlv */
443 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
446 for_each_eth_queue(bp, i)
447 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
450 /* statistics - requests only supports single queue for now */
451 req->stats_addr = bp->fw_stats_data_mapping +
452 offsetof(struct bnx2x_fw_stats_data, queue_stats);
454 req->stats_stride = sizeof(struct per_queue_stats);
456 /* add list termination tlv */
457 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
458 sizeof(struct channel_list_end_tlv));
460 /* output tlvs list */
461 bnx2x_dp_tlv_list(bp, req);
463 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
467 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
468 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
474 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
476 bnx2x_vfpf_finalize(bp, &req->first_tlv);
481 /* CLOSE VF - opposite to INIT_VF */
482 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
484 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
485 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
489 /* If we haven't got a valid VF id, there is no sense to
490 * continue with sending messages
492 if (bnx2x_get_vf_id(bp, &vf_id))
495 /* Close the queues */
496 for_each_queue(bp, i)
497 bnx2x_vfpf_teardown_queue(bp, i);
500 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
502 /* clear mailbox and prep first tlv */
503 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
507 /* add list termination tlv */
508 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
509 sizeof(struct channel_list_end_tlv));
511 /* output tlvs list */
512 bnx2x_dp_tlv_list(bp, req);
514 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
517 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
519 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
520 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
523 bnx2x_vfpf_finalize(bp, &req->first_tlv);
526 /* Disable HW interrupts, NAPI */
527 bnx2x_netif_stop(bp, 0);
528 /* Delete all NAPI objects */
529 bnx2x_del_all_napi(bp);
535 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
536 struct bnx2x_vf_queue *q)
538 u8 cl_id = vfq_cl_id(vf, q);
539 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
542 bnx2x_init_mac_obj(bp, &q->mac_obj,
543 cl_id, q->cid, func_id,
544 bnx2x_vf_sp(bp, vf, mac_rdata),
545 bnx2x_vf_sp_map(bp, vf, mac_rdata),
546 BNX2X_FILTER_MAC_PENDING,
548 BNX2X_OBJ_TYPE_RX_TX,
551 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
552 cl_id, q->cid, func_id,
553 bnx2x_vf_sp(bp, vf, vlan_rdata),
554 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
555 BNX2X_FILTER_VLAN_PENDING,
557 BNX2X_OBJ_TYPE_RX_TX,
561 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
562 q->cid, func_id, func_id,
563 bnx2x_vf_sp(bp, vf, mcast_rdata),
564 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
565 BNX2X_FILTER_MCAST_PENDING,
567 BNX2X_OBJ_TYPE_RX_TX);
570 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
572 bnx2x_vf_sp(bp, vf, rss_rdata),
573 bnx2x_vf_sp_map(bp, vf, rss_rdata),
574 BNX2X_FILTER_RSS_CONF_PENDING,
576 BNX2X_OBJ_TYPE_RX_TX);
578 vf->leading_rss = cl_id;
579 q->is_leading = true;
580 q->sp_initialized = true;
583 /* ask the pf to open a queue for the vf */
584 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
587 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
588 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
589 u8 fp_idx = fp->index;
590 u16 tpa_agg_size = 0, flags = 0;
593 /* clear mailbox and prep first tlv */
594 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
596 /* select tpa mode to request */
597 if (fp->mode != TPA_MODE_DISABLED) {
598 flags |= VFPF_QUEUE_FLG_TPA;
599 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
600 if (fp->mode == TPA_MODE_GRO)
601 flags |= VFPF_QUEUE_FLG_TPA_GRO;
602 tpa_agg_size = TPA_AGG_SIZE;
606 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
608 /* calculate queue flags */
609 flags |= VFPF_QUEUE_FLG_STATS;
610 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
611 flags |= VFPF_QUEUE_FLG_VLAN;
614 req->vf_qid = fp_idx;
615 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
618 req->rxq.rcq_addr = fp->rx_comp_mapping;
619 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
620 req->rxq.rxq_addr = fp->rx_desc_mapping;
621 req->rxq.sge_addr = fp->rx_sge_mapping;
622 req->rxq.vf_sb = fp_idx;
623 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
624 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
625 req->rxq.mtu = bp->dev->mtu;
626 req->rxq.buf_sz = fp->rx_buf_size;
627 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
628 req->rxq.tpa_agg_sz = tpa_agg_size;
629 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
630 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
631 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
632 req->rxq.flags = flags;
633 req->rxq.drop_flags = 0;
634 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
635 req->rxq.stat_id = -1; /* No stats at the moment */
638 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
639 req->txq.vf_sb = fp_idx;
640 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
641 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
642 req->txq.flags = flags;
643 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
645 /* add list termination tlv */
646 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
647 sizeof(struct channel_list_end_tlv));
649 /* output tlvs list */
650 bnx2x_dp_tlv_list(bp, req);
652 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
654 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
657 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
658 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
659 fp_idx, resp->hdr.status);
663 bnx2x_vfpf_finalize(bp, &req->first_tlv);
668 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
670 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
671 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
674 /* clear mailbox and prep first tlv */
675 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
680 /* add list termination tlv */
681 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
682 sizeof(struct channel_list_end_tlv));
684 /* output tlvs list */
685 bnx2x_dp_tlv_list(bp, req);
687 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
690 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
695 /* PF failed the transaction */
696 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
697 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
703 bnx2x_vfpf_finalize(bp, &req->first_tlv);
708 /* request pf to add a mac for the vf */
709 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
711 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
712 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
713 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
716 /* clear mailbox and prep first tlv */
717 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
720 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
721 req->vf_qid = vf_qid;
722 req->n_mac_vlan_filters = 1;
724 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
726 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
728 /* sample bulletin board for new mac */
729 bnx2x_sample_bulletin(bp);
731 /* copy mac from device to request */
732 memcpy(req->filters[0].mac, addr, ETH_ALEN);
734 /* add list termination tlv */
735 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
736 sizeof(struct channel_list_end_tlv));
738 /* output tlvs list */
739 bnx2x_dp_tlv_list(bp, req);
741 /* send message to pf */
742 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
744 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
748 /* failure may mean PF was configured with a new mac for us */
749 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
751 "vfpf SET MAC failed. Check bulletin board for new posts\n");
753 /* copy mac from bulletin to device */
754 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
756 /* check if bulletin board was updated */
757 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
758 /* copy mac from device to request */
759 memcpy(req->filters[0].mac, bp->dev->dev_addr,
762 /* send message to pf */
763 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
764 bp->vf2pf_mbox_mapping);
766 /* no new info in bulletin */
771 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
772 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
776 bnx2x_vfpf_finalize(bp, &req->first_tlv);
781 /* request pf to config rss table for vf queues*/
782 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
783 struct bnx2x_config_rss_params *params)
785 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
786 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
789 /* clear mailbox and prep first tlv */
790 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
793 /* add list termination tlv */
794 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
795 sizeof(struct channel_list_end_tlv));
797 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
798 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
799 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
800 req->rss_key_size = T_ETH_RSS_KEY;
801 req->rss_result_mask = params->rss_result_mask;
803 /* flags handled individually for backward/forward compatibility */
804 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
805 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
806 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
807 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
808 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
809 req->rss_flags |= VFPF_RSS_SET_SRCH;
810 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
811 req->rss_flags |= VFPF_RSS_IPV4;
812 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
813 req->rss_flags |= VFPF_RSS_IPV4_TCP;
814 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
815 req->rss_flags |= VFPF_RSS_IPV4_UDP;
816 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
817 req->rss_flags |= VFPF_RSS_IPV6;
818 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
819 req->rss_flags |= VFPF_RSS_IPV6_TCP;
820 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
821 req->rss_flags |= VFPF_RSS_IPV6_UDP;
823 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
825 /* output tlvs list */
826 bnx2x_dp_tlv_list(bp, req);
828 /* send message to pf */
829 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
831 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
835 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
836 /* Since older drivers don't support this feature (and VF has
837 * no way of knowing other than failing this), don't propagate
838 * an error in this case.
841 "Failed to send rss message to PF over VF-PF channel [%d]\n",
845 bnx2x_vfpf_finalize(bp, &req->first_tlv);
850 int bnx2x_vfpf_set_mcast(struct net_device *dev)
852 struct bnx2x *bp = netdev_priv(dev);
853 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
854 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
856 struct netdev_hw_addr *ha;
858 if (bp->state != BNX2X_STATE_OPEN) {
859 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
863 /* clear mailbox and prep first tlv */
864 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
867 /* Get Rx mode requested */
868 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
870 netdev_for_each_mc_addr(ha, dev) {
871 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
873 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
877 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
880 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
882 "VF supports not more than %d multicast MAC addresses\n",
883 PFVF_MAX_MULTICAST_PER_VF);
887 req->n_multicast = i;
888 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
891 /* add list termination tlv */
892 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
893 sizeof(struct channel_list_end_tlv));
895 /* output tlvs list */
896 bnx2x_dp_tlv_list(bp, req);
897 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
899 BNX2X_ERR("Sending a message failed: %d\n", rc);
903 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
904 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
909 bnx2x_vfpf_finalize(bp, &req->first_tlv);
914 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
916 int mode = bp->rx_mode;
917 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
918 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
921 /* clear mailbox and prep first tlv */
922 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
925 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
927 /* Ignore everything accept MODE_NONE */
928 if (mode == BNX2X_RX_MODE_NONE) {
929 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
931 /* Current PF driver will not look at the specific flags,
932 * but they are required when working with older drivers on hv.
934 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
935 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
936 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
939 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
942 /* add list termination tlv */
943 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
944 sizeof(struct channel_list_end_tlv));
946 /* output tlvs list */
947 bnx2x_dp_tlv_list(bp, req);
949 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
951 BNX2X_ERR("Sending a message failed: %d\n", rc);
953 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
954 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
958 bnx2x_vfpf_finalize(bp, &req->first_tlv);
963 /* General service functions */
964 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
966 u32 addr = BAR_CSTRORM_INTMEM +
967 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
969 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
972 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
974 u32 addr = BAR_CSTRORM_INTMEM +
975 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
977 REG_WR8(bp, addr, 1);
980 /* enable vf_pf mailbox (aka vf-pf-channel) */
981 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
983 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
985 /* enable the mailbox in the FW */
986 storm_memset_vf_mbx_ack(bp, abs_vfid);
987 storm_memset_vf_mbx_valid(bp, abs_vfid);
989 /* enable the VF access to the mailbox */
990 bnx2x_vf_enable_access(bp, abs_vfid);
993 /* this works only on !E1h */
994 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
995 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
996 u32 vf_addr_lo, u32 len32)
998 struct dmae_command dmae;
1000 if (CHIP_IS_E1x(bp)) {
1001 BNX2X_ERR("Chip revision does not support VFs\n");
1002 return DMAE_NOT_RDY;
1005 if (!bp->dmae_ready) {
1006 BNX2X_ERR("DMAE is not ready, can not copy\n");
1007 return DMAE_NOT_RDY;
1010 /* set opcode and fixed command fields */
1011 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1014 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1015 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1016 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1018 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1020 dmae.src_addr_lo = vf_addr_lo;
1021 dmae.src_addr_hi = vf_addr_hi;
1022 dmae.dst_addr_lo = U64_LO(pf_addr);
1023 dmae.dst_addr_hi = U64_HI(pf_addr);
1025 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1026 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1027 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1029 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1031 dmae.src_addr_lo = U64_LO(pf_addr);
1032 dmae.src_addr_hi = U64_HI(pf_addr);
1033 dmae.dst_addr_lo = vf_addr_lo;
1034 dmae.dst_addr_hi = vf_addr_hi;
1038 /* issue the command and wait for completion */
1039 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1042 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1043 struct bnx2x_virtf *vf)
1045 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1048 /* prepare response */
1049 type = mbx->first_tlv.tl.type;
1050 length = type == CHANNEL_TLV_ACQUIRE ?
1051 sizeof(struct pfvf_acquire_resp_tlv) :
1052 sizeof(struct pfvf_general_resp_tlv);
1053 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1054 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1055 sizeof(struct channel_list_end_tlv));
1058 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1059 struct bnx2x_virtf *vf,
1062 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1063 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1068 bnx2x_dp_tlv_list(bp, resp);
1069 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1070 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1072 resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1075 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1076 mbx->first_tlv.resp_msg_offset;
1077 pf_addr = mbx->msg_mapping +
1078 offsetof(struct bnx2x_vf_mbx_msg, resp);
1080 /* Copy the response buffer. The first u64 is written afterwards, as
1081 * the vf is sensitive to the header being written
1083 vf_addr += sizeof(u64);
1084 pf_addr += sizeof(u64);
1085 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1088 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1090 BNX2X_ERR("Failed to copy response body to VF %d\n",
1094 vf_addr -= sizeof(u64);
1095 pf_addr -= sizeof(u64);
1098 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1101 /* copy the response header including status-done field,
1102 * must be last dmae, must be after FW is acked
1104 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1109 /* unlock channel mutex */
1110 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1113 BNX2X_ERR("Failed to copy response status to VF %d\n",
1120 bnx2x_vf_release(bp, vf);
1123 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1124 struct bnx2x_virtf *vf,
1127 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1128 bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1131 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1132 struct bnx2x_virtf *vf,
1136 struct vfpf_port_phys_id_resp_tlv *port_id;
1138 if (!(bp->flags & HAS_PHYS_PORT_ID))
1141 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1142 sizeof(struct vfpf_port_phys_id_resp_tlv));
1144 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1145 (((u8 *)buffer) + *offset);
1146 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1148 /* Offset should continue representing the offset to the tail
1149 * of TLV data (outside this function scope)
1151 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1154 static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1155 struct bnx2x_virtf *vf,
1159 struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1161 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1162 sizeof(struct vfpf_fp_hsi_resp_tlv));
1164 fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1165 (((u8 *)buffer) + *offset);
1166 fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1168 /* Offset should continue representing the offset to the tail
1169 * of TLV data (outside this function scope)
1171 *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1174 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1175 struct bnx2x_vf_mbx *mbx, int vfop_status)
1178 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1179 struct pf_vf_resc *resc = &resp->resc;
1180 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1183 memset(resp, 0, sizeof(*resp));
1185 /* fill in pfdev info */
1186 resp->pfdev_info.chip_num = bp->common.chip_id;
1187 resp->pfdev_info.db_size = bp->db_size;
1188 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1189 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1191 PFVF_CAP_TPA_UPDATE);
1192 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1193 sizeof(resp->pfdev_info.fw_ver));
1195 if (status == PFVF_STATUS_NO_RESOURCE ||
1196 status == PFVF_STATUS_SUCCESS) {
1197 /* set resources numbers, if status equals NO_RESOURCE these
1198 * are max possible numbers
1200 resc->num_rxqs = vf_rxq_count(vf) ? :
1201 bnx2x_vf_max_queue_cnt(bp, vf);
1202 resc->num_txqs = vf_txq_count(vf) ? :
1203 bnx2x_vf_max_queue_cnt(bp, vf);
1204 resc->num_sbs = vf_sb_count(vf);
1205 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1206 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
1207 resc->num_mc_filters = 0;
1209 if (status == PFVF_STATUS_SUCCESS) {
1210 /* fill in the allocated resources */
1211 struct pf_vf_bulletin_content *bulletin =
1212 BP_VF_BULLETIN(bp, vf->index);
1216 vfq_qzone_id(vf, vfq_get(vf, i));
1218 for_each_vf_sb(vf, i) {
1219 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1220 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1223 /* if a mac has been set for this vf, supply it */
1224 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1225 memcpy(resc->current_mac_addr, bulletin->mac,
1231 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"
1232 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1234 resp->pfdev_info.chip_num,
1235 resp->pfdev_info.db_size,
1236 resp->pfdev_info.indices_per_sb,
1237 resp->pfdev_info.pf_cap,
1241 resc->num_mac_filters,
1242 resc->num_vlan_filters,
1243 resc->num_mc_filters,
1244 resp->pfdev_info.fw_ver);
1246 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1247 for (i = 0; i < vf_rxq_count(vf); i++)
1248 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1249 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1250 for (i = 0; i < vf_sb_count(vf); i++)
1251 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1252 resc->hw_sbs[i].hw_sb_id,
1253 resc->hw_sbs[i].sb_qid);
1254 DP_CONT(BNX2X_MSG_IOV, "]\n");
1256 /* prepare response */
1257 length = sizeof(struct pfvf_acquire_resp_tlv);
1258 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1260 /* Handle possible VF requests for physical port identifiers.
1261 * 'length' should continue to indicate the offset of the first empty
1262 * place in the buffer (i.e., where next TLV should be inserted)
1264 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1265 CHANNEL_TLV_PHYS_PORT_ID))
1266 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1268 /* `New' vfs will want to know if fastpath HSI is supported, since
1269 * if that's not the case they could print into system log the fact
1270 * the driver version must be updated.
1272 bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1274 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1275 sizeof(struct channel_list_end_tlv));
1277 /* send the response */
1278 bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1281 static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1282 struct vfpf_acquire_tlv *acquire)
1284 /* Windows driver does one of three things:
1285 * 1. Old driver doesn't have bulletin board address set.
1286 * 2. 'Middle' driver sends mc_num == 32.
1287 * 3. New driver sets the OS field.
1289 if (!acquire->bulletin_addr ||
1290 acquire->resc_request.num_mc_filters == 32 ||
1291 ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1298 static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1299 struct bnx2x_virtf *vf,
1300 struct bnx2x_vf_mbx *mbx)
1302 /* Linux drivers which correctly set the doorbell size also
1303 * send a physical port request
1305 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1306 CHANNEL_TLV_PHYS_PORT_ID))
1309 /* Issue does not exist in windows VMs */
1310 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1316 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1317 struct bnx2x_vf_mbx *mbx)
1320 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1322 /* log vfdef info */
1324 "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",
1325 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1326 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1327 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1328 acquire->resc_request.num_vlan_filters,
1329 acquire->resc_request.num_mc_filters);
1331 /* Prevent VFs with old drivers from loading, since they calculate
1332 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
1333 * while being upgraded.
1335 rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1338 "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1343 /* Verify the VF fastpath HSI can be supported by the loaded FW.
1344 * Linux vfs should be oblivious to changes between v0 and v2.
1346 if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1347 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1349 vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
1351 if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1353 "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1354 vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1355 ETH_FP_HSI_VERSION);
1360 /* acquire the resources */
1361 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1363 /* store address of vf's bulletin board */
1364 vf->bulletin_map = acquire->bulletin_addr;
1365 if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1366 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1368 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1370 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1375 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1378 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1379 struct bnx2x_vf_mbx *mbx)
1381 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1384 /* record ghost addresses from vf message */
1385 vf->spq_map = init->spq_addr;
1386 vf->fw_stat_map = init->stats_addr;
1387 vf->stats_stride = init->stats_stride;
1388 rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1390 /* set VF multiqueue statistics collection mode */
1391 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1392 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1394 /* Update VF's view of link state */
1395 if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1396 bnx2x_iov_link_update_vf(bp, vf->index);
1399 bnx2x_vf_mbx_resp(bp, vf, rc);
1402 /* convert MBX queue-flags to standard SP queue-flags */
1403 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1404 unsigned long *sp_q_flags)
1406 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1407 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1408 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1409 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1410 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1411 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1412 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1413 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1414 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1415 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1416 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1417 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1418 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1419 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1420 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1421 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1422 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1423 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1425 /* outer vlan removal is set according to PF's multi function mode */
1427 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1430 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1431 struct bnx2x_vf_mbx *mbx)
1433 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1434 struct bnx2x_vf_queue_construct_params qctor;
1438 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1439 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1440 setup_q->vf_qid, vf_rxq_count(vf));
1445 /* tx queues must be setup alongside rx queues thus if the rx queue
1446 * is not marked as valid there's nothing to do.
1448 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1449 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1450 unsigned long q_type = 0;
1452 struct bnx2x_queue_init_params *init_p;
1453 struct bnx2x_queue_setup_params *setup_p;
1455 if (bnx2x_vfq_is_leading(q))
1456 bnx2x_leading_vfq_init(bp, vf, q);
1458 /* re-init the VF operation context */
1460 sizeof(struct bnx2x_vf_queue_construct_params));
1461 setup_p = &qctor.prep_qsetup;
1462 init_p = &qctor.qstate.params.init;
1464 /* activate immediately */
1465 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1467 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1468 struct bnx2x_txq_setup_params *txq_params =
1469 &setup_p->txq_params;
1471 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1473 /* save sb resource index */
1474 q->sb_idx = setup_q->txq.vf_sb;
1477 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1478 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1480 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1483 /* tx setup - flags */
1484 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1487 /* tx setup - general, nothing */
1490 txq_params->dscr_map = setup_q->txq.txq_addr;
1491 txq_params->sb_cq_index = setup_q->txq.sb_index;
1492 txq_params->traffic_type = setup_q->txq.traffic_type;
1494 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1495 q->index, q->sb_idx);
1498 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1499 struct bnx2x_rxq_setup_params *rxq_params =
1500 &setup_p->rxq_params;
1502 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1504 /* Note: there is no support for different SBs
1507 q->sb_idx = setup_q->rxq.vf_sb;
1510 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1511 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1512 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1515 /* rx setup - flags */
1516 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1519 /* rx setup - general */
1520 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1523 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1524 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1525 rxq_params->sge_map = setup_q->rxq.sge_addr;
1526 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1527 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1528 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1529 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1530 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1531 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1532 rxq_params->cache_line_log =
1533 setup_q->rxq.cache_line_log;
1534 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1536 /* rx setup - multicast engine */
1537 if (bnx2x_vfq_is_leading(q)) {
1538 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1540 rxq_params->mcast_engine_id = mcast_id;
1541 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1544 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1545 q->index, q->sb_idx);
1547 /* complete the preparations */
1548 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1550 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1555 bnx2x_vf_mbx_resp(bp, vf, rc);
1558 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1559 struct bnx2x_virtf *vf,
1560 struct vfpf_set_q_filters_tlv *tlv,
1561 struct bnx2x_vf_mac_vlan_filters **pfl,
1565 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1568 fsz = tlv->n_mac_vlan_filters *
1569 sizeof(struct bnx2x_vf_mac_vlan_filter) +
1570 sizeof(struct bnx2x_vf_mac_vlan_filters);
1572 fl = kzalloc(fsz, GFP_KERNEL);
1576 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1577 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1579 if ((msg_filter->flags & type_flag) != type_flag)
1581 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1582 fl->filters[j].mac = msg_filter->mac;
1583 fl->filters[j].type = BNX2X_VF_FILTER_MAC;
1585 fl->filters[j].vid = msg_filter->vlan_tag;
1586 fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
1588 fl->filters[j].add =
1589 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1601 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1602 struct vfpf_q_mac_vlan_filter *filter)
1604 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1605 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1606 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1607 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1608 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1609 DP_CONT(msglvl, "\n");
1612 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1613 struct vfpf_set_q_filters_tlv *filters)
1617 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1618 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1619 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1620 &filters->filters[i]);
1622 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1623 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1625 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1626 for (i = 0; i < filters->n_multicast; i++)
1627 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1630 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1631 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1633 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1637 struct vfpf_set_q_filters_tlv *msg =
1638 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1640 /* check for any mac/vlan changes */
1641 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1642 /* build mac list */
1643 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1645 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1653 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1660 /* build vlan list */
1663 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1670 rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1678 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1679 unsigned long accept = 0;
1680 struct pf_vf_bulletin_content *bulletin =
1681 BP_VF_BULLETIN(bp, vf->index);
1683 /* Ignore VF requested mode; instead set a regular mode */
1684 if (msg->rx_mask != VFPF_RX_MASK_ACCEPT_NONE) {
1685 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1686 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1687 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1690 /* A packet arriving the vf's mac should be accepted
1691 * with any vlan, unless a vlan has already been
1694 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
1695 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1698 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1703 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1705 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1706 msg->n_multicast, false);
1712 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1713 vf->abs_vfid, msg->vf_qid, rc);
1717 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1718 struct bnx2x_virtf *vf,
1719 struct vfpf_set_q_filters_tlv *filters)
1721 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1724 /* if a mac was already set for this VF via the set vf mac ndo, we only
1725 * accept mac configurations of that mac. Why accept them at all?
1726 * because PF may have been unable to configure the mac at the time
1727 * since queue was not set up.
1729 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1730 /* once a mac was set by ndo can only accept a single mac... */
1731 if (filters->n_mac_vlan_filters > 1) {
1732 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1738 /* ...and only the mac set by the ndo */
1739 if (filters->n_mac_vlan_filters == 1 &&
1740 !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
1741 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1753 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1754 struct bnx2x_virtf *vf,
1755 struct vfpf_set_q_filters_tlv *filters)
1757 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1760 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1761 if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1764 /* search for vlan filters */
1765 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1766 if (filters->filters[i].flags &
1767 VFPF_Q_FILTER_VLAN_TAG_VALID) {
1768 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1777 if (filters->vf_qid > vf_rxq_count(vf)) {
1786 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1787 struct bnx2x_virtf *vf,
1788 struct bnx2x_vf_mbx *mbx)
1790 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1793 rc = bnx2x_filters_validate_mac(bp, vf, filters);
1797 rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1801 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1805 /* print q_filter message */
1806 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1808 rc = bnx2x_vf_mbx_qfilters(bp, vf);
1810 bnx2x_vf_mbx_resp(bp, vf, rc);
1813 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1814 struct bnx2x_vf_mbx *mbx)
1816 int qid = mbx->msg->req.q_op.vf_qid;
1819 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1822 rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1823 bnx2x_vf_mbx_resp(bp, vf, rc);
1826 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1827 struct bnx2x_vf_mbx *mbx)
1831 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1833 rc = bnx2x_vf_close(bp, vf);
1834 bnx2x_vf_mbx_resp(bp, vf, rc);
1837 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1838 struct bnx2x_vf_mbx *mbx)
1842 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1844 rc = bnx2x_vf_free(bp, vf);
1845 bnx2x_vf_mbx_resp(bp, vf, rc);
1848 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1849 struct bnx2x_vf_mbx *mbx)
1851 struct bnx2x_config_rss_params rss;
1852 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1855 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1856 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1857 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1863 memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1865 /* set vfop params according to rss tlv */
1866 memcpy(rss.ind_table, rss_tlv->ind_table,
1867 T_ETH_INDIRECTION_TABLE_SIZE);
1868 memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
1869 rss.rss_obj = &vf->rss_conf_obj;
1870 rss.rss_result_mask = rss_tlv->rss_result_mask;
1872 /* flags handled individually for backward/forward compatibility */
1874 rss.ramrod_flags = 0;
1876 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1877 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
1878 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1879 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
1880 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1881 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
1882 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1883 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
1884 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1885 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
1886 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1887 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
1888 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1889 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
1890 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1891 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
1892 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1893 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
1895 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1896 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1897 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1898 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1899 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1904 rc = bnx2x_vf_rss_update(bp, vf, &rss);
1906 bnx2x_vf_mbx_resp(bp, vf, rc);
1909 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
1910 struct vfpf_tpa_tlv *tpa_tlv)
1914 if (tpa_tlv->tpa_client_info.max_sges_for_packet >
1915 U_ETH_MAX_SGES_FOR_PACKET) {
1917 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
1918 tpa_tlv->tpa_client_info.max_sges_for_packet,
1919 U_ETH_MAX_SGES_FOR_PACKET);
1922 if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
1924 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
1925 tpa_tlv->tpa_client_info.max_tpa_queues,
1932 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
1933 struct bnx2x_vf_mbx *mbx)
1935 struct bnx2x_queue_update_tpa_params vf_op_params;
1936 struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
1939 memset(&vf_op_params, 0, sizeof(vf_op_params));
1941 if (bnx2x_validate_tpa_params(bp, tpa_tlv))
1944 vf_op_params.complete_on_both_clients =
1945 tpa_tlv->tpa_client_info.complete_on_both_clients;
1946 vf_op_params.dont_verify_thr =
1947 tpa_tlv->tpa_client_info.dont_verify_thr;
1948 vf_op_params.max_agg_sz =
1949 tpa_tlv->tpa_client_info.max_agg_size;
1950 vf_op_params.max_sges_pkt =
1951 tpa_tlv->tpa_client_info.max_sges_for_packet;
1952 vf_op_params.max_tpa_queues =
1953 tpa_tlv->tpa_client_info.max_tpa_queues;
1954 vf_op_params.sge_buff_sz =
1955 tpa_tlv->tpa_client_info.sge_buff_size;
1956 vf_op_params.sge_pause_thr_high =
1957 tpa_tlv->tpa_client_info.sge_pause_thr_high;
1958 vf_op_params.sge_pause_thr_low =
1959 tpa_tlv->tpa_client_info.sge_pause_thr_low;
1960 vf_op_params.tpa_mode =
1961 tpa_tlv->tpa_client_info.tpa_mode;
1962 vf_op_params.update_ipv4 =
1963 tpa_tlv->tpa_client_info.update_ipv4;
1964 vf_op_params.update_ipv6 =
1965 tpa_tlv->tpa_client_info.update_ipv6;
1967 rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
1970 bnx2x_vf_mbx_resp(bp, vf, rc);
1973 /* dispatch request */
1974 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1975 struct bnx2x_vf_mbx *mbx)
1979 /* check if tlv type is known */
1980 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1981 /* Lock the per vf op mutex and note the locker's identity.
1982 * The unlock will take place in mbx response.
1984 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1986 /* switch on the opcode */
1987 switch (mbx->first_tlv.tl.type) {
1988 case CHANNEL_TLV_ACQUIRE:
1989 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1991 case CHANNEL_TLV_INIT:
1992 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1994 case CHANNEL_TLV_SETUP_Q:
1995 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1997 case CHANNEL_TLV_SET_Q_FILTERS:
1998 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2000 case CHANNEL_TLV_TEARDOWN_Q:
2001 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2003 case CHANNEL_TLV_CLOSE:
2004 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2006 case CHANNEL_TLV_RELEASE:
2007 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2009 case CHANNEL_TLV_UPDATE_RSS:
2010 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2012 case CHANNEL_TLV_UPDATE_TPA:
2013 bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2018 /* unknown TLV - this may belong to a VF driver from the future
2019 * - a version written after this PF driver was written, which
2020 * supports features unknown as of yet. Too bad since we don't
2021 * support them. Or this may be because someone wrote a crappy
2022 * VF driver and is sending garbage over the channel.
2024 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2025 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2027 for (i = 0; i < 20; i++)
2028 DP_CONT(BNX2X_MSG_IOV, "%x ",
2029 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2032 /* can we respond to VF (do we have an address for it?) */
2033 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2034 /* notify the VF that we do not support this request */
2035 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2037 /* can't send a response since this VF is unknown to us
2038 * just ack the FW to release the mailbox and unlock
2041 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2042 /* Firmware ack should be written before unlocking channel */
2044 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2048 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2049 struct vf_pf_event_data *vfpf_event)
2054 "vf pf event received: vfid %d, address_hi %x, address lo %x",
2055 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2056 /* Sanity checks consider removing later */
2058 /* check if the vf_id is valid */
2059 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2060 BNX2X_NR_VIRTFN(bp)) {
2061 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2062 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2066 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2068 /* Update VFDB with current message and schedule its handling */
2069 mutex_lock(&BP_VFDB(bp)->event_mutex);
2070 BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
2071 BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
2072 BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2073 mutex_unlock(&BP_VFDB(bp)->event_mutex);
2075 bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2078 /* handle new vf-pf messages */
2079 void bnx2x_vf_mbx(struct bnx2x *bp)
2081 struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2089 mutex_lock(&vfdb->event_mutex);
2090 events = vfdb->event_occur;
2091 vfdb->event_occur = 0;
2092 mutex_unlock(&vfdb->event_mutex);
2094 for_each_vf(bp, vf_idx) {
2095 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2096 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2098 /* Handle VFs which have pending events */
2099 if (!(events & (1ULL << vf_idx)))
2103 "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2104 vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2105 mbx->first_tlv.resp_msg_offset);
2107 /* dmae to get the VF request */
2108 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2109 vf->abs_vfid, mbx->vf_addr_hi,
2111 sizeof(union vfpf_tlvs)/4);
2113 BNX2X_ERR("Failed to copy request VF %d\n",
2115 bnx2x_vf_release(bp, vf);
2119 /* process the VF message header */
2120 mbx->first_tlv = mbx->msg->req.first_tlv;
2122 /* Clean response buffer to refrain from falsely
2125 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2127 /* dispatch the request (will prepare the response) */
2128 bnx2x_vf_mbx_request(bp, vf, mbx);
2132 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2135 /* Older VFs contain a bug where they can't check CRC for bulletin
2136 * boards of length greater than legacy size.
2138 bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2139 BULLETIN_CONTENT_LEGACY_SIZE;
2140 bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2143 /* propagate local bulletin board to vf */
2144 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2146 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2147 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2148 vf * BULLETIN_CONTENT_SIZE;
2149 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2152 /* can only update vf after init took place */
2153 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2154 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2157 /* increment bulletin board version and compute crc */
2158 bulletin->version++;
2159 bnx2x_vf_bulletin_finalize(bulletin,
2160 (bnx2x_vf(bp, vf, cfg_flags) &
2161 VF_CFG_EXT_BULLETIN) ? true : false);
2163 /* propagate bulletin board via dmae to vm memory */
2164 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2165 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2166 U64_LO(vf_addr), bulletin->length / 4);