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 /* VFOP operations states */
106 enum bnx2x_vfop_qctor_state {
107 BNX2X_VFOP_QCTOR_INIT,
108 BNX2X_VFOP_QCTOR_SETUP,
109 BNX2X_VFOP_QCTOR_INT_EN
112 enum bnx2x_vfop_vlan_mac_state {
113 BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
114 BNX2X_VFOP_VLAN_MAC_CLEAR,
115 BNX2X_VFOP_VLAN_MAC_CHK_DONE,
116 BNX2X_VFOP_MAC_CONFIG_LIST,
117 BNX2X_VFOP_VLAN_CONFIG_LIST,
118 BNX2X_VFOP_VLAN_CONFIG_LIST_0
121 enum bnx2x_vfop_qsetup_state {
122 BNX2X_VFOP_QSETUP_CTOR,
123 BNX2X_VFOP_QSETUP_VLAN0,
124 BNX2X_VFOP_QSETUP_DONE
127 #define bnx2x_vfop_reset_wq(vf) atomic_set(&vf->op_in_progress, 0)
129 void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
130 struct bnx2x_queue_init_params *init_params,
131 struct bnx2x_queue_setup_params *setup_params,
132 u16 q_idx, u16 sb_idx)
135 "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d",
139 init_params->tx.sb_cq_index,
140 init_params->tx.hc_rate,
142 setup_params->txq_params.traffic_type);
145 void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
146 struct bnx2x_queue_init_params *init_params,
147 struct bnx2x_queue_setup_params *setup_params,
148 u16 q_idx, u16 sb_idx)
150 struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params;
152 DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n"
153 "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n",
157 init_params->rx.sb_cq_index,
158 init_params->rx.hc_rate,
159 setup_params->gen_params.mtu,
161 rxq_params->sge_buf_sz,
162 rxq_params->max_sges_pkt,
163 rxq_params->tpa_agg_sz,
165 rxq_params->drop_flags,
166 rxq_params->cache_line_log);
169 void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
170 struct bnx2x_virtf *vf,
171 struct bnx2x_vf_queue *q,
172 struct bnx2x_vfop_qctor_params *p,
173 unsigned long q_type)
175 struct bnx2x_queue_init_params *init_p = &p->qstate.params.init;
176 struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup;
180 /* Enable host coalescing in the transition to INIT state */
181 if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags))
182 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags);
184 if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags))
185 __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags);
188 init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
189 init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
192 init_p->cxts[0] = q->cxt;
196 /* Setup-op general parameters */
197 setup_p->gen_params.spcl_id = vf->sp_cl_id;
198 setup_p->gen_params.stat_id = vfq_stat_id(vf, q);
200 /* Setup-op pause params:
201 * Nothing to do, the pause thresholds are set by default to 0 which
202 * effectively turns off the feature for this queue. We don't want
203 * one queue (VF) to interfering with another queue (another VF)
205 if (vf->cfg_flags & VF_CFG_FW_FC)
206 BNX2X_ERR("No support for pause to VFs (abs_vfid: %d)\n",
209 * collect statistics, zero statistics, local-switching, security,
210 * OV for Flex10, RSS and MCAST for leading
212 if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags))
213 __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags);
215 /* for VFs, enable tx switching, bd coherency, and mac address
218 __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags);
219 __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags);
220 __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags);
222 if (vfq_is_leading(q)) {
223 __set_bit(BNX2X_Q_FLG_LEADING_RSS, &setup_p->flags);
224 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
227 /* Setup-op rx parameters */
228 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) {
229 struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params;
231 rxq_p->cl_qzone_id = vfq_qzone_id(vf, q);
232 rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx);
233 rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid);
235 if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags))
236 rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES;
239 /* Setup-op tx parameters */
240 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) {
241 setup_p->txq_params.tss_leading_cl_id = vf->leading_rss;
242 setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
246 /* VFOP queue construction */
247 static void bnx2x_vfop_qctor(struct bnx2x *bp, struct bnx2x_virtf *vf)
249 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
250 struct bnx2x_vfop_args_qctor *args = &vfop->args.qctor;
251 struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
252 enum bnx2x_vfop_qctor_state state = vfop->state;
254 bnx2x_vfop_reset_wq(vf);
259 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
262 case BNX2X_VFOP_QCTOR_INIT:
264 /* has this queue already been opened? */
265 if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
266 BNX2X_Q_LOGICAL_STATE_ACTIVE) {
268 "Entered qctor but queue was already up. Aborting gracefully\n");
273 vfop->state = BNX2X_VFOP_QCTOR_SETUP;
275 q_params->cmd = BNX2X_Q_CMD_INIT;
276 vfop->rc = bnx2x_queue_state_change(bp, q_params);
278 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
280 case BNX2X_VFOP_QCTOR_SETUP:
282 vfop->state = BNX2X_VFOP_QCTOR_INT_EN;
284 /* copy pre-prepared setup params to the queue-state params */
285 vfop->op_p->qctor.qstate.params.setup =
286 vfop->op_p->qctor.prep_qsetup;
288 q_params->cmd = BNX2X_Q_CMD_SETUP;
289 vfop->rc = bnx2x_queue_state_change(bp, q_params);
291 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
293 case BNX2X_VFOP_QCTOR_INT_EN:
295 /* enable interrupts */
296 bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, args->sb_idx),
297 USTORM_ID, 0, IGU_INT_ENABLE, 0);
300 bnx2x_vfop_default(state);
303 BNX2X_ERR("QCTOR[%d:%d] error: cmd %d, rc %d\n",
304 vf->abs_vfid, args->qid, q_params->cmd, vfop->rc);
306 bnx2x_vfop_end(bp, vf, vfop);
311 static int bnx2x_vfop_qctor_cmd(struct bnx2x *bp,
312 struct bnx2x_virtf *vf,
313 struct bnx2x_vfop_cmd *cmd,
316 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
319 vf->op_params.qctor.qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
321 vfop->args.qctor.qid = qid;
322 vfop->args.qctor.sb_idx = bnx2x_vfq(vf, qid, sb_idx);
324 bnx2x_vfop_opset(BNX2X_VFOP_QCTOR_INIT,
325 bnx2x_vfop_qctor, cmd->done);
326 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qctor,
333 bnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid)
335 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
337 if (!vf_sb_count(vf))
338 vf->igu_base_id = igu_sb_id;
343 /* VFOP MAC/VLAN helpers */
344 static inline void bnx2x_vfop_credit(struct bnx2x *bp,
345 struct bnx2x_vfop *vfop,
346 struct bnx2x_vlan_mac_obj *obj)
348 struct bnx2x_vfop_args_filters *args = &vfop->args.filters;
350 /* update credit only if there is no error
351 * and a valid credit counter
353 if (!vfop->rc && args->credit) {
355 struct list_head *pos;
357 list_for_each(pos, &obj->head)
360 atomic_set(args->credit, cnt);
364 static int bnx2x_vfop_set_user_req(struct bnx2x *bp,
365 struct bnx2x_vfop_filter *pos,
366 struct bnx2x_vlan_mac_data *user_req)
368 user_req->cmd = pos->add ? BNX2X_VLAN_MAC_ADD :
372 case BNX2X_VFOP_FILTER_MAC:
373 memcpy(user_req->u.mac.mac, pos->mac, ETH_ALEN);
375 case BNX2X_VFOP_FILTER_VLAN:
376 user_req->u.vlan.vlan = pos->vid;
379 BNX2X_ERR("Invalid filter type, skipping\n");
386 bnx2x_vfop_config_vlan0(struct bnx2x *bp,
387 struct bnx2x_vlan_mac_ramrod_params *vlan_mac,
392 vlan_mac->user_req.cmd = add ? BNX2X_VLAN_MAC_ADD :
394 vlan_mac->user_req.u.vlan.vlan = 0;
396 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
402 static int bnx2x_vfop_config_list(struct bnx2x *bp,
403 struct bnx2x_vfop_filters *filters,
404 struct bnx2x_vlan_mac_ramrod_params *vlan_mac)
406 struct bnx2x_vfop_filter *pos, *tmp;
407 struct list_head rollback_list, *filters_list = &filters->head;
408 struct bnx2x_vlan_mac_data *user_req = &vlan_mac->user_req;
411 INIT_LIST_HEAD(&rollback_list);
413 list_for_each_entry_safe(pos, tmp, filters_list, link) {
414 if (bnx2x_vfop_set_user_req(bp, pos, user_req))
417 rc = bnx2x_config_vlan_mac(bp, vlan_mac);
419 cnt += pos->add ? 1 : -1;
420 list_del(&pos->link);
421 list_add(&pos->link, &rollback_list);
423 } else if (rc == -EEXIST) {
426 BNX2X_ERR("Failed to add a new vlan_mac command\n");
431 /* rollback if error or too many rules added */
432 if (rc || cnt > filters->add_cnt) {
433 BNX2X_ERR("error or too many rules added. Performing rollback\n");
434 list_for_each_entry_safe(pos, tmp, &rollback_list, link) {
435 pos->add = !pos->add; /* reverse op */
436 bnx2x_vfop_set_user_req(bp, pos, user_req);
437 bnx2x_config_vlan_mac(bp, vlan_mac);
438 list_del(&pos->link);
444 filters->add_cnt = cnt;
448 /* VFOP set VLAN/MAC */
449 static void bnx2x_vfop_vlan_mac(struct bnx2x *bp, struct bnx2x_virtf *vf)
451 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
452 struct bnx2x_vlan_mac_ramrod_params *vlan_mac = &vfop->op_p->vlan_mac;
453 struct bnx2x_vlan_mac_obj *obj = vlan_mac->vlan_mac_obj;
454 struct bnx2x_vfop_filters *filters = vfop->args.filters.multi_filter;
456 enum bnx2x_vfop_vlan_mac_state state = vfop->state;
461 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
463 bnx2x_vfop_reset_wq(vf);
466 case BNX2X_VFOP_VLAN_MAC_CLEAR:
468 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
471 vfop->rc = obj->delete_all(bp, obj,
472 &vlan_mac->user_req.vlan_mac_flags,
473 &vlan_mac->ramrod_flags);
475 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
477 case BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE:
479 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
482 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
483 if (vfop->rc == -EEXIST)
486 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
488 case BNX2X_VFOP_VLAN_MAC_CHK_DONE:
489 vfop->rc = !!obj->raw.check_pending(&obj->raw);
490 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
492 case BNX2X_VFOP_MAC_CONFIG_LIST:
494 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
497 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
501 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
502 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
503 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
505 case BNX2X_VFOP_VLAN_CONFIG_LIST:
507 vfop->state = BNX2X_VFOP_VLAN_CONFIG_LIST_0;
509 /* remove vlan0 - could be no-op */
510 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, false);
514 /* Do vlan list config. if this operation fails we try to
515 * restore vlan0 to keep the queue is working order
517 vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
519 set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
520 vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
522 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT); /* fall-through */
524 case BNX2X_VFOP_VLAN_CONFIG_LIST_0:
526 vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
528 if (list_empty(&obj->head))
530 vfop->rc = bnx2x_vfop_config_vlan0(bp, vlan_mac, true);
531 bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
534 bnx2x_vfop_default(state);
537 BNX2X_ERR("VLAN-MAC error: rc %d\n", vfop->rc);
540 bnx2x_vfop_credit(bp, vfop, obj);
541 bnx2x_vfop_end(bp, vf, vfop);
546 struct bnx2x_vfop_vlan_mac_flags {
554 bnx2x_vfop_vlan_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
555 struct bnx2x_vfop_vlan_mac_flags *flags)
557 struct bnx2x_vlan_mac_data *ureq = &ramrod->user_req;
559 memset(ramrod, 0, sizeof(*ramrod));
563 set_bit(RAMROD_DRV_CLR_ONLY, &ramrod->ramrod_flags);
564 if (flags->single_cmd)
565 set_bit(RAMROD_EXEC, &ramrod->ramrod_flags);
568 if (flags->dont_consume)
569 set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT, &ureq->vlan_mac_flags);
572 ureq->cmd = flags->add ? BNX2X_VLAN_MAC_ADD : BNX2X_VLAN_MAC_DEL;
575 int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
576 struct bnx2x_virtf *vf,
577 struct bnx2x_vfop_cmd *cmd,
578 int qid, u16 vid, bool add)
580 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
583 struct bnx2x_vfop_args_filters filters = {
584 .multi_filter = NULL, /* single command */
585 .credit = &bnx2x_vfq(vf, qid, vlan_count),
587 struct bnx2x_vfop_vlan_mac_flags flags = {
589 .dont_consume = (filters.credit != NULL),
593 struct bnx2x_vlan_mac_ramrod_params *ramrod =
594 &vf->op_params.vlan_mac;
596 /* set ramrod params */
597 bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
598 ramrod->user_req.u.vlan.vlan = vid;
601 ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
604 vfop->args.filters = filters;
606 bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
607 bnx2x_vfop_vlan_mac, cmd->done);
608 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
614 /* VFOP queue setup (queue constructor + set vlan 0) */
615 static void bnx2x_vfop_qsetup(struct bnx2x *bp, struct bnx2x_virtf *vf)
617 struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
618 int qid = vfop->args.qctor.qid;
619 enum bnx2x_vfop_qsetup_state state = vfop->state;
620 struct bnx2x_vfop_cmd cmd = {
621 .done = bnx2x_vfop_qsetup,
628 DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
631 case BNX2X_VFOP_QSETUP_CTOR:
632 /* init the queue ctor command */
633 vfop->state = BNX2X_VFOP_QSETUP_VLAN0;
634 vfop->rc = bnx2x_vfop_qctor_cmd(bp, vf, &cmd, qid);
639 case BNX2X_VFOP_QSETUP_VLAN0:
640 /* skip if non-leading or FPGA/EMU*/
644 /* init the queue set-vlan command (for vlan 0) */
645 vfop->state = BNX2X_VFOP_QSETUP_DONE;
646 vfop->rc = bnx2x_vfop_vlan_set_cmd(bp, vf, &cmd, qid, 0, true);
651 BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, vfop->rc);
653 case BNX2X_VFOP_QSETUP_DONE:
654 bnx2x_vfop_end(bp, vf, vfop);
657 bnx2x_vfop_default(state);
661 int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
662 struct bnx2x_virtf *vf,
663 struct bnx2x_vfop_cmd *cmd,
666 struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
669 vfop->args.qctor.qid = qid;
671 bnx2x_vfop_opset(BNX2X_VFOP_QSETUP_CTOR,
672 bnx2x_vfop_qsetup, cmd->done);
673 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qsetup,
679 /* VF enable primitives
680 * when pretend is required the caller is responsible
681 * for calling pretend prior to calling these routines
684 /* called only on E1H or E2.
685 * When pretending to be PF, the pretend value is the function number 0...7
686 * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
689 int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
693 if (CHIP_IS_E1H(bp) && pretend_func_val > E1H_FUNC_MAX)
696 /* get my own pretend register */
697 pretend_reg = bnx2x_get_pretend_reg(bp);
698 REG_WR(bp, pretend_reg, pretend_func_val);
699 REG_RD(bp, pretend_reg);
703 /* internal vf enable - until vf is enabled internally all transactions
704 * are blocked. this routine should always be called last with pretend.
706 static void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable)
708 REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0);
711 /* clears vf error in all semi blocks */
712 static void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid)
714 REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid);
715 REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid);
716 REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid);
717 REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid);
720 static void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid)
722 u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5;
725 switch (was_err_group) {
727 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR;
730 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR;
733 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR;
736 was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR;
739 REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f));
742 static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
747 /* Set VF masks and configuration - pretend */
748 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
750 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
751 REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
752 REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
753 REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
754 REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
755 REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
757 val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
758 val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN);
759 if (vf->cfg_flags & VF_CFG_INT_SIMD)
760 val |= IGU_VF_CONF_SINGLE_ISR_EN;
761 val &= ~IGU_VF_CONF_PARENT_MASK;
762 val |= BP_FUNC(bp) << IGU_VF_CONF_PARENT_SHIFT; /* parent PF */
763 REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
766 "value in IGU_REG_VF_CONFIGURATION of vf %d after write %x\n",
767 vf->abs_vfid, REG_RD(bp, IGU_REG_VF_CONFIGURATION));
769 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
771 /* iterate over all queues, clear sb consumer */
772 for (i = 0; i < vf_sb_count(vf); i++) {
773 u8 igu_sb_id = vf_igu_sb(vf, i);
775 /* zero prod memory */
776 REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0);
778 /* clear sb state machine */
779 bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id,
782 /* disable + update */
783 bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0,
788 void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid)
790 /* set the VF-PF association in the FW */
791 storm_memset_vf_to_pf(bp, FW_VF_HANDLE(abs_vfid), BP_FUNC(bp));
792 storm_memset_func_en(bp, FW_VF_HANDLE(abs_vfid), 1);
795 bnx2x_vf_semi_clear_err(bp, abs_vfid);
796 bnx2x_vf_pglue_clear_err(bp, abs_vfid);
798 /* internal vf-enable - pretend */
799 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid));
800 DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid);
801 bnx2x_vf_enable_internal(bp, true);
802 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
805 static void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf)
807 /* Reset vf in IGU interrupts are still disabled */
808 bnx2x_vf_igu_reset(bp, vf);
810 /* pretend to enable the vf with the PBF */
811 bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
812 REG_WR(bp, PBF_REG_DISABLE_VF, 0);
813 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
816 static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
819 struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
824 dev = pci_get_bus_and_slot(vf->bus, vf->devfn);
826 return bnx2x_is_pcie_pending(dev);
829 BNX2X_ERR("Unknown device\n");
833 int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid)
838 /* Verify no pending pci transactions */
839 if (bnx2x_vf_is_pcie_pending(bp, abs_vfid))
840 BNX2X_ERR("PCIE Transactions still pending\n");
845 /* must be called after the number of PF queues and the number of VFs are
849 bnx2x_iov_static_resc(struct bnx2x *bp, struct vf_pf_resc_request *resc)
853 /* will be set only during VF-ACQUIRE */
857 /* no credit calculcis for macs (just yet) */
858 resc->num_mac_filters = 1;
860 /* divvy up vlan rules */
861 vlan_count = bp->vlans_pool.check(&bp->vlans_pool);
862 vlan_count = 1 << ilog2(vlan_count);
863 resc->num_vlan_filters = vlan_count / BNX2X_NR_VIRTFN(bp);
865 /* no real limitation */
866 resc->num_mc_filters = 0;
868 /* num_sbs already set */
871 /* IOV global initialization routines */
872 void bnx2x_iov_init_dq(struct bnx2x *bp)
877 /* Set the DQ such that the CID reflect the abs_vfid */
878 REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0);
879 REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS));
881 /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to
884 REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID);
886 /* The VF window size is the log2 of the max number of CIDs per VF */
887 REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND);
889 /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match
890 * the Pf doorbell size although the 2 are independent.
892 REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST,
893 BNX2X_DB_SHIFT - BNX2X_DB_MIN_SHIFT);
895 /* No security checks for now -
896 * configure single rule (out of 16) mask = 0x1, value = 0x0,
897 * CID range 0 - 0x1ffff
899 REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1);
900 REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0);
901 REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0);
902 REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff);
904 /* set the number of VF alllowed doorbells to the full DQ range */
905 REG_WR(bp, DORQ_REG_VF_NORM_MAX_CID_COUNT, 0x20000);
907 /* set the VF doorbell threshold */
908 REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 4);
911 void bnx2x_iov_init_dmae(struct bnx2x *bp)
913 DP(BNX2X_MSG_IOV, "SRIOV is %s\n", IS_SRIOV(bp) ? "ON" : "OFF");
917 REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0);
920 static int bnx2x_vf_bus(struct bnx2x *bp, int vfid)
922 struct pci_dev *dev = bp->pdev;
923 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
925 return dev->bus->number + ((dev->devfn + iov->offset +
926 iov->stride * vfid) >> 8);
929 static int bnx2x_vf_devfn(struct bnx2x *bp, int vfid)
931 struct pci_dev *dev = bp->pdev;
932 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
934 return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff;
937 static void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
940 struct pci_dev *dev = bp->pdev;
941 struct bnx2x_sriov *iov = &bp->vfdb->sriov;
943 for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
944 u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i);
945 u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i);
947 do_div(size, iov->total);
948 vf->bars[n].bar = start + size * vf->abs_vfid;
949 vf->bars[n].size = size;
953 static int bnx2x_ari_enabled(struct pci_dev *dev)
955 return dev->bus->self && dev->bus->self->ari_enabled;
959 bnx2x_get_vf_igu_cam_info(struct bnx2x *bp)
965 /* IGU in normal mode - read CAM */
966 for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) {
967 val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4);
968 if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
970 fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID);
971 if (!(fid & IGU_FID_ENCODE_IS_PF))
972 bnx2x_vf_set_igu_info(bp, sb_id,
973 (fid & IGU_FID_VF_NUM_MASK));
975 DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n",
976 ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"),
977 ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) :
978 (fid & IGU_FID_VF_NUM_MASK)), sb_id,
979 GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR));
983 static void __bnx2x_iov_free_vfdb(struct bnx2x *bp)
986 kfree(bp->vfdb->vfqs);
987 kfree(bp->vfdb->vfs);
993 static int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
996 struct pci_dev *dev = bp->pdev;
998 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
1000 BNX2X_ERR("failed to find SRIOV capability in device\n");
1005 DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos);
1006 pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
1007 pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total);
1008 pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial);
1009 pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
1010 pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
1011 pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
1012 pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
1013 pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
1018 static int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
1022 /* read the SRIOV capability structure
1023 * The fields can be read via configuration read or
1024 * directly from the device (starting at offset PCICFG_OFFSET)
1026 if (bnx2x_sriov_pci_cfg_info(bp, iov))
1029 /* get the number of SRIOV bars */
1032 /* read the first_vfid */
1033 val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF);
1034 iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK)
1035 * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp));
1038 "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",
1040 iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total,
1041 iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
1046 static u8 bnx2x_iov_get_max_queue_count(struct bnx2x *bp)
1053 queue_count += bnx2x_vf(bp, i, alloc_resc.num_sbs);
1058 /* must be called after PF bars are mapped */
1059 int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
1063 struct bnx2x_sriov *iov;
1064 struct pci_dev *dev = bp->pdev;
1072 /* verify sriov capability is present in configuration space */
1073 if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV))
1076 /* verify chip revision */
1077 if (CHIP_IS_E1x(bp))
1080 /* check if SRIOV support is turned off */
1084 /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */
1085 if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) {
1086 BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n",
1087 BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID);
1091 /* SRIOV can be enabled only with MSIX */
1092 if (int_mode_param == BNX2X_INT_MODE_MSI ||
1093 int_mode_param == BNX2X_INT_MODE_INTX)
1094 BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n");
1097 /* verify ari is enabled */
1098 if (!bnx2x_ari_enabled(bp->pdev)) {
1099 BNX2X_ERR("ARI not supported, SRIOV can not be enabled\n");
1103 /* verify igu is in normal mode */
1104 if (CHIP_INT_MODE_IS_BC(bp)) {
1105 BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n");
1109 /* allocate the vfs database */
1110 bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL);
1112 BNX2X_ERR("failed to allocate vf database\n");
1117 /* get the sriov info - Linux already collected all the pertinent
1118 * information, however the sriov structure is for the private use
1119 * of the pci module. Also we want this information regardless
1120 * of the hyper-visor.
1122 iov = &(bp->vfdb->sriov);
1123 err = bnx2x_sriov_info(bp, iov);
1127 /* SR-IOV capability was enabled but there are no VFs*/
1128 if (iov->total == 0)
1131 /* calculate the actual number of VFs */
1132 iov->nr_virtfn = min_t(u16, iov->total, (u16)num_vfs_param);
1134 /* allocate the vf array */
1135 bp->vfdb->vfs = kzalloc(sizeof(struct bnx2x_virtf) *
1136 BNX2X_NR_VIRTFN(bp), GFP_KERNEL);
1137 if (!bp->vfdb->vfs) {
1138 BNX2X_ERR("failed to allocate vf array\n");
1143 /* Initial VF init - index and abs_vfid - nr_virtfn must be set */
1144 for_each_vf(bp, i) {
1145 bnx2x_vf(bp, i, index) = i;
1146 bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i;
1147 bnx2x_vf(bp, i, state) = VF_FREE;
1148 INIT_LIST_HEAD(&bnx2x_vf(bp, i, op_list_head));
1149 mutex_init(&bnx2x_vf(bp, i, op_mutex));
1150 bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE;
1153 /* re-read the IGU CAM for VFs - index and abs_vfid must be set */
1154 bnx2x_get_vf_igu_cam_info(bp);
1156 /* get the total queue count and allocate the global queue arrays */
1157 qcount = bnx2x_iov_get_max_queue_count(bp);
1159 /* allocate the queue arrays for all VFs */
1160 bp->vfdb->vfqs = kzalloc(qcount * sizeof(struct bnx2x_vf_queue),
1162 if (!bp->vfdb->vfqs) {
1163 BNX2X_ERR("failed to allocate vf queue array\n");
1170 DP(BNX2X_MSG_IOV, "Failed err=%d\n", err);
1171 __bnx2x_iov_free_vfdb(bp);
1175 void bnx2x_iov_remove_one(struct bnx2x *bp)
1177 /* if SRIOV is not enabled there's nothing to do */
1181 /* free vf database */
1182 __bnx2x_iov_free_vfdb(bp);
1185 void bnx2x_iov_free_mem(struct bnx2x *bp)
1192 /* free vfs hw contexts */
1193 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
1194 struct hw_dma *cxt = &bp->vfdb->context[i];
1195 BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size);
1198 BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr,
1199 BP_VFDB(bp)->sp_dma.mapping,
1200 BP_VFDB(bp)->sp_dma.size);
1202 BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr,
1203 BP_VF_MBX_DMA(bp)->mapping,
1204 BP_VF_MBX_DMA(bp)->size);
1207 int bnx2x_iov_alloc_mem(struct bnx2x *bp)
1215 /* allocate vfs hw contexts */
1216 tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) *
1217 BNX2X_CIDS_PER_VF * sizeof(union cdu_context);
1219 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
1220 struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
1221 cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
1224 BNX2X_PCI_ALLOC(cxt->addr, &cxt->mapping, cxt->size);
1229 tot_size -= cxt->size;
1232 /* allocate vfs ramrods dma memory - client_init and set_mac */
1233 tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
1234 BNX2X_PCI_ALLOC(BP_VFDB(bp)->sp_dma.addr, &BP_VFDB(bp)->sp_dma.mapping,
1236 BP_VFDB(bp)->sp_dma.size = tot_size;
1238 /* allocate mailboxes */
1239 tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
1240 BNX2X_PCI_ALLOC(BP_VF_MBX_DMA(bp)->addr, &BP_VF_MBX_DMA(bp)->mapping,
1242 BP_VF_MBX_DMA(bp)->size = tot_size;
1250 static void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
1251 struct bnx2x_vf_queue *q)
1253 u8 cl_id = vfq_cl_id(vf, q);
1254 u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
1255 unsigned long q_type = 0;
1257 set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1258 set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1260 /* Queue State object */
1261 bnx2x_init_queue_obj(bp, &q->sp_obj,
1262 cl_id, &q->cid, 1, func_id,
1263 bnx2x_vf_sp(bp, vf, q_data),
1264 bnx2x_vf_sp_map(bp, vf, q_data),
1268 "initialized vf %d's queue object. func id set to %d\n",
1269 vf->abs_vfid, q->sp_obj.func_id);
1271 /* mac/vlan objects are per queue, but only those
1272 * that belong to the leading queue are initialized
1274 if (vfq_is_leading(q)) {
1276 bnx2x_init_mac_obj(bp, &q->mac_obj,
1277 cl_id, q->cid, func_id,
1278 bnx2x_vf_sp(bp, vf, mac_rdata),
1279 bnx2x_vf_sp_map(bp, vf, mac_rdata),
1280 BNX2X_FILTER_MAC_PENDING,
1282 BNX2X_OBJ_TYPE_RX_TX,
1285 bnx2x_init_vlan_obj(bp, &q->vlan_obj,
1286 cl_id, q->cid, func_id,
1287 bnx2x_vf_sp(bp, vf, vlan_rdata),
1288 bnx2x_vf_sp_map(bp, vf, vlan_rdata),
1289 BNX2X_FILTER_VLAN_PENDING,
1291 BNX2X_OBJ_TYPE_RX_TX,
1295 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
1296 q->cid, func_id, func_id,
1297 bnx2x_vf_sp(bp, vf, mcast_rdata),
1298 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
1299 BNX2X_FILTER_MCAST_PENDING,
1301 BNX2X_OBJ_TYPE_RX_TX);
1303 vf->leading_rss = cl_id;
1307 /* called by bnx2x_nic_load */
1308 int bnx2x_iov_nic_init(struct bnx2x *bp)
1310 int vfid, qcount, i;
1312 if (!IS_SRIOV(bp)) {
1313 DP(BNX2X_MSG_IOV, "vfdb was not allocated\n");
1317 DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn);
1319 /* initialize vf database */
1320 for_each_vf(bp, vfid) {
1321 struct bnx2x_virtf *vf = BP_VF(bp, vfid);
1323 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) *
1326 union cdu_context *base_cxt = (union cdu_context *)
1327 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
1328 (base_vf_cid & (ILT_PAGE_CIDS-1));
1331 "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n",
1332 vf->abs_vfid, vf_sb_count(vf), base_vf_cid,
1333 BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt);
1335 /* init statically provisioned resources */
1336 bnx2x_iov_static_resc(bp, &vf->alloc_resc);
1338 /* queues are initialized during VF-ACQUIRE */
1340 /* reserve the vf vlan credit */
1341 bp->vlans_pool.get(&bp->vlans_pool, vf_vlan_rules_cnt(vf));
1343 vf->filter_state = 0;
1344 vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id);
1346 /* init mcast object - This object will be re-initialized
1347 * during VF-ACQUIRE with the proper cl_id and cid.
1348 * It needs to be initialized here so that it can be safely
1349 * handled by a subsequent FLR flow.
1351 bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF,
1353 bnx2x_vf_sp(bp, vf, mcast_rdata),
1354 bnx2x_vf_sp_map(bp, vf, mcast_rdata),
1355 BNX2X_FILTER_MCAST_PENDING,
1357 BNX2X_OBJ_TYPE_RX_TX);
1359 /* set the mailbox message addresses */
1360 BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *)
1361 (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid *
1362 MBX_MSG_ALIGNED_SIZE);
1364 BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping +
1365 vfid * MBX_MSG_ALIGNED_SIZE;
1367 /* Enable vf mailbox */
1368 bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
1373 for_each_vf(bp, i) {
1374 struct bnx2x_virtf *vf = BP_VF(bp, i);
1376 /* fill in the BDF and bars */
1377 vf->bus = bnx2x_vf_bus(bp, i);
1378 vf->devfn = bnx2x_vf_devfn(bp, i);
1379 bnx2x_vf_set_bars(bp, vf);
1382 "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n",
1383 vf->abs_vfid, vf->bus, vf->devfn,
1384 (unsigned)vf->bars[0].bar, vf->bars[0].size,
1385 (unsigned)vf->bars[1].bar, vf->bars[1].size,
1386 (unsigned)vf->bars[2].bar, vf->bars[2].size);
1388 /* set local queue arrays */
1389 vf->vfqs = &bp->vfdb->vfqs[qcount];
1390 qcount += bnx2x_vf(bp, i, alloc_resc.num_sbs);
1396 /* called by bnx2x_init_hw_func, returns the next ilt line */
1397 int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line)
1400 struct bnx2x_ilt *ilt = BP_ILT(bp);
1405 /* set vfs ilt lines */
1406 for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
1407 struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i);
1409 ilt->lines[line+i].page = hw_cxt->addr;
1410 ilt->lines[line+i].page_mapping = hw_cxt->mapping;
1411 ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */
1416 static u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid)
1418 return ((cid >= BNX2X_FIRST_VF_CID) &&
1419 ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS));
1423 void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
1424 struct bnx2x_vf_queue *vfq,
1425 union event_ring_elem *elem)
1427 unsigned long ramrod_flags = 0;
1430 /* Always push next commands out, don't wait here */
1431 set_bit(RAMROD_CONT, &ramrod_flags);
1433 switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
1434 case BNX2X_FILTER_MAC_PENDING:
1435 rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
1438 case BNX2X_FILTER_VLAN_PENDING:
1439 rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem,
1443 BNX2X_ERR("Unsupported classification command: %d\n",
1444 elem->message.data.eth_event.echo);
1448 BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
1450 DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n");
1454 void bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp,
1455 struct bnx2x_virtf *vf)
1457 struct bnx2x_mcast_ramrod_params rparam = {NULL};
1460 rparam.mcast_obj = &vf->mcast_obj;
1461 vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw);
1463 /* If there are pending mcast commands - send them */
1464 if (vf->mcast_obj.check_pending(&vf->mcast_obj)) {
1465 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
1467 BNX2X_ERR("Failed to send pending mcast commands: %d\n",
1473 void bnx2x_vf_handle_filters_eqe(struct bnx2x *bp,
1474 struct bnx2x_virtf *vf)
1476 smp_mb__before_clear_bit();
1477 clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
1478 smp_mb__after_clear_bit();
1481 int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
1483 struct bnx2x_virtf *vf;
1484 int qidx = 0, abs_vfid;
1491 /* first get the cid - the only events we handle here are cfc-delete
1492 * and set-mac completion
1494 opcode = elem->message.opcode;
1497 case EVENT_RING_OPCODE_CFC_DEL:
1498 cid = SW_CID((__force __le32)
1499 elem->message.data.cfc_del_event.cid);
1500 DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
1502 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
1503 case EVENT_RING_OPCODE_MULTICAST_RULES:
1504 case EVENT_RING_OPCODE_FILTERS_RULES:
1505 cid = (elem->message.data.eth_event.echo &
1507 DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
1509 case EVENT_RING_OPCODE_VF_FLR:
1510 abs_vfid = elem->message.data.vf_flr_event.vf_id;
1511 DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n",
1514 case EVENT_RING_OPCODE_MALICIOUS_VF:
1515 abs_vfid = elem->message.data.malicious_vf_event.vf_id;
1516 DP(BNX2X_MSG_IOV, "Got VF MALICIOUS notification abs_vfid=%d\n",
1523 /* check if the cid is the VF range */
1524 if (!bnx2x_iov_is_vf_cid(bp, cid)) {
1525 DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid);
1529 /* extract vf and rxq index from vf_cid - relies on the following:
1530 * 1. vfid on cid reflects the true abs_vfid
1531 * 2. the max number of VFs (per path) is 64
1533 qidx = cid & ((1 << BNX2X_VF_CID_WND)-1);
1534 abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
1536 vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
1539 BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n",
1545 case EVENT_RING_OPCODE_CFC_DEL:
1546 DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n",
1547 vf->abs_vfid, qidx);
1548 vfq_get(vf, qidx)->sp_obj.complete_cmd(bp,
1551 BNX2X_Q_CMD_CFC_DEL);
1553 case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
1554 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n",
1555 vf->abs_vfid, qidx);
1556 bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem);
1558 case EVENT_RING_OPCODE_MULTICAST_RULES:
1559 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n",
1560 vf->abs_vfid, qidx);
1561 bnx2x_vf_handle_mcast_eqe(bp, vf);
1563 case EVENT_RING_OPCODE_FILTERS_RULES:
1564 DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n",
1565 vf->abs_vfid, qidx);
1566 bnx2x_vf_handle_filters_eqe(bp, vf);
1568 case EVENT_RING_OPCODE_VF_FLR:
1569 DP(BNX2X_MSG_IOV, "got VF [%d] FLR notification\n",
1571 /* Do nothing for now */
1573 case EVENT_RING_OPCODE_MALICIOUS_VF:
1574 DP(BNX2X_MSG_IOV, "got VF [%d] MALICIOUS notification\n",
1576 /* Do nothing for now */
1579 /* SRIOV: reschedule any 'in_progress' operations */
1580 bnx2x_iov_sp_event(bp, cid, false);
1585 static struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid)
1587 /* extract the vf from vf_cid - relies on the following:
1588 * 1. vfid on cid reflects the true abs_vfid
1589 * 2. the max number of VFs (per path) is 64
1591 int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
1592 return bnx2x_vf_by_abs_fid(bp, abs_vfid);
1595 void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
1596 struct bnx2x_queue_sp_obj **q_obj)
1598 struct bnx2x_virtf *vf;
1603 vf = bnx2x_vf_by_cid(bp, vf_cid);
1606 /* extract queue index from vf_cid - relies on the following:
1607 * 1. vfid on cid reflects the true abs_vfid
1608 * 2. the max number of VFs (per path) is 64
1610 int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1);
1611 *q_obj = &bnx2x_vfq(vf, q_index, sp_obj);
1613 BNX2X_ERR("No vf matching cid %d\n", vf_cid);
1617 void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work)
1619 struct bnx2x_virtf *vf;
1621 /* check if the cid is the VF range */
1622 if (!IS_SRIOV(bp) || !bnx2x_iov_is_vf_cid(bp, vf_cid))
1625 vf = bnx2x_vf_by_cid(bp, vf_cid);
1627 /* set in_progress flag */
1628 atomic_set(&vf->op_in_progress, 1);
1630 queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
1634 void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
1637 int first_queue_query_index, num_queues_req;
1638 dma_addr_t cur_data_offset;
1639 struct stats_query_entry *cur_query_entry;
1641 bool is_fcoe = false;
1649 /* fcoe adds one global request and one queue request */
1650 num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe;
1651 first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX -
1655 "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",
1656 BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index,
1657 first_queue_query_index + num_queues_req);
1659 cur_data_offset = bp->fw_stats_data_mapping +
1660 offsetof(struct bnx2x_fw_stats_data, queue_stats) +
1661 num_queues_req * sizeof(struct per_queue_stats);
1663 cur_query_entry = &bp->fw_stats_req->
1664 query[first_queue_query_index + num_queues_req];
1666 for_each_vf(bp, i) {
1668 struct bnx2x_virtf *vf = BP_VF(bp, i);
1670 if (vf->state != VF_ENABLED) {
1672 "vf %d not enabled so no stats for it\n",
1677 DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid);
1678 for_each_vfq(vf, j) {
1679 struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
1681 /* collect stats fro active queues only */
1682 if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) ==
1683 BNX2X_Q_LOGICAL_STATE_STOPPED)
1686 /* create stats query entry for this queue */
1687 cur_query_entry->kind = STATS_TYPE_QUEUE;
1688 cur_query_entry->index = vfq_cl_id(vf, rxq);
1689 cur_query_entry->funcID =
1690 cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid));
1691 cur_query_entry->address.hi =
1692 cpu_to_le32(U64_HI(vf->fw_stat_map));
1693 cur_query_entry->address.lo =
1694 cpu_to_le32(U64_LO(vf->fw_stat_map));
1696 "added address %x %x for vf %d queue %d client %d\n",
1697 cur_query_entry->address.hi,
1698 cur_query_entry->address.lo, cur_query_entry->funcID,
1699 j, cur_query_entry->index);
1701 cur_data_offset += sizeof(struct per_queue_stats);
1705 bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count;
1708 void bnx2x_iov_sp_task(struct bnx2x *bp)
1714 /* Iterate over all VFs and invoke state transition for VFs with
1715 * 'in-progress' slow-path operations
1717 DP(BNX2X_MSG_IOV, "searching for pending vf operations\n");
1718 for_each_vf(bp, i) {
1719 struct bnx2x_virtf *vf = BP_VF(bp, i);
1721 if (!list_empty(&vf->op_list_head) &&
1722 atomic_read(&vf->op_in_progress)) {
1723 DP(BNX2X_MSG_IOV, "running pending op for vf %d\n", i);
1724 bnx2x_vfop_cur(bp, vf)->transition(bp, vf);
1730 struct bnx2x_virtf *__vf_from_stat_id(struct bnx2x *bp, u8 stat_id)
1733 struct bnx2x_virtf *vf = NULL;
1735 for_each_vf(bp, i) {
1737 if (stat_id >= vf->igu_base_id &&
1738 stat_id < vf->igu_base_id + vf_sb_count(vf))
1744 /* VF API helpers */
1745 static void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid,
1748 u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4;
1749 u32 val = enable ? (abs_vfid | (1 << 6)) : 0;
1751 REG_WR(bp, reg, val);
1754 u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
1756 return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
1757 BNX2X_VF_MAX_QUEUES);
1761 int bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf,
1762 struct vf_pf_resc_request *req_resc)
1764 u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
1765 u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
1767 return ((req_resc->num_rxqs <= rxq_cnt) &&
1768 (req_resc->num_txqs <= txq_cnt) &&
1769 (req_resc->num_sbs <= vf_sb_count(vf)) &&
1770 (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) &&
1771 (req_resc->num_vlan_filters <= vf_vlan_rules_cnt(vf)));
1775 int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1776 struct vf_pf_resc_request *resc)
1778 int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) *
1781 union cdu_context *base_cxt = (union cdu_context *)
1782 BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
1783 (base_vf_cid & (ILT_PAGE_CIDS-1));
1786 /* if state is 'acquired' the VF was not released or FLR'd, in
1787 * this case the returned resources match the acquired already
1788 * acquired resources. Verify that the requested numbers do
1789 * not exceed the already acquired numbers.
1791 if (vf->state == VF_ACQUIRED) {
1792 DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n",
1795 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
1796 BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n",
1803 /* Otherwise vf state must be 'free' or 'reset' */
1804 if (vf->state != VF_FREE && vf->state != VF_RESET) {
1805 BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n",
1806 vf->abs_vfid, vf->state);
1810 /* static allocation:
1811 * the global maximum number are fixed per VF. fail the request if
1812 * requested number exceed these globals
1814 if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
1816 "cannot fulfill vf resource request. Placing maximal available values in response\n");
1817 /* set the max resource in the vf */
1821 /* Set resources counters - 0 request means max available */
1822 vf_sb_count(vf) = resc->num_sbs;
1823 vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
1824 vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
1825 if (resc->num_mac_filters)
1826 vf_mac_rules_cnt(vf) = resc->num_mac_filters;
1827 if (resc->num_vlan_filters)
1828 vf_vlan_rules_cnt(vf) = resc->num_vlan_filters;
1831 "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n",
1832 vf_sb_count(vf), vf_rxq_count(vf),
1833 vf_txq_count(vf), vf_mac_rules_cnt(vf),
1834 vf_vlan_rules_cnt(vf));
1836 /* Initialize the queues */
1838 DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n");
1842 for_each_vfq(vf, i) {
1843 struct bnx2x_vf_queue *q = vfq_get(vf, i);
1846 DP(BNX2X_MSG_IOV, "q number %d was not allocated\n", i);
1851 q->cxt = &((base_cxt + i)->eth);
1852 q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i;
1854 DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n",
1855 vf->abs_vfid, i, q->index, q->cid, q->cxt);
1857 /* init SP objects */
1858 bnx2x_vfq_init(bp, vf, q);
1860 vf->state = VF_ACQUIRED;
1864 int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map)
1866 struct bnx2x_func_init_params func_init = {0};
1870 /* the sb resources are initialized at this point, do the
1871 * FW/HW initializations
1873 for_each_vf_sb(vf, i)
1874 bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true,
1875 vf_igu_sb(vf, i), vf_igu_sb(vf, i));
1878 if (vf->state != VF_ACQUIRED) {
1879 DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n",
1880 vf->abs_vfid, vf->state);
1883 /* FLR cleanup epilogue */
1884 if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid))
1887 /* reset IGU VF statistics: MSIX */
1888 REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0);
1891 if (vf->cfg_flags & VF_CFG_STATS)
1892 flags |= (FUNC_FLG_STATS | FUNC_FLG_SPQ);
1894 if (vf->cfg_flags & VF_CFG_TPA)
1895 flags |= FUNC_FLG_TPA;
1897 if (is_vf_multi(vf))
1898 flags |= FUNC_FLG_RSS;
1900 /* function setup */
1901 func_init.func_flgs = flags;
1902 func_init.pf_id = BP_FUNC(bp);
1903 func_init.func_id = FW_VF_HANDLE(vf->abs_vfid);
1904 func_init.fw_stat_map = vf->fw_stat_map;
1905 func_init.spq_map = vf->spq_map;
1906 func_init.spq_prod = 0;
1907 bnx2x_func_init(bp, &func_init);
1910 bnx2x_vf_enable_access(bp, vf->abs_vfid);
1911 bnx2x_vf_enable_traffic(bp, vf);
1913 /* queue protection table */
1915 bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
1916 vfq_qzone_id(vf, vfq_get(vf, i)), true);
1918 vf->state = VF_ENABLED;
1923 void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
1924 enum channel_tlvs tlv)
1926 /* lock the channel */
1927 mutex_lock(&vf->op_mutex);
1929 /* record the locking op */
1930 vf->op_current = tlv;
1933 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n",
1937 void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
1938 enum channel_tlvs expected_tlv)
1940 WARN(expected_tlv != vf->op_current,
1941 "lock mismatch: expected %d found %d", expected_tlv,
1944 /* lock the channel */
1945 mutex_unlock(&vf->op_mutex);
1947 /* log the unlock */
1948 DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n",
1949 vf->abs_vfid, vf->op_current);
1951 /* record the locking op */
1952 vf->op_current = CHANNEL_TLV_NONE;