1 /* bnx2x_vfpf.c: Broadcom Everest network driver.
3 * Copyright 2009-2013 Broadcom Corporation
5 * Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2, available
8 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
10 * Notwithstanding the above, under no circumstances may you combine this
11 * software in any way with any other Broadcom software provided under a
12 * license other than the GPL, without Broadcom's express prior written
15 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16 * Written by: Shmulik Ravid <shmulikr@broadcom.com>
17 * Ariel Elior <ariele@broadcom.com>
21 #include "bnx2x_cmn.h"
22 #include <linux/crc32.h>
24 /* place a given tlv on the tlv buffer at a given offset */
25 void bnx2x_add_tlv(struct bnx2x
*bp
, void *tlvs_list
, u16 offset
, u16 type
,
28 struct channel_tlv
*tl
=
29 (struct channel_tlv
*)(tlvs_list
+ offset
);
35 /* Clear the mailbox and init the header of the first tlv */
36 void bnx2x_vfpf_prep(struct bnx2x
*bp
, struct vfpf_first_tlv
*first_tlv
,
39 mutex_lock(&bp
->vf2pf_mutex
);
41 DP(BNX2X_MSG_IOV
, "preparing to send %d tlv over vf pf channel\n",
45 memset(bp
->vf2pf_mbox
, 0, sizeof(struct bnx2x_vf_mbx_msg
));
47 /* init type and length */
48 bnx2x_add_tlv(bp
, &first_tlv
->tl
, 0, type
, length
);
50 /* init first tlv header */
51 first_tlv
->resp_msg_offset
= sizeof(bp
->vf2pf_mbox
->req
);
54 /* releases the mailbox */
55 void bnx2x_vfpf_finalize(struct bnx2x
*bp
, struct vfpf_first_tlv
*first_tlv
)
57 DP(BNX2X_MSG_IOV
, "done sending [%d] tlv over vf pf channel\n",
60 mutex_unlock(&bp
->vf2pf_mutex
);
63 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
64 static void *bnx2x_search_tlv_list(struct bnx2x
*bp
, void *tlvs_list
,
65 enum channel_tlvs req_tlv
)
67 struct channel_tlv
*tlv
= (struct channel_tlv
*)tlvs_list
;
70 if (tlv
->type
== req_tlv
)
74 BNX2X_ERR("Found TLV with length 0\n");
78 tlvs_list
+= tlv
->length
;
79 tlv
= (struct channel_tlv
*)tlvs_list
;
80 } while (tlv
->type
!= CHANNEL_TLV_LIST_END
);
82 DP(BNX2X_MSG_IOV
, "TLV list does not contain %d TLV\n", req_tlv
);
87 /* list the types and lengths of the tlvs on the buffer */
88 void bnx2x_dp_tlv_list(struct bnx2x
*bp
, void *tlvs_list
)
91 struct channel_tlv
*tlv
= (struct channel_tlv
*)tlvs_list
;
93 while (tlv
->type
!= CHANNEL_TLV_LIST_END
) {
95 DP(BNX2X_MSG_IOV
, "TLV number %d: type %d, length %d\n", i
,
96 tlv
->type
, tlv
->length
);
98 /* advance to next tlv */
99 tlvs_list
+= tlv
->length
;
101 /* cast general tlv list pointer to channel tlv header*/
102 tlv
= (struct channel_tlv
*)tlvs_list
;
106 /* break condition for this loop */
107 if (i
> MAX_TLVS_IN_LIST
) {
108 WARN(true, "corrupt tlvs");
113 /* output last tlv */
114 DP(BNX2X_MSG_IOV
, "TLV number %d: type %d, length %d\n", i
,
115 tlv
->type
, tlv
->length
);
118 /* test whether we support a tlv type */
119 bool bnx2x_tlv_supported(u16 tlvtype
)
121 return CHANNEL_TLV_NONE
< tlvtype
&& tlvtype
< CHANNEL_TLV_MAX
;
124 static inline int bnx2x_pfvf_status_codes(int rc
)
128 return PFVF_STATUS_SUCCESS
;
130 return PFVF_STATUS_NO_RESOURCE
;
132 return PFVF_STATUS_FAILURE
;
136 static int bnx2x_send_msg2pf(struct bnx2x
*bp
, u8
*done
, dma_addr_t msg_mapping
)
138 struct cstorm_vf_zone_data __iomem
*zone_data
=
139 REG_ADDR(bp
, PXP_VF_ADDR_CSDM_GLOBAL_START
);
140 int tout
= 100, interval
= 100; /* wait for 10 seconds */
143 BNX2X_ERR("done was non zero before message to pf was sent\n");
148 /* if PF indicated channel is down avoid sending message. Return success
149 * so calling flow can continue
151 bnx2x_sample_bulletin(bp
);
152 if (bp
->old_bulletin
.valid_bitmap
& 1 << CHANNEL_DOWN
) {
153 DP(BNX2X_MSG_IOV
, "detecting channel down. Aborting message\n");
154 *done
= PFVF_STATUS_SUCCESS
;
158 /* Write message address */
159 writel(U64_LO(msg_mapping
),
160 &zone_data
->non_trigger
.vf_pf_channel
.msg_addr_lo
);
161 writel(U64_HI(msg_mapping
),
162 &zone_data
->non_trigger
.vf_pf_channel
.msg_addr_hi
);
164 /* make sure the address is written before FW accesses it */
167 /* Trigger the PF FW */
168 writeb(1, &zone_data
->trigger
.vf_pf_channel
.addr_valid
);
170 /* Wait for PF to complete */
171 while ((tout
>= 0) && (!*done
)) {
175 /* progress indicator - HV can take its own sweet time in
178 DP_CONT(BNX2X_MSG_IOV
, ".");
182 BNX2X_ERR("PF response has timed out\n");
185 DP(BNX2X_MSG_SP
, "Got a response from PF\n");
189 static int bnx2x_get_vf_id(struct bnx2x
*bp
, u32
*vf_id
)
192 int tout
= 10, interval
= 100; /* Wait for 1 sec */
195 /* pxp traps vf read of doorbells and returns me reg value */
196 me_reg
= readl(bp
->doorbells
);
197 if (GOOD_ME_REG(me_reg
))
202 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
204 } while (tout
-- > 0);
206 if (!GOOD_ME_REG(me_reg
)) {
207 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg
);
211 DP(BNX2X_MSG_IOV
, "valid ME register value: 0x%08x\n", me_reg
);
213 *vf_id
= (me_reg
& ME_REG_VF_NUM_MASK
) >> ME_REG_VF_NUM_SHIFT
;
218 int bnx2x_vfpf_acquire(struct bnx2x
*bp
, u8 tx_count
, u8 rx_count
)
220 int rc
= 0, attempts
= 0;
221 struct vfpf_acquire_tlv
*req
= &bp
->vf2pf_mbox
->req
.acquire
;
222 struct pfvf_acquire_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.acquire_resp
;
223 struct vfpf_port_phys_id_resp_tlv
*phys_port_resp
;
225 bool resources_acquired
= false;
227 /* clear mailbox and prep first tlv */
228 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_ACQUIRE
, sizeof(*req
));
230 if (bnx2x_get_vf_id(bp
, &vf_id
)) {
235 req
->vfdev_info
.vf_id
= vf_id
;
236 req
->vfdev_info
.vf_os
= 0;
238 req
->resc_request
.num_rxqs
= rx_count
;
239 req
->resc_request
.num_txqs
= tx_count
;
240 req
->resc_request
.num_sbs
= bp
->igu_sb_cnt
;
241 req
->resc_request
.num_mac_filters
= VF_ACQUIRE_MAC_FILTERS
;
242 req
->resc_request
.num_mc_filters
= VF_ACQUIRE_MC_FILTERS
;
244 /* pf 2 vf bulletin board address */
245 req
->bulletin_addr
= bp
->pf2vf_bulletin_mapping
;
247 /* Request physical port identifier */
248 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
,
249 CHANNEL_TLV_PHYS_PORT_ID
, sizeof(struct channel_tlv
));
251 /* add list termination tlv */
252 bnx2x_add_tlv(bp
, req
,
253 req
->first_tlv
.tl
.length
+ sizeof(struct channel_tlv
),
254 CHANNEL_TLV_LIST_END
,
255 sizeof(struct channel_list_end_tlv
));
257 /* output tlvs list */
258 bnx2x_dp_tlv_list(bp
, req
);
260 while (!resources_acquired
) {
261 DP(BNX2X_MSG_SP
, "attempting to acquire resources\n");
263 /* send acquire request */
264 rc
= bnx2x_send_msg2pf(bp
,
266 bp
->vf2pf_mbox_mapping
);
272 /* copy acquire response from buffer to bp */
273 memcpy(&bp
->acquire_resp
, resp
, sizeof(bp
->acquire_resp
));
277 /* test whether the PF accepted our request. If not, humble
278 * the request and try again.
280 if (bp
->acquire_resp
.hdr
.status
== PFVF_STATUS_SUCCESS
) {
281 DP(BNX2X_MSG_SP
, "resources acquired\n");
282 resources_acquired
= true;
283 } else if (bp
->acquire_resp
.hdr
.status
==
284 PFVF_STATUS_NO_RESOURCE
&&
285 attempts
< VF_ACQUIRE_THRESH
) {
287 "PF unwilling to fulfill resource request. Try PF recommended amount\n");
289 /* humble our request */
290 req
->resc_request
.num_txqs
=
291 min(req
->resc_request
.num_txqs
,
292 bp
->acquire_resp
.resc
.num_txqs
);
293 req
->resc_request
.num_rxqs
=
294 min(req
->resc_request
.num_rxqs
,
295 bp
->acquire_resp
.resc
.num_rxqs
);
296 req
->resc_request
.num_sbs
=
297 min(req
->resc_request
.num_sbs
,
298 bp
->acquire_resp
.resc
.num_sbs
);
299 req
->resc_request
.num_mac_filters
=
300 min(req
->resc_request
.num_mac_filters
,
301 bp
->acquire_resp
.resc
.num_mac_filters
);
302 req
->resc_request
.num_vlan_filters
=
303 min(req
->resc_request
.num_vlan_filters
,
304 bp
->acquire_resp
.resc
.num_vlan_filters
);
305 req
->resc_request
.num_mc_filters
=
306 min(req
->resc_request
.num_mc_filters
,
307 bp
->acquire_resp
.resc
.num_mc_filters
);
309 /* Clear response buffer */
310 memset(&bp
->vf2pf_mbox
->resp
, 0,
311 sizeof(union pfvf_tlvs
));
313 /* PF reports error */
314 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
315 bp
->acquire_resp
.hdr
.status
);
321 /* Retrieve physical port id (if possible) */
322 phys_port_resp
= (struct vfpf_port_phys_id_resp_tlv
*)
323 bnx2x_search_tlv_list(bp
, resp
,
324 CHANNEL_TLV_PHYS_PORT_ID
);
325 if (phys_port_resp
) {
326 memcpy(bp
->phys_port_id
, phys_port_resp
->id
, ETH_ALEN
);
327 bp
->flags
|= HAS_PHYS_PORT_ID
;
331 bp
->common
.chip_id
|= (bp
->acquire_resp
.pfdev_info
.chip_num
& 0xffff);
332 bp
->link_params
.chip_id
= bp
->common
.chip_id
;
333 bp
->db_size
= bp
->acquire_resp
.pfdev_info
.db_size
;
334 bp
->common
.int_block
= INT_BLOCK_IGU
;
335 bp
->common
.chip_port_mode
= CHIP_2_PORT_MODE
;
339 bp
->common
.flash_size
= 0;
341 NO_WOL_FLAG
| NO_ISCSI_OOO_FLAG
| NO_ISCSI_FLAG
| NO_FCOE_FLAG
;
342 bp
->igu_sb_cnt
= bp
->acquire_resp
.resc
.num_sbs
;
343 bp
->igu_base_sb
= bp
->acquire_resp
.resc
.hw_sbs
[0].hw_sb_id
;
344 strlcpy(bp
->fw_ver
, bp
->acquire_resp
.pfdev_info
.fw_ver
,
347 if (is_valid_ether_addr(bp
->acquire_resp
.resc
.current_mac_addr
))
348 memcpy(bp
->dev
->dev_addr
,
349 bp
->acquire_resp
.resc
.current_mac_addr
,
353 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
357 int bnx2x_vfpf_release(struct bnx2x
*bp
)
359 struct vfpf_release_tlv
*req
= &bp
->vf2pf_mbox
->req
.release
;
360 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
363 /* clear mailbox and prep first tlv */
364 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_RELEASE
, sizeof(*req
));
366 if (bnx2x_get_vf_id(bp
, &vf_id
)) {
373 /* add list termination tlv */
374 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
375 sizeof(struct channel_list_end_tlv
));
377 /* output tlvs list */
378 bnx2x_dp_tlv_list(bp
, req
);
380 /* send release request */
381 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
387 if (resp
->hdr
.status
== PFVF_STATUS_SUCCESS
) {
389 DP(BNX2X_MSG_SP
, "vf released\n");
391 /* PF reports error */
392 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
398 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
403 /* Tell PF about SB addresses */
404 int bnx2x_vfpf_init(struct bnx2x
*bp
)
406 struct vfpf_init_tlv
*req
= &bp
->vf2pf_mbox
->req
.init
;
407 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
410 /* clear mailbox and prep first tlv */
411 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_INIT
, sizeof(*req
));
414 for_each_eth_queue(bp
, i
)
415 req
->sb_addr
[i
] = (dma_addr_t
)bnx2x_fp(bp
, i
,
418 /* statistics - requests only supports single queue for now */
419 req
->stats_addr
= bp
->fw_stats_data_mapping
+
420 offsetof(struct bnx2x_fw_stats_data
, queue_stats
);
422 req
->stats_stride
= sizeof(struct per_queue_stats
);
424 /* add list termination tlv */
425 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
426 sizeof(struct channel_list_end_tlv
));
428 /* output tlvs list */
429 bnx2x_dp_tlv_list(bp
, req
);
431 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
435 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
436 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
442 DP(BNX2X_MSG_SP
, "INIT VF Succeeded\n");
444 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
449 /* CLOSE VF - opposite to INIT_VF */
450 void bnx2x_vfpf_close_vf(struct bnx2x
*bp
)
452 struct vfpf_close_tlv
*req
= &bp
->vf2pf_mbox
->req
.close
;
453 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
457 /* If we haven't got a valid VF id, there is no sense to
458 * continue with sending messages
460 if (bnx2x_get_vf_id(bp
, &vf_id
))
463 /* Close the queues */
464 for_each_queue(bp
, i
)
465 bnx2x_vfpf_teardown_queue(bp
, i
);
468 bnx2x_vfpf_config_mac(bp
, bp
->dev
->dev_addr
, bp
->fp
->index
, false);
470 /* clear mailbox and prep first tlv */
471 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_CLOSE
, sizeof(*req
));
475 /* add list termination tlv */
476 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
477 sizeof(struct channel_list_end_tlv
));
479 /* output tlvs list */
480 bnx2x_dp_tlv_list(bp
, req
);
482 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
485 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc
);
487 else if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
)
488 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
491 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
494 /* Disable HW interrupts, NAPI */
495 bnx2x_netif_stop(bp
, 0);
496 /* Delete all NAPI objects */
497 bnx2x_del_all_napi(bp
);
503 static void bnx2x_leading_vfq_init(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
504 struct bnx2x_vf_queue
*q
)
506 u8 cl_id
= vfq_cl_id(vf
, q
);
507 u8 func_id
= FW_VF_HANDLE(vf
->abs_vfid
);
510 bnx2x_init_mac_obj(bp
, &q
->mac_obj
,
511 cl_id
, q
->cid
, func_id
,
512 bnx2x_vf_sp(bp
, vf
, mac_rdata
),
513 bnx2x_vf_sp_map(bp
, vf
, mac_rdata
),
514 BNX2X_FILTER_MAC_PENDING
,
516 BNX2X_OBJ_TYPE_RX_TX
,
519 bnx2x_init_vlan_obj(bp
, &q
->vlan_obj
,
520 cl_id
, q
->cid
, func_id
,
521 bnx2x_vf_sp(bp
, vf
, vlan_rdata
),
522 bnx2x_vf_sp_map(bp
, vf
, vlan_rdata
),
523 BNX2X_FILTER_VLAN_PENDING
,
525 BNX2X_OBJ_TYPE_RX_TX
,
529 bnx2x_init_mcast_obj(bp
, &vf
->mcast_obj
, cl_id
,
530 q
->cid
, func_id
, func_id
,
531 bnx2x_vf_sp(bp
, vf
, mcast_rdata
),
532 bnx2x_vf_sp_map(bp
, vf
, mcast_rdata
),
533 BNX2X_FILTER_MCAST_PENDING
,
535 BNX2X_OBJ_TYPE_RX_TX
);
538 bnx2x_init_rss_config_obj(bp
, &vf
->rss_conf_obj
, cl_id
, q
->cid
,
540 bnx2x_vf_sp(bp
, vf
, rss_rdata
),
541 bnx2x_vf_sp_map(bp
, vf
, rss_rdata
),
542 BNX2X_FILTER_RSS_CONF_PENDING
,
544 BNX2X_OBJ_TYPE_RX_TX
);
546 vf
->leading_rss
= cl_id
;
547 q
->is_leading
= true;
550 /* ask the pf to open a queue for the vf */
551 int bnx2x_vfpf_setup_q(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
554 struct vfpf_setup_q_tlv
*req
= &bp
->vf2pf_mbox
->req
.setup_q
;
555 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
556 u8 fp_idx
= fp
->index
;
557 u16 tpa_agg_size
= 0, flags
= 0;
560 /* clear mailbox and prep first tlv */
561 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_SETUP_Q
, sizeof(*req
));
563 /* select tpa mode to request */
564 if (!fp
->disable_tpa
) {
565 flags
|= VFPF_QUEUE_FLG_TPA
;
566 flags
|= VFPF_QUEUE_FLG_TPA_IPV6
;
567 if (fp
->mode
== TPA_MODE_GRO
)
568 flags
|= VFPF_QUEUE_FLG_TPA_GRO
;
569 tpa_agg_size
= TPA_AGG_SIZE
;
573 flags
|= VFPF_QUEUE_FLG_LEADING_RSS
;
575 /* calculate queue flags */
576 flags
|= VFPF_QUEUE_FLG_STATS
;
577 flags
|= VFPF_QUEUE_FLG_CACHE_ALIGN
;
578 flags
|= VFPF_QUEUE_FLG_VLAN
;
579 DP(NETIF_MSG_IFUP
, "vlan removal enabled\n");
582 req
->vf_qid
= fp_idx
;
583 req
->param_valid
= VFPF_RXQ_VALID
| VFPF_TXQ_VALID
;
586 req
->rxq
.rcq_addr
= fp
->rx_comp_mapping
;
587 req
->rxq
.rcq_np_addr
= fp
->rx_comp_mapping
+ BCM_PAGE_SIZE
;
588 req
->rxq
.rxq_addr
= fp
->rx_desc_mapping
;
589 req
->rxq
.sge_addr
= fp
->rx_sge_mapping
;
590 req
->rxq
.vf_sb
= fp_idx
;
591 req
->rxq
.sb_index
= HC_INDEX_ETH_RX_CQ_CONS
;
592 req
->rxq
.hc_rate
= bp
->rx_ticks
? 1000000/bp
->rx_ticks
: 0;
593 req
->rxq
.mtu
= bp
->dev
->mtu
;
594 req
->rxq
.buf_sz
= fp
->rx_buf_size
;
595 req
->rxq
.sge_buf_sz
= BCM_PAGE_SIZE
* PAGES_PER_SGE
;
596 req
->rxq
.tpa_agg_sz
= tpa_agg_size
;
597 req
->rxq
.max_sge_pkt
= SGE_PAGE_ALIGN(bp
->dev
->mtu
) >> SGE_PAGE_SHIFT
;
598 req
->rxq
.max_sge_pkt
= ((req
->rxq
.max_sge_pkt
+ PAGES_PER_SGE
- 1) &
599 (~(PAGES_PER_SGE
-1))) >> PAGES_PER_SGE_SHIFT
;
600 req
->rxq
.flags
= flags
;
601 req
->rxq
.drop_flags
= 0;
602 req
->rxq
.cache_line_log
= BNX2X_RX_ALIGN_SHIFT
;
603 req
->rxq
.stat_id
= -1; /* No stats at the moment */
606 req
->txq
.txq_addr
= fp
->txdata_ptr
[FIRST_TX_COS_INDEX
]->tx_desc_mapping
;
607 req
->txq
.vf_sb
= fp_idx
;
608 req
->txq
.sb_index
= HC_INDEX_ETH_TX_CQ_CONS_COS0
;
609 req
->txq
.hc_rate
= bp
->tx_ticks
? 1000000/bp
->tx_ticks
: 0;
610 req
->txq
.flags
= flags
;
611 req
->txq
.traffic_type
= LLFC_TRAFFIC_TYPE_NW
;
613 /* add list termination tlv */
614 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
615 sizeof(struct channel_list_end_tlv
));
617 /* output tlvs list */
618 bnx2x_dp_tlv_list(bp
, req
);
620 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
622 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
625 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
626 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
627 fp_idx
, resp
->hdr
.status
);
631 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
636 int bnx2x_vfpf_teardown_queue(struct bnx2x
*bp
, int qidx
)
638 struct vfpf_q_op_tlv
*req
= &bp
->vf2pf_mbox
->req
.q_op
;
639 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
642 /* clear mailbox and prep first tlv */
643 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_TEARDOWN_Q
,
648 /* add list termination tlv */
649 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
650 sizeof(struct channel_list_end_tlv
));
652 /* output tlvs list */
653 bnx2x_dp_tlv_list(bp
, req
);
655 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
658 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx
,
663 /* PF failed the transaction */
664 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
665 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx
,
671 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
675 /* request pf to add a mac for the vf */
676 int bnx2x_vfpf_config_mac(struct bnx2x
*bp
, u8
*addr
, u8 vf_qid
, bool set
)
678 struct vfpf_set_q_filters_tlv
*req
= &bp
->vf2pf_mbox
->req
.set_q_filters
;
679 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
680 struct pf_vf_bulletin_content bulletin
= bp
->pf2vf_bulletin
->content
;
683 /* clear mailbox and prep first tlv */
684 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_SET_Q_FILTERS
,
687 req
->flags
= VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED
;
688 req
->vf_qid
= vf_qid
;
689 req
->n_mac_vlan_filters
= 1;
691 req
->filters
[0].flags
= VFPF_Q_FILTER_DEST_MAC_VALID
;
693 req
->filters
[0].flags
|= VFPF_Q_FILTER_SET_MAC
;
695 /* sample bulletin board for new mac */
696 bnx2x_sample_bulletin(bp
);
698 /* copy mac from device to request */
699 memcpy(req
->filters
[0].mac
, addr
, ETH_ALEN
);
701 /* add list termination tlv */
702 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
703 sizeof(struct channel_list_end_tlv
));
705 /* output tlvs list */
706 bnx2x_dp_tlv_list(bp
, req
);
708 /* send message to pf */
709 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
711 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc
);
715 /* failure may mean PF was configured with a new mac for us */
716 while (resp
->hdr
.status
== PFVF_STATUS_FAILURE
) {
718 "vfpf SET MAC failed. Check bulletin board for new posts\n");
720 /* copy mac from bulletin to device */
721 memcpy(bp
->dev
->dev_addr
, bulletin
.mac
, ETH_ALEN
);
723 /* check if bulletin board was updated */
724 if (bnx2x_sample_bulletin(bp
) == PFVF_BULLETIN_UPDATED
) {
725 /* copy mac from device to request */
726 memcpy(req
->filters
[0].mac
, bp
->dev
->dev_addr
,
729 /* send message to pf */
730 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
,
731 bp
->vf2pf_mbox_mapping
);
733 /* no new info in bulletin */
738 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
739 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp
->hdr
.status
);
743 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
748 /* request pf to config rss table for vf queues*/
749 int bnx2x_vfpf_config_rss(struct bnx2x
*bp
,
750 struct bnx2x_config_rss_params
*params
)
752 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
753 struct vfpf_rss_tlv
*req
= &bp
->vf2pf_mbox
->req
.update_rss
;
756 /* clear mailbox and prep first tlv */
757 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_UPDATE_RSS
,
760 /* add list termination tlv */
761 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
762 sizeof(struct channel_list_end_tlv
));
764 memcpy(req
->ind_table
, params
->ind_table
, T_ETH_INDIRECTION_TABLE_SIZE
);
765 memcpy(req
->rss_key
, params
->rss_key
, sizeof(params
->rss_key
));
766 req
->ind_table_size
= T_ETH_INDIRECTION_TABLE_SIZE
;
767 req
->rss_key_size
= T_ETH_RSS_KEY
;
768 req
->rss_result_mask
= params
->rss_result_mask
;
770 /* flags handled individually for backward/forward compatability */
771 if (params
->rss_flags
& (1 << BNX2X_RSS_MODE_DISABLED
))
772 req
->rss_flags
|= VFPF_RSS_MODE_DISABLED
;
773 if (params
->rss_flags
& (1 << BNX2X_RSS_MODE_REGULAR
))
774 req
->rss_flags
|= VFPF_RSS_MODE_REGULAR
;
775 if (params
->rss_flags
& (1 << BNX2X_RSS_SET_SRCH
))
776 req
->rss_flags
|= VFPF_RSS_SET_SRCH
;
777 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV4
))
778 req
->rss_flags
|= VFPF_RSS_IPV4
;
779 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV4_TCP
))
780 req
->rss_flags
|= VFPF_RSS_IPV4_TCP
;
781 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV4_UDP
))
782 req
->rss_flags
|= VFPF_RSS_IPV4_UDP
;
783 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV6
))
784 req
->rss_flags
|= VFPF_RSS_IPV6
;
785 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV6_TCP
))
786 req
->rss_flags
|= VFPF_RSS_IPV6_TCP
;
787 if (params
->rss_flags
& (1 << BNX2X_RSS_IPV6_UDP
))
788 req
->rss_flags
|= VFPF_RSS_IPV6_UDP
;
790 DP(BNX2X_MSG_IOV
, "rss flags %x\n", req
->rss_flags
);
792 /* output tlvs list */
793 bnx2x_dp_tlv_list(bp
, req
);
795 /* send message to pf */
796 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
798 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc
);
802 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
803 /* Since older drivers don't support this feature (and VF has
804 * no way of knowing other than failing this), don't propagate
805 * an error in this case.
808 "Failed to send rss message to PF over VF-PF channel [%d]\n",
812 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
817 int bnx2x_vfpf_set_mcast(struct net_device
*dev
)
819 struct bnx2x
*bp
= netdev_priv(dev
);
820 struct vfpf_set_q_filters_tlv
*req
= &bp
->vf2pf_mbox
->req
.set_q_filters
;
821 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
823 struct netdev_hw_addr
*ha
;
825 if (bp
->state
!= BNX2X_STATE_OPEN
) {
826 DP(NETIF_MSG_IFUP
, "state is %x, returning\n", bp
->state
);
830 /* clear mailbox and prep first tlv */
831 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_SET_Q_FILTERS
,
834 /* Get Rx mode requested */
835 DP(NETIF_MSG_IFUP
, "dev->flags = %x\n", dev
->flags
);
837 netdev_for_each_mc_addr(ha
, dev
) {
838 DP(NETIF_MSG_IFUP
, "Adding mcast MAC: %pM\n",
840 memcpy(req
->multicast
[i
], bnx2x_mc_addr(ha
), ETH_ALEN
);
844 /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
847 if (i
>= PFVF_MAX_MULTICAST_PER_VF
) {
849 "VF supports not more than %d multicast MAC addresses\n",
850 PFVF_MAX_MULTICAST_PER_VF
);
854 req
->n_multicast
= i
;
855 req
->flags
|= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED
;
858 /* add list termination tlv */
859 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
860 sizeof(struct channel_list_end_tlv
));
862 /* output tlvs list */
863 bnx2x_dp_tlv_list(bp
, req
);
864 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
866 BNX2X_ERR("Sending a message failed: %d\n", rc
);
870 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
871 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
876 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
881 int bnx2x_vfpf_storm_rx_mode(struct bnx2x
*bp
)
883 int mode
= bp
->rx_mode
;
884 struct vfpf_set_q_filters_tlv
*req
= &bp
->vf2pf_mbox
->req
.set_q_filters
;
885 struct pfvf_general_resp_tlv
*resp
= &bp
->vf2pf_mbox
->resp
.general_resp
;
888 /* clear mailbox and prep first tlv */
889 bnx2x_vfpf_prep(bp
, &req
->first_tlv
, CHANNEL_TLV_SET_Q_FILTERS
,
892 DP(NETIF_MSG_IFUP
, "Rx mode is %d\n", mode
);
895 case BNX2X_RX_MODE_NONE
: /* no Rx */
896 req
->rx_mask
= VFPF_RX_MASK_ACCEPT_NONE
;
898 case BNX2X_RX_MODE_NORMAL
:
899 req
->rx_mask
= VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST
;
900 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST
;
901 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_BROADCAST
;
903 case BNX2X_RX_MODE_ALLMULTI
:
904 req
->rx_mask
= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST
;
905 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST
;
906 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_BROADCAST
;
908 case BNX2X_RX_MODE_PROMISC
:
909 req
->rx_mask
= VFPF_RX_MASK_ACCEPT_ALL_UNICAST
;
910 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST
;
911 req
->rx_mask
|= VFPF_RX_MASK_ACCEPT_BROADCAST
;
914 BNX2X_ERR("BAD rx mode (%d)\n", mode
);
919 req
->flags
|= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED
;
922 /* add list termination tlv */
923 bnx2x_add_tlv(bp
, req
, req
->first_tlv
.tl
.length
, CHANNEL_TLV_LIST_END
,
924 sizeof(struct channel_list_end_tlv
));
926 /* output tlvs list */
927 bnx2x_dp_tlv_list(bp
, req
);
929 rc
= bnx2x_send_msg2pf(bp
, &resp
->hdr
.status
, bp
->vf2pf_mbox_mapping
);
931 BNX2X_ERR("Sending a message failed: %d\n", rc
);
933 if (resp
->hdr
.status
!= PFVF_STATUS_SUCCESS
) {
934 BNX2X_ERR("Set Rx mode failed: %d\n", resp
->hdr
.status
);
938 bnx2x_vfpf_finalize(bp
, &req
->first_tlv
);
943 /* General service functions */
944 static void storm_memset_vf_mbx_ack(struct bnx2x
*bp
, u16 abs_fid
)
946 u32 addr
= BAR_CSTRORM_INTMEM
+
947 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid
);
949 REG_WR8(bp
, addr
, VF_PF_CHANNEL_STATE_READY
);
952 static void storm_memset_vf_mbx_valid(struct bnx2x
*bp
, u16 abs_fid
)
954 u32 addr
= BAR_CSTRORM_INTMEM
+
955 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid
);
957 REG_WR8(bp
, addr
, 1);
960 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x
*bp
)
965 storm_memset_vf_mbx_valid(bp
, bnx2x_vf(bp
, i
, abs_vfid
));
968 /* enable vf_pf mailbox (aka vf-pf-channel) */
969 void bnx2x_vf_enable_mbx(struct bnx2x
*bp
, u8 abs_vfid
)
971 bnx2x_vf_flr_clnup_epilog(bp
, abs_vfid
);
973 /* enable the mailbox in the FW */
974 storm_memset_vf_mbx_ack(bp
, abs_vfid
);
975 storm_memset_vf_mbx_valid(bp
, abs_vfid
);
977 /* enable the VF access to the mailbox */
978 bnx2x_vf_enable_access(bp
, abs_vfid
);
981 /* this works only on !E1h */
982 static int bnx2x_copy32_vf_dmae(struct bnx2x
*bp
, u8 from_vf
,
983 dma_addr_t pf_addr
, u8 vfid
, u32 vf_addr_hi
,
984 u32 vf_addr_lo
, u32 len32
)
986 struct dmae_command dmae
;
988 if (CHIP_IS_E1x(bp
)) {
989 BNX2X_ERR("Chip revision does not support VFs\n");
993 if (!bp
->dmae_ready
) {
994 BNX2X_ERR("DMAE is not ready, can not copy\n");
998 /* set opcode and fixed command fields */
999 bnx2x_prep_dmae_with_comp(bp
, &dmae
, DMAE_SRC_PCI
, DMAE_DST_PCI
);
1002 dmae
.opcode_iov
= (vfid
<< DMAE_COMMAND_SRC_VFID_SHIFT
) |
1003 (DMAE_SRC_VF
<< DMAE_COMMAND_SRC_VFPF_SHIFT
) |
1004 (DMAE_DST_PF
<< DMAE_COMMAND_DST_VFPF_SHIFT
);
1006 dmae
.opcode
|= (DMAE_C_DST
<< DMAE_COMMAND_C_FUNC_SHIFT
);
1008 dmae
.src_addr_lo
= vf_addr_lo
;
1009 dmae
.src_addr_hi
= vf_addr_hi
;
1010 dmae
.dst_addr_lo
= U64_LO(pf_addr
);
1011 dmae
.dst_addr_hi
= U64_HI(pf_addr
);
1013 dmae
.opcode_iov
= (vfid
<< DMAE_COMMAND_DST_VFID_SHIFT
) |
1014 (DMAE_DST_VF
<< DMAE_COMMAND_DST_VFPF_SHIFT
) |
1015 (DMAE_SRC_PF
<< DMAE_COMMAND_SRC_VFPF_SHIFT
);
1017 dmae
.opcode
|= (DMAE_C_SRC
<< DMAE_COMMAND_C_FUNC_SHIFT
);
1019 dmae
.src_addr_lo
= U64_LO(pf_addr
);
1020 dmae
.src_addr_hi
= U64_HI(pf_addr
);
1021 dmae
.dst_addr_lo
= vf_addr_lo
;
1022 dmae
.dst_addr_hi
= vf_addr_hi
;
1026 /* issue the command and wait for completion */
1027 return bnx2x_issue_dmae_with_comp(bp
, &dmae
, bnx2x_sp(bp
, wb_comp
));
1030 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x
*bp
,
1031 struct bnx2x_virtf
*vf
)
1033 struct bnx2x_vf_mbx
*mbx
= BP_VF_MBX(bp
, vf
->index
);
1036 /* prepare response */
1037 type
= mbx
->first_tlv
.tl
.type
;
1038 length
= type
== CHANNEL_TLV_ACQUIRE
?
1039 sizeof(struct pfvf_acquire_resp_tlv
) :
1040 sizeof(struct pfvf_general_resp_tlv
);
1041 bnx2x_add_tlv(bp
, &mbx
->msg
->resp
, 0, type
, length
);
1042 bnx2x_add_tlv(bp
, &mbx
->msg
->resp
, length
, CHANNEL_TLV_LIST_END
,
1043 sizeof(struct channel_list_end_tlv
));
1046 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x
*bp
,
1047 struct bnx2x_virtf
*vf
)
1049 struct bnx2x_vf_mbx
*mbx
= BP_VF_MBX(bp
, vf
->index
);
1050 struct pfvf_general_resp_tlv
*resp
= &mbx
->msg
->resp
.general_resp
;
1055 bnx2x_dp_tlv_list(bp
, resp
);
1056 DP(BNX2X_MSG_IOV
, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1057 mbx
->vf_addr_hi
, mbx
->vf_addr_lo
, mbx
->first_tlv
.resp_msg_offset
);
1059 resp
->hdr
.status
= bnx2x_pfvf_status_codes(vf
->op_rc
);
1062 vf_addr
= HILO_U64(mbx
->vf_addr_hi
, mbx
->vf_addr_lo
) +
1063 mbx
->first_tlv
.resp_msg_offset
;
1064 pf_addr
= mbx
->msg_mapping
+
1065 offsetof(struct bnx2x_vf_mbx_msg
, resp
);
1067 /* Copy the response buffer. The first u64 is written afterwards, as
1068 * the vf is sensitive to the header being written
1070 vf_addr
+= sizeof(u64
);
1071 pf_addr
+= sizeof(u64
);
1072 rc
= bnx2x_copy32_vf_dmae(bp
, false, pf_addr
, vf
->abs_vfid
,
1075 (sizeof(union pfvf_tlvs
) - sizeof(u64
))/4);
1077 BNX2X_ERR("Failed to copy response body to VF %d\n",
1081 vf_addr
-= sizeof(u64
);
1082 pf_addr
-= sizeof(u64
);
1085 storm_memset_vf_mbx_ack(bp
, vf
->abs_vfid
);
1088 /* initiate dmae to send the response */
1089 mbx
->flags
&= ~VF_MSG_INPROCESS
;
1091 /* copy the response header including status-done field,
1092 * must be last dmae, must be after FW is acked
1094 rc
= bnx2x_copy32_vf_dmae(bp
, false, pf_addr
, vf
->abs_vfid
,
1099 /* unlock channel mutex */
1100 bnx2x_unlock_vf_pf_channel(bp
, vf
, mbx
->first_tlv
.tl
.type
);
1103 BNX2X_ERR("Failed to copy response status to VF %d\n",
1110 bnx2x_vf_release(bp
, vf
, false); /* non blocking */
1113 static void bnx2x_vf_mbx_resp(struct bnx2x
*bp
,
1114 struct bnx2x_virtf
*vf
)
1116 bnx2x_vf_mbx_resp_single_tlv(bp
, vf
);
1117 bnx2x_vf_mbx_resp_send_msg(bp
, vf
);
1120 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x
*bp
,
1121 struct bnx2x_virtf
*vf
,
1125 struct vfpf_port_phys_id_resp_tlv
*port_id
;
1127 if (!(bp
->flags
& HAS_PHYS_PORT_ID
))
1130 bnx2x_add_tlv(bp
, buffer
, *offset
, CHANNEL_TLV_PHYS_PORT_ID
,
1131 sizeof(struct vfpf_port_phys_id_resp_tlv
));
1133 port_id
= (struct vfpf_port_phys_id_resp_tlv
*)
1134 (((u8
*)buffer
) + *offset
);
1135 memcpy(port_id
->id
, bp
->phys_port_id
, ETH_ALEN
);
1137 /* Offset should continue representing the offset to the tail
1138 * of TLV data (outside this function scope)
1140 *offset
+= sizeof(struct vfpf_port_phys_id_resp_tlv
);
1143 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1144 struct bnx2x_vf_mbx
*mbx
, int vfop_status
)
1147 struct pfvf_acquire_resp_tlv
*resp
= &mbx
->msg
->resp
.acquire_resp
;
1148 struct pf_vf_resc
*resc
= &resp
->resc
;
1149 u8 status
= bnx2x_pfvf_status_codes(vfop_status
);
1152 memset(resp
, 0, sizeof(*resp
));
1154 /* fill in pfdev info */
1155 resp
->pfdev_info
.chip_num
= bp
->common
.chip_id
;
1156 resp
->pfdev_info
.db_size
= bp
->db_size
;
1157 resp
->pfdev_info
.indices_per_sb
= HC_SB_MAX_INDICES_E2
;
1158 resp
->pfdev_info
.pf_cap
= (PFVF_CAP_RSS
|
1159 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA
);
1160 bnx2x_fill_fw_str(bp
, resp
->pfdev_info
.fw_ver
,
1161 sizeof(resp
->pfdev_info
.fw_ver
));
1163 if (status
== PFVF_STATUS_NO_RESOURCE
||
1164 status
== PFVF_STATUS_SUCCESS
) {
1165 /* set resources numbers, if status equals NO_RESOURCE these
1166 * are max possible numbers
1168 resc
->num_rxqs
= vf_rxq_count(vf
) ? :
1169 bnx2x_vf_max_queue_cnt(bp
, vf
);
1170 resc
->num_txqs
= vf_txq_count(vf
) ? :
1171 bnx2x_vf_max_queue_cnt(bp
, vf
);
1172 resc
->num_sbs
= vf_sb_count(vf
);
1173 resc
->num_mac_filters
= vf_mac_rules_cnt(vf
);
1174 resc
->num_vlan_filters
= vf_vlan_rules_cnt(vf
);
1175 resc
->num_mc_filters
= 0;
1177 if (status
== PFVF_STATUS_SUCCESS
) {
1178 /* fill in the allocated resources */
1179 struct pf_vf_bulletin_content
*bulletin
=
1180 BP_VF_BULLETIN(bp
, vf
->index
);
1184 vfq_qzone_id(vf
, vfq_get(vf
, i
));
1186 for_each_vf_sb(vf
, i
) {
1187 resc
->hw_sbs
[i
].hw_sb_id
= vf_igu_sb(vf
, i
);
1188 resc
->hw_sbs
[i
].sb_qid
= vf_hc_qzone(vf
, i
);
1191 /* if a mac has been set for this vf, supply it */
1192 if (bulletin
->valid_bitmap
& 1 << MAC_ADDR_VALID
) {
1193 memcpy(resc
->current_mac_addr
, bulletin
->mac
,
1199 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"
1200 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1202 resp
->pfdev_info
.chip_num
,
1203 resp
->pfdev_info
.db_size
,
1204 resp
->pfdev_info
.indices_per_sb
,
1205 resp
->pfdev_info
.pf_cap
,
1209 resc
->num_mac_filters
,
1210 resc
->num_vlan_filters
,
1211 resc
->num_mc_filters
,
1212 resp
->pfdev_info
.fw_ver
);
1214 DP_CONT(BNX2X_MSG_IOV
, "hw_qids- [ ");
1215 for (i
= 0; i
< vf_rxq_count(vf
); i
++)
1216 DP_CONT(BNX2X_MSG_IOV
, "%d ", resc
->hw_qid
[i
]);
1217 DP_CONT(BNX2X_MSG_IOV
, "], sb_info- [ ");
1218 for (i
= 0; i
< vf_sb_count(vf
); i
++)
1219 DP_CONT(BNX2X_MSG_IOV
, "%d:%d ",
1220 resc
->hw_sbs
[i
].hw_sb_id
,
1221 resc
->hw_sbs
[i
].sb_qid
);
1222 DP_CONT(BNX2X_MSG_IOV
, "]\n");
1224 /* prepare response */
1225 length
= sizeof(struct pfvf_acquire_resp_tlv
);
1226 bnx2x_add_tlv(bp
, &mbx
->msg
->resp
, 0, CHANNEL_TLV_ACQUIRE
, length
);
1228 /* Handle possible VF requests for physical port identifiers.
1229 * 'length' should continue to indicate the offset of the first empty
1230 * place in the buffer (i.e., where next TLV should be inserted)
1232 if (bnx2x_search_tlv_list(bp
, &mbx
->msg
->req
,
1233 CHANNEL_TLV_PHYS_PORT_ID
))
1234 bnx2x_vf_mbx_resp_phys_port(bp
, vf
, &mbx
->msg
->resp
, &length
);
1236 bnx2x_add_tlv(bp
, &mbx
->msg
->resp
, length
, CHANNEL_TLV_LIST_END
,
1237 sizeof(struct channel_list_end_tlv
));
1239 /* send the response */
1240 vf
->op_rc
= vfop_status
;
1241 bnx2x_vf_mbx_resp_send_msg(bp
, vf
);
1244 static void bnx2x_vf_mbx_acquire(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1245 struct bnx2x_vf_mbx
*mbx
)
1248 struct vfpf_acquire_tlv
*acquire
= &mbx
->msg
->req
.acquire
;
1250 /* log vfdef info */
1252 "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",
1253 vf
->abs_vfid
, acquire
->vfdev_info
.vf_id
, acquire
->vfdev_info
.vf_os
,
1254 acquire
->resc_request
.num_rxqs
, acquire
->resc_request
.num_txqs
,
1255 acquire
->resc_request
.num_sbs
, acquire
->resc_request
.num_mac_filters
,
1256 acquire
->resc_request
.num_vlan_filters
,
1257 acquire
->resc_request
.num_mc_filters
);
1259 /* acquire the resources */
1260 rc
= bnx2x_vf_acquire(bp
, vf
, &acquire
->resc_request
);
1262 /* store address of vf's bulletin board */
1263 vf
->bulletin_map
= acquire
->bulletin_addr
;
1266 bnx2x_vf_mbx_acquire_resp(bp
, vf
, mbx
, rc
);
1269 static void bnx2x_vf_mbx_init_vf(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1270 struct bnx2x_vf_mbx
*mbx
)
1272 struct vfpf_init_tlv
*init
= &mbx
->msg
->req
.init
;
1274 /* record ghost addresses from vf message */
1275 vf
->spq_map
= init
->spq_addr
;
1276 vf
->fw_stat_map
= init
->stats_addr
;
1277 vf
->stats_stride
= init
->stats_stride
;
1278 vf
->op_rc
= bnx2x_vf_init(bp
, vf
, (dma_addr_t
*)init
->sb_addr
);
1280 /* set VF multiqueue statistics collection mode */
1281 if (init
->flags
& VFPF_INIT_FLG_STATS_COALESCE
)
1282 vf
->cfg_flags
|= VF_CFG_STATS_COALESCE
;
1285 bnx2x_vf_mbx_resp(bp
, vf
);
1288 /* convert MBX queue-flags to standard SP queue-flags */
1289 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x
*bp
, u32 mbx_q_flags
,
1290 unsigned long *sp_q_flags
)
1292 if (mbx_q_flags
& VFPF_QUEUE_FLG_TPA
)
1293 __set_bit(BNX2X_Q_FLG_TPA
, sp_q_flags
);
1294 if (mbx_q_flags
& VFPF_QUEUE_FLG_TPA_IPV6
)
1295 __set_bit(BNX2X_Q_FLG_TPA_IPV6
, sp_q_flags
);
1296 if (mbx_q_flags
& VFPF_QUEUE_FLG_TPA_GRO
)
1297 __set_bit(BNX2X_Q_FLG_TPA_GRO
, sp_q_flags
);
1298 if (mbx_q_flags
& VFPF_QUEUE_FLG_STATS
)
1299 __set_bit(BNX2X_Q_FLG_STATS
, sp_q_flags
);
1300 if (mbx_q_flags
& VFPF_QUEUE_FLG_VLAN
)
1301 __set_bit(BNX2X_Q_FLG_VLAN
, sp_q_flags
);
1302 if (mbx_q_flags
& VFPF_QUEUE_FLG_COS
)
1303 __set_bit(BNX2X_Q_FLG_COS
, sp_q_flags
);
1304 if (mbx_q_flags
& VFPF_QUEUE_FLG_HC
)
1305 __set_bit(BNX2X_Q_FLG_HC
, sp_q_flags
);
1306 if (mbx_q_flags
& VFPF_QUEUE_FLG_DHC
)
1307 __set_bit(BNX2X_Q_FLG_DHC
, sp_q_flags
);
1308 if (mbx_q_flags
& VFPF_QUEUE_FLG_LEADING_RSS
)
1309 __set_bit(BNX2X_Q_FLG_LEADING_RSS
, sp_q_flags
);
1311 /* outer vlan removal is set according to PF's multi function mode */
1313 __set_bit(BNX2X_Q_FLG_OV
, sp_q_flags
);
1316 static void bnx2x_vf_mbx_setup_q(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1317 struct bnx2x_vf_mbx
*mbx
)
1319 struct vfpf_setup_q_tlv
*setup_q
= &mbx
->msg
->req
.setup_q
;
1320 struct bnx2x_vfop_cmd cmd
= {
1321 .done
= bnx2x_vf_mbx_resp
,
1326 if (setup_q
->vf_qid
>= vf_rxq_count(vf
)) {
1327 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1328 setup_q
->vf_qid
, vf_rxq_count(vf
));
1329 vf
->op_rc
= -EINVAL
;
1333 /* tx queues must be setup alongside rx queues thus if the rx queue
1334 * is not marked as valid there's nothing to do.
1336 if (setup_q
->param_valid
& (VFPF_RXQ_VALID
|VFPF_TXQ_VALID
)) {
1337 struct bnx2x_vf_queue
*q
= vfq_get(vf
, setup_q
->vf_qid
);
1338 unsigned long q_type
= 0;
1340 struct bnx2x_queue_init_params
*init_p
;
1341 struct bnx2x_queue_setup_params
*setup_p
;
1343 if (bnx2x_vfq_is_leading(q
))
1344 bnx2x_leading_vfq_init(bp
, vf
, q
);
1346 /* re-init the VF operation context */
1347 memset(&vf
->op_params
.qctor
, 0 , sizeof(vf
->op_params
.qctor
));
1348 setup_p
= &vf
->op_params
.qctor
.prep_qsetup
;
1349 init_p
= &vf
->op_params
.qctor
.qstate
.params
.init
;
1351 /* activate immediately */
1352 __set_bit(BNX2X_Q_FLG_ACTIVE
, &setup_p
->flags
);
1354 if (setup_q
->param_valid
& VFPF_TXQ_VALID
) {
1355 struct bnx2x_txq_setup_params
*txq_params
=
1356 &setup_p
->txq_params
;
1358 __set_bit(BNX2X_Q_TYPE_HAS_TX
, &q_type
);
1360 /* save sb resource index */
1361 q
->sb_idx
= setup_q
->txq
.vf_sb
;
1364 init_p
->tx
.hc_rate
= setup_q
->txq
.hc_rate
;
1365 init_p
->tx
.sb_cq_index
= setup_q
->txq
.sb_index
;
1367 bnx2x_vf_mbx_set_q_flags(bp
, setup_q
->txq
.flags
,
1370 /* tx setup - flags */
1371 bnx2x_vf_mbx_set_q_flags(bp
, setup_q
->txq
.flags
,
1374 /* tx setup - general, nothing */
1377 txq_params
->dscr_map
= setup_q
->txq
.txq_addr
;
1378 txq_params
->sb_cq_index
= setup_q
->txq
.sb_index
;
1379 txq_params
->traffic_type
= setup_q
->txq
.traffic_type
;
1381 bnx2x_vfop_qctor_dump_tx(bp
, vf
, init_p
, setup_p
,
1382 q
->index
, q
->sb_idx
);
1385 if (setup_q
->param_valid
& VFPF_RXQ_VALID
) {
1386 struct bnx2x_rxq_setup_params
*rxq_params
=
1387 &setup_p
->rxq_params
;
1389 __set_bit(BNX2X_Q_TYPE_HAS_RX
, &q_type
);
1391 /* Note: there is no support for different SBs
1394 q
->sb_idx
= setup_q
->rxq
.vf_sb
;
1397 init_p
->rx
.hc_rate
= setup_q
->rxq
.hc_rate
;
1398 init_p
->rx
.sb_cq_index
= setup_q
->rxq
.sb_index
;
1399 bnx2x_vf_mbx_set_q_flags(bp
, setup_q
->rxq
.flags
,
1402 /* rx setup - flags */
1403 bnx2x_vf_mbx_set_q_flags(bp
, setup_q
->rxq
.flags
,
1406 /* rx setup - general */
1407 setup_p
->gen_params
.mtu
= setup_q
->rxq
.mtu
;
1410 rxq_params
->drop_flags
= setup_q
->rxq
.drop_flags
;
1411 rxq_params
->dscr_map
= setup_q
->rxq
.rxq_addr
;
1412 rxq_params
->sge_map
= setup_q
->rxq
.sge_addr
;
1413 rxq_params
->rcq_map
= setup_q
->rxq
.rcq_addr
;
1414 rxq_params
->rcq_np_map
= setup_q
->rxq
.rcq_np_addr
;
1415 rxq_params
->buf_sz
= setup_q
->rxq
.buf_sz
;
1416 rxq_params
->tpa_agg_sz
= setup_q
->rxq
.tpa_agg_sz
;
1417 rxq_params
->max_sges_pkt
= setup_q
->rxq
.max_sge_pkt
;
1418 rxq_params
->sge_buf_sz
= setup_q
->rxq
.sge_buf_sz
;
1419 rxq_params
->cache_line_log
=
1420 setup_q
->rxq
.cache_line_log
;
1421 rxq_params
->sb_cq_index
= setup_q
->rxq
.sb_index
;
1423 /* rx setup - multicast engine */
1424 if (bnx2x_vfq_is_leading(q
)) {
1425 u8 mcast_id
= FW_VF_HANDLE(vf
->abs_vfid
);
1427 rxq_params
->mcast_engine_id
= mcast_id
;
1428 __set_bit(BNX2X_Q_FLG_MCAST
, &setup_p
->flags
);
1431 bnx2x_vfop_qctor_dump_rx(bp
, vf
, init_p
, setup_p
,
1432 q
->index
, q
->sb_idx
);
1434 /* complete the preparations */
1435 bnx2x_vfop_qctor_prep(bp
, vf
, q
, &vf
->op_params
.qctor
, q_type
);
1437 vf
->op_rc
= bnx2x_vfop_qsetup_cmd(bp
, vf
, &cmd
, q
->index
);
1443 bnx2x_vf_mbx_resp(bp
, vf
);
1446 enum bnx2x_vfop_filters_state
{
1447 BNX2X_VFOP_MBX_Q_FILTERS_MACS
,
1448 BNX2X_VFOP_MBX_Q_FILTERS_VLANS
,
1449 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE
,
1450 BNX2X_VFOP_MBX_Q_FILTERS_MCAST
,
1451 BNX2X_VFOP_MBX_Q_FILTERS_DONE
1454 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x
*bp
,
1455 struct bnx2x_virtf
*vf
,
1456 struct vfpf_set_q_filters_tlv
*tlv
,
1457 struct bnx2x_vfop_filters
**pfl
,
1461 struct bnx2x_vfop_filters
*fl
= NULL
;
1464 fsz
= tlv
->n_mac_vlan_filters
* sizeof(struct bnx2x_vfop_filter
) +
1465 sizeof(struct bnx2x_vfop_filters
);
1467 fl
= kzalloc(fsz
, GFP_KERNEL
);
1471 INIT_LIST_HEAD(&fl
->head
);
1473 for (i
= 0, j
= 0; i
< tlv
->n_mac_vlan_filters
; i
++) {
1474 struct vfpf_q_mac_vlan_filter
*msg_filter
= &tlv
->filters
[i
];
1476 if ((msg_filter
->flags
& type_flag
) != type_flag
)
1478 if (type_flag
== VFPF_Q_FILTER_DEST_MAC_VALID
) {
1479 fl
->filters
[j
].mac
= msg_filter
->mac
;
1480 fl
->filters
[j
].type
= BNX2X_VFOP_FILTER_MAC
;
1482 fl
->filters
[j
].vid
= msg_filter
->vlan_tag
;
1483 fl
->filters
[j
].type
= BNX2X_VFOP_FILTER_VLAN
;
1485 fl
->filters
[j
].add
=
1486 (msg_filter
->flags
& VFPF_Q_FILTER_SET_MAC
) ?
1488 list_add_tail(&fl
->filters
[j
++].link
, &fl
->head
);
1490 if (list_empty(&fl
->head
))
1498 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x
*bp
, int msglvl
, int idx
,
1499 struct vfpf_q_mac_vlan_filter
*filter
)
1501 DP(msglvl
, "MAC-VLAN[%d] -- flags=0x%x\n", idx
, filter
->flags
);
1502 if (filter
->flags
& VFPF_Q_FILTER_VLAN_TAG_VALID
)
1503 DP_CONT(msglvl
, ", vlan=%d", filter
->vlan_tag
);
1504 if (filter
->flags
& VFPF_Q_FILTER_DEST_MAC_VALID
)
1505 DP_CONT(msglvl
, ", MAC=%pM", filter
->mac
);
1506 DP_CONT(msglvl
, "\n");
1509 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x
*bp
, int msglvl
,
1510 struct vfpf_set_q_filters_tlv
*filters
)
1514 if (filters
->flags
& VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED
)
1515 for (i
= 0; i
< filters
->n_mac_vlan_filters
; i
++)
1516 bnx2x_vf_mbx_dp_q_filter(bp
, msglvl
, i
,
1517 &filters
->filters
[i
]);
1519 if (filters
->flags
& VFPF_SET_Q_FILTERS_RX_MASK_CHANGED
)
1520 DP(msglvl
, "RX-MASK=0x%x\n", filters
->rx_mask
);
1522 if (filters
->flags
& VFPF_SET_Q_FILTERS_MULTICAST_CHANGED
)
1523 for (i
= 0; i
< filters
->n_multicast
; i
++)
1524 DP(msglvl
, "MULTICAST=%pM\n", filters
->multicast
[i
]);
1527 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
1528 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
1530 static void bnx2x_vfop_mbx_qfilters(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
)
1534 struct vfpf_set_q_filters_tlv
*msg
=
1535 &BP_VF_MBX(bp
, vf
->index
)->msg
->req
.set_q_filters
;
1537 struct bnx2x_vfop
*vfop
= bnx2x_vfop_cur(bp
, vf
);
1538 enum bnx2x_vfop_filters_state state
= vfop
->state
;
1540 struct bnx2x_vfop_cmd cmd
= {
1541 .done
= bnx2x_vfop_mbx_qfilters
,
1545 DP(BNX2X_MSG_IOV
, "STATE: %d\n", state
);
1551 case BNX2X_VFOP_MBX_Q_FILTERS_MACS
:
1553 vfop
->state
= BNX2X_VFOP_MBX_Q_FILTERS_VLANS
;
1555 /* check for any vlan/mac changes */
1556 if (msg
->flags
& VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED
) {
1557 /* build mac list */
1558 struct bnx2x_vfop_filters
*fl
= NULL
;
1560 vfop
->rc
= bnx2x_vf_mbx_macvlan_list(bp
, vf
, msg
, &fl
,
1567 rc
= bnx2x_vfop_mac_list_cmd(bp
, vf
, &cmd
, fl
,
1579 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS
:
1581 vfop
->state
= BNX2X_VFOP_MBX_Q_FILTERS_RXMODE
;
1583 /* check for any vlan/mac changes */
1584 if (msg
->flags
& VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED
) {
1585 /* build vlan list */
1586 struct bnx2x_vfop_filters
*fl
= NULL
;
1588 vfop
->rc
= bnx2x_vf_mbx_macvlan_list(bp
, vf
, msg
, &fl
,
1595 rc
= bnx2x_vfop_vlan_list_cmd(bp
, vf
, &cmd
, fl
,
1607 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE
:
1609 vfop
->state
= BNX2X_VFOP_MBX_Q_FILTERS_MCAST
;
1611 if (msg
->flags
& VFPF_SET_Q_FILTERS_RX_MASK_CHANGED
) {
1612 unsigned long accept
= 0;
1613 struct pf_vf_bulletin_content
*bulletin
=
1614 BP_VF_BULLETIN(bp
, vf
->index
);
1616 /* covert VF-PF if mask to bnx2x accept flags */
1617 if (msg
->rx_mask
& VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST
)
1618 __set_bit(BNX2X_ACCEPT_UNICAST
, &accept
);
1621 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST
)
1622 __set_bit(BNX2X_ACCEPT_MULTICAST
, &accept
);
1624 if (msg
->rx_mask
& VFPF_RX_MASK_ACCEPT_ALL_UNICAST
)
1625 __set_bit(BNX2X_ACCEPT_ALL_UNICAST
, &accept
);
1627 if (msg
->rx_mask
& VFPF_RX_MASK_ACCEPT_ALL_MULTICAST
)
1628 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &accept
);
1630 if (msg
->rx_mask
& VFPF_RX_MASK_ACCEPT_BROADCAST
)
1631 __set_bit(BNX2X_ACCEPT_BROADCAST
, &accept
);
1633 /* A packet arriving the vf's mac should be accepted
1634 * with any vlan, unless a vlan has already been
1637 if (!(bulletin
->valid_bitmap
& (1 << VLAN_VALID
)))
1638 __set_bit(BNX2X_ACCEPT_ANY_VLAN
, &accept
);
1641 rc
= bnx2x_vfop_rxmode_cmd(bp
, vf
, &cmd
,
1642 msg
->vf_qid
, accept
);
1651 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST
:
1653 vfop
->state
= BNX2X_VFOP_MBX_Q_FILTERS_DONE
;
1655 if (msg
->flags
& VFPF_SET_Q_FILTERS_MULTICAST_CHANGED
) {
1657 rc
= bnx2x_vfop_mcast_cmd(bp
, vf
, &cmd
, msg
->multicast
,
1658 msg
->n_multicast
, false);
1667 case BNX2X_VFOP_MBX_Q_FILTERS_DONE
:
1668 bnx2x_vfop_end(bp
, vf
, vfop
);
1671 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1672 vf
->abs_vfid
, msg
->vf_qid
, vfop
->rc
);
1676 bnx2x_vfop_default(state
);
1680 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x
*bp
,
1681 struct bnx2x_virtf
*vf
,
1682 struct bnx2x_vfop_cmd
*cmd
)
1684 struct bnx2x_vfop
*vfop
= bnx2x_vfop_add(bp
, vf
);
1686 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS
,
1687 bnx2x_vfop_mbx_qfilters
, cmd
->done
);
1688 return bnx2x_vfop_transition(bp
, vf
, bnx2x_vfop_mbx_qfilters
,
1694 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x
*bp
,
1695 struct bnx2x_virtf
*vf
,
1696 struct bnx2x_vf_mbx
*mbx
)
1698 struct vfpf_set_q_filters_tlv
*filters
= &mbx
->msg
->req
.set_q_filters
;
1699 struct pf_vf_bulletin_content
*bulletin
= BP_VF_BULLETIN(bp
, vf
->index
);
1700 struct bnx2x_vfop_cmd cmd
= {
1701 .done
= bnx2x_vf_mbx_resp
,
1705 /* if a mac was already set for this VF via the set vf mac ndo, we only
1706 * accept mac configurations of that mac. Why accept them at all?
1707 * because PF may have been unable to configure the mac at the time
1708 * since queue was not set up.
1710 if (bulletin
->valid_bitmap
& 1 << MAC_ADDR_VALID
) {
1711 /* once a mac was set by ndo can only accept a single mac... */
1712 if (filters
->n_mac_vlan_filters
> 1) {
1713 BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1719 /* ...and only the mac set by the ndo */
1720 if (filters
->n_mac_vlan_filters
== 1 &&
1721 !ether_addr_equal(filters
->filters
->mac
, bulletin
->mac
)) {
1722 BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1729 /* if vlan was set by hypervisor we don't allow guest to config vlan */
1730 if (bulletin
->valid_bitmap
& 1 << VLAN_VALID
) {
1733 /* search for vlan filters */
1734 for (i
= 0; i
< filters
->n_mac_vlan_filters
; i
++) {
1735 if (filters
->filters
[i
].flags
&
1736 VFPF_Q_FILTER_VLAN_TAG_VALID
) {
1737 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1746 if (filters
->vf_qid
> vf_rxq_count(vf
))
1749 DP(BNX2X_MSG_IOV
, "VF[%d] Q_FILTERS: queue[%d]\n",
1753 /* print q_filter message */
1754 bnx2x_vf_mbx_dp_q_filters(bp
, BNX2X_MSG_IOV
, filters
);
1756 vf
->op_rc
= bnx2x_vfop_mbx_qfilters_cmd(bp
, vf
, &cmd
);
1762 bnx2x_vf_mbx_resp(bp
, vf
);
1765 static void bnx2x_vf_mbx_teardown_q(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1766 struct bnx2x_vf_mbx
*mbx
)
1768 int qid
= mbx
->msg
->req
.q_op
.vf_qid
;
1769 struct bnx2x_vfop_cmd cmd
= {
1770 .done
= bnx2x_vf_mbx_resp
,
1774 DP(BNX2X_MSG_IOV
, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1777 vf
->op_rc
= bnx2x_vfop_qdown_cmd(bp
, vf
, &cmd
, qid
);
1779 bnx2x_vf_mbx_resp(bp
, vf
);
1782 static void bnx2x_vf_mbx_close_vf(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1783 struct bnx2x_vf_mbx
*mbx
)
1785 struct bnx2x_vfop_cmd cmd
= {
1786 .done
= bnx2x_vf_mbx_resp
,
1790 DP(BNX2X_MSG_IOV
, "VF[%d] VF_CLOSE\n", vf
->abs_vfid
);
1792 vf
->op_rc
= bnx2x_vfop_close_cmd(bp
, vf
, &cmd
);
1794 bnx2x_vf_mbx_resp(bp
, vf
);
1797 static void bnx2x_vf_mbx_release_vf(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1798 struct bnx2x_vf_mbx
*mbx
)
1800 struct bnx2x_vfop_cmd cmd
= {
1801 .done
= bnx2x_vf_mbx_resp
,
1805 DP(BNX2X_MSG_IOV
, "VF[%d] VF_RELEASE\n", vf
->abs_vfid
);
1807 vf
->op_rc
= bnx2x_vfop_release_cmd(bp
, vf
, &cmd
);
1809 bnx2x_vf_mbx_resp(bp
, vf
);
1812 static void bnx2x_vf_mbx_update_rss(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1813 struct bnx2x_vf_mbx
*mbx
)
1815 struct bnx2x_vfop_cmd cmd
= {
1816 .done
= bnx2x_vf_mbx_resp
,
1819 struct bnx2x_config_rss_params
*vf_op_params
= &vf
->op_params
.rss
;
1820 struct vfpf_rss_tlv
*rss_tlv
= &mbx
->msg
->req
.update_rss
;
1822 if (rss_tlv
->ind_table_size
!= T_ETH_INDIRECTION_TABLE_SIZE
||
1823 rss_tlv
->rss_key_size
!= T_ETH_RSS_KEY
) {
1824 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1826 vf
->op_rc
= -EINVAL
;
1830 /* set vfop params according to rss tlv */
1831 memcpy(vf_op_params
->ind_table
, rss_tlv
->ind_table
,
1832 T_ETH_INDIRECTION_TABLE_SIZE
);
1833 memcpy(vf_op_params
->rss_key
, rss_tlv
->rss_key
,
1834 sizeof(rss_tlv
->rss_key
));
1835 vf_op_params
->rss_obj
= &vf
->rss_conf_obj
;
1836 vf_op_params
->rss_result_mask
= rss_tlv
->rss_result_mask
;
1838 /* flags handled individually for backward/forward compatability */
1839 vf_op_params
->rss_flags
= 0;
1840 vf_op_params
->ramrod_flags
= 0;
1842 if (rss_tlv
->rss_flags
& VFPF_RSS_MODE_DISABLED
)
1843 __set_bit(BNX2X_RSS_MODE_DISABLED
, &vf_op_params
->rss_flags
);
1844 if (rss_tlv
->rss_flags
& VFPF_RSS_MODE_REGULAR
)
1845 __set_bit(BNX2X_RSS_MODE_REGULAR
, &vf_op_params
->rss_flags
);
1846 if (rss_tlv
->rss_flags
& VFPF_RSS_SET_SRCH
)
1847 __set_bit(BNX2X_RSS_SET_SRCH
, &vf_op_params
->rss_flags
);
1848 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV4
)
1849 __set_bit(BNX2X_RSS_IPV4
, &vf_op_params
->rss_flags
);
1850 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV4_TCP
)
1851 __set_bit(BNX2X_RSS_IPV4_TCP
, &vf_op_params
->rss_flags
);
1852 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV4_UDP
)
1853 __set_bit(BNX2X_RSS_IPV4_UDP
, &vf_op_params
->rss_flags
);
1854 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV6
)
1855 __set_bit(BNX2X_RSS_IPV6
, &vf_op_params
->rss_flags
);
1856 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV6_TCP
)
1857 __set_bit(BNX2X_RSS_IPV6_TCP
, &vf_op_params
->rss_flags
);
1858 if (rss_tlv
->rss_flags
& VFPF_RSS_IPV6_UDP
)
1859 __set_bit(BNX2X_RSS_IPV6_UDP
, &vf_op_params
->rss_flags
);
1861 if ((!(rss_tlv
->rss_flags
& VFPF_RSS_IPV4_TCP
) &&
1862 rss_tlv
->rss_flags
& VFPF_RSS_IPV4_UDP
) ||
1863 (!(rss_tlv
->rss_flags
& VFPF_RSS_IPV6_TCP
) &&
1864 rss_tlv
->rss_flags
& VFPF_RSS_IPV6_UDP
)) {
1865 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1866 vf
->op_rc
= -EINVAL
;
1870 vf
->op_rc
= bnx2x_vfop_rss_cmd(bp
, vf
, &cmd
);
1874 bnx2x_vf_mbx_resp(bp
, vf
);
1877 /* dispatch request */
1878 static void bnx2x_vf_mbx_request(struct bnx2x
*bp
, struct bnx2x_virtf
*vf
,
1879 struct bnx2x_vf_mbx
*mbx
)
1883 /* check if tlv type is known */
1884 if (bnx2x_tlv_supported(mbx
->first_tlv
.tl
.type
)) {
1885 /* Lock the per vf op mutex and note the locker's identity.
1886 * The unlock will take place in mbx response.
1888 bnx2x_lock_vf_pf_channel(bp
, vf
, mbx
->first_tlv
.tl
.type
);
1890 /* switch on the opcode */
1891 switch (mbx
->first_tlv
.tl
.type
) {
1892 case CHANNEL_TLV_ACQUIRE
:
1893 bnx2x_vf_mbx_acquire(bp
, vf
, mbx
);
1895 case CHANNEL_TLV_INIT
:
1896 bnx2x_vf_mbx_init_vf(bp
, vf
, mbx
);
1898 case CHANNEL_TLV_SETUP_Q
:
1899 bnx2x_vf_mbx_setup_q(bp
, vf
, mbx
);
1901 case CHANNEL_TLV_SET_Q_FILTERS
:
1902 bnx2x_vf_mbx_set_q_filters(bp
, vf
, mbx
);
1904 case CHANNEL_TLV_TEARDOWN_Q
:
1905 bnx2x_vf_mbx_teardown_q(bp
, vf
, mbx
);
1907 case CHANNEL_TLV_CLOSE
:
1908 bnx2x_vf_mbx_close_vf(bp
, vf
, mbx
);
1910 case CHANNEL_TLV_RELEASE
:
1911 bnx2x_vf_mbx_release_vf(bp
, vf
, mbx
);
1913 case CHANNEL_TLV_UPDATE_RSS
:
1914 bnx2x_vf_mbx_update_rss(bp
, vf
, mbx
);
1919 /* unknown TLV - this may belong to a VF driver from the future
1920 * - a version written after this PF driver was written, which
1921 * supports features unknown as of yet. Too bad since we don't
1922 * support them. Or this may be because someone wrote a crappy
1923 * VF driver and is sending garbage over the channel.
1925 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
1926 mbx
->first_tlv
.tl
.type
, mbx
->first_tlv
.tl
.length
,
1928 for (i
= 0; i
< 20; i
++)
1929 DP_CONT(BNX2X_MSG_IOV
, "%x ",
1930 mbx
->msg
->req
.tlv_buf_size
.tlv_buffer
[i
]);
1933 /* can we respond to VF (do we have an address for it?) */
1934 if (vf
->state
== VF_ACQUIRED
|| vf
->state
== VF_ENABLED
) {
1935 /* mbx_resp uses the op_rc of the VF */
1936 vf
->op_rc
= PFVF_STATUS_NOT_SUPPORTED
;
1938 /* notify the VF that we do not support this request */
1939 bnx2x_vf_mbx_resp(bp
, vf
);
1941 /* can't send a response since this VF is unknown to us
1942 * just ack the FW to release the mailbox and unlock
1945 storm_memset_vf_mbx_ack(bp
, vf
->abs_vfid
);
1946 /* Firmware ack should be written before unlocking channel */
1948 bnx2x_unlock_vf_pf_channel(bp
, vf
, mbx
->first_tlv
.tl
.type
);
1952 /* handle new vf-pf message */
1953 void bnx2x_vf_mbx(struct bnx2x
*bp
, struct vf_pf_event_data
*vfpf_event
)
1955 struct bnx2x_virtf
*vf
;
1956 struct bnx2x_vf_mbx
*mbx
;
1961 "vf pf event received: vfid %d, address_hi %x, address lo %x",
1962 vfpf_event
->vf_id
, vfpf_event
->msg_addr_hi
, vfpf_event
->msg_addr_lo
);
1963 /* Sanity checks consider removing later */
1965 /* check if the vf_id is valid */
1966 if (vfpf_event
->vf_id
- BP_VFDB(bp
)->sriov
.first_vf_in_pf
>
1967 BNX2X_NR_VIRTFN(bp
)) {
1968 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1969 vfpf_event
->vf_id
, BNX2X_NR_VIRTFN(bp
));
1972 vf_idx
= bnx2x_vf_idx_by_abs_fid(bp
, vfpf_event
->vf_id
);
1973 mbx
= BP_VF_MBX(bp
, vf_idx
);
1975 /* verify an event is not currently being processed -
1976 * debug failsafe only
1978 if (mbx
->flags
& VF_MSG_INPROCESS
) {
1979 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1983 vf
= BP_VF(bp
, vf_idx
);
1985 /* save the VF message address */
1986 mbx
->vf_addr_hi
= vfpf_event
->msg_addr_hi
;
1987 mbx
->vf_addr_lo
= vfpf_event
->msg_addr_lo
;
1988 DP(BNX2X_MSG_IOV
, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1989 mbx
->vf_addr_hi
, mbx
->vf_addr_lo
, mbx
->first_tlv
.resp_msg_offset
);
1991 /* dmae to get the VF request */
1992 rc
= bnx2x_copy32_vf_dmae(bp
, true, mbx
->msg_mapping
, vf
->abs_vfid
,
1993 mbx
->vf_addr_hi
, mbx
->vf_addr_lo
,
1994 sizeof(union vfpf_tlvs
)/4);
1996 BNX2X_ERR("Failed to copy request VF %d\n", vf
->abs_vfid
);
2000 /* process the VF message header */
2001 mbx
->first_tlv
= mbx
->msg
->req
.first_tlv
;
2003 /* Clean response buffer to refrain from falsely seeing chains */
2004 memset(&mbx
->msg
->resp
, 0, sizeof(union pfvf_tlvs
));
2006 /* dispatch the request (will prepare the response) */
2007 bnx2x_vf_mbx_request(bp
, vf
, mbx
);
2011 bnx2x_vf_release(bp
, vf
, false); /* non blocking */
2016 /* propagate local bulletin board to vf */
2017 int bnx2x_post_vf_bulletin(struct bnx2x
*bp
, int vf
)
2019 struct pf_vf_bulletin_content
*bulletin
= BP_VF_BULLETIN(bp
, vf
);
2020 dma_addr_t pf_addr
= BP_VF_BULLETIN_DMA(bp
)->mapping
+
2021 vf
* BULLETIN_CONTENT_SIZE
;
2022 dma_addr_t vf_addr
= bnx2x_vf(bp
, vf
, bulletin_map
);
2025 /* can only update vf after init took place */
2026 if (bnx2x_vf(bp
, vf
, state
) != VF_ENABLED
&&
2027 bnx2x_vf(bp
, vf
, state
) != VF_ACQUIRED
)
2030 /* increment bulletin board version and compute crc */
2031 bulletin
->version
++;
2032 bulletin
->length
= BULLETIN_CONTENT_SIZE
;
2033 bulletin
->crc
= bnx2x_crc_vf_bulletin(bp
, bulletin
);
2035 /* propagate bulletin board via dmae to vm memory */
2036 rc
= bnx2x_copy32_vf_dmae(bp
, false, pf_addr
,
2037 bnx2x_vf(bp
, vf
, abs_vfid
), U64_HI(vf_addr
),
2038 U64_LO(vf_addr
), bulletin
->length
/ 4);