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 = 600, interval = 100; /* wait for 60 seconds */
119 BNX2X_ERR("done was non zero before message to pf was sent\n");
124 /* Write message address */
125 writel(U64_LO(msg_mapping),
126 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
127 writel(U64_HI(msg_mapping),
128 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
130 /* make sure the address is written before FW accesses it */
133 /* Trigger the PF FW */
134 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
136 /* Wait for PF to complete */
137 while ((tout >= 0) && (!*done)) {
141 /* progress indicator - HV can take its own sweet time in
144 DP_CONT(BNX2X_MSG_IOV, ".");
148 BNX2X_ERR("PF response has timed out\n");
151 DP(BNX2X_MSG_SP, "Got a response from PF\n");
155 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
158 int tout = 10, interval = 100; /* Wait for 1 sec */
161 /* pxp traps vf read of doorbells and returns me reg value */
162 me_reg = readl(bp->doorbells);
163 if (GOOD_ME_REG(me_reg))
168 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
170 } while (tout-- > 0);
172 if (!GOOD_ME_REG(me_reg)) {
173 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
177 BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
179 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
184 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
186 int rc = 0, attempts = 0;
187 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
188 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
190 bool resources_acquired = false;
192 /* clear mailbox and prep first tlv */
193 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
195 if (bnx2x_get_vf_id(bp, &vf_id)) {
200 req->vfdev_info.vf_id = vf_id;
201 req->vfdev_info.vf_os = 0;
203 req->resc_request.num_rxqs = rx_count;
204 req->resc_request.num_txqs = tx_count;
205 req->resc_request.num_sbs = bp->igu_sb_cnt;
206 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
207 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
209 /* pf 2 vf bulletin board address */
210 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
212 /* add list termination tlv */
213 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
214 sizeof(struct channel_list_end_tlv));
216 /* output tlvs list */
217 bnx2x_dp_tlv_list(bp, req);
219 while (!resources_acquired) {
220 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
222 /* send acquire request */
223 rc = bnx2x_send_msg2pf(bp,
225 bp->vf2pf_mbox_mapping);
231 /* copy acquire response from buffer to bp */
232 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
236 /* test whether the PF accepted our request. If not, humble
237 * the request and try again.
239 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
240 DP(BNX2X_MSG_SP, "resources acquired\n");
241 resources_acquired = true;
242 } else if (bp->acquire_resp.hdr.status ==
243 PFVF_STATUS_NO_RESOURCE &&
244 attempts < VF_ACQUIRE_THRESH) {
246 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
248 /* humble our request */
249 req->resc_request.num_txqs =
250 bp->acquire_resp.resc.num_txqs;
251 req->resc_request.num_rxqs =
252 bp->acquire_resp.resc.num_rxqs;
253 req->resc_request.num_sbs =
254 bp->acquire_resp.resc.num_sbs;
255 req->resc_request.num_mac_filters =
256 bp->acquire_resp.resc.num_mac_filters;
257 req->resc_request.num_vlan_filters =
258 bp->acquire_resp.resc.num_vlan_filters;
259 req->resc_request.num_mc_filters =
260 bp->acquire_resp.resc.num_mc_filters;
262 /* Clear response buffer */
263 memset(&bp->vf2pf_mbox->resp, 0,
264 sizeof(union pfvf_tlvs));
266 /* PF reports error */
267 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
268 bp->acquire_resp.hdr.status);
275 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
276 bp->link_params.chip_id = bp->common.chip_id;
277 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
278 bp->common.int_block = INT_BLOCK_IGU;
279 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
283 bp->common.flash_size = 0;
285 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
287 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
288 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
291 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
292 memcpy(bp->dev->dev_addr,
293 bp->acquire_resp.resc.current_mac_addr,
297 bnx2x_vfpf_finalize(bp, &req->first_tlv);
301 int bnx2x_vfpf_release(struct bnx2x *bp)
303 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
304 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
307 /* clear mailbox and prep first tlv */
308 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
310 if (bnx2x_get_vf_id(bp, &vf_id)) {
317 /* add list termination tlv */
318 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
319 sizeof(struct channel_list_end_tlv));
321 /* output tlvs list */
322 bnx2x_dp_tlv_list(bp, req);
324 /* send release request */
325 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
331 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
333 DP(BNX2X_MSG_SP, "vf released\n");
335 /* PF reports error */
336 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
342 bnx2x_vfpf_finalize(bp, &req->first_tlv);
347 /* Tell PF about SB addresses */
348 int bnx2x_vfpf_init(struct bnx2x *bp)
350 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
351 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
354 /* clear mailbox and prep first tlv */
355 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
358 for_each_eth_queue(bp, i)
359 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
362 /* statistics - requests only supports single queue for now */
363 req->stats_addr = bp->fw_stats_data_mapping +
364 offsetof(struct bnx2x_fw_stats_data, queue_stats);
366 /* add list termination tlv */
367 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
368 sizeof(struct channel_list_end_tlv));
370 /* output tlvs list */
371 bnx2x_dp_tlv_list(bp, req);
373 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
377 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
378 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
384 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
386 bnx2x_vfpf_finalize(bp, &req->first_tlv);
391 /* CLOSE VF - opposite to INIT_VF */
392 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
394 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
395 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
399 /* If we haven't got a valid VF id, there is no sense to
400 * continue with sending messages
402 if (bnx2x_get_vf_id(bp, &vf_id))
405 /* Close the queues */
406 for_each_queue(bp, i)
407 bnx2x_vfpf_teardown_queue(bp, i);
410 bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
412 /* clear mailbox and prep first tlv */
413 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
417 /* add list termination tlv */
418 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
419 sizeof(struct channel_list_end_tlv));
421 /* output tlvs list */
422 bnx2x_dp_tlv_list(bp, req);
424 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
427 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
429 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
430 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
433 bnx2x_vfpf_finalize(bp, &req->first_tlv);
436 /* Disable HW interrupts, NAPI */
437 bnx2x_netif_stop(bp, 0);
438 /* Delete all NAPI objects */
439 bnx2x_del_all_napi(bp);
445 /* ask the pf to open a queue for the vf */
446 int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
448 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
449 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
450 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
451 u16 tpa_agg_size = 0, flags = 0;
454 /* clear mailbox and prep first tlv */
455 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
457 /* select tpa mode to request */
458 if (!fp->disable_tpa) {
459 flags |= VFPF_QUEUE_FLG_TPA;
460 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
461 if (fp->mode == TPA_MODE_GRO)
462 flags |= VFPF_QUEUE_FLG_TPA_GRO;
463 tpa_agg_size = TPA_AGG_SIZE;
466 /* calculate queue flags */
467 flags |= VFPF_QUEUE_FLG_STATS;
468 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
469 flags |= VFPF_QUEUE_FLG_VLAN;
470 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
473 req->vf_qid = fp_idx;
474 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
477 req->rxq.rcq_addr = fp->rx_comp_mapping;
478 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
479 req->rxq.rxq_addr = fp->rx_desc_mapping;
480 req->rxq.sge_addr = fp->rx_sge_mapping;
481 req->rxq.vf_sb = fp_idx;
482 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
483 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
484 req->rxq.mtu = bp->dev->mtu;
485 req->rxq.buf_sz = fp->rx_buf_size;
486 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
487 req->rxq.tpa_agg_sz = tpa_agg_size;
488 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
489 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
490 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
491 req->rxq.flags = flags;
492 req->rxq.drop_flags = 0;
493 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
494 req->rxq.stat_id = -1; /* No stats at the moment */
497 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
498 req->txq.vf_sb = fp_idx;
499 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
500 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
501 req->txq.flags = flags;
502 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
504 /* add list termination tlv */
505 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
506 sizeof(struct channel_list_end_tlv));
508 /* output tlvs list */
509 bnx2x_dp_tlv_list(bp, req);
511 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
513 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
516 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
517 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
518 fp_idx, resp->hdr.status);
522 bnx2x_vfpf_finalize(bp, &req->first_tlv);
527 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
529 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
530 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
533 /* clear mailbox and prep first tlv */
534 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
539 /* add list termination tlv */
540 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
541 sizeof(struct channel_list_end_tlv));
543 /* output tlvs list */
544 bnx2x_dp_tlv_list(bp, req);
546 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
549 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
554 /* PF failed the transaction */
555 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
556 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
562 bnx2x_vfpf_finalize(bp, &req->first_tlv);
566 /* request pf to add a mac for the vf */
567 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
569 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
570 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
571 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
574 /* clear mailbox and prep first tlv */
575 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
578 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
579 req->vf_qid = vf_qid;
580 req->n_mac_vlan_filters = 1;
582 req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
584 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
586 /* sample bulletin board for new mac */
587 bnx2x_sample_bulletin(bp);
589 /* copy mac from device to request */
590 memcpy(req->filters[0].mac, addr, ETH_ALEN);
592 /* add list termination tlv */
593 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
594 sizeof(struct channel_list_end_tlv));
596 /* output tlvs list */
597 bnx2x_dp_tlv_list(bp, req);
599 /* send message to pf */
600 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
602 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
606 /* failure may mean PF was configured with a new mac for us */
607 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
609 "vfpf SET MAC failed. Check bulletin board for new posts\n");
611 /* copy mac from bulletin to device */
612 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
614 /* check if bulletin board was updated */
615 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
616 /* copy mac from device to request */
617 memcpy(req->filters[0].mac, bp->dev->dev_addr,
620 /* send message to pf */
621 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
622 bp->vf2pf_mbox_mapping);
624 /* no new info in bulletin */
629 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
630 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
634 bnx2x_vfpf_finalize(bp, &req->first_tlv);
639 int bnx2x_vfpf_set_mcast(struct net_device *dev)
641 struct bnx2x *bp = netdev_priv(dev);
642 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
643 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
645 struct netdev_hw_addr *ha;
647 if (bp->state != BNX2X_STATE_OPEN) {
648 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
652 /* clear mailbox and prep first tlv */
653 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
656 /* Get Rx mode requested */
657 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
659 netdev_for_each_mc_addr(ha, dev) {
660 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
662 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
666 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
669 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
671 "VF supports not more than %d multicast MAC addresses\n",
672 PFVF_MAX_MULTICAST_PER_VF);
676 req->n_multicast = i;
677 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
680 /* add list termination tlv */
681 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
682 sizeof(struct channel_list_end_tlv));
684 /* output tlvs list */
685 bnx2x_dp_tlv_list(bp, req);
686 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
688 BNX2X_ERR("Sending a message failed: %d\n", rc);
692 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
693 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
698 bnx2x_vfpf_finalize(bp, &req->first_tlv);
703 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
705 int mode = bp->rx_mode;
706 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
707 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
710 /* clear mailbox and prep first tlv */
711 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
714 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
717 case BNX2X_RX_MODE_NONE: /* no Rx */
718 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
720 case BNX2X_RX_MODE_NORMAL:
721 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
722 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
723 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
725 case BNX2X_RX_MODE_ALLMULTI:
726 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
727 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
728 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
730 case BNX2X_RX_MODE_PROMISC:
731 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
732 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
733 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
736 BNX2X_ERR("BAD rx mode (%d)\n", mode);
741 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
744 /* add list termination tlv */
745 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
746 sizeof(struct channel_list_end_tlv));
748 /* output tlvs list */
749 bnx2x_dp_tlv_list(bp, req);
751 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
753 BNX2X_ERR("Sending a message failed: %d\n", rc);
755 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
756 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
760 bnx2x_vfpf_finalize(bp, &req->first_tlv);
765 /* General service functions */
766 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
768 u32 addr = BAR_CSTRORM_INTMEM +
769 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
771 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
774 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
776 u32 addr = BAR_CSTRORM_INTMEM +
777 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
779 REG_WR8(bp, addr, 1);
782 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
787 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
790 /* enable vf_pf mailbox (aka vf-pf-channel) */
791 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
793 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
795 /* enable the mailbox in the FW */
796 storm_memset_vf_mbx_ack(bp, abs_vfid);
797 storm_memset_vf_mbx_valid(bp, abs_vfid);
799 /* enable the VF access to the mailbox */
800 bnx2x_vf_enable_access(bp, abs_vfid);
803 /* this works only on !E1h */
804 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
805 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
806 u32 vf_addr_lo, u32 len32)
808 struct dmae_command dmae;
810 if (CHIP_IS_E1x(bp)) {
811 BNX2X_ERR("Chip revision does not support VFs\n");
815 if (!bp->dmae_ready) {
816 BNX2X_ERR("DMAE is not ready, can not copy\n");
820 /* set opcode and fixed command fields */
821 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
824 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
825 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
826 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
828 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
830 dmae.src_addr_lo = vf_addr_lo;
831 dmae.src_addr_hi = vf_addr_hi;
832 dmae.dst_addr_lo = U64_LO(pf_addr);
833 dmae.dst_addr_hi = U64_HI(pf_addr);
835 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
836 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
837 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
839 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
841 dmae.src_addr_lo = U64_LO(pf_addr);
842 dmae.src_addr_hi = U64_HI(pf_addr);
843 dmae.dst_addr_lo = vf_addr_lo;
844 dmae.dst_addr_hi = vf_addr_hi;
848 /* issue the command and wait for completion */
849 return bnx2x_issue_dmae_with_comp(bp, &dmae);
852 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
854 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
859 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
861 /* prepare response */
862 type = mbx->first_tlv.tl.type;
863 length = type == CHANNEL_TLV_ACQUIRE ?
864 sizeof(struct pfvf_acquire_resp_tlv) :
865 sizeof(struct pfvf_general_resp_tlv);
866 bnx2x_add_tlv(bp, resp, 0, type, length);
867 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
868 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
869 sizeof(struct channel_list_end_tlv));
870 bnx2x_dp_tlv_list(bp, resp);
871 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
872 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
875 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
876 mbx->first_tlv.resp_msg_offset;
877 pf_addr = mbx->msg_mapping +
878 offsetof(struct bnx2x_vf_mbx_msg, resp);
880 /* copy the response body, if there is one, before the header, as the vf
881 * is sensitive to the header being written
883 if (resp->hdr.tl.length > sizeof(u64)) {
884 length = resp->hdr.tl.length - sizeof(u64);
885 vf_addr += sizeof(u64);
886 pf_addr += sizeof(u64);
887 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
892 BNX2X_ERR("Failed to copy response body to VF %d\n",
896 vf_addr -= sizeof(u64);
897 pf_addr -= sizeof(u64);
901 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
904 /* initiate dmae to send the response */
905 mbx->flags &= ~VF_MSG_INPROCESS;
907 /* copy the response header including status-done field,
908 * must be last dmae, must be after FW is acked
910 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
915 /* unlock channel mutex */
916 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
919 BNX2X_ERR("Failed to copy response status to VF %d\n",
926 bnx2x_vf_release(bp, vf, false); /* non blocking */
929 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
930 struct bnx2x_vf_mbx *mbx, int vfop_status)
933 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
934 struct pf_vf_resc *resc = &resp->resc;
935 u8 status = bnx2x_pfvf_status_codes(vfop_status);
937 memset(resp, 0, sizeof(*resp));
939 /* fill in pfdev info */
940 resp->pfdev_info.chip_num = bp->common.chip_id;
941 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
942 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
943 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
944 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
945 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
946 sizeof(resp->pfdev_info.fw_ver));
948 if (status == PFVF_STATUS_NO_RESOURCE ||
949 status == PFVF_STATUS_SUCCESS) {
950 /* set resources numbers, if status equals NO_RESOURCE these
951 * are max possible numbers
953 resc->num_rxqs = vf_rxq_count(vf) ? :
954 bnx2x_vf_max_queue_cnt(bp, vf);
955 resc->num_txqs = vf_txq_count(vf) ? :
956 bnx2x_vf_max_queue_cnt(bp, vf);
957 resc->num_sbs = vf_sb_count(vf);
958 resc->num_mac_filters = vf_mac_rules_cnt(vf);
959 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
960 resc->num_mc_filters = 0;
962 if (status == PFVF_STATUS_SUCCESS) {
963 /* fill in the allocated resources */
964 struct pf_vf_bulletin_content *bulletin =
965 BP_VF_BULLETIN(bp, vf->index);
969 vfq_qzone_id(vf, vfq_get(vf, i));
971 for_each_vf_sb(vf, i) {
972 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
973 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
976 /* if a mac has been set for this vf, supply it */
977 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
978 memcpy(resc->current_mac_addr, bulletin->mac,
984 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"
985 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
987 resp->pfdev_info.chip_num,
988 resp->pfdev_info.db_size,
989 resp->pfdev_info.indices_per_sb,
990 resp->pfdev_info.pf_cap,
994 resc->num_mac_filters,
995 resc->num_vlan_filters,
996 resc->num_mc_filters,
997 resp->pfdev_info.fw_ver);
999 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1000 for (i = 0; i < vf_rxq_count(vf); i++)
1001 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1002 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1003 for (i = 0; i < vf_sb_count(vf); i++)
1004 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1005 resc->hw_sbs[i].hw_sb_id,
1006 resc->hw_sbs[i].sb_qid);
1007 DP_CONT(BNX2X_MSG_IOV, "]\n");
1009 /* send the response */
1010 vf->op_rc = vfop_status;
1011 bnx2x_vf_mbx_resp(bp, vf);
1014 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1015 struct bnx2x_vf_mbx *mbx)
1018 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1020 /* log vfdef info */
1022 "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",
1023 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1024 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1025 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1026 acquire->resc_request.num_vlan_filters,
1027 acquire->resc_request.num_mc_filters);
1029 /* acquire the resources */
1030 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1032 /* store address of vf's bulletin board */
1033 vf->bulletin_map = acquire->bulletin_addr;
1036 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1039 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1040 struct bnx2x_vf_mbx *mbx)
1042 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1044 /* record ghost addresses from vf message */
1045 vf->spq_map = init->spq_addr;
1046 vf->fw_stat_map = init->stats_addr;
1047 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1050 bnx2x_vf_mbx_resp(bp, vf);
1053 /* convert MBX queue-flags to standard SP queue-flags */
1054 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1055 unsigned long *sp_q_flags)
1057 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1058 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1059 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1060 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1061 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1062 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1063 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1064 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1065 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1066 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1067 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1068 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1069 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1070 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1071 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1072 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1074 /* outer vlan removal is set according to PF's multi function mode */
1076 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1079 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1080 struct bnx2x_vf_mbx *mbx)
1082 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1083 struct bnx2x_vfop_cmd cmd = {
1084 .done = bnx2x_vf_mbx_resp,
1089 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1090 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1091 setup_q->vf_qid, vf_rxq_count(vf));
1092 vf->op_rc = -EINVAL;
1096 /* tx queues must be setup alongside rx queues thus if the rx queue
1097 * is not marked as valid there's nothing to do.
1099 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1100 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1101 unsigned long q_type = 0;
1103 struct bnx2x_queue_init_params *init_p;
1104 struct bnx2x_queue_setup_params *setup_p;
1106 /* re-init the VF operation context */
1107 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1108 setup_p = &vf->op_params.qctor.prep_qsetup;
1109 init_p = &vf->op_params.qctor.qstate.params.init;
1111 /* activate immediately */
1112 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1114 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1115 struct bnx2x_txq_setup_params *txq_params =
1116 &setup_p->txq_params;
1118 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1120 /* save sb resource index */
1121 q->sb_idx = setup_q->txq.vf_sb;
1124 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1125 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1127 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1130 /* tx setup - flags */
1131 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1134 /* tx setup - general, nothing */
1137 txq_params->dscr_map = setup_q->txq.txq_addr;
1138 txq_params->sb_cq_index = setup_q->txq.sb_index;
1139 txq_params->traffic_type = setup_q->txq.traffic_type;
1141 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1142 q->index, q->sb_idx);
1145 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1146 struct bnx2x_rxq_setup_params *rxq_params =
1147 &setup_p->rxq_params;
1149 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1151 /* Note: there is no support for different SBs
1154 q->sb_idx = setup_q->rxq.vf_sb;
1157 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1158 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1159 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1162 /* rx setup - flags */
1163 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1166 /* rx setup - general */
1167 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1170 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1171 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1172 rxq_params->sge_map = setup_q->rxq.sge_addr;
1173 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1174 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1175 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1176 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1177 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1178 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1179 rxq_params->cache_line_log =
1180 setup_q->rxq.cache_line_log;
1181 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1183 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1184 q->index, q->sb_idx);
1186 /* complete the preparations */
1187 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1189 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1195 bnx2x_vf_mbx_resp(bp, vf);
1198 enum bnx2x_vfop_filters_state {
1199 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1200 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1201 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1202 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1203 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1206 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1207 struct bnx2x_virtf *vf,
1208 struct vfpf_set_q_filters_tlv *tlv,
1209 struct bnx2x_vfop_filters **pfl,
1213 struct bnx2x_vfop_filters *fl = NULL;
1216 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1217 sizeof(struct bnx2x_vfop_filters);
1219 fl = kzalloc(fsz, GFP_KERNEL);
1223 INIT_LIST_HEAD(&fl->head);
1225 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1226 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1228 if ((msg_filter->flags & type_flag) != type_flag)
1230 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1231 fl->filters[j].mac = msg_filter->mac;
1232 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1234 fl->filters[j].vid = msg_filter->vlan_tag;
1235 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1237 fl->filters[j].add =
1238 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1240 list_add_tail(&fl->filters[j++].link, &fl->head);
1242 if (list_empty(&fl->head))
1250 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1251 struct vfpf_q_mac_vlan_filter *filter)
1253 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1254 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1255 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1256 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1257 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1258 DP_CONT(msglvl, "\n");
1261 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1262 struct vfpf_set_q_filters_tlv *filters)
1266 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1267 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1268 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1269 &filters->filters[i]);
1271 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1272 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1274 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1275 for (i = 0; i < filters->n_multicast; i++)
1276 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1279 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1280 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1282 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1286 struct vfpf_set_q_filters_tlv *msg =
1287 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1289 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1290 enum bnx2x_vfop_filters_state state = vfop->state;
1292 struct bnx2x_vfop_cmd cmd = {
1293 .done = bnx2x_vfop_mbx_qfilters,
1297 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1303 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1305 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1307 /* check for any vlan/mac changes */
1308 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1309 /* build mac list */
1310 struct bnx2x_vfop_filters *fl = NULL;
1312 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1319 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1331 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1333 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1335 /* check for any vlan/mac changes */
1336 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1337 /* build vlan list */
1338 struct bnx2x_vfop_filters *fl = NULL;
1340 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1347 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1359 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1361 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1363 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1364 unsigned long accept = 0;
1366 /* covert VF-PF if mask to bnx2x accept flags */
1367 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1368 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1371 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1372 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1374 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1375 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1377 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1378 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1380 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1381 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1383 /* A packet arriving the vf's mac should be accepted
1386 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1389 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1390 msg->vf_qid, accept);
1399 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1401 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1403 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1405 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1406 msg->n_multicast, false);
1415 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1416 bnx2x_vfop_end(bp, vf, vfop);
1419 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1420 vf->abs_vfid, msg->vf_qid, vfop->rc);
1424 bnx2x_vfop_default(state);
1428 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1429 struct bnx2x_virtf *vf,
1430 struct bnx2x_vfop_cmd *cmd)
1432 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1434 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1435 bnx2x_vfop_mbx_qfilters, cmd->done);
1436 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1442 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1443 struct bnx2x_virtf *vf,
1444 struct bnx2x_vf_mbx *mbx)
1446 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1447 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1448 struct bnx2x_vfop_cmd cmd = {
1449 .done = bnx2x_vf_mbx_resp,
1453 /* if a mac was already set for this VF via the set vf mac ndo, we only
1454 * accept mac configurations of that mac. Why accept them at all?
1455 * because PF may have been unable to configure the mac at the time
1456 * since queue was not set up.
1458 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1459 /* once a mac was set by ndo can only accept a single mac... */
1460 if (filters->n_mac_vlan_filters > 1) {
1461 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1467 /* ...and only the mac set by the ndo */
1468 if (filters->n_mac_vlan_filters == 1 &&
1469 memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1470 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1479 if (filters->vf_qid > vf_rxq_count(vf))
1482 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1486 /* print q_filter message */
1487 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1489 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1495 bnx2x_vf_mbx_resp(bp, vf);
1498 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1499 struct bnx2x_vf_mbx *mbx)
1501 int qid = mbx->msg->req.q_op.vf_qid;
1502 struct bnx2x_vfop_cmd cmd = {
1503 .done = bnx2x_vf_mbx_resp,
1507 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1510 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1512 bnx2x_vf_mbx_resp(bp, vf);
1515 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1516 struct bnx2x_vf_mbx *mbx)
1518 struct bnx2x_vfop_cmd cmd = {
1519 .done = bnx2x_vf_mbx_resp,
1523 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1525 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1527 bnx2x_vf_mbx_resp(bp, vf);
1530 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1531 struct bnx2x_vf_mbx *mbx)
1533 struct bnx2x_vfop_cmd cmd = {
1534 .done = bnx2x_vf_mbx_resp,
1538 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1540 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1542 bnx2x_vf_mbx_resp(bp, vf);
1545 /* dispatch request */
1546 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1547 struct bnx2x_vf_mbx *mbx)
1551 /* check if tlv type is known */
1552 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1553 /* Lock the per vf op mutex and note the locker's identity.
1554 * The unlock will take place in mbx response.
1556 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1558 /* switch on the opcode */
1559 switch (mbx->first_tlv.tl.type) {
1560 case CHANNEL_TLV_ACQUIRE:
1561 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1563 case CHANNEL_TLV_INIT:
1564 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1566 case CHANNEL_TLV_SETUP_Q:
1567 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1569 case CHANNEL_TLV_SET_Q_FILTERS:
1570 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1572 case CHANNEL_TLV_TEARDOWN_Q:
1573 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1575 case CHANNEL_TLV_CLOSE:
1576 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1578 case CHANNEL_TLV_RELEASE:
1579 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1584 /* unknown TLV - this may belong to a VF driver from the future
1585 * - a version written after this PF driver was written, which
1586 * supports features unknown as of yet. Too bad since we don't
1587 * support them. Or this may be because someone wrote a crappy
1588 * VF driver and is sending garbage over the channel.
1590 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
1591 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
1593 for (i = 0; i < 20; i++)
1594 DP_CONT(BNX2X_MSG_IOV, "%x ",
1595 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1597 /* test whether we can respond to the VF (do we have an address
1600 if (vf->state == VF_ACQUIRED) {
1601 /* mbx_resp uses the op_rc of the VF */
1602 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1604 /* notify the VF that we do not support this request */
1605 bnx2x_vf_mbx_resp(bp, vf);
1607 /* can't send a response since this VF is unknown to us
1608 * just ack the FW to release the mailbox and unlock
1611 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1613 bnx2x_unlock_vf_pf_channel(bp, vf,
1614 mbx->first_tlv.tl.type);
1619 /* handle new vf-pf message */
1620 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1622 struct bnx2x_virtf *vf;
1623 struct bnx2x_vf_mbx *mbx;
1628 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1629 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1630 /* Sanity checks consider removing later */
1632 /* check if the vf_id is valid */
1633 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1634 BNX2X_NR_VIRTFN(bp)) {
1635 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1636 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1639 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1640 mbx = BP_VF_MBX(bp, vf_idx);
1642 /* verify an event is not currently being processed -
1643 * debug failsafe only
1645 if (mbx->flags & VF_MSG_INPROCESS) {
1646 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1650 vf = BP_VF(bp, vf_idx);
1652 /* save the VF message address */
1653 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1654 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1655 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1656 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1658 /* dmae to get the VF request */
1659 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1660 mbx->vf_addr_hi, mbx->vf_addr_lo,
1661 sizeof(union vfpf_tlvs)/4);
1663 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1667 /* process the VF message header */
1668 mbx->first_tlv = mbx->msg->req.first_tlv;
1670 /* dispatch the request (will prepare the response) */
1671 bnx2x_vf_mbx_request(bp, vf, mbx);
1675 bnx2x_vf_release(bp, vf, false); /* non blocking */
1680 /* propagate local bulletin board to vf */
1681 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1683 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1684 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1685 vf * BULLETIN_CONTENT_SIZE;
1686 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1689 /* can only update vf after init took place */
1690 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1691 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1694 /* increment bulletin board version and compute crc */
1695 bulletin->version++;
1696 bulletin->length = BULLETIN_CONTENT_SIZE;
1697 bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1699 /* propagate bulletin board via dmae to vm memory */
1700 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1701 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
1702 U64_LO(vf_addr), bulletin->length / 4);