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 the
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);
409 /* clear mailbox and prep first tlv */
410 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
414 /* add list termination tlv */
415 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
416 sizeof(struct channel_list_end_tlv));
418 /* output tlvs list */
419 bnx2x_dp_tlv_list(bp, req);
421 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
424 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
426 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
427 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
430 bnx2x_vfpf_finalize(bp, &req->first_tlv);
433 /* Disable HW interrupts, NAPI */
434 bnx2x_netif_stop(bp, 0);
435 /* Delete all NAPI objects */
436 bnx2x_del_all_napi(bp);
442 /* ask the pf to open a queue for the vf */
443 int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
445 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
446 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
447 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
448 u16 tpa_agg_size = 0, flags = 0;
451 /* clear mailbox and prep first tlv */
452 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
454 /* select tpa mode to request */
455 if (!fp->disable_tpa) {
456 flags |= VFPF_QUEUE_FLG_TPA;
457 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
458 if (fp->mode == TPA_MODE_GRO)
459 flags |= VFPF_QUEUE_FLG_TPA_GRO;
460 tpa_agg_size = TPA_AGG_SIZE;
463 /* calculate queue flags */
464 flags |= VFPF_QUEUE_FLG_STATS;
465 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
466 flags |= VFPF_QUEUE_FLG_VLAN;
467 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
470 req->vf_qid = fp_idx;
471 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
474 req->rxq.rcq_addr = fp->rx_comp_mapping;
475 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
476 req->rxq.rxq_addr = fp->rx_desc_mapping;
477 req->rxq.sge_addr = fp->rx_sge_mapping;
478 req->rxq.vf_sb = fp_idx;
479 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
480 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
481 req->rxq.mtu = bp->dev->mtu;
482 req->rxq.buf_sz = fp->rx_buf_size;
483 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
484 req->rxq.tpa_agg_sz = tpa_agg_size;
485 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
486 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
487 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
488 req->rxq.flags = flags;
489 req->rxq.drop_flags = 0;
490 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
491 req->rxq.stat_id = -1; /* No stats at the moment */
494 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
495 req->txq.vf_sb = fp_idx;
496 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
497 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
498 req->txq.flags = flags;
499 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
501 /* add list termination tlv */
502 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
503 sizeof(struct channel_list_end_tlv));
505 /* output tlvs list */
506 bnx2x_dp_tlv_list(bp, req);
508 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
510 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
513 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
514 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
515 fp_idx, resp->hdr.status);
519 bnx2x_vfpf_finalize(bp, &req->first_tlv);
524 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
526 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
527 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
530 /* clear mailbox and prep first tlv */
531 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
536 /* add list termination tlv */
537 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
538 sizeof(struct channel_list_end_tlv));
540 /* output tlvs list */
541 bnx2x_dp_tlv_list(bp, req);
543 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
546 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
551 /* PF failed the transaction */
552 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
553 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
559 bnx2x_vfpf_finalize(bp, &req->first_tlv);
563 /* request pf to add a mac for the vf */
564 int bnx2x_vfpf_set_mac(struct bnx2x *bp)
566 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
567 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
570 /* clear mailbox and prep first tlv */
571 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
574 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
576 req->n_mac_vlan_filters = 1;
577 req->filters[0].flags =
578 VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
580 /* sample bulletin board for new mac */
581 bnx2x_sample_bulletin(bp);
583 /* copy mac from device to request */
584 memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
586 /* add list termination tlv */
587 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
588 sizeof(struct channel_list_end_tlv));
590 /* output tlvs list */
591 bnx2x_dp_tlv_list(bp, req);
593 /* send message to pf */
594 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
596 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
600 /* failure may mean PF was configured with a new mac for us */
601 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
603 "vfpf SET MAC failed. Check bulletin board for new posts\n");
605 /* check if bulletin board was updated */
606 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
607 /* copy mac from device to request */
608 memcpy(req->filters[0].mac, bp->dev->dev_addr,
611 /* send message to pf */
612 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
613 bp->vf2pf_mbox_mapping);
615 /* no new info in bulletin */
620 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
621 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
625 bnx2x_vfpf_finalize(bp, &req->first_tlv);
630 int bnx2x_vfpf_set_mcast(struct net_device *dev)
632 struct bnx2x *bp = netdev_priv(dev);
633 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
634 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
636 struct netdev_hw_addr *ha;
638 if (bp->state != BNX2X_STATE_OPEN) {
639 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
643 /* clear mailbox and prep first tlv */
644 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
647 /* Get Rx mode requested */
648 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
650 netdev_for_each_mc_addr(ha, dev) {
651 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
653 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
657 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
660 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
662 "VF supports not more than %d multicast MAC addresses\n",
663 PFVF_MAX_MULTICAST_PER_VF);
667 req->n_multicast = i;
668 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
671 /* add list termination tlv */
672 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
673 sizeof(struct channel_list_end_tlv));
675 /* output tlvs list */
676 bnx2x_dp_tlv_list(bp, req);
677 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
679 BNX2X_ERR("Sending a message failed: %d\n", rc);
683 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
684 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
689 bnx2x_vfpf_finalize(bp, &req->first_tlv);
694 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
696 int mode = bp->rx_mode;
697 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
698 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
701 /* clear mailbox and prep first tlv */
702 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
705 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
708 case BNX2X_RX_MODE_NONE: /* no Rx */
709 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
711 case BNX2X_RX_MODE_NORMAL:
712 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
713 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
714 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
716 case BNX2X_RX_MODE_ALLMULTI:
717 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
718 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
719 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
721 case BNX2X_RX_MODE_PROMISC:
722 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
723 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
724 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
727 BNX2X_ERR("BAD rx mode (%d)\n", mode);
732 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
735 /* add list termination tlv */
736 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
737 sizeof(struct channel_list_end_tlv));
739 /* output tlvs list */
740 bnx2x_dp_tlv_list(bp, req);
742 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
744 BNX2X_ERR("Sending a message failed: %d\n", rc);
746 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
747 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
751 bnx2x_vfpf_finalize(bp, &req->first_tlv);
756 /* General service functions */
757 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
759 u32 addr = BAR_CSTRORM_INTMEM +
760 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
762 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
765 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
767 u32 addr = BAR_CSTRORM_INTMEM +
768 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
770 REG_WR8(bp, addr, 1);
773 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
778 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
781 /* enable vf_pf mailbox (aka vf-pf-chanell) */
782 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
784 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
786 /* enable the mailbox in the FW */
787 storm_memset_vf_mbx_ack(bp, abs_vfid);
788 storm_memset_vf_mbx_valid(bp, abs_vfid);
790 /* enable the VF access to the mailbox */
791 bnx2x_vf_enable_access(bp, abs_vfid);
794 /* this works only on !E1h */
795 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
796 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
797 u32 vf_addr_lo, u32 len32)
799 struct dmae_command dmae;
801 if (CHIP_IS_E1x(bp)) {
802 BNX2X_ERR("Chip revision does not support VFs\n");
806 if (!bp->dmae_ready) {
807 BNX2X_ERR("DMAE is not ready, can not copy\n");
811 /* set opcode and fixed command fields */
812 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
815 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
816 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
817 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
819 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
821 dmae.src_addr_lo = vf_addr_lo;
822 dmae.src_addr_hi = vf_addr_hi;
823 dmae.dst_addr_lo = U64_LO(pf_addr);
824 dmae.dst_addr_hi = U64_HI(pf_addr);
826 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
827 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
828 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
830 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
832 dmae.src_addr_lo = U64_LO(pf_addr);
833 dmae.src_addr_hi = U64_HI(pf_addr);
834 dmae.dst_addr_lo = vf_addr_lo;
835 dmae.dst_addr_hi = vf_addr_hi;
838 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
840 /* issue the command and wait for completion */
841 return bnx2x_issue_dmae_with_comp(bp, &dmae);
844 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
846 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
851 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
853 /* prepare response */
854 type = mbx->first_tlv.tl.type;
855 length = type == CHANNEL_TLV_ACQUIRE ?
856 sizeof(struct pfvf_acquire_resp_tlv) :
857 sizeof(struct pfvf_general_resp_tlv);
858 bnx2x_add_tlv(bp, resp, 0, type, length);
859 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
860 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
861 sizeof(struct channel_list_end_tlv));
862 bnx2x_dp_tlv_list(bp, resp);
863 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
864 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
867 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
868 mbx->first_tlv.resp_msg_offset;
869 pf_addr = mbx->msg_mapping +
870 offsetof(struct bnx2x_vf_mbx_msg, resp);
872 /* copy the response body, if there is one, before the header, as the vf
873 * is sensitive to the header being written
875 if (resp->hdr.tl.length > sizeof(u64)) {
876 length = resp->hdr.tl.length - sizeof(u64);
877 vf_addr += sizeof(u64);
878 pf_addr += sizeof(u64);
879 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
884 BNX2X_ERR("Failed to copy response body to VF %d\n",
888 vf_addr -= sizeof(u64);
889 pf_addr -= sizeof(u64);
893 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
896 /* initiate dmae to send the response */
897 mbx->flags &= ~VF_MSG_INPROCESS;
899 /* copy the response header including status-done field,
900 * must be last dmae, must be after FW is acked
902 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
907 /* unlock channel mutex */
908 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
911 BNX2X_ERR("Failed to copy response status to VF %d\n",
918 bnx2x_vf_release(bp, vf, false); /* non blocking */
921 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
922 struct bnx2x_vf_mbx *mbx, int vfop_status)
925 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
926 struct pf_vf_resc *resc = &resp->resc;
927 u8 status = bnx2x_pfvf_status_codes(vfop_status);
929 memset(resp, 0, sizeof(*resp));
931 /* fill in pfdev info */
932 resp->pfdev_info.chip_num = bp->common.chip_id;
933 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
934 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
935 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
936 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
937 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
938 sizeof(resp->pfdev_info.fw_ver));
940 if (status == PFVF_STATUS_NO_RESOURCE ||
941 status == PFVF_STATUS_SUCCESS) {
942 /* set resources numbers, if status equals NO_RESOURCE these
943 * are max possible numbers
945 resc->num_rxqs = vf_rxq_count(vf) ? :
946 bnx2x_vf_max_queue_cnt(bp, vf);
947 resc->num_txqs = vf_txq_count(vf) ? :
948 bnx2x_vf_max_queue_cnt(bp, vf);
949 resc->num_sbs = vf_sb_count(vf);
950 resc->num_mac_filters = vf_mac_rules_cnt(vf);
951 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
952 resc->num_mc_filters = 0;
954 if (status == PFVF_STATUS_SUCCESS) {
955 /* fill in the allocated resources */
956 struct pf_vf_bulletin_content *bulletin =
957 BP_VF_BULLETIN(bp, vf->index);
961 vfq_qzone_id(vf, vfq_get(vf, i));
963 for_each_vf_sb(vf, i) {
964 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
965 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
968 /* if a mac has been set for this vf, supply it */
969 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
970 memcpy(resc->current_mac_addr, bulletin->mac,
976 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"
977 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
979 resp->pfdev_info.chip_num,
980 resp->pfdev_info.db_size,
981 resp->pfdev_info.indices_per_sb,
982 resp->pfdev_info.pf_cap,
986 resc->num_mac_filters,
987 resc->num_vlan_filters,
988 resc->num_mc_filters,
989 resp->pfdev_info.fw_ver);
991 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
992 for (i = 0; i < vf_rxq_count(vf); i++)
993 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
994 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
995 for (i = 0; i < vf_sb_count(vf); i++)
996 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
997 resc->hw_sbs[i].hw_sb_id,
998 resc->hw_sbs[i].sb_qid);
999 DP_CONT(BNX2X_MSG_IOV, "]\n");
1001 /* send the response */
1002 vf->op_rc = vfop_status;
1003 bnx2x_vf_mbx_resp(bp, vf);
1006 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1007 struct bnx2x_vf_mbx *mbx)
1010 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1012 /* log vfdef info */
1014 "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",
1015 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1016 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1017 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1018 acquire->resc_request.num_vlan_filters,
1019 acquire->resc_request.num_mc_filters);
1021 /* acquire the resources */
1022 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1024 /* store address of vf's bulletin board */
1025 vf->bulletin_map = acquire->bulletin_addr;
1028 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1031 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1032 struct bnx2x_vf_mbx *mbx)
1034 struct vfpf_init_tlv *init = &mbx->msg->req.init;
1036 /* record ghost addresses from vf message */
1037 vf->spq_map = init->spq_addr;
1038 vf->fw_stat_map = init->stats_addr;
1039 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1042 bnx2x_vf_mbx_resp(bp, vf);
1045 /* convert MBX queue-flags to standard SP queue-flags */
1046 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1047 unsigned long *sp_q_flags)
1049 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1050 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1051 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1052 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1053 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1054 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1055 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1056 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1057 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1058 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1059 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1060 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1061 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1062 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1063 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1064 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1066 /* outer vlan removal is set according to the PF's multi fuction mode */
1068 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1071 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1072 struct bnx2x_vf_mbx *mbx)
1074 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1075 struct bnx2x_vfop_cmd cmd = {
1076 .done = bnx2x_vf_mbx_resp,
1081 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1082 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1083 setup_q->vf_qid, vf_rxq_count(vf));
1084 vf->op_rc = -EINVAL;
1088 /* tx queues must be setup alongside rx queues thus if the rx queue
1089 * is not marked as valid there's nothing to do.
1091 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1092 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1093 unsigned long q_type = 0;
1095 struct bnx2x_queue_init_params *init_p;
1096 struct bnx2x_queue_setup_params *setup_p;
1098 /* reinit the VF operation context */
1099 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1100 setup_p = &vf->op_params.qctor.prep_qsetup;
1101 init_p = &vf->op_params.qctor.qstate.params.init;
1103 /* activate immediately */
1104 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1106 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1107 struct bnx2x_txq_setup_params *txq_params =
1108 &setup_p->txq_params;
1110 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1112 /* save sb resource index */
1113 q->sb_idx = setup_q->txq.vf_sb;
1116 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1117 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1119 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1122 /* tx setup - flags */
1123 bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1126 /* tx setup - general, nothing */
1129 txq_params->dscr_map = setup_q->txq.txq_addr;
1130 txq_params->sb_cq_index = setup_q->txq.sb_index;
1131 txq_params->traffic_type = setup_q->txq.traffic_type;
1133 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1134 q->index, q->sb_idx);
1137 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1138 struct bnx2x_rxq_setup_params *rxq_params =
1139 &setup_p->rxq_params;
1141 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1143 /* Note: there is no support for different SBs
1146 q->sb_idx = setup_q->rxq.vf_sb;
1149 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1150 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1151 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1154 /* rx setup - flags */
1155 bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1158 /* rx setup - general */
1159 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1162 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1163 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1164 rxq_params->sge_map = setup_q->rxq.sge_addr;
1165 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1166 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1167 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1168 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1169 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1170 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1171 rxq_params->cache_line_log =
1172 setup_q->rxq.cache_line_log;
1173 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1175 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1176 q->index, q->sb_idx);
1178 /* complete the preparations */
1179 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1181 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1187 bnx2x_vf_mbx_resp(bp, vf);
1190 enum bnx2x_vfop_filters_state {
1191 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1192 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1193 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1194 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1195 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1198 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1199 struct bnx2x_virtf *vf,
1200 struct vfpf_set_q_filters_tlv *tlv,
1201 struct bnx2x_vfop_filters **pfl,
1205 struct bnx2x_vfop_filters *fl = NULL;
1208 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1209 sizeof(struct bnx2x_vfop_filters);
1211 fl = kzalloc(fsz, GFP_KERNEL);
1215 INIT_LIST_HEAD(&fl->head);
1217 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1218 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1220 if ((msg_filter->flags & type_flag) != type_flag)
1222 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1223 fl->filters[j].mac = msg_filter->mac;
1224 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1226 fl->filters[j].vid = msg_filter->vlan_tag;
1227 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1229 fl->filters[j].add =
1230 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1232 list_add_tail(&fl->filters[j++].link, &fl->head);
1234 if (list_empty(&fl->head))
1242 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1243 struct vfpf_q_mac_vlan_filter *filter)
1245 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1246 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1247 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1248 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1249 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1250 DP_CONT(msglvl, "\n");
1253 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1254 struct vfpf_set_q_filters_tlv *filters)
1258 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1259 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1260 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1261 &filters->filters[i]);
1263 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1264 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1266 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1267 for (i = 0; i < filters->n_multicast; i++)
1268 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1271 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1272 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1274 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1278 struct vfpf_set_q_filters_tlv *msg =
1279 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1281 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1282 enum bnx2x_vfop_filters_state state = vfop->state;
1284 struct bnx2x_vfop_cmd cmd = {
1285 .done = bnx2x_vfop_mbx_qfilters,
1289 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1295 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1297 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1299 /* check for any vlan/mac changes */
1300 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1301 /* build mac list */
1302 struct bnx2x_vfop_filters *fl = NULL;
1304 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1311 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1323 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1325 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1327 /* check for any vlan/mac changes */
1328 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1329 /* build vlan list */
1330 struct bnx2x_vfop_filters *fl = NULL;
1332 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1339 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1351 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1353 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1355 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1356 unsigned long accept = 0;
1358 /* covert VF-PF if mask to bnx2x accept flags */
1359 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1360 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1363 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1364 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1366 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1367 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1369 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1370 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1372 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1373 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1375 /* A packet arriving the vf's mac should be accepted
1378 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1381 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1382 msg->vf_qid, accept);
1391 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1393 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1395 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1397 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1398 msg->n_multicast, false);
1407 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1408 bnx2x_vfop_end(bp, vf, vfop);
1411 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1412 vf->abs_vfid, msg->vf_qid, vfop->rc);
1416 bnx2x_vfop_default(state);
1420 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1421 struct bnx2x_virtf *vf,
1422 struct bnx2x_vfop_cmd *cmd)
1424 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1426 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1427 bnx2x_vfop_mbx_qfilters, cmd->done);
1428 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1434 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1435 struct bnx2x_virtf *vf,
1436 struct bnx2x_vf_mbx *mbx)
1438 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1439 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1440 struct bnx2x_vfop_cmd cmd = {
1441 .done = bnx2x_vf_mbx_resp,
1445 /* if a mac was already set for this VF via the set vf mac ndo, we only
1446 * accept mac configurations of that mac. Why accept them at all?
1447 * because PF may have been unable to configure the mac at the time
1448 * since queue was not set up.
1450 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1451 /* once a mac was set by ndo can only accept a single mac... */
1452 if (filters->n_mac_vlan_filters > 1) {
1453 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1459 /* ...and only the mac set by the ndo */
1460 if (filters->n_mac_vlan_filters == 1 &&
1461 memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1462 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1471 if (filters->vf_qid > vf_rxq_count(vf))
1474 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1478 /* print q_filter message */
1479 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1481 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1487 bnx2x_vf_mbx_resp(bp, vf);
1490 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1491 struct bnx2x_vf_mbx *mbx)
1493 int qid = mbx->msg->req.q_op.vf_qid;
1494 struct bnx2x_vfop_cmd cmd = {
1495 .done = bnx2x_vf_mbx_resp,
1499 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1502 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1504 bnx2x_vf_mbx_resp(bp, vf);
1507 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1508 struct bnx2x_vf_mbx *mbx)
1510 struct bnx2x_vfop_cmd cmd = {
1511 .done = bnx2x_vf_mbx_resp,
1515 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1517 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1519 bnx2x_vf_mbx_resp(bp, vf);
1522 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1523 struct bnx2x_vf_mbx *mbx)
1525 struct bnx2x_vfop_cmd cmd = {
1526 .done = bnx2x_vf_mbx_resp,
1530 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1532 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1534 bnx2x_vf_mbx_resp(bp, vf);
1537 /* dispatch request */
1538 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1539 struct bnx2x_vf_mbx *mbx)
1543 /* check if tlv type is known */
1544 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1545 /* Lock the per vf op mutex and note the locker's identity.
1546 * The unlock will take place in mbx response.
1548 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1550 /* switch on the opcode */
1551 switch (mbx->first_tlv.tl.type) {
1552 case CHANNEL_TLV_ACQUIRE:
1553 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1555 case CHANNEL_TLV_INIT:
1556 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1558 case CHANNEL_TLV_SETUP_Q:
1559 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1561 case CHANNEL_TLV_SET_Q_FILTERS:
1562 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1564 case CHANNEL_TLV_TEARDOWN_Q:
1565 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1567 case CHANNEL_TLV_CLOSE:
1568 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1570 case CHANNEL_TLV_RELEASE:
1571 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1576 /* unknown TLV - this may belong to a VF driver from the future
1577 * - a version written after this PF driver was written, which
1578 * supports features unknown as of yet. Too bad since we don't
1579 * support them. Or this may be because someone wrote a crappy
1580 * VF driver and is sending garbage over the channel.
1582 BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
1583 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
1584 for (i = 0; i < 20; i++)
1585 DP_CONT(BNX2X_MSG_IOV, "%x ",
1586 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1588 /* test whether we can respond to the VF (do we have an address
1591 if (vf->state == VF_ACQUIRED) {
1592 /* mbx_resp uses the op_rc of the VF */
1593 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1595 /* notify the VF that we do not support this request */
1596 bnx2x_vf_mbx_resp(bp, vf);
1598 /* can't send a response since this VF is unknown to us
1599 * just unlock the channel and be done with.
1601 bnx2x_unlock_vf_pf_channel(bp, vf,
1602 mbx->first_tlv.tl.type);
1607 /* handle new vf-pf message */
1608 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1610 struct bnx2x_virtf *vf;
1611 struct bnx2x_vf_mbx *mbx;
1616 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1617 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1618 /* Sanity checks consider removing later */
1620 /* check if the vf_id is valid */
1621 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1622 BNX2X_NR_VIRTFN(bp)) {
1623 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1624 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1627 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1628 mbx = BP_VF_MBX(bp, vf_idx);
1630 /* verify an event is not currently being processed -
1631 * debug failsafe only
1633 if (mbx->flags & VF_MSG_INPROCESS) {
1634 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1638 vf = BP_VF(bp, vf_idx);
1640 /* save the VF message address */
1641 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1642 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1643 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1644 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1646 /* dmae to get the VF request */
1647 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1648 mbx->vf_addr_hi, mbx->vf_addr_lo,
1649 sizeof(union vfpf_tlvs)/4);
1651 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1655 /* process the VF message header */
1656 mbx->first_tlv = mbx->msg->req.first_tlv;
1658 /* dispatch the request (will prepare the response) */
1659 bnx2x_vf_mbx_request(bp, vf, mbx);
1663 bnx2x_vf_release(bp, vf, false); /* non blocking */
1668 /* propagate local bulletin board to vf */
1669 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1671 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1672 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1673 vf * BULLETIN_CONTENT_SIZE;
1674 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1677 /* can only update vf after init took place */
1678 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1679 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1682 /* increment bulletin board version and compute crc */
1683 bulletin->version++;
1684 bulletin->length = BULLETIN_CONTENT_SIZE;
1685 bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1687 /* propagate bulletin board via dmae to vm memory */
1688 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1689 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
1690 U64_LO(vf_addr), bulletin->length / 4);