1 /* bnx2x_vfpf.c: Broadcom Everest network driver.
3 * Copyright 2009-2012 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_sriov.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 /* General service functions */
102 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
104 u32 addr = BAR_CSTRORM_INTMEM +
105 CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
107 REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
110 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
112 u32 addr = BAR_CSTRORM_INTMEM +
113 CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
115 REG_WR8(bp, addr, 1);
118 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
123 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
126 /* enable vf_pf mailbox (aka vf-pf-chanell) */
127 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
129 bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
131 /* enable the mailbox in the FW */
132 storm_memset_vf_mbx_ack(bp, abs_vfid);
133 storm_memset_vf_mbx_valid(bp, abs_vfid);
135 /* enable the VF access to the mailbox */
136 bnx2x_vf_enable_access(bp, abs_vfid);
139 /* this works only on !E1h */
140 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
141 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
142 u32 vf_addr_lo, u32 len32)
144 struct dmae_command dmae;
146 if (CHIP_IS_E1x(bp)) {
147 BNX2X_ERR("Chip revision does not support VFs\n");
151 if (!bp->dmae_ready) {
152 BNX2X_ERR("DMAE is not ready, can not copy\n");
156 /* set opcode and fixed command fields */
157 bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
160 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
161 (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
162 (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
164 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
166 dmae.src_addr_lo = vf_addr_lo;
167 dmae.src_addr_hi = vf_addr_hi;
168 dmae.dst_addr_lo = U64_LO(pf_addr);
169 dmae.dst_addr_hi = U64_HI(pf_addr);
171 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
172 (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
173 (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
175 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
177 dmae.src_addr_lo = U64_LO(pf_addr);
178 dmae.src_addr_hi = U64_HI(pf_addr);
179 dmae.dst_addr_lo = vf_addr_lo;
180 dmae.dst_addr_hi = vf_addr_hi;
183 bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
185 /* issue the command and wait for completion */
186 return bnx2x_issue_dmae_with_comp(bp, &dmae);
189 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
191 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
196 struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
198 /* prepare response */
199 type = mbx->first_tlv.tl.type;
200 length = type == CHANNEL_TLV_ACQUIRE ?
201 sizeof(struct pfvf_acquire_resp_tlv) :
202 sizeof(struct pfvf_general_resp_tlv);
203 bnx2x_add_tlv(bp, resp, 0, type, length);
204 resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
205 bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
206 sizeof(struct channel_list_end_tlv));
207 bnx2x_dp_tlv_list(bp, resp);
208 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
209 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
212 vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
213 mbx->first_tlv.resp_msg_offset;
214 pf_addr = mbx->msg_mapping +
215 offsetof(struct bnx2x_vf_mbx_msg, resp);
217 /* copy the response body, if there is one, before the header, as the vf
218 * is sensitive to the header being written
220 if (resp->hdr.tl.length > sizeof(u64)) {
221 length = resp->hdr.tl.length - sizeof(u64);
222 vf_addr += sizeof(u64);
223 pf_addr += sizeof(u64);
224 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
229 BNX2X_ERR("Failed to copy response body to VF %d\n",
233 vf_addr -= sizeof(u64);
234 pf_addr -= sizeof(u64);
238 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
241 /* initiate dmae to send the response */
242 mbx->flags &= ~VF_MSG_INPROCESS;
244 /* copy the response header including status-done field,
245 * must be last dmae, must be after FW is acked
247 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
252 /* unlock channel mutex */
253 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
256 BNX2X_ERR("Failed to copy response status to VF %d\n",
262 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
263 struct bnx2x_vf_mbx *mbx, int vfop_status)
266 struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
267 struct pf_vf_resc *resc = &resp->resc;
268 u8 status = bnx2x_pfvf_status_codes(vfop_status);
270 memset(resp, 0, sizeof(*resp));
272 /* fill in pfdev info */
273 resp->pfdev_info.chip_num = bp->common.chip_id;
274 resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
275 resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
276 resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
277 /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
278 bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
279 sizeof(resp->pfdev_info.fw_ver));
281 if (status == PFVF_STATUS_NO_RESOURCE ||
282 status == PFVF_STATUS_SUCCESS) {
283 /* set resources numbers, if status equals NO_RESOURCE these
284 * are max possible numbers
286 resc->num_rxqs = vf_rxq_count(vf) ? :
287 bnx2x_vf_max_queue_cnt(bp, vf);
288 resc->num_txqs = vf_txq_count(vf) ? :
289 bnx2x_vf_max_queue_cnt(bp, vf);
290 resc->num_sbs = vf_sb_count(vf);
291 resc->num_mac_filters = vf_mac_rules_cnt(vf);
292 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
293 resc->num_mc_filters = 0;
295 if (status == PFVF_STATUS_SUCCESS) {
298 vfq_qzone_id(vf, vfq_get(vf, i));
300 for_each_vf_sb(vf, i) {
301 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
302 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
307 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"
308 "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
310 resp->pfdev_info.chip_num,
311 resp->pfdev_info.db_size,
312 resp->pfdev_info.indices_per_sb,
313 resp->pfdev_info.pf_cap,
317 resc->num_mac_filters,
318 resc->num_vlan_filters,
319 resc->num_mc_filters,
320 resp->pfdev_info.fw_ver);
322 DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
323 for (i = 0; i < vf_rxq_count(vf); i++)
324 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
325 DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
326 for (i = 0; i < vf_sb_count(vf); i++)
327 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
328 resc->hw_sbs[i].hw_sb_id,
329 resc->hw_sbs[i].sb_qid);
330 DP_CONT(BNX2X_MSG_IOV, "]\n");
332 /* send the response */
333 vf->op_rc = vfop_status;
334 bnx2x_vf_mbx_resp(bp, vf);
337 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
338 struct bnx2x_vf_mbx *mbx)
341 struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
345 "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",
346 vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
347 acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
348 acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
349 acquire->resc_request.num_vlan_filters,
350 acquire->resc_request.num_mc_filters);
352 /* acquire the resources */
353 rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
356 bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
359 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
360 struct bnx2x_vf_mbx *mbx)
362 struct vfpf_init_tlv *init = &mbx->msg->req.init;
364 /* record ghost addresses from vf message */
365 vf->spq_map = init->spq_addr;
366 vf->fw_stat_map = init->stats_addr;
367 vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
370 bnx2x_vf_mbx_resp(bp, vf);
373 /* convert MBX queue-flags to standard SP queue-flags */
374 static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags,
375 unsigned long *sp_q_flags)
377 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
378 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
379 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
380 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
381 if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
382 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
383 if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
384 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
385 if (mbx_q_flags & VFPF_QUEUE_FLG_OV)
386 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
387 if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
388 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
389 if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
390 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
391 if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
392 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
393 if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
394 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
397 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
398 struct bnx2x_vf_mbx *mbx)
400 struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
401 struct bnx2x_vfop_cmd cmd = {
402 .done = bnx2x_vf_mbx_resp,
407 if (setup_q->vf_qid >= vf_rxq_count(vf)) {
408 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
409 setup_q->vf_qid, vf_rxq_count(vf));
414 /* tx queues must be setup alongside rx queues thus if the rx queue
415 * is not marked as valid there's nothing to do.
417 if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
418 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
419 unsigned long q_type = 0;
421 struct bnx2x_queue_init_params *init_p;
422 struct bnx2x_queue_setup_params *setup_p;
424 /* reinit the VF operation context */
425 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
426 setup_p = &vf->op_params.qctor.prep_qsetup;
427 init_p = &vf->op_params.qctor.qstate.params.init;
429 /* activate immediately */
430 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
432 if (setup_q->param_valid & VFPF_TXQ_VALID) {
433 struct bnx2x_txq_setup_params *txq_params =
434 &setup_p->txq_params;
436 __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
438 /* save sb resource index */
439 q->sb_idx = setup_q->txq.vf_sb;
442 init_p->tx.hc_rate = setup_q->txq.hc_rate;
443 init_p->tx.sb_cq_index = setup_q->txq.sb_index;
445 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
448 /* tx setup - flags */
449 bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
452 /* tx setup - general, nothing */
455 txq_params->dscr_map = setup_q->txq.txq_addr;
456 txq_params->sb_cq_index = setup_q->txq.sb_index;
457 txq_params->traffic_type = setup_q->txq.traffic_type;
459 bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
460 q->index, q->sb_idx);
463 if (setup_q->param_valid & VFPF_RXQ_VALID) {
464 struct bnx2x_rxq_setup_params *rxq_params =
465 &setup_p->rxq_params;
467 __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
469 /* Note: there is no support for different SBs
472 q->sb_idx = setup_q->rxq.vf_sb;
475 init_p->rx.hc_rate = setup_q->rxq.hc_rate;
476 init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
477 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
480 /* rx setup - flags */
481 bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
484 /* rx setup - general */
485 setup_p->gen_params.mtu = setup_q->rxq.mtu;
488 rxq_params->drop_flags = setup_q->rxq.drop_flags;
489 rxq_params->dscr_map = setup_q->rxq.rxq_addr;
490 rxq_params->sge_map = setup_q->rxq.sge_addr;
491 rxq_params->rcq_map = setup_q->rxq.rcq_addr;
492 rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
493 rxq_params->buf_sz = setup_q->rxq.buf_sz;
494 rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
495 rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
496 rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
497 rxq_params->cache_line_log =
498 setup_q->rxq.cache_line_log;
499 rxq_params->sb_cq_index = setup_q->rxq.sb_index;
501 bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
502 q->index, q->sb_idx);
504 /* complete the preparations */
505 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
507 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
513 bnx2x_vf_mbx_resp(bp, vf);
516 enum bnx2x_vfop_filters_state {
517 BNX2X_VFOP_MBX_Q_FILTERS_MACS,
518 BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
519 BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
520 BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
521 BNX2X_VFOP_MBX_Q_FILTERS_DONE
524 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
525 struct bnx2x_virtf *vf,
526 struct vfpf_set_q_filters_tlv *tlv,
527 struct bnx2x_vfop_filters **pfl,
531 struct bnx2x_vfop_filters *fl = NULL;
534 fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
535 sizeof(struct bnx2x_vfop_filters);
537 fl = kzalloc(fsz, GFP_KERNEL);
541 INIT_LIST_HEAD(&fl->head);
543 for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
544 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
546 if ((msg_filter->flags & type_flag) != type_flag)
548 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
549 fl->filters[j].mac = msg_filter->mac;
550 fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
552 fl->filters[j].vid = msg_filter->vlan_tag;
553 fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
556 (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
558 list_add_tail(&fl->filters[j++].link, &fl->head);
560 if (list_empty(&fl->head))
568 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
569 struct vfpf_q_mac_vlan_filter *filter)
571 DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
572 if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
573 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
574 if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
575 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
576 DP_CONT(msglvl, "\n");
579 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
580 struct vfpf_set_q_filters_tlv *filters)
584 if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
585 for (i = 0; i < filters->n_mac_vlan_filters; i++)
586 bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
587 &filters->filters[i]);
589 if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
590 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
592 if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
593 for (i = 0; i < filters->n_multicast; i++)
594 DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
597 #define VFPF_MAC_FILTER VFPF_Q_FILTER_DEST_MAC_VALID
598 #define VFPF_VLAN_FILTER VFPF_Q_FILTER_VLAN_TAG_VALID
600 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
604 struct vfpf_set_q_filters_tlv *msg =
605 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
607 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
608 enum bnx2x_vfop_filters_state state = vfop->state;
610 struct bnx2x_vfop_cmd cmd = {
611 .done = bnx2x_vfop_mbx_qfilters,
615 DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
621 case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
623 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
625 /* check for any vlan/mac changes */
626 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
628 struct bnx2x_vfop_filters *fl = NULL;
630 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
637 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
649 case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
651 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
653 /* check for any vlan/mac changes */
654 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
655 /* build vlan list */
656 struct bnx2x_vfop_filters *fl = NULL;
658 vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
665 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
677 case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
679 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
681 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
682 unsigned long accept = 0;
684 /* covert VF-PF if mask to bnx2x accept flags */
685 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
686 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
689 VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
690 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
692 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
693 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
695 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
696 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
698 if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
699 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
701 /* A packet arriving the vf's mac should be accepted
704 __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
707 rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
708 msg->vf_qid, accept);
717 case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
719 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
721 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
723 rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
724 msg->n_multicast, false);
733 case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
734 bnx2x_vfop_end(bp, vf, vfop);
737 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
738 vf->abs_vfid, msg->vf_qid, vfop->rc);
742 bnx2x_vfop_default(state);
746 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
747 struct bnx2x_virtf *vf,
748 struct bnx2x_vfop_cmd *cmd)
750 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
752 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
753 bnx2x_vfop_mbx_qfilters, cmd->done);
754 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
760 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
761 struct bnx2x_virtf *vf,
762 struct bnx2x_vf_mbx *mbx)
764 struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
765 struct bnx2x_vfop_cmd cmd = {
766 .done = bnx2x_vf_mbx_resp,
771 if (filters->vf_qid > vf_rxq_count(vf))
774 DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
778 /* print q_filter message */
779 bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
781 vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
787 bnx2x_vf_mbx_resp(bp, vf);
790 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
791 struct bnx2x_vf_mbx *mbx)
793 int qid = mbx->msg->req.q_op.vf_qid;
794 struct bnx2x_vfop_cmd cmd = {
795 .done = bnx2x_vf_mbx_resp,
799 DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
802 vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
804 bnx2x_vf_mbx_resp(bp, vf);
807 /* dispatch request */
808 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
809 struct bnx2x_vf_mbx *mbx)
813 /* check if tlv type is known */
814 if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
815 /* Lock the per vf op mutex and note the locker's identity.
816 * The unlock will take place in mbx response.
818 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
820 /* switch on the opcode */
821 switch (mbx->first_tlv.tl.type) {
822 case CHANNEL_TLV_ACQUIRE:
823 bnx2x_vf_mbx_acquire(bp, vf, mbx);
825 case CHANNEL_TLV_INIT:
826 bnx2x_vf_mbx_init_vf(bp, vf, mbx);
828 case CHANNEL_TLV_SETUP_Q:
829 bnx2x_vf_mbx_setup_q(bp, vf, mbx);
831 case CHANNEL_TLV_SET_Q_FILTERS:
832 bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
834 case CHANNEL_TLV_TEARDOWN_Q:
835 bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
840 /* unknown TLV - this may belong to a VF driver from the future
841 * - a version written after this PF driver was written, which
842 * supports features unknown as of yet. Too bad since we don't
843 * support them. Or this may be because someone wrote a crappy
844 * VF driver and is sending garbage over the channel.
846 BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
847 mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
848 for (i = 0; i < 20; i++)
849 DP_CONT(BNX2X_MSG_IOV, "%x ",
850 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
852 /* test whether we can respond to the VF (do we have an address
855 if (vf->state == VF_ACQUIRED) {
856 /* mbx_resp uses the op_rc of the VF */
857 vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
859 /* notify the VF that we do not support this request */
860 bnx2x_vf_mbx_resp(bp, vf);
862 /* can't send a response since this VF is unknown to us
863 * just unlock the channel and be done with.
865 bnx2x_unlock_vf_pf_channel(bp, vf,
866 mbx->first_tlv.tl.type);
871 /* handle new vf-pf message */
872 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
874 struct bnx2x_virtf *vf;
875 struct bnx2x_vf_mbx *mbx;
880 "vf pf event received: vfid %d, address_hi %x, address lo %x",
881 vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
882 /* Sanity checks consider removing later */
884 /* check if the vf_id is valid */
885 if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
886 BNX2X_NR_VIRTFN(bp)) {
887 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
888 vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
891 vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
892 mbx = BP_VF_MBX(bp, vf_idx);
894 /* verify an event is not currently being processed -
895 * debug failsafe only
897 if (mbx->flags & VF_MSG_INPROCESS) {
898 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
902 vf = BP_VF(bp, vf_idx);
904 /* save the VF message address */
905 mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
906 mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
907 DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
908 mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
910 /* dmae to get the VF request */
911 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
912 mbx->vf_addr_hi, mbx->vf_addr_lo,
913 sizeof(union vfpf_tlvs)/4);
915 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
919 /* process the VF message header */
920 mbx->first_tlv = mbx->msg->req.first_tlv;
922 /* dispatch the request (will prepare the response) */
923 bnx2x_vf_mbx_request(bp, vf, mbx);