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: Eilon Greenstein <eilong@broadcom.com>
16 * Written by: Shmulik Ravid <shmulikr@broadcom.com>
17 * Ariel Elior <ariele@broadcom.com>
21 #include "bnx2x_cmn.h"
22 #include <linux/crc32.h>
24 /* place a given tlv on the tlv buffer at a given offset */
25 void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
28 struct channel_tlv *tl =
29 (struct channel_tlv *)(tlvs_list + offset);
35 /* Clear the mailbox and init the header of the first tlv */
36 void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
39 mutex_lock(&bp->vf2pf_mutex);
41 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
45 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
47 /* init type and length */
48 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
50 /* init first tlv header */
51 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
54 /* releases the mailbox */
55 void bnx2x_vfpf_finalize(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv)
57 DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
60 mutex_unlock(&bp->vf2pf_mutex);
63 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
64 static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
65 enum channel_tlvs req_tlv)
67 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
70 if (tlv->type == req_tlv)
74 BNX2X_ERR("Found TLV with length 0\n");
78 tlvs_list += tlv->length;
79 tlv = (struct channel_tlv *)tlvs_list;
80 } while (tlv->type != CHANNEL_TLV_LIST_END);
82 DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
87 /* list the types and lengths of the tlvs on the buffer */
88 void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
91 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
93 while (tlv->type != CHANNEL_TLV_LIST_END) {
95 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
96 tlv->type, tlv->length);
98 /* advance to next tlv */
99 tlvs_list += tlv->length;
101 /* cast general tlv list pointer to channel tlv header*/
102 tlv = (struct channel_tlv *)tlvs_list;
106 /* break condition for this loop */
107 if (i > MAX_TLVS_IN_LIST) {
108 WARN(true, "corrupt tlvs");
113 /* output last tlv */
114 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
115 tlv->type, tlv->length);
118 /* test whether we support a tlv type */
119 bool bnx2x_tlv_supported(u16 tlvtype)
121 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
124 static inline int bnx2x_pfvf_status_codes(int rc)
128 return PFVF_STATUS_SUCCESS;
130 return PFVF_STATUS_NO_RESOURCE;
132 return PFVF_STATUS_FAILURE;
136 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
138 struct cstorm_vf_zone_data __iomem *zone_data =
139 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
140 int tout = 100, interval = 100; /* wait for 10 seconds */
143 BNX2X_ERR("done was non zero before message to pf was sent\n");
148 /* if PF indicated channel is down avoid sending message. Return success
149 * so calling flow can continue
151 bnx2x_sample_bulletin(bp);
152 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
153 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
154 *done = PFVF_STATUS_SUCCESS;
158 /* Write message address */
159 writel(U64_LO(msg_mapping),
160 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
161 writel(U64_HI(msg_mapping),
162 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
164 /* make sure the address is written before FW accesses it */
167 /* Trigger the PF FW */
168 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
170 /* Wait for PF to complete */
171 while ((tout >= 0) && (!*done)) {
175 /* progress indicator - HV can take its own sweet time in
178 DP_CONT(BNX2X_MSG_IOV, ".");
182 BNX2X_ERR("PF response has timed out\n");
185 DP(BNX2X_MSG_SP, "Got a response from PF\n");
189 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
192 int tout = 10, interval = 100; /* Wait for 1 sec */
195 /* pxp traps vf read of doorbells and returns me reg value */
196 me_reg = readl(bp->doorbells);
197 if (GOOD_ME_REG(me_reg))
202 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
204 } while (tout-- > 0);
206 if (!GOOD_ME_REG(me_reg)) {
207 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
211 DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
213 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
218 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
220 int rc = 0, attempts = 0;
221 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
222 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
223 struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
225 bool resources_acquired = false;
227 /* clear mailbox and prep first tlv */
228 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
230 if (bnx2x_get_vf_id(bp, &vf_id)) {
235 req->vfdev_info.vf_id = vf_id;
236 req->vfdev_info.vf_os = 0;
238 req->resc_request.num_rxqs = rx_count;
239 req->resc_request.num_txqs = tx_count;
240 req->resc_request.num_sbs = bp->igu_sb_cnt;
241 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
242 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
244 /* pf 2 vf bulletin board address */
245 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
247 /* Request physical port identifier */
248 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
249 CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
251 /* add list termination tlv */
252 bnx2x_add_tlv(bp, req,
253 req->first_tlv.tl.length + sizeof(struct channel_tlv),
254 CHANNEL_TLV_LIST_END,
255 sizeof(struct channel_list_end_tlv));
257 /* output tlvs list */
258 bnx2x_dp_tlv_list(bp, req);
260 while (!resources_acquired) {
261 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
263 /* send acquire request */
264 rc = bnx2x_send_msg2pf(bp,
266 bp->vf2pf_mbox_mapping);
272 /* copy acquire response from buffer to bp */
273 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
277 /* test whether the PF accepted our request. If not, humble
278 * the request and try again.
280 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
281 DP(BNX2X_MSG_SP, "resources acquired\n");
282 resources_acquired = true;
283 } else if (bp->acquire_resp.hdr.status ==
284 PFVF_STATUS_NO_RESOURCE &&
285 attempts < VF_ACQUIRE_THRESH) {
287 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
289 /* humble our request */
290 req->resc_request.num_txqs =
291 min(req->resc_request.num_txqs,
292 bp->acquire_resp.resc.num_txqs);
293 req->resc_request.num_rxqs =
294 min(req->resc_request.num_rxqs,
295 bp->acquire_resp.resc.num_rxqs);
296 req->resc_request.num_sbs =
297 min(req->resc_request.num_sbs,
298 bp->acquire_resp.resc.num_sbs);
299 req->resc_request.num_mac_filters =
300 min(req->resc_request.num_mac_filters,
301 bp->acquire_resp.resc.num_mac_filters);
302 req->resc_request.num_vlan_filters =
303 min(req->resc_request.num_vlan_filters,
304 bp->acquire_resp.resc.num_vlan_filters);
305 req->resc_request.num_mc_filters =
306 min(req->resc_request.num_mc_filters,
307 bp->acquire_resp.resc.num_mc_filters);
309 /* Clear response buffer */
310 memset(&bp->vf2pf_mbox->resp, 0,
311 sizeof(union pfvf_tlvs));
313 /* PF reports error */
314 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
315 bp->acquire_resp.hdr.status);
321 /* Retrieve physical port id (if possible) */
322 phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
323 bnx2x_search_tlv_list(bp, resp,
324 CHANNEL_TLV_PHYS_PORT_ID);
325 if (phys_port_resp) {
326 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
327 bp->flags |= HAS_PHYS_PORT_ID;
331 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
332 bp->link_params.chip_id = bp->common.chip_id;
333 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
334 bp->common.int_block = INT_BLOCK_IGU;
335 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
339 bp->common.flash_size = 0;
341 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
342 bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
343 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
344 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
347 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
348 memcpy(bp->dev->dev_addr,
349 bp->acquire_resp.resc.current_mac_addr,
353 bnx2x_vfpf_finalize(bp, &req->first_tlv);
357 int bnx2x_vfpf_release(struct bnx2x *bp)
359 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
360 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
363 /* clear mailbox and prep first tlv */
364 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
366 if (bnx2x_get_vf_id(bp, &vf_id)) {
373 /* add list termination tlv */
374 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
375 sizeof(struct channel_list_end_tlv));
377 /* output tlvs list */
378 bnx2x_dp_tlv_list(bp, req);
380 /* send release request */
381 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
387 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
389 DP(BNX2X_MSG_SP, "vf released\n");
391 /* PF reports error */
392 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
398 bnx2x_vfpf_finalize(bp, &req->first_tlv);
403 /* Tell PF about SB addresses */
404 int bnx2x_vfpf_init(struct bnx2x *bp)
406 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
407 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
410 /* clear mailbox and prep first tlv */
411 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
414 for_each_eth_queue(bp, i)
415 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
418 /* statistics - requests only supports single queue for now */
419 req->stats_addr = bp->fw_stats_data_mapping +
420 offsetof(struct bnx2x_fw_stats_data, queue_stats);
422 req->stats_stride = sizeof(struct per_queue_stats);
424 /* add list termination tlv */
425 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
426 sizeof(struct channel_list_end_tlv));
428 /* output tlvs list */
429 bnx2x_dp_tlv_list(bp, req);
431 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
435 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
436 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
442 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
444 bnx2x_vfpf_finalize(bp, &req->first_tlv);
449 /* CLOSE VF - opposite to INIT_VF */
450 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
452 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
453 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
457 /* If we haven't got a valid VF id, there is no sense to
458 * continue with sending messages
460 if (bnx2x_get_vf_id(bp, &vf_id))
463 /* Close the queues */
464 for_each_queue(bp, i)
465 bnx2x_vfpf_teardown_queue(bp, i);
468 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
470 /* clear mailbox and prep first tlv */
471 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
475 /* add list termination tlv */
476 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
477 sizeof(struct channel_list_end_tlv));
479 /* output tlvs list */
480 bnx2x_dp_tlv_list(bp, req);
482 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
485 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
487 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
488 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
491 bnx2x_vfpf_finalize(bp, &req->first_tlv);
494 /* Disable HW interrupts, NAPI */
495 bnx2x_netif_stop(bp, 0);
496 /* Delete all NAPI objects */
497 bnx2x_del_all_napi(bp);
503 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
504 struct bnx2x_vf_queue *q)
506 u8 cl_id = vfq_cl_id(vf, q);
507 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
510 bnx2x_init_mac_obj(bp, &q->mac_obj,
511 cl_id, q->cid, func_id,
512 bnx2x_vf_sp(bp, vf, mac_rdata),
513 bnx2x_vf_sp_map(bp, vf, mac_rdata),
514 BNX2X_FILTER_MAC_PENDING,
516 BNX2X_OBJ_TYPE_RX_TX,
519 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
520 cl_id, q->cid, func_id,
521 bnx2x_vf_sp(bp, vf, vlan_rdata),
522 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
523 BNX2X_FILTER_VLAN_PENDING,
525 BNX2X_OBJ_TYPE_RX_TX,
529 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
530 q->cid, func_id, func_id,
531 bnx2x_vf_sp(bp, vf, mcast_rdata),
532 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
533 BNX2X_FILTER_MCAST_PENDING,
535 BNX2X_OBJ_TYPE_RX_TX);
538 bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
540 bnx2x_vf_sp(bp, vf, rss_rdata),
541 bnx2x_vf_sp_map(bp, vf, rss_rdata),
542 BNX2X_FILTER_RSS_CONF_PENDING,
544 BNX2X_OBJ_TYPE_RX_TX);
546 vf->leading_rss = cl_id;
547 q->is_leading = true;
550 /* ask the pf to open a queue for the vf */
551 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
554 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
555 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
556 u8 fp_idx = fp->index;
557 u16 tpa_agg_size = 0, flags = 0;
560 /* clear mailbox and prep first tlv */
561 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
563 /* select tpa mode to request */
564 if (!fp->disable_tpa) {
565 flags |= VFPF_QUEUE_FLG_TPA;
566 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
567 if (fp->mode == TPA_MODE_GRO)
568 flags |= VFPF_QUEUE_FLG_TPA_GRO;
569 tpa_agg_size = TPA_AGG_SIZE;
573 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
575 /* calculate queue flags */
576 flags |= VFPF_QUEUE_FLG_STATS;
577 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
578 flags |= VFPF_QUEUE_FLG_VLAN;
579 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
582 req->vf_qid = fp_idx;
583 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
586 req->rxq.rcq_addr = fp->rx_comp_mapping;
587 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
588 req->rxq.rxq_addr = fp->rx_desc_mapping;
589 req->rxq.sge_addr = fp->rx_sge_mapping;
590 req->rxq.vf_sb = fp_idx;
591 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
592 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
593 req->rxq.mtu = bp->dev->mtu;
594 req->rxq.buf_sz = fp->rx_buf_size;
595 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
596 req->rxq.tpa_agg_sz = tpa_agg_size;
597 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
598 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
599 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
600 req->rxq.flags = flags;
601 req->rxq.drop_flags = 0;
602 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
603 req->rxq.stat_id = -1; /* No stats at the moment */
606 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
607 req->txq.vf_sb = fp_idx;
608 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
609 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
610 req->txq.flags = flags;
611 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
613 /* add list termination tlv */
614 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
615 sizeof(struct channel_list_end_tlv));
617 /* output tlvs list */
618 bnx2x_dp_tlv_list(bp, req);
620 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
622 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
625 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
626 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
627 fp_idx, resp->hdr.status);
631 bnx2x_vfpf_finalize(bp, &req->first_tlv);
636 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
638 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
639 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
642 /* clear mailbox and prep first tlv */
643 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
648 /* add list termination tlv */
649 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
650 sizeof(struct channel_list_end_tlv));
652 /* output tlvs list */
653 bnx2x_dp_tlv_list(bp, req);
655 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
658 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
663 /* PF failed the transaction */
664 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
665 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
671 bnx2x_vfpf_finalize(bp, &req->first_tlv);
675 /* request pf to add a mac for the vf */
676 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
678 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
679 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
680 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
683 /* clear mailbox and prep first tlv */
684 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
687 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
688 req->vf_qid = vf_qid;
689 req->n_mac_vlan_filters = 1;
691 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
693 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
695 /* sample bulletin board for new mac */
696 bnx2x_sample_bulletin(bp);
698 /* copy mac from device to request */
699 memcpy(req->filters[0].mac, addr, ETH_ALEN);
701 /* add list termination tlv */
702 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
703 sizeof(struct channel_list_end_tlv));
705 /* output tlvs list */
706 bnx2x_dp_tlv_list(bp, req);
708 /* send message to pf */
709 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
711 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
715 /* failure may mean PF was configured with a new mac for us */
716 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
718 "vfpf SET MAC failed. Check bulletin board for new posts\n");
720 /* copy mac from bulletin to device */
721 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
723 /* check if bulletin board was updated */
724 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
725 /* copy mac from device to request */
726 memcpy(req->filters[0].mac, bp->dev->dev_addr,
729 /* send message to pf */
730 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
731 bp->vf2pf_mbox_mapping);
733 /* no new info in bulletin */
738 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
739 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
743 bnx2x_vfpf_finalize(bp, &req->first_tlv);
748 /* request pf to config rss table for vf queues*/
749 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
750 struct bnx2x_config_rss_params *params)
752 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
753 struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
756 /* clear mailbox and prep first tlv */
757 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
760 /* add list termination tlv */
761 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
762 sizeof(struct channel_list_end_tlv));
764 memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
765 memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
766 req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
767 req->rss_key_size = T_ETH_RSS_KEY;
768 req->rss_result_mask = params->rss_result_mask;
770 /* flags handled individually for backward/forward compatability */
771 if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
772 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
773 if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
774 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
775 if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
776 req->rss_flags |= VFPF_RSS_SET_SRCH;
777 if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
778 req->rss_flags |= VFPF_RSS_IPV4;
779 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
780 req->rss_flags |= VFPF_RSS_IPV4_TCP;
781 if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
782 req->rss_flags |= VFPF_RSS_IPV4_UDP;
783 if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
784 req->rss_flags |= VFPF_RSS_IPV6;
785 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
786 req->rss_flags |= VFPF_RSS_IPV6_TCP;
787 if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
788 req->rss_flags |= VFPF_RSS_IPV6_UDP;
790 DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
792 /* output tlvs list */
793 bnx2x_dp_tlv_list(bp, req);
795 /* send message to pf */
796 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
798 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
802 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
803 BNX2X_ERR("failed to send rss message to PF over Vf PF channel %d\n",
808 bnx2x_vfpf_finalize(bp, &req->first_tlv);
813 int bnx2x_vfpf_set_mcast(struct net_device *dev)
815 struct bnx2x *bp = netdev_priv(dev);
816 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
817 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
819 struct netdev_hw_addr *ha;
821 if (bp->state != BNX2X_STATE_OPEN) {
822 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
826 /* clear mailbox and prep first tlv */
827 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
830 /* Get Rx mode requested */
831 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
833 netdev_for_each_mc_addr(ha, dev) {
834 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
836 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
840 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
843 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
845 "VF supports not more than %d multicast MAC addresses\n",
846 PFVF_MAX_MULTICAST_PER_VF);
850 req->n_multicast = i;
851 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
854 /* add list termination tlv */
855 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
856 sizeof(struct channel_list_end_tlv));
858 /* output tlvs list */
859 bnx2x_dp_tlv_list(bp, req);
860 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
862 BNX2X_ERR("Sending a message failed: %d\n", rc);
866 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
867 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
872 bnx2x_vfpf_finalize(bp, &req->first_tlv);
877 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
879 int mode = bp->rx_mode;
880 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
881 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
884 /* clear mailbox and prep first tlv */
885 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
888 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
891 case BNX2X_RX_MODE_NONE: /* no Rx */
892 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
894 case BNX2X_RX_MODE_NORMAL:
895 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
896 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
897 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
899 case BNX2X_RX_MODE_ALLMULTI:
900 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
901 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
902 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
904 case BNX2X_RX_MODE_PROMISC:
905 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
906 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
907 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
910 BNX2X_ERR("BAD rx mode (%d)\n", mode);
915 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
918 /* add list termination tlv */
919 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
920 sizeof(struct channel_list_end_tlv));
922 /* output tlvs list */
923 bnx2x_dp_tlv_list(bp, req);
925 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
927 BNX2X_ERR("Sending a message failed: %d\n", rc);
929 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
930 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
934 bnx2x_vfpf_finalize(bp, &req->first_tlv);
939 /* General service functions */
940 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
942 u32 addr = BAR_CSTRORM_INTMEM +
943 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
945 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
948 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
950 u32 addr = BAR_CSTRORM_INTMEM +
951 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
953 REG_WR8(bp, addr, 1);
956 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
961 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
964 /* enable vf_pf mailbox (aka vf-pf-channel) */
965 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
967 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
969 /* enable the mailbox in the FW */
970 storm_memset_vf_mbx_ack(bp, abs_vfid);
971 storm_memset_vf_mbx_valid(bp, abs_vfid);
973 /* enable the VF access to the mailbox */
974 bnx2x_vf_enable_access(bp, abs_vfid);
977 /* this works only on !E1h */
978 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
979 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
980 u32 vf_addr_lo, u32 len32)
982 struct dmae_command dmae;
984 if (CHIP_IS_E1x(bp)) {
985 BNX2X_ERR("Chip revision does not support VFs\n");
989 if (!bp->dmae_ready) {
990 BNX2X_ERR("DMAE is not ready, can not copy\n");
994 /* set opcode and fixed command fields */
995 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
998 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
999 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1000 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1002 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1004 dmae.src_addr_lo = vf_addr_lo;
1005 dmae.src_addr_hi = vf_addr_hi;
1006 dmae.dst_addr_lo = U64_LO(pf_addr);
1007 dmae.dst_addr_hi = U64_HI(pf_addr);
1009 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1010 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1011 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1013 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1015 dmae.src_addr_lo = U64_LO(pf_addr);
1016 dmae.src_addr_hi = U64_HI(pf_addr);
1017 dmae.dst_addr_lo = vf_addr_lo;
1018 dmae.dst_addr_hi = vf_addr_hi;
1022 /* issue the command and wait for completion */
1023 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1026 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1027 struct bnx2x_virtf *vf)
1029 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1032 /* prepare response */
1033 type = mbx->first_tlv.tl.type;
1034 length = type == CHANNEL_TLV_ACQUIRE ?
1035 sizeof(struct pfvf_acquire_resp_tlv) :
1036 sizeof(struct pfvf_general_resp_tlv);
1037 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1038 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1039 sizeof(struct channel_list_end_tlv));
1042 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1043 struct bnx2x_virtf *vf)
1045 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1046 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1051 bnx2x_dp_tlv_list(bp, resp);
1052 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1053 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1055 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
1058 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1059 mbx->first_tlv.resp_msg_offset;
1060 pf_addr = mbx->msg_mapping +
1061 offsetof(struct bnx2x_vf_mbx_msg, resp);
1063 /* Copy the response buffer. The first u64 is written afterwards, as
1064 * the vf is sensitive to the header being written
1066 vf_addr += sizeof(u64);
1067 pf_addr += sizeof(u64);
1068 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1071 (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1073 BNX2X_ERR("Failed to copy response body to VF %d\n",
1077 vf_addr -= sizeof(u64);
1078 pf_addr -= sizeof(u64);
1081 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1084 /* initiate dmae to send the response */
1085 mbx->flags &= ~VF_MSG_INPROCESS;
1087 /* copy the response header including status-done field,
1088 * must be last dmae, must be after FW is acked
1090 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1095 /* unlock channel mutex */
1096 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1099 BNX2X_ERR("Failed to copy response status to VF %d\n",
1106 bnx2x_vf_release(bp, vf, false); /* non blocking */
1109 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1110 struct bnx2x_virtf *vf)
1112 bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1113 bnx2x_vf_mbx_resp_send_msg(bp, vf);
1116 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1117 struct bnx2x_virtf *vf,
1121 struct vfpf_port_phys_id_resp_tlv *port_id;
1123 if (!(bp->flags & HAS_PHYS_PORT_ID))
1126 bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1127 sizeof(struct vfpf_port_phys_id_resp_tlv));
1129 port_id = (struct vfpf_port_phys_id_resp_tlv *)
1130 (((u8 *)buffer) + *offset);
1131 memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1133 /* Offset should continue representing the offset to the tail
1134 * of TLV data (outside this function scope)
1136 *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1139 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1140 struct bnx2x_vf_mbx *mbx, int vfop_status)
1143 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1144 struct pf_vf_resc *resc = &resp->resc;
1145 u8 status = bnx2x_pfvf_status_codes(vfop_status);
1148 memset(resp, 0, sizeof(*resp));
1150 /* fill in pfdev info */
1151 resp->pfdev_info.chip_num = bp->common.chip_id;
1152 resp->pfdev_info.db_size = bp->db_size;
1153 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1154 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1155 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
1156 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1157 sizeof(resp->pfdev_info.fw_ver));
1159 if (status == PFVF_STATUS_NO_RESOURCE ||
1160 status == PFVF_STATUS_SUCCESS) {
1161 /* set resources numbers, if status equals NO_RESOURCE these
1162 * are max possible numbers
1164 resc->num_rxqs = vf_rxq_count(vf) ? :
1165 bnx2x_vf_max_queue_cnt(bp, vf);
1166 resc->num_txqs = vf_txq_count(vf) ? :
1167 bnx2x_vf_max_queue_cnt(bp, vf);
1168 resc->num_sbs = vf_sb_count(vf);
1169 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1170 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
1171 resc->num_mc_filters = 0;
1173 if (status == PFVF_STATUS_SUCCESS) {
1174 /* fill in the allocated resources */
1175 struct pf_vf_bulletin_content *bulletin =
1176 BP_VF_BULLETIN(bp, vf->index);
1180 vfq_qzone_id(vf, vfq_get(vf, i));
1182 for_each_vf_sb(vf, i) {
1183 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1184 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1187 /* if a mac has been set for this vf, supply it */
1188 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1189 memcpy(resc->current_mac_addr, bulletin->mac,
1195 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"
1196 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1198 resp->pfdev_info.chip_num,
1199 resp->pfdev_info.db_size,
1200 resp->pfdev_info.indices_per_sb,
1201 resp->pfdev_info.pf_cap,
1205 resc->num_mac_filters,
1206 resc->num_vlan_filters,
1207 resc->num_mc_filters,
1208 resp->pfdev_info.fw_ver);
1210 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1211 for (i = 0; i < vf_rxq_count(vf); i++)
1212 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1213 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1214 for (i = 0; i < vf_sb_count(vf); i++)
1215 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1216 resc->hw_sbs[i].hw_sb_id,
1217 resc->hw_sbs[i].sb_qid);
1218 DP_CONT(BNX2X_MSG_IOV, "]\n");
1220 /* prepare response */
1221 length = sizeof(struct pfvf_acquire_resp_tlv);
1222 bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1224 /* Handle possible VF requests for physical port identifiers.
1225 * 'length' should continue to indicate the offset of the first empty
1226 * place in the buffer (i.e., where next TLV should be inserted)
1228 if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1229 CHANNEL_TLV_PHYS_PORT_ID))
1230 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1232 bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1233 sizeof(struct channel_list_end_tlv));
1235 /* send the response */
1236 vf->op_rc = vfop_status;
1237 bnx2x_vf_mbx_resp_send_msg(bp, vf);
1240 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1241 struct bnx2x_vf_mbx *mbx)
1244 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1246 /* log vfdef info */
1248 "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",
1249 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1250 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1251 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1252 acquire->resc_request.num_vlan_filters,
1253 acquire->resc_request.num_mc_filters);
1255 /* acquire the resources */
1256 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1258 /* store address of vf's bulletin board */
1259 vf->bulletin_map = acquire->bulletin_addr;
1262 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1265 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1266 struct bnx2x_vf_mbx *mbx)
1268 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1270 /* record ghost addresses from vf message */
1271 vf->spq_map = init->spq_addr;
1272 vf->fw_stat_map = init->stats_addr;
1273 vf->stats_stride = init->stats_stride;
1274 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1276 /* set VF multiqueue statistics collection mode */
1277 if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1278 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1281 bnx2x_vf_mbx_resp(bp, vf);
1284 /* convert MBX queue-flags to standard SP queue-flags */
1285 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1286 unsigned long *sp_q_flags)
1288 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1289 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1290 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1291 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1292 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1293 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1294 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1295 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1296 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1297 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1298 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1299 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1300 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1301 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1302 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1303 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1304 if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1305 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1307 /* outer vlan removal is set according to PF's multi function mode */
1309 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1312 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1313 struct bnx2x_vf_mbx *mbx)
1315 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1316 struct bnx2x_vfop_cmd cmd = {
1317 .done = bnx2x_vf_mbx_resp,
1322 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1323 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1324 setup_q->vf_qid, vf_rxq_count(vf));
1325 vf->op_rc = -EINVAL;
1329 /* tx queues must be setup alongside rx queues thus if the rx queue
1330 * is not marked as valid there's nothing to do.
1332 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1333 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1334 unsigned long q_type = 0;
1336 struct bnx2x_queue_init_params *init_p;
1337 struct bnx2x_queue_setup_params *setup_p;
1339 if (bnx2x_vfq_is_leading(q))
1340 bnx2x_leading_vfq_init(bp, vf, q);
1342 /* re-init the VF operation context */
1343 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1344 setup_p = &vf->op_params.qctor.prep_qsetup;
1345 init_p = &vf->op_params.qctor.qstate.params.init;
1347 /* activate immediately */
1348 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1350 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1351 struct bnx2x_txq_setup_params *txq_params =
1352 &setup_p->txq_params;
1354 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1356 /* save sb resource index */
1357 q->sb_idx = setup_q->txq.vf_sb;
1360 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1361 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1363 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1366 /* tx setup - flags */
1367 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1370 /* tx setup - general, nothing */
1373 txq_params->dscr_map = setup_q->txq.txq_addr;
1374 txq_params->sb_cq_index = setup_q->txq.sb_index;
1375 txq_params->traffic_type = setup_q->txq.traffic_type;
1377 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1378 q->index, q->sb_idx);
1381 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1382 struct bnx2x_rxq_setup_params *rxq_params =
1383 &setup_p->rxq_params;
1385 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1387 /* Note: there is no support for different SBs
1390 q->sb_idx = setup_q->rxq.vf_sb;
1393 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1394 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1395 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1398 /* rx setup - flags */
1399 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1402 /* rx setup - general */
1403 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1406 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1407 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1408 rxq_params->sge_map = setup_q->rxq.sge_addr;
1409 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1410 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1411 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1412 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1413 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1414 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1415 rxq_params->cache_line_log =
1416 setup_q->rxq.cache_line_log;
1417 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1419 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1420 q->index, q->sb_idx);
1422 /* complete the preparations */
1423 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1425 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1431 bnx2x_vf_mbx_resp(bp, vf);
1434 enum bnx2x_vfop_filters_state {
1435 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1436 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1437 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1438 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1439 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1442 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1443 struct bnx2x_virtf *vf,
1444 struct vfpf_set_q_filters_tlv *tlv,
1445 struct bnx2x_vfop_filters **pfl,
1449 struct bnx2x_vfop_filters *fl = NULL;
1452 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1453 sizeof(struct bnx2x_vfop_filters);
1455 fl = kzalloc(fsz, GFP_KERNEL);
1459 INIT_LIST_HEAD(&fl->head);
1461 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1462 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1464 if ((msg_filter->flags & type_flag) != type_flag)
1466 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1467 fl->filters[j].mac = msg_filter->mac;
1468 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1470 fl->filters[j].vid = msg_filter->vlan_tag;
1471 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1473 fl->filters[j].add =
1474 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1476 list_add_tail(&fl->filters[j++].link, &fl->head);
1478 if (list_empty(&fl->head))
1486 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1487 struct vfpf_q_mac_vlan_filter *filter)
1489 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1490 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1491 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1492 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1493 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1494 DP_CONT(msglvl, "\n");
1497 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1498 struct vfpf_set_q_filters_tlv *filters)
1502 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1503 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1504 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1505 &filters->filters[i]);
1507 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1508 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1510 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1511 for (i = 0; i < filters->n_multicast; i++)
1512 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1515 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1516 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1518 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1522 struct vfpf_set_q_filters_tlv *msg =
1523 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1525 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1526 enum bnx2x_vfop_filters_state state = vfop->state;
1528 struct bnx2x_vfop_cmd cmd = {
1529 .done = bnx2x_vfop_mbx_qfilters,
1533 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1539 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1541 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1543 /* check for any vlan/mac changes */
1544 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1545 /* build mac list */
1546 struct bnx2x_vfop_filters *fl = NULL;
1548 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1555 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1567 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1569 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1571 /* check for any vlan/mac changes */
1572 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1573 /* build vlan list */
1574 struct bnx2x_vfop_filters *fl = NULL;
1576 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1583 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1595 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1597 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1599 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1600 unsigned long accept = 0;
1602 /* covert VF-PF if mask to bnx2x accept flags */
1603 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1604 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1607 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1608 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1610 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1611 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1613 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1614 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1616 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1617 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1619 /* A packet arriving the vf's mac should be accepted
1622 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1625 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1626 msg->vf_qid, accept);
1635 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1637 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1639 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1641 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1642 msg->n_multicast, false);
1651 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1652 bnx2x_vfop_end(bp, vf, vfop);
1655 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1656 vf->abs_vfid, msg->vf_qid, vfop->rc);
1660 bnx2x_vfop_default(state);
1664 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1665 struct bnx2x_virtf *vf,
1666 struct bnx2x_vfop_cmd *cmd)
1668 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1670 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1671 bnx2x_vfop_mbx_qfilters, cmd->done);
1672 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1678 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1679 struct bnx2x_virtf *vf,
1680 struct bnx2x_vf_mbx *mbx)
1682 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1683 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1684 struct bnx2x_vfop_cmd cmd = {
1685 .done = bnx2x_vf_mbx_resp,
1689 /* if a mac was already set for this VF via the set vf mac ndo, we only
1690 * accept mac configurations of that mac. Why accept them at all?
1691 * because PF may have been unable to configure the mac at the time
1692 * since queue was not set up.
1694 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1695 /* once a mac was set by ndo can only accept a single mac... */
1696 if (filters->n_mac_vlan_filters > 1) {
1697 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1703 /* ...and only the mac set by the ndo */
1704 if (filters->n_mac_vlan_filters == 1 &&
1705 memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1706 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1715 if (filters->vf_qid > vf_rxq_count(vf))
1718 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1722 /* print q_filter message */
1723 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1725 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1731 bnx2x_vf_mbx_resp(bp, vf);
1734 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1735 struct bnx2x_vf_mbx *mbx)
1737 int qid = mbx->msg->req.q_op.vf_qid;
1738 struct bnx2x_vfop_cmd cmd = {
1739 .done = bnx2x_vf_mbx_resp,
1743 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1746 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1748 bnx2x_vf_mbx_resp(bp, vf);
1751 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1752 struct bnx2x_vf_mbx *mbx)
1754 struct bnx2x_vfop_cmd cmd = {
1755 .done = bnx2x_vf_mbx_resp,
1759 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1761 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1763 bnx2x_vf_mbx_resp(bp, vf);
1766 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1767 struct bnx2x_vf_mbx *mbx)
1769 struct bnx2x_vfop_cmd cmd = {
1770 .done = bnx2x_vf_mbx_resp,
1774 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1776 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1778 bnx2x_vf_mbx_resp(bp, vf);
1781 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1782 struct bnx2x_vf_mbx *mbx)
1784 struct bnx2x_vfop_cmd cmd = {
1785 .done = bnx2x_vf_mbx_resp,
1788 struct bnx2x_config_rss_params *vf_op_params = &vf->op_params.rss;
1789 struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1791 if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1792 rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1793 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1795 vf->op_rc = -EINVAL;
1799 /* set vfop params according to rss tlv */
1800 memcpy(vf_op_params->ind_table, rss_tlv->ind_table,
1801 T_ETH_INDIRECTION_TABLE_SIZE);
1802 memcpy(vf_op_params->rss_key, rss_tlv->rss_key,
1803 sizeof(rss_tlv->rss_key));
1804 vf_op_params->rss_obj = &vf->rss_conf_obj;
1805 vf_op_params->rss_result_mask = rss_tlv->rss_result_mask;
1807 /* flags handled individually for backward/forward compatability */
1808 if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1809 __set_bit(BNX2X_RSS_MODE_DISABLED, &vf_op_params->rss_flags);
1810 if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1811 __set_bit(BNX2X_RSS_MODE_REGULAR, &vf_op_params->rss_flags);
1812 if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1813 __set_bit(BNX2X_RSS_SET_SRCH, &vf_op_params->rss_flags);
1814 if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1815 __set_bit(BNX2X_RSS_IPV4, &vf_op_params->rss_flags);
1816 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1817 __set_bit(BNX2X_RSS_IPV4_TCP, &vf_op_params->rss_flags);
1818 if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1819 __set_bit(BNX2X_RSS_IPV4_UDP, &vf_op_params->rss_flags);
1820 if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1821 __set_bit(BNX2X_RSS_IPV6, &vf_op_params->rss_flags);
1822 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1823 __set_bit(BNX2X_RSS_IPV6_TCP, &vf_op_params->rss_flags);
1824 if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1825 __set_bit(BNX2X_RSS_IPV6_UDP, &vf_op_params->rss_flags);
1827 if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1828 rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1829 (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1830 rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1831 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1832 vf->op_rc = -EINVAL;
1836 vf->op_rc = bnx2x_vfop_rss_cmd(bp, vf, &cmd);
1840 bnx2x_vf_mbx_resp(bp, vf);
1843 /* dispatch request */
1844 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1845 struct bnx2x_vf_mbx *mbx)
1849 /* check if tlv type is known */
1850 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1851 /* Lock the per vf op mutex and note the locker's identity.
1852 * The unlock will take place in mbx response.
1854 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1856 /* switch on the opcode */
1857 switch (mbx->first_tlv.tl.type) {
1858 case CHANNEL_TLV_ACQUIRE:
1859 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1861 case CHANNEL_TLV_INIT:
1862 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1864 case CHANNEL_TLV_SETUP_Q:
1865 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1867 case CHANNEL_TLV_SET_Q_FILTERS:
1868 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1870 case CHANNEL_TLV_TEARDOWN_Q:
1871 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1873 case CHANNEL_TLV_CLOSE:
1874 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1876 case CHANNEL_TLV_RELEASE:
1877 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1879 case CHANNEL_TLV_UPDATE_RSS:
1880 bnx2x_vf_mbx_update_rss(bp, vf, mbx);
1885 /* unknown TLV - this may belong to a VF driver from the future
1886 * - a version written after this PF driver was written, which
1887 * supports features unknown as of yet. Too bad since we don't
1888 * support them. Or this may be because someone wrote a crappy
1889 * VF driver and is sending garbage over the channel.
1891 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
1892 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
1894 for (i = 0; i < 20; i++)
1895 DP_CONT(BNX2X_MSG_IOV, "%x ",
1896 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1899 /* can we respond to VF (do we have an address for it?) */
1900 if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
1901 /* mbx_resp uses the op_rc of the VF */
1902 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1904 /* notify the VF that we do not support this request */
1905 bnx2x_vf_mbx_resp(bp, vf);
1907 /* can't send a response since this VF is unknown to us
1908 * just ack the FW to release the mailbox and unlock
1911 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1912 /* Firmware ack should be written before unlocking channel */
1914 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1918 /* handle new vf-pf message */
1919 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1921 struct bnx2x_virtf *vf;
1922 struct bnx2x_vf_mbx *mbx;
1927 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1928 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1929 /* Sanity checks consider removing later */
1931 /* check if the vf_id is valid */
1932 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1933 BNX2X_NR_VIRTFN(bp)) {
1934 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1935 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1938 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1939 mbx = BP_VF_MBX(bp, vf_idx);
1941 /* verify an event is not currently being processed -
1942 * debug failsafe only
1944 if (mbx->flags & VF_MSG_INPROCESS) {
1945 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1949 vf = BP_VF(bp, vf_idx);
1951 /* save the VF message address */
1952 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1953 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1954 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1955 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1957 /* dmae to get the VF request */
1958 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1959 mbx->vf_addr_hi, mbx->vf_addr_lo,
1960 sizeof(union vfpf_tlvs)/4);
1962 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1966 /* process the VF message header */
1967 mbx->first_tlv = mbx->msg->req.first_tlv;
1969 /* Clean response buffer to refrain from falsely seeing chains */
1970 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
1972 /* dispatch the request (will prepare the response) */
1973 bnx2x_vf_mbx_request(bp, vf, mbx);
1977 bnx2x_vf_release(bp, vf, false); /* non blocking */
1982 /* propagate local bulletin board to vf */
1983 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1985 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1986 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1987 vf * BULLETIN_CONTENT_SIZE;
1988 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1991 /* can only update vf after init took place */
1992 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1993 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1996 /* increment bulletin board version and compute crc */
1997 bulletin->version++;
1998 bulletin->length = BULLETIN_CONTENT_SIZE;
1999 bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
2001 /* propagate bulletin board via dmae to vm memory */
2002 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2003 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2004 U64_LO(vf_addr), bulletin->length / 4);