1 /* bnx2x_sriov.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_init.h"
22 #include "bnx2x_cmn.h"
24 #include <linux/crc32.h>
25 #include <linux/if_vlan.h>
27 /* General service functions */
28 static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
31 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
33 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
35 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
37 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
41 static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
44 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
46 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
48 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
50 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
54 int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
59 if (bnx2x_vf(bp, idx, abs_vfid) == abs_vfid)
65 struct bnx2x_virtf *bnx2x_vf_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
67 u16 idx = (u16)bnx2x_vf_idx_by_abs_fid(bp, abs_vfid);
68 return (idx < BNX2X_NR_VIRTFN(bp)) ? BP_VF(bp, idx) : NULL;
71 static void bnx2x_vf_igu_ack_sb(struct bnx2x *bp, struct bnx2x_virtf *vf,
72 u8 igu_sb_id, u8 segment, u16 index, u8 op,
75 /* acking a VF sb through the PF - use the GRC */
77 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
78 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
79 u32 func_encode = vf->abs_vfid;
80 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + igu_sb_id;
81 struct igu_regular cmd_data = {0};
83 cmd_data.sb_id_and_flags =
84 ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
85 (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
86 (update << IGU_REGULAR_BUPDATE_SHIFT) |
87 (op << IGU_REGULAR_ENABLE_INT_SHIFT));
89 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
90 func_encode << IGU_CTRL_REG_FID_SHIFT |
91 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
93 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
94 cmd_data.sb_id_and_flags, igu_addr_data);
95 REG_WR(bp, igu_addr_data, cmd_data.sb_id_and_flags);
99 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
101 REG_WR(bp, igu_addr_ctl, ctl);
105 /* VFOP - VF slow-path operation support */
107 #define BNX2X_VFOP_FILTER_ADD_CNT_MAX 0x10000
109 /* VFOP operations states */
110 enum bnx2x_vfop_qctor_state {
111 BNX2X_VFOP_QCTOR_INIT,
112 BNX2X_VFOP_QCTOR_SETUP,
113 BNX2X_VFOP_QCTOR_INT_EN
116 enum bnx2x_vfop_qdtor_state {
117 BNX2X_VFOP_QDTOR_HALT,
118 BNX2X_VFOP_QDTOR_TERMINATE,
119 BNX2X_VFOP_QDTOR_CFCDEL,
120 BNX2X_VFOP_QDTOR_DONE
123 enum bnx2x_vfop_vlan_mac_state {
124 BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
125 BNX2X_VFOP_VLAN_MAC_CLEAR,
126 BNX2X_VFOP_VLAN_MAC_CHK_DONE,
127 BNX2X_VFOP_MAC_CONFIG_LIST,
128 BNX2X_VFOP_VLAN_CONFIG_LIST,
129 BNX2X_VFOP_VLAN_CONFIG_LIST_0
132 enum bnx2x_vfop_qsetup_state {
133 BNX2X_VFOP_QSETUP_CTOR,
134 BNX2X_VFOP_QSETUP_VLAN0,
135 BNX2X_VFOP_QSETUP_DONE
138 enum bnx2x_vfop_mcast_state {
139 BNX2X_VFOP_MCAST_DEL,
140 BNX2X_VFOP_MCAST_ADD,
141 BNX2X_VFOP_MCAST_CHK_DONE
143 enum bnx2x_vfop_qflr_state {
144 BNX2X_VFOP_QFLR_CLR_VLAN,
145 BNX2X_VFOP_QFLR_CLR_MAC,
146 BNX2X_VFOP_QFLR_TERMINATE,
150 enum bnx2x_vfop_flr_state {
151 BNX2X_VFOP_FLR_QUEUES,
155 enum bnx2x_vfop_close_state {
156 BNX2X_VFOP_CLOSE_QUEUES,
160 enum bnx2x_vfop_rxmode_state {
161 BNX2X_VFOP_RXMODE_CONFIG,
162 BNX2X_VFOP_RXMODE_DONE
165 enum bnx2x_vfop_qteardown_state {
166 BNX2X_VFOP_QTEARDOWN_RXMODE,
167 BNX2X_VFOP_QTEARDOWN_CLR_VLAN,
168 BNX2X_VFOP_QTEARDOWN_CLR_MAC,
169 BNX2X_VFOP_QTEARDOWN_QDTOR,
170 BNX2X_VFOP_QTEARDOWN_DONE
173 #define bnx2x_vfop_reset_wq(vf) atomic_set(&vf->op_in_progress, 0)
175 void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
176 struct bnx2x_queue_init_params *init_params,
177 struct bnx2x_queue_setup_params *setup_params,
178 u16 q_idx, u16 sb_idx)
181 "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d",
185 init_params->tx.sb_cq_index,
186 init_params->tx.hc_rate,
188 setup_params->txq_params.traffic_type);
191 void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
192 struct bnx2x_queue_init_params *init_params,
193 struct bnx2x_queue_setup_params *setup_params,
194 u16 q_idx, u16 sb_idx)
196 struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params;
198 DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n"
199 "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n",
203 init_params->rx.sb_cq_index,
204 init_params->rx.hc_rate,
205 setup_params->gen_params.mtu,
207 rxq_params->sge_buf_sz,
208 rxq_params->max_sges_pkt,
209 rxq_params->tpa_agg_sz,
211 rxq_params->drop_flags,
212 rxq_params->cache_line_log);
215 void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
216 struct bnx2x_virtf *vf,
217 struct bnx2x_vf_queue *q,
218 struct bnx2x_vfop_qctor_params *p,
219 unsigned long q_type)
221 struct bnx2x_queue_init_params *init_p = &p->qstate.params.init;
222 struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup;
226 /* Enable host coalescing in the transition to INIT state */
227 if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags))
228 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags);
230 if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags))
231 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags);
234 init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
235 init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
238 init_p->cxts[0] = q->cxt;
242 /* Setup-op general parameters */
243 setup_p->gen_params.spcl_id = vf->sp_cl_id;
244 setup_p->gen_params.stat_id = vfq_stat_id(vf, q);
246 /* Setup-op pause params:
247 * Nothing to do, the pause thresholds are set by default to 0 which
248 * effectively turns off the feature for this queue. We don't want
249 * one queue (VF) to interfering with another queue (another VF)
251 if (vf->cfg_flags & VF_CFG_FW_FC)
252 BNX2X_ERR("No support for pause to VFs (abs_vfid: %d)\n",
255 * collect statistics, zero statistics, local-switching, security,
256 * OV for Flex10, RSS and MCAST for leading
258 if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags))
259 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags);
261 /* for VFs, enable tx switching, bd coherency, and mac address
264 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags);
265 __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags);
266 __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags);
268 if (vfq_is_leading(q)) {
269 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &setup_p->flags);
270 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
273 /* Setup-op rx parameters */
274 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) {
275 struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params;
277 rxq_p->cl_qzone_id = vfq_qzone_id(vf, q);
278 rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx);
279 rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid);
281 if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags))
282 rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES;
285 /* Setup-op tx parameters */
286 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) {
287 setup_p->txq_params.tss_leading_cl_id = vf->leading_rss;
288 setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
292 /* VFOP queue construction */
293 static void bnx2x_vfop_qctor(struct bnx2x *bp, struct bnx2x_virtf *vf)
295 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
296 struct bnx2x_vfop_args_qctor *args = &vfop->args.qctor;
297 struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
298 enum bnx2x_vfop_qctor_state state = vfop->state;
300 bnx2x_vfop_reset_wq(vf);
305 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
308 case BNX2X_VFOP_QCTOR_INIT:
310 /* has this queue already been opened? */
311 if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
312 BNX2X_Q_LOGICAL_STATE_ACTIVE) {
314 "Entered qctor but queue was already up. Aborting gracefully\n");
319 vfop->state = BNX2X_VFOP_QCTOR_SETUP;
321 q_params->cmd = BNX2X_Q_CMD_INIT;
322 vfop->rc = bnx2x_queue_state_change(bp, q_params);
324 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
326 case BNX2X_VFOP_QCTOR_SETUP:
328 vfop->state = BNX2X_VFOP_QCTOR_INT_EN;
330 /* copy pre-prepared setup params to the queue-state params */
331 vfop->op_p->qctor.qstate.params.setup =
332 vfop->op_p->qctor.prep_qsetup;
334 q_params->cmd = BNX2X_Q_CMD_SETUP;
335 vfop->rc = bnx2x_queue_state_change(bp, q_params);
337 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
339 case BNX2X_VFOP_QCTOR_INT_EN:
341 /* enable interrupts */
342 bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, args->sb_idx),
343 USTORM_ID, 0, IGU_INT_ENABLE, 0);
346 bnx2x_vfop_default(state);
349 BNX2X_ERR("QCTOR[%d:%d] error: cmd %d, rc %d\n",
350 vf->abs_vfid, args->qid, q_params->cmd, vfop->rc);
352 bnx2x_vfop_end(bp, vf, vfop);
357 static int bnx2x_vfop_qctor_cmd(struct bnx2x *bp,
358 struct bnx2x_virtf *vf,
359 struct bnx2x_vfop_cmd *cmd,
362 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
365 vf->op_params.qctor.qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
367 vfop->args.qctor.qid = qid;
368 vfop->args.qctor.sb_idx = bnx2x_vfq(vf, qid, sb_idx);
370 bnx2x_vfop_opset(BNX2X_VFOP_QCTOR_INIT,
371 bnx2x_vfop_qctor, cmd->done);
372 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qctor,
378 /* VFOP queue destruction */
379 static void bnx2x_vfop_qdtor(struct bnx2x *bp, struct bnx2x_virtf *vf)
381 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
382 struct bnx2x_vfop_args_qdtor *qdtor = &vfop->args.qdtor;
383 struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
384 enum bnx2x_vfop_qdtor_state state = vfop->state;
386 bnx2x_vfop_reset_wq(vf);
391 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
394 case BNX2X_VFOP_QDTOR_HALT:
396 /* has this queue already been stopped? */
397 if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
398 BNX2X_Q_LOGICAL_STATE_STOPPED) {
400 "Entered qdtor but queue was already stopped. Aborting gracefully\n");
405 vfop->state = BNX2X_VFOP_QDTOR_TERMINATE;
407 q_params->cmd = BNX2X_Q_CMD_HALT;
408 vfop->rc = bnx2x_queue_state_change(bp, q_params);
410 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
412 case BNX2X_VFOP_QDTOR_TERMINATE:
414 vfop->state = BNX2X_VFOP_QDTOR_CFCDEL;
416 q_params->cmd = BNX2X_Q_CMD_TERMINATE;
417 vfop->rc = bnx2x_queue_state_change(bp, q_params);
419 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
421 case BNX2X_VFOP_QDTOR_CFCDEL:
423 vfop->state = BNX2X_VFOP_QDTOR_DONE;
425 q_params->cmd = BNX2X_Q_CMD_CFC_DEL;
426 vfop->rc = bnx2x_queue_state_change(bp, q_params);
428 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
430 BNX2X_ERR("QDTOR[%d:%d] error: cmd %d, rc %d\n",
431 vf->abs_vfid, qdtor->qid, q_params->cmd, vfop->rc);
433 case BNX2X_VFOP_QDTOR_DONE:
434 /* invalidate the context */
435 qdtor->cxt->ustorm_ag_context.cdu_usage = 0;
436 qdtor->cxt->xstorm_ag_context.cdu_reserved = 0;
437 bnx2x_vfop_end(bp, vf, vfop);
440 bnx2x_vfop_default(state);
446 static int bnx2x_vfop_qdtor_cmd(struct bnx2x *bp,
447 struct bnx2x_virtf *vf,
448 struct bnx2x_vfop_cmd *cmd,
451 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
454 struct bnx2x_queue_state_params *qstate =
455 &vf->op_params.qctor.qstate;
457 memset(qstate, 0, sizeof(*qstate));
458 qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
460 vfop->args.qdtor.qid = qid;
461 vfop->args.qdtor.cxt = bnx2x_vfq(vf, qid, cxt);
463 bnx2x_vfop_opset(BNX2X_VFOP_QDTOR_HALT,
464 bnx2x_vfop_qdtor, cmd->done);
465 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdtor,
468 DP(BNX2X_MSG_IOV, "VF[%d] failed to add a vfop.\n", vf->abs_vfid);
473 bnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid)
475 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
477 if (!vf_sb_count(vf))
478 vf->igu_base_id = igu_sb_id;
483 /* VFOP MAC/VLAN helpers */
484 static inline void bnx2x_vfop_credit(struct bnx2x *bp,
485 struct bnx2x_vfop *vfop,
486 struct bnx2x_vlan_mac_obj *obj)
488 struct bnx2x_vfop_args_filters *args = &vfop->args.filters;
490 /* update credit only if there is no error
491 * and a valid credit counter
493 if (!vfop->rc && args->credit) {
495 struct list_head *pos;
497 list_for_each(pos, &obj->head)
500 atomic_set(args->credit, cnt);
504 static int bnx2x_vfop_set_user_req(struct bnx2x *bp,
505 struct bnx2x_vfop_filter *pos,
506 struct bnx2x_vlan_mac_data *user_req)
508 user_req->cmd = pos->add ? BNX2X_VLAN_MAC_ADD :
512 case BNX2X_VFOP_FILTER_MAC:
513 memcpy(user_req->u.mac.mac, pos->mac, ETH_ALEN);
515 case BNX2X_VFOP_FILTER_VLAN:
516 user_req->u.vlan.vlan = pos->vid;
519 BNX2X_ERR("Invalid filter type, skipping\n");
526 bnx2x_vfop_config_vlan0(struct bnx2x *bp,
527 struct bnx2x_vlan_mac_ramrod_params *vlan_mac,
532 vlan_mac->user_req.cmd = add ? BNX2X_VLAN_MAC_ADD :
534 vlan_mac->user_req.u.vlan.vlan = 0;
536 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
542 static int bnx2x_vfop_config_list(struct bnx2x *bp,
543 struct bnx2x_vfop_filters *filters,
544 struct bnx2x_vlan_mac_ramrod_params *vlan_mac)
546 struct bnx2x_vfop_filter *pos, *tmp;
547 struct list_head rollback_list, *filters_list = &filters->head;
548 struct bnx2x_vlan_mac_data *user_req = &vlan_mac->user_req;
551 INIT_LIST_HEAD(&rollback_list);
553 list_for_each_entry_safe(pos, tmp, filters_list, link) {
554 if (bnx2x_vfop_set_user_req(bp, pos, user_req))
557 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
559 cnt += pos->add ? 1 : -1;
560 list_del(&pos->link);
561 list_add(&pos->link, &rollback_list);
563 } else if (rc == -EEXIST) {
566 BNX2X_ERR("Failed to add a new vlan_mac command\n");
571 /* rollback if error or too many rules added */
572 if (rc || cnt > filters->add_cnt) {
573 BNX2X_ERR("error or too many rules added. Performing rollback\n");
574 list_for_each_entry_safe(pos, tmp, &rollback_list, link) {
575 pos->add = !pos->add; /* reverse op */
576 bnx2x_vfop_set_user_req(bp, pos, user_req);
577 bnx2x_config_vlan_mac(bp, vlan_mac);
578 list_del(&pos->link);
584 filters->add_cnt = cnt;
588 /* VFOP set VLAN/MAC */
589 static void bnx2x_vfop_vlan_mac(struct bnx2x *bp, struct bnx2x_virtf *vf)
591 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
592 struct bnx2x_vlan_mac_ramrod_params *vlan_mac = &vfop->op_p->vlan_mac;
593 struct bnx2x_vlan_mac_obj *obj = vlan_mac->vlan_mac_obj;
594 struct bnx2x_vfop_filters *filters = vfop->args.filters.multi_filter;
596 enum bnx2x_vfop_vlan_mac_state state = vfop->state;
601 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
603 bnx2x_vfop_reset_wq(vf);
606 case BNX2X_VFOP_VLAN_MAC_CLEAR:
608 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
611 vfop->rc = obj->delete_all(bp, obj,
612 &vlan_mac->user_req.vlan_mac_flags,
613 &vlan_mac->ramrod_flags);
615 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
617 case BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE:
619 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
622 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
623 if (vfop->rc == -EEXIST)
626 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
628 case BNX2X_VFOP_VLAN_MAC_CHK_DONE:
629 vfop->rc = !!obj->raw.check_pending(&obj->raw);
630 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
632 case BNX2X_VFOP_MAC_CONFIG_LIST:
634 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
637 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
641 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
642 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
643 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
645 case BNX2X_VFOP_VLAN_CONFIG_LIST:
647 vfop->state = BNX2X_VFOP_VLAN_CONFIG_LIST_0;
649 /* remove vlan0 - could be no-op */
650 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, false);
654 /* Do vlan list config. if this operation fails we try to
655 * restore vlan0 to keep the queue is working order
657 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
659 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
660 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
662 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT); /* fall-through */
664 case BNX2X_VFOP_VLAN_CONFIG_LIST_0:
666 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
668 if (list_empty(&obj->head))
670 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, true);
671 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
674 bnx2x_vfop_default(state);
677 BNX2X_ERR("VLAN-MAC error: rc %d\n", vfop->rc);
680 bnx2x_vfop_credit(bp, vfop, obj);
681 bnx2x_vfop_end(bp, vf, vfop);
686 struct bnx2x_vfop_vlan_mac_flags {
694 bnx2x_vfop_vlan_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
695 struct bnx2x_vfop_vlan_mac_flags *flags)
697 struct bnx2x_vlan_mac_data *ureq = &ramrod->user_req;
699 memset(ramrod, 0, sizeof(*ramrod));
703 set_bit(RAMROD_DRV_CLR_ONLY, &ramrod->ramrod_flags);
704 if (flags->single_cmd)
705 set_bit(RAMROD_EXEC, &ramrod->ramrod_flags);
708 if (flags->dont_consume)
709 set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT, &ureq->vlan_mac_flags);
712 ureq->cmd = flags->add ? BNX2X_VLAN_MAC_ADD : BNX2X_VLAN_MAC_DEL;
716 bnx2x_vfop_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
717 struct bnx2x_vfop_vlan_mac_flags *flags)
719 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, flags);
720 set_bit(BNX2X_ETH_MAC, &ramrod->user_req.vlan_mac_flags);
723 static int bnx2x_vfop_mac_delall_cmd(struct bnx2x *bp,
724 struct bnx2x_virtf *vf,
725 struct bnx2x_vfop_cmd *cmd,
726 int qid, bool drv_only)
728 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
731 struct bnx2x_vfop_args_filters filters = {
732 .multi_filter = NULL, /* single */
733 .credit = NULL, /* consume credit */
735 struct bnx2x_vfop_vlan_mac_flags flags = {
736 .drv_only = drv_only,
737 .dont_consume = (filters.credit != NULL),
739 .add = false /* don't care */,
741 struct bnx2x_vlan_mac_ramrod_params *ramrod =
742 &vf->op_params.vlan_mac;
744 /* set ramrod params */
745 bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
748 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
751 vfop->args.filters = filters;
753 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
754 bnx2x_vfop_vlan_mac, cmd->done);
755 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
761 int bnx2x_vfop_mac_list_cmd(struct bnx2x *bp,
762 struct bnx2x_virtf *vf,
763 struct bnx2x_vfop_cmd *cmd,
764 struct bnx2x_vfop_filters *macs,
765 int qid, bool drv_only)
767 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
770 struct bnx2x_vfop_args_filters filters = {
771 .multi_filter = macs,
772 .credit = NULL, /* consume credit */
774 struct bnx2x_vfop_vlan_mac_flags flags = {
775 .drv_only = drv_only,
776 .dont_consume = (filters.credit != NULL),
778 .add = false, /* don't care since only the items in the
779 * filters list affect the sp operation,
780 * not the list itself
783 struct bnx2x_vlan_mac_ramrod_params *ramrod =
784 &vf->op_params.vlan_mac;
786 /* set ramrod params */
787 bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
790 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
793 filters.multi_filter->add_cnt = BNX2X_VFOP_FILTER_ADD_CNT_MAX;
794 vfop->args.filters = filters;
796 bnx2x_vfop_opset(BNX2X_VFOP_MAC_CONFIG_LIST,
797 bnx2x_vfop_vlan_mac, cmd->done);
798 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
804 int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
805 struct bnx2x_virtf *vf,
806 struct bnx2x_vfop_cmd *cmd,
807 int qid, u16 vid, bool add)
809 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
812 struct bnx2x_vfop_args_filters filters = {
813 .multi_filter = NULL, /* single command */
814 .credit = &bnx2x_vfq(vf, qid, vlan_count),
816 struct bnx2x_vfop_vlan_mac_flags flags = {
818 .dont_consume = (filters.credit != NULL),
822 struct bnx2x_vlan_mac_ramrod_params *ramrod =
823 &vf->op_params.vlan_mac;
825 /* set ramrod params */
826 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
827 ramrod->user_req.u.vlan.vlan = vid;
830 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
833 vfop->args.filters = filters;
835 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
836 bnx2x_vfop_vlan_mac, cmd->done);
837 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
843 static int bnx2x_vfop_vlan_delall_cmd(struct bnx2x *bp,
844 struct bnx2x_virtf *vf,
845 struct bnx2x_vfop_cmd *cmd,
846 int qid, bool drv_only)
848 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
851 struct bnx2x_vfop_args_filters filters = {
852 .multi_filter = NULL, /* single command */
853 .credit = &bnx2x_vfq(vf, qid, vlan_count),
855 struct bnx2x_vfop_vlan_mac_flags flags = {
856 .drv_only = drv_only,
857 .dont_consume = (filters.credit != NULL),
859 .add = false, /* don't care */
861 struct bnx2x_vlan_mac_ramrod_params *ramrod =
862 &vf->op_params.vlan_mac;
864 /* set ramrod params */
865 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
868 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
871 vfop->args.filters = filters;
873 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
874 bnx2x_vfop_vlan_mac, cmd->done);
875 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
881 int bnx2x_vfop_vlan_list_cmd(struct bnx2x *bp,
882 struct bnx2x_virtf *vf,
883 struct bnx2x_vfop_cmd *cmd,
884 struct bnx2x_vfop_filters *vlans,
885 int qid, bool drv_only)
887 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
890 struct bnx2x_vfop_args_filters filters = {
891 .multi_filter = vlans,
892 .credit = &bnx2x_vfq(vf, qid, vlan_count),
894 struct bnx2x_vfop_vlan_mac_flags flags = {
895 .drv_only = drv_only,
896 .dont_consume = (filters.credit != NULL),
898 .add = false, /* don't care */
900 struct bnx2x_vlan_mac_ramrod_params *ramrod =
901 &vf->op_params.vlan_mac;
903 /* set ramrod params */
904 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
907 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
910 filters.multi_filter->add_cnt = vf_vlan_rules_cnt(vf) -
911 atomic_read(filters.credit);
913 vfop->args.filters = filters;
915 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_CONFIG_LIST,
916 bnx2x_vfop_vlan_mac, cmd->done);
917 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
923 /* VFOP queue setup (queue constructor + set vlan 0) */
924 static void bnx2x_vfop_qsetup(struct bnx2x *bp, struct bnx2x_virtf *vf)
926 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
927 int qid = vfop->args.qctor.qid;
928 enum bnx2x_vfop_qsetup_state state = vfop->state;
929 struct bnx2x_vfop_cmd cmd = {
930 .done = bnx2x_vfop_qsetup,
937 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
940 case BNX2X_VFOP_QSETUP_CTOR:
941 /* init the queue ctor command */
942 vfop->state = BNX2X_VFOP_QSETUP_VLAN0;
943 vfop->rc = bnx2x_vfop_qctor_cmd(bp, vf, &cmd, qid);
948 case BNX2X_VFOP_QSETUP_VLAN0:
949 /* skip if non-leading or FPGA/EMU*/
953 /* init the queue set-vlan command (for vlan 0) */
954 vfop->state = BNX2X_VFOP_QSETUP_DONE;
955 vfop->rc = bnx2x_vfop_vlan_set_cmd(bp, vf, &cmd, qid, 0, true);
960 BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, vfop->rc);
962 case BNX2X_VFOP_QSETUP_DONE:
963 vf->cfg_flags |= VF_CFG_VLAN;
964 smp_mb__before_clear_bit();
965 set_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
967 smp_mb__after_clear_bit();
968 schedule_delayed_work(&bp->sp_rtnl_task, 0);
969 bnx2x_vfop_end(bp, vf, vfop);
972 bnx2x_vfop_default(state);
976 int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
977 struct bnx2x_virtf *vf,
978 struct bnx2x_vfop_cmd *cmd,
981 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
984 vfop->args.qctor.qid = qid;
986 bnx2x_vfop_opset(BNX2X_VFOP_QSETUP_CTOR,
987 bnx2x_vfop_qsetup, cmd->done);
988 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qsetup,
994 /* VFOP queue FLR handling (clear vlans, clear macs, queue destructor) */
995 static void bnx2x_vfop_qflr(struct bnx2x *bp, struct bnx2x_virtf *vf)
997 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
998 int qid = vfop->args.qx.qid;
999 enum bnx2x_vfop_qflr_state state = vfop->state;
1000 struct bnx2x_queue_state_params *qstate;
1001 struct bnx2x_vfop_cmd cmd;
1003 bnx2x_vfop_reset_wq(vf);
1008 DP(BNX2X_MSG_IOV, "VF[%d] STATE: %d\n", vf->abs_vfid, state);
1010 cmd.done = bnx2x_vfop_qflr;
1014 case BNX2X_VFOP_QFLR_CLR_VLAN:
1015 /* vlan-clear-all: driver-only, don't consume credit */
1016 vfop->state = BNX2X_VFOP_QFLR_CLR_MAC;
1017 vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, true);
1022 case BNX2X_VFOP_QFLR_CLR_MAC:
1023 /* mac-clear-all: driver only consume credit */
1024 vfop->state = BNX2X_VFOP_QFLR_TERMINATE;
1025 vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid, true);
1027 "VF[%d] vfop->rc after bnx2x_vfop_mac_delall_cmd was %d",
1028 vf->abs_vfid, vfop->rc);
1033 case BNX2X_VFOP_QFLR_TERMINATE:
1034 qstate = &vfop->op_p->qctor.qstate;
1035 memset(qstate , 0, sizeof(*qstate));
1036 qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
1037 vfop->state = BNX2X_VFOP_QFLR_DONE;
1039 DP(BNX2X_MSG_IOV, "VF[%d] qstate during flr was %d\n",
1040 vf->abs_vfid, qstate->q_obj->state);
1042 if (qstate->q_obj->state != BNX2X_Q_STATE_RESET) {
1043 qstate->q_obj->state = BNX2X_Q_STATE_STOPPED;
1044 qstate->cmd = BNX2X_Q_CMD_TERMINATE;
1045 vfop->rc = bnx2x_queue_state_change(bp, qstate);
1046 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_VERIFY_PEND);
1052 BNX2X_ERR("QFLR[%d:%d] error: rc %d\n",
1053 vf->abs_vfid, qid, vfop->rc);
1055 case BNX2X_VFOP_QFLR_DONE:
1056 bnx2x_vfop_end(bp, vf, vfop);
1059 bnx2x_vfop_default(state);
1065 static int bnx2x_vfop_qflr_cmd(struct bnx2x *bp,
1066 struct bnx2x_virtf *vf,
1067 struct bnx2x_vfop_cmd *cmd,
1070 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1073 vfop->args.qx.qid = qid;
1074 bnx2x_vfop_opset(BNX2X_VFOP_QFLR_CLR_VLAN,
1075 bnx2x_vfop_qflr, cmd->done);
1076 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qflr,
1082 /* VFOP multi-casts */
1083 static void bnx2x_vfop_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf)
1085 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1086 struct bnx2x_mcast_ramrod_params *mcast = &vfop->op_p->mcast;
1087 struct bnx2x_raw_obj *raw = &mcast->mcast_obj->raw;
1088 struct bnx2x_vfop_args_mcast *args = &vfop->args.mc_list;
1089 enum bnx2x_vfop_mcast_state state = vfop->state;
1092 bnx2x_vfop_reset_wq(vf);
1097 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1100 case BNX2X_VFOP_MCAST_DEL:
1101 /* clear existing mcasts */
1102 vfop->state = BNX2X_VFOP_MCAST_ADD;
1103 vfop->rc = bnx2x_config_mcast(bp, mcast, BNX2X_MCAST_CMD_DEL);
1104 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
1106 case BNX2X_VFOP_MCAST_ADD:
1107 if (raw->check_pending(raw))
1111 /* update mcast list on the ramrod params */
1112 INIT_LIST_HEAD(&mcast->mcast_list);
1113 for (i = 0; i < args->mc_num; i++)
1114 list_add_tail(&(args->mc[i].link),
1115 &mcast->mcast_list);
1116 /* add new mcasts */
1117 vfop->state = BNX2X_VFOP_MCAST_CHK_DONE;
1118 vfop->rc = bnx2x_config_mcast(bp, mcast,
1119 BNX2X_MCAST_CMD_ADD);
1121 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1123 case BNX2X_VFOP_MCAST_CHK_DONE:
1124 vfop->rc = raw->check_pending(raw) ? 1 : 0;
1125 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1127 bnx2x_vfop_default(state);
1130 BNX2X_ERR("MCAST CONFIG error: rc %d\n", vfop->rc);
1133 bnx2x_vfop_end(bp, vf, vfop);
1138 int bnx2x_vfop_mcast_cmd(struct bnx2x *bp,
1139 struct bnx2x_virtf *vf,
1140 struct bnx2x_vfop_cmd *cmd,
1141 bnx2x_mac_addr_t *mcasts,
1142 int mcast_num, bool drv_only)
1144 struct bnx2x_vfop *vfop = NULL;
1145 size_t mc_sz = mcast_num * sizeof(struct bnx2x_mcast_list_elem);
1146 struct bnx2x_mcast_list_elem *mc = mc_sz ? kzalloc(mc_sz, GFP_KERNEL) :
1150 vfop = bnx2x_vfop_add(bp, vf);
1153 struct bnx2x_mcast_ramrod_params *ramrod =
1154 &vf->op_params.mcast;
1156 /* set ramrod params */
1157 memset(ramrod, 0, sizeof(*ramrod));
1158 ramrod->mcast_obj = &vf->mcast_obj;
1160 set_bit(RAMROD_DRV_CLR_ONLY,
1161 &ramrod->ramrod_flags);
1163 /* copy mcasts pointers */
1164 vfop->args.mc_list.mc_num = mcast_num;
1165 vfop->args.mc_list.mc = mc;
1166 for (i = 0; i < mcast_num; i++)
1167 mc[i].mac = mcasts[i];
1169 bnx2x_vfop_opset(BNX2X_VFOP_MCAST_DEL,
1170 bnx2x_vfop_mcast, cmd->done);
1171 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mcast,
1181 static void bnx2x_vfop_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf)
1183 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1184 struct bnx2x_rx_mode_ramrod_params *ramrod = &vfop->op_p->rx_mode;
1185 enum bnx2x_vfop_rxmode_state state = vfop->state;
1187 bnx2x_vfop_reset_wq(vf);
1192 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1195 case BNX2X_VFOP_RXMODE_CONFIG:
1197 vfop->state = BNX2X_VFOP_RXMODE_DONE;
1199 vfop->rc = bnx2x_config_rx_mode(bp, ramrod);
1200 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1202 BNX2X_ERR("RXMODE error: rc %d\n", vfop->rc);
1204 case BNX2X_VFOP_RXMODE_DONE:
1205 bnx2x_vfop_end(bp, vf, vfop);
1208 bnx2x_vfop_default(state);
1214 int bnx2x_vfop_rxmode_cmd(struct bnx2x *bp,
1215 struct bnx2x_virtf *vf,
1216 struct bnx2x_vfop_cmd *cmd,
1217 int qid, unsigned long accept_flags)
1219 struct bnx2x_vf_queue *vfq = vfq_get(vf, qid);
1220 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1223 struct bnx2x_rx_mode_ramrod_params *ramrod =
1224 &vf->op_params.rx_mode;
1226 memset(ramrod, 0, sizeof(*ramrod));
1228 /* Prepare ramrod parameters */
1229 ramrod->cid = vfq->cid;
1230 ramrod->cl_id = vfq_cl_id(vf, vfq);
1231 ramrod->rx_mode_obj = &bp->rx_mode_obj;
1232 ramrod->func_id = FW_VF_HANDLE(vf->abs_vfid);
1234 ramrod->rx_accept_flags = accept_flags;
1235 ramrod->tx_accept_flags = accept_flags;
1236 ramrod->pstate = &vf->filter_state;
1237 ramrod->state = BNX2X_FILTER_RX_MODE_PENDING;
1239 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
1240 set_bit(RAMROD_RX, &ramrod->ramrod_flags);
1241 set_bit(RAMROD_TX, &ramrod->ramrod_flags);
1244 bnx2x_vf_sp(bp, vf, rx_mode_rdata.e2);
1245 ramrod->rdata_mapping =
1246 bnx2x_vf_sp_map(bp, vf, rx_mode_rdata.e2);
1248 bnx2x_vfop_opset(BNX2X_VFOP_RXMODE_CONFIG,
1249 bnx2x_vfop_rxmode, cmd->done);
1250 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_rxmode,
1256 /* VFOP queue tear-down ('drop all' rx-mode, clear vlans, clear macs,
1259 static void bnx2x_vfop_qdown(struct bnx2x *bp, struct bnx2x_virtf *vf)
1261 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1262 int qid = vfop->args.qx.qid;
1263 enum bnx2x_vfop_qteardown_state state = vfop->state;
1264 struct bnx2x_vfop_cmd cmd;
1269 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1271 cmd.done = bnx2x_vfop_qdown;
1275 case BNX2X_VFOP_QTEARDOWN_RXMODE:
1277 vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_VLAN;
1278 vfop->rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, qid, 0);
1283 case BNX2X_VFOP_QTEARDOWN_CLR_VLAN:
1284 /* vlan-clear-all: don't consume credit */
1285 vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_MAC;
1286 vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, false);
1291 case BNX2X_VFOP_QTEARDOWN_CLR_MAC:
1292 /* mac-clear-all: consume credit */
1293 vfop->state = BNX2X_VFOP_QTEARDOWN_QDTOR;
1294 vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid, false);
1299 case BNX2X_VFOP_QTEARDOWN_QDTOR:
1300 /* run the queue destruction flow */
1301 DP(BNX2X_MSG_IOV, "case: BNX2X_VFOP_QTEARDOWN_QDTOR\n");
1302 vfop->state = BNX2X_VFOP_QTEARDOWN_DONE;
1303 DP(BNX2X_MSG_IOV, "new state: BNX2X_VFOP_QTEARDOWN_DONE\n");
1304 vfop->rc = bnx2x_vfop_qdtor_cmd(bp, vf, &cmd, qid);
1305 DP(BNX2X_MSG_IOV, "returned from cmd\n");
1310 BNX2X_ERR("QTEARDOWN[%d:%d] error: rc %d\n",
1311 vf->abs_vfid, qid, vfop->rc);
1313 case BNX2X_VFOP_QTEARDOWN_DONE:
1314 bnx2x_vfop_end(bp, vf, vfop);
1317 bnx2x_vfop_default(state);
1321 int bnx2x_vfop_qdown_cmd(struct bnx2x *bp,
1322 struct bnx2x_virtf *vf,
1323 struct bnx2x_vfop_cmd *cmd,
1326 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1329 vfop->args.qx.qid = qid;
1330 bnx2x_vfop_opset(BNX2X_VFOP_QTEARDOWN_RXMODE,
1331 bnx2x_vfop_qdown, cmd->done);
1332 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdown,
1339 /* VF enable primitives
1340 * when pretend is required the caller is responsible
1341 * for calling pretend prior to calling these routines
1344 /* internal vf enable - until vf is enabled internally all transactions
1345 * are blocked. this routine should always be called last with pretend.
1347 static void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable)
1349 REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0);
1352 /* clears vf error in all semi blocks */
1353 static void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid)
1355 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid);
1356 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid);
1357 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid);
1358 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid);
1361 static void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid)
1363 u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5;
1364 u32 was_err_reg = 0;
1366 switch (was_err_group) {
1368 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR;
1371 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR;
1374 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR;
1377 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR;
1380 REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f));
1383 static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
1388 /* Set VF masks and configuration - pretend */
1389 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1391 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
1392 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
1393 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
1394 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
1395 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
1396 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
1398 val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
1399 val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN);
1400 if (vf->cfg_flags & VF_CFG_INT_SIMD)
1401 val |= IGU_VF_CONF_SINGLE_ISR_EN;
1402 val &= ~IGU_VF_CONF_PARENT_MASK;
1403 val |= BP_FUNC(bp) << IGU_VF_CONF_PARENT_SHIFT; /* parent PF */
1404 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
1407 "value in IGU_REG_VF_CONFIGURATION of vf %d after write %x\n",
1408 vf->abs_vfid, REG_RD(bp, IGU_REG_VF_CONFIGURATION));
1410 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1412 /* iterate over all queues, clear sb consumer */
1413 for (i = 0; i < vf_sb_count(vf); i++) {
1414 u8 igu_sb_id = vf_igu_sb(vf, i);
1416 /* zero prod memory */
1417 REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0);
1419 /* clear sb state machine */
1420 bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id,
1423 /* disable + update */
1424 bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0,
1425 IGU_INT_DISABLE, 1);
1429 void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid)
1431 /* set the VF-PF association in the FW */
1432 storm_memset_vf_to_pf(bp, FW_VF_HANDLE(abs_vfid), BP_FUNC(bp));
1433 storm_memset_func_en(bp, FW_VF_HANDLE(abs_vfid), 1);
1435 /* clear vf errors*/
1436 bnx2x_vf_semi_clear_err(bp, abs_vfid);
1437 bnx2x_vf_pglue_clear_err(bp, abs_vfid);
1439 /* internal vf-enable - pretend */
1440 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid));
1441 DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid);
1442 bnx2x_vf_enable_internal(bp, true);
1443 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1446 static void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf)
1448 /* Reset vf in IGU interrupts are still disabled */
1449 bnx2x_vf_igu_reset(bp, vf);
1451 /* pretend to enable the vf with the PBF */
1452 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1453 REG_WR(bp, PBF_REG_DISABLE_VF, 0);
1454 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1457 static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
1459 struct pci_dev *dev;
1460 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
1465 dev = pci_get_bus_and_slot(vf->bus, vf->devfn);
1467 return bnx2x_is_pcie_pending(dev);
1470 BNX2X_ERR("Unknown device\n");
1474 int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid)
1479 /* Verify no pending pci transactions */
1480 if (bnx2x_vf_is_pcie_pending(bp, abs_vfid))
1481 BNX2X_ERR("PCIE Transactions still pending\n");
1486 /* must be called after the number of PF queues and the number of VFs are
1490 bnx2x_iov_static_resc(struct bnx2x *bp, struct vf_pf_resc_request *resc)
1494 /* will be set only during VF-ACQUIRE */
1498 /* no credit calculcis for macs (just yet) */
1499 resc->num_mac_filters = 1;
1501 /* divvy up vlan rules */
1502 vlan_count = bp->vlans_pool.check(&bp->vlans_pool);
1503 vlan_count = 1 << ilog2(vlan_count);
1504 resc->num_vlan_filters = vlan_count / BNX2X_NR_VIRTFN(bp);
1506 /* no real limitation */
1507 resc->num_mc_filters = 0;
1509 /* num_sbs already set */
1513 static void bnx2x_vf_free_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
1515 /* reset the state variables */
1516 bnx2x_iov_static_resc(bp, &vf->alloc_resc);
1517 vf->state = VF_FREE;
1520 static void bnx2x_vf_flr_clnup_hw(struct bnx2x *bp, struct bnx2x_virtf *vf)
1522 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1524 /* DQ usage counter */
1525 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1526 bnx2x_flr_clnup_poll_hw_counter(bp, DORQ_REG_VF_USAGE_CNT,
1527 "DQ VF usage counter timed out",
1529 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1531 /* FW cleanup command - poll for the results */
1532 if (bnx2x_send_final_clnup(bp, (u8)FW_VF_HANDLE(vf->abs_vfid),
1534 BNX2X_ERR("VF[%d] Final cleanup timed-out\n", vf->abs_vfid);
1536 /* verify TX hw is flushed */
1537 bnx2x_tx_hw_flushed(bp, poll_cnt);
1540 static void bnx2x_vfop_flr(struct bnx2x *bp, struct bnx2x_virtf *vf)
1542 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1543 struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
1544 enum bnx2x_vfop_flr_state state = vfop->state;
1545 struct bnx2x_vfop_cmd cmd = {
1546 .done = bnx2x_vfop_flr,
1553 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1556 case BNX2X_VFOP_FLR_QUEUES:
1557 /* the cleanup operations are valid if and only if the VF
1558 * was first acquired.
1560 if (++(qx->qid) < vf_rxq_count(vf)) {
1561 vfop->rc = bnx2x_vfop_qflr_cmd(bp, vf, &cmd,
1567 /* remove multicasts */
1568 vfop->state = BNX2X_VFOP_FLR_HW;
1569 vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL,
1574 case BNX2X_VFOP_FLR_HW:
1576 /* dispatch final cleanup and wait for HW queues to flush */
1577 bnx2x_vf_flr_clnup_hw(bp, vf);
1579 /* release VF resources */
1580 bnx2x_vf_free_resc(bp, vf);
1582 /* re-open the mailbox */
1583 bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
1587 bnx2x_vfop_default(state);
1590 BNX2X_ERR("VF[%d] FLR error: rc %d\n", vf->abs_vfid, vfop->rc);
1592 vf->flr_clnup_stage = VF_FLR_ACK;
1593 bnx2x_vfop_end(bp, vf, vfop);
1594 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
1597 static int bnx2x_vfop_flr_cmd(struct bnx2x *bp,
1598 struct bnx2x_virtf *vf,
1599 vfop_handler_t done)
1601 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1603 vfop->args.qx.qid = -1; /* loop */
1604 bnx2x_vfop_opset(BNX2X_VFOP_FLR_QUEUES,
1605 bnx2x_vfop_flr, done);
1606 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_flr, false);
1611 static void bnx2x_vf_flr_clnup(struct bnx2x *bp, struct bnx2x_virtf *prev_vf)
1613 int i = prev_vf ? prev_vf->index + 1 : 0;
1614 struct bnx2x_virtf *vf;
1616 /* find next VF to cleanup */
1619 i < BNX2X_NR_VIRTFN(bp) &&
1620 (bnx2x_vf(bp, i, state) != VF_RESET ||
1621 bnx2x_vf(bp, i, flr_clnup_stage) != VF_FLR_CLN);
1625 DP(BNX2X_MSG_IOV, "next vf to cleanup: %d. num of vfs: %d\n", i,
1626 BNX2X_NR_VIRTFN(bp));
1628 if (i < BNX2X_NR_VIRTFN(bp)) {
1631 /* lock the vf pf channel */
1632 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
1634 /* invoke the VF FLR SM */
1635 if (bnx2x_vfop_flr_cmd(bp, vf, bnx2x_vf_flr_clnup)) {
1636 BNX2X_ERR("VF[%d]: FLR cleanup failed -ENOMEM\n",
1639 /* mark the VF to be ACKED and continue */
1640 vf->flr_clnup_stage = VF_FLR_ACK;
1641 goto next_vf_to_clean;
1646 /* we are done, update vf records */
1647 for_each_vf(bp, i) {
1650 if (vf->flr_clnup_stage != VF_FLR_ACK)
1653 vf->flr_clnup_stage = VF_FLR_EPILOG;
1656 /* Acknowledge the handled VFs.
1657 * we are acknowledge all the vfs which an flr was requested for, even
1658 * if amongst them there are such that we never opened, since the mcp
1659 * will interrupt us immediately again if we only ack some of the bits,
1660 * resulting in an endless loop. This can happen for example in KVM
1661 * where an 'all ones' flr request is sometimes given by hyper visor
1663 DP(BNX2X_MSG_MCP, "DRV_STATUS_VF_DISABLED ACK for vfs 0x%x 0x%x\n",
1664 bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
1665 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1666 SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i],
1667 bp->vfdb->flrd_vfs[i]);
1669 bnx2x_fw_command(bp, DRV_MSG_CODE_VF_DISABLED_DONE, 0);
1671 /* clear the acked bits - better yet if the MCP implemented
1672 * write to clear semantics
1674 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1675 SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 0);
1678 void bnx2x_vf_handle_flr_event(struct bnx2x *bp)
1682 /* Read FLR'd VFs */
1683 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1684 bp->vfdb->flrd_vfs[i] = SHMEM2_RD(bp, mcp_vf_disabled[i]);
1687 "DRV_STATUS_VF_DISABLED received for vfs 0x%x 0x%x\n",
1688 bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
1690 for_each_vf(bp, i) {
1691 struct bnx2x_virtf *vf = BP_VF(bp, i);
1694 if (vf->abs_vfid < 32)
1695 reset = bp->vfdb->flrd_vfs[0] & (1 << vf->abs_vfid);
1697 reset = bp->vfdb->flrd_vfs[1] &
1698 (1 << (vf->abs_vfid - 32));
1701 /* set as reset and ready for cleanup */
1702 vf->state = VF_RESET;
1703 vf->flr_clnup_stage = VF_FLR_CLN;
1706 "Initiating Final cleanup for VF %d\n",
1711 /* do the FLR cleanup for all marked VFs*/
1712 bnx2x_vf_flr_clnup(bp, NULL);
1715 /* IOV global initialization routines */
1716 void bnx2x_iov_init_dq(struct bnx2x *bp)
1721 /* Set the DQ such that the CID reflect the abs_vfid */
1722 REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0);
1723 REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS));
1725 /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to
1728 REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID);
1730 /* The VF window size is the log2 of the max number of CIDs per VF */
1731 REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND);
1733 /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match
1734 * the Pf doorbell size although the 2 are independent.
1736 REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST,
1737 BNX2X_DB_SHIFT - BNX2X_DB_MIN_SHIFT);
1739 /* No security checks for now -
1740 * configure single rule (out of 16) mask = 0x1, value = 0x0,
1741 * CID range 0 - 0x1ffff
1743 REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1);
1744 REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0);
1745 REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0);
1746 REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff);
1748 /* set the number of VF alllowed doorbells to the full DQ range */
1749 REG_WR(bp, DORQ_REG_VF_NORM_MAX_CID_COUNT, 0x20000);
1751 /* set the VF doorbell threshold */
1752 REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 4);
1755 void bnx2x_iov_init_dmae(struct bnx2x *bp)
1757 DP(BNX2X_MSG_IOV, "SRIOV is %s\n", IS_SRIOV(bp) ? "ON" : "OFF");
1761 REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0);
1764 static int bnx2x_vf_bus(struct bnx2x *bp, int vfid)
1766 struct pci_dev *dev = bp->pdev;
1767 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1769 return dev->bus->number + ((dev->devfn + iov->offset +
1770 iov->stride * vfid) >> 8);
1773 static int bnx2x_vf_devfn(struct bnx2x *bp, int vfid)
1775 struct pci_dev *dev = bp->pdev;
1776 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1778 return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff;
1781 static void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
1784 struct pci_dev *dev = bp->pdev;
1785 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1787 for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
1788 u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i);
1789 u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i);
1792 vf->bars[n].bar = start + size * vf->abs_vfid;
1793 vf->bars[n].size = size;
1797 static int bnx2x_ari_enabled(struct pci_dev *dev)
1799 return dev->bus->self && dev->bus->self->ari_enabled;
1803 bnx2x_get_vf_igu_cam_info(struct bnx2x *bp)
1809 /* IGU in normal mode - read CAM */
1810 for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) {
1811 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4);
1812 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
1814 fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID);
1815 if (!(fid & IGU_FID_ENCODE_IS_PF))
1816 bnx2x_vf_set_igu_info(bp, sb_id,
1817 (fid & IGU_FID_VF_NUM_MASK));
1819 DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n",
1820 ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"),
1821 ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) :
1822 (fid & IGU_FID_VF_NUM_MASK)), sb_id,
1823 GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR));
1827 static void __bnx2x_iov_free_vfdb(struct bnx2x *bp)
1830 kfree(bp->vfdb->vfqs);
1831 kfree(bp->vfdb->vfs);
1837 static int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
1840 struct pci_dev *dev = bp->pdev;
1842 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
1844 BNX2X_ERR("failed to find SRIOV capability in device\n");
1849 DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos);
1850 pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
1851 pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total);
1852 pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial);
1853 pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
1854 pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
1855 pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
1856 pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
1857 pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
1862 static int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
1866 /* read the SRIOV capability structure
1867 * The fields can be read via configuration read or
1868 * directly from the device (starting at offset PCICFG_OFFSET)
1870 if (bnx2x_sriov_pci_cfg_info(bp, iov))
1873 /* get the number of SRIOV bars */
1876 /* read the first_vfid */
1877 val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF);
1878 iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK)
1879 * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp));
1882 "IOV info[%d]: first vf %d, nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
1884 iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total,
1885 iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
1890 static u8 bnx2x_iov_get_max_queue_count(struct bnx2x *bp)
1897 queue_count += bnx2x_vf(bp, i, alloc_resc.num_sbs);
1902 /* must be called after PF bars are mapped */
1903 int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
1907 struct bnx2x_sriov *iov;
1908 struct pci_dev *dev = bp->pdev;
1916 /* verify sriov capability is present in configuration space */
1917 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV))
1920 /* verify chip revision */
1921 if (CHIP_IS_E1x(bp))
1924 /* check if SRIOV support is turned off */
1928 /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */
1929 if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) {
1930 BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n",
1931 BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID);
1935 /* SRIOV can be enabled only with MSIX */
1936 if (int_mode_param == BNX2X_INT_MODE_MSI ||
1937 int_mode_param == BNX2X_INT_MODE_INTX)
1938 BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n");
1941 /* verify ari is enabled */
1942 if (!bnx2x_ari_enabled(bp->pdev)) {
1943 BNX2X_ERR("ARI not supported, SRIOV can not be enabled\n");
1947 /* verify igu is in normal mode */
1948 if (CHIP_INT_MODE_IS_BC(bp)) {
1949 BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n");
1953 /* allocate the vfs database */
1954 bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL);
1956 BNX2X_ERR("failed to allocate vf database\n");
1961 /* get the sriov info - Linux already collected all the pertinent
1962 * information, however the sriov structure is for the private use
1963 * of the pci module. Also we want this information regardless
1964 * of the hyper-visor.
1966 iov = &(bp->vfdb->sriov);
1967 err = bnx2x_sriov_info(bp, iov);
1971 /* SR-IOV capability was enabled but there are no VFs*/
1972 if (iov->total == 0)
1975 /* calculate the actual number of VFs */
1976 iov->nr_virtfn = min_t(u16, iov->total, (u16)num_vfs_param);
1978 /* allocate the vf array */
1979 bp->vfdb->vfs = kzalloc(sizeof(struct bnx2x_virtf) *
1980 BNX2X_NR_VIRTFN(bp), GFP_KERNEL);
1981 if (!bp->vfdb->vfs) {
1982 BNX2X_ERR("failed to allocate vf array\n");
1987 /* Initial VF init - index and abs_vfid - nr_virtfn must be set */
1988 for_each_vf(bp, i) {
1989 bnx2x_vf(bp, i, index) = i;
1990 bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i;
1991 bnx2x_vf(bp, i, state) = VF_FREE;
1992 INIT_LIST_HEAD(&bnx2x_vf(bp, i, op_list_head));
1993 mutex_init(&bnx2x_vf(bp, i, op_mutex));
1994 bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE;
1997 /* re-read the IGU CAM for VFs - index and abs_vfid must be set */
1998 bnx2x_get_vf_igu_cam_info(bp);
2000 /* get the total queue count and allocate the global queue arrays */
2001 qcount = bnx2x_iov_get_max_queue_count(bp);
2003 /* allocate the queue arrays for all VFs */
2004 bp->vfdb->vfqs = kzalloc(qcount * sizeof(struct bnx2x_vf_queue),
2006 if (!bp->vfdb->vfqs) {
2007 BNX2X_ERR("failed to allocate vf queue array\n");
2014 DP(BNX2X_MSG_IOV, "Failed err=%d\n", err);
2015 __bnx2x_iov_free_vfdb(bp);
2019 void bnx2x_iov_remove_one(struct bnx2x *bp)
2021 /* if SRIOV is not enabled there's nothing to do */
2025 DP(BNX2X_MSG_IOV, "about to call disable sriov\n");
2026 pci_disable_sriov(bp->pdev);
2027 DP(BNX2X_MSG_IOV, "sriov disabled\n");
2029 /* free vf database */
2030 __bnx2x_iov_free_vfdb(bp);
2033 void bnx2x_iov_free_mem(struct bnx2x *bp)
2040 /* free vfs hw contexts */
2041 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2042 struct hw_dma *cxt = &bp->vfdb->context[i];
2043 BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size);
2046 BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr,
2047 BP_VFDB(bp)->sp_dma.mapping,
2048 BP_VFDB(bp)->sp_dma.size);
2050 BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr,
2051 BP_VF_MBX_DMA(bp)->mapping,
2052 BP_VF_MBX_DMA(bp)->size);
2054 BNX2X_PCI_FREE(BP_VF_BULLETIN_DMA(bp)->addr,
2055 BP_VF_BULLETIN_DMA(bp)->mapping,
2056 BP_VF_BULLETIN_DMA(bp)->size);
2059 int bnx2x_iov_alloc_mem(struct bnx2x *bp)
2067 /* allocate vfs hw contexts */
2068 tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) *
2069 BNX2X_CIDS_PER_VF * sizeof(union cdu_context);
2071 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2072 struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
2073 cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
2076 BNX2X_PCI_ALLOC(cxt->addr, &cxt->mapping, cxt->size);
2081 tot_size -= cxt->size;
2084 /* allocate vfs ramrods dma memory - client_init and set_mac */
2085 tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
2086 BNX2X_PCI_ALLOC(BP_VFDB(bp)->sp_dma.addr, &BP_VFDB(bp)->sp_dma.mapping,
2088 BP_VFDB(bp)->sp_dma.size = tot_size;
2090 /* allocate mailboxes */
2091 tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
2092 BNX2X_PCI_ALLOC(BP_VF_MBX_DMA(bp)->addr, &BP_VF_MBX_DMA(bp)->mapping,
2094 BP_VF_MBX_DMA(bp)->size = tot_size;
2096 /* allocate local bulletin boards */
2097 tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE;
2098 BNX2X_PCI_ALLOC(BP_VF_BULLETIN_DMA(bp)->addr,
2099 &BP_VF_BULLETIN_DMA(bp)->mapping, tot_size);
2100 BP_VF_BULLETIN_DMA(bp)->size = tot_size;
2108 static void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
2109 struct bnx2x_vf_queue *q)
2111 u8 cl_id = vfq_cl_id(vf, q);
2112 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
2113 unsigned long q_type = 0;
2115 set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
2116 set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
2118 /* Queue State object */
2119 bnx2x_init_queue_obj(bp, &q->sp_obj,
2120 cl_id, &q->cid, 1, func_id,
2121 bnx2x_vf_sp(bp, vf, q_data),
2122 bnx2x_vf_sp_map(bp, vf, q_data),
2126 "initialized vf %d's queue object. func id set to %d\n",
2127 vf->abs_vfid, q->sp_obj.func_id);
2129 /* mac/vlan objects are per queue, but only those
2130 * that belong to the leading queue are initialized
2132 if (vfq_is_leading(q)) {
2134 bnx2x_init_mac_obj(bp, &q->mac_obj,
2135 cl_id, q->cid, func_id,
2136 bnx2x_vf_sp(bp, vf, mac_rdata),
2137 bnx2x_vf_sp_map(bp, vf, mac_rdata),
2138 BNX2X_FILTER_MAC_PENDING,
2140 BNX2X_OBJ_TYPE_RX_TX,
2143 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
2144 cl_id, q->cid, func_id,
2145 bnx2x_vf_sp(bp, vf, vlan_rdata),
2146 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
2147 BNX2X_FILTER_VLAN_PENDING,
2149 BNX2X_OBJ_TYPE_RX_TX,
2153 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
2154 q->cid, func_id, func_id,
2155 bnx2x_vf_sp(bp, vf, mcast_rdata),
2156 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
2157 BNX2X_FILTER_MCAST_PENDING,
2159 BNX2X_OBJ_TYPE_RX_TX);
2161 vf->leading_rss = cl_id;
2165 /* called by bnx2x_nic_load */
2166 int bnx2x_iov_nic_init(struct bnx2x *bp)
2168 int vfid, qcount, i;
2170 if (!IS_SRIOV(bp)) {
2171 DP(BNX2X_MSG_IOV, "vfdb was not allocated\n");
2175 DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn);
2177 /* initialize vf database */
2178 for_each_vf(bp, vfid) {
2179 struct bnx2x_virtf *vf = BP_VF(bp, vfid);
2181 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) *
2184 union cdu_context *base_cxt = (union cdu_context *)
2185 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
2186 (base_vf_cid & (ILT_PAGE_CIDS-1));
2189 "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n",
2190 vf->abs_vfid, vf_sb_count(vf), base_vf_cid,
2191 BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt);
2193 /* init statically provisioned resources */
2194 bnx2x_iov_static_resc(bp, &vf->alloc_resc);
2196 /* queues are initialized during VF-ACQUIRE */
2198 /* reserve the vf vlan credit */
2199 bp->vlans_pool.get(&bp->vlans_pool, vf_vlan_rules_cnt(vf));
2201 vf->filter_state = 0;
2202 vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id);
2204 /* init mcast object - This object will be re-initialized
2205 * during VF-ACQUIRE with the proper cl_id and cid.
2206 * It needs to be initialized here so that it can be safely
2207 * handled by a subsequent FLR flow.
2209 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF,
2211 bnx2x_vf_sp(bp, vf, mcast_rdata),
2212 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
2213 BNX2X_FILTER_MCAST_PENDING,
2215 BNX2X_OBJ_TYPE_RX_TX);
2217 /* set the mailbox message addresses */
2218 BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *)
2219 (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid *
2220 MBX_MSG_ALIGNED_SIZE);
2222 BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping +
2223 vfid * MBX_MSG_ALIGNED_SIZE;
2225 /* Enable vf mailbox */
2226 bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
2231 for_each_vf(bp, i) {
2232 struct bnx2x_virtf *vf = BP_VF(bp, i);
2234 /* fill in the BDF and bars */
2235 vf->bus = bnx2x_vf_bus(bp, i);
2236 vf->devfn = bnx2x_vf_devfn(bp, i);
2237 bnx2x_vf_set_bars(bp, vf);
2240 "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n",
2241 vf->abs_vfid, vf->bus, vf->devfn,
2242 (unsigned)vf->bars[0].bar, vf->bars[0].size,
2243 (unsigned)vf->bars[1].bar, vf->bars[1].size,
2244 (unsigned)vf->bars[2].bar, vf->bars[2].size);
2246 /* set local queue arrays */
2247 vf->vfqs = &bp->vfdb->vfqs[qcount];
2248 qcount += bnx2x_vf(bp, i, alloc_resc.num_sbs);
2254 /* called by bnx2x_chip_cleanup */
2255 int bnx2x_iov_chip_cleanup(struct bnx2x *bp)
2262 /* release all the VFs */
2264 bnx2x_vf_release(bp, BP_VF(bp, i), true); /* blocking */
2269 /* called by bnx2x_init_hw_func, returns the next ilt line */
2270 int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line)
2273 struct bnx2x_ilt *ilt = BP_ILT(bp);
2278 /* set vfs ilt lines */
2279 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2280 struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i);
2282 ilt->lines[line+i].page = hw_cxt->addr;
2283 ilt->lines[line+i].page_mapping = hw_cxt->mapping;
2284 ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */
2289 static u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid)
2291 return ((cid >= BNX2X_FIRST_VF_CID) &&
2292 ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS));
2296 void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
2297 struct bnx2x_vf_queue *vfq,
2298 union event_ring_elem *elem)
2300 unsigned long ramrod_flags = 0;
2303 /* Always push next commands out, don't wait here */
2304 set_bit(RAMROD_CONT, &ramrod_flags);
2306 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
2307 case BNX2X_FILTER_MAC_PENDING:
2308 rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
2311 case BNX2X_FILTER_VLAN_PENDING:
2312 rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem,
2316 BNX2X_ERR("Unsupported classification command: %d\n",
2317 elem->message.data.eth_event.echo);
2321 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
2323 DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n");
2327 void bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp,
2328 struct bnx2x_virtf *vf)
2330 struct bnx2x_mcast_ramrod_params rparam = {NULL};
2333 rparam.mcast_obj = &vf->mcast_obj;
2334 vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw);
2336 /* If there are pending mcast commands - send them */
2337 if (vf->mcast_obj.check_pending(&vf->mcast_obj)) {
2338 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
2340 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
2346 void bnx2x_vf_handle_filters_eqe(struct bnx2x *bp,
2347 struct bnx2x_virtf *vf)
2349 smp_mb__before_clear_bit();
2350 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
2351 smp_mb__after_clear_bit();
2354 int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
2356 struct bnx2x_virtf *vf;
2357 int qidx = 0, abs_vfid;
2364 /* first get the cid - the only events we handle here are cfc-delete
2365 * and set-mac completion
2367 opcode = elem->message.opcode;
2370 case EVENT_RING_OPCODE_CFC_DEL:
2371 cid = SW_CID((__force __le32)
2372 elem->message.data.cfc_del_event.cid);
2373 DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
2375 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
2376 case EVENT_RING_OPCODE_MULTICAST_RULES:
2377 case EVENT_RING_OPCODE_FILTERS_RULES:
2378 cid = (elem->message.data.eth_event.echo &
2380 DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
2382 case EVENT_RING_OPCODE_VF_FLR:
2383 abs_vfid = elem->message.data.vf_flr_event.vf_id;
2384 DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n",
2387 case EVENT_RING_OPCODE_MALICIOUS_VF:
2388 abs_vfid = elem->message.data.malicious_vf_event.vf_id;
2389 DP(BNX2X_MSG_IOV, "Got VF MALICIOUS notification abs_vfid=%d\n",
2396 /* check if the cid is the VF range */
2397 if (!bnx2x_iov_is_vf_cid(bp, cid)) {
2398 DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid);
2402 /* extract vf and rxq index from vf_cid - relies on the following:
2403 * 1. vfid on cid reflects the true abs_vfid
2404 * 2. the max number of VFs (per path) is 64
2406 qidx = cid & ((1 << BNX2X_VF_CID_WND)-1);
2407 abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
2409 vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
2412 BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n",
2418 case EVENT_RING_OPCODE_CFC_DEL:
2419 DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n",
2420 vf->abs_vfid, qidx);
2421 vfq_get(vf, qidx)->sp_obj.complete_cmd(bp,
2424 BNX2X_Q_CMD_CFC_DEL);
2426 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
2427 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n",
2428 vf->abs_vfid, qidx);
2429 bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem);
2431 case EVENT_RING_OPCODE_MULTICAST_RULES:
2432 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n",
2433 vf->abs_vfid, qidx);
2434 bnx2x_vf_handle_mcast_eqe(bp, vf);
2436 case EVENT_RING_OPCODE_FILTERS_RULES:
2437 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n",
2438 vf->abs_vfid, qidx);
2439 bnx2x_vf_handle_filters_eqe(bp, vf);
2441 case EVENT_RING_OPCODE_VF_FLR:
2442 DP(BNX2X_MSG_IOV, "got VF [%d] FLR notification\n",
2444 /* Do nothing for now */
2446 case EVENT_RING_OPCODE_MALICIOUS_VF:
2447 DP(BNX2X_MSG_IOV, "got VF [%d] MALICIOUS notification\n",
2449 /* Do nothing for now */
2452 /* SRIOV: reschedule any 'in_progress' operations */
2453 bnx2x_iov_sp_event(bp, cid, false);
2458 static struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid)
2460 /* extract the vf from vf_cid - relies on the following:
2461 * 1. vfid on cid reflects the true abs_vfid
2462 * 2. the max number of VFs (per path) is 64
2464 int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
2465 return bnx2x_vf_by_abs_fid(bp, abs_vfid);
2468 void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
2469 struct bnx2x_queue_sp_obj **q_obj)
2471 struct bnx2x_virtf *vf;
2476 vf = bnx2x_vf_by_cid(bp, vf_cid);
2479 /* extract queue index from vf_cid - relies on the following:
2480 * 1. vfid on cid reflects the true abs_vfid
2481 * 2. the max number of VFs (per path) is 64
2483 int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1);
2484 *q_obj = &bnx2x_vfq(vf, q_index, sp_obj);
2486 BNX2X_ERR("No vf matching cid %d\n", vf_cid);
2490 void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work)
2492 struct bnx2x_virtf *vf;
2494 /* check if the cid is the VF range */
2495 if (!IS_SRIOV(bp) || !bnx2x_iov_is_vf_cid(bp, vf_cid))
2498 vf = bnx2x_vf_by_cid(bp, vf_cid);
2500 /* set in_progress flag */
2501 atomic_set(&vf->op_in_progress, 1);
2503 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
2507 void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
2510 int first_queue_query_index, num_queues_req;
2511 dma_addr_t cur_data_offset;
2512 struct stats_query_entry *cur_query_entry;
2514 bool is_fcoe = false;
2522 /* fcoe adds one global request and one queue request */
2523 num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe;
2524 first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX -
2528 "BNX2X_NUM_ETH_QUEUES %d, is_fcoe %d, first_queue_query_index %d => determined the last non virtual statistics query index is %d. Will add queries on top of that\n",
2529 BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index,
2530 first_queue_query_index + num_queues_req);
2532 cur_data_offset = bp->fw_stats_data_mapping +
2533 offsetof(struct bnx2x_fw_stats_data, queue_stats) +
2534 num_queues_req * sizeof(struct per_queue_stats);
2536 cur_query_entry = &bp->fw_stats_req->
2537 query[first_queue_query_index + num_queues_req];
2539 for_each_vf(bp, i) {
2541 struct bnx2x_virtf *vf = BP_VF(bp, i);
2543 if (vf->state != VF_ENABLED) {
2545 "vf %d not enabled so no stats for it\n",
2550 DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid);
2551 for_each_vfq(vf, j) {
2552 struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
2554 /* collect stats fro active queues only */
2555 if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) ==
2556 BNX2X_Q_LOGICAL_STATE_STOPPED)
2559 /* create stats query entry for this queue */
2560 cur_query_entry->kind = STATS_TYPE_QUEUE;
2561 cur_query_entry->index = vfq_cl_id(vf, rxq);
2562 cur_query_entry->funcID =
2563 cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid));
2564 cur_query_entry->address.hi =
2565 cpu_to_le32(U64_HI(vf->fw_stat_map));
2566 cur_query_entry->address.lo =
2567 cpu_to_le32(U64_LO(vf->fw_stat_map));
2569 "added address %x %x for vf %d queue %d client %d\n",
2570 cur_query_entry->address.hi,
2571 cur_query_entry->address.lo, cur_query_entry->funcID,
2572 j, cur_query_entry->index);
2574 cur_data_offset += sizeof(struct per_queue_stats);
2578 bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count;
2581 void bnx2x_iov_sp_task(struct bnx2x *bp)
2587 /* Iterate over all VFs and invoke state transition for VFs with
2588 * 'in-progress' slow-path operations
2590 DP(BNX2X_MSG_IOV, "searching for pending vf operations\n");
2591 for_each_vf(bp, i) {
2592 struct bnx2x_virtf *vf = BP_VF(bp, i);
2594 if (!list_empty(&vf->op_list_head) &&
2595 atomic_read(&vf->op_in_progress)) {
2596 DP(BNX2X_MSG_IOV, "running pending op for vf %d\n", i);
2597 bnx2x_vfop_cur(bp, vf)->transition(bp, vf);
2603 struct bnx2x_virtf *__vf_from_stat_id(struct bnx2x *bp, u8 stat_id)
2606 struct bnx2x_virtf *vf = NULL;
2608 for_each_vf(bp, i) {
2610 if (stat_id >= vf->igu_base_id &&
2611 stat_id < vf->igu_base_id + vf_sb_count(vf))
2617 /* VF API helpers */
2618 static void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid,
2621 u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4;
2622 u32 val = enable ? (abs_vfid | (1 << 6)) : 0;
2624 REG_WR(bp, reg, val);
2627 static void bnx2x_vf_clr_qtbl(struct bnx2x *bp, struct bnx2x_virtf *vf)
2632 bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
2633 vfq_qzone_id(vf, vfq_get(vf, i)), false);
2636 static void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf)
2640 /* clear the VF configuration - pretend */
2641 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
2642 val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
2643 val &= ~(IGU_VF_CONF_MSI_MSIX_EN | IGU_VF_CONF_SINGLE_ISR_EN |
2644 IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_PARENT_MASK);
2645 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
2646 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
2649 u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
2651 return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
2652 BNX2X_VF_MAX_QUEUES);
2656 int bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf,
2657 struct vf_pf_resc_request *req_resc)
2659 u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
2660 u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
2662 return ((req_resc->num_rxqs <= rxq_cnt) &&
2663 (req_resc->num_txqs <= txq_cnt) &&
2664 (req_resc->num_sbs <= vf_sb_count(vf)) &&
2665 (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) &&
2666 (req_resc->num_vlan_filters <= vf_vlan_rules_cnt(vf)));
2670 int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
2671 struct vf_pf_resc_request *resc)
2673 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) *
2676 union cdu_context *base_cxt = (union cdu_context *)
2677 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
2678 (base_vf_cid & (ILT_PAGE_CIDS-1));
2681 /* if state is 'acquired' the VF was not released or FLR'd, in
2682 * this case the returned resources match the acquired already
2683 * acquired resources. Verify that the requested numbers do
2684 * not exceed the already acquired numbers.
2686 if (vf->state == VF_ACQUIRED) {
2687 DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n",
2690 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
2691 BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n",
2698 /* Otherwise vf state must be 'free' or 'reset' */
2699 if (vf->state != VF_FREE && vf->state != VF_RESET) {
2700 BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n",
2701 vf->abs_vfid, vf->state);
2705 /* static allocation:
2706 * the global maximum number are fixed per VF. fail the request if
2707 * requested number exceed these globals
2709 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
2711 "cannot fulfill vf resource request. Placing maximal available values in response\n");
2712 /* set the max resource in the vf */
2716 /* Set resources counters - 0 request means max available */
2717 vf_sb_count(vf) = resc->num_sbs;
2718 vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
2719 vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
2720 if (resc->num_mac_filters)
2721 vf_mac_rules_cnt(vf) = resc->num_mac_filters;
2722 if (resc->num_vlan_filters)
2723 vf_vlan_rules_cnt(vf) = resc->num_vlan_filters;
2726 "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n",
2727 vf_sb_count(vf), vf_rxq_count(vf),
2728 vf_txq_count(vf), vf_mac_rules_cnt(vf),
2729 vf_vlan_rules_cnt(vf));
2731 /* Initialize the queues */
2733 DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n");
2737 for_each_vfq(vf, i) {
2738 struct bnx2x_vf_queue *q = vfq_get(vf, i);
2741 DP(BNX2X_MSG_IOV, "q number %d was not allocated\n", i);
2746 q->cxt = &((base_cxt + i)->eth);
2747 q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i;
2749 DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n",
2750 vf->abs_vfid, i, q->index, q->cid, q->cxt);
2752 /* init SP objects */
2753 bnx2x_vfq_init(bp, vf, q);
2755 vf->state = VF_ACQUIRED;
2759 int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map)
2761 struct bnx2x_func_init_params func_init = {0};
2765 /* the sb resources are initialized at this point, do the
2766 * FW/HW initializations
2768 for_each_vf_sb(vf, i)
2769 bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true,
2770 vf_igu_sb(vf, i), vf_igu_sb(vf, i));
2773 if (vf->state != VF_ACQUIRED) {
2774 DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n",
2775 vf->abs_vfid, vf->state);
2778 /* FLR cleanup epilogue */
2779 if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid))
2782 /* reset IGU VF statistics: MSIX */
2783 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0);
2786 if (vf->cfg_flags & VF_CFG_STATS)
2787 flags |= (FUNC_FLG_STATS | FUNC_FLG_SPQ);
2789 if (vf->cfg_flags & VF_CFG_TPA)
2790 flags |= FUNC_FLG_TPA;
2792 if (is_vf_multi(vf))
2793 flags |= FUNC_FLG_RSS;
2795 /* function setup */
2796 func_init.func_flgs = flags;
2797 func_init.pf_id = BP_FUNC(bp);
2798 func_init.func_id = FW_VF_HANDLE(vf->abs_vfid);
2799 func_init.fw_stat_map = vf->fw_stat_map;
2800 func_init.spq_map = vf->spq_map;
2801 func_init.spq_prod = 0;
2802 bnx2x_func_init(bp, &func_init);
2805 bnx2x_vf_enable_access(bp, vf->abs_vfid);
2806 bnx2x_vf_enable_traffic(bp, vf);
2808 /* queue protection table */
2810 bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
2811 vfq_qzone_id(vf, vfq_get(vf, i)), true);
2813 vf->state = VF_ENABLED;
2815 /* update vf bulletin board */
2816 bnx2x_post_vf_bulletin(bp, vf->index);
2821 /* VFOP close (teardown the queues, delete mcasts and close HW) */
2822 static void bnx2x_vfop_close(struct bnx2x *bp, struct bnx2x_virtf *vf)
2824 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
2825 struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
2826 enum bnx2x_vfop_close_state state = vfop->state;
2827 struct bnx2x_vfop_cmd cmd = {
2828 .done = bnx2x_vfop_close,
2835 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
2838 case BNX2X_VFOP_CLOSE_QUEUES:
2840 if (++(qx->qid) < vf_rxq_count(vf)) {
2841 vfop->rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qx->qid);
2847 /* remove multicasts */
2848 vfop->state = BNX2X_VFOP_CLOSE_HW;
2849 vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL, 0, false);
2854 case BNX2X_VFOP_CLOSE_HW:
2856 /* disable the interrupts */
2857 DP(BNX2X_MSG_IOV, "disabling igu\n");
2858 bnx2x_vf_igu_disable(bp, vf);
2860 /* disable the VF */
2861 DP(BNX2X_MSG_IOV, "clearing qtbl\n");
2862 bnx2x_vf_clr_qtbl(bp, vf);
2866 bnx2x_vfop_default(state);
2869 BNX2X_ERR("VF[%d] CLOSE error: rc %d\n", vf->abs_vfid, vfop->rc);
2871 vf->state = VF_ACQUIRED;
2872 DP(BNX2X_MSG_IOV, "set state to acquired\n");
2873 bnx2x_vfop_end(bp, vf, vfop);
2876 int bnx2x_vfop_close_cmd(struct bnx2x *bp,
2877 struct bnx2x_virtf *vf,
2878 struct bnx2x_vfop_cmd *cmd)
2880 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
2882 vfop->args.qx.qid = -1; /* loop */
2883 bnx2x_vfop_opset(BNX2X_VFOP_CLOSE_QUEUES,
2884 bnx2x_vfop_close, cmd->done);
2885 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_close,
2891 /* VF release can be called either: 1. the VF was acquired but
2892 * not enabled 2. the vf was enabled or in the process of being
2895 static void bnx2x_vfop_release(struct bnx2x *bp, struct bnx2x_virtf *vf)
2897 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
2898 struct bnx2x_vfop_cmd cmd = {
2899 .done = bnx2x_vfop_release,
2903 DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
2908 DP(BNX2X_MSG_IOV, "VF[%d] STATE: %s\n", vf->abs_vfid,
2909 vf->state == VF_FREE ? "Free" :
2910 vf->state == VF_ACQUIRED ? "Acquired" :
2911 vf->state == VF_ENABLED ? "Enabled" :
2912 vf->state == VF_RESET ? "Reset" :
2915 switch (vf->state) {
2917 vfop->rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
2923 DP(BNX2X_MSG_IOV, "about to free resources\n");
2924 bnx2x_vf_free_resc(bp, vf);
2925 DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
2933 bnx2x_vfop_default(vf->state);
2936 BNX2X_ERR("VF[%d] RELEASE error: rc %d\n", vf->abs_vfid, vfop->rc);
2938 bnx2x_vfop_end(bp, vf, vfop);
2941 int bnx2x_vfop_release_cmd(struct bnx2x *bp,
2942 struct bnx2x_virtf *vf,
2943 struct bnx2x_vfop_cmd *cmd)
2945 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
2947 bnx2x_vfop_opset(-1, /* use vf->state */
2948 bnx2x_vfop_release, cmd->done);
2949 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_release,
2955 /* VF release ~ VF close + VF release-resources
2956 * Release is the ultimate SW shutdown and is called whenever an
2957 * irrecoverable error is encountered.
2959 void bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf, bool block)
2961 struct bnx2x_vfop_cmd cmd = {
2966 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
2968 rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
2971 "VF[%d] Failed to allocate resources for release op- rc=%d\n",
2975 static inline void bnx2x_vf_get_sbdf(struct bnx2x *bp,
2976 struct bnx2x_virtf *vf, u32 *sbdf)
2978 *sbdf = vf->devfn | (vf->bus << 8);
2981 static inline void bnx2x_vf_get_bars(struct bnx2x *bp, struct bnx2x_virtf *vf,
2982 struct bnx2x_vf_bar_info *bar_info)
2986 bar_info->nr_bars = bp->vfdb->sriov.nres;
2987 for (n = 0; n < bar_info->nr_bars; n++)
2988 bar_info->bars[n] = vf->bars[n];
2991 void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
2992 enum channel_tlvs tlv)
2994 /* lock the channel */
2995 mutex_lock(&vf->op_mutex);
2997 /* record the locking op */
2998 vf->op_current = tlv;
3001 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n",
3005 void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
3006 enum channel_tlvs expected_tlv)
3008 WARN(expected_tlv != vf->op_current,
3009 "lock mismatch: expected %d found %d", expected_tlv,
3012 /* lock the channel */
3013 mutex_unlock(&vf->op_mutex);
3015 /* log the unlock */
3016 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n",
3017 vf->abs_vfid, vf->op_current);
3019 /* record the locking op */
3020 vf->op_current = CHANNEL_TLV_NONE;
3023 void bnx2x_enable_sriov(struct bnx2x *bp)
3027 /* disbale sriov in case it is still enabled */
3028 pci_disable_sriov(bp->pdev);
3029 DP(BNX2X_MSG_IOV, "sriov disabled\n");
3032 DP(BNX2X_MSG_IOV, "vf num (%d)\n", (bp->vfdb->sriov.nr_virtfn));
3033 rc = pci_enable_sriov(bp->pdev, (bp->vfdb->sriov.nr_virtfn));
3035 BNX2X_ERR("pci_enable_sriov failed with %d\n", rc);
3037 DP(BNX2X_MSG_IOV, "sriov enabled\n");
3040 void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp)
3043 struct pf_vf_bulletin_content *bulletin;
3045 DP(BNX2X_MSG_IOV, "configuring vlan for VFs from sp-task\n");
3046 for_each_vf(bp, vfidx) {
3047 bulletin = BP_VF_BULLETIN(bp, vfidx);
3048 if (BP_VF(bp, vfidx)->cfg_flags & VF_CFG_VLAN)
3049 bnx2x_set_vf_vlan(bp->dev, vfidx, bulletin->vlan, 0);
3053 static int bnx2x_vf_ndo_sanity(struct bnx2x *bp, int vfidx,
3054 struct bnx2x_virtf *vf)
3056 if (!IS_SRIOV(bp)) {
3057 BNX2X_ERR("vf ndo called though sriov is disabled\n");
3061 if (vfidx >= BNX2X_NR_VIRTFN(bp)) {
3062 BNX2X_ERR("vf ndo called for uninitialized VF. vfidx was %d BNX2X_NR_VIRTFN was %d\n",
3063 vfidx, BNX2X_NR_VIRTFN(bp));
3068 BNX2X_ERR("vf ndo called but vf was null. vfidx was %d\n",
3076 int bnx2x_get_vf_config(struct net_device *dev, int vfidx,
3077 struct ifla_vf_info *ivi)
3079 struct bnx2x *bp = netdev_priv(dev);
3080 struct bnx2x_virtf *vf = BP_VF(bp, vfidx);
3081 struct bnx2x_vlan_mac_obj *mac_obj = &bnx2x_vfq(vf, 0, mac_obj);
3082 struct bnx2x_vlan_mac_obj *vlan_obj = &bnx2x_vfq(vf, 0, vlan_obj);
3083 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vfidx);
3087 rc = bnx2x_vf_ndo_sanity(bp, vfidx, vf);
3093 ivi->tx_rate = 10000; /* always 10G. TBA take from link struct */
3094 ivi->spoofchk = 1; /*always enabled */
3095 if (vf->state == VF_ENABLED) {
3096 /* mac and vlan are in vlan_mac objects */
3097 mac_obj->get_n_elements(bp, mac_obj, 1, (u8 *)&ivi->mac,
3099 vlan_obj->get_n_elements(bp, vlan_obj, 1, (u8 *)&ivi->vlan,
3103 if (bulletin->valid_bitmap & (1 << MAC_ADDR_VALID))
3104 /* mac configured by ndo so its in bulletin board */
3105 memcpy(&ivi->mac, bulletin->mac, ETH_ALEN);
3107 /* funtion has not been loaded yet. Show mac as 0s */
3108 memset(&ivi->mac, 0, ETH_ALEN);
3111 if (bulletin->valid_bitmap & (1 << VLAN_VALID))
3112 /* vlan configured by ndo so its in bulletin board */
3113 memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN);
3115 /* funtion has not been loaded yet. Show vlans as 0s */
3116 memset(&ivi->vlan, 0, VLAN_HLEN);
3122 /* New mac for VF. Consider these cases:
3123 * 1. VF hasn't been acquired yet - save the mac in local bulletin board and
3124 * supply at acquire.
3125 * 2. VF has already been acquired but has not yet initialized - store in local
3126 * bulletin board. mac will be posted on VF bulletin board after VF init. VF
3127 * will configure this mac when it is ready.
3128 * 3. VF has already initialized but has not yet setup a queue - post the new
3129 * mac on VF's bulletin board right now. VF will configure this mac when it
3131 * 4. VF has already set a queue - delete any macs already configured for this
3132 * queue and manually config the new mac.
3133 * In any event, once this function has been called refuse any attempts by the
3134 * VF to configure any mac for itself except for this mac. In case of a race
3135 * where the VF fails to see the new post on its bulletin board before sending a
3136 * mac configuration request, the PF will simply fail the request and VF can try
3137 * again after consulting its bulletin board.
3139 int bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac)
3141 struct bnx2x *bp = netdev_priv(dev);
3142 int rc, q_logical_state;
3143 struct bnx2x_virtf *vf = BP_VF(bp, vfidx);
3144 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vfidx);
3147 rc = bnx2x_vf_ndo_sanity(bp, vfidx, vf);
3150 if (!is_valid_ether_addr(mac)) {
3151 BNX2X_ERR("mac address invalid\n");
3155 /* update PF's copy of the VF's bulletin. will no longer accept mac
3156 * configuration requests from vf unless match this mac
3158 bulletin->valid_bitmap |= 1 << MAC_ADDR_VALID;
3159 memcpy(bulletin->mac, mac, ETH_ALEN);
3161 /* Post update on VF's bulletin board */
3162 rc = bnx2x_post_vf_bulletin(bp, vfidx);
3164 BNX2X_ERR("failed to update VF[%d] bulletin\n", vfidx);
3168 /* is vf initialized and queue set up? */
3170 bnx2x_get_q_logical_state(bp, &bnx2x_vfq(vf, 0, sp_obj));
3171 if (vf->state == VF_ENABLED &&
3172 q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) {
3173 /* configure the mac in device on this vf's queue */
3174 unsigned long ramrod_flags = 0;
3175 struct bnx2x_vlan_mac_obj *mac_obj = &bnx2x_vfq(vf, 0, mac_obj);
3177 /* must lock vfpf channel to protect against vf flows */
3178 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
3180 /* remove existing eth macs */
3181 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true);
3183 BNX2X_ERR("failed to delete eth macs\n");
3187 /* remove existing uc list macs */
3188 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true);
3190 BNX2X_ERR("failed to delete uc_list macs\n");
3194 /* configure the new mac to device */
3195 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3196 bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true,
3197 BNX2X_ETH_MAC, &ramrod_flags);
3199 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
3205 int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
3207 struct bnx2x *bp = netdev_priv(dev);
3208 int rc, q_logical_state;
3209 struct bnx2x_virtf *vf = BP_VF(bp, vfidx);
3210 struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vfidx);
3213 rc = bnx2x_vf_ndo_sanity(bp, vfidx, vf);
3218 BNX2X_ERR("illegal vlan value %d\n", vlan);
3222 DP(BNX2X_MSG_IOV, "configuring VF %d with VLAN %d qos %d\n",
3225 /* update PF's copy of the VF's bulletin. No point in posting the vlan
3226 * to the VF since it doesn't have anything to do with it. But it useful
3227 * to store it here in case the VF is not up yet and we can only
3228 * configure the vlan later when it does.
3230 bulletin->valid_bitmap |= 1 << VLAN_VALID;
3231 bulletin->vlan = vlan;
3233 /* is vf initialized and queue set up? */
3235 bnx2x_get_q_logical_state(bp, &bnx2x_vfq(vf, 0, sp_obj));
3236 if (vf->state == VF_ENABLED &&
3237 q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) {
3238 /* configure the vlan in device on this vf's queue */
3239 unsigned long ramrod_flags = 0;
3240 unsigned long vlan_mac_flags = 0;
3241 struct bnx2x_vlan_mac_obj *vlan_obj =
3242 &bnx2x_vfq(vf, 0, vlan_obj);
3243 struct bnx2x_vlan_mac_ramrod_params ramrod_param;
3244 struct bnx2x_queue_state_params q_params = {NULL};
3245 struct bnx2x_queue_update_params *update_params;
3247 memset(&ramrod_param, 0, sizeof(ramrod_param));
3249 /* must lock vfpf channel to protect against vf flows */
3250 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
3252 /* remove existing vlans */
3253 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3254 rc = vlan_obj->delete_all(bp, vlan_obj, &vlan_mac_flags,
3257 BNX2X_ERR("failed to delete vlans\n");
3261 /* send queue update ramrod to configure default vlan and silent
3264 __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
3265 q_params.cmd = BNX2X_Q_CMD_UPDATE;
3266 q_params.q_obj = &bnx2x_vfq(vf, 0, sp_obj);
3267 update_params = &q_params.params.update;
3268 __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
3269 &update_params->update_flags);
3270 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
3271 &update_params->update_flags);
3274 /* if vlan is 0 then we want to leave the VF traffic
3275 * untagged, and leave the incoming traffic untouched
3276 * (i.e. do not remove any vlan tags).
3278 __clear_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
3279 &update_params->update_flags);
3280 __clear_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
3281 &update_params->update_flags);
3283 /* configure the new vlan to device */
3284 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
3285 ramrod_param.vlan_mac_obj = vlan_obj;
3286 ramrod_param.ramrod_flags = ramrod_flags;
3287 ramrod_param.user_req.u.vlan.vlan = vlan;
3288 ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
3289 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
3291 BNX2X_ERR("failed to configure vlan\n");
3295 /* configure default vlan to vf queue and set silent
3296 * vlan removal (the vf remains unaware of this vlan).
3298 update_params = &q_params.params.update;
3299 __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
3300 &update_params->update_flags);
3301 __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
3302 &update_params->update_flags);
3303 update_params->def_vlan = vlan;
3306 /* Update the Queue state */
3307 rc = bnx2x_queue_state_change(bp, &q_params);
3309 BNX2X_ERR("Failed to configure default VLAN\n");
3313 /* clear the flag indicating that this VF needs its vlan
3314 * (will only be set if the HV configured th Vlan before vf was
3315 * and we were called because the VF came up later
3317 vf->cfg_flags &= ~VF_CFG_VLAN;
3319 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
3324 /* crc is the first field in the bulletin board. compute the crc over the
3325 * entire bulletin board excluding the crc field itself
3327 u32 bnx2x_crc_vf_bulletin(struct bnx2x *bp,
3328 struct pf_vf_bulletin_content *bulletin)
3330 return crc32(BULLETIN_CRC_SEED,
3331 ((u8 *)bulletin) + sizeof(bulletin->crc),
3332 bulletin->length - sizeof(bulletin->crc));
3335 /* Check for new posts on the bulletin board */
3336 enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp)
3338 struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
3341 /* bulletin board hasn't changed since last sample */
3342 if (bp->old_bulletin.version == bulletin.version)
3343 return PFVF_BULLETIN_UNCHANGED;
3345 /* validate crc of new bulletin board */
3346 if (bp->old_bulletin.version != bp->pf2vf_bulletin->content.version) {
3347 /* sampling structure in mid post may result with corrupted data
3348 * validate crc to ensure coherency.
3350 for (attempts = 0; attempts < BULLETIN_ATTEMPTS; attempts++) {
3351 bulletin = bp->pf2vf_bulletin->content;
3352 if (bulletin.crc == bnx2x_crc_vf_bulletin(bp,
3355 BNX2X_ERR("bad crc on bulletin board. contained %x computed %x\n",
3357 bnx2x_crc_vf_bulletin(bp, &bulletin));
3359 if (attempts >= BULLETIN_ATTEMPTS) {
3360 BNX2X_ERR("pf to vf bulletin board crc was wrong %d consecutive times. Aborting\n",
3362 return PFVF_BULLETIN_CRC_ERR;
3366 /* the mac address in bulletin board is valid and is new */
3367 if (bulletin.valid_bitmap & 1 << MAC_ADDR_VALID &&
3368 memcmp(bulletin.mac, bp->old_bulletin.mac, ETH_ALEN)) {
3369 /* update new mac to net device */
3370 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
3373 /* the vlan in bulletin board is valid and is new */
3374 if (bulletin.valid_bitmap & 1 << VLAN_VALID)
3375 memcpy(&bulletin.vlan, &bp->old_bulletin.vlan, VLAN_HLEN);
3377 /* copy new bulletin board to bp */
3378 bp->old_bulletin = bulletin;
3380 return PFVF_BULLETIN_UPDATED;
3383 void bnx2x_vf_map_doorbells(struct bnx2x *bp)
3385 /* vf doorbells are embedded within the regview */
3386 bp->doorbells = bp->regview + PXP_VF_ADDR_DB_START;
3389 int bnx2x_vf_pci_alloc(struct bnx2x *bp)
3391 /* allocate vf2pf mailbox for vf to pf channel */
3392 BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
3393 sizeof(struct bnx2x_vf_mbx_msg));
3395 /* allocate pf 2 vf bulletin board */
3396 BNX2X_PCI_ALLOC(bp->pf2vf_bulletin, &bp->pf2vf_bulletin_mapping,
3397 sizeof(union pf_vf_bulletin));
3402 BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
3403 sizeof(struct bnx2x_vf_mbx_msg));
3404 BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
3405 sizeof(union pf_vf_bulletin));