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 DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
43 memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
45 /* init type and length */
46 bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
48 /* init first tlv header */
49 first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
52 /* list the types and lengths of the tlvs on the buffer */
53 void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
56 struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
58 while (tlv->type != CHANNEL_TLV_LIST_END) {
60 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
61 tlv->type, tlv->length);
63 /* advance to next tlv */
64 tlvs_list += tlv->length;
66 /* cast general tlv list pointer to channel tlv header*/
67 tlv = (struct channel_tlv *)tlvs_list;
71 /* break condition for this loop */
72 if (i > MAX_TLVS_IN_LIST) {
73 WARN(true, "corrupt tlvs");
79 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
80 tlv->type, tlv->length);
83 /* test whether we support a tlv type */
84 bool bnx2x_tlv_supported(u16 tlvtype)
86 return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
89 static inline int bnx2x_pfvf_status_codes(int rc)
93 return PFVF_STATUS_SUCCESS;
95 return PFVF_STATUS_NO_RESOURCE;
97 return PFVF_STATUS_FAILURE;
101 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
103 struct cstorm_vf_zone_data __iomem *zone_data =
104 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
105 int tout = 600, interval = 100; /* wait for 60 seconds */
108 BNX2X_ERR("done was non zero before message to pf was sent\n");
113 /* Write message address */
114 writel(U64_LO(msg_mapping),
115 &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
116 writel(U64_HI(msg_mapping),
117 &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
119 /* make sure the address is written before FW accesses it */
122 /* Trigger the PF FW */
123 writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
125 /* Wait for PF to complete */
126 while ((tout >= 0) && (!*done)) {
130 /* progress indicator - HV can take its own sweet time in
133 DP_CONT(BNX2X_MSG_IOV, ".");
137 BNX2X_ERR("PF response has timed out\n");
140 DP(BNX2X_MSG_SP, "Got a response from PF\n");
144 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
147 int tout = 10, interval = 100; /* Wait for 1 sec */
150 /* pxp traps vf read of doorbells and returns me reg value */
151 me_reg = readl(bp->doorbells);
152 if (GOOD_ME_REG(me_reg))
157 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
159 } while (tout-- > 0);
161 if (!GOOD_ME_REG(me_reg)) {
162 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
166 BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
168 *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
173 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
175 int rc = 0, attempts = 0;
176 struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
177 struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
179 bool resources_acquired = false;
181 /* clear mailbox and prep first tlv */
182 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
184 if (bnx2x_get_vf_id(bp, &vf_id))
187 req->vfdev_info.vf_id = vf_id;
188 req->vfdev_info.vf_os = 0;
190 req->resc_request.num_rxqs = rx_count;
191 req->resc_request.num_txqs = tx_count;
192 req->resc_request.num_sbs = bp->igu_sb_cnt;
193 req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
194 req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
196 /* pf 2 vf bulletin board address */
197 req->bulletin_addr = bp->pf2vf_bulletin_mapping;
199 /* add list termination tlv */
200 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
201 sizeof(struct channel_list_end_tlv));
203 /* output tlvs list */
204 bnx2x_dp_tlv_list(bp, req);
206 while (!resources_acquired) {
207 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
209 /* send acquire request */
210 rc = bnx2x_send_msg2pf(bp,
212 bp->vf2pf_mbox_mapping);
218 /* copy acquire response from buffer to bp */
219 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
223 /* test whether the PF accepted our request. If not, humble the
224 * the request and try again.
226 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
227 DP(BNX2X_MSG_SP, "resources acquired\n");
228 resources_acquired = true;
229 } else if (bp->acquire_resp.hdr.status ==
230 PFVF_STATUS_NO_RESOURCE &&
231 attempts < VF_ACQUIRE_THRESH) {
233 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
235 /* humble our request */
236 req->resc_request.num_txqs =
237 bp->acquire_resp.resc.num_txqs;
238 req->resc_request.num_rxqs =
239 bp->acquire_resp.resc.num_rxqs;
240 req->resc_request.num_sbs =
241 bp->acquire_resp.resc.num_sbs;
242 req->resc_request.num_mac_filters =
243 bp->acquire_resp.resc.num_mac_filters;
244 req->resc_request.num_vlan_filters =
245 bp->acquire_resp.resc.num_vlan_filters;
246 req->resc_request.num_mc_filters =
247 bp->acquire_resp.resc.num_mc_filters;
249 /* Clear response buffer */
250 memset(&bp->vf2pf_mbox->resp, 0,
251 sizeof(union pfvf_tlvs));
253 /* PF reports error */
254 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
255 bp->acquire_resp.hdr.status);
261 bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
262 bp->link_params.chip_id = bp->common.chip_id;
263 bp->db_size = bp->acquire_resp.pfdev_info.db_size;
264 bp->common.int_block = INT_BLOCK_IGU;
265 bp->common.chip_port_mode = CHIP_2_PORT_MODE;
269 bp->common.flash_size = 0;
271 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
273 bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
274 strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
277 if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
278 memcpy(bp->dev->dev_addr,
279 bp->acquire_resp.resc.current_mac_addr,
285 int bnx2x_vfpf_release(struct bnx2x *bp)
287 struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
288 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
291 /* clear mailbox and prep first tlv */
292 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
294 if (bnx2x_get_vf_id(bp, &vf_id))
299 /* add list termination tlv */
300 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
301 sizeof(struct channel_list_end_tlv));
303 /* output tlvs list */
304 bnx2x_dp_tlv_list(bp, req);
306 /* send release request */
307 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
312 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
314 DP(BNX2X_MSG_SP, "vf released\n");
316 /* PF reports error */
317 BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
325 /* Tell PF about SB addresses */
326 int bnx2x_vfpf_init(struct bnx2x *bp)
328 struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
329 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
332 /* clear mailbox and prep first tlv */
333 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
336 for_each_eth_queue(bp, i)
337 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
340 /* statistics - requests only supports single queue for now */
341 req->stats_addr = bp->fw_stats_data_mapping +
342 offsetof(struct bnx2x_fw_stats_data, queue_stats);
344 /* add list termination tlv */
345 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
346 sizeof(struct channel_list_end_tlv));
348 /* output tlvs list */
349 bnx2x_dp_tlv_list(bp, req);
351 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
355 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
356 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
361 DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
365 /* CLOSE VF - opposite to INIT_VF */
366 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
368 struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
369 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
373 /* If we haven't got a valid VF id, there is no sense to
374 * continue with sending messages
376 if (bnx2x_get_vf_id(bp, &vf_id))
379 /* Close the queues */
380 for_each_queue(bp, i)
381 bnx2x_vfpf_teardown_queue(bp, i);
383 /* clear mailbox and prep first tlv */
384 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
388 /* add list termination tlv */
389 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
390 sizeof(struct channel_list_end_tlv));
392 /* output tlvs list */
393 bnx2x_dp_tlv_list(bp, req);
395 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
398 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
400 else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
401 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
405 /* Disable HW interrupts, NAPI */
406 bnx2x_netif_stop(bp, 0);
407 /* Delete all NAPI objects */
408 bnx2x_del_all_napi(bp);
414 /* ask the pf to open a queue for the vf */
415 int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
417 struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
418 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
419 struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
420 u16 tpa_agg_size = 0, flags = 0;
423 /* clear mailbox and prep first tlv */
424 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
426 /* select tpa mode to request */
427 if (!fp->disable_tpa) {
428 flags |= VFPF_QUEUE_FLG_TPA;
429 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
430 if (fp->mode == TPA_MODE_GRO)
431 flags |= VFPF_QUEUE_FLG_TPA_GRO;
432 tpa_agg_size = TPA_AGG_SIZE;
435 /* calculate queue flags */
436 flags |= VFPF_QUEUE_FLG_STATS;
437 flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
438 flags |= IS_MF_SD(bp) ? VFPF_QUEUE_FLG_OV : 0;
439 flags |= VFPF_QUEUE_FLG_VLAN;
440 DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
443 req->vf_qid = fp_idx;
444 req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
447 req->rxq.rcq_addr = fp->rx_comp_mapping;
448 req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
449 req->rxq.rxq_addr = fp->rx_desc_mapping;
450 req->rxq.sge_addr = fp->rx_sge_mapping;
451 req->rxq.vf_sb = fp_idx;
452 req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
453 req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
454 req->rxq.mtu = bp->dev->mtu;
455 req->rxq.buf_sz = fp->rx_buf_size;
456 req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
457 req->rxq.tpa_agg_sz = tpa_agg_size;
458 req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
459 req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
460 (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
461 req->rxq.flags = flags;
462 req->rxq.drop_flags = 0;
463 req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
464 req->rxq.stat_id = -1; /* No stats at the moment */
467 req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
468 req->txq.vf_sb = fp_idx;
469 req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
470 req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
471 req->txq.flags = flags;
472 req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
474 /* add list termination tlv */
475 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
476 sizeof(struct channel_list_end_tlv));
478 /* output tlvs list */
479 bnx2x_dp_tlv_list(bp, req);
481 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
483 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
486 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
487 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
488 fp_idx, resp->hdr.status);
494 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
496 struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
497 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
500 /* clear mailbox and prep first tlv */
501 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
506 /* add list termination tlv */
507 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
508 sizeof(struct channel_list_end_tlv));
510 /* output tlvs list */
511 bnx2x_dp_tlv_list(bp, req);
513 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
516 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
521 /* PF failed the transaction */
522 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
523 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
531 /* request pf to add a mac for the vf */
532 int bnx2x_vfpf_set_mac(struct bnx2x *bp)
534 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
535 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
538 /* clear mailbox and prep first tlv */
539 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
542 req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
544 req->n_mac_vlan_filters = 1;
545 req->filters[0].flags =
546 VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
548 /* sample bulletin board for new mac */
549 bnx2x_sample_bulletin(bp);
551 /* copy mac from device to request */
552 memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
554 /* add list termination tlv */
555 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
556 sizeof(struct channel_list_end_tlv));
558 /* output tlvs list */
559 bnx2x_dp_tlv_list(bp, req);
561 /* send message to pf */
562 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
564 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
568 /* failure may mean PF was configured with a new mac for us */
569 while (resp->hdr.status == PFVF_STATUS_FAILURE) {
571 "vfpf SET MAC failed. Check bulletin board for new posts\n");
573 /* check if bulletin board was updated */
574 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
575 /* copy mac from device to request */
576 memcpy(req->filters[0].mac, bp->dev->dev_addr,
579 /* send message to pf */
580 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
581 bp->vf2pf_mbox_mapping);
583 /* no new info in bulletin */
588 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
589 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
596 int bnx2x_vfpf_set_mcast(struct net_device *dev)
598 struct bnx2x *bp = netdev_priv(dev);
599 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
600 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
602 struct netdev_hw_addr *ha;
604 if (bp->state != BNX2X_STATE_OPEN) {
605 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
609 /* clear mailbox and prep first tlv */
610 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
613 /* Get Rx mode requested */
614 DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
616 netdev_for_each_mc_addr(ha, dev) {
617 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
619 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
623 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
626 if (i >= PFVF_MAX_MULTICAST_PER_VF) {
628 "VF supports not more than %d multicast MAC addresses\n",
629 PFVF_MAX_MULTICAST_PER_VF);
633 req->n_multicast = i;
634 req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
637 /* add list termination tlv */
638 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
639 sizeof(struct channel_list_end_tlv));
641 /* output tlvs list */
642 bnx2x_dp_tlv_list(bp, req);
643 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
645 BNX2X_ERR("Sending a message failed: %d\n", rc);
649 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
650 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
658 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
660 int mode = bp->rx_mode;
661 struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
662 struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
665 /* clear mailbox and prep first tlv */
666 bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
669 DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
672 case BNX2X_RX_MODE_NONE: /* no Rx */
673 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
675 case BNX2X_RX_MODE_NORMAL:
676 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
677 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
678 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
680 case BNX2X_RX_MODE_ALLMULTI:
681 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
682 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
683 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
685 case BNX2X_RX_MODE_PROMISC:
686 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
687 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
688 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
691 BNX2X_ERR("BAD rx mode (%d)\n", mode);
695 req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
698 /* add list termination tlv */
699 bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
700 sizeof(struct channel_list_end_tlv));
702 /* output tlvs list */
703 bnx2x_dp_tlv_list(bp, req);
705 rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
707 BNX2X_ERR("Sending a message failed: %d\n", rc);
709 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
710 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
717 /* General service functions */
718 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
720 u32 addr = BAR_CSTRORM_INTMEM +
721 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
723 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
726 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
728 u32 addr = BAR_CSTRORM_INTMEM +
729 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
731 REG_WR8(bp, addr, 1);
734 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
739 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
742 /* enable vf_pf mailbox (aka vf-pf-chanell) */
743 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
745 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
747 /* enable the mailbox in the FW */
748 storm_memset_vf_mbx_ack(bp, abs_vfid);
749 storm_memset_vf_mbx_valid(bp, abs_vfid);
751 /* enable the VF access to the mailbox */
752 bnx2x_vf_enable_access(bp, abs_vfid);
755 /* this works only on !E1h */
756 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
757 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
758 u32 vf_addr_lo, u32 len32)
760 struct dmae_command dmae;
762 if (CHIP_IS_E1x(bp)) {
763 BNX2X_ERR("Chip revision does not support VFs\n");
767 if (!bp->dmae_ready) {
768 BNX2X_ERR("DMAE is not ready, can not copy\n");
772 /* set opcode and fixed command fields */
773 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
776 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
777 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
778 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
780 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
782 dmae.src_addr_lo = vf_addr_lo;
783 dmae.src_addr_hi = vf_addr_hi;
784 dmae.dst_addr_lo = U64_LO(pf_addr);
785 dmae.dst_addr_hi = U64_HI(pf_addr);
787 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
788 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
789 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
791 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
793 dmae.src_addr_lo = U64_LO(pf_addr);
794 dmae.src_addr_hi = U64_HI(pf_addr);
795 dmae.dst_addr_lo = vf_addr_lo;
796 dmae.dst_addr_hi = vf_addr_hi;
799 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
801 /* issue the command and wait for completion */
802 return bnx2x_issue_dmae_with_comp(bp, &dmae);
805 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
807 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
812 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
814 /* prepare response */
815 type = mbx->first_tlv.tl.type;
816 length = type == CHANNEL_TLV_ACQUIRE ?
817 sizeof(struct pfvf_acquire_resp_tlv) :
818 sizeof(struct pfvf_general_resp_tlv);
819 bnx2x_add_tlv(bp, resp, 0, type, length);
820 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
821 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
822 sizeof(struct channel_list_end_tlv));
823 bnx2x_dp_tlv_list(bp, resp);
824 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
825 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
828 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
829 mbx->first_tlv.resp_msg_offset;
830 pf_addr = mbx->msg_mapping +
831 offsetof(struct bnx2x_vf_mbx_msg, resp);
833 /* copy the response body, if there is one, before the header, as the vf
834 * is sensitive to the header being written
836 if (resp->hdr.tl.length > sizeof(u64)) {
837 length = resp->hdr.tl.length - sizeof(u64);
838 vf_addr += sizeof(u64);
839 pf_addr += sizeof(u64);
840 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
845 BNX2X_ERR("Failed to copy response body to VF %d\n",
849 vf_addr -= sizeof(u64);
850 pf_addr -= sizeof(u64);
854 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
857 /* initiate dmae to send the response */
858 mbx->flags &= ~VF_MSG_INPROCESS;
860 /* copy the response header including status-done field,
861 * must be last dmae, must be after FW is acked
863 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
868 /* unlock channel mutex */
869 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
872 BNX2X_ERR("Failed to copy response status to VF %d\n",
879 bnx2x_vf_release(bp, vf, false); /* non blocking */
882 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
883 struct bnx2x_vf_mbx *mbx, int vfop_status)
886 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
887 struct pf_vf_resc *resc = &resp->resc;
888 u8 status = bnx2x_pfvf_status_codes(vfop_status);
890 memset(resp, 0, sizeof(*resp));
892 /* fill in pfdev info */
893 resp->pfdev_info.chip_num = bp->common.chip_id;
894 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
895 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
896 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
897 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
898 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
899 sizeof(resp->pfdev_info.fw_ver));
901 if (status == PFVF_STATUS_NO_RESOURCE ||
902 status == PFVF_STATUS_SUCCESS) {
903 /* set resources numbers, if status equals NO_RESOURCE these
904 * are max possible numbers
906 resc->num_rxqs = vf_rxq_count(vf) ? :
907 bnx2x_vf_max_queue_cnt(bp, vf);
908 resc->num_txqs = vf_txq_count(vf) ? :
909 bnx2x_vf_max_queue_cnt(bp, vf);
910 resc->num_sbs = vf_sb_count(vf);
911 resc->num_mac_filters = vf_mac_rules_cnt(vf);
912 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
913 resc->num_mc_filters = 0;
915 if (status == PFVF_STATUS_SUCCESS) {
916 /* fill in the allocated resources */
917 struct pf_vf_bulletin_content *bulletin =
918 BP_VF_BULLETIN(bp, vf->index);
922 vfq_qzone_id(vf, vfq_get(vf, i));
924 for_each_vf_sb(vf, i) {
925 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
926 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
929 /* if a mac has been set for this vf, supply it */
930 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
931 memcpy(resc->current_mac_addr, bulletin->mac,
937 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"
938 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
940 resp->pfdev_info.chip_num,
941 resp->pfdev_info.db_size,
942 resp->pfdev_info.indices_per_sb,
943 resp->pfdev_info.pf_cap,
947 resc->num_mac_filters,
948 resc->num_vlan_filters,
949 resc->num_mc_filters,
950 resp->pfdev_info.fw_ver);
952 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
953 for (i = 0; i < vf_rxq_count(vf); i++)
954 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
955 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
956 for (i = 0; i < vf_sb_count(vf); i++)
957 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
958 resc->hw_sbs[i].hw_sb_id,
959 resc->hw_sbs[i].sb_qid);
960 DP_CONT(BNX2X_MSG_IOV, "]\n");
962 /* send the response */
963 vf->op_rc = vfop_status;
964 bnx2x_vf_mbx_resp(bp, vf);
967 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
968 struct bnx2x_vf_mbx *mbx)
971 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
975 "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",
976 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
977 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
978 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
979 acquire->resc_request.num_vlan_filters,
980 acquire->resc_request.num_mc_filters);
982 /* acquire the resources */
983 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
985 /* store address of vf's bulletin board */
986 vf->bulletin_map = acquire->bulletin_addr;
989 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
992 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
993 struct bnx2x_vf_mbx *mbx)
995 struct vfpf_init_tlv *init = &mbx->msg->req.init;
997 /* record ghost addresses from vf message */
998 vf->spq_map = init->spq_addr;
999 vf->fw_stat_map = init->stats_addr;
1000 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1003 bnx2x_vf_mbx_resp(bp, vf);
1006 /* convert MBX queue-flags to standard SP queue-flags */
1007 static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags,
1008 unsigned long *sp_q_flags)
1010 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1011 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1012 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1013 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1014 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1015 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1016 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1017 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1018 if (mbx_q_flags & VFPF_QUEUE_FLG_OV)
1019 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1020 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1021 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1022 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1023 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1024 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1025 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1026 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1027 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1030 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1031 struct bnx2x_vf_mbx *mbx)
1033 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1034 struct bnx2x_vfop_cmd cmd = {
1035 .done = bnx2x_vf_mbx_resp,
1040 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1041 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1042 setup_q->vf_qid, vf_rxq_count(vf));
1043 vf->op_rc = -EINVAL;
1047 /* tx queues must be setup alongside rx queues thus if the rx queue
1048 * is not marked as valid there's nothing to do.
1050 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1051 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1052 unsigned long q_type = 0;
1054 struct bnx2x_queue_init_params *init_p;
1055 struct bnx2x_queue_setup_params *setup_p;
1057 /* reinit the VF operation context */
1058 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1059 setup_p = &vf->op_params.qctor.prep_qsetup;
1060 init_p = &vf->op_params.qctor.qstate.params.init;
1062 /* activate immediately */
1063 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1065 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1066 struct bnx2x_txq_setup_params *txq_params =
1067 &setup_p->txq_params;
1069 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1071 /* save sb resource index */
1072 q->sb_idx = setup_q->txq.vf_sb;
1075 init_p->tx.hc_rate = setup_q->txq.hc_rate;
1076 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1078 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
1081 /* tx setup - flags */
1082 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
1085 /* tx setup - general, nothing */
1088 txq_params->dscr_map = setup_q->txq.txq_addr;
1089 txq_params->sb_cq_index = setup_q->txq.sb_index;
1090 txq_params->traffic_type = setup_q->txq.traffic_type;
1092 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1093 q->index, q->sb_idx);
1096 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1097 struct bnx2x_rxq_setup_params *rxq_params =
1098 &setup_p->rxq_params;
1100 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1102 /* Note: there is no support for different SBs
1105 q->sb_idx = setup_q->rxq.vf_sb;
1108 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1109 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1110 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
1113 /* rx setup - flags */
1114 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
1117 /* rx setup - general */
1118 setup_p->gen_params.mtu = setup_q->rxq.mtu;
1121 rxq_params->drop_flags = setup_q->rxq.drop_flags;
1122 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1123 rxq_params->sge_map = setup_q->rxq.sge_addr;
1124 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1125 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1126 rxq_params->buf_sz = setup_q->rxq.buf_sz;
1127 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1128 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1129 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1130 rxq_params->cache_line_log =
1131 setup_q->rxq.cache_line_log;
1132 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1134 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1135 q->index, q->sb_idx);
1137 /* complete the preparations */
1138 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1140 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1146 bnx2x_vf_mbx_resp(bp, vf);
1149 enum bnx2x_vfop_filters_state {
1150 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1151 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1152 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1153 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1154 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1157 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1158 struct bnx2x_virtf *vf,
1159 struct vfpf_set_q_filters_tlv *tlv,
1160 struct bnx2x_vfop_filters **pfl,
1164 struct bnx2x_vfop_filters *fl = NULL;
1167 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1168 sizeof(struct bnx2x_vfop_filters);
1170 fl = kzalloc(fsz, GFP_KERNEL);
1174 INIT_LIST_HEAD(&fl->head);
1176 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1177 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1179 if ((msg_filter->flags & type_flag) != type_flag)
1181 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1182 fl->filters[j].mac = msg_filter->mac;
1183 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1185 fl->filters[j].vid = msg_filter->vlan_tag;
1186 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1188 fl->filters[j].add =
1189 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1191 list_add_tail(&fl->filters[j++].link, &fl->head);
1193 if (list_empty(&fl->head))
1201 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1202 struct vfpf_q_mac_vlan_filter *filter)
1204 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1205 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1206 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1207 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1208 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1209 DP_CONT(msglvl, "\n");
1212 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1213 struct vfpf_set_q_filters_tlv *filters)
1217 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1218 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1219 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1220 &filters->filters[i]);
1222 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1223 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1225 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1226 for (i = 0; i < filters->n_multicast; i++)
1227 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1230 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1231 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1233 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1237 struct vfpf_set_q_filters_tlv *msg =
1238 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1240 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1241 enum bnx2x_vfop_filters_state state = vfop->state;
1243 struct bnx2x_vfop_cmd cmd = {
1244 .done = bnx2x_vfop_mbx_qfilters,
1248 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1254 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1256 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1258 /* check for any vlan/mac changes */
1259 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1260 /* build mac list */
1261 struct bnx2x_vfop_filters *fl = NULL;
1263 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1270 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1282 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1284 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1286 /* check for any vlan/mac changes */
1287 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1288 /* build vlan list */
1289 struct bnx2x_vfop_filters *fl = NULL;
1291 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1298 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1310 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1312 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1314 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1315 unsigned long accept = 0;
1317 /* covert VF-PF if mask to bnx2x accept flags */
1318 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1319 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1322 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1323 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1325 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1326 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1328 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1329 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1331 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1332 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1334 /* A packet arriving the vf's mac should be accepted
1337 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1340 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1341 msg->vf_qid, accept);
1350 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1352 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1354 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1356 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1357 msg->n_multicast, false);
1366 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1367 bnx2x_vfop_end(bp, vf, vfop);
1370 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1371 vf->abs_vfid, msg->vf_qid, vfop->rc);
1375 bnx2x_vfop_default(state);
1379 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1380 struct bnx2x_virtf *vf,
1381 struct bnx2x_vfop_cmd *cmd)
1383 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1385 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1386 bnx2x_vfop_mbx_qfilters, cmd->done);
1387 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1393 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1394 struct bnx2x_virtf *vf,
1395 struct bnx2x_vf_mbx *mbx)
1397 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1398 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1399 struct bnx2x_vfop_cmd cmd = {
1400 .done = bnx2x_vf_mbx_resp,
1404 /* if a mac was already set for this VF via the set vf mac ndo, we only
1405 * accept mac configurations of that mac. Why accept them at all?
1406 * because PF may have been unable to configure the mac at the time
1407 * since queue was not set up.
1409 if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1410 /* once a mac was set by ndo can only accept a single mac... */
1411 if (filters->n_mac_vlan_filters > 1) {
1412 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1418 /* ...and only the mac set by the ndo */
1419 if (filters->n_mac_vlan_filters == 1 &&
1420 memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1421 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1430 if (filters->vf_qid > vf_rxq_count(vf))
1433 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1437 /* print q_filter message */
1438 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1440 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1446 bnx2x_vf_mbx_resp(bp, vf);
1449 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1450 struct bnx2x_vf_mbx *mbx)
1452 int qid = mbx->msg->req.q_op.vf_qid;
1453 struct bnx2x_vfop_cmd cmd = {
1454 .done = bnx2x_vf_mbx_resp,
1458 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1461 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1463 bnx2x_vf_mbx_resp(bp, vf);
1466 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1467 struct bnx2x_vf_mbx *mbx)
1469 struct bnx2x_vfop_cmd cmd = {
1470 .done = bnx2x_vf_mbx_resp,
1474 DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1476 vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1478 bnx2x_vf_mbx_resp(bp, vf);
1481 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1482 struct bnx2x_vf_mbx *mbx)
1484 struct bnx2x_vfop_cmd cmd = {
1485 .done = bnx2x_vf_mbx_resp,
1489 DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1491 vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1493 bnx2x_vf_mbx_resp(bp, vf);
1496 /* dispatch request */
1497 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1498 struct bnx2x_vf_mbx *mbx)
1502 /* check if tlv type is known */
1503 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1504 /* Lock the per vf op mutex and note the locker's identity.
1505 * The unlock will take place in mbx response.
1507 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1509 /* switch on the opcode */
1510 switch (mbx->first_tlv.tl.type) {
1511 case CHANNEL_TLV_ACQUIRE:
1512 bnx2x_vf_mbx_acquire(bp, vf, mbx);
1514 case CHANNEL_TLV_INIT:
1515 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1517 case CHANNEL_TLV_SETUP_Q:
1518 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1520 case CHANNEL_TLV_SET_Q_FILTERS:
1521 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1523 case CHANNEL_TLV_TEARDOWN_Q:
1524 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1526 case CHANNEL_TLV_CLOSE:
1527 bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1529 case CHANNEL_TLV_RELEASE:
1530 bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1535 /* unknown TLV - this may belong to a VF driver from the future
1536 * - a version written after this PF driver was written, which
1537 * supports features unknown as of yet. Too bad since we don't
1538 * support them. Or this may be because someone wrote a crappy
1539 * VF driver and is sending garbage over the channel.
1541 BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
1542 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
1543 for (i = 0; i < 20; i++)
1544 DP_CONT(BNX2X_MSG_IOV, "%x ",
1545 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1547 /* test whether we can respond to the VF (do we have an address
1550 if (vf->state == VF_ACQUIRED) {
1551 /* mbx_resp uses the op_rc of the VF */
1552 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1554 /* notify the VF that we do not support this request */
1555 bnx2x_vf_mbx_resp(bp, vf);
1557 /* can't send a response since this VF is unknown to us
1558 * just unlock the channel and be done with.
1560 bnx2x_unlock_vf_pf_channel(bp, vf,
1561 mbx->first_tlv.tl.type);
1566 /* handle new vf-pf message */
1567 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1569 struct bnx2x_virtf *vf;
1570 struct bnx2x_vf_mbx *mbx;
1575 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1576 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1577 /* Sanity checks consider removing later */
1579 /* check if the vf_id is valid */
1580 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1581 BNX2X_NR_VIRTFN(bp)) {
1582 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1583 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1586 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1587 mbx = BP_VF_MBX(bp, vf_idx);
1589 /* verify an event is not currently being processed -
1590 * debug failsafe only
1592 if (mbx->flags & VF_MSG_INPROCESS) {
1593 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1597 vf = BP_VF(bp, vf_idx);
1599 /* save the VF message address */
1600 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1601 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1602 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1603 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1605 /* dmae to get the VF request */
1606 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1607 mbx->vf_addr_hi, mbx->vf_addr_lo,
1608 sizeof(union vfpf_tlvs)/4);
1610 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1614 /* process the VF message header */
1615 mbx->first_tlv = mbx->msg->req.first_tlv;
1617 /* dispatch the request (will prepare the response) */
1618 bnx2x_vf_mbx_request(bp, vf, mbx);
1622 bnx2x_vf_release(bp, vf, false); /* non blocking */
1627 /* propagate local bulletin board to vf */
1628 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1630 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1631 dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1632 vf * BULLETIN_CONTENT_SIZE;
1633 dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1636 /* can only update vf after init took place */
1637 if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1638 bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1641 /* increment bulletin board version and compute crc */
1642 bulletin->version++;
1643 bulletin->length = BULLETIN_CONTENT_SIZE;
1644 bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1646 /* propagate bulletin board via dmae to vm memory */
1647 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1648 bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
1649 U64_LO(vf_addr), bulletin->length / 4);