1 /* bnx2x_sriov.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_init.h"
22 #include "bnx2x_cmn.h"
23 #include "bnx2x_sriov.h"
25 /* General service functions */
26 static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
29 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
31 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
33 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
35 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
39 static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
42 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
44 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
46 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
48 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
52 int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
57 if (bnx2x_vf(bp, idx, abs_vfid) == abs_vfid)
63 struct bnx2x_virtf *bnx2x_vf_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
65 u16 idx = (u16)bnx2x_vf_idx_by_abs_fid(bp, abs_vfid);
66 return (idx < BNX2X_NR_VIRTFN(bp)) ? BP_VF(bp, idx) : NULL;
69 static void bnx2x_vf_igu_ack_sb(struct bnx2x *bp, struct bnx2x_virtf *vf,
70 u8 igu_sb_id, u8 segment, u16 index, u8 op,
73 /* acking a VF sb through the PF - use the GRC */
75 u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
76 u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
77 u32 func_encode = vf->abs_vfid;
78 u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + igu_sb_id;
79 struct igu_regular cmd_data = {0};
81 cmd_data.sb_id_and_flags =
82 ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
83 (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
84 (update << IGU_REGULAR_BUPDATE_SHIFT) |
85 (op << IGU_REGULAR_ENABLE_INT_SHIFT));
87 ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
88 func_encode << IGU_CTRL_REG_FID_SHIFT |
89 IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
91 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
92 cmd_data.sb_id_and_flags, igu_addr_data);
93 REG_WR(bp, igu_addr_data, cmd_data.sb_id_and_flags);
97 DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
99 REG_WR(bp, igu_addr_ctl, ctl);
103 /* VFOP - VF slow-path operation support */
105 #define BNX2X_VFOP_FILTER_ADD_CNT_MAX 0x10000
107 /* VFOP operations states */
108 enum bnx2x_vfop_qctor_state {
109 BNX2X_VFOP_QCTOR_INIT,
110 BNX2X_VFOP_QCTOR_SETUP,
111 BNX2X_VFOP_QCTOR_INT_EN
114 enum bnx2x_vfop_qdtor_state {
115 BNX2X_VFOP_QDTOR_HALT,
116 BNX2X_VFOP_QDTOR_TERMINATE,
117 BNX2X_VFOP_QDTOR_CFCDEL,
118 BNX2X_VFOP_QDTOR_DONE
121 enum bnx2x_vfop_vlan_mac_state {
122 BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
123 BNX2X_VFOP_VLAN_MAC_CLEAR,
124 BNX2X_VFOP_VLAN_MAC_CHK_DONE,
125 BNX2X_VFOP_MAC_CONFIG_LIST,
126 BNX2X_VFOP_VLAN_CONFIG_LIST,
127 BNX2X_VFOP_VLAN_CONFIG_LIST_0
130 enum bnx2x_vfop_qsetup_state {
131 BNX2X_VFOP_QSETUP_CTOR,
132 BNX2X_VFOP_QSETUP_VLAN0,
133 BNX2X_VFOP_QSETUP_DONE
136 enum bnx2x_vfop_mcast_state {
137 BNX2X_VFOP_MCAST_DEL,
138 BNX2X_VFOP_MCAST_ADD,
139 BNX2X_VFOP_MCAST_CHK_DONE
141 enum bnx2x_vfop_qflr_state {
142 BNX2X_VFOP_QFLR_CLR_VLAN,
143 BNX2X_VFOP_QFLR_CLR_MAC,
144 BNX2X_VFOP_QFLR_TERMINATE,
148 enum bnx2x_vfop_flr_state {
149 BNX2X_VFOP_FLR_QUEUES,
153 enum bnx2x_vfop_close_state {
154 BNX2X_VFOP_CLOSE_QUEUES,
158 enum bnx2x_vfop_rxmode_state {
159 BNX2X_VFOP_RXMODE_CONFIG,
160 BNX2X_VFOP_RXMODE_DONE
163 enum bnx2x_vfop_qteardown_state {
164 BNX2X_VFOP_QTEARDOWN_RXMODE,
165 BNX2X_VFOP_QTEARDOWN_CLR_VLAN,
166 BNX2X_VFOP_QTEARDOWN_CLR_MAC,
167 BNX2X_VFOP_QTEARDOWN_QDTOR,
168 BNX2X_VFOP_QTEARDOWN_DONE
171 #define bnx2x_vfop_reset_wq(vf) atomic_set(&vf->op_in_progress, 0)
173 void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
174 struct bnx2x_queue_init_params *init_params,
175 struct bnx2x_queue_setup_params *setup_params,
176 u16 q_idx, u16 sb_idx)
179 "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d",
183 init_params->tx.sb_cq_index,
184 init_params->tx.hc_rate,
186 setup_params->txq_params.traffic_type);
189 void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
190 struct bnx2x_queue_init_params *init_params,
191 struct bnx2x_queue_setup_params *setup_params,
192 u16 q_idx, u16 sb_idx)
194 struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params;
196 DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n"
197 "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n",
201 init_params->rx.sb_cq_index,
202 init_params->rx.hc_rate,
203 setup_params->gen_params.mtu,
205 rxq_params->sge_buf_sz,
206 rxq_params->max_sges_pkt,
207 rxq_params->tpa_agg_sz,
209 rxq_params->drop_flags,
210 rxq_params->cache_line_log);
213 void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
214 struct bnx2x_virtf *vf,
215 struct bnx2x_vf_queue *q,
216 struct bnx2x_vfop_qctor_params *p,
217 unsigned long q_type)
219 struct bnx2x_queue_init_params *init_p = &p->qstate.params.init;
220 struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup;
224 /* Enable host coalescing in the transition to INIT state */
225 if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags))
226 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags);
228 if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags))
229 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags);
232 init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
233 init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
236 init_p->cxts[0] = q->cxt;
240 /* Setup-op general parameters */
241 setup_p->gen_params.spcl_id = vf->sp_cl_id;
242 setup_p->gen_params.stat_id = vfq_stat_id(vf, q);
244 /* Setup-op pause params:
245 * Nothing to do, the pause thresholds are set by default to 0 which
246 * effectively turns off the feature for this queue. We don't want
247 * one queue (VF) to interfering with another queue (another VF)
249 if (vf->cfg_flags & VF_CFG_FW_FC)
250 BNX2X_ERR("No support for pause to VFs (abs_vfid: %d)\n",
253 * collect statistics, zero statistics, local-switching, security,
254 * OV for Flex10, RSS and MCAST for leading
256 if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags))
257 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags);
259 /* for VFs, enable tx switching, bd coherency, and mac address
262 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags);
263 __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags);
264 __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags);
266 if (vfq_is_leading(q)) {
267 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &setup_p->flags);
268 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
271 /* Setup-op rx parameters */
272 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) {
273 struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params;
275 rxq_p->cl_qzone_id = vfq_qzone_id(vf, q);
276 rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx);
277 rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid);
279 if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags))
280 rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES;
283 /* Setup-op tx parameters */
284 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) {
285 setup_p->txq_params.tss_leading_cl_id = vf->leading_rss;
286 setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
290 /* VFOP queue construction */
291 static void bnx2x_vfop_qctor(struct bnx2x *bp, struct bnx2x_virtf *vf)
293 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
294 struct bnx2x_vfop_args_qctor *args = &vfop->args.qctor;
295 struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
296 enum bnx2x_vfop_qctor_state state = vfop->state;
298 bnx2x_vfop_reset_wq(vf);
303 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
306 case BNX2X_VFOP_QCTOR_INIT:
308 /* has this queue already been opened? */
309 if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
310 BNX2X_Q_LOGICAL_STATE_ACTIVE) {
312 "Entered qctor but queue was already up. Aborting gracefully\n");
317 vfop->state = BNX2X_VFOP_QCTOR_SETUP;
319 q_params->cmd = BNX2X_Q_CMD_INIT;
320 vfop->rc = bnx2x_queue_state_change(bp, q_params);
322 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
324 case BNX2X_VFOP_QCTOR_SETUP:
326 vfop->state = BNX2X_VFOP_QCTOR_INT_EN;
328 /* copy pre-prepared setup params to the queue-state params */
329 vfop->op_p->qctor.qstate.params.setup =
330 vfop->op_p->qctor.prep_qsetup;
332 q_params->cmd = BNX2X_Q_CMD_SETUP;
333 vfop->rc = bnx2x_queue_state_change(bp, q_params);
335 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
337 case BNX2X_VFOP_QCTOR_INT_EN:
339 /* enable interrupts */
340 bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, args->sb_idx),
341 USTORM_ID, 0, IGU_INT_ENABLE, 0);
344 bnx2x_vfop_default(state);
347 BNX2X_ERR("QCTOR[%d:%d] error: cmd %d, rc %d\n",
348 vf->abs_vfid, args->qid, q_params->cmd, vfop->rc);
350 bnx2x_vfop_end(bp, vf, vfop);
355 static int bnx2x_vfop_qctor_cmd(struct bnx2x *bp,
356 struct bnx2x_virtf *vf,
357 struct bnx2x_vfop_cmd *cmd,
360 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
363 vf->op_params.qctor.qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
365 vfop->args.qctor.qid = qid;
366 vfop->args.qctor.sb_idx = bnx2x_vfq(vf, qid, sb_idx);
368 bnx2x_vfop_opset(BNX2X_VFOP_QCTOR_INIT,
369 bnx2x_vfop_qctor, cmd->done);
370 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qctor,
376 /* VFOP queue destruction */
377 static void bnx2x_vfop_qdtor(struct bnx2x *bp, struct bnx2x_virtf *vf)
379 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
380 struct bnx2x_vfop_args_qdtor *qdtor = &vfop->args.qdtor;
381 struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
382 enum bnx2x_vfop_qdtor_state state = vfop->state;
384 bnx2x_vfop_reset_wq(vf);
389 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
392 case BNX2X_VFOP_QDTOR_HALT:
394 /* has this queue already been stopped? */
395 if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
396 BNX2X_Q_LOGICAL_STATE_STOPPED) {
398 "Entered qdtor but queue was already stopped. Aborting gracefully\n");
403 vfop->state = BNX2X_VFOP_QDTOR_TERMINATE;
405 q_params->cmd = BNX2X_Q_CMD_HALT;
406 vfop->rc = bnx2x_queue_state_change(bp, q_params);
408 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
410 case BNX2X_VFOP_QDTOR_TERMINATE:
412 vfop->state = BNX2X_VFOP_QDTOR_CFCDEL;
414 q_params->cmd = BNX2X_Q_CMD_TERMINATE;
415 vfop->rc = bnx2x_queue_state_change(bp, q_params);
417 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
419 case BNX2X_VFOP_QDTOR_CFCDEL:
421 vfop->state = BNX2X_VFOP_QDTOR_DONE;
423 q_params->cmd = BNX2X_Q_CMD_CFC_DEL;
424 vfop->rc = bnx2x_queue_state_change(bp, q_params);
426 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
428 BNX2X_ERR("QDTOR[%d:%d] error: cmd %d, rc %d\n",
429 vf->abs_vfid, qdtor->qid, q_params->cmd, vfop->rc);
431 case BNX2X_VFOP_QDTOR_DONE:
432 /* invalidate the context */
433 qdtor->cxt->ustorm_ag_context.cdu_usage = 0;
434 qdtor->cxt->xstorm_ag_context.cdu_reserved = 0;
435 bnx2x_vfop_end(bp, vf, vfop);
438 bnx2x_vfop_default(state);
444 static int bnx2x_vfop_qdtor_cmd(struct bnx2x *bp,
445 struct bnx2x_virtf *vf,
446 struct bnx2x_vfop_cmd *cmd,
449 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
452 struct bnx2x_queue_state_params *qstate =
453 &vf->op_params.qctor.qstate;
455 memset(qstate, 0, sizeof(*qstate));
456 qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
458 vfop->args.qdtor.qid = qid;
459 vfop->args.qdtor.cxt = bnx2x_vfq(vf, qid, cxt);
461 bnx2x_vfop_opset(BNX2X_VFOP_QDTOR_HALT,
462 bnx2x_vfop_qdtor, cmd->done);
463 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdtor,
466 DP(BNX2X_MSG_IOV, "VF[%d] failed to add a vfop. rc %d\n",
467 vf->abs_vfid, vfop->rc);
472 bnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid)
474 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
476 if (!vf_sb_count(vf))
477 vf->igu_base_id = igu_sb_id;
482 /* VFOP MAC/VLAN helpers */
483 static inline void bnx2x_vfop_credit(struct bnx2x *bp,
484 struct bnx2x_vfop *vfop,
485 struct bnx2x_vlan_mac_obj *obj)
487 struct bnx2x_vfop_args_filters *args = &vfop->args.filters;
489 /* update credit only if there is no error
490 * and a valid credit counter
492 if (!vfop->rc && args->credit) {
494 struct list_head *pos;
496 list_for_each(pos, &obj->head)
499 atomic_set(args->credit, cnt);
503 static int bnx2x_vfop_set_user_req(struct bnx2x *bp,
504 struct bnx2x_vfop_filter *pos,
505 struct bnx2x_vlan_mac_data *user_req)
507 user_req->cmd = pos->add ? BNX2X_VLAN_MAC_ADD :
511 case BNX2X_VFOP_FILTER_MAC:
512 memcpy(user_req->u.mac.mac, pos->mac, ETH_ALEN);
514 case BNX2X_VFOP_FILTER_VLAN:
515 user_req->u.vlan.vlan = pos->vid;
518 BNX2X_ERR("Invalid filter type, skipping\n");
525 bnx2x_vfop_config_vlan0(struct bnx2x *bp,
526 struct bnx2x_vlan_mac_ramrod_params *vlan_mac,
531 vlan_mac->user_req.cmd = add ? BNX2X_VLAN_MAC_ADD :
533 vlan_mac->user_req.u.vlan.vlan = 0;
535 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
541 static int bnx2x_vfop_config_list(struct bnx2x *bp,
542 struct bnx2x_vfop_filters *filters,
543 struct bnx2x_vlan_mac_ramrod_params *vlan_mac)
545 struct bnx2x_vfop_filter *pos, *tmp;
546 struct list_head rollback_list, *filters_list = &filters->head;
547 struct bnx2x_vlan_mac_data *user_req = &vlan_mac->user_req;
550 INIT_LIST_HEAD(&rollback_list);
552 list_for_each_entry_safe(pos, tmp, filters_list, link) {
553 if (bnx2x_vfop_set_user_req(bp, pos, user_req))
556 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
558 cnt += pos->add ? 1 : -1;
559 list_del(&pos->link);
560 list_add(&pos->link, &rollback_list);
562 } else if (rc == -EEXIST) {
565 BNX2X_ERR("Failed to add a new vlan_mac command\n");
570 /* rollback if error or too many rules added */
571 if (rc || cnt > filters->add_cnt) {
572 BNX2X_ERR("error or too many rules added. Performing rollback\n");
573 list_for_each_entry_safe(pos, tmp, &rollback_list, link) {
574 pos->add = !pos->add; /* reverse op */
575 bnx2x_vfop_set_user_req(bp, pos, user_req);
576 bnx2x_config_vlan_mac(bp, vlan_mac);
577 list_del(&pos->link);
583 filters->add_cnt = cnt;
587 /* VFOP set VLAN/MAC */
588 static void bnx2x_vfop_vlan_mac(struct bnx2x *bp, struct bnx2x_virtf *vf)
590 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
591 struct bnx2x_vlan_mac_ramrod_params *vlan_mac = &vfop->op_p->vlan_mac;
592 struct bnx2x_vlan_mac_obj *obj = vlan_mac->vlan_mac_obj;
593 struct bnx2x_vfop_filters *filters = vfop->args.filters.multi_filter;
595 enum bnx2x_vfop_vlan_mac_state state = vfop->state;
600 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
602 bnx2x_vfop_reset_wq(vf);
605 case BNX2X_VFOP_VLAN_MAC_CLEAR:
607 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
610 vfop->rc = obj->delete_all(bp, obj,
611 &vlan_mac->user_req.vlan_mac_flags,
612 &vlan_mac->ramrod_flags);
614 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
616 case BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE:
618 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
621 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
622 if (vfop->rc == -EEXIST)
625 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
627 case BNX2X_VFOP_VLAN_MAC_CHK_DONE:
628 vfop->rc = !!obj->raw.check_pending(&obj->raw);
629 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
631 case BNX2X_VFOP_MAC_CONFIG_LIST:
633 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
636 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
640 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
641 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
642 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
644 case BNX2X_VFOP_VLAN_CONFIG_LIST:
646 vfop->state = BNX2X_VFOP_VLAN_CONFIG_LIST_0;
648 /* remove vlan0 - could be no-op */
649 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, false);
653 /* Do vlan list config. if this operation fails we try to
654 * restore vlan0 to keep the queue is working order
656 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
658 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
659 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
661 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT); /* fall-through */
663 case BNX2X_VFOP_VLAN_CONFIG_LIST_0:
665 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
667 if (list_empty(&obj->head))
669 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, true);
670 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
673 bnx2x_vfop_default(state);
676 BNX2X_ERR("VLAN-MAC error: rc %d\n", vfop->rc);
679 bnx2x_vfop_credit(bp, vfop, obj);
680 bnx2x_vfop_end(bp, vf, vfop);
685 struct bnx2x_vfop_vlan_mac_flags {
693 bnx2x_vfop_vlan_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
694 struct bnx2x_vfop_vlan_mac_flags *flags)
696 struct bnx2x_vlan_mac_data *ureq = &ramrod->user_req;
698 memset(ramrod, 0, sizeof(*ramrod));
702 set_bit(RAMROD_DRV_CLR_ONLY, &ramrod->ramrod_flags);
703 if (flags->single_cmd)
704 set_bit(RAMROD_EXEC, &ramrod->ramrod_flags);
707 if (flags->dont_consume)
708 set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT, &ureq->vlan_mac_flags);
711 ureq->cmd = flags->add ? BNX2X_VLAN_MAC_ADD : BNX2X_VLAN_MAC_DEL;
715 bnx2x_vfop_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
716 struct bnx2x_vfop_vlan_mac_flags *flags)
718 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, flags);
719 set_bit(BNX2X_ETH_MAC, &ramrod->user_req.vlan_mac_flags);
722 static int bnx2x_vfop_mac_delall_cmd(struct bnx2x *bp,
723 struct bnx2x_virtf *vf,
724 struct bnx2x_vfop_cmd *cmd,
725 int qid, bool drv_only)
727 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
730 struct bnx2x_vfop_args_filters filters = {
731 .multi_filter = NULL, /* single */
732 .credit = NULL, /* consume credit */
734 struct bnx2x_vfop_vlan_mac_flags flags = {
735 .drv_only = drv_only,
736 .dont_consume = (filters.credit != NULL),
738 .add = false /* don't care */,
740 struct bnx2x_vlan_mac_ramrod_params *ramrod =
741 &vf->op_params.vlan_mac;
743 /* set ramrod params */
744 bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
747 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
750 vfop->args.filters = filters;
752 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
753 bnx2x_vfop_vlan_mac, cmd->done);
754 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
760 int bnx2x_vfop_mac_list_cmd(struct bnx2x *bp,
761 struct bnx2x_virtf *vf,
762 struct bnx2x_vfop_cmd *cmd,
763 struct bnx2x_vfop_filters *macs,
764 int qid, bool drv_only)
766 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
769 struct bnx2x_vfop_args_filters filters = {
770 .multi_filter = macs,
771 .credit = NULL, /* consume credit */
773 struct bnx2x_vfop_vlan_mac_flags flags = {
774 .drv_only = drv_only,
775 .dont_consume = (filters.credit != NULL),
777 .add = false, /* don't care since only the items in the
778 * filters list affect the sp operation,
779 * not the list itself
782 struct bnx2x_vlan_mac_ramrod_params *ramrod =
783 &vf->op_params.vlan_mac;
785 /* set ramrod params */
786 bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
789 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
792 filters.multi_filter->add_cnt = BNX2X_VFOP_FILTER_ADD_CNT_MAX;
793 vfop->args.filters = filters;
795 bnx2x_vfop_opset(BNX2X_VFOP_MAC_CONFIG_LIST,
796 bnx2x_vfop_vlan_mac, cmd->done);
797 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
803 int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
804 struct bnx2x_virtf *vf,
805 struct bnx2x_vfop_cmd *cmd,
806 int qid, u16 vid, bool add)
808 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
811 struct bnx2x_vfop_args_filters filters = {
812 .multi_filter = NULL, /* single command */
813 .credit = &bnx2x_vfq(vf, qid, vlan_count),
815 struct bnx2x_vfop_vlan_mac_flags flags = {
817 .dont_consume = (filters.credit != NULL),
821 struct bnx2x_vlan_mac_ramrod_params *ramrod =
822 &vf->op_params.vlan_mac;
824 /* set ramrod params */
825 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
826 ramrod->user_req.u.vlan.vlan = vid;
829 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
832 vfop->args.filters = filters;
834 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
835 bnx2x_vfop_vlan_mac, cmd->done);
836 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
842 static int bnx2x_vfop_vlan_delall_cmd(struct bnx2x *bp,
843 struct bnx2x_virtf *vf,
844 struct bnx2x_vfop_cmd *cmd,
845 int qid, bool drv_only)
847 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
850 struct bnx2x_vfop_args_filters filters = {
851 .multi_filter = NULL, /* single command */
852 .credit = &bnx2x_vfq(vf, qid, vlan_count),
854 struct bnx2x_vfop_vlan_mac_flags flags = {
855 .drv_only = drv_only,
856 .dont_consume = (filters.credit != NULL),
858 .add = false, /* don't care */
860 struct bnx2x_vlan_mac_ramrod_params *ramrod =
861 &vf->op_params.vlan_mac;
863 /* set ramrod params */
864 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
867 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
870 vfop->args.filters = filters;
872 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
873 bnx2x_vfop_vlan_mac, cmd->done);
874 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
880 int bnx2x_vfop_vlan_list_cmd(struct bnx2x *bp,
881 struct bnx2x_virtf *vf,
882 struct bnx2x_vfop_cmd *cmd,
883 struct bnx2x_vfop_filters *vlans,
884 int qid, bool drv_only)
886 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
889 struct bnx2x_vfop_args_filters filters = {
890 .multi_filter = vlans,
891 .credit = &bnx2x_vfq(vf, qid, vlan_count),
893 struct bnx2x_vfop_vlan_mac_flags flags = {
894 .drv_only = drv_only,
895 .dont_consume = (filters.credit != NULL),
897 .add = false, /* don't care */
899 struct bnx2x_vlan_mac_ramrod_params *ramrod =
900 &vf->op_params.vlan_mac;
902 /* set ramrod params */
903 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
906 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
909 filters.multi_filter->add_cnt = vf_vlan_rules_cnt(vf) -
910 atomic_read(filters.credit);
912 vfop->args.filters = filters;
914 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_CONFIG_LIST,
915 bnx2x_vfop_vlan_mac, cmd->done);
916 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
922 /* VFOP queue setup (queue constructor + set vlan 0) */
923 static void bnx2x_vfop_qsetup(struct bnx2x *bp, struct bnx2x_virtf *vf)
925 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
926 int qid = vfop->args.qctor.qid;
927 enum bnx2x_vfop_qsetup_state state = vfop->state;
928 struct bnx2x_vfop_cmd cmd = {
929 .done = bnx2x_vfop_qsetup,
936 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
939 case BNX2X_VFOP_QSETUP_CTOR:
940 /* init the queue ctor command */
941 vfop->state = BNX2X_VFOP_QSETUP_VLAN0;
942 vfop->rc = bnx2x_vfop_qctor_cmd(bp, vf, &cmd, qid);
947 case BNX2X_VFOP_QSETUP_VLAN0:
948 /* skip if non-leading or FPGA/EMU*/
952 /* init the queue set-vlan command (for vlan 0) */
953 vfop->state = BNX2X_VFOP_QSETUP_DONE;
954 vfop->rc = bnx2x_vfop_vlan_set_cmd(bp, vf, &cmd, qid, 0, true);
959 BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, vfop->rc);
961 case BNX2X_VFOP_QSETUP_DONE:
962 bnx2x_vfop_end(bp, vf, vfop);
965 bnx2x_vfop_default(state);
969 int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
970 struct bnx2x_virtf *vf,
971 struct bnx2x_vfop_cmd *cmd,
974 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
977 vfop->args.qctor.qid = qid;
979 bnx2x_vfop_opset(BNX2X_VFOP_QSETUP_CTOR,
980 bnx2x_vfop_qsetup, cmd->done);
981 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qsetup,
987 /* VFOP queue FLR handling (clear vlans, clear macs, queue destructor) */
988 static void bnx2x_vfop_qflr(struct bnx2x *bp, struct bnx2x_virtf *vf)
990 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
991 int qid = vfop->args.qx.qid;
992 enum bnx2x_vfop_qflr_state state = vfop->state;
993 struct bnx2x_queue_state_params *qstate;
994 struct bnx2x_vfop_cmd cmd;
996 bnx2x_vfop_reset_wq(vf);
1001 DP(BNX2X_MSG_IOV, "VF[%d] STATE: %d\n", vf->abs_vfid, state);
1003 cmd.done = bnx2x_vfop_qflr;
1007 case BNX2X_VFOP_QFLR_CLR_VLAN:
1008 /* vlan-clear-all: driver-only, don't consume credit */
1009 vfop->state = BNX2X_VFOP_QFLR_CLR_MAC;
1010 vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, true);
1015 case BNX2X_VFOP_QFLR_CLR_MAC:
1016 /* mac-clear-all: driver only consume credit */
1017 vfop->state = BNX2X_VFOP_QFLR_TERMINATE;
1018 vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid, true);
1020 "VF[%d] vfop->rc after bnx2x_vfop_mac_delall_cmd was %d",
1021 vf->abs_vfid, vfop->rc);
1026 case BNX2X_VFOP_QFLR_TERMINATE:
1027 qstate = &vfop->op_p->qctor.qstate;
1028 memset(qstate , 0, sizeof(*qstate));
1029 qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
1030 vfop->state = BNX2X_VFOP_QFLR_DONE;
1032 DP(BNX2X_MSG_IOV, "VF[%d] qstate during flr was %d\n",
1033 vf->abs_vfid, qstate->q_obj->state);
1035 if (qstate->q_obj->state != BNX2X_Q_STATE_RESET) {
1036 qstate->q_obj->state = BNX2X_Q_STATE_STOPPED;
1037 qstate->cmd = BNX2X_Q_CMD_TERMINATE;
1038 vfop->rc = bnx2x_queue_state_change(bp, qstate);
1039 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_VERIFY_PEND);
1045 BNX2X_ERR("QFLR[%d:%d] error: rc %d\n",
1046 vf->abs_vfid, qid, vfop->rc);
1048 case BNX2X_VFOP_QFLR_DONE:
1049 bnx2x_vfop_end(bp, vf, vfop);
1052 bnx2x_vfop_default(state);
1058 static int bnx2x_vfop_qflr_cmd(struct bnx2x *bp,
1059 struct bnx2x_virtf *vf,
1060 struct bnx2x_vfop_cmd *cmd,
1063 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1066 vfop->args.qx.qid = qid;
1067 bnx2x_vfop_opset(BNX2X_VFOP_QFLR_CLR_VLAN,
1068 bnx2x_vfop_qflr, cmd->done);
1069 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qflr,
1075 /* VFOP multi-casts */
1076 static void bnx2x_vfop_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf)
1078 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1079 struct bnx2x_mcast_ramrod_params *mcast = &vfop->op_p->mcast;
1080 struct bnx2x_raw_obj *raw = &mcast->mcast_obj->raw;
1081 struct bnx2x_vfop_args_mcast *args = &vfop->args.mc_list;
1082 enum bnx2x_vfop_mcast_state state = vfop->state;
1085 bnx2x_vfop_reset_wq(vf);
1090 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1093 case BNX2X_VFOP_MCAST_DEL:
1094 /* clear existing mcasts */
1095 vfop->state = BNX2X_VFOP_MCAST_ADD;
1096 vfop->rc = bnx2x_config_mcast(bp, mcast, BNX2X_MCAST_CMD_DEL);
1097 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
1099 case BNX2X_VFOP_MCAST_ADD:
1100 if (raw->check_pending(raw))
1104 /* update mcast list on the ramrod params */
1105 INIT_LIST_HEAD(&mcast->mcast_list);
1106 for (i = 0; i < args->mc_num; i++)
1107 list_add_tail(&(args->mc[i].link),
1108 &mcast->mcast_list);
1109 /* add new mcasts */
1110 vfop->state = BNX2X_VFOP_MCAST_CHK_DONE;
1111 vfop->rc = bnx2x_config_mcast(bp, mcast,
1112 BNX2X_MCAST_CMD_ADD);
1114 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1116 case BNX2X_VFOP_MCAST_CHK_DONE:
1117 vfop->rc = raw->check_pending(raw) ? 1 : 0;
1118 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1120 bnx2x_vfop_default(state);
1123 BNX2X_ERR("MCAST CONFIG error: rc %d\n", vfop->rc);
1126 bnx2x_vfop_end(bp, vf, vfop);
1131 int bnx2x_vfop_mcast_cmd(struct bnx2x *bp,
1132 struct bnx2x_virtf *vf,
1133 struct bnx2x_vfop_cmd *cmd,
1134 bnx2x_mac_addr_t *mcasts,
1135 int mcast_num, bool drv_only)
1137 struct bnx2x_vfop *vfop = NULL;
1138 size_t mc_sz = mcast_num * sizeof(struct bnx2x_mcast_list_elem);
1139 struct bnx2x_mcast_list_elem *mc = mc_sz ? kzalloc(mc_sz, GFP_KERNEL) :
1143 vfop = bnx2x_vfop_add(bp, vf);
1146 struct bnx2x_mcast_ramrod_params *ramrod =
1147 &vf->op_params.mcast;
1149 /* set ramrod params */
1150 memset(ramrod, 0, sizeof(*ramrod));
1151 ramrod->mcast_obj = &vf->mcast_obj;
1153 set_bit(RAMROD_DRV_CLR_ONLY,
1154 &ramrod->ramrod_flags);
1156 /* copy mcasts pointers */
1157 vfop->args.mc_list.mc_num = mcast_num;
1158 vfop->args.mc_list.mc = mc;
1159 for (i = 0; i < mcast_num; i++)
1160 mc[i].mac = mcasts[i];
1162 bnx2x_vfop_opset(BNX2X_VFOP_MCAST_DEL,
1163 bnx2x_vfop_mcast, cmd->done);
1164 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mcast,
1174 static void bnx2x_vfop_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf)
1176 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1177 struct bnx2x_rx_mode_ramrod_params *ramrod = &vfop->op_p->rx_mode;
1178 enum bnx2x_vfop_rxmode_state state = vfop->state;
1180 bnx2x_vfop_reset_wq(vf);
1185 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1188 case BNX2X_VFOP_RXMODE_CONFIG:
1190 vfop->state = BNX2X_VFOP_RXMODE_DONE;
1192 vfop->rc = bnx2x_config_rx_mode(bp, ramrod);
1193 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
1195 BNX2X_ERR("RXMODE error: rc %d\n", vfop->rc);
1197 case BNX2X_VFOP_RXMODE_DONE:
1198 bnx2x_vfop_end(bp, vf, vfop);
1201 bnx2x_vfop_default(state);
1207 int bnx2x_vfop_rxmode_cmd(struct bnx2x *bp,
1208 struct bnx2x_virtf *vf,
1209 struct bnx2x_vfop_cmd *cmd,
1210 int qid, unsigned long accept_flags)
1212 struct bnx2x_vf_queue *vfq = vfq_get(vf, qid);
1213 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1216 struct bnx2x_rx_mode_ramrod_params *ramrod =
1217 &vf->op_params.rx_mode;
1219 memset(ramrod, 0, sizeof(*ramrod));
1221 /* Prepare ramrod parameters */
1222 ramrod->cid = vfq->cid;
1223 ramrod->cl_id = vfq_cl_id(vf, vfq);
1224 ramrod->rx_mode_obj = &bp->rx_mode_obj;
1225 ramrod->func_id = FW_VF_HANDLE(vf->abs_vfid);
1227 ramrod->rx_accept_flags = accept_flags;
1228 ramrod->tx_accept_flags = accept_flags;
1229 ramrod->pstate = &vf->filter_state;
1230 ramrod->state = BNX2X_FILTER_RX_MODE_PENDING;
1232 set_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
1233 set_bit(RAMROD_RX, &ramrod->ramrod_flags);
1234 set_bit(RAMROD_TX, &ramrod->ramrod_flags);
1237 bnx2x_vf_sp(bp, vf, rx_mode_rdata.e2);
1238 ramrod->rdata_mapping =
1239 bnx2x_vf_sp_map(bp, vf, rx_mode_rdata.e2);
1241 bnx2x_vfop_opset(BNX2X_VFOP_RXMODE_CONFIG,
1242 bnx2x_vfop_rxmode, cmd->done);
1243 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_rxmode,
1249 /* VFOP queue tear-down ('drop all' rx-mode, clear vlans, clear macs,
1252 static void bnx2x_vfop_qdown(struct bnx2x *bp, struct bnx2x_virtf *vf)
1254 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1255 int qid = vfop->args.qx.qid;
1256 enum bnx2x_vfop_qteardown_state state = vfop->state;
1257 struct bnx2x_vfop_cmd cmd;
1262 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1264 cmd.done = bnx2x_vfop_qdown;
1268 case BNX2X_VFOP_QTEARDOWN_RXMODE:
1270 vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_VLAN;
1271 vfop->rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, qid, 0);
1276 case BNX2X_VFOP_QTEARDOWN_CLR_VLAN:
1277 /* vlan-clear-all: don't consume credit */
1278 vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_MAC;
1279 vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, false);
1284 case BNX2X_VFOP_QTEARDOWN_CLR_MAC:
1285 /* mac-clear-all: consume credit */
1286 vfop->state = BNX2X_VFOP_QTEARDOWN_QDTOR;
1287 vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid, false);
1292 case BNX2X_VFOP_QTEARDOWN_QDTOR:
1293 /* run the queue destruction flow */
1294 DP(BNX2X_MSG_IOV, "case: BNX2X_VFOP_QTEARDOWN_QDTOR\n");
1295 vfop->state = BNX2X_VFOP_QTEARDOWN_DONE;
1296 DP(BNX2X_MSG_IOV, "new state: BNX2X_VFOP_QTEARDOWN_DONE\n");
1297 vfop->rc = bnx2x_vfop_qdtor_cmd(bp, vf, &cmd, qid);
1298 DP(BNX2X_MSG_IOV, "returned from cmd\n");
1303 BNX2X_ERR("QTEARDOWN[%d:%d] error: rc %d\n",
1304 vf->abs_vfid, qid, vfop->rc);
1306 case BNX2X_VFOP_QTEARDOWN_DONE:
1307 bnx2x_vfop_end(bp, vf, vfop);
1310 bnx2x_vfop_default(state);
1314 int bnx2x_vfop_qdown_cmd(struct bnx2x *bp,
1315 struct bnx2x_virtf *vf,
1316 struct bnx2x_vfop_cmd *cmd,
1319 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1322 vfop->args.qx.qid = qid;
1323 bnx2x_vfop_opset(BNX2X_VFOP_QTEARDOWN_RXMODE,
1324 bnx2x_vfop_qdown, cmd->done);
1325 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdown,
1332 /* VF enable primitives
1333 * when pretend is required the caller is responsible
1334 * for calling pretend prior to calling these routines
1337 /* called only on E1H or E2.
1338 * When pretending to be PF, the pretend value is the function number 0...7
1339 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
1342 int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
1346 if (CHIP_IS_E1H(bp) && pretend_func_val > E1H_FUNC_MAX)
1349 /* get my own pretend register */
1350 pretend_reg = bnx2x_get_pretend_reg(bp);
1351 REG_WR(bp, pretend_reg, pretend_func_val);
1352 REG_RD(bp, pretend_reg);
1356 /* internal vf enable - until vf is enabled internally all transactions
1357 * are blocked. this routine should always be called last with pretend.
1359 static void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable)
1361 REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0);
1364 /* clears vf error in all semi blocks */
1365 static void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid)
1367 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid);
1368 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid);
1369 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid);
1370 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid);
1373 static void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid)
1375 u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5;
1376 u32 was_err_reg = 0;
1378 switch (was_err_group) {
1380 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR;
1383 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR;
1386 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR;
1389 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR;
1392 REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f));
1395 static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
1400 /* Set VF masks and configuration - pretend */
1401 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1403 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
1404 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
1405 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
1406 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
1407 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
1408 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
1410 val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
1411 val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN);
1412 if (vf->cfg_flags & VF_CFG_INT_SIMD)
1413 val |= IGU_VF_CONF_SINGLE_ISR_EN;
1414 val &= ~IGU_VF_CONF_PARENT_MASK;
1415 val |= BP_FUNC(bp) << IGU_VF_CONF_PARENT_SHIFT; /* parent PF */
1416 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
1419 "value in IGU_REG_VF_CONFIGURATION of vf %d after write %x\n",
1420 vf->abs_vfid, REG_RD(bp, IGU_REG_VF_CONFIGURATION));
1422 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1424 /* iterate over all queues, clear sb consumer */
1425 for (i = 0; i < vf_sb_count(vf); i++) {
1426 u8 igu_sb_id = vf_igu_sb(vf, i);
1428 /* zero prod memory */
1429 REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0);
1431 /* clear sb state machine */
1432 bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id,
1435 /* disable + update */
1436 bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0,
1437 IGU_INT_DISABLE, 1);
1441 void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid)
1443 /* set the VF-PF association in the FW */
1444 storm_memset_vf_to_pf(bp, FW_VF_HANDLE(abs_vfid), BP_FUNC(bp));
1445 storm_memset_func_en(bp, FW_VF_HANDLE(abs_vfid), 1);
1447 /* clear vf errors*/
1448 bnx2x_vf_semi_clear_err(bp, abs_vfid);
1449 bnx2x_vf_pglue_clear_err(bp, abs_vfid);
1451 /* internal vf-enable - pretend */
1452 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid));
1453 DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid);
1454 bnx2x_vf_enable_internal(bp, true);
1455 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1458 static void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf)
1460 /* Reset vf in IGU interrupts are still disabled */
1461 bnx2x_vf_igu_reset(bp, vf);
1463 /* pretend to enable the vf with the PBF */
1464 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1465 REG_WR(bp, PBF_REG_DISABLE_VF, 0);
1466 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1469 static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
1471 struct pci_dev *dev;
1472 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
1477 dev = pci_get_bus_and_slot(vf->bus, vf->devfn);
1479 return bnx2x_is_pcie_pending(dev);
1482 BNX2X_ERR("Unknown device\n");
1486 int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid)
1491 /* Verify no pending pci transactions */
1492 if (bnx2x_vf_is_pcie_pending(bp, abs_vfid))
1493 BNX2X_ERR("PCIE Transactions still pending\n");
1498 /* must be called after the number of PF queues and the number of VFs are
1502 bnx2x_iov_static_resc(struct bnx2x *bp, struct vf_pf_resc_request *resc)
1506 /* will be set only during VF-ACQUIRE */
1510 /* no credit calculcis for macs (just yet) */
1511 resc->num_mac_filters = 1;
1513 /* divvy up vlan rules */
1514 vlan_count = bp->vlans_pool.check(&bp->vlans_pool);
1515 vlan_count = 1 << ilog2(vlan_count);
1516 resc->num_vlan_filters = vlan_count / BNX2X_NR_VIRTFN(bp);
1518 /* no real limitation */
1519 resc->num_mc_filters = 0;
1521 /* num_sbs already set */
1525 static void bnx2x_vf_free_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
1527 /* reset the state variables */
1528 bnx2x_iov_static_resc(bp, &vf->alloc_resc);
1529 vf->state = VF_FREE;
1532 static void bnx2x_vf_flr_clnup_hw(struct bnx2x *bp, struct bnx2x_virtf *vf)
1534 u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
1536 /* DQ usage counter */
1537 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
1538 bnx2x_flr_clnup_poll_hw_counter(bp, DORQ_REG_VF_USAGE_CNT,
1539 "DQ VF usage counter timed out",
1541 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1543 /* FW cleanup command - poll for the results */
1544 if (bnx2x_send_final_clnup(bp, (u8)FW_VF_HANDLE(vf->abs_vfid),
1546 BNX2X_ERR("VF[%d] Final cleanup timed-out\n", vf->abs_vfid);
1548 /* verify TX hw is flushed */
1549 bnx2x_tx_hw_flushed(bp, poll_cnt);
1552 static void bnx2x_vfop_flr(struct bnx2x *bp, struct bnx2x_virtf *vf)
1554 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1555 struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
1556 enum bnx2x_vfop_flr_state state = vfop->state;
1557 struct bnx2x_vfop_cmd cmd = {
1558 .done = bnx2x_vfop_flr,
1565 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
1568 case BNX2X_VFOP_FLR_QUEUES:
1569 /* the cleanup operations are valid if and only if the VF
1570 * was first acquired.
1572 if (++(qx->qid) < vf_rxq_count(vf)) {
1573 vfop->rc = bnx2x_vfop_qflr_cmd(bp, vf, &cmd,
1579 /* remove multicasts */
1580 vfop->state = BNX2X_VFOP_FLR_HW;
1581 vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL,
1586 case BNX2X_VFOP_FLR_HW:
1588 /* dispatch final cleanup and wait for HW queues to flush */
1589 bnx2x_vf_flr_clnup_hw(bp, vf);
1591 /* release VF resources */
1592 bnx2x_vf_free_resc(bp, vf);
1594 /* re-open the mailbox */
1595 bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
1599 bnx2x_vfop_default(state);
1602 BNX2X_ERR("VF[%d] FLR error: rc %d\n", vf->abs_vfid, vfop->rc);
1604 vf->flr_clnup_stage = VF_FLR_ACK;
1605 bnx2x_vfop_end(bp, vf, vfop);
1606 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
1609 static int bnx2x_vfop_flr_cmd(struct bnx2x *bp,
1610 struct bnx2x_virtf *vf,
1611 vfop_handler_t done)
1613 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1615 vfop->args.qx.qid = -1; /* loop */
1616 bnx2x_vfop_opset(BNX2X_VFOP_FLR_QUEUES,
1617 bnx2x_vfop_flr, done);
1618 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_flr, false);
1623 static void bnx2x_vf_flr_clnup(struct bnx2x *bp, struct bnx2x_virtf *prev_vf)
1625 int i = prev_vf ? prev_vf->index + 1 : 0;
1626 struct bnx2x_virtf *vf;
1628 /* find next VF to cleanup */
1631 i < BNX2X_NR_VIRTFN(bp) &&
1632 (bnx2x_vf(bp, i, state) != VF_RESET ||
1633 bnx2x_vf(bp, i, flr_clnup_stage) != VF_FLR_CLN);
1637 DP(BNX2X_MSG_IOV, "next vf to cleanup: %d. num of vfs: %d\n", i,
1638 BNX2X_NR_VIRTFN(bp));
1640 if (i < BNX2X_NR_VIRTFN(bp)) {
1643 /* lock the vf pf channel */
1644 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
1646 /* invoke the VF FLR SM */
1647 if (bnx2x_vfop_flr_cmd(bp, vf, bnx2x_vf_flr_clnup)) {
1648 BNX2X_ERR("VF[%d]: FLR cleanup failed -ENOMEM\n",
1651 /* mark the VF to be ACKED and continue */
1652 vf->flr_clnup_stage = VF_FLR_ACK;
1653 goto next_vf_to_clean;
1658 /* we are done, update vf records */
1659 for_each_vf(bp, i) {
1662 if (vf->flr_clnup_stage != VF_FLR_ACK)
1665 vf->flr_clnup_stage = VF_FLR_EPILOG;
1668 /* Acknowledge the handled VFs.
1669 * we are acknowledge all the vfs which an flr was requested for, even
1670 * if amongst them there are such that we never opened, since the mcp
1671 * will interrupt us immediately again if we only ack some of the bits,
1672 * resulting in an endless loop. This can happen for example in KVM
1673 * where an 'all ones' flr request is sometimes given by hyper visor
1675 DP(BNX2X_MSG_MCP, "DRV_STATUS_VF_DISABLED ACK for vfs 0x%x 0x%x\n",
1676 bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
1677 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1678 SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i],
1679 bp->vfdb->flrd_vfs[i]);
1681 bnx2x_fw_command(bp, DRV_MSG_CODE_VF_DISABLED_DONE, 0);
1683 /* clear the acked bits - better yet if the MCP implemented
1684 * write to clear semantics
1686 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1687 SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 0);
1690 void bnx2x_vf_handle_flr_event(struct bnx2x *bp)
1694 /* Read FLR'd VFs */
1695 for (i = 0; i < FLRD_VFS_DWORDS; i++)
1696 bp->vfdb->flrd_vfs[i] = SHMEM2_RD(bp, mcp_vf_disabled[i]);
1699 "DRV_STATUS_VF_DISABLED received for vfs 0x%x 0x%x\n",
1700 bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
1702 for_each_vf(bp, i) {
1703 struct bnx2x_virtf *vf = BP_VF(bp, i);
1706 if (vf->abs_vfid < 32)
1707 reset = bp->vfdb->flrd_vfs[0] & (1 << vf->abs_vfid);
1709 reset = bp->vfdb->flrd_vfs[1] &
1710 (1 << (vf->abs_vfid - 32));
1713 /* set as reset and ready for cleanup */
1714 vf->state = VF_RESET;
1715 vf->flr_clnup_stage = VF_FLR_CLN;
1718 "Initiating Final cleanup for VF %d\n",
1723 /* do the FLR cleanup for all marked VFs*/
1724 bnx2x_vf_flr_clnup(bp, NULL);
1727 /* IOV global initialization routines */
1728 void bnx2x_iov_init_dq(struct bnx2x *bp)
1733 /* Set the DQ such that the CID reflect the abs_vfid */
1734 REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0);
1735 REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS));
1737 /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to
1740 REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID);
1742 /* The VF window size is the log2 of the max number of CIDs per VF */
1743 REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND);
1745 /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match
1746 * the Pf doorbell size although the 2 are independent.
1748 REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST,
1749 BNX2X_DB_SHIFT - BNX2X_DB_MIN_SHIFT);
1751 /* No security checks for now -
1752 * configure single rule (out of 16) mask = 0x1, value = 0x0,
1753 * CID range 0 - 0x1ffff
1755 REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1);
1756 REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0);
1757 REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0);
1758 REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff);
1760 /* set the number of VF alllowed doorbells to the full DQ range */
1761 REG_WR(bp, DORQ_REG_VF_NORM_MAX_CID_COUNT, 0x20000);
1763 /* set the VF doorbell threshold */
1764 REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 4);
1767 void bnx2x_iov_init_dmae(struct bnx2x *bp)
1769 DP(BNX2X_MSG_IOV, "SRIOV is %s\n", IS_SRIOV(bp) ? "ON" : "OFF");
1773 REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0);
1776 static int bnx2x_vf_bus(struct bnx2x *bp, int vfid)
1778 struct pci_dev *dev = bp->pdev;
1779 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1781 return dev->bus->number + ((dev->devfn + iov->offset +
1782 iov->stride * vfid) >> 8);
1785 static int bnx2x_vf_devfn(struct bnx2x *bp, int vfid)
1787 struct pci_dev *dev = bp->pdev;
1788 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1790 return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff;
1793 static void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
1796 struct pci_dev *dev = bp->pdev;
1797 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
1799 for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
1800 u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i);
1801 u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i);
1803 do_div(size, iov->total);
1804 vf->bars[n].bar = start + size * vf->abs_vfid;
1805 vf->bars[n].size = size;
1809 static int bnx2x_ari_enabled(struct pci_dev *dev)
1811 return dev->bus->self && dev->bus->self->ari_enabled;
1815 bnx2x_get_vf_igu_cam_info(struct bnx2x *bp)
1821 /* IGU in normal mode - read CAM */
1822 for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) {
1823 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4);
1824 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
1826 fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID);
1827 if (!(fid & IGU_FID_ENCODE_IS_PF))
1828 bnx2x_vf_set_igu_info(bp, sb_id,
1829 (fid & IGU_FID_VF_NUM_MASK));
1831 DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n",
1832 ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"),
1833 ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) :
1834 (fid & IGU_FID_VF_NUM_MASK)), sb_id,
1835 GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR));
1839 static void __bnx2x_iov_free_vfdb(struct bnx2x *bp)
1842 kfree(bp->vfdb->vfqs);
1843 kfree(bp->vfdb->vfs);
1849 static int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
1852 struct pci_dev *dev = bp->pdev;
1854 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
1856 BNX2X_ERR("failed to find SRIOV capability in device\n");
1861 DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos);
1862 pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
1863 pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total);
1864 pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial);
1865 pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
1866 pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
1867 pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
1868 pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
1869 pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
1874 static int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
1878 /* read the SRIOV capability structure
1879 * The fields can be read via configuration read or
1880 * directly from the device (starting at offset PCICFG_OFFSET)
1882 if (bnx2x_sriov_pci_cfg_info(bp, iov))
1885 /* get the number of SRIOV bars */
1888 /* read the first_vfid */
1889 val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF);
1890 iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK)
1891 * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp));
1894 "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",
1896 iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total,
1897 iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
1902 static u8 bnx2x_iov_get_max_queue_count(struct bnx2x *bp)
1909 queue_count += bnx2x_vf(bp, i, alloc_resc.num_sbs);
1914 /* must be called after PF bars are mapped */
1915 int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
1919 struct bnx2x_sriov *iov;
1920 struct pci_dev *dev = bp->pdev;
1928 /* verify sriov capability is present in configuration space */
1929 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV))
1932 /* verify chip revision */
1933 if (CHIP_IS_E1x(bp))
1936 /* check if SRIOV support is turned off */
1940 /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */
1941 if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) {
1942 BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n",
1943 BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID);
1947 /* SRIOV can be enabled only with MSIX */
1948 if (int_mode_param == BNX2X_INT_MODE_MSI ||
1949 int_mode_param == BNX2X_INT_MODE_INTX)
1950 BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n");
1953 /* verify ari is enabled */
1954 if (!bnx2x_ari_enabled(bp->pdev)) {
1955 BNX2X_ERR("ARI not supported, SRIOV can not be enabled\n");
1959 /* verify igu is in normal mode */
1960 if (CHIP_INT_MODE_IS_BC(bp)) {
1961 BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n");
1965 /* allocate the vfs database */
1966 bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL);
1968 BNX2X_ERR("failed to allocate vf database\n");
1973 /* get the sriov info - Linux already collected all the pertinent
1974 * information, however the sriov structure is for the private use
1975 * of the pci module. Also we want this information regardless
1976 * of the hyper-visor.
1978 iov = &(bp->vfdb->sriov);
1979 err = bnx2x_sriov_info(bp, iov);
1983 /* SR-IOV capability was enabled but there are no VFs*/
1984 if (iov->total == 0)
1987 /* calculate the actual number of VFs */
1988 iov->nr_virtfn = min_t(u16, iov->total, (u16)num_vfs_param);
1990 /* allocate the vf array */
1991 bp->vfdb->vfs = kzalloc(sizeof(struct bnx2x_virtf) *
1992 BNX2X_NR_VIRTFN(bp), GFP_KERNEL);
1993 if (!bp->vfdb->vfs) {
1994 BNX2X_ERR("failed to allocate vf array\n");
1999 /* Initial VF init - index and abs_vfid - nr_virtfn must be set */
2000 for_each_vf(bp, i) {
2001 bnx2x_vf(bp, i, index) = i;
2002 bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i;
2003 bnx2x_vf(bp, i, state) = VF_FREE;
2004 INIT_LIST_HEAD(&bnx2x_vf(bp, i, op_list_head));
2005 mutex_init(&bnx2x_vf(bp, i, op_mutex));
2006 bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE;
2009 /* re-read the IGU CAM for VFs - index and abs_vfid must be set */
2010 bnx2x_get_vf_igu_cam_info(bp);
2012 /* get the total queue count and allocate the global queue arrays */
2013 qcount = bnx2x_iov_get_max_queue_count(bp);
2015 /* allocate the queue arrays for all VFs */
2016 bp->vfdb->vfqs = kzalloc(qcount * sizeof(struct bnx2x_vf_queue),
2018 if (!bp->vfdb->vfqs) {
2019 BNX2X_ERR("failed to allocate vf queue array\n");
2026 DP(BNX2X_MSG_IOV, "Failed err=%d\n", err);
2027 __bnx2x_iov_free_vfdb(bp);
2031 void bnx2x_iov_remove_one(struct bnx2x *bp)
2033 /* if SRIOV is not enabled there's nothing to do */
2037 /* free vf database */
2038 __bnx2x_iov_free_vfdb(bp);
2041 void bnx2x_iov_free_mem(struct bnx2x *bp)
2048 /* free vfs hw contexts */
2049 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2050 struct hw_dma *cxt = &bp->vfdb->context[i];
2051 BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size);
2054 BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr,
2055 BP_VFDB(bp)->sp_dma.mapping,
2056 BP_VFDB(bp)->sp_dma.size);
2058 BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr,
2059 BP_VF_MBX_DMA(bp)->mapping,
2060 BP_VF_MBX_DMA(bp)->size);
2062 BNX2X_PCI_FREE(BP_VF_BULLETIN_DMA(bp)->addr,
2063 BP_VF_BULLETIN_DMA(bp)->mapping,
2064 BP_VF_BULLETIN_DMA(bp)->size);
2067 int bnx2x_iov_alloc_mem(struct bnx2x *bp)
2075 /* allocate vfs hw contexts */
2076 tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) *
2077 BNX2X_CIDS_PER_VF * sizeof(union cdu_context);
2079 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2080 struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
2081 cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
2084 BNX2X_PCI_ALLOC(cxt->addr, &cxt->mapping, cxt->size);
2089 tot_size -= cxt->size;
2092 /* allocate vfs ramrods dma memory - client_init and set_mac */
2093 tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
2094 BNX2X_PCI_ALLOC(BP_VFDB(bp)->sp_dma.addr, &BP_VFDB(bp)->sp_dma.mapping,
2096 BP_VFDB(bp)->sp_dma.size = tot_size;
2098 /* allocate mailboxes */
2099 tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
2100 BNX2X_PCI_ALLOC(BP_VF_MBX_DMA(bp)->addr, &BP_VF_MBX_DMA(bp)->mapping,
2102 BP_VF_MBX_DMA(bp)->size = tot_size;
2104 /* allocate local bulletin boards */
2105 tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE;
2106 BNX2X_PCI_ALLOC(BP_VF_BULLETIN_DMA(bp)->addr,
2107 &BP_VF_BULLETIN_DMA(bp)->mapping, tot_size);
2108 BP_VF_BULLETIN_DMA(bp)->size = tot_size;
2116 static void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
2117 struct bnx2x_vf_queue *q)
2119 u8 cl_id = vfq_cl_id(vf, q);
2120 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
2121 unsigned long q_type = 0;
2123 set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
2124 set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
2126 /* Queue State object */
2127 bnx2x_init_queue_obj(bp, &q->sp_obj,
2128 cl_id, &q->cid, 1, func_id,
2129 bnx2x_vf_sp(bp, vf, q_data),
2130 bnx2x_vf_sp_map(bp, vf, q_data),
2134 "initialized vf %d's queue object. func id set to %d\n",
2135 vf->abs_vfid, q->sp_obj.func_id);
2137 /* mac/vlan objects are per queue, but only those
2138 * that belong to the leading queue are initialized
2140 if (vfq_is_leading(q)) {
2142 bnx2x_init_mac_obj(bp, &q->mac_obj,
2143 cl_id, q->cid, func_id,
2144 bnx2x_vf_sp(bp, vf, mac_rdata),
2145 bnx2x_vf_sp_map(bp, vf, mac_rdata),
2146 BNX2X_FILTER_MAC_PENDING,
2148 BNX2X_OBJ_TYPE_RX_TX,
2151 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
2152 cl_id, q->cid, func_id,
2153 bnx2x_vf_sp(bp, vf, vlan_rdata),
2154 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
2155 BNX2X_FILTER_VLAN_PENDING,
2157 BNX2X_OBJ_TYPE_RX_TX,
2161 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
2162 q->cid, func_id, func_id,
2163 bnx2x_vf_sp(bp, vf, mcast_rdata),
2164 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
2165 BNX2X_FILTER_MCAST_PENDING,
2167 BNX2X_OBJ_TYPE_RX_TX);
2169 vf->leading_rss = cl_id;
2173 /* called by bnx2x_nic_load */
2174 int bnx2x_iov_nic_init(struct bnx2x *bp)
2176 int vfid, qcount, i;
2178 if (!IS_SRIOV(bp)) {
2179 DP(BNX2X_MSG_IOV, "vfdb was not allocated\n");
2183 DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn);
2185 /* initialize vf database */
2186 for_each_vf(bp, vfid) {
2187 struct bnx2x_virtf *vf = BP_VF(bp, vfid);
2189 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) *
2192 union cdu_context *base_cxt = (union cdu_context *)
2193 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
2194 (base_vf_cid & (ILT_PAGE_CIDS-1));
2197 "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n",
2198 vf->abs_vfid, vf_sb_count(vf), base_vf_cid,
2199 BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt);
2201 /* init statically provisioned resources */
2202 bnx2x_iov_static_resc(bp, &vf->alloc_resc);
2204 /* queues are initialized during VF-ACQUIRE */
2206 /* reserve the vf vlan credit */
2207 bp->vlans_pool.get(&bp->vlans_pool, vf_vlan_rules_cnt(vf));
2209 vf->filter_state = 0;
2210 vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id);
2212 /* init mcast object - This object will be re-initialized
2213 * during VF-ACQUIRE with the proper cl_id and cid.
2214 * It needs to be initialized here so that it can be safely
2215 * handled by a subsequent FLR flow.
2217 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF,
2219 bnx2x_vf_sp(bp, vf, mcast_rdata),
2220 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
2221 BNX2X_FILTER_MCAST_PENDING,
2223 BNX2X_OBJ_TYPE_RX_TX);
2225 /* set the mailbox message addresses */
2226 BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *)
2227 (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid *
2228 MBX_MSG_ALIGNED_SIZE);
2230 BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping +
2231 vfid * MBX_MSG_ALIGNED_SIZE;
2233 /* Enable vf mailbox */
2234 bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
2239 for_each_vf(bp, i) {
2240 struct bnx2x_virtf *vf = BP_VF(bp, i);
2242 /* fill in the BDF and bars */
2243 vf->bus = bnx2x_vf_bus(bp, i);
2244 vf->devfn = bnx2x_vf_devfn(bp, i);
2245 bnx2x_vf_set_bars(bp, vf);
2248 "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n",
2249 vf->abs_vfid, vf->bus, vf->devfn,
2250 (unsigned)vf->bars[0].bar, vf->bars[0].size,
2251 (unsigned)vf->bars[1].bar, vf->bars[1].size,
2252 (unsigned)vf->bars[2].bar, vf->bars[2].size);
2254 /* set local queue arrays */
2255 vf->vfqs = &bp->vfdb->vfqs[qcount];
2256 qcount += bnx2x_vf(bp, i, alloc_resc.num_sbs);
2262 /* called by bnx2x_chip_cleanup */
2263 int bnx2x_iov_chip_cleanup(struct bnx2x *bp)
2270 /* release all the VFs */
2272 bnx2x_vf_release(bp, BP_VF(bp, i), true); /* blocking */
2277 /* called by bnx2x_init_hw_func, returns the next ilt line */
2278 int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line)
2281 struct bnx2x_ilt *ilt = BP_ILT(bp);
2286 /* set vfs ilt lines */
2287 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
2288 struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i);
2290 ilt->lines[line+i].page = hw_cxt->addr;
2291 ilt->lines[line+i].page_mapping = hw_cxt->mapping;
2292 ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */
2297 static u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid)
2299 return ((cid >= BNX2X_FIRST_VF_CID) &&
2300 ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS));
2304 void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
2305 struct bnx2x_vf_queue *vfq,
2306 union event_ring_elem *elem)
2308 unsigned long ramrod_flags = 0;
2311 /* Always push next commands out, don't wait here */
2312 set_bit(RAMROD_CONT, &ramrod_flags);
2314 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
2315 case BNX2X_FILTER_MAC_PENDING:
2316 rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
2319 case BNX2X_FILTER_VLAN_PENDING:
2320 rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem,
2324 BNX2X_ERR("Unsupported classification command: %d\n",
2325 elem->message.data.eth_event.echo);
2329 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
2331 DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n");
2335 void bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp,
2336 struct bnx2x_virtf *vf)
2338 struct bnx2x_mcast_ramrod_params rparam = {NULL};
2341 rparam.mcast_obj = &vf->mcast_obj;
2342 vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw);
2344 /* If there are pending mcast commands - send them */
2345 if (vf->mcast_obj.check_pending(&vf->mcast_obj)) {
2346 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
2348 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
2354 void bnx2x_vf_handle_filters_eqe(struct bnx2x *bp,
2355 struct bnx2x_virtf *vf)
2357 smp_mb__before_clear_bit();
2358 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
2359 smp_mb__after_clear_bit();
2362 int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
2364 struct bnx2x_virtf *vf;
2365 int qidx = 0, abs_vfid;
2372 /* first get the cid - the only events we handle here are cfc-delete
2373 * and set-mac completion
2375 opcode = elem->message.opcode;
2378 case EVENT_RING_OPCODE_CFC_DEL:
2379 cid = SW_CID((__force __le32)
2380 elem->message.data.cfc_del_event.cid);
2381 DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
2383 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
2384 case EVENT_RING_OPCODE_MULTICAST_RULES:
2385 case EVENT_RING_OPCODE_FILTERS_RULES:
2386 cid = (elem->message.data.eth_event.echo &
2388 DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
2390 case EVENT_RING_OPCODE_VF_FLR:
2391 abs_vfid = elem->message.data.vf_flr_event.vf_id;
2392 DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n",
2395 case EVENT_RING_OPCODE_MALICIOUS_VF:
2396 abs_vfid = elem->message.data.malicious_vf_event.vf_id;
2397 DP(BNX2X_MSG_IOV, "Got VF MALICIOUS notification abs_vfid=%d\n",
2404 /* check if the cid is the VF range */
2405 if (!bnx2x_iov_is_vf_cid(bp, cid)) {
2406 DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid);
2410 /* extract vf and rxq index from vf_cid - relies on the following:
2411 * 1. vfid on cid reflects the true abs_vfid
2412 * 2. the max number of VFs (per path) is 64
2414 qidx = cid & ((1 << BNX2X_VF_CID_WND)-1);
2415 abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
2417 vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
2420 BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n",
2426 case EVENT_RING_OPCODE_CFC_DEL:
2427 DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n",
2428 vf->abs_vfid, qidx);
2429 vfq_get(vf, qidx)->sp_obj.complete_cmd(bp,
2432 BNX2X_Q_CMD_CFC_DEL);
2434 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
2435 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n",
2436 vf->abs_vfid, qidx);
2437 bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem);
2439 case EVENT_RING_OPCODE_MULTICAST_RULES:
2440 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n",
2441 vf->abs_vfid, qidx);
2442 bnx2x_vf_handle_mcast_eqe(bp, vf);
2444 case EVENT_RING_OPCODE_FILTERS_RULES:
2445 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n",
2446 vf->abs_vfid, qidx);
2447 bnx2x_vf_handle_filters_eqe(bp, vf);
2449 case EVENT_RING_OPCODE_VF_FLR:
2450 DP(BNX2X_MSG_IOV, "got VF [%d] FLR notification\n",
2452 /* Do nothing for now */
2454 case EVENT_RING_OPCODE_MALICIOUS_VF:
2455 DP(BNX2X_MSG_IOV, "got VF [%d] MALICIOUS notification\n",
2457 /* Do nothing for now */
2460 /* SRIOV: reschedule any 'in_progress' operations */
2461 bnx2x_iov_sp_event(bp, cid, false);
2466 static struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid)
2468 /* extract the vf from vf_cid - relies on the following:
2469 * 1. vfid on cid reflects the true abs_vfid
2470 * 2. the max number of VFs (per path) is 64
2472 int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
2473 return bnx2x_vf_by_abs_fid(bp, abs_vfid);
2476 void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
2477 struct bnx2x_queue_sp_obj **q_obj)
2479 struct bnx2x_virtf *vf;
2484 vf = bnx2x_vf_by_cid(bp, vf_cid);
2487 /* extract queue index from vf_cid - relies on the following:
2488 * 1. vfid on cid reflects the true abs_vfid
2489 * 2. the max number of VFs (per path) is 64
2491 int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1);
2492 *q_obj = &bnx2x_vfq(vf, q_index, sp_obj);
2494 BNX2X_ERR("No vf matching cid %d\n", vf_cid);
2498 void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work)
2500 struct bnx2x_virtf *vf;
2502 /* check if the cid is the VF range */
2503 if (!IS_SRIOV(bp) || !bnx2x_iov_is_vf_cid(bp, vf_cid))
2506 vf = bnx2x_vf_by_cid(bp, vf_cid);
2508 /* set in_progress flag */
2509 atomic_set(&vf->op_in_progress, 1);
2511 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
2515 void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
2518 int first_queue_query_index, num_queues_req;
2519 dma_addr_t cur_data_offset;
2520 struct stats_query_entry *cur_query_entry;
2522 bool is_fcoe = false;
2530 /* fcoe adds one global request and one queue request */
2531 num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe;
2532 first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX -
2536 "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",
2537 BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index,
2538 first_queue_query_index + num_queues_req);
2540 cur_data_offset = bp->fw_stats_data_mapping +
2541 offsetof(struct bnx2x_fw_stats_data, queue_stats) +
2542 num_queues_req * sizeof(struct per_queue_stats);
2544 cur_query_entry = &bp->fw_stats_req->
2545 query[first_queue_query_index + num_queues_req];
2547 for_each_vf(bp, i) {
2549 struct bnx2x_virtf *vf = BP_VF(bp, i);
2551 if (vf->state != VF_ENABLED) {
2553 "vf %d not enabled so no stats for it\n",
2558 DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid);
2559 for_each_vfq(vf, j) {
2560 struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
2562 /* collect stats fro active queues only */
2563 if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) ==
2564 BNX2X_Q_LOGICAL_STATE_STOPPED)
2567 /* create stats query entry for this queue */
2568 cur_query_entry->kind = STATS_TYPE_QUEUE;
2569 cur_query_entry->index = vfq_cl_id(vf, rxq);
2570 cur_query_entry->funcID =
2571 cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid));
2572 cur_query_entry->address.hi =
2573 cpu_to_le32(U64_HI(vf->fw_stat_map));
2574 cur_query_entry->address.lo =
2575 cpu_to_le32(U64_LO(vf->fw_stat_map));
2577 "added address %x %x for vf %d queue %d client %d\n",
2578 cur_query_entry->address.hi,
2579 cur_query_entry->address.lo, cur_query_entry->funcID,
2580 j, cur_query_entry->index);
2582 cur_data_offset += sizeof(struct per_queue_stats);
2586 bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count;
2589 void bnx2x_iov_sp_task(struct bnx2x *bp)
2595 /* Iterate over all VFs and invoke state transition for VFs with
2596 * 'in-progress' slow-path operations
2598 DP(BNX2X_MSG_IOV, "searching for pending vf operations\n");
2599 for_each_vf(bp, i) {
2600 struct bnx2x_virtf *vf = BP_VF(bp, i);
2602 if (!list_empty(&vf->op_list_head) &&
2603 atomic_read(&vf->op_in_progress)) {
2604 DP(BNX2X_MSG_IOV, "running pending op for vf %d\n", i);
2605 bnx2x_vfop_cur(bp, vf)->transition(bp, vf);
2611 struct bnx2x_virtf *__vf_from_stat_id(struct bnx2x *bp, u8 stat_id)
2614 struct bnx2x_virtf *vf = NULL;
2616 for_each_vf(bp, i) {
2618 if (stat_id >= vf->igu_base_id &&
2619 stat_id < vf->igu_base_id + vf_sb_count(vf))
2625 /* VF API helpers */
2626 static void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid,
2629 u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4;
2630 u32 val = enable ? (abs_vfid | (1 << 6)) : 0;
2632 REG_WR(bp, reg, val);
2635 static void bnx2x_vf_clr_qtbl(struct bnx2x *bp, struct bnx2x_virtf *vf)
2640 bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
2641 vfq_qzone_id(vf, vfq_get(vf, i)), false);
2644 static void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf)
2648 /* clear the VF configuration - pretend */
2649 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
2650 val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
2651 val &= ~(IGU_VF_CONF_MSI_MSIX_EN | IGU_VF_CONF_SINGLE_ISR_EN |
2652 IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_PARENT_MASK);
2653 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
2654 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
2657 u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
2659 return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
2660 BNX2X_VF_MAX_QUEUES);
2664 int bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf,
2665 struct vf_pf_resc_request *req_resc)
2667 u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
2668 u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
2670 return ((req_resc->num_rxqs <= rxq_cnt) &&
2671 (req_resc->num_txqs <= txq_cnt) &&
2672 (req_resc->num_sbs <= vf_sb_count(vf)) &&
2673 (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) &&
2674 (req_resc->num_vlan_filters <= vf_vlan_rules_cnt(vf)));
2678 int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
2679 struct vf_pf_resc_request *resc)
2681 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) *
2684 union cdu_context *base_cxt = (union cdu_context *)
2685 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
2686 (base_vf_cid & (ILT_PAGE_CIDS-1));
2689 /* if state is 'acquired' the VF was not released or FLR'd, in
2690 * this case the returned resources match the acquired already
2691 * acquired resources. Verify that the requested numbers do
2692 * not exceed the already acquired numbers.
2694 if (vf->state == VF_ACQUIRED) {
2695 DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n",
2698 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
2699 BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n",
2706 /* Otherwise vf state must be 'free' or 'reset' */
2707 if (vf->state != VF_FREE && vf->state != VF_RESET) {
2708 BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n",
2709 vf->abs_vfid, vf->state);
2713 /* static allocation:
2714 * the global maximum number are fixed per VF. fail the request if
2715 * requested number exceed these globals
2717 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
2719 "cannot fulfill vf resource request. Placing maximal available values in response\n");
2720 /* set the max resource in the vf */
2724 /* Set resources counters - 0 request means max available */
2725 vf_sb_count(vf) = resc->num_sbs;
2726 vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
2727 vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
2728 if (resc->num_mac_filters)
2729 vf_mac_rules_cnt(vf) = resc->num_mac_filters;
2730 if (resc->num_vlan_filters)
2731 vf_vlan_rules_cnt(vf) = resc->num_vlan_filters;
2734 "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n",
2735 vf_sb_count(vf), vf_rxq_count(vf),
2736 vf_txq_count(vf), vf_mac_rules_cnt(vf),
2737 vf_vlan_rules_cnt(vf));
2739 /* Initialize the queues */
2741 DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n");
2745 for_each_vfq(vf, i) {
2746 struct bnx2x_vf_queue *q = vfq_get(vf, i);
2749 DP(BNX2X_MSG_IOV, "q number %d was not allocated\n", i);
2754 q->cxt = &((base_cxt + i)->eth);
2755 q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i;
2757 DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n",
2758 vf->abs_vfid, i, q->index, q->cid, q->cxt);
2760 /* init SP objects */
2761 bnx2x_vfq_init(bp, vf, q);
2763 vf->state = VF_ACQUIRED;
2767 int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map)
2769 struct bnx2x_func_init_params func_init = {0};
2773 /* the sb resources are initialized at this point, do the
2774 * FW/HW initializations
2776 for_each_vf_sb(vf, i)
2777 bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true,
2778 vf_igu_sb(vf, i), vf_igu_sb(vf, i));
2781 if (vf->state != VF_ACQUIRED) {
2782 DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n",
2783 vf->abs_vfid, vf->state);
2786 /* FLR cleanup epilogue */
2787 if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid))
2790 /* reset IGU VF statistics: MSIX */
2791 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0);
2794 if (vf->cfg_flags & VF_CFG_STATS)
2795 flags |= (FUNC_FLG_STATS | FUNC_FLG_SPQ);
2797 if (vf->cfg_flags & VF_CFG_TPA)
2798 flags |= FUNC_FLG_TPA;
2800 if (is_vf_multi(vf))
2801 flags |= FUNC_FLG_RSS;
2803 /* function setup */
2804 func_init.func_flgs = flags;
2805 func_init.pf_id = BP_FUNC(bp);
2806 func_init.func_id = FW_VF_HANDLE(vf->abs_vfid);
2807 func_init.fw_stat_map = vf->fw_stat_map;
2808 func_init.spq_map = vf->spq_map;
2809 func_init.spq_prod = 0;
2810 bnx2x_func_init(bp, &func_init);
2813 bnx2x_vf_enable_access(bp, vf->abs_vfid);
2814 bnx2x_vf_enable_traffic(bp, vf);
2816 /* queue protection table */
2818 bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
2819 vfq_qzone_id(vf, vfq_get(vf, i)), true);
2821 vf->state = VF_ENABLED;
2823 /* update vf bulletin board */
2824 bnx2x_post_vf_bulletin(bp, vf->index);
2829 /* VFOP close (teardown the queues, delete mcasts and close HW) */
2830 static void bnx2x_vfop_close(struct bnx2x *bp, struct bnx2x_virtf *vf)
2832 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
2833 struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
2834 enum bnx2x_vfop_close_state state = vfop->state;
2835 struct bnx2x_vfop_cmd cmd = {
2836 .done = bnx2x_vfop_close,
2843 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
2846 case BNX2X_VFOP_CLOSE_QUEUES:
2848 if (++(qx->qid) < vf_rxq_count(vf)) {
2849 vfop->rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qx->qid);
2855 /* remove multicasts */
2856 vfop->state = BNX2X_VFOP_CLOSE_HW;
2857 vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL, 0, false);
2862 case BNX2X_VFOP_CLOSE_HW:
2864 /* disable the interrupts */
2865 DP(BNX2X_MSG_IOV, "disabling igu\n");
2866 bnx2x_vf_igu_disable(bp, vf);
2868 /* disable the VF */
2869 DP(BNX2X_MSG_IOV, "clearing qtbl\n");
2870 bnx2x_vf_clr_qtbl(bp, vf);
2874 bnx2x_vfop_default(state);
2877 BNX2X_ERR("VF[%d] CLOSE error: rc %d\n", vf->abs_vfid, vfop->rc);
2879 vf->state = VF_ACQUIRED;
2880 DP(BNX2X_MSG_IOV, "set state to acquired\n");
2881 bnx2x_vfop_end(bp, vf, vfop);
2884 int bnx2x_vfop_close_cmd(struct bnx2x *bp,
2885 struct bnx2x_virtf *vf,
2886 struct bnx2x_vfop_cmd *cmd)
2888 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
2890 vfop->args.qx.qid = -1; /* loop */
2891 bnx2x_vfop_opset(BNX2X_VFOP_CLOSE_QUEUES,
2892 bnx2x_vfop_close, cmd->done);
2893 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_close,
2899 /* VF release can be called either: 1. the VF was acquired but
2900 * not enabled 2. the vf was enabled or in the process of being
2903 static void bnx2x_vfop_release(struct bnx2x *bp, struct bnx2x_virtf *vf)
2905 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
2906 struct bnx2x_vfop_cmd cmd = {
2907 .done = bnx2x_vfop_release,
2911 DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
2916 DP(BNX2X_MSG_IOV, "VF[%d] STATE: %s\n", vf->abs_vfid,
2917 vf->state == VF_FREE ? "Free" :
2918 vf->state == VF_ACQUIRED ? "Acquired" :
2919 vf->state == VF_ENABLED ? "Enabled" :
2920 vf->state == VF_RESET ? "Reset" :
2923 switch (vf->state) {
2925 vfop->rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
2931 DP(BNX2X_MSG_IOV, "about to free resources\n");
2932 bnx2x_vf_free_resc(bp, vf);
2933 DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
2941 bnx2x_vfop_default(vf->state);
2944 BNX2X_ERR("VF[%d] RELEASE error: rc %d\n", vf->abs_vfid, vfop->rc);
2946 bnx2x_vfop_end(bp, vf, vfop);
2949 int bnx2x_vfop_release_cmd(struct bnx2x *bp,
2950 struct bnx2x_virtf *vf,
2951 struct bnx2x_vfop_cmd *cmd)
2953 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
2955 bnx2x_vfop_opset(-1, /* use vf->state */
2956 bnx2x_vfop_release, cmd->done);
2957 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_release,
2963 /* VF release ~ VF close + VF release-resources
2964 * Release is the ultimate SW shutdown and is called whenever an
2965 * irrecoverable error is encountered.
2967 void bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf, bool block)
2969 struct bnx2x_vfop_cmd cmd = {
2974 bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
2976 rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
2979 "VF[%d] Failed to allocate resources for release op- rc=%d\n",
2983 static inline void bnx2x_vf_get_sbdf(struct bnx2x *bp,
2984 struct bnx2x_virtf *vf, u32 *sbdf)
2986 *sbdf = vf->devfn | (vf->bus << 8);
2989 static inline void bnx2x_vf_get_bars(struct bnx2x *bp, struct bnx2x_virtf *vf,
2990 struct bnx2x_vf_bar_info *bar_info)
2994 bar_info->nr_bars = bp->vfdb->sriov.nres;
2995 for (n = 0; n < bar_info->nr_bars; n++)
2996 bar_info->bars[n] = vf->bars[n];
2999 void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
3000 enum channel_tlvs tlv)
3002 /* lock the channel */
3003 mutex_lock(&vf->op_mutex);
3005 /* record the locking op */
3006 vf->op_current = tlv;
3009 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n",
3013 void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
3014 enum channel_tlvs expected_tlv)
3016 WARN(expected_tlv != vf->op_current,
3017 "lock mismatch: expected %d found %d", expected_tlv,
3020 /* lock the channel */
3021 mutex_unlock(&vf->op_mutex);
3023 /* log the unlock */
3024 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n",
3025 vf->abs_vfid, vf->op_current);
3027 /* record the locking op */
3028 vf->op_current = CHANNEL_TLV_NONE;