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 /* list the types and lengths of the tlvs on the buffer */
64 void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
67 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
69 while (tlv->type != CHANNEL_TLV_LIST_END) {
71 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
72 tlv->type, tlv->length);
74 /* advance to next tlv */
75 tlvs_list += tlv->length;
77 /* cast general tlv list pointer to channel tlv header*/
78 tlv = (struct channel_tlv *)tlvs_list;
82 /* break condition for this loop */
83 if (i > MAX_TLVS_IN_LIST) {
84 WARN(true, "corrupt tlvs");
90 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
91 tlv->type, tlv->length);
94 /* test whether we support a tlv type */
95 bool bnx2x_tlv_supported(u16 tlvtype)
97 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
100 static inline int bnx2x_pfvf_status_codes(int rc)
104 return PFVF_STATUS_SUCCESS;
106 return PFVF_STATUS_NO_RESOURCE;
108 return PFVF_STATUS_FAILURE;
112 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
114 struct cstorm_vf_zone_data __iomem *zone_data =
115 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
116 int tout = 100, interval = 100; /* wait for 10 seconds */
119 BNX2X_ERR("done was non zero before message to pf was sent\n");
124 /* if PF indicated channel is down avoid sending message. Return success
125 * so calling flow can continue
127 bnx2x_sample_bulletin(bp);
128 if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
129 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
130 *done = PFVF_STATUS_SUCCESS;
134 /* Write message address */
135 writel(U64_LO(msg_mapping),
136 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
137 writel(U64_HI(msg_mapping),
138 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
140 /* make sure the address is written before FW accesses it */
143 /* Trigger the PF FW */
144 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
146 /* Wait for PF to complete */
147 while ((tout >= 0) && (!*done)) {
151 /* progress indicator - HV can take its own sweet time in
154 DP_CONT(BNX2X_MSG_IOV, ".");
158 BNX2X_ERR("PF response has timed out\n");
161 DP(BNX2X_MSG_SP, "Got a response from PF\n");
165 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
168 int tout = 10, interval = 100; /* Wait for 1 sec */
171 /* pxp traps vf read of doorbells and returns me reg value */
172 me_reg = readl(bp->doorbells);
173 if (GOOD_ME_REG(me_reg))
178 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
180 } while (tout-- > 0);
182 if (!GOOD_ME_REG(me_reg)) {
183 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
187 BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
189 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
194 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
196 int rc = 0, attempts = 0;
197 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
198 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
200 bool resources_acquired = false;
202 /* clear mailbox and prep first tlv */
203 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
205 if (bnx2x_get_vf_id(bp, &vf_id)) {
210 req->vfdev_info.vf_id = vf_id;
211 req->vfdev_info.vf_os = 0;
213 req->resc_request.num_rxqs = rx_count;
214 req->resc_request.num_txqs = tx_count;
215 req->resc_request.num_sbs = bp->igu_sb_cnt;
216 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
217 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
219 /* pf 2 vf bulletin board address */
220 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
222 /* add list termination tlv */
223 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
224 sizeof(struct channel_list_end_tlv));
226 /* output tlvs list */
227 bnx2x_dp_tlv_list(bp, req);
229 while (!resources_acquired) {
230 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
232 /* send acquire request */
233 rc = bnx2x_send_msg2pf(bp,
235 bp->vf2pf_mbox_mapping);
241 /* copy acquire response from buffer to bp */
242 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
246 /* test whether the PF accepted our request. If not, humble
247 * the request and try again.
249 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
250 DP(BNX2X_MSG_SP, "resources acquired\n");
251 resources_acquired = true;
252 } else if (bp->acquire_resp.hdr.status ==
253 PFVF_STATUS_NO_RESOURCE &&
254 attempts < VF_ACQUIRE_THRESH) {
256 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
258 /* humble our request */
259 req->resc_request.num_txqs =
260 bp->acquire_resp.resc.num_txqs;
261 req->resc_request.num_rxqs =
262 bp->acquire_resp.resc.num_rxqs;
263 req->resc_request.num_sbs =
264 bp->acquire_resp.resc.num_sbs;
265 req->resc_request.num_mac_filters =
266 bp->acquire_resp.resc.num_mac_filters;
267 req->resc_request.num_vlan_filters =
268 bp->acquire_resp.resc.num_vlan_filters;
269 req->resc_request.num_mc_filters =
270 bp->acquire_resp.resc.num_mc_filters;
272 /* Clear response buffer */
273 memset(&bp->vf2pf_mbox->resp, 0,
274 sizeof(union pfvf_tlvs));
276 /* PF reports error */
277 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
278 bp->acquire_resp.hdr.status);
285 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
286 bp->link_params.chip_id = bp->common.chip_id;
287 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
288 bp->common.int_block = INT_BLOCK_IGU;
289 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
293 bp->common.flash_size = 0;
295 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
297 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
298 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
301 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
302 memcpy(bp->dev->dev_addr,
303 bp->acquire_resp.resc.current_mac_addr,
307 bnx2x_vfpf_finalize(bp, &req->first_tlv);
311 int bnx2x_vfpf_release(struct bnx2x *bp)
313 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
314 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
317 /* clear mailbox and prep first tlv */
318 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
320 if (bnx2x_get_vf_id(bp, &vf_id)) {
327 /* add list termination tlv */
328 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
329 sizeof(struct channel_list_end_tlv));
331 /* output tlvs list */
332 bnx2x_dp_tlv_list(bp, req);
334 /* send release request */
335 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
341 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
343 DP(BNX2X_MSG_SP, "vf released\n");
345 /* PF reports error */
346 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
352 bnx2x_vfpf_finalize(bp, &req->first_tlv);
357 /* Tell PF about SB addresses */
358 int bnx2x_vfpf_init(struct bnx2x *bp)
360 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
361 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
364 /* clear mailbox and prep first tlv */
365 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
368 for_each_eth_queue(bp, i)
369 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
372 /* statistics - requests only supports single queue for now */
373 req->stats_addr = bp->fw_stats_data_mapping +
374 offsetof(struct bnx2x_fw_stats_data, queue_stats);
376 /* add list termination tlv */
377 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
378 sizeof(struct channel_list_end_tlv));
380 /* output tlvs list */
381 bnx2x_dp_tlv_list(bp, req);
383 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
387 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
388 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
394 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
396 bnx2x_vfpf_finalize(bp, &req->first_tlv);
401 /* CLOSE VF - opposite to INIT_VF */
402 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
404 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
405 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
409 /* If we haven't got a valid VF id, there is no sense to
410 * continue with sending messages
412 if (bnx2x_get_vf_id(bp, &vf_id))
415 /* Close the queues */
416 for_each_queue(bp, i)
417 bnx2x_vfpf_teardown_queue(bp, i);
420 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
422 /* clear mailbox and prep first tlv */
423 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
427 /* add list termination tlv */
428 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
429 sizeof(struct channel_list_end_tlv));
431 /* output tlvs list */
432 bnx2x_dp_tlv_list(bp, req);
434 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
437 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
439 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
440 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
443 bnx2x_vfpf_finalize(bp, &req->first_tlv);
446 /* Disable HW interrupts, NAPI */
447 bnx2x_netif_stop(bp, 0);
448 /* Delete all NAPI objects */
449 bnx2x_del_all_napi(bp);
455 /* ask the pf to open a queue for the vf */
456 int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
458 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
459 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
460 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
461 u16 tpa_agg_size = 0, flags = 0;
464 /* clear mailbox and prep first tlv */
465 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
467 /* select tpa mode to request */
468 if (!fp->disable_tpa) {
469 flags |= VFPF_QUEUE_FLG_TPA;
470 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
471 if (fp->mode == TPA_MODE_GRO)
472 flags |= VFPF_QUEUE_FLG_TPA_GRO;
473 tpa_agg_size = TPA_AGG_SIZE;
476 /* calculate queue flags */
477 flags |= VFPF_QUEUE_FLG_STATS;
478 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
479 flags |= VFPF_QUEUE_FLG_VLAN;
480 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
483 req->vf_qid = fp_idx;
484 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
487 req->rxq.rcq_addr = fp->rx_comp_mapping;
488 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
489 req->rxq.rxq_addr = fp->rx_desc_mapping;
490 req->rxq.sge_addr = fp->rx_sge_mapping;
491 req->rxq.vf_sb = fp_idx;
492 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
493 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
494 req->rxq.mtu = bp->dev->mtu;
495 req->rxq.buf_sz = fp->rx_buf_size;
496 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
497 req->rxq.tpa_agg_sz = tpa_agg_size;
498 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
499 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
500 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
501 req->rxq.flags = flags;
502 req->rxq.drop_flags = 0;
503 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
504 req->rxq.stat_id = -1; /* No stats at the moment */
507 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
508 req->txq.vf_sb = fp_idx;
509 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
510 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
511 req->txq.flags = flags;
512 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
514 /* add list termination tlv */
515 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
516 sizeof(struct channel_list_end_tlv));
518 /* output tlvs list */
519 bnx2x_dp_tlv_list(bp, req);
521 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
523 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
526 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
527 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
528 fp_idx, resp->hdr.status);
532 bnx2x_vfpf_finalize(bp, &req->first_tlv);
537 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
539 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
540 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
543 /* clear mailbox and prep first tlv */
544 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
549 /* add list termination tlv */
550 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
551 sizeof(struct channel_list_end_tlv));
553 /* output tlvs list */
554 bnx2x_dp_tlv_list(bp, req);
556 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
559 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
564 /* PF failed the transaction */
565 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
566 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
572 bnx2x_vfpf_finalize(bp, &req->first_tlv);
576 /* request pf to add a mac for the vf */
577 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
579 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
580 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
581 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
584 /* clear mailbox and prep first tlv */
585 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
588 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
589 req->vf_qid = vf_qid;
590 req->n_mac_vlan_filters = 1;
592 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
594 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
596 /* sample bulletin board for new mac */
597 bnx2x_sample_bulletin(bp);
599 /* copy mac from device to request */
600 memcpy(req->filters[0].mac, addr, ETH_ALEN);
602 /* add list termination tlv */
603 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
604 sizeof(struct channel_list_end_tlv));
606 /* output tlvs list */
607 bnx2x_dp_tlv_list(bp, req);
609 /* send message to pf */
610 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
612 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
616 /* failure may mean PF was configured with a new mac for us */
617 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
619 "vfpf SET MAC failed. Check bulletin board for new posts\n");
621 /* copy mac from bulletin to device */
622 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
624 /* check if bulletin board was updated */
625 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
626 /* copy mac from device to request */
627 memcpy(req->filters[0].mac, bp->dev->dev_addr,
630 /* send message to pf */
631 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
632 bp->vf2pf_mbox_mapping);
634 /* no new info in bulletin */
639 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
640 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
644 bnx2x_vfpf_finalize(bp, &req->first_tlv);
649 int bnx2x_vfpf_set_mcast(struct net_device *dev)
651 struct bnx2x *bp = netdev_priv(dev);
652 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
653 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
655 struct netdev_hw_addr *ha;
657 if (bp->state != BNX2X_STATE_OPEN) {
658 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
662 /* clear mailbox and prep first tlv */
663 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
666 /* Get Rx mode requested */
667 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
669 netdev_for_each_mc_addr(ha, dev) {
670 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
672 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
676 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
679 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
681 "VF supports not more than %d multicast MAC addresses\n",
682 PFVF_MAX_MULTICAST_PER_VF);
686 req->n_multicast = i;
687 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
690 /* add list termination tlv */
691 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
692 sizeof(struct channel_list_end_tlv));
694 /* output tlvs list */
695 bnx2x_dp_tlv_list(bp, req);
696 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
698 BNX2X_ERR("Sending a message failed: %d\n", rc);
702 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
703 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
708 bnx2x_vfpf_finalize(bp, &req->first_tlv);
713 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
715 int mode = bp->rx_mode;
716 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
717 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
720 /* clear mailbox and prep first tlv */
721 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
724 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
727 case BNX2X_RX_MODE_NONE: /* no Rx */
728 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
730 case BNX2X_RX_MODE_NORMAL:
731 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
732 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
733 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
735 case BNX2X_RX_MODE_ALLMULTI:
736 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
737 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
738 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
740 case BNX2X_RX_MODE_PROMISC:
741 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
742 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
743 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
746 BNX2X_ERR("BAD rx mode (%d)\n", mode);
751 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
754 /* add list termination tlv */
755 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
756 sizeof(struct channel_list_end_tlv));
758 /* output tlvs list */
759 bnx2x_dp_tlv_list(bp, req);
761 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
763 BNX2X_ERR("Sending a message failed: %d\n", rc);
765 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
766 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
770 bnx2x_vfpf_finalize(bp, &req->first_tlv);
775 /* General service functions */
776 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
778 u32 addr = BAR_CSTRORM_INTMEM +
779 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
781 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
784 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
786 u32 addr = BAR_CSTRORM_INTMEM +
787 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
789 REG_WR8(bp, addr, 1);
792 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
797 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
800 /* enable vf_pf mailbox (aka vf-pf-channel) */
801 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
803 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
805 /* enable the mailbox in the FW */
806 storm_memset_vf_mbx_ack(bp, abs_vfid);
807 storm_memset_vf_mbx_valid(bp, abs_vfid);
809 /* enable the VF access to the mailbox */
810 bnx2x_vf_enable_access(bp, abs_vfid);
813 /* this works only on !E1h */
814 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
815 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
816 u32 vf_addr_lo, u32 len32)
818 struct dmae_command dmae;
820 if (CHIP_IS_E1x(bp)) {
821 BNX2X_ERR("Chip revision does not support VFs\n");
825 if (!bp->dmae_ready) {
826 BNX2X_ERR("DMAE is not ready, can not copy\n");
830 /* set opcode and fixed command fields */
831 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
834 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
835 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
836 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
838 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
840 dmae.src_addr_lo = vf_addr_lo;
841 dmae.src_addr_hi = vf_addr_hi;
842 dmae.dst_addr_lo = U64_LO(pf_addr);
843 dmae.dst_addr_hi = U64_HI(pf_addr);
845 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
846 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
847 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
849 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
851 dmae.src_addr_lo = U64_LO(pf_addr);
852 dmae.src_addr_hi = U64_HI(pf_addr);
853 dmae.dst_addr_lo = vf_addr_lo;
854 dmae.dst_addr_hi = vf_addr_hi;
858 /* issue the command and wait for completion */
859 return bnx2x_issue_dmae_with_comp(bp, &dmae);
862 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
864 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
869 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
871 /* prepare response */
872 type = mbx->first_tlv.tl.type;
873 length = type == CHANNEL_TLV_ACQUIRE ?
874 sizeof(struct pfvf_acquire_resp_tlv) :
875 sizeof(struct pfvf_general_resp_tlv);
876 bnx2x_add_tlv(bp, resp, 0, type, length);
877 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
878 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
879 sizeof(struct channel_list_end_tlv));
880 bnx2x_dp_tlv_list(bp, resp);
881 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
882 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
885 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
886 mbx->first_tlv.resp_msg_offset;
887 pf_addr = mbx->msg_mapping +
888 offsetof(struct bnx2x_vf_mbx_msg, resp);
890 /* copy the response body, if there is one, before the header, as the vf
891 * is sensitive to the header being written
893 if (resp->hdr.tl.length > sizeof(u64)) {
894 length = resp->hdr.tl.length - sizeof(u64);
895 vf_addr += sizeof(u64);
896 pf_addr += sizeof(u64);
897 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
902 BNX2X_ERR("Failed to copy response body to VF %d\n",
906 vf_addr -= sizeof(u64);
907 pf_addr -= sizeof(u64);
911 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
914 /* initiate dmae to send the response */
915 mbx->flags &= ~VF_MSG_INPROCESS;
917 /* copy the response header including status-done field,
918 * must be last dmae, must be after FW is acked
920 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
925 /* unlock channel mutex */
926 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
929 BNX2X_ERR("Failed to copy response status to VF %d\n",
936 bnx2x_vf_release(bp, vf, false); /* non blocking */
939 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
940 struct bnx2x_vf_mbx *mbx, int vfop_status)
943 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
944 struct pf_vf_resc *resc = &resp->resc;
945 u8 status = bnx2x_pfvf_status_codes(vfop_status);
947 memset(resp, 0, sizeof(*resp));
949 /* fill in pfdev info */
950 resp->pfdev_info.chip_num = bp->common.chip_id;
951 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
952 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
953 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
954 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
955 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
956 sizeof(resp->pfdev_info.fw_ver));
958 if (status == PFVF_STATUS_NO_RESOURCE ||
959 status == PFVF_STATUS_SUCCESS) {
960 /* set resources numbers, if status equals NO_RESOURCE these
961 * are max possible numbers
963 resc->num_rxqs = vf_rxq_count(vf) ? :
964 bnx2x_vf_max_queue_cnt(bp, vf);
965 resc->num_txqs = vf_txq_count(vf) ? :
966 bnx2x_vf_max_queue_cnt(bp, vf);
967 resc->num_sbs = vf_sb_count(vf);
968 resc->num_mac_filters = vf_mac_rules_cnt(vf);
969 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
970 resc->num_mc_filters = 0;
972 if (status == PFVF_STATUS_SUCCESS) {
973 /* fill in the allocated resources */
974 struct pf_vf_bulletin_content *bulletin =
975 BP_VF_BULLETIN(bp, vf->index);
979 vfq_qzone_id(vf, vfq_get(vf, i));
981 for_each_vf_sb(vf, i) {
982 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
983 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
986 /* if a mac has been set for this vf, supply it */
987 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
988 memcpy(resc->current_mac_addr, bulletin->mac,
994 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"
995 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
997 resp->pfdev_info.chip_num,
998 resp->pfdev_info.db_size,
999 resp->pfdev_info.indices_per_sb,
1000 resp->pfdev_info.pf_cap,
1004 resc->num_mac_filters,
1005 resc->num_vlan_filters,
1006 resc->num_mc_filters,
1007 resp->pfdev_info.fw_ver);
1009 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1010 for (i = 0; i < vf_rxq_count(vf); i++)
1011 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1012 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1013 for (i = 0; i < vf_sb_count(vf); i++)
1014 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1015 resc->hw_sbs[i].hw_sb_id,
1016 resc->hw_sbs[i].sb_qid);
1017 DP_CONT(BNX2X_MSG_IOV, "]\n");
1019 /* send the response */
1020 vf->op_rc = vfop_status;
1021 bnx2x_vf_mbx_resp(bp, vf);
1024 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1025 struct bnx2x_vf_mbx *mbx)
1028 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1030 /* log vfdef info */
1032 "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",
1033 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1034 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1035 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1036 acquire->resc_request.num_vlan_filters,
1037 acquire->resc_request.num_mc_filters);
1039 /* acquire the resources */
1040 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1042 /* store address of vf's bulletin board */
1043 vf->bulletin_map = acquire->bulletin_addr;
1046 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1049 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1050 struct bnx2x_vf_mbx *mbx)
1052 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1054 /* record ghost addresses from vf message */
1055 vf->spq_map = init->spq_addr;
1056 vf->fw_stat_map = init->stats_addr;
1057 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1060 bnx2x_vf_mbx_resp(bp, vf);
1063 /* convert MBX queue-flags to standard SP queue-flags */
1064 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1065 unsigned long *sp_q_flags)
1067 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1068 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1069 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1070 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1071 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1072 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1073 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1074 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1075 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1076 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1077 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1078 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1079 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1080 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1081 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1082 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1084 /* outer vlan removal is set according to PF's multi function mode */
1086 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1089 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1090 struct bnx2x_vf_mbx *mbx)
1092 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1093 struct bnx2x_vfop_cmd cmd = {
1094 .done = bnx2x_vf_mbx_resp,
1099 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1100 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1101 setup_q->vf_qid, vf_rxq_count(vf));
1102 vf->op_rc = -EINVAL;
1106 /* tx queues must be setup alongside rx queues thus if the rx queue
1107 * is not marked as valid there's nothing to do.
1109 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1110 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1111 unsigned long q_type = 0;
1113 struct bnx2x_queue_init_params *init_p;
1114 struct bnx2x_queue_setup_params *setup_p;
1116 /* re-init the VF operation context */
1117 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1118 setup_p = &vf->op_params.qctor.prep_qsetup;
1119 init_p = &vf->op_params.qctor.qstate.params.init;
1121 /* activate immediately */
1122 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1124 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1125 struct bnx2x_txq_setup_params *txq_params =
1126 &setup_p->txq_params;
1128 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1130 /* save sb resource index */
1131 q->sb_idx = setup_q->txq.vf_sb;
1134 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1135 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1137 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1140 /* tx setup - flags */
1141 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1144 /* tx setup - general, nothing */
1147 txq_params->dscr_map = setup_q->txq.txq_addr;
1148 txq_params->sb_cq_index = setup_q->txq.sb_index;
1149 txq_params->traffic_type = setup_q->txq.traffic_type;
1151 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1152 q->index, q->sb_idx);
1155 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1156 struct bnx2x_rxq_setup_params *rxq_params =
1157 &setup_p->rxq_params;
1159 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1161 /* Note: there is no support for different SBs
1164 q->sb_idx = setup_q->rxq.vf_sb;
1167 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1168 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1169 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1172 /* rx setup - flags */
1173 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1176 /* rx setup - general */
1177 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1180 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1181 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1182 rxq_params->sge_map = setup_q->rxq.sge_addr;
1183 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1184 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1185 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1186 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1187 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1188 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1189 rxq_params->cache_line_log =
1190 setup_q->rxq.cache_line_log;
1191 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1193 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1194 q->index, q->sb_idx);
1196 /* complete the preparations */
1197 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1199 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1205 bnx2x_vf_mbx_resp(bp, vf);
1208 enum bnx2x_vfop_filters_state {
1209 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1210 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1211 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1212 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1213 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1216 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1217 struct bnx2x_virtf *vf,
1218 struct vfpf_set_q_filters_tlv *tlv,
1219 struct bnx2x_vfop_filters **pfl,
1223 struct bnx2x_vfop_filters *fl = NULL;
1226 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1227 sizeof(struct bnx2x_vfop_filters);
1229 fl = kzalloc(fsz, GFP_KERNEL);
1233 INIT_LIST_HEAD(&fl->head);
1235 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1236 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1238 if ((msg_filter->flags & type_flag) != type_flag)
1240 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1241 fl->filters[j].mac = msg_filter->mac;
1242 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1244 fl->filters[j].vid = msg_filter->vlan_tag;
1245 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1247 fl->filters[j].add =
1248 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1250 list_add_tail(&fl->filters[j++].link, &fl->head);
1252 if (list_empty(&fl->head))
1260 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1261 struct vfpf_q_mac_vlan_filter *filter)
1263 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1264 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1265 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1266 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1267 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1268 DP_CONT(msglvl, "\n");
1271 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1272 struct vfpf_set_q_filters_tlv *filters)
1276 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1277 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1278 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1279 &filters->filters[i]);
1281 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1282 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1284 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1285 for (i = 0; i < filters->n_multicast; i++)
1286 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1289 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1290 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1292 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1296 struct vfpf_set_q_filters_tlv *msg =
1297 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1299 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1300 enum bnx2x_vfop_filters_state state = vfop->state;
1302 struct bnx2x_vfop_cmd cmd = {
1303 .done = bnx2x_vfop_mbx_qfilters,
1307 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1313 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1315 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1317 /* check for any vlan/mac changes */
1318 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1319 /* build mac list */
1320 struct bnx2x_vfop_filters *fl = NULL;
1322 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1329 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1341 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1343 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1345 /* check for any vlan/mac changes */
1346 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1347 /* build vlan list */
1348 struct bnx2x_vfop_filters *fl = NULL;
1350 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1357 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1369 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1371 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1373 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1374 unsigned long accept = 0;
1376 /* covert VF-PF if mask to bnx2x accept flags */
1377 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1378 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1381 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1382 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1384 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1385 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1387 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1388 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1390 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1391 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1393 /* A packet arriving the vf's mac should be accepted
1396 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1399 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1400 msg->vf_qid, accept);
1409 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1411 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1413 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1415 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1416 msg->n_multicast, false);
1425 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1426 bnx2x_vfop_end(bp, vf, vfop);
1429 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1430 vf->abs_vfid, msg->vf_qid, vfop->rc);
1434 bnx2x_vfop_default(state);
1438 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1439 struct bnx2x_virtf *vf,
1440 struct bnx2x_vfop_cmd *cmd)
1442 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1444 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1445 bnx2x_vfop_mbx_qfilters, cmd->done);
1446 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1452 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1453 struct bnx2x_virtf *vf,
1454 struct bnx2x_vf_mbx *mbx)
1456 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1457 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1458 struct bnx2x_vfop_cmd cmd = {
1459 .done = bnx2x_vf_mbx_resp,
1463 /* if a mac was already set for this VF via the set vf mac ndo, we only
1464 * accept mac configurations of that mac. Why accept them at all?
1465 * because PF may have been unable to configure the mac at the time
1466 * since queue was not set up.
1468 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1469 /* once a mac was set by ndo can only accept a single mac... */
1470 if (filters->n_mac_vlan_filters > 1) {
1471 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1477 /* ...and only the mac set by the ndo */
1478 if (filters->n_mac_vlan_filters == 1 &&
1479 memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1480 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1489 if (filters->vf_qid > vf_rxq_count(vf))
1492 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1496 /* print q_filter message */
1497 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1499 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1505 bnx2x_vf_mbx_resp(bp, vf);
1508 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1509 struct bnx2x_vf_mbx *mbx)
1511 int qid = mbx->msg->req.q_op.vf_qid;
1512 struct bnx2x_vfop_cmd cmd = {
1513 .done = bnx2x_vf_mbx_resp,
1517 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1520 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1522 bnx2x_vf_mbx_resp(bp, vf);
1525 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1526 struct bnx2x_vf_mbx *mbx)
1528 struct bnx2x_vfop_cmd cmd = {
1529 .done = bnx2x_vf_mbx_resp,
1533 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1535 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1537 bnx2x_vf_mbx_resp(bp, vf);
1540 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1541 struct bnx2x_vf_mbx *mbx)
1543 struct bnx2x_vfop_cmd cmd = {
1544 .done = bnx2x_vf_mbx_resp,
1548 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1550 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1552 bnx2x_vf_mbx_resp(bp, vf);
1555 /* dispatch request */
1556 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1557 struct bnx2x_vf_mbx *mbx)
1561 /* check if tlv type is known */
1562 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1563 /* Lock the per vf op mutex and note the locker's identity.
1564 * The unlock will take place in mbx response.
1566 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1568 /* switch on the opcode */
1569 switch (mbx->first_tlv.tl.type) {
1570 case CHANNEL_TLV_ACQUIRE:
1571 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1573 case CHANNEL_TLV_INIT:
1574 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1576 case CHANNEL_TLV_SETUP_Q:
1577 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1579 case CHANNEL_TLV_SET_Q_FILTERS:
1580 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1582 case CHANNEL_TLV_TEARDOWN_Q:
1583 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1585 case CHANNEL_TLV_CLOSE:
1586 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1588 case CHANNEL_TLV_RELEASE:
1589 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1594 /* unknown TLV - this may belong to a VF driver from the future
1595 * - a version written after this PF driver was written, which
1596 * supports features unknown as of yet. Too bad since we don't
1597 * support them. Or this may be because someone wrote a crappy
1598 * VF driver and is sending garbage over the channel.
1600 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
1601 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
1603 for (i = 0; i < 20; i++)
1604 DP_CONT(BNX2X_MSG_IOV, "%x ",
1605 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1607 /* test whether we can respond to the VF (do we have an address
1610 if (vf->state == VF_ACQUIRED) {
1611 /* mbx_resp uses the op_rc of the VF */
1612 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1614 /* notify the VF that we do not support this request */
1615 bnx2x_vf_mbx_resp(bp, vf);
1617 /* can't send a response since this VF is unknown to us
1618 * just ack the FW to release the mailbox and unlock
1621 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1623 bnx2x_unlock_vf_pf_channel(bp, vf,
1624 mbx->first_tlv.tl.type);
1629 /* handle new vf-pf message */
1630 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1632 struct bnx2x_virtf *vf;
1633 struct bnx2x_vf_mbx *mbx;
1638 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1639 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1640 /* Sanity checks consider removing later */
1642 /* check if the vf_id is valid */
1643 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1644 BNX2X_NR_VIRTFN(bp)) {
1645 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1646 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1649 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1650 mbx = BP_VF_MBX(bp, vf_idx);
1652 /* verify an event is not currently being processed -
1653 * debug failsafe only
1655 if (mbx->flags & VF_MSG_INPROCESS) {
1656 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1660 vf = BP_VF(bp, vf_idx);
1662 /* save the VF message address */
1663 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1664 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1665 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1666 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1668 /* dmae to get the VF request */
1669 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1670 mbx->vf_addr_hi, mbx->vf_addr_lo,
1671 sizeof(union vfpf_tlvs)/4);
1673 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1677 /* process the VF message header */
1678 mbx->first_tlv = mbx->msg->req.first_tlv;
1680 /* dispatch the request (will prepare the response) */
1681 bnx2x_vf_mbx_request(bp, vf, mbx);
1685 bnx2x_vf_release(bp, vf, false); /* non blocking */
1690 /* propagate local bulletin board to vf */
1691 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1693 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1694 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1695 vf * BULLETIN_CONTENT_SIZE;
1696 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1699 /* can only update vf after init took place */
1700 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1701 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1704 /* increment bulletin board version and compute crc */
1705 bulletin->version++;
1706 bulletin->length = BULLETIN_CONTENT_SIZE;
1707 bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1709 /* propagate bulletin board via dmae to vm memory */
1710 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1711 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
1712 U64_LO(vf_addr), bulletin->length / 4);