162306a36Sopenharmony_ci/* bnx2x_sriov.c: QLogic Everest network driver. 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Copyright 2009-2013 Broadcom Corporation 462306a36Sopenharmony_ci * Copyright 2014 QLogic Corporation 562306a36Sopenharmony_ci * All rights reserved 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Unless you and QLogic execute a separate written software license 862306a36Sopenharmony_ci * agreement governing use of this software, this software is licensed to you 962306a36Sopenharmony_ci * under the terms of the GNU General Public License version 2, available 1062306a36Sopenharmony_ci * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"). 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Notwithstanding the above, under no circumstances may you combine this 1362306a36Sopenharmony_ci * software in any way with any other QLogic software provided under a 1462306a36Sopenharmony_ci * license other than the GPL, without QLogic's express prior written 1562306a36Sopenharmony_ci * consent. 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * Maintained by: Ariel Elior <ariel.elior@qlogic.com> 1862306a36Sopenharmony_ci * Written by: Shmulik Ravid 1962306a36Sopenharmony_ci * Ariel Elior <ariel.elior@qlogic.com> 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#include "bnx2x.h" 2362306a36Sopenharmony_ci#include "bnx2x_init.h" 2462306a36Sopenharmony_ci#include "bnx2x_cmn.h" 2562306a36Sopenharmony_ci#include "bnx2x_sp.h" 2662306a36Sopenharmony_ci#include <linux/crc32.h> 2762306a36Sopenharmony_ci#include <linux/if_vlan.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistatic int bnx2x_vf_op_prep(struct bnx2x *bp, int vfidx, 3062306a36Sopenharmony_ci struct bnx2x_virtf **vf, 3162306a36Sopenharmony_ci struct pf_vf_bulletin_content **bulletin, 3262306a36Sopenharmony_ci bool test_queue); 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* General service functions */ 3562306a36Sopenharmony_cistatic void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid, 3662306a36Sopenharmony_ci u16 pf_id) 3762306a36Sopenharmony_ci{ 3862306a36Sopenharmony_ci REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid), 3962306a36Sopenharmony_ci pf_id); 4062306a36Sopenharmony_ci REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid), 4162306a36Sopenharmony_ci pf_id); 4262306a36Sopenharmony_ci REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid), 4362306a36Sopenharmony_ci pf_id); 4462306a36Sopenharmony_ci REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid), 4562306a36Sopenharmony_ci pf_id); 4662306a36Sopenharmony_ci} 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cistatic void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid, 4962306a36Sopenharmony_ci u8 enable) 5062306a36Sopenharmony_ci{ 5162306a36Sopenharmony_ci REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid), 5262306a36Sopenharmony_ci enable); 5362306a36Sopenharmony_ci REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid), 5462306a36Sopenharmony_ci enable); 5562306a36Sopenharmony_ci REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid), 5662306a36Sopenharmony_ci enable); 5762306a36Sopenharmony_ci REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid), 5862306a36Sopenharmony_ci enable); 5962306a36Sopenharmony_ci} 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciint bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid) 6262306a36Sopenharmony_ci{ 6362306a36Sopenharmony_ci int idx; 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci for_each_vf(bp, idx) 6662306a36Sopenharmony_ci if (bnx2x_vf(bp, idx, abs_vfid) == abs_vfid) 6762306a36Sopenharmony_ci break; 6862306a36Sopenharmony_ci return idx; 6962306a36Sopenharmony_ci} 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistatic 7262306a36Sopenharmony_cistruct bnx2x_virtf *bnx2x_vf_by_abs_fid(struct bnx2x *bp, u16 abs_vfid) 7362306a36Sopenharmony_ci{ 7462306a36Sopenharmony_ci u16 idx = (u16)bnx2x_vf_idx_by_abs_fid(bp, abs_vfid); 7562306a36Sopenharmony_ci return (idx < BNX2X_NR_VIRTFN(bp)) ? BP_VF(bp, idx) : NULL; 7662306a36Sopenharmony_ci} 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistatic void bnx2x_vf_igu_ack_sb(struct bnx2x *bp, struct bnx2x_virtf *vf, 7962306a36Sopenharmony_ci u8 igu_sb_id, u8 segment, u16 index, u8 op, 8062306a36Sopenharmony_ci u8 update) 8162306a36Sopenharmony_ci{ 8262306a36Sopenharmony_ci /* acking a VF sb through the PF - use the GRC */ 8362306a36Sopenharmony_ci u32 ctl; 8462306a36Sopenharmony_ci u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA; 8562306a36Sopenharmony_ci u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL; 8662306a36Sopenharmony_ci u32 func_encode = vf->abs_vfid; 8762306a36Sopenharmony_ci u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + igu_sb_id; 8862306a36Sopenharmony_ci struct igu_regular cmd_data = {0}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci cmd_data.sb_id_and_flags = 9162306a36Sopenharmony_ci ((index << IGU_REGULAR_SB_INDEX_SHIFT) | 9262306a36Sopenharmony_ci (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) | 9362306a36Sopenharmony_ci (update << IGU_REGULAR_BUPDATE_SHIFT) | 9462306a36Sopenharmony_ci (op << IGU_REGULAR_ENABLE_INT_SHIFT)); 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT | 9762306a36Sopenharmony_ci func_encode << IGU_CTRL_REG_FID_SHIFT | 9862306a36Sopenharmony_ci IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", 10162306a36Sopenharmony_ci cmd_data.sb_id_and_flags, igu_addr_data); 10262306a36Sopenharmony_ci REG_WR(bp, igu_addr_data, cmd_data.sb_id_and_flags); 10362306a36Sopenharmony_ci barrier(); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n", 10662306a36Sopenharmony_ci ctl, igu_addr_ctl); 10762306a36Sopenharmony_ci REG_WR(bp, igu_addr_ctl, ctl); 10862306a36Sopenharmony_ci barrier(); 10962306a36Sopenharmony_ci} 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistatic bool bnx2x_validate_vf_sp_objs(struct bnx2x *bp, 11262306a36Sopenharmony_ci struct bnx2x_virtf *vf, 11362306a36Sopenharmony_ci bool print_err) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci if (!bnx2x_leading_vfq(vf, sp_initialized)) { 11662306a36Sopenharmony_ci if (print_err) 11762306a36Sopenharmony_ci BNX2X_ERR("Slowpath objects not yet initialized!\n"); 11862306a36Sopenharmony_ci else 11962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "Slowpath objects not yet initialized!\n"); 12062306a36Sopenharmony_ci return false; 12162306a36Sopenharmony_ci } 12262306a36Sopenharmony_ci return true; 12362306a36Sopenharmony_ci} 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* VFOP operations states */ 12662306a36Sopenharmony_civoid bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf, 12762306a36Sopenharmony_ci struct bnx2x_queue_init_params *init_params, 12862306a36Sopenharmony_ci struct bnx2x_queue_setup_params *setup_params, 12962306a36Sopenharmony_ci u16 q_idx, u16 sb_idx) 13062306a36Sopenharmony_ci{ 13162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 13262306a36Sopenharmony_ci "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d", 13362306a36Sopenharmony_ci vf->abs_vfid, 13462306a36Sopenharmony_ci q_idx, 13562306a36Sopenharmony_ci sb_idx, 13662306a36Sopenharmony_ci init_params->tx.sb_cq_index, 13762306a36Sopenharmony_ci init_params->tx.hc_rate, 13862306a36Sopenharmony_ci setup_params->flags, 13962306a36Sopenharmony_ci setup_params->txq_params.traffic_type); 14062306a36Sopenharmony_ci} 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_civoid bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf, 14362306a36Sopenharmony_ci struct bnx2x_queue_init_params *init_params, 14462306a36Sopenharmony_ci struct bnx2x_queue_setup_params *setup_params, 14562306a36Sopenharmony_ci u16 q_idx, u16 sb_idx) 14662306a36Sopenharmony_ci{ 14762306a36Sopenharmony_ci struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n" 15062306a36Sopenharmony_ci "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n", 15162306a36Sopenharmony_ci vf->abs_vfid, 15262306a36Sopenharmony_ci q_idx, 15362306a36Sopenharmony_ci sb_idx, 15462306a36Sopenharmony_ci init_params->rx.sb_cq_index, 15562306a36Sopenharmony_ci init_params->rx.hc_rate, 15662306a36Sopenharmony_ci setup_params->gen_params.mtu, 15762306a36Sopenharmony_ci rxq_params->buf_sz, 15862306a36Sopenharmony_ci rxq_params->sge_buf_sz, 15962306a36Sopenharmony_ci rxq_params->max_sges_pkt, 16062306a36Sopenharmony_ci rxq_params->tpa_agg_sz, 16162306a36Sopenharmony_ci setup_params->flags, 16262306a36Sopenharmony_ci rxq_params->drop_flags, 16362306a36Sopenharmony_ci rxq_params->cache_line_log); 16462306a36Sopenharmony_ci} 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_civoid bnx2x_vfop_qctor_prep(struct bnx2x *bp, 16762306a36Sopenharmony_ci struct bnx2x_virtf *vf, 16862306a36Sopenharmony_ci struct bnx2x_vf_queue *q, 16962306a36Sopenharmony_ci struct bnx2x_vf_queue_construct_params *p, 17062306a36Sopenharmony_ci unsigned long q_type) 17162306a36Sopenharmony_ci{ 17262306a36Sopenharmony_ci struct bnx2x_queue_init_params *init_p = &p->qstate.params.init; 17362306a36Sopenharmony_ci struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup; 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci /* INIT */ 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci /* Enable host coalescing in the transition to INIT state */ 17862306a36Sopenharmony_ci if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags)) 17962306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags); 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags)) 18262306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags); 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci /* FW SB ID */ 18562306a36Sopenharmony_ci init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx); 18662306a36Sopenharmony_ci init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx); 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci /* context */ 18962306a36Sopenharmony_ci init_p->cxts[0] = q->cxt; 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci /* SETUP */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci /* Setup-op general parameters */ 19462306a36Sopenharmony_ci setup_p->gen_params.spcl_id = vf->sp_cl_id; 19562306a36Sopenharmony_ci setup_p->gen_params.stat_id = vfq_stat_id(vf, q); 19662306a36Sopenharmony_ci setup_p->gen_params.fp_hsi = vf->fp_hsi; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci /* Setup-op flags: 19962306a36Sopenharmony_ci * collect statistics, zero statistics, local-switching, security, 20062306a36Sopenharmony_ci * OV for Flex10, RSS and MCAST for leading 20162306a36Sopenharmony_ci */ 20262306a36Sopenharmony_ci if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags)) 20362306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags); 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci /* for VFs, enable tx switching, bd coherency, and mac address 20662306a36Sopenharmony_ci * anti-spoofing 20762306a36Sopenharmony_ci */ 20862306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags); 20962306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags); 21062306a36Sopenharmony_ci if (vf->spoofchk) 21162306a36Sopenharmony_ci __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags); 21262306a36Sopenharmony_ci else 21362306a36Sopenharmony_ci __clear_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags); 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci /* Setup-op rx parameters */ 21662306a36Sopenharmony_ci if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) { 21762306a36Sopenharmony_ci struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params; 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci rxq_p->cl_qzone_id = vfq_qzone_id(vf, q); 22062306a36Sopenharmony_ci rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx); 22162306a36Sopenharmony_ci rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid); 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags)) 22462306a36Sopenharmony_ci rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES; 22562306a36Sopenharmony_ci } 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ci /* Setup-op tx parameters */ 22862306a36Sopenharmony_ci if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) { 22962306a36Sopenharmony_ci setup_p->txq_params.tss_leading_cl_id = vf->leading_rss; 23062306a36Sopenharmony_ci setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx); 23162306a36Sopenharmony_ci } 23262306a36Sopenharmony_ci} 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_cistatic int bnx2x_vf_queue_create(struct bnx2x *bp, 23562306a36Sopenharmony_ci struct bnx2x_virtf *vf, int qid, 23662306a36Sopenharmony_ci struct bnx2x_vf_queue_construct_params *qctor) 23762306a36Sopenharmony_ci{ 23862306a36Sopenharmony_ci struct bnx2x_queue_state_params *q_params; 23962306a36Sopenharmony_ci int rc = 0; 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid); 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci /* Prepare ramrod information */ 24462306a36Sopenharmony_ci q_params = &qctor->qstate; 24562306a36Sopenharmony_ci q_params->q_obj = &bnx2x_vfq(vf, qid, sp_obj); 24662306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &q_params->ramrod_flags); 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci if (bnx2x_get_q_logical_state(bp, q_params->q_obj) == 24962306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE) { 25062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "queue was already up. Aborting gracefully\n"); 25162306a36Sopenharmony_ci goto out; 25262306a36Sopenharmony_ci } 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci /* Run Queue 'construction' ramrods */ 25562306a36Sopenharmony_ci q_params->cmd = BNX2X_Q_CMD_INIT; 25662306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, q_params); 25762306a36Sopenharmony_ci if (rc) 25862306a36Sopenharmony_ci goto out; 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_ci memcpy(&q_params->params.setup, &qctor->prep_qsetup, 26162306a36Sopenharmony_ci sizeof(struct bnx2x_queue_setup_params)); 26262306a36Sopenharmony_ci q_params->cmd = BNX2X_Q_CMD_SETUP; 26362306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, q_params); 26462306a36Sopenharmony_ci if (rc) 26562306a36Sopenharmony_ci goto out; 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci /* enable interrupts */ 26862306a36Sopenharmony_ci bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, bnx2x_vfq(vf, qid, sb_idx)), 26962306a36Sopenharmony_ci USTORM_ID, 0, IGU_INT_ENABLE, 0); 27062306a36Sopenharmony_ciout: 27162306a36Sopenharmony_ci return rc; 27262306a36Sopenharmony_ci} 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_cistatic int bnx2x_vf_queue_destroy(struct bnx2x *bp, struct bnx2x_virtf *vf, 27562306a36Sopenharmony_ci int qid) 27662306a36Sopenharmony_ci{ 27762306a36Sopenharmony_ci enum bnx2x_queue_cmd cmds[] = {BNX2X_Q_CMD_HALT, 27862306a36Sopenharmony_ci BNX2X_Q_CMD_TERMINATE, 27962306a36Sopenharmony_ci BNX2X_Q_CMD_CFC_DEL}; 28062306a36Sopenharmony_ci struct bnx2x_queue_state_params q_params; 28162306a36Sopenharmony_ci int rc, i; 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ci /* Prepare ramrod information */ 28662306a36Sopenharmony_ci memset(&q_params, 0, sizeof(struct bnx2x_queue_state_params)); 28762306a36Sopenharmony_ci q_params.q_obj = &bnx2x_vfq(vf, qid, sp_obj); 28862306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci if (bnx2x_get_q_logical_state(bp, q_params.q_obj) == 29162306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_STOPPED) { 29262306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "queue was already stopped. Aborting gracefully\n"); 29362306a36Sopenharmony_ci goto out; 29462306a36Sopenharmony_ci } 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci /* Run Queue 'destruction' ramrods */ 29762306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(cmds); i++) { 29862306a36Sopenharmony_ci q_params.cmd = cmds[i]; 29962306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &q_params); 30062306a36Sopenharmony_ci if (rc) { 30162306a36Sopenharmony_ci BNX2X_ERR("Failed to run Queue command %d\n", cmds[i]); 30262306a36Sopenharmony_ci return rc; 30362306a36Sopenharmony_ci } 30462306a36Sopenharmony_ci } 30562306a36Sopenharmony_ciout: 30662306a36Sopenharmony_ci /* Clean Context */ 30762306a36Sopenharmony_ci if (bnx2x_vfq(vf, qid, cxt)) { 30862306a36Sopenharmony_ci bnx2x_vfq(vf, qid, cxt)->ustorm_ag_context.cdu_usage = 0; 30962306a36Sopenharmony_ci bnx2x_vfq(vf, qid, cxt)->xstorm_ag_context.cdu_reserved = 0; 31062306a36Sopenharmony_ci } 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci return 0; 31362306a36Sopenharmony_ci} 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_cistatic void 31662306a36Sopenharmony_cibnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid) 31762306a36Sopenharmony_ci{ 31862306a36Sopenharmony_ci struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid); 31962306a36Sopenharmony_ci if (vf) { 32062306a36Sopenharmony_ci /* the first igu entry belonging to VFs of this PF */ 32162306a36Sopenharmony_ci if (!BP_VFDB(bp)->first_vf_igu_entry) 32262306a36Sopenharmony_ci BP_VFDB(bp)->first_vf_igu_entry = igu_sb_id; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci /* the first igu entry belonging to this VF */ 32562306a36Sopenharmony_ci if (!vf_sb_count(vf)) 32662306a36Sopenharmony_ci vf->igu_base_id = igu_sb_id; 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci ++vf_sb_count(vf); 32962306a36Sopenharmony_ci ++vf->sb_count; 33062306a36Sopenharmony_ci } 33162306a36Sopenharmony_ci BP_VFDB(bp)->vf_sbs_pool++; 33262306a36Sopenharmony_ci} 33362306a36Sopenharmony_ci 33462306a36Sopenharmony_cistatic int bnx2x_vf_vlan_mac_clear(struct bnx2x *bp, struct bnx2x_virtf *vf, 33562306a36Sopenharmony_ci int qid, bool drv_only, int type) 33662306a36Sopenharmony_ci{ 33762306a36Sopenharmony_ci struct bnx2x_vlan_mac_ramrod_params ramrod; 33862306a36Sopenharmony_ci int rc; 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d] - deleting all %s\n", vf->abs_vfid, 34162306a36Sopenharmony_ci (type == BNX2X_VF_FILTER_VLAN_MAC) ? "VLAN-MACs" : 34262306a36Sopenharmony_ci (type == BNX2X_VF_FILTER_MAC) ? "MACs" : "VLANs"); 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci /* Prepare ramrod params */ 34562306a36Sopenharmony_ci memset(&ramrod, 0, sizeof(struct bnx2x_vlan_mac_ramrod_params)); 34662306a36Sopenharmony_ci if (type == BNX2X_VF_FILTER_VLAN_MAC) { 34762306a36Sopenharmony_ci set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags); 34862306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_mac_obj); 34962306a36Sopenharmony_ci } else if (type == BNX2X_VF_FILTER_MAC) { 35062306a36Sopenharmony_ci set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags); 35162306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj); 35262306a36Sopenharmony_ci } else { 35362306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj); 35462306a36Sopenharmony_ci } 35562306a36Sopenharmony_ci ramrod.user_req.cmd = BNX2X_VLAN_MAC_DEL; 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_ci set_bit(RAMROD_EXEC, &ramrod.ramrod_flags); 35862306a36Sopenharmony_ci if (drv_only) 35962306a36Sopenharmony_ci set_bit(RAMROD_DRV_CLR_ONLY, &ramrod.ramrod_flags); 36062306a36Sopenharmony_ci else 36162306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags); 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci /* Start deleting */ 36462306a36Sopenharmony_ci rc = ramrod.vlan_mac_obj->delete_all(bp, 36562306a36Sopenharmony_ci ramrod.vlan_mac_obj, 36662306a36Sopenharmony_ci &ramrod.user_req.vlan_mac_flags, 36762306a36Sopenharmony_ci &ramrod.ramrod_flags); 36862306a36Sopenharmony_ci if (rc) { 36962306a36Sopenharmony_ci BNX2X_ERR("Failed to delete all %s\n", 37062306a36Sopenharmony_ci (type == BNX2X_VF_FILTER_VLAN_MAC) ? "VLAN-MACs" : 37162306a36Sopenharmony_ci (type == BNX2X_VF_FILTER_MAC) ? "MACs" : "VLANs"); 37262306a36Sopenharmony_ci return rc; 37362306a36Sopenharmony_ci } 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_ci return 0; 37662306a36Sopenharmony_ci} 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_cistatic int bnx2x_vf_mac_vlan_config(struct bnx2x *bp, 37962306a36Sopenharmony_ci struct bnx2x_virtf *vf, int qid, 38062306a36Sopenharmony_ci struct bnx2x_vf_mac_vlan_filter *filter, 38162306a36Sopenharmony_ci bool drv_only) 38262306a36Sopenharmony_ci{ 38362306a36Sopenharmony_ci struct bnx2x_vlan_mac_ramrod_params ramrod; 38462306a36Sopenharmony_ci int rc; 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d] - %s a %s filter\n", 38762306a36Sopenharmony_ci vf->abs_vfid, filter->add ? "Adding" : "Deleting", 38862306a36Sopenharmony_ci (filter->type == BNX2X_VF_FILTER_VLAN_MAC) ? "VLAN-MAC" : 38962306a36Sopenharmony_ci (filter->type == BNX2X_VF_FILTER_MAC) ? "MAC" : "VLAN"); 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci /* Prepare ramrod params */ 39262306a36Sopenharmony_ci memset(&ramrod, 0, sizeof(struct bnx2x_vlan_mac_ramrod_params)); 39362306a36Sopenharmony_ci if (filter->type == BNX2X_VF_FILTER_VLAN_MAC) { 39462306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_mac_obj); 39562306a36Sopenharmony_ci ramrod.user_req.u.vlan.vlan = filter->vid; 39662306a36Sopenharmony_ci memcpy(&ramrod.user_req.u.mac.mac, filter->mac, ETH_ALEN); 39762306a36Sopenharmony_ci set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags); 39862306a36Sopenharmony_ci } else if (filter->type == BNX2X_VF_FILTER_VLAN) { 39962306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj); 40062306a36Sopenharmony_ci ramrod.user_req.u.vlan.vlan = filter->vid; 40162306a36Sopenharmony_ci } else { 40262306a36Sopenharmony_ci set_bit(BNX2X_ETH_MAC, &ramrod.user_req.vlan_mac_flags); 40362306a36Sopenharmony_ci ramrod.vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj); 40462306a36Sopenharmony_ci memcpy(&ramrod.user_req.u.mac.mac, filter->mac, ETH_ALEN); 40562306a36Sopenharmony_ci } 40662306a36Sopenharmony_ci ramrod.user_req.cmd = filter->add ? BNX2X_VLAN_MAC_ADD : 40762306a36Sopenharmony_ci BNX2X_VLAN_MAC_DEL; 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_ci set_bit(RAMROD_EXEC, &ramrod.ramrod_flags); 41062306a36Sopenharmony_ci if (drv_only) 41162306a36Sopenharmony_ci set_bit(RAMROD_DRV_CLR_ONLY, &ramrod.ramrod_flags); 41262306a36Sopenharmony_ci else 41362306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags); 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ci /* Add/Remove the filter */ 41662306a36Sopenharmony_ci rc = bnx2x_config_vlan_mac(bp, &ramrod); 41762306a36Sopenharmony_ci if (rc == -EEXIST) 41862306a36Sopenharmony_ci return 0; 41962306a36Sopenharmony_ci if (rc) { 42062306a36Sopenharmony_ci BNX2X_ERR("Failed to %s %s\n", 42162306a36Sopenharmony_ci filter->add ? "add" : "delete", 42262306a36Sopenharmony_ci (filter->type == BNX2X_VF_FILTER_VLAN_MAC) ? 42362306a36Sopenharmony_ci "VLAN-MAC" : 42462306a36Sopenharmony_ci (filter->type == BNX2X_VF_FILTER_MAC) ? 42562306a36Sopenharmony_ci "MAC" : "VLAN"); 42662306a36Sopenharmony_ci return rc; 42762306a36Sopenharmony_ci } 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci filter->applied = true; 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci return 0; 43262306a36Sopenharmony_ci} 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ciint bnx2x_vf_mac_vlan_config_list(struct bnx2x *bp, struct bnx2x_virtf *vf, 43562306a36Sopenharmony_ci struct bnx2x_vf_mac_vlan_filters *filters, 43662306a36Sopenharmony_ci int qid, bool drv_only) 43762306a36Sopenharmony_ci{ 43862306a36Sopenharmony_ci int rc = 0, i; 43962306a36Sopenharmony_ci 44062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ci if (!bnx2x_validate_vf_sp_objs(bp, vf, true)) 44362306a36Sopenharmony_ci return -EINVAL; 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ci /* Prepare ramrod params */ 44662306a36Sopenharmony_ci for (i = 0; i < filters->count; i++) { 44762306a36Sopenharmony_ci rc = bnx2x_vf_mac_vlan_config(bp, vf, qid, 44862306a36Sopenharmony_ci &filters->filters[i], drv_only); 44962306a36Sopenharmony_ci if (rc) 45062306a36Sopenharmony_ci break; 45162306a36Sopenharmony_ci } 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci /* Rollback if needed */ 45462306a36Sopenharmony_ci if (i != filters->count) { 45562306a36Sopenharmony_ci BNX2X_ERR("Managed only %d/%d filters - rolling back\n", 45662306a36Sopenharmony_ci i, filters->count); 45762306a36Sopenharmony_ci while (--i >= 0) { 45862306a36Sopenharmony_ci if (!filters->filters[i].applied) 45962306a36Sopenharmony_ci continue; 46062306a36Sopenharmony_ci filters->filters[i].add = !filters->filters[i].add; 46162306a36Sopenharmony_ci bnx2x_vf_mac_vlan_config(bp, vf, qid, 46262306a36Sopenharmony_ci &filters->filters[i], 46362306a36Sopenharmony_ci drv_only); 46462306a36Sopenharmony_ci } 46562306a36Sopenharmony_ci } 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci /* It's our responsibility to free the filters */ 46862306a36Sopenharmony_ci kfree(filters); 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci return rc; 47162306a36Sopenharmony_ci} 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ciint bnx2x_vf_queue_setup(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid, 47462306a36Sopenharmony_ci struct bnx2x_vf_queue_construct_params *qctor) 47562306a36Sopenharmony_ci{ 47662306a36Sopenharmony_ci int rc; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid); 47962306a36Sopenharmony_ci 48062306a36Sopenharmony_ci rc = bnx2x_vf_queue_create(bp, vf, qid, qctor); 48162306a36Sopenharmony_ci if (rc) 48262306a36Sopenharmony_ci goto op_err; 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci /* Schedule the configuration of any pending vlan filters */ 48562306a36Sopenharmony_ci bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_HYPERVISOR_VLAN, 48662306a36Sopenharmony_ci BNX2X_MSG_IOV); 48762306a36Sopenharmony_ci return 0; 48862306a36Sopenharmony_ciop_err: 48962306a36Sopenharmony_ci BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, rc); 49062306a36Sopenharmony_ci return rc; 49162306a36Sopenharmony_ci} 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_cistatic int bnx2x_vf_queue_flr(struct bnx2x *bp, struct bnx2x_virtf *vf, 49462306a36Sopenharmony_ci int qid) 49562306a36Sopenharmony_ci{ 49662306a36Sopenharmony_ci int rc; 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid); 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci /* If needed, clean the filtering data base */ 50162306a36Sopenharmony_ci if ((qid == LEADING_IDX) && 50262306a36Sopenharmony_ci bnx2x_validate_vf_sp_objs(bp, vf, false)) { 50362306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, true, 50462306a36Sopenharmony_ci BNX2X_VF_FILTER_VLAN_MAC); 50562306a36Sopenharmony_ci if (rc) 50662306a36Sopenharmony_ci goto op_err; 50762306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, true, 50862306a36Sopenharmony_ci BNX2X_VF_FILTER_VLAN); 50962306a36Sopenharmony_ci if (rc) 51062306a36Sopenharmony_ci goto op_err; 51162306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, true, 51262306a36Sopenharmony_ci BNX2X_VF_FILTER_MAC); 51362306a36Sopenharmony_ci if (rc) 51462306a36Sopenharmony_ci goto op_err; 51562306a36Sopenharmony_ci } 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci /* Terminate queue */ 51862306a36Sopenharmony_ci if (bnx2x_vfq(vf, qid, sp_obj).state != BNX2X_Q_STATE_RESET) { 51962306a36Sopenharmony_ci struct bnx2x_queue_state_params qstate; 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ci memset(&qstate, 0, sizeof(struct bnx2x_queue_state_params)); 52262306a36Sopenharmony_ci qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj); 52362306a36Sopenharmony_ci qstate.q_obj->state = BNX2X_Q_STATE_STOPPED; 52462306a36Sopenharmony_ci qstate.cmd = BNX2X_Q_CMD_TERMINATE; 52562306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &qstate.ramrod_flags); 52662306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &qstate); 52762306a36Sopenharmony_ci if (rc) 52862306a36Sopenharmony_ci goto op_err; 52962306a36Sopenharmony_ci } 53062306a36Sopenharmony_ci 53162306a36Sopenharmony_ci return 0; 53262306a36Sopenharmony_ciop_err: 53362306a36Sopenharmony_ci BNX2X_ERR("vf[%d:%d] error: rc %d\n", vf->abs_vfid, qid, rc); 53462306a36Sopenharmony_ci return rc; 53562306a36Sopenharmony_ci} 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ciint bnx2x_vf_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf, 53862306a36Sopenharmony_ci bnx2x_mac_addr_t *mcasts, int mc_num, bool drv_only) 53962306a36Sopenharmony_ci{ 54062306a36Sopenharmony_ci struct bnx2x_mcast_list_elem *mc = NULL; 54162306a36Sopenharmony_ci struct bnx2x_mcast_ramrod_params mcast; 54262306a36Sopenharmony_ci int rc, i; 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci /* Prepare Multicast command */ 54762306a36Sopenharmony_ci memset(&mcast, 0, sizeof(struct bnx2x_mcast_ramrod_params)); 54862306a36Sopenharmony_ci mcast.mcast_obj = &vf->mcast_obj; 54962306a36Sopenharmony_ci if (drv_only) 55062306a36Sopenharmony_ci set_bit(RAMROD_DRV_CLR_ONLY, &mcast.ramrod_flags); 55162306a36Sopenharmony_ci else 55262306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &mcast.ramrod_flags); 55362306a36Sopenharmony_ci if (mc_num) { 55462306a36Sopenharmony_ci mc = kcalloc(mc_num, sizeof(struct bnx2x_mcast_list_elem), 55562306a36Sopenharmony_ci GFP_KERNEL); 55662306a36Sopenharmony_ci if (!mc) { 55762306a36Sopenharmony_ci BNX2X_ERR("Cannot Configure multicasts due to lack of memory\n"); 55862306a36Sopenharmony_ci return -ENOMEM; 55962306a36Sopenharmony_ci } 56062306a36Sopenharmony_ci } 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_ci if (mc_num) { 56362306a36Sopenharmony_ci INIT_LIST_HEAD(&mcast.mcast_list); 56462306a36Sopenharmony_ci for (i = 0; i < mc_num; i++) { 56562306a36Sopenharmony_ci mc[i].mac = mcasts[i]; 56662306a36Sopenharmony_ci list_add_tail(&mc[i].link, 56762306a36Sopenharmony_ci &mcast.mcast_list); 56862306a36Sopenharmony_ci } 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci /* add new mcasts */ 57162306a36Sopenharmony_ci mcast.mcast_list_len = mc_num; 57262306a36Sopenharmony_ci rc = bnx2x_config_mcast(bp, &mcast, BNX2X_MCAST_CMD_SET); 57362306a36Sopenharmony_ci if (rc) 57462306a36Sopenharmony_ci BNX2X_ERR("Failed to set multicasts\n"); 57562306a36Sopenharmony_ci } else { 57662306a36Sopenharmony_ci /* clear existing mcasts */ 57762306a36Sopenharmony_ci rc = bnx2x_config_mcast(bp, &mcast, BNX2X_MCAST_CMD_DEL); 57862306a36Sopenharmony_ci if (rc) 57962306a36Sopenharmony_ci BNX2X_ERR("Failed to remove multicasts\n"); 58062306a36Sopenharmony_ci } 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci kfree(mc); 58362306a36Sopenharmony_ci 58462306a36Sopenharmony_ci return rc; 58562306a36Sopenharmony_ci} 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_cistatic void bnx2x_vf_prep_rx_mode(struct bnx2x *bp, u8 qid, 58862306a36Sopenharmony_ci struct bnx2x_rx_mode_ramrod_params *ramrod, 58962306a36Sopenharmony_ci struct bnx2x_virtf *vf, 59062306a36Sopenharmony_ci unsigned long accept_flags) 59162306a36Sopenharmony_ci{ 59262306a36Sopenharmony_ci struct bnx2x_vf_queue *vfq = vfq_get(vf, qid); 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci memset(ramrod, 0, sizeof(*ramrod)); 59562306a36Sopenharmony_ci ramrod->cid = vfq->cid; 59662306a36Sopenharmony_ci ramrod->cl_id = vfq_cl_id(vf, vfq); 59762306a36Sopenharmony_ci ramrod->rx_mode_obj = &bp->rx_mode_obj; 59862306a36Sopenharmony_ci ramrod->func_id = FW_VF_HANDLE(vf->abs_vfid); 59962306a36Sopenharmony_ci ramrod->rx_accept_flags = accept_flags; 60062306a36Sopenharmony_ci ramrod->tx_accept_flags = accept_flags; 60162306a36Sopenharmony_ci ramrod->pstate = &vf->filter_state; 60262306a36Sopenharmony_ci ramrod->state = BNX2X_FILTER_RX_MODE_PENDING; 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci set_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state); 60562306a36Sopenharmony_ci set_bit(RAMROD_RX, &ramrod->ramrod_flags); 60662306a36Sopenharmony_ci set_bit(RAMROD_TX, &ramrod->ramrod_flags); 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ci ramrod->rdata = bnx2x_vf_sp(bp, vf, rx_mode_rdata.e2); 60962306a36Sopenharmony_ci ramrod->rdata_mapping = bnx2x_vf_sp_map(bp, vf, rx_mode_rdata.e2); 61062306a36Sopenharmony_ci} 61162306a36Sopenharmony_ci 61262306a36Sopenharmony_ciint bnx2x_vf_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf, 61362306a36Sopenharmony_ci int qid, unsigned long accept_flags) 61462306a36Sopenharmony_ci{ 61562306a36Sopenharmony_ci struct bnx2x_rx_mode_ramrod_params ramrod; 61662306a36Sopenharmony_ci 61762306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci bnx2x_vf_prep_rx_mode(bp, qid, &ramrod, vf, accept_flags); 62062306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &ramrod.ramrod_flags); 62162306a36Sopenharmony_ci vfq_get(vf, qid)->accept_flags = ramrod.rx_accept_flags; 62262306a36Sopenharmony_ci return bnx2x_config_rx_mode(bp, &ramrod); 62362306a36Sopenharmony_ci} 62462306a36Sopenharmony_ci 62562306a36Sopenharmony_ciint bnx2x_vf_queue_teardown(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid) 62662306a36Sopenharmony_ci{ 62762306a36Sopenharmony_ci int rc; 62862306a36Sopenharmony_ci 62962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d:%d]\n", vf->abs_vfid, qid); 63062306a36Sopenharmony_ci 63162306a36Sopenharmony_ci /* Remove all classification configuration for leading queue */ 63262306a36Sopenharmony_ci if (qid == LEADING_IDX) { 63362306a36Sopenharmony_ci rc = bnx2x_vf_rxmode(bp, vf, qid, 0); 63462306a36Sopenharmony_ci if (rc) 63562306a36Sopenharmony_ci goto op_err; 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_ci /* Remove filtering if feasible */ 63862306a36Sopenharmony_ci if (bnx2x_validate_vf_sp_objs(bp, vf, true)) { 63962306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, 64062306a36Sopenharmony_ci false, 64162306a36Sopenharmony_ci BNX2X_VF_FILTER_VLAN_MAC); 64262306a36Sopenharmony_ci if (rc) 64362306a36Sopenharmony_ci goto op_err; 64462306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, 64562306a36Sopenharmony_ci false, 64662306a36Sopenharmony_ci BNX2X_VF_FILTER_VLAN); 64762306a36Sopenharmony_ci if (rc) 64862306a36Sopenharmony_ci goto op_err; 64962306a36Sopenharmony_ci rc = bnx2x_vf_vlan_mac_clear(bp, vf, qid, 65062306a36Sopenharmony_ci false, 65162306a36Sopenharmony_ci BNX2X_VF_FILTER_MAC); 65262306a36Sopenharmony_ci if (rc) 65362306a36Sopenharmony_ci goto op_err; 65462306a36Sopenharmony_ci rc = bnx2x_vf_mcast(bp, vf, NULL, 0, false); 65562306a36Sopenharmony_ci if (rc) 65662306a36Sopenharmony_ci goto op_err; 65762306a36Sopenharmony_ci } 65862306a36Sopenharmony_ci } 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci /* Destroy queue */ 66162306a36Sopenharmony_ci rc = bnx2x_vf_queue_destroy(bp, vf, qid); 66262306a36Sopenharmony_ci if (rc) 66362306a36Sopenharmony_ci goto op_err; 66462306a36Sopenharmony_ci return rc; 66562306a36Sopenharmony_ciop_err: 66662306a36Sopenharmony_ci BNX2X_ERR("vf[%d:%d] error: rc %d\n", 66762306a36Sopenharmony_ci vf->abs_vfid, qid, rc); 66862306a36Sopenharmony_ci return rc; 66962306a36Sopenharmony_ci} 67062306a36Sopenharmony_ci 67162306a36Sopenharmony_ci/* VF enable primitives 67262306a36Sopenharmony_ci * when pretend is required the caller is responsible 67362306a36Sopenharmony_ci * for calling pretend prior to calling these routines 67462306a36Sopenharmony_ci */ 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ci/* internal vf enable - until vf is enabled internally all transactions 67762306a36Sopenharmony_ci * are blocked. This routine should always be called last with pretend. 67862306a36Sopenharmony_ci */ 67962306a36Sopenharmony_cistatic void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable) 68062306a36Sopenharmony_ci{ 68162306a36Sopenharmony_ci REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0); 68262306a36Sopenharmony_ci} 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci/* clears vf error in all semi blocks */ 68562306a36Sopenharmony_cistatic void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid) 68662306a36Sopenharmony_ci{ 68762306a36Sopenharmony_ci REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid); 68862306a36Sopenharmony_ci REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid); 68962306a36Sopenharmony_ci REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid); 69062306a36Sopenharmony_ci REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid); 69162306a36Sopenharmony_ci} 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_cistatic void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid) 69462306a36Sopenharmony_ci{ 69562306a36Sopenharmony_ci u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5; 69662306a36Sopenharmony_ci u32 was_err_reg = 0; 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ci switch (was_err_group) { 69962306a36Sopenharmony_ci case 0: 70062306a36Sopenharmony_ci was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR; 70162306a36Sopenharmony_ci break; 70262306a36Sopenharmony_ci case 1: 70362306a36Sopenharmony_ci was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR; 70462306a36Sopenharmony_ci break; 70562306a36Sopenharmony_ci case 2: 70662306a36Sopenharmony_ci was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR; 70762306a36Sopenharmony_ci break; 70862306a36Sopenharmony_ci case 3: 70962306a36Sopenharmony_ci was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR; 71062306a36Sopenharmony_ci break; 71162306a36Sopenharmony_ci } 71262306a36Sopenharmony_ci REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f)); 71362306a36Sopenharmony_ci} 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_cistatic void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf) 71662306a36Sopenharmony_ci{ 71762306a36Sopenharmony_ci int i; 71862306a36Sopenharmony_ci u32 val; 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_ci /* Set VF masks and configuration - pretend */ 72162306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid)); 72262306a36Sopenharmony_ci 72362306a36Sopenharmony_ci REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0); 72462306a36Sopenharmony_ci REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0); 72562306a36Sopenharmony_ci REG_WR(bp, IGU_REG_SB_MASK_LSB, 0); 72662306a36Sopenharmony_ci REG_WR(bp, IGU_REG_SB_MASK_MSB, 0); 72762306a36Sopenharmony_ci REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0); 72862306a36Sopenharmony_ci REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0); 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ci val = REG_RD(bp, IGU_REG_VF_CONFIGURATION); 73162306a36Sopenharmony_ci val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN); 73262306a36Sopenharmony_ci val &= ~IGU_VF_CONF_PARENT_MASK; 73362306a36Sopenharmony_ci val |= (BP_ABS_FUNC(bp) >> 1) << IGU_VF_CONF_PARENT_SHIFT; 73462306a36Sopenharmony_ci REG_WR(bp, IGU_REG_VF_CONFIGURATION, val); 73562306a36Sopenharmony_ci 73662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 73762306a36Sopenharmony_ci "value in IGU_REG_VF_CONFIGURATION of vf %d after write is 0x%08x\n", 73862306a36Sopenharmony_ci vf->abs_vfid, val); 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci /* iterate over all queues, clear sb consumer */ 74362306a36Sopenharmony_ci for (i = 0; i < vf_sb_count(vf); i++) { 74462306a36Sopenharmony_ci u8 igu_sb_id = vf_igu_sb(vf, i); 74562306a36Sopenharmony_ci 74662306a36Sopenharmony_ci /* zero prod memory */ 74762306a36Sopenharmony_ci REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0); 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci /* clear sb state machine */ 75062306a36Sopenharmony_ci bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id, 75162306a36Sopenharmony_ci false /* VF */); 75262306a36Sopenharmony_ci 75362306a36Sopenharmony_ci /* disable + update */ 75462306a36Sopenharmony_ci bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0, 75562306a36Sopenharmony_ci IGU_INT_DISABLE, 1); 75662306a36Sopenharmony_ci } 75762306a36Sopenharmony_ci} 75862306a36Sopenharmony_ci 75962306a36Sopenharmony_civoid bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid) 76062306a36Sopenharmony_ci{ 76162306a36Sopenharmony_ci u16 abs_fid; 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci abs_fid = FW_VF_HANDLE(abs_vfid); 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_ci /* set the VF-PF association in the FW */ 76662306a36Sopenharmony_ci storm_memset_vf_to_pf(bp, abs_fid, BP_FUNC(bp)); 76762306a36Sopenharmony_ci storm_memset_func_en(bp, abs_fid, 1); 76862306a36Sopenharmony_ci 76962306a36Sopenharmony_ci /* Invalidate fp_hsi version for vfs */ 77062306a36Sopenharmony_ci if (bp->fw_cap & FW_CAP_INVALIDATE_VF_FP_HSI) 77162306a36Sopenharmony_ci REG_WR8(bp, BAR_XSTRORM_INTMEM + 77262306a36Sopenharmony_ci XSTORM_ETH_FUNCTION_INFO_FP_HSI_VALID_E2_OFFSET(abs_fid), 0); 77362306a36Sopenharmony_ci 77462306a36Sopenharmony_ci /* clear vf errors*/ 77562306a36Sopenharmony_ci bnx2x_vf_semi_clear_err(bp, abs_vfid); 77662306a36Sopenharmony_ci bnx2x_vf_pglue_clear_err(bp, abs_vfid); 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ci /* internal vf-enable - pretend */ 77962306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid)); 78062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid); 78162306a36Sopenharmony_ci bnx2x_vf_enable_internal(bp, true); 78262306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 78362306a36Sopenharmony_ci} 78462306a36Sopenharmony_ci 78562306a36Sopenharmony_cistatic void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf) 78662306a36Sopenharmony_ci{ 78762306a36Sopenharmony_ci /* Reset vf in IGU interrupts are still disabled */ 78862306a36Sopenharmony_ci bnx2x_vf_igu_reset(bp, vf); 78962306a36Sopenharmony_ci 79062306a36Sopenharmony_ci /* pretend to enable the vf with the PBF */ 79162306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid)); 79262306a36Sopenharmony_ci REG_WR(bp, PBF_REG_DISABLE_VF, 0); 79362306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 79462306a36Sopenharmony_ci} 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_cistatic u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid) 79762306a36Sopenharmony_ci{ 79862306a36Sopenharmony_ci struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid); 79962306a36Sopenharmony_ci struct pci_dev *dev; 80062306a36Sopenharmony_ci bool pending; 80162306a36Sopenharmony_ci 80262306a36Sopenharmony_ci if (!vf) 80362306a36Sopenharmony_ci return false; 80462306a36Sopenharmony_ci 80562306a36Sopenharmony_ci dev = pci_get_domain_bus_and_slot(vf->domain, vf->bus, vf->devfn); 80662306a36Sopenharmony_ci if (!dev) 80762306a36Sopenharmony_ci return false; 80862306a36Sopenharmony_ci pending = bnx2x_is_pcie_pending(dev); 80962306a36Sopenharmony_ci pci_dev_put(dev); 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_ci return pending; 81262306a36Sopenharmony_ci} 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ciint bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid) 81562306a36Sopenharmony_ci{ 81662306a36Sopenharmony_ci /* Verify no pending pci transactions */ 81762306a36Sopenharmony_ci if (bnx2x_vf_is_pcie_pending(bp, abs_vfid)) 81862306a36Sopenharmony_ci BNX2X_ERR("PCIE Transactions still pending\n"); 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_ci return 0; 82162306a36Sopenharmony_ci} 82262306a36Sopenharmony_ci 82362306a36Sopenharmony_ci/* must be called after the number of PF queues and the number of VFs are 82462306a36Sopenharmony_ci * both known 82562306a36Sopenharmony_ci */ 82662306a36Sopenharmony_cistatic void 82762306a36Sopenharmony_cibnx2x_iov_static_resc(struct bnx2x *bp, struct bnx2x_virtf *vf) 82862306a36Sopenharmony_ci{ 82962306a36Sopenharmony_ci struct vf_pf_resc_request *resc = &vf->alloc_resc; 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci /* will be set only during VF-ACQUIRE */ 83262306a36Sopenharmony_ci resc->num_rxqs = 0; 83362306a36Sopenharmony_ci resc->num_txqs = 0; 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_ci resc->num_mac_filters = VF_MAC_CREDIT_CNT; 83662306a36Sopenharmony_ci resc->num_vlan_filters = VF_VLAN_CREDIT_CNT; 83762306a36Sopenharmony_ci 83862306a36Sopenharmony_ci /* no real limitation */ 83962306a36Sopenharmony_ci resc->num_mc_filters = 0; 84062306a36Sopenharmony_ci 84162306a36Sopenharmony_ci /* num_sbs already set */ 84262306a36Sopenharmony_ci resc->num_sbs = vf->sb_count; 84362306a36Sopenharmony_ci} 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci/* FLR routines: */ 84662306a36Sopenharmony_cistatic void bnx2x_vf_free_resc(struct bnx2x *bp, struct bnx2x_virtf *vf) 84762306a36Sopenharmony_ci{ 84862306a36Sopenharmony_ci /* reset the state variables */ 84962306a36Sopenharmony_ci bnx2x_iov_static_resc(bp, vf); 85062306a36Sopenharmony_ci vf->state = VF_FREE; 85162306a36Sopenharmony_ci} 85262306a36Sopenharmony_ci 85362306a36Sopenharmony_cistatic void bnx2x_vf_flr_clnup_hw(struct bnx2x *bp, struct bnx2x_virtf *vf) 85462306a36Sopenharmony_ci{ 85562306a36Sopenharmony_ci u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp); 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci /* DQ usage counter */ 85862306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid)); 85962306a36Sopenharmony_ci bnx2x_flr_clnup_poll_hw_counter(bp, DORQ_REG_VF_USAGE_CNT, 86062306a36Sopenharmony_ci "DQ VF usage counter timed out", 86162306a36Sopenharmony_ci poll_cnt); 86262306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 86362306a36Sopenharmony_ci 86462306a36Sopenharmony_ci /* FW cleanup command - poll for the results */ 86562306a36Sopenharmony_ci if (bnx2x_send_final_clnup(bp, (u8)FW_VF_HANDLE(vf->abs_vfid), 86662306a36Sopenharmony_ci poll_cnt)) 86762306a36Sopenharmony_ci BNX2X_ERR("VF[%d] Final cleanup timed-out\n", vf->abs_vfid); 86862306a36Sopenharmony_ci 86962306a36Sopenharmony_ci /* verify TX hw is flushed */ 87062306a36Sopenharmony_ci bnx2x_tx_hw_flushed(bp, poll_cnt); 87162306a36Sopenharmony_ci} 87262306a36Sopenharmony_ci 87362306a36Sopenharmony_cistatic void bnx2x_vf_flr(struct bnx2x *bp, struct bnx2x_virtf *vf) 87462306a36Sopenharmony_ci{ 87562306a36Sopenharmony_ci int rc, i; 87662306a36Sopenharmony_ci 87762306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 87862306a36Sopenharmony_ci 87962306a36Sopenharmony_ci /* the cleanup operations are valid if and only if the VF 88062306a36Sopenharmony_ci * was first acquired. 88162306a36Sopenharmony_ci */ 88262306a36Sopenharmony_ci for (i = 0; i < vf_rxq_count(vf); i++) { 88362306a36Sopenharmony_ci rc = bnx2x_vf_queue_flr(bp, vf, i); 88462306a36Sopenharmony_ci if (rc) 88562306a36Sopenharmony_ci goto out; 88662306a36Sopenharmony_ci } 88762306a36Sopenharmony_ci 88862306a36Sopenharmony_ci /* remove multicasts */ 88962306a36Sopenharmony_ci bnx2x_vf_mcast(bp, vf, NULL, 0, true); 89062306a36Sopenharmony_ci 89162306a36Sopenharmony_ci /* dispatch final cleanup and wait for HW queues to flush */ 89262306a36Sopenharmony_ci bnx2x_vf_flr_clnup_hw(bp, vf); 89362306a36Sopenharmony_ci 89462306a36Sopenharmony_ci /* release VF resources */ 89562306a36Sopenharmony_ci bnx2x_vf_free_resc(bp, vf); 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ci vf->malicious = false; 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ci /* re-open the mailbox */ 90062306a36Sopenharmony_ci bnx2x_vf_enable_mbx(bp, vf->abs_vfid); 90162306a36Sopenharmony_ci return; 90262306a36Sopenharmony_ciout: 90362306a36Sopenharmony_ci BNX2X_ERR("vf[%d:%d] failed flr: rc %d\n", 90462306a36Sopenharmony_ci vf->abs_vfid, i, rc); 90562306a36Sopenharmony_ci} 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_cistatic void bnx2x_vf_flr_clnup(struct bnx2x *bp) 90862306a36Sopenharmony_ci{ 90962306a36Sopenharmony_ci struct bnx2x_virtf *vf; 91062306a36Sopenharmony_ci int i; 91162306a36Sopenharmony_ci 91262306a36Sopenharmony_ci for (i = 0; i < BNX2X_NR_VIRTFN(bp); i++) { 91362306a36Sopenharmony_ci /* VF should be RESET & in FLR cleanup states */ 91462306a36Sopenharmony_ci if (bnx2x_vf(bp, i, state) != VF_RESET || 91562306a36Sopenharmony_ci !bnx2x_vf(bp, i, flr_clnup_stage)) 91662306a36Sopenharmony_ci continue; 91762306a36Sopenharmony_ci 91862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "next vf to cleanup: %d. Num of vfs: %d\n", 91962306a36Sopenharmony_ci i, BNX2X_NR_VIRTFN(bp)); 92062306a36Sopenharmony_ci 92162306a36Sopenharmony_ci vf = BP_VF(bp, i); 92262306a36Sopenharmony_ci 92362306a36Sopenharmony_ci /* lock the vf pf channel */ 92462306a36Sopenharmony_ci bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR); 92562306a36Sopenharmony_ci 92662306a36Sopenharmony_ci /* invoke the VF FLR SM */ 92762306a36Sopenharmony_ci bnx2x_vf_flr(bp, vf); 92862306a36Sopenharmony_ci 92962306a36Sopenharmony_ci /* mark the VF to be ACKED and continue */ 93062306a36Sopenharmony_ci vf->flr_clnup_stage = false; 93162306a36Sopenharmony_ci bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR); 93262306a36Sopenharmony_ci } 93362306a36Sopenharmony_ci 93462306a36Sopenharmony_ci /* Acknowledge the handled VFs. 93562306a36Sopenharmony_ci * we are acknowledge all the vfs which an flr was requested for, even 93662306a36Sopenharmony_ci * if amongst them there are such that we never opened, since the mcp 93762306a36Sopenharmony_ci * will interrupt us immediately again if we only ack some of the bits, 93862306a36Sopenharmony_ci * resulting in an endless loop. This can happen for example in KVM 93962306a36Sopenharmony_ci * where an 'all ones' flr request is sometimes given by hyper visor 94062306a36Sopenharmony_ci */ 94162306a36Sopenharmony_ci DP(BNX2X_MSG_MCP, "DRV_STATUS_VF_DISABLED ACK for vfs 0x%x 0x%x\n", 94262306a36Sopenharmony_ci bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]); 94362306a36Sopenharmony_ci for (i = 0; i < FLRD_VFS_DWORDS; i++) 94462306a36Sopenharmony_ci SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 94562306a36Sopenharmony_ci bp->vfdb->flrd_vfs[i]); 94662306a36Sopenharmony_ci 94762306a36Sopenharmony_ci bnx2x_fw_command(bp, DRV_MSG_CODE_VF_DISABLED_DONE, 0); 94862306a36Sopenharmony_ci 94962306a36Sopenharmony_ci /* clear the acked bits - better yet if the MCP implemented 95062306a36Sopenharmony_ci * write to clear semantics 95162306a36Sopenharmony_ci */ 95262306a36Sopenharmony_ci for (i = 0; i < FLRD_VFS_DWORDS; i++) 95362306a36Sopenharmony_ci SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 0); 95462306a36Sopenharmony_ci} 95562306a36Sopenharmony_ci 95662306a36Sopenharmony_civoid bnx2x_vf_handle_flr_event(struct bnx2x *bp) 95762306a36Sopenharmony_ci{ 95862306a36Sopenharmony_ci int i; 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_ci /* Read FLR'd VFs */ 96162306a36Sopenharmony_ci for (i = 0; i < FLRD_VFS_DWORDS; i++) 96262306a36Sopenharmony_ci bp->vfdb->flrd_vfs[i] = SHMEM2_RD(bp, mcp_vf_disabled[i]); 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_ci DP(BNX2X_MSG_MCP, 96562306a36Sopenharmony_ci "DRV_STATUS_VF_DISABLED received for vfs 0x%x 0x%x\n", 96662306a36Sopenharmony_ci bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]); 96762306a36Sopenharmony_ci 96862306a36Sopenharmony_ci for_each_vf(bp, i) { 96962306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, i); 97062306a36Sopenharmony_ci u32 reset = 0; 97162306a36Sopenharmony_ci 97262306a36Sopenharmony_ci if (vf->abs_vfid < 32) 97362306a36Sopenharmony_ci reset = bp->vfdb->flrd_vfs[0] & (1 << vf->abs_vfid); 97462306a36Sopenharmony_ci else 97562306a36Sopenharmony_ci reset = bp->vfdb->flrd_vfs[1] & 97662306a36Sopenharmony_ci (1 << (vf->abs_vfid - 32)); 97762306a36Sopenharmony_ci 97862306a36Sopenharmony_ci if (reset) { 97962306a36Sopenharmony_ci /* set as reset and ready for cleanup */ 98062306a36Sopenharmony_ci vf->state = VF_RESET; 98162306a36Sopenharmony_ci vf->flr_clnup_stage = true; 98262306a36Sopenharmony_ci 98362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 98462306a36Sopenharmony_ci "Initiating Final cleanup for VF %d\n", 98562306a36Sopenharmony_ci vf->abs_vfid); 98662306a36Sopenharmony_ci } 98762306a36Sopenharmony_ci } 98862306a36Sopenharmony_ci 98962306a36Sopenharmony_ci /* do the FLR cleanup for all marked VFs*/ 99062306a36Sopenharmony_ci bnx2x_vf_flr_clnup(bp); 99162306a36Sopenharmony_ci} 99262306a36Sopenharmony_ci 99362306a36Sopenharmony_ci/* IOV global initialization routines */ 99462306a36Sopenharmony_civoid bnx2x_iov_init_dq(struct bnx2x *bp) 99562306a36Sopenharmony_ci{ 99662306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 99762306a36Sopenharmony_ci return; 99862306a36Sopenharmony_ci 99962306a36Sopenharmony_ci /* Set the DQ such that the CID reflect the abs_vfid */ 100062306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0); 100162306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS)); 100262306a36Sopenharmony_ci 100362306a36Sopenharmony_ci /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to 100462306a36Sopenharmony_ci * the PF L2 queues 100562306a36Sopenharmony_ci */ 100662306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID); 100762306a36Sopenharmony_ci 100862306a36Sopenharmony_ci /* The VF window size is the log2 of the max number of CIDs per VF */ 100962306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND); 101062306a36Sopenharmony_ci 101162306a36Sopenharmony_ci /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match 101262306a36Sopenharmony_ci * the Pf doorbell size although the 2 are independent. 101362306a36Sopenharmony_ci */ 101462306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST, 3); 101562306a36Sopenharmony_ci 101662306a36Sopenharmony_ci /* No security checks for now - 101762306a36Sopenharmony_ci * configure single rule (out of 16) mask = 0x1, value = 0x0, 101862306a36Sopenharmony_ci * CID range 0 - 0x1ffff 101962306a36Sopenharmony_ci */ 102062306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1); 102162306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0); 102262306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0); 102362306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff); 102462306a36Sopenharmony_ci 102562306a36Sopenharmony_ci /* set the VF doorbell threshold. This threshold represents the amount 102662306a36Sopenharmony_ci * of doorbells allowed in the main DORQ fifo for a specific VF. 102762306a36Sopenharmony_ci */ 102862306a36Sopenharmony_ci REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 64); 102962306a36Sopenharmony_ci} 103062306a36Sopenharmony_ci 103162306a36Sopenharmony_civoid bnx2x_iov_init_dmae(struct bnx2x *bp) 103262306a36Sopenharmony_ci{ 103362306a36Sopenharmony_ci if (pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV)) 103462306a36Sopenharmony_ci REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0); 103562306a36Sopenharmony_ci} 103662306a36Sopenharmony_ci 103762306a36Sopenharmony_cistatic int bnx2x_vf_domain(struct bnx2x *bp, int vfid) 103862306a36Sopenharmony_ci{ 103962306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 104062306a36Sopenharmony_ci 104162306a36Sopenharmony_ci return pci_domain_nr(dev->bus); 104262306a36Sopenharmony_ci} 104362306a36Sopenharmony_ci 104462306a36Sopenharmony_cistatic int bnx2x_vf_bus(struct bnx2x *bp, int vfid) 104562306a36Sopenharmony_ci{ 104662306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 104762306a36Sopenharmony_ci struct bnx2x_sriov *iov = &bp->vfdb->sriov; 104862306a36Sopenharmony_ci 104962306a36Sopenharmony_ci return dev->bus->number + ((dev->devfn + iov->offset + 105062306a36Sopenharmony_ci iov->stride * vfid) >> 8); 105162306a36Sopenharmony_ci} 105262306a36Sopenharmony_ci 105362306a36Sopenharmony_cistatic int bnx2x_vf_devfn(struct bnx2x *bp, int vfid) 105462306a36Sopenharmony_ci{ 105562306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 105662306a36Sopenharmony_ci struct bnx2x_sriov *iov = &bp->vfdb->sriov; 105762306a36Sopenharmony_ci 105862306a36Sopenharmony_ci return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff; 105962306a36Sopenharmony_ci} 106062306a36Sopenharmony_ci 106162306a36Sopenharmony_cistatic void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf) 106262306a36Sopenharmony_ci{ 106362306a36Sopenharmony_ci int i, n; 106462306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 106562306a36Sopenharmony_ci struct bnx2x_sriov *iov = &bp->vfdb->sriov; 106662306a36Sopenharmony_ci 106762306a36Sopenharmony_ci for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) { 106862306a36Sopenharmony_ci u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i); 106962306a36Sopenharmony_ci u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i); 107062306a36Sopenharmony_ci 107162306a36Sopenharmony_ci size /= iov->total; 107262306a36Sopenharmony_ci vf->bars[n].bar = start + size * vf->abs_vfid; 107362306a36Sopenharmony_ci vf->bars[n].size = size; 107462306a36Sopenharmony_ci } 107562306a36Sopenharmony_ci} 107662306a36Sopenharmony_ci 107762306a36Sopenharmony_cistatic int 107862306a36Sopenharmony_cibnx2x_get_vf_igu_cam_info(struct bnx2x *bp) 107962306a36Sopenharmony_ci{ 108062306a36Sopenharmony_ci int sb_id; 108162306a36Sopenharmony_ci u32 val; 108262306a36Sopenharmony_ci u8 fid, current_pf = 0; 108362306a36Sopenharmony_ci 108462306a36Sopenharmony_ci /* IGU in normal mode - read CAM */ 108562306a36Sopenharmony_ci for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) { 108662306a36Sopenharmony_ci val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4); 108762306a36Sopenharmony_ci if (!(val & IGU_REG_MAPPING_MEMORY_VALID)) 108862306a36Sopenharmony_ci continue; 108962306a36Sopenharmony_ci fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID); 109062306a36Sopenharmony_ci if (fid & IGU_FID_ENCODE_IS_PF) 109162306a36Sopenharmony_ci current_pf = fid & IGU_FID_PF_NUM_MASK; 109262306a36Sopenharmony_ci else if (current_pf == BP_FUNC(bp)) 109362306a36Sopenharmony_ci bnx2x_vf_set_igu_info(bp, sb_id, 109462306a36Sopenharmony_ci (fid & IGU_FID_VF_NUM_MASK)); 109562306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n", 109662306a36Sopenharmony_ci ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"), 109762306a36Sopenharmony_ci ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) : 109862306a36Sopenharmony_ci (fid & IGU_FID_VF_NUM_MASK)), sb_id, 109962306a36Sopenharmony_ci GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)); 110062306a36Sopenharmony_ci } 110162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf_sbs_pool is %d\n", BP_VFDB(bp)->vf_sbs_pool); 110262306a36Sopenharmony_ci return BP_VFDB(bp)->vf_sbs_pool; 110362306a36Sopenharmony_ci} 110462306a36Sopenharmony_ci 110562306a36Sopenharmony_cistatic void __bnx2x_iov_free_vfdb(struct bnx2x *bp) 110662306a36Sopenharmony_ci{ 110762306a36Sopenharmony_ci if (bp->vfdb) { 110862306a36Sopenharmony_ci kfree(bp->vfdb->vfqs); 110962306a36Sopenharmony_ci kfree(bp->vfdb->vfs); 111062306a36Sopenharmony_ci kfree(bp->vfdb); 111162306a36Sopenharmony_ci } 111262306a36Sopenharmony_ci bp->vfdb = NULL; 111362306a36Sopenharmony_ci} 111462306a36Sopenharmony_ci 111562306a36Sopenharmony_cistatic int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov) 111662306a36Sopenharmony_ci{ 111762306a36Sopenharmony_ci int pos; 111862306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 111962306a36Sopenharmony_ci 112062306a36Sopenharmony_ci pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV); 112162306a36Sopenharmony_ci if (!pos) { 112262306a36Sopenharmony_ci BNX2X_ERR("failed to find SRIOV capability in device\n"); 112362306a36Sopenharmony_ci return -ENODEV; 112462306a36Sopenharmony_ci } 112562306a36Sopenharmony_ci 112662306a36Sopenharmony_ci iov->pos = pos; 112762306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos); 112862306a36Sopenharmony_ci pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl); 112962306a36Sopenharmony_ci pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total); 113062306a36Sopenharmony_ci pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial); 113162306a36Sopenharmony_ci pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset); 113262306a36Sopenharmony_ci pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride); 113362306a36Sopenharmony_ci pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz); 113462306a36Sopenharmony_ci pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap); 113562306a36Sopenharmony_ci pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link); 113662306a36Sopenharmony_ci 113762306a36Sopenharmony_ci return 0; 113862306a36Sopenharmony_ci} 113962306a36Sopenharmony_ci 114062306a36Sopenharmony_cistatic int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov) 114162306a36Sopenharmony_ci{ 114262306a36Sopenharmony_ci u32 val; 114362306a36Sopenharmony_ci 114462306a36Sopenharmony_ci /* read the SRIOV capability structure 114562306a36Sopenharmony_ci * The fields can be read via configuration read or 114662306a36Sopenharmony_ci * directly from the device (starting at offset PCICFG_OFFSET) 114762306a36Sopenharmony_ci */ 114862306a36Sopenharmony_ci if (bnx2x_sriov_pci_cfg_info(bp, iov)) 114962306a36Sopenharmony_ci return -ENODEV; 115062306a36Sopenharmony_ci 115162306a36Sopenharmony_ci /* get the number of SRIOV bars */ 115262306a36Sopenharmony_ci iov->nres = 0; 115362306a36Sopenharmony_ci 115462306a36Sopenharmony_ci /* read the first_vfid */ 115562306a36Sopenharmony_ci val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF); 115662306a36Sopenharmony_ci iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK) 115762306a36Sopenharmony_ci * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp)); 115862306a36Sopenharmony_ci 115962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 116062306a36Sopenharmony_ci "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", 116162306a36Sopenharmony_ci BP_FUNC(bp), 116262306a36Sopenharmony_ci iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total, 116362306a36Sopenharmony_ci iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz); 116462306a36Sopenharmony_ci 116562306a36Sopenharmony_ci return 0; 116662306a36Sopenharmony_ci} 116762306a36Sopenharmony_ci 116862306a36Sopenharmony_ci/* must be called after PF bars are mapped */ 116962306a36Sopenharmony_ciint bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param, 117062306a36Sopenharmony_ci int num_vfs_param) 117162306a36Sopenharmony_ci{ 117262306a36Sopenharmony_ci int err, i; 117362306a36Sopenharmony_ci struct bnx2x_sriov *iov; 117462306a36Sopenharmony_ci struct pci_dev *dev = bp->pdev; 117562306a36Sopenharmony_ci 117662306a36Sopenharmony_ci bp->vfdb = NULL; 117762306a36Sopenharmony_ci 117862306a36Sopenharmony_ci /* verify is pf */ 117962306a36Sopenharmony_ci if (IS_VF(bp)) 118062306a36Sopenharmony_ci return 0; 118162306a36Sopenharmony_ci 118262306a36Sopenharmony_ci /* verify sriov capability is present in configuration space */ 118362306a36Sopenharmony_ci if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV)) 118462306a36Sopenharmony_ci return 0; 118562306a36Sopenharmony_ci 118662306a36Sopenharmony_ci /* verify chip revision */ 118762306a36Sopenharmony_ci if (CHIP_IS_E1x(bp)) 118862306a36Sopenharmony_ci return 0; 118962306a36Sopenharmony_ci 119062306a36Sopenharmony_ci /* check if SRIOV support is turned off */ 119162306a36Sopenharmony_ci if (!num_vfs_param) 119262306a36Sopenharmony_ci return 0; 119362306a36Sopenharmony_ci 119462306a36Sopenharmony_ci /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */ 119562306a36Sopenharmony_ci if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) { 119662306a36Sopenharmony_ci BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n", 119762306a36Sopenharmony_ci BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID); 119862306a36Sopenharmony_ci return 0; 119962306a36Sopenharmony_ci } 120062306a36Sopenharmony_ci 120162306a36Sopenharmony_ci /* SRIOV can be enabled only with MSIX */ 120262306a36Sopenharmony_ci if (int_mode_param == BNX2X_INT_MODE_MSI || 120362306a36Sopenharmony_ci int_mode_param == BNX2X_INT_MODE_INTX) { 120462306a36Sopenharmony_ci BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n"); 120562306a36Sopenharmony_ci return 0; 120662306a36Sopenharmony_ci } 120762306a36Sopenharmony_ci 120862306a36Sopenharmony_ci /* verify ari is enabled */ 120962306a36Sopenharmony_ci if (!pci_ari_enabled(bp->pdev->bus)) { 121062306a36Sopenharmony_ci BNX2X_ERR("ARI not supported (check pci bridge ARI forwarding), SRIOV can not be enabled\n"); 121162306a36Sopenharmony_ci return 0; 121262306a36Sopenharmony_ci } 121362306a36Sopenharmony_ci 121462306a36Sopenharmony_ci /* verify igu is in normal mode */ 121562306a36Sopenharmony_ci if (CHIP_INT_MODE_IS_BC(bp)) { 121662306a36Sopenharmony_ci BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n"); 121762306a36Sopenharmony_ci return 0; 121862306a36Sopenharmony_ci } 121962306a36Sopenharmony_ci 122062306a36Sopenharmony_ci /* allocate the vfs database */ 122162306a36Sopenharmony_ci bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL); 122262306a36Sopenharmony_ci if (!bp->vfdb) { 122362306a36Sopenharmony_ci BNX2X_ERR("failed to allocate vf database\n"); 122462306a36Sopenharmony_ci err = -ENOMEM; 122562306a36Sopenharmony_ci goto failed; 122662306a36Sopenharmony_ci } 122762306a36Sopenharmony_ci 122862306a36Sopenharmony_ci /* get the sriov info - Linux already collected all the pertinent 122962306a36Sopenharmony_ci * information, however the sriov structure is for the private use 123062306a36Sopenharmony_ci * of the pci module. Also we want this information regardless 123162306a36Sopenharmony_ci * of the hyper-visor. 123262306a36Sopenharmony_ci */ 123362306a36Sopenharmony_ci iov = &(bp->vfdb->sriov); 123462306a36Sopenharmony_ci err = bnx2x_sriov_info(bp, iov); 123562306a36Sopenharmony_ci if (err) 123662306a36Sopenharmony_ci goto failed; 123762306a36Sopenharmony_ci 123862306a36Sopenharmony_ci /* SR-IOV capability was enabled but there are no VFs*/ 123962306a36Sopenharmony_ci if (iov->total == 0) { 124062306a36Sopenharmony_ci err = 0; 124162306a36Sopenharmony_ci goto failed; 124262306a36Sopenharmony_ci } 124362306a36Sopenharmony_ci 124462306a36Sopenharmony_ci iov->nr_virtfn = min_t(u16, iov->total, num_vfs_param); 124562306a36Sopenharmony_ci 124662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "num_vfs_param was %d, nr_virtfn was %d\n", 124762306a36Sopenharmony_ci num_vfs_param, iov->nr_virtfn); 124862306a36Sopenharmony_ci 124962306a36Sopenharmony_ci /* allocate the vf array */ 125062306a36Sopenharmony_ci bp->vfdb->vfs = kcalloc(BNX2X_NR_VIRTFN(bp), 125162306a36Sopenharmony_ci sizeof(struct bnx2x_virtf), 125262306a36Sopenharmony_ci GFP_KERNEL); 125362306a36Sopenharmony_ci if (!bp->vfdb->vfs) { 125462306a36Sopenharmony_ci BNX2X_ERR("failed to allocate vf array\n"); 125562306a36Sopenharmony_ci err = -ENOMEM; 125662306a36Sopenharmony_ci goto failed; 125762306a36Sopenharmony_ci } 125862306a36Sopenharmony_ci 125962306a36Sopenharmony_ci /* Initial VF init - index and abs_vfid - nr_virtfn must be set */ 126062306a36Sopenharmony_ci for_each_vf(bp, i) { 126162306a36Sopenharmony_ci bnx2x_vf(bp, i, index) = i; 126262306a36Sopenharmony_ci bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i; 126362306a36Sopenharmony_ci bnx2x_vf(bp, i, state) = VF_FREE; 126462306a36Sopenharmony_ci mutex_init(&bnx2x_vf(bp, i, op_mutex)); 126562306a36Sopenharmony_ci bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE; 126662306a36Sopenharmony_ci /* enable spoofchk by default */ 126762306a36Sopenharmony_ci bnx2x_vf(bp, i, spoofchk) = 1; 126862306a36Sopenharmony_ci } 126962306a36Sopenharmony_ci 127062306a36Sopenharmony_ci /* re-read the IGU CAM for VFs - index and abs_vfid must be set */ 127162306a36Sopenharmony_ci if (!bnx2x_get_vf_igu_cam_info(bp)) { 127262306a36Sopenharmony_ci BNX2X_ERR("No entries in IGU CAM for vfs\n"); 127362306a36Sopenharmony_ci err = -EINVAL; 127462306a36Sopenharmony_ci goto failed; 127562306a36Sopenharmony_ci } 127662306a36Sopenharmony_ci 127762306a36Sopenharmony_ci /* allocate the queue arrays for all VFs */ 127862306a36Sopenharmony_ci bp->vfdb->vfqs = kcalloc(BNX2X_MAX_NUM_VF_QUEUES, 127962306a36Sopenharmony_ci sizeof(struct bnx2x_vf_queue), 128062306a36Sopenharmony_ci GFP_KERNEL); 128162306a36Sopenharmony_ci 128262306a36Sopenharmony_ci if (!bp->vfdb->vfqs) { 128362306a36Sopenharmony_ci BNX2X_ERR("failed to allocate vf queue array\n"); 128462306a36Sopenharmony_ci err = -ENOMEM; 128562306a36Sopenharmony_ci goto failed; 128662306a36Sopenharmony_ci } 128762306a36Sopenharmony_ci 128862306a36Sopenharmony_ci /* Prepare the VFs event synchronization mechanism */ 128962306a36Sopenharmony_ci mutex_init(&bp->vfdb->event_mutex); 129062306a36Sopenharmony_ci 129162306a36Sopenharmony_ci mutex_init(&bp->vfdb->bulletin_mutex); 129262306a36Sopenharmony_ci 129362306a36Sopenharmony_ci if (SHMEM2_HAS(bp, sriov_switch_mode)) 129462306a36Sopenharmony_ci SHMEM2_WR(bp, sriov_switch_mode, SRIOV_SWITCH_MODE_VEB); 129562306a36Sopenharmony_ci 129662306a36Sopenharmony_ci return 0; 129762306a36Sopenharmony_cifailed: 129862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "Failed err=%d\n", err); 129962306a36Sopenharmony_ci __bnx2x_iov_free_vfdb(bp); 130062306a36Sopenharmony_ci return err; 130162306a36Sopenharmony_ci} 130262306a36Sopenharmony_ci 130362306a36Sopenharmony_civoid bnx2x_iov_remove_one(struct bnx2x *bp) 130462306a36Sopenharmony_ci{ 130562306a36Sopenharmony_ci int vf_idx; 130662306a36Sopenharmony_ci 130762306a36Sopenharmony_ci /* if SRIOV is not enabled there's nothing to do */ 130862306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 130962306a36Sopenharmony_ci return; 131062306a36Sopenharmony_ci 131162306a36Sopenharmony_ci bnx2x_disable_sriov(bp); 131262306a36Sopenharmony_ci 131362306a36Sopenharmony_ci /* disable access to all VFs */ 131462306a36Sopenharmony_ci for (vf_idx = 0; vf_idx < bp->vfdb->sriov.total; vf_idx++) { 131562306a36Sopenharmony_ci bnx2x_pretend_func(bp, 131662306a36Sopenharmony_ci HW_VF_HANDLE(bp, 131762306a36Sopenharmony_ci bp->vfdb->sriov.first_vf_in_pf + 131862306a36Sopenharmony_ci vf_idx)); 131962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "disabling internal access for vf %d\n", 132062306a36Sopenharmony_ci bp->vfdb->sriov.first_vf_in_pf + vf_idx); 132162306a36Sopenharmony_ci bnx2x_vf_enable_internal(bp, 0); 132262306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 132362306a36Sopenharmony_ci } 132462306a36Sopenharmony_ci 132562306a36Sopenharmony_ci /* free vf database */ 132662306a36Sopenharmony_ci __bnx2x_iov_free_vfdb(bp); 132762306a36Sopenharmony_ci} 132862306a36Sopenharmony_ci 132962306a36Sopenharmony_civoid bnx2x_iov_free_mem(struct bnx2x *bp) 133062306a36Sopenharmony_ci{ 133162306a36Sopenharmony_ci int i; 133262306a36Sopenharmony_ci 133362306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 133462306a36Sopenharmony_ci return; 133562306a36Sopenharmony_ci 133662306a36Sopenharmony_ci /* free vfs hw contexts */ 133762306a36Sopenharmony_ci for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) { 133862306a36Sopenharmony_ci struct hw_dma *cxt = &bp->vfdb->context[i]; 133962306a36Sopenharmony_ci BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size); 134062306a36Sopenharmony_ci } 134162306a36Sopenharmony_ci 134262306a36Sopenharmony_ci BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr, 134362306a36Sopenharmony_ci BP_VFDB(bp)->sp_dma.mapping, 134462306a36Sopenharmony_ci BP_VFDB(bp)->sp_dma.size); 134562306a36Sopenharmony_ci 134662306a36Sopenharmony_ci BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr, 134762306a36Sopenharmony_ci BP_VF_MBX_DMA(bp)->mapping, 134862306a36Sopenharmony_ci BP_VF_MBX_DMA(bp)->size); 134962306a36Sopenharmony_ci 135062306a36Sopenharmony_ci BNX2X_PCI_FREE(BP_VF_BULLETIN_DMA(bp)->addr, 135162306a36Sopenharmony_ci BP_VF_BULLETIN_DMA(bp)->mapping, 135262306a36Sopenharmony_ci BP_VF_BULLETIN_DMA(bp)->size); 135362306a36Sopenharmony_ci} 135462306a36Sopenharmony_ci 135562306a36Sopenharmony_ciint bnx2x_iov_alloc_mem(struct bnx2x *bp) 135662306a36Sopenharmony_ci{ 135762306a36Sopenharmony_ci size_t tot_size; 135862306a36Sopenharmony_ci int i, rc = 0; 135962306a36Sopenharmony_ci 136062306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 136162306a36Sopenharmony_ci return rc; 136262306a36Sopenharmony_ci 136362306a36Sopenharmony_ci /* allocate vfs hw contexts */ 136462306a36Sopenharmony_ci tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) * 136562306a36Sopenharmony_ci BNX2X_CIDS_PER_VF * sizeof(union cdu_context); 136662306a36Sopenharmony_ci 136762306a36Sopenharmony_ci for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) { 136862306a36Sopenharmony_ci struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i); 136962306a36Sopenharmony_ci cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ); 137062306a36Sopenharmony_ci 137162306a36Sopenharmony_ci if (cxt->size) { 137262306a36Sopenharmony_ci cxt->addr = BNX2X_PCI_ALLOC(&cxt->mapping, cxt->size); 137362306a36Sopenharmony_ci if (!cxt->addr) 137462306a36Sopenharmony_ci goto alloc_mem_err; 137562306a36Sopenharmony_ci } else { 137662306a36Sopenharmony_ci cxt->addr = NULL; 137762306a36Sopenharmony_ci cxt->mapping = 0; 137862306a36Sopenharmony_ci } 137962306a36Sopenharmony_ci tot_size -= cxt->size; 138062306a36Sopenharmony_ci } 138162306a36Sopenharmony_ci 138262306a36Sopenharmony_ci /* allocate vfs ramrods dma memory - client_init and set_mac */ 138362306a36Sopenharmony_ci tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp); 138462306a36Sopenharmony_ci BP_VFDB(bp)->sp_dma.addr = BNX2X_PCI_ALLOC(&BP_VFDB(bp)->sp_dma.mapping, 138562306a36Sopenharmony_ci tot_size); 138662306a36Sopenharmony_ci if (!BP_VFDB(bp)->sp_dma.addr) 138762306a36Sopenharmony_ci goto alloc_mem_err; 138862306a36Sopenharmony_ci BP_VFDB(bp)->sp_dma.size = tot_size; 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_ci /* allocate mailboxes */ 139162306a36Sopenharmony_ci tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE; 139262306a36Sopenharmony_ci BP_VF_MBX_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_MBX_DMA(bp)->mapping, 139362306a36Sopenharmony_ci tot_size); 139462306a36Sopenharmony_ci if (!BP_VF_MBX_DMA(bp)->addr) 139562306a36Sopenharmony_ci goto alloc_mem_err; 139662306a36Sopenharmony_ci 139762306a36Sopenharmony_ci BP_VF_MBX_DMA(bp)->size = tot_size; 139862306a36Sopenharmony_ci 139962306a36Sopenharmony_ci /* allocate local bulletin boards */ 140062306a36Sopenharmony_ci tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE; 140162306a36Sopenharmony_ci BP_VF_BULLETIN_DMA(bp)->addr = BNX2X_PCI_ALLOC(&BP_VF_BULLETIN_DMA(bp)->mapping, 140262306a36Sopenharmony_ci tot_size); 140362306a36Sopenharmony_ci if (!BP_VF_BULLETIN_DMA(bp)->addr) 140462306a36Sopenharmony_ci goto alloc_mem_err; 140562306a36Sopenharmony_ci 140662306a36Sopenharmony_ci BP_VF_BULLETIN_DMA(bp)->size = tot_size; 140762306a36Sopenharmony_ci 140862306a36Sopenharmony_ci return 0; 140962306a36Sopenharmony_ci 141062306a36Sopenharmony_cialloc_mem_err: 141162306a36Sopenharmony_ci return -ENOMEM; 141262306a36Sopenharmony_ci} 141362306a36Sopenharmony_ci 141462306a36Sopenharmony_cistatic void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf, 141562306a36Sopenharmony_ci struct bnx2x_vf_queue *q) 141662306a36Sopenharmony_ci{ 141762306a36Sopenharmony_ci u8 cl_id = vfq_cl_id(vf, q); 141862306a36Sopenharmony_ci u8 func_id = FW_VF_HANDLE(vf->abs_vfid); 141962306a36Sopenharmony_ci unsigned long q_type = 0; 142062306a36Sopenharmony_ci 142162306a36Sopenharmony_ci set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); 142262306a36Sopenharmony_ci set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); 142362306a36Sopenharmony_ci 142462306a36Sopenharmony_ci /* Queue State object */ 142562306a36Sopenharmony_ci bnx2x_init_queue_obj(bp, &q->sp_obj, 142662306a36Sopenharmony_ci cl_id, &q->cid, 1, func_id, 142762306a36Sopenharmony_ci bnx2x_vf_sp(bp, vf, q_data), 142862306a36Sopenharmony_ci bnx2x_vf_sp_map(bp, vf, q_data), 142962306a36Sopenharmony_ci q_type); 143062306a36Sopenharmony_ci 143162306a36Sopenharmony_ci /* sp indication is set only when vlan/mac/etc. are initialized */ 143262306a36Sopenharmony_ci q->sp_initialized = false; 143362306a36Sopenharmony_ci 143462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 143562306a36Sopenharmony_ci "initialized vf %d's queue object. func id set to %d. cid set to 0x%x\n", 143662306a36Sopenharmony_ci vf->abs_vfid, q->sp_obj.func_id, q->cid); 143762306a36Sopenharmony_ci} 143862306a36Sopenharmony_ci 143962306a36Sopenharmony_cistatic int bnx2x_max_speed_cap(struct bnx2x *bp) 144062306a36Sopenharmony_ci{ 144162306a36Sopenharmony_ci u32 supported = bp->port.supported[bnx2x_get_link_cfg_idx(bp)]; 144262306a36Sopenharmony_ci 144362306a36Sopenharmony_ci if (supported & 144462306a36Sopenharmony_ci (SUPPORTED_20000baseMLD2_Full | SUPPORTED_20000baseKR2_Full)) 144562306a36Sopenharmony_ci return 20000; 144662306a36Sopenharmony_ci 144762306a36Sopenharmony_ci return 10000; /* assume lowest supported speed is 10G */ 144862306a36Sopenharmony_ci} 144962306a36Sopenharmony_ci 145062306a36Sopenharmony_ciint bnx2x_iov_link_update_vf(struct bnx2x *bp, int idx) 145162306a36Sopenharmony_ci{ 145262306a36Sopenharmony_ci struct bnx2x_link_report_data *state = &bp->last_reported_link; 145362306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin; 145462306a36Sopenharmony_ci struct bnx2x_virtf *vf; 145562306a36Sopenharmony_ci bool update = true; 145662306a36Sopenharmony_ci int rc = 0; 145762306a36Sopenharmony_ci 145862306a36Sopenharmony_ci /* sanity and init */ 145962306a36Sopenharmony_ci rc = bnx2x_vf_op_prep(bp, idx, &vf, &bulletin, false); 146062306a36Sopenharmony_ci if (rc) 146162306a36Sopenharmony_ci return rc; 146262306a36Sopenharmony_ci 146362306a36Sopenharmony_ci mutex_lock(&bp->vfdb->bulletin_mutex); 146462306a36Sopenharmony_ci 146562306a36Sopenharmony_ci if (vf->link_cfg == IFLA_VF_LINK_STATE_AUTO) { 146662306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << LINK_VALID; 146762306a36Sopenharmony_ci 146862306a36Sopenharmony_ci bulletin->link_speed = state->line_speed; 146962306a36Sopenharmony_ci bulletin->link_flags = 0; 147062306a36Sopenharmony_ci if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN, 147162306a36Sopenharmony_ci &state->link_report_flags)) 147262306a36Sopenharmony_ci bulletin->link_flags |= VFPF_LINK_REPORT_LINK_DOWN; 147362306a36Sopenharmony_ci if (test_bit(BNX2X_LINK_REPORT_FD, 147462306a36Sopenharmony_ci &state->link_report_flags)) 147562306a36Sopenharmony_ci bulletin->link_flags |= VFPF_LINK_REPORT_FULL_DUPLEX; 147662306a36Sopenharmony_ci if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON, 147762306a36Sopenharmony_ci &state->link_report_flags)) 147862306a36Sopenharmony_ci bulletin->link_flags |= VFPF_LINK_REPORT_RX_FC_ON; 147962306a36Sopenharmony_ci if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON, 148062306a36Sopenharmony_ci &state->link_report_flags)) 148162306a36Sopenharmony_ci bulletin->link_flags |= VFPF_LINK_REPORT_TX_FC_ON; 148262306a36Sopenharmony_ci } else if (vf->link_cfg == IFLA_VF_LINK_STATE_DISABLE && 148362306a36Sopenharmony_ci !(bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN)) { 148462306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << LINK_VALID; 148562306a36Sopenharmony_ci bulletin->link_flags |= VFPF_LINK_REPORT_LINK_DOWN; 148662306a36Sopenharmony_ci } else if (vf->link_cfg == IFLA_VF_LINK_STATE_ENABLE && 148762306a36Sopenharmony_ci (bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN)) { 148862306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << LINK_VALID; 148962306a36Sopenharmony_ci bulletin->link_speed = bnx2x_max_speed_cap(bp); 149062306a36Sopenharmony_ci bulletin->link_flags &= ~VFPF_LINK_REPORT_LINK_DOWN; 149162306a36Sopenharmony_ci } else { 149262306a36Sopenharmony_ci update = false; 149362306a36Sopenharmony_ci } 149462306a36Sopenharmony_ci 149562306a36Sopenharmony_ci if (update) { 149662306a36Sopenharmony_ci DP(NETIF_MSG_LINK | BNX2X_MSG_IOV, 149762306a36Sopenharmony_ci "vf %d mode %u speed %d flags %x\n", idx, 149862306a36Sopenharmony_ci vf->link_cfg, bulletin->link_speed, bulletin->link_flags); 149962306a36Sopenharmony_ci 150062306a36Sopenharmony_ci /* Post update on VF's bulletin board */ 150162306a36Sopenharmony_ci rc = bnx2x_post_vf_bulletin(bp, idx); 150262306a36Sopenharmony_ci if (rc) { 150362306a36Sopenharmony_ci BNX2X_ERR("failed to update VF[%d] bulletin\n", idx); 150462306a36Sopenharmony_ci goto out; 150562306a36Sopenharmony_ci } 150662306a36Sopenharmony_ci } 150762306a36Sopenharmony_ci 150862306a36Sopenharmony_ciout: 150962306a36Sopenharmony_ci mutex_unlock(&bp->vfdb->bulletin_mutex); 151062306a36Sopenharmony_ci return rc; 151162306a36Sopenharmony_ci} 151262306a36Sopenharmony_ci 151362306a36Sopenharmony_ciint bnx2x_set_vf_link_state(struct net_device *dev, int idx, int link_state) 151462306a36Sopenharmony_ci{ 151562306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(dev); 151662306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, idx); 151762306a36Sopenharmony_ci 151862306a36Sopenharmony_ci if (!vf) 151962306a36Sopenharmony_ci return -EINVAL; 152062306a36Sopenharmony_ci 152162306a36Sopenharmony_ci if (vf->link_cfg == link_state) 152262306a36Sopenharmony_ci return 0; /* nothing todo */ 152362306a36Sopenharmony_ci 152462306a36Sopenharmony_ci vf->link_cfg = link_state; 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_ci return bnx2x_iov_link_update_vf(bp, idx); 152762306a36Sopenharmony_ci} 152862306a36Sopenharmony_ci 152962306a36Sopenharmony_civoid bnx2x_iov_link_update(struct bnx2x *bp) 153062306a36Sopenharmony_ci{ 153162306a36Sopenharmony_ci int vfid; 153262306a36Sopenharmony_ci 153362306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 153462306a36Sopenharmony_ci return; 153562306a36Sopenharmony_ci 153662306a36Sopenharmony_ci for_each_vf(bp, vfid) 153762306a36Sopenharmony_ci bnx2x_iov_link_update_vf(bp, vfid); 153862306a36Sopenharmony_ci} 153962306a36Sopenharmony_ci 154062306a36Sopenharmony_ci/* called by bnx2x_nic_load */ 154162306a36Sopenharmony_ciint bnx2x_iov_nic_init(struct bnx2x *bp) 154262306a36Sopenharmony_ci{ 154362306a36Sopenharmony_ci int vfid; 154462306a36Sopenharmony_ci 154562306a36Sopenharmony_ci if (!IS_SRIOV(bp)) { 154662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vfdb was not allocated\n"); 154762306a36Sopenharmony_ci return 0; 154862306a36Sopenharmony_ci } 154962306a36Sopenharmony_ci 155062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn); 155162306a36Sopenharmony_ci 155262306a36Sopenharmony_ci /* let FLR complete ... */ 155362306a36Sopenharmony_ci msleep(100); 155462306a36Sopenharmony_ci 155562306a36Sopenharmony_ci /* initialize vf database */ 155662306a36Sopenharmony_ci for_each_vf(bp, vfid) { 155762306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, vfid); 155862306a36Sopenharmony_ci 155962306a36Sopenharmony_ci int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) * 156062306a36Sopenharmony_ci BNX2X_CIDS_PER_VF; 156162306a36Sopenharmony_ci 156262306a36Sopenharmony_ci union cdu_context *base_cxt = (union cdu_context *) 156362306a36Sopenharmony_ci BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr + 156462306a36Sopenharmony_ci (base_vf_cid & (ILT_PAGE_CIDS-1)); 156562306a36Sopenharmony_ci 156662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 156762306a36Sopenharmony_ci "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n", 156862306a36Sopenharmony_ci vf->abs_vfid, vf_sb_count(vf), base_vf_cid, 156962306a36Sopenharmony_ci BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt); 157062306a36Sopenharmony_ci 157162306a36Sopenharmony_ci /* init statically provisioned resources */ 157262306a36Sopenharmony_ci bnx2x_iov_static_resc(bp, vf); 157362306a36Sopenharmony_ci 157462306a36Sopenharmony_ci /* queues are initialized during VF-ACQUIRE */ 157562306a36Sopenharmony_ci vf->filter_state = 0; 157662306a36Sopenharmony_ci vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id); 157762306a36Sopenharmony_ci 157862306a36Sopenharmony_ci bnx2x_init_credit_pool(&vf->vf_vlans_pool, 0, 157962306a36Sopenharmony_ci vf_vlan_rules_cnt(vf)); 158062306a36Sopenharmony_ci bnx2x_init_credit_pool(&vf->vf_macs_pool, 0, 158162306a36Sopenharmony_ci vf_mac_rules_cnt(vf)); 158262306a36Sopenharmony_ci 158362306a36Sopenharmony_ci /* init mcast object - This object will be re-initialized 158462306a36Sopenharmony_ci * during VF-ACQUIRE with the proper cl_id and cid. 158562306a36Sopenharmony_ci * It needs to be initialized here so that it can be safely 158662306a36Sopenharmony_ci * handled by a subsequent FLR flow. 158762306a36Sopenharmony_ci */ 158862306a36Sopenharmony_ci bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF, 158962306a36Sopenharmony_ci 0xFF, 0xFF, 0xFF, 159062306a36Sopenharmony_ci bnx2x_vf_sp(bp, vf, mcast_rdata), 159162306a36Sopenharmony_ci bnx2x_vf_sp_map(bp, vf, mcast_rdata), 159262306a36Sopenharmony_ci BNX2X_FILTER_MCAST_PENDING, 159362306a36Sopenharmony_ci &vf->filter_state, 159462306a36Sopenharmony_ci BNX2X_OBJ_TYPE_RX_TX); 159562306a36Sopenharmony_ci 159662306a36Sopenharmony_ci /* set the mailbox message addresses */ 159762306a36Sopenharmony_ci BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *) 159862306a36Sopenharmony_ci (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid * 159962306a36Sopenharmony_ci MBX_MSG_ALIGNED_SIZE); 160062306a36Sopenharmony_ci 160162306a36Sopenharmony_ci BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping + 160262306a36Sopenharmony_ci vfid * MBX_MSG_ALIGNED_SIZE; 160362306a36Sopenharmony_ci 160462306a36Sopenharmony_ci /* Enable vf mailbox */ 160562306a36Sopenharmony_ci bnx2x_vf_enable_mbx(bp, vf->abs_vfid); 160662306a36Sopenharmony_ci } 160762306a36Sopenharmony_ci 160862306a36Sopenharmony_ci /* Final VF init */ 160962306a36Sopenharmony_ci for_each_vf(bp, vfid) { 161062306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, vfid); 161162306a36Sopenharmony_ci 161262306a36Sopenharmony_ci /* fill in the BDF and bars */ 161362306a36Sopenharmony_ci vf->domain = bnx2x_vf_domain(bp, vfid); 161462306a36Sopenharmony_ci vf->bus = bnx2x_vf_bus(bp, vfid); 161562306a36Sopenharmony_ci vf->devfn = bnx2x_vf_devfn(bp, vfid); 161662306a36Sopenharmony_ci bnx2x_vf_set_bars(bp, vf); 161762306a36Sopenharmony_ci 161862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 161962306a36Sopenharmony_ci "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n", 162062306a36Sopenharmony_ci vf->abs_vfid, vf->bus, vf->devfn, 162162306a36Sopenharmony_ci (unsigned)vf->bars[0].bar, vf->bars[0].size, 162262306a36Sopenharmony_ci (unsigned)vf->bars[1].bar, vf->bars[1].size, 162362306a36Sopenharmony_ci (unsigned)vf->bars[2].bar, vf->bars[2].size); 162462306a36Sopenharmony_ci } 162562306a36Sopenharmony_ci 162662306a36Sopenharmony_ci return 0; 162762306a36Sopenharmony_ci} 162862306a36Sopenharmony_ci 162962306a36Sopenharmony_ci/* called by bnx2x_chip_cleanup */ 163062306a36Sopenharmony_ciint bnx2x_iov_chip_cleanup(struct bnx2x *bp) 163162306a36Sopenharmony_ci{ 163262306a36Sopenharmony_ci int i; 163362306a36Sopenharmony_ci 163462306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 163562306a36Sopenharmony_ci return 0; 163662306a36Sopenharmony_ci 163762306a36Sopenharmony_ci /* release all the VFs */ 163862306a36Sopenharmony_ci for_each_vf(bp, i) 163962306a36Sopenharmony_ci bnx2x_vf_release(bp, BP_VF(bp, i)); 164062306a36Sopenharmony_ci 164162306a36Sopenharmony_ci return 0; 164262306a36Sopenharmony_ci} 164362306a36Sopenharmony_ci 164462306a36Sopenharmony_ci/* called by bnx2x_init_hw_func, returns the next ilt line */ 164562306a36Sopenharmony_ciint bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line) 164662306a36Sopenharmony_ci{ 164762306a36Sopenharmony_ci int i; 164862306a36Sopenharmony_ci struct bnx2x_ilt *ilt = BP_ILT(bp); 164962306a36Sopenharmony_ci 165062306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 165162306a36Sopenharmony_ci return line; 165262306a36Sopenharmony_ci 165362306a36Sopenharmony_ci /* set vfs ilt lines */ 165462306a36Sopenharmony_ci for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) { 165562306a36Sopenharmony_ci struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i); 165662306a36Sopenharmony_ci 165762306a36Sopenharmony_ci ilt->lines[line+i].page = hw_cxt->addr; 165862306a36Sopenharmony_ci ilt->lines[line+i].page_mapping = hw_cxt->mapping; 165962306a36Sopenharmony_ci ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */ 166062306a36Sopenharmony_ci } 166162306a36Sopenharmony_ci return line + i; 166262306a36Sopenharmony_ci} 166362306a36Sopenharmony_ci 166462306a36Sopenharmony_cistatic u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid) 166562306a36Sopenharmony_ci{ 166662306a36Sopenharmony_ci return ((cid >= BNX2X_FIRST_VF_CID) && 166762306a36Sopenharmony_ci ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS)); 166862306a36Sopenharmony_ci} 166962306a36Sopenharmony_ci 167062306a36Sopenharmony_cistatic 167162306a36Sopenharmony_civoid bnx2x_vf_handle_classification_eqe(struct bnx2x *bp, 167262306a36Sopenharmony_ci struct bnx2x_vf_queue *vfq, 167362306a36Sopenharmony_ci union event_ring_elem *elem) 167462306a36Sopenharmony_ci{ 167562306a36Sopenharmony_ci unsigned long ramrod_flags = 0; 167662306a36Sopenharmony_ci int rc = 0; 167762306a36Sopenharmony_ci u32 echo = le32_to_cpu(elem->message.data.eth_event.echo); 167862306a36Sopenharmony_ci 167962306a36Sopenharmony_ci /* Always push next commands out, don't wait here */ 168062306a36Sopenharmony_ci set_bit(RAMROD_CONT, &ramrod_flags); 168162306a36Sopenharmony_ci 168262306a36Sopenharmony_ci switch (echo >> BNX2X_SWCID_SHIFT) { 168362306a36Sopenharmony_ci case BNX2X_FILTER_MAC_PENDING: 168462306a36Sopenharmony_ci rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem, 168562306a36Sopenharmony_ci &ramrod_flags); 168662306a36Sopenharmony_ci break; 168762306a36Sopenharmony_ci case BNX2X_FILTER_VLAN_PENDING: 168862306a36Sopenharmony_ci rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem, 168962306a36Sopenharmony_ci &ramrod_flags); 169062306a36Sopenharmony_ci break; 169162306a36Sopenharmony_ci default: 169262306a36Sopenharmony_ci BNX2X_ERR("Unsupported classification command: 0x%x\n", echo); 169362306a36Sopenharmony_ci return; 169462306a36Sopenharmony_ci } 169562306a36Sopenharmony_ci if (rc < 0) 169662306a36Sopenharmony_ci BNX2X_ERR("Failed to schedule new commands: %d\n", rc); 169762306a36Sopenharmony_ci else if (rc > 0) 169862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n"); 169962306a36Sopenharmony_ci} 170062306a36Sopenharmony_ci 170162306a36Sopenharmony_cistatic 170262306a36Sopenharmony_civoid bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp, 170362306a36Sopenharmony_ci struct bnx2x_virtf *vf) 170462306a36Sopenharmony_ci{ 170562306a36Sopenharmony_ci struct bnx2x_mcast_ramrod_params rparam = {NULL}; 170662306a36Sopenharmony_ci int rc; 170762306a36Sopenharmony_ci 170862306a36Sopenharmony_ci rparam.mcast_obj = &vf->mcast_obj; 170962306a36Sopenharmony_ci vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw); 171062306a36Sopenharmony_ci 171162306a36Sopenharmony_ci /* If there are pending mcast commands - send them */ 171262306a36Sopenharmony_ci if (vf->mcast_obj.check_pending(&vf->mcast_obj)) { 171362306a36Sopenharmony_ci rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT); 171462306a36Sopenharmony_ci if (rc < 0) 171562306a36Sopenharmony_ci BNX2X_ERR("Failed to send pending mcast commands: %d\n", 171662306a36Sopenharmony_ci rc); 171762306a36Sopenharmony_ci } 171862306a36Sopenharmony_ci} 171962306a36Sopenharmony_ci 172062306a36Sopenharmony_cistatic 172162306a36Sopenharmony_civoid bnx2x_vf_handle_filters_eqe(struct bnx2x *bp, 172262306a36Sopenharmony_ci struct bnx2x_virtf *vf) 172362306a36Sopenharmony_ci{ 172462306a36Sopenharmony_ci smp_mb__before_atomic(); 172562306a36Sopenharmony_ci clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state); 172662306a36Sopenharmony_ci smp_mb__after_atomic(); 172762306a36Sopenharmony_ci} 172862306a36Sopenharmony_ci 172962306a36Sopenharmony_cistatic void bnx2x_vf_handle_rss_update_eqe(struct bnx2x *bp, 173062306a36Sopenharmony_ci struct bnx2x_virtf *vf) 173162306a36Sopenharmony_ci{ 173262306a36Sopenharmony_ci vf->rss_conf_obj.raw.clear_pending(&vf->rss_conf_obj.raw); 173362306a36Sopenharmony_ci} 173462306a36Sopenharmony_ci 173562306a36Sopenharmony_ciint bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem) 173662306a36Sopenharmony_ci{ 173762306a36Sopenharmony_ci struct bnx2x_virtf *vf; 173862306a36Sopenharmony_ci int qidx = 0, abs_vfid; 173962306a36Sopenharmony_ci u8 opcode; 174062306a36Sopenharmony_ci u16 cid = 0xffff; 174162306a36Sopenharmony_ci 174262306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 174362306a36Sopenharmony_ci return 1; 174462306a36Sopenharmony_ci 174562306a36Sopenharmony_ci /* first get the cid - the only events we handle here are cfc-delete 174662306a36Sopenharmony_ci * and set-mac completion 174762306a36Sopenharmony_ci */ 174862306a36Sopenharmony_ci opcode = elem->message.opcode; 174962306a36Sopenharmony_ci 175062306a36Sopenharmony_ci switch (opcode) { 175162306a36Sopenharmony_ci case EVENT_RING_OPCODE_CFC_DEL: 175262306a36Sopenharmony_ci cid = SW_CID(elem->message.data.cfc_del_event.cid); 175362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid); 175462306a36Sopenharmony_ci break; 175562306a36Sopenharmony_ci case EVENT_RING_OPCODE_CLASSIFICATION_RULES: 175662306a36Sopenharmony_ci case EVENT_RING_OPCODE_MULTICAST_RULES: 175762306a36Sopenharmony_ci case EVENT_RING_OPCODE_FILTERS_RULES: 175862306a36Sopenharmony_ci case EVENT_RING_OPCODE_RSS_UPDATE_RULES: 175962306a36Sopenharmony_ci cid = SW_CID(elem->message.data.eth_event.echo); 176062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid); 176162306a36Sopenharmony_ci break; 176262306a36Sopenharmony_ci case EVENT_RING_OPCODE_VF_FLR: 176362306a36Sopenharmony_ci abs_vfid = elem->message.data.vf_flr_event.vf_id; 176462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n", 176562306a36Sopenharmony_ci abs_vfid); 176662306a36Sopenharmony_ci goto get_vf; 176762306a36Sopenharmony_ci case EVENT_RING_OPCODE_MALICIOUS_VF: 176862306a36Sopenharmony_ci abs_vfid = elem->message.data.malicious_vf_event.vf_id; 176962306a36Sopenharmony_ci BNX2X_ERR("Got VF MALICIOUS notification abs_vfid=%d err_id=0x%x\n", 177062306a36Sopenharmony_ci abs_vfid, 177162306a36Sopenharmony_ci elem->message.data.malicious_vf_event.err_id); 177262306a36Sopenharmony_ci goto get_vf; 177362306a36Sopenharmony_ci default: 177462306a36Sopenharmony_ci return 1; 177562306a36Sopenharmony_ci } 177662306a36Sopenharmony_ci 177762306a36Sopenharmony_ci /* check if the cid is the VF range */ 177862306a36Sopenharmony_ci if (!bnx2x_iov_is_vf_cid(bp, cid)) { 177962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid); 178062306a36Sopenharmony_ci return 1; 178162306a36Sopenharmony_ci } 178262306a36Sopenharmony_ci 178362306a36Sopenharmony_ci /* extract vf and rxq index from vf_cid - relies on the following: 178462306a36Sopenharmony_ci * 1. vfid on cid reflects the true abs_vfid 178562306a36Sopenharmony_ci * 2. The max number of VFs (per path) is 64 178662306a36Sopenharmony_ci */ 178762306a36Sopenharmony_ci qidx = cid & ((1 << BNX2X_VF_CID_WND)-1); 178862306a36Sopenharmony_ci abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1); 178962306a36Sopenharmony_ciget_vf: 179062306a36Sopenharmony_ci vf = bnx2x_vf_by_abs_fid(bp, abs_vfid); 179162306a36Sopenharmony_ci 179262306a36Sopenharmony_ci if (!vf) { 179362306a36Sopenharmony_ci BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n", 179462306a36Sopenharmony_ci cid, abs_vfid); 179562306a36Sopenharmony_ci return 0; 179662306a36Sopenharmony_ci } 179762306a36Sopenharmony_ci 179862306a36Sopenharmony_ci switch (opcode) { 179962306a36Sopenharmony_ci case EVENT_RING_OPCODE_CFC_DEL: 180062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n", 180162306a36Sopenharmony_ci vf->abs_vfid, qidx); 180262306a36Sopenharmony_ci vfq_get(vf, qidx)->sp_obj.complete_cmd(bp, 180362306a36Sopenharmony_ci &vfq_get(vf, 180462306a36Sopenharmony_ci qidx)->sp_obj, 180562306a36Sopenharmony_ci BNX2X_Q_CMD_CFC_DEL); 180662306a36Sopenharmony_ci break; 180762306a36Sopenharmony_ci case EVENT_RING_OPCODE_CLASSIFICATION_RULES: 180862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n", 180962306a36Sopenharmony_ci vf->abs_vfid, qidx); 181062306a36Sopenharmony_ci bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem); 181162306a36Sopenharmony_ci break; 181262306a36Sopenharmony_ci case EVENT_RING_OPCODE_MULTICAST_RULES: 181362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n", 181462306a36Sopenharmony_ci vf->abs_vfid, qidx); 181562306a36Sopenharmony_ci bnx2x_vf_handle_mcast_eqe(bp, vf); 181662306a36Sopenharmony_ci break; 181762306a36Sopenharmony_ci case EVENT_RING_OPCODE_FILTERS_RULES: 181862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n", 181962306a36Sopenharmony_ci vf->abs_vfid, qidx); 182062306a36Sopenharmony_ci bnx2x_vf_handle_filters_eqe(bp, vf); 182162306a36Sopenharmony_ci break; 182262306a36Sopenharmony_ci case EVENT_RING_OPCODE_RSS_UPDATE_RULES: 182362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "got VF [%d:%d] RSS update ramrod\n", 182462306a36Sopenharmony_ci vf->abs_vfid, qidx); 182562306a36Sopenharmony_ci bnx2x_vf_handle_rss_update_eqe(bp, vf); 182662306a36Sopenharmony_ci fallthrough; 182762306a36Sopenharmony_ci case EVENT_RING_OPCODE_VF_FLR: 182862306a36Sopenharmony_ci /* Do nothing for now */ 182962306a36Sopenharmony_ci return 0; 183062306a36Sopenharmony_ci case EVENT_RING_OPCODE_MALICIOUS_VF: 183162306a36Sopenharmony_ci vf->malicious = true; 183262306a36Sopenharmony_ci return 0; 183362306a36Sopenharmony_ci } 183462306a36Sopenharmony_ci 183562306a36Sopenharmony_ci return 0; 183662306a36Sopenharmony_ci} 183762306a36Sopenharmony_ci 183862306a36Sopenharmony_cistatic struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid) 183962306a36Sopenharmony_ci{ 184062306a36Sopenharmony_ci /* extract the vf from vf_cid - relies on the following: 184162306a36Sopenharmony_ci * 1. vfid on cid reflects the true abs_vfid 184262306a36Sopenharmony_ci * 2. The max number of VFs (per path) is 64 184362306a36Sopenharmony_ci */ 184462306a36Sopenharmony_ci int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1); 184562306a36Sopenharmony_ci return bnx2x_vf_by_abs_fid(bp, abs_vfid); 184662306a36Sopenharmony_ci} 184762306a36Sopenharmony_ci 184862306a36Sopenharmony_civoid bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid, 184962306a36Sopenharmony_ci struct bnx2x_queue_sp_obj **q_obj) 185062306a36Sopenharmony_ci{ 185162306a36Sopenharmony_ci struct bnx2x_virtf *vf; 185262306a36Sopenharmony_ci 185362306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 185462306a36Sopenharmony_ci return; 185562306a36Sopenharmony_ci 185662306a36Sopenharmony_ci vf = bnx2x_vf_by_cid(bp, vf_cid); 185762306a36Sopenharmony_ci 185862306a36Sopenharmony_ci if (vf) { 185962306a36Sopenharmony_ci /* extract queue index from vf_cid - relies on the following: 186062306a36Sopenharmony_ci * 1. vfid on cid reflects the true abs_vfid 186162306a36Sopenharmony_ci * 2. The max number of VFs (per path) is 64 186262306a36Sopenharmony_ci */ 186362306a36Sopenharmony_ci int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1); 186462306a36Sopenharmony_ci *q_obj = &bnx2x_vfq(vf, q_index, sp_obj); 186562306a36Sopenharmony_ci } else { 186662306a36Sopenharmony_ci BNX2X_ERR("No vf matching cid %d\n", vf_cid); 186762306a36Sopenharmony_ci } 186862306a36Sopenharmony_ci} 186962306a36Sopenharmony_ci 187062306a36Sopenharmony_civoid bnx2x_iov_adjust_stats_req(struct bnx2x *bp) 187162306a36Sopenharmony_ci{ 187262306a36Sopenharmony_ci int i; 187362306a36Sopenharmony_ci int first_queue_query_index, num_queues_req; 187462306a36Sopenharmony_ci struct stats_query_entry *cur_query_entry; 187562306a36Sopenharmony_ci u8 stats_count = 0; 187662306a36Sopenharmony_ci bool is_fcoe = false; 187762306a36Sopenharmony_ci 187862306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 187962306a36Sopenharmony_ci return; 188062306a36Sopenharmony_ci 188162306a36Sopenharmony_ci if (!NO_FCOE(bp)) 188262306a36Sopenharmony_ci is_fcoe = true; 188362306a36Sopenharmony_ci 188462306a36Sopenharmony_ci /* fcoe adds one global request and one queue request */ 188562306a36Sopenharmony_ci num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe; 188662306a36Sopenharmony_ci first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX - 188762306a36Sopenharmony_ci (is_fcoe ? 0 : 1); 188862306a36Sopenharmony_ci 188962306a36Sopenharmony_ci DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS), 189062306a36Sopenharmony_ci "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", 189162306a36Sopenharmony_ci BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index, 189262306a36Sopenharmony_ci first_queue_query_index + num_queues_req); 189362306a36Sopenharmony_ci 189462306a36Sopenharmony_ci cur_query_entry = &bp->fw_stats_req-> 189562306a36Sopenharmony_ci query[first_queue_query_index + num_queues_req]; 189662306a36Sopenharmony_ci 189762306a36Sopenharmony_ci for_each_vf(bp, i) { 189862306a36Sopenharmony_ci int j; 189962306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, i); 190062306a36Sopenharmony_ci 190162306a36Sopenharmony_ci if (vf->state != VF_ENABLED) { 190262306a36Sopenharmony_ci DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS), 190362306a36Sopenharmony_ci "vf %d not enabled so no stats for it\n", 190462306a36Sopenharmony_ci vf->abs_vfid); 190562306a36Sopenharmony_ci continue; 190662306a36Sopenharmony_ci } 190762306a36Sopenharmony_ci 190862306a36Sopenharmony_ci if (vf->malicious) { 190962306a36Sopenharmony_ci DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS), 191062306a36Sopenharmony_ci "vf %d malicious so no stats for it\n", 191162306a36Sopenharmony_ci vf->abs_vfid); 191262306a36Sopenharmony_ci continue; 191362306a36Sopenharmony_ci } 191462306a36Sopenharmony_ci 191562306a36Sopenharmony_ci DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS), 191662306a36Sopenharmony_ci "add addresses for vf %d\n", vf->abs_vfid); 191762306a36Sopenharmony_ci for_each_vfq(vf, j) { 191862306a36Sopenharmony_ci struct bnx2x_vf_queue *rxq = vfq_get(vf, j); 191962306a36Sopenharmony_ci 192062306a36Sopenharmony_ci dma_addr_t q_stats_addr = 192162306a36Sopenharmony_ci vf->fw_stat_map + j * vf->stats_stride; 192262306a36Sopenharmony_ci 192362306a36Sopenharmony_ci /* collect stats fro active queues only */ 192462306a36Sopenharmony_ci if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) == 192562306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_STOPPED) 192662306a36Sopenharmony_ci continue; 192762306a36Sopenharmony_ci 192862306a36Sopenharmony_ci /* create stats query entry for this queue */ 192962306a36Sopenharmony_ci cur_query_entry->kind = STATS_TYPE_QUEUE; 193062306a36Sopenharmony_ci cur_query_entry->index = vfq_stat_id(vf, rxq); 193162306a36Sopenharmony_ci cur_query_entry->funcID = 193262306a36Sopenharmony_ci cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid)); 193362306a36Sopenharmony_ci cur_query_entry->address.hi = 193462306a36Sopenharmony_ci cpu_to_le32(U64_HI(q_stats_addr)); 193562306a36Sopenharmony_ci cur_query_entry->address.lo = 193662306a36Sopenharmony_ci cpu_to_le32(U64_LO(q_stats_addr)); 193762306a36Sopenharmony_ci DP_AND((BNX2X_MSG_IOV | BNX2X_MSG_STATS), 193862306a36Sopenharmony_ci "added address %x %x for vf %d queue %d client %d\n", 193962306a36Sopenharmony_ci cur_query_entry->address.hi, 194062306a36Sopenharmony_ci cur_query_entry->address.lo, 194162306a36Sopenharmony_ci cur_query_entry->funcID, 194262306a36Sopenharmony_ci j, cur_query_entry->index); 194362306a36Sopenharmony_ci cur_query_entry++; 194462306a36Sopenharmony_ci stats_count++; 194562306a36Sopenharmony_ci 194662306a36Sopenharmony_ci /* all stats are coalesced to the leading queue */ 194762306a36Sopenharmony_ci if (vf->cfg_flags & VF_CFG_STATS_COALESCE) 194862306a36Sopenharmony_ci break; 194962306a36Sopenharmony_ci } 195062306a36Sopenharmony_ci } 195162306a36Sopenharmony_ci bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count; 195262306a36Sopenharmony_ci} 195362306a36Sopenharmony_ci 195462306a36Sopenharmony_ci/* VF API helpers */ 195562306a36Sopenharmony_cistatic void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid, 195662306a36Sopenharmony_ci u8 enable) 195762306a36Sopenharmony_ci{ 195862306a36Sopenharmony_ci u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4; 195962306a36Sopenharmony_ci u32 val = enable ? (abs_vfid | (1 << 6)) : 0; 196062306a36Sopenharmony_ci 196162306a36Sopenharmony_ci REG_WR(bp, reg, val); 196262306a36Sopenharmony_ci} 196362306a36Sopenharmony_ci 196462306a36Sopenharmony_cistatic void bnx2x_vf_clr_qtbl(struct bnx2x *bp, struct bnx2x_virtf *vf) 196562306a36Sopenharmony_ci{ 196662306a36Sopenharmony_ci int i; 196762306a36Sopenharmony_ci 196862306a36Sopenharmony_ci for_each_vfq(vf, i) 196962306a36Sopenharmony_ci bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid, 197062306a36Sopenharmony_ci vfq_qzone_id(vf, vfq_get(vf, i)), false); 197162306a36Sopenharmony_ci} 197262306a36Sopenharmony_ci 197362306a36Sopenharmony_cistatic void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf) 197462306a36Sopenharmony_ci{ 197562306a36Sopenharmony_ci u32 val; 197662306a36Sopenharmony_ci 197762306a36Sopenharmony_ci /* clear the VF configuration - pretend */ 197862306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid)); 197962306a36Sopenharmony_ci val = REG_RD(bp, IGU_REG_VF_CONFIGURATION); 198062306a36Sopenharmony_ci val &= ~(IGU_VF_CONF_MSI_MSIX_EN | IGU_VF_CONF_SINGLE_ISR_EN | 198162306a36Sopenharmony_ci IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_PARENT_MASK); 198262306a36Sopenharmony_ci REG_WR(bp, IGU_REG_VF_CONFIGURATION, val); 198362306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 198462306a36Sopenharmony_ci} 198562306a36Sopenharmony_ci 198662306a36Sopenharmony_ciu8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf) 198762306a36Sopenharmony_ci{ 198862306a36Sopenharmony_ci return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF), 198962306a36Sopenharmony_ci BNX2X_VF_MAX_QUEUES); 199062306a36Sopenharmony_ci} 199162306a36Sopenharmony_ci 199262306a36Sopenharmony_cistatic 199362306a36Sopenharmony_ciint bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf, 199462306a36Sopenharmony_ci struct vf_pf_resc_request *req_resc) 199562306a36Sopenharmony_ci{ 199662306a36Sopenharmony_ci u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf); 199762306a36Sopenharmony_ci u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf); 199862306a36Sopenharmony_ci 199962306a36Sopenharmony_ci return ((req_resc->num_rxqs <= rxq_cnt) && 200062306a36Sopenharmony_ci (req_resc->num_txqs <= txq_cnt) && 200162306a36Sopenharmony_ci (req_resc->num_sbs <= vf_sb_count(vf)) && 200262306a36Sopenharmony_ci (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) && 200362306a36Sopenharmony_ci (req_resc->num_vlan_filters <= vf_vlan_rules_cnt(vf))); 200462306a36Sopenharmony_ci} 200562306a36Sopenharmony_ci 200662306a36Sopenharmony_ci/* CORE VF API */ 200762306a36Sopenharmony_ciint bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf, 200862306a36Sopenharmony_ci struct vf_pf_resc_request *resc) 200962306a36Sopenharmony_ci{ 201062306a36Sopenharmony_ci int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) * 201162306a36Sopenharmony_ci BNX2X_CIDS_PER_VF; 201262306a36Sopenharmony_ci 201362306a36Sopenharmony_ci union cdu_context *base_cxt = (union cdu_context *) 201462306a36Sopenharmony_ci BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr + 201562306a36Sopenharmony_ci (base_vf_cid & (ILT_PAGE_CIDS-1)); 201662306a36Sopenharmony_ci int i; 201762306a36Sopenharmony_ci 201862306a36Sopenharmony_ci /* if state is 'acquired' the VF was not released or FLR'd, in 201962306a36Sopenharmony_ci * this case the returned resources match the acquired already 202062306a36Sopenharmony_ci * acquired resources. Verify that the requested numbers do 202162306a36Sopenharmony_ci * not exceed the already acquired numbers. 202262306a36Sopenharmony_ci */ 202362306a36Sopenharmony_ci if (vf->state == VF_ACQUIRED) { 202462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n", 202562306a36Sopenharmony_ci vf->abs_vfid); 202662306a36Sopenharmony_ci 202762306a36Sopenharmony_ci if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) { 202862306a36Sopenharmony_ci BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n", 202962306a36Sopenharmony_ci vf->abs_vfid); 203062306a36Sopenharmony_ci return -EINVAL; 203162306a36Sopenharmony_ci } 203262306a36Sopenharmony_ci return 0; 203362306a36Sopenharmony_ci } 203462306a36Sopenharmony_ci 203562306a36Sopenharmony_ci /* Otherwise vf state must be 'free' or 'reset' */ 203662306a36Sopenharmony_ci if (vf->state != VF_FREE && vf->state != VF_RESET) { 203762306a36Sopenharmony_ci BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n", 203862306a36Sopenharmony_ci vf->abs_vfid, vf->state); 203962306a36Sopenharmony_ci return -EINVAL; 204062306a36Sopenharmony_ci } 204162306a36Sopenharmony_ci 204262306a36Sopenharmony_ci /* static allocation: 204362306a36Sopenharmony_ci * the global maximum number are fixed per VF. Fail the request if 204462306a36Sopenharmony_ci * requested number exceed these globals 204562306a36Sopenharmony_ci */ 204662306a36Sopenharmony_ci if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) { 204762306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 204862306a36Sopenharmony_ci "cannot fulfill vf resource request. Placing maximal available values in response\n"); 204962306a36Sopenharmony_ci /* set the max resource in the vf */ 205062306a36Sopenharmony_ci return -ENOMEM; 205162306a36Sopenharmony_ci } 205262306a36Sopenharmony_ci 205362306a36Sopenharmony_ci /* Set resources counters - 0 request means max available */ 205462306a36Sopenharmony_ci vf_sb_count(vf) = resc->num_sbs; 205562306a36Sopenharmony_ci vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf); 205662306a36Sopenharmony_ci vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf); 205762306a36Sopenharmony_ci 205862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 205962306a36Sopenharmony_ci "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n", 206062306a36Sopenharmony_ci vf_sb_count(vf), vf_rxq_count(vf), 206162306a36Sopenharmony_ci vf_txq_count(vf), vf_mac_rules_cnt(vf), 206262306a36Sopenharmony_ci vf_vlan_rules_cnt(vf)); 206362306a36Sopenharmony_ci 206462306a36Sopenharmony_ci /* Initialize the queues */ 206562306a36Sopenharmony_ci if (!vf->vfqs) { 206662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n"); 206762306a36Sopenharmony_ci return -EINVAL; 206862306a36Sopenharmony_ci } 206962306a36Sopenharmony_ci 207062306a36Sopenharmony_ci for_each_vfq(vf, i) { 207162306a36Sopenharmony_ci struct bnx2x_vf_queue *q = vfq_get(vf, i); 207262306a36Sopenharmony_ci 207362306a36Sopenharmony_ci if (!q) { 207462306a36Sopenharmony_ci BNX2X_ERR("q number %d was not allocated\n", i); 207562306a36Sopenharmony_ci return -EINVAL; 207662306a36Sopenharmony_ci } 207762306a36Sopenharmony_ci 207862306a36Sopenharmony_ci q->index = i; 207962306a36Sopenharmony_ci q->cxt = &((base_cxt + i)->eth); 208062306a36Sopenharmony_ci q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i; 208162306a36Sopenharmony_ci 208262306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n", 208362306a36Sopenharmony_ci vf->abs_vfid, i, q->index, q->cid, q->cxt); 208462306a36Sopenharmony_ci 208562306a36Sopenharmony_ci /* init SP objects */ 208662306a36Sopenharmony_ci bnx2x_vfq_init(bp, vf, q); 208762306a36Sopenharmony_ci } 208862306a36Sopenharmony_ci vf->state = VF_ACQUIRED; 208962306a36Sopenharmony_ci return 0; 209062306a36Sopenharmony_ci} 209162306a36Sopenharmony_ci 209262306a36Sopenharmony_ciint bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map) 209362306a36Sopenharmony_ci{ 209462306a36Sopenharmony_ci struct bnx2x_func_init_params func_init = {0}; 209562306a36Sopenharmony_ci int i; 209662306a36Sopenharmony_ci 209762306a36Sopenharmony_ci /* the sb resources are initialized at this point, do the 209862306a36Sopenharmony_ci * FW/HW initializations 209962306a36Sopenharmony_ci */ 210062306a36Sopenharmony_ci for_each_vf_sb(vf, i) 210162306a36Sopenharmony_ci bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true, 210262306a36Sopenharmony_ci vf_igu_sb(vf, i), vf_igu_sb(vf, i)); 210362306a36Sopenharmony_ci 210462306a36Sopenharmony_ci /* Sanity checks */ 210562306a36Sopenharmony_ci if (vf->state != VF_ACQUIRED) { 210662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n", 210762306a36Sopenharmony_ci vf->abs_vfid, vf->state); 210862306a36Sopenharmony_ci return -EINVAL; 210962306a36Sopenharmony_ci } 211062306a36Sopenharmony_ci 211162306a36Sopenharmony_ci /* let FLR complete ... */ 211262306a36Sopenharmony_ci msleep(100); 211362306a36Sopenharmony_ci 211462306a36Sopenharmony_ci /* FLR cleanup epilogue */ 211562306a36Sopenharmony_ci if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid)) 211662306a36Sopenharmony_ci return -EBUSY; 211762306a36Sopenharmony_ci 211862306a36Sopenharmony_ci /* reset IGU VF statistics: MSIX */ 211962306a36Sopenharmony_ci REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0); 212062306a36Sopenharmony_ci 212162306a36Sopenharmony_ci /* function setup */ 212262306a36Sopenharmony_ci func_init.pf_id = BP_FUNC(bp); 212362306a36Sopenharmony_ci func_init.func_id = FW_VF_HANDLE(vf->abs_vfid); 212462306a36Sopenharmony_ci bnx2x_func_init(bp, &func_init); 212562306a36Sopenharmony_ci 212662306a36Sopenharmony_ci /* Enable the vf */ 212762306a36Sopenharmony_ci bnx2x_vf_enable_access(bp, vf->abs_vfid); 212862306a36Sopenharmony_ci bnx2x_vf_enable_traffic(bp, vf); 212962306a36Sopenharmony_ci 213062306a36Sopenharmony_ci /* queue protection table */ 213162306a36Sopenharmony_ci for_each_vfq(vf, i) 213262306a36Sopenharmony_ci bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid, 213362306a36Sopenharmony_ci vfq_qzone_id(vf, vfq_get(vf, i)), true); 213462306a36Sopenharmony_ci 213562306a36Sopenharmony_ci vf->state = VF_ENABLED; 213662306a36Sopenharmony_ci 213762306a36Sopenharmony_ci /* update vf bulletin board */ 213862306a36Sopenharmony_ci bnx2x_post_vf_bulletin(bp, vf->index); 213962306a36Sopenharmony_ci 214062306a36Sopenharmony_ci return 0; 214162306a36Sopenharmony_ci} 214262306a36Sopenharmony_ci 214362306a36Sopenharmony_cistruct set_vf_state_cookie { 214462306a36Sopenharmony_ci struct bnx2x_virtf *vf; 214562306a36Sopenharmony_ci u8 state; 214662306a36Sopenharmony_ci}; 214762306a36Sopenharmony_ci 214862306a36Sopenharmony_cistatic void bnx2x_set_vf_state(void *cookie) 214962306a36Sopenharmony_ci{ 215062306a36Sopenharmony_ci struct set_vf_state_cookie *p = (struct set_vf_state_cookie *)cookie; 215162306a36Sopenharmony_ci 215262306a36Sopenharmony_ci p->vf->state = p->state; 215362306a36Sopenharmony_ci} 215462306a36Sopenharmony_ci 215562306a36Sopenharmony_ciint bnx2x_vf_close(struct bnx2x *bp, struct bnx2x_virtf *vf) 215662306a36Sopenharmony_ci{ 215762306a36Sopenharmony_ci int rc = 0, i; 215862306a36Sopenharmony_ci 215962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 216062306a36Sopenharmony_ci 216162306a36Sopenharmony_ci /* Close all queues */ 216262306a36Sopenharmony_ci for (i = 0; i < vf_rxq_count(vf); i++) { 216362306a36Sopenharmony_ci rc = bnx2x_vf_queue_teardown(bp, vf, i); 216462306a36Sopenharmony_ci if (rc) 216562306a36Sopenharmony_ci goto op_err; 216662306a36Sopenharmony_ci } 216762306a36Sopenharmony_ci 216862306a36Sopenharmony_ci /* disable the interrupts */ 216962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "disabling igu\n"); 217062306a36Sopenharmony_ci bnx2x_vf_igu_disable(bp, vf); 217162306a36Sopenharmony_ci 217262306a36Sopenharmony_ci /* disable the VF */ 217362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "clearing qtbl\n"); 217462306a36Sopenharmony_ci bnx2x_vf_clr_qtbl(bp, vf); 217562306a36Sopenharmony_ci 217662306a36Sopenharmony_ci /* need to make sure there are no outstanding stats ramrods which may 217762306a36Sopenharmony_ci * cause the device to access the VF's stats buffer which it will free 217862306a36Sopenharmony_ci * as soon as we return from the close flow. 217962306a36Sopenharmony_ci */ 218062306a36Sopenharmony_ci { 218162306a36Sopenharmony_ci struct set_vf_state_cookie cookie; 218262306a36Sopenharmony_ci 218362306a36Sopenharmony_ci cookie.vf = vf; 218462306a36Sopenharmony_ci cookie.state = VF_ACQUIRED; 218562306a36Sopenharmony_ci rc = bnx2x_stats_safe_exec(bp, bnx2x_set_vf_state, &cookie); 218662306a36Sopenharmony_ci if (rc) 218762306a36Sopenharmony_ci goto op_err; 218862306a36Sopenharmony_ci } 218962306a36Sopenharmony_ci 219062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "set state to acquired\n"); 219162306a36Sopenharmony_ci 219262306a36Sopenharmony_ci return 0; 219362306a36Sopenharmony_ciop_err: 219462306a36Sopenharmony_ci BNX2X_ERR("vf[%d] CLOSE error: rc %d\n", vf->abs_vfid, rc); 219562306a36Sopenharmony_ci return rc; 219662306a36Sopenharmony_ci} 219762306a36Sopenharmony_ci 219862306a36Sopenharmony_ci/* VF release can be called either: 1. The VF was acquired but 219962306a36Sopenharmony_ci * not enabled 2. the vf was enabled or in the process of being 220062306a36Sopenharmony_ci * enabled 220162306a36Sopenharmony_ci */ 220262306a36Sopenharmony_ciint bnx2x_vf_free(struct bnx2x *bp, struct bnx2x_virtf *vf) 220362306a36Sopenharmony_ci{ 220462306a36Sopenharmony_ci int rc; 220562306a36Sopenharmony_ci 220662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d] STATE: %s\n", vf->abs_vfid, 220762306a36Sopenharmony_ci vf->state == VF_FREE ? "Free" : 220862306a36Sopenharmony_ci vf->state == VF_ACQUIRED ? "Acquired" : 220962306a36Sopenharmony_ci vf->state == VF_ENABLED ? "Enabled" : 221062306a36Sopenharmony_ci vf->state == VF_RESET ? "Reset" : 221162306a36Sopenharmony_ci "Unknown"); 221262306a36Sopenharmony_ci 221362306a36Sopenharmony_ci switch (vf->state) { 221462306a36Sopenharmony_ci case VF_ENABLED: 221562306a36Sopenharmony_ci rc = bnx2x_vf_close(bp, vf); 221662306a36Sopenharmony_ci if (rc) 221762306a36Sopenharmony_ci goto op_err; 221862306a36Sopenharmony_ci fallthrough; /* to release resources */ 221962306a36Sopenharmony_ci case VF_ACQUIRED: 222062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "about to free resources\n"); 222162306a36Sopenharmony_ci bnx2x_vf_free_resc(bp, vf); 222262306a36Sopenharmony_ci break; 222362306a36Sopenharmony_ci 222462306a36Sopenharmony_ci case VF_FREE: 222562306a36Sopenharmony_ci case VF_RESET: 222662306a36Sopenharmony_ci default: 222762306a36Sopenharmony_ci break; 222862306a36Sopenharmony_ci } 222962306a36Sopenharmony_ci return 0; 223062306a36Sopenharmony_ciop_err: 223162306a36Sopenharmony_ci BNX2X_ERR("VF[%d] RELEASE error: rc %d\n", vf->abs_vfid, rc); 223262306a36Sopenharmony_ci return rc; 223362306a36Sopenharmony_ci} 223462306a36Sopenharmony_ci 223562306a36Sopenharmony_ciint bnx2x_vf_rss_update(struct bnx2x *bp, struct bnx2x_virtf *vf, 223662306a36Sopenharmony_ci struct bnx2x_config_rss_params *rss) 223762306a36Sopenharmony_ci{ 223862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 223962306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &rss->ramrod_flags); 224062306a36Sopenharmony_ci return bnx2x_config_rss(bp, rss); 224162306a36Sopenharmony_ci} 224262306a36Sopenharmony_ci 224362306a36Sopenharmony_ciint bnx2x_vf_tpa_update(struct bnx2x *bp, struct bnx2x_virtf *vf, 224462306a36Sopenharmony_ci struct vfpf_tpa_tlv *tlv, 224562306a36Sopenharmony_ci struct bnx2x_queue_update_tpa_params *params) 224662306a36Sopenharmony_ci{ 224762306a36Sopenharmony_ci aligned_u64 *sge_addr = tlv->tpa_client_info.sge_addr; 224862306a36Sopenharmony_ci struct bnx2x_queue_state_params qstate; 224962306a36Sopenharmony_ci int qid, rc = 0; 225062306a36Sopenharmony_ci 225162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf[%d]\n", vf->abs_vfid); 225262306a36Sopenharmony_ci 225362306a36Sopenharmony_ci /* Set ramrod params */ 225462306a36Sopenharmony_ci memset(&qstate, 0, sizeof(struct bnx2x_queue_state_params)); 225562306a36Sopenharmony_ci memcpy(&qstate.params.update_tpa, params, 225662306a36Sopenharmony_ci sizeof(struct bnx2x_queue_update_tpa_params)); 225762306a36Sopenharmony_ci qstate.cmd = BNX2X_Q_CMD_UPDATE_TPA; 225862306a36Sopenharmony_ci set_bit(RAMROD_COMP_WAIT, &qstate.ramrod_flags); 225962306a36Sopenharmony_ci 226062306a36Sopenharmony_ci for (qid = 0; qid < vf_rxq_count(vf); qid++) { 226162306a36Sopenharmony_ci qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj); 226262306a36Sopenharmony_ci qstate.params.update_tpa.sge_map = sge_addr[qid]; 226362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "sge_addr[%d:%d] %08x:%08x\n", 226462306a36Sopenharmony_ci vf->abs_vfid, qid, U64_HI(sge_addr[qid]), 226562306a36Sopenharmony_ci U64_LO(sge_addr[qid])); 226662306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &qstate); 226762306a36Sopenharmony_ci if (rc) { 226862306a36Sopenharmony_ci BNX2X_ERR("Failed to configure sge_addr %08x:%08x for [%d:%d]\n", 226962306a36Sopenharmony_ci U64_HI(sge_addr[qid]), U64_LO(sge_addr[qid]), 227062306a36Sopenharmony_ci vf->abs_vfid, qid); 227162306a36Sopenharmony_ci return rc; 227262306a36Sopenharmony_ci } 227362306a36Sopenharmony_ci } 227462306a36Sopenharmony_ci 227562306a36Sopenharmony_ci return rc; 227662306a36Sopenharmony_ci} 227762306a36Sopenharmony_ci 227862306a36Sopenharmony_ci/* VF release ~ VF close + VF release-resources 227962306a36Sopenharmony_ci * Release is the ultimate SW shutdown and is called whenever an 228062306a36Sopenharmony_ci * irrecoverable error is encountered. 228162306a36Sopenharmony_ci */ 228262306a36Sopenharmony_ciint bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf) 228362306a36Sopenharmony_ci{ 228462306a36Sopenharmony_ci int rc; 228562306a36Sopenharmony_ci 228662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "PF releasing vf %d\n", vf->abs_vfid); 228762306a36Sopenharmony_ci bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF); 228862306a36Sopenharmony_ci 228962306a36Sopenharmony_ci rc = bnx2x_vf_free(bp, vf); 229062306a36Sopenharmony_ci if (rc) 229162306a36Sopenharmony_ci WARN(rc, 229262306a36Sopenharmony_ci "VF[%d] Failed to allocate resources for release op- rc=%d\n", 229362306a36Sopenharmony_ci vf->abs_vfid, rc); 229462306a36Sopenharmony_ci bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF); 229562306a36Sopenharmony_ci return rc; 229662306a36Sopenharmony_ci} 229762306a36Sopenharmony_ci 229862306a36Sopenharmony_civoid bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf, 229962306a36Sopenharmony_ci enum channel_tlvs tlv) 230062306a36Sopenharmony_ci{ 230162306a36Sopenharmony_ci /* we don't lock the channel for unsupported tlvs */ 230262306a36Sopenharmony_ci if (!bnx2x_tlv_supported(tlv)) { 230362306a36Sopenharmony_ci BNX2X_ERR("attempting to lock with unsupported tlv. Aborting\n"); 230462306a36Sopenharmony_ci return; 230562306a36Sopenharmony_ci } 230662306a36Sopenharmony_ci 230762306a36Sopenharmony_ci /* lock the channel */ 230862306a36Sopenharmony_ci mutex_lock(&vf->op_mutex); 230962306a36Sopenharmony_ci 231062306a36Sopenharmony_ci /* record the locking op */ 231162306a36Sopenharmony_ci vf->op_current = tlv; 231262306a36Sopenharmony_ci 231362306a36Sopenharmony_ci /* log the lock */ 231462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n", 231562306a36Sopenharmony_ci vf->abs_vfid, tlv); 231662306a36Sopenharmony_ci} 231762306a36Sopenharmony_ci 231862306a36Sopenharmony_civoid bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf, 231962306a36Sopenharmony_ci enum channel_tlvs expected_tlv) 232062306a36Sopenharmony_ci{ 232162306a36Sopenharmony_ci enum channel_tlvs current_tlv; 232262306a36Sopenharmony_ci 232362306a36Sopenharmony_ci if (!vf) { 232462306a36Sopenharmony_ci BNX2X_ERR("VF was %p\n", vf); 232562306a36Sopenharmony_ci return; 232662306a36Sopenharmony_ci } 232762306a36Sopenharmony_ci 232862306a36Sopenharmony_ci current_tlv = vf->op_current; 232962306a36Sopenharmony_ci 233062306a36Sopenharmony_ci /* we don't unlock the channel for unsupported tlvs */ 233162306a36Sopenharmony_ci if (!bnx2x_tlv_supported(expected_tlv)) 233262306a36Sopenharmony_ci return; 233362306a36Sopenharmony_ci 233462306a36Sopenharmony_ci WARN(expected_tlv != vf->op_current, 233562306a36Sopenharmony_ci "lock mismatch: expected %d found %d", expected_tlv, 233662306a36Sopenharmony_ci vf->op_current); 233762306a36Sopenharmony_ci 233862306a36Sopenharmony_ci /* record the locking op */ 233962306a36Sopenharmony_ci vf->op_current = CHANNEL_TLV_NONE; 234062306a36Sopenharmony_ci 234162306a36Sopenharmony_ci /* lock the channel */ 234262306a36Sopenharmony_ci mutex_unlock(&vf->op_mutex); 234362306a36Sopenharmony_ci 234462306a36Sopenharmony_ci /* log the unlock */ 234562306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n", 234662306a36Sopenharmony_ci vf->abs_vfid, current_tlv); 234762306a36Sopenharmony_ci} 234862306a36Sopenharmony_ci 234962306a36Sopenharmony_cistatic int bnx2x_set_pf_tx_switching(struct bnx2x *bp, bool enable) 235062306a36Sopenharmony_ci{ 235162306a36Sopenharmony_ci struct bnx2x_queue_state_params q_params; 235262306a36Sopenharmony_ci u32 prev_flags; 235362306a36Sopenharmony_ci int i, rc; 235462306a36Sopenharmony_ci 235562306a36Sopenharmony_ci /* Verify changes are needed and record current Tx switching state */ 235662306a36Sopenharmony_ci prev_flags = bp->flags; 235762306a36Sopenharmony_ci if (enable) 235862306a36Sopenharmony_ci bp->flags |= TX_SWITCHING; 235962306a36Sopenharmony_ci else 236062306a36Sopenharmony_ci bp->flags &= ~TX_SWITCHING; 236162306a36Sopenharmony_ci if (prev_flags == bp->flags) 236262306a36Sopenharmony_ci return 0; 236362306a36Sopenharmony_ci 236462306a36Sopenharmony_ci /* Verify state enables the sending of queue ramrods */ 236562306a36Sopenharmony_ci if ((bp->state != BNX2X_STATE_OPEN) || 236662306a36Sopenharmony_ci (bnx2x_get_q_logical_state(bp, 236762306a36Sopenharmony_ci &bnx2x_sp_obj(bp, &bp->fp[0]).q_obj) != 236862306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE)) 236962306a36Sopenharmony_ci return 0; 237062306a36Sopenharmony_ci 237162306a36Sopenharmony_ci /* send q. update ramrod to configure Tx switching */ 237262306a36Sopenharmony_ci memset(&q_params, 0, sizeof(q_params)); 237362306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 237462306a36Sopenharmony_ci q_params.cmd = BNX2X_Q_CMD_UPDATE; 237562306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING_CHNG, 237662306a36Sopenharmony_ci &q_params.params.update.update_flags); 237762306a36Sopenharmony_ci if (enable) 237862306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_TX_SWITCHING, 237962306a36Sopenharmony_ci &q_params.params.update.update_flags); 238062306a36Sopenharmony_ci else 238162306a36Sopenharmony_ci __clear_bit(BNX2X_Q_UPDATE_TX_SWITCHING, 238262306a36Sopenharmony_ci &q_params.params.update.update_flags); 238362306a36Sopenharmony_ci 238462306a36Sopenharmony_ci /* send the ramrod on all the queues of the PF */ 238562306a36Sopenharmony_ci for_each_eth_queue(bp, i) { 238662306a36Sopenharmony_ci struct bnx2x_fastpath *fp = &bp->fp[i]; 238762306a36Sopenharmony_ci int tx_idx; 238862306a36Sopenharmony_ci 238962306a36Sopenharmony_ci /* Set the appropriate Queue object */ 239062306a36Sopenharmony_ci q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj; 239162306a36Sopenharmony_ci 239262306a36Sopenharmony_ci for (tx_idx = FIRST_TX_COS_INDEX; 239362306a36Sopenharmony_ci tx_idx < fp->max_cos; tx_idx++) { 239462306a36Sopenharmony_ci q_params.params.update.cid_index = tx_idx; 239562306a36Sopenharmony_ci 239662306a36Sopenharmony_ci /* Update the Queue state */ 239762306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &q_params); 239862306a36Sopenharmony_ci if (rc) { 239962306a36Sopenharmony_ci BNX2X_ERR("Failed to configure Tx switching\n"); 240062306a36Sopenharmony_ci return rc; 240162306a36Sopenharmony_ci } 240262306a36Sopenharmony_ci } 240362306a36Sopenharmony_ci } 240462306a36Sopenharmony_ci 240562306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "%s Tx Switching\n", enable ? "Enabled" : "Disabled"); 240662306a36Sopenharmony_ci return 0; 240762306a36Sopenharmony_ci} 240862306a36Sopenharmony_ci 240962306a36Sopenharmony_ciint bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs_param) 241062306a36Sopenharmony_ci{ 241162306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(pci_get_drvdata(dev)); 241262306a36Sopenharmony_ci 241362306a36Sopenharmony_ci if (!IS_SRIOV(bp)) { 241462306a36Sopenharmony_ci BNX2X_ERR("failed to configure SR-IOV since vfdb was not allocated. Check dmesg for errors in probe stage\n"); 241562306a36Sopenharmony_ci return -EINVAL; 241662306a36Sopenharmony_ci } 241762306a36Sopenharmony_ci 241862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "bnx2x_sriov_configure called with %d, BNX2X_NR_VIRTFN(bp) was %d\n", 241962306a36Sopenharmony_ci num_vfs_param, BNX2X_NR_VIRTFN(bp)); 242062306a36Sopenharmony_ci 242162306a36Sopenharmony_ci /* HW channel is only operational when PF is up */ 242262306a36Sopenharmony_ci if (bp->state != BNX2X_STATE_OPEN) { 242362306a36Sopenharmony_ci BNX2X_ERR("VF num configuration via sysfs not supported while PF is down\n"); 242462306a36Sopenharmony_ci return -EINVAL; 242562306a36Sopenharmony_ci } 242662306a36Sopenharmony_ci 242762306a36Sopenharmony_ci /* we are always bound by the total_vfs in the configuration space */ 242862306a36Sopenharmony_ci if (num_vfs_param > BNX2X_NR_VIRTFN(bp)) { 242962306a36Sopenharmony_ci BNX2X_ERR("truncating requested number of VFs (%d) down to maximum allowed (%d)\n", 243062306a36Sopenharmony_ci num_vfs_param, BNX2X_NR_VIRTFN(bp)); 243162306a36Sopenharmony_ci num_vfs_param = BNX2X_NR_VIRTFN(bp); 243262306a36Sopenharmony_ci } 243362306a36Sopenharmony_ci 243462306a36Sopenharmony_ci bp->requested_nr_virtfn = num_vfs_param; 243562306a36Sopenharmony_ci if (num_vfs_param == 0) { 243662306a36Sopenharmony_ci bnx2x_set_pf_tx_switching(bp, false); 243762306a36Sopenharmony_ci bnx2x_disable_sriov(bp); 243862306a36Sopenharmony_ci return 0; 243962306a36Sopenharmony_ci } else { 244062306a36Sopenharmony_ci return bnx2x_enable_sriov(bp); 244162306a36Sopenharmony_ci } 244262306a36Sopenharmony_ci} 244362306a36Sopenharmony_ci 244462306a36Sopenharmony_ci#define IGU_ENTRY_SIZE 4 244562306a36Sopenharmony_ci 244662306a36Sopenharmony_ciint bnx2x_enable_sriov(struct bnx2x *bp) 244762306a36Sopenharmony_ci{ 244862306a36Sopenharmony_ci int rc = 0, req_vfs = bp->requested_nr_virtfn; 244962306a36Sopenharmony_ci int vf_idx, sb_idx, vfq_idx, qcount, first_vf; 245062306a36Sopenharmony_ci u32 igu_entry, address; 245162306a36Sopenharmony_ci u16 num_vf_queues; 245262306a36Sopenharmony_ci 245362306a36Sopenharmony_ci if (req_vfs == 0) 245462306a36Sopenharmony_ci return 0; 245562306a36Sopenharmony_ci 245662306a36Sopenharmony_ci first_vf = bp->vfdb->sriov.first_vf_in_pf; 245762306a36Sopenharmony_ci 245862306a36Sopenharmony_ci /* statically distribute vf sb pool between VFs */ 245962306a36Sopenharmony_ci num_vf_queues = min_t(u16, BNX2X_VF_MAX_QUEUES, 246062306a36Sopenharmony_ci BP_VFDB(bp)->vf_sbs_pool / req_vfs); 246162306a36Sopenharmony_ci 246262306a36Sopenharmony_ci /* zero previous values learned from igu cam */ 246362306a36Sopenharmony_ci for (vf_idx = 0; vf_idx < req_vfs; vf_idx++) { 246462306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, vf_idx); 246562306a36Sopenharmony_ci 246662306a36Sopenharmony_ci vf->sb_count = 0; 246762306a36Sopenharmony_ci vf_sb_count(BP_VF(bp, vf_idx)) = 0; 246862306a36Sopenharmony_ci } 246962306a36Sopenharmony_ci bp->vfdb->vf_sbs_pool = 0; 247062306a36Sopenharmony_ci 247162306a36Sopenharmony_ci /* prepare IGU cam */ 247262306a36Sopenharmony_ci sb_idx = BP_VFDB(bp)->first_vf_igu_entry; 247362306a36Sopenharmony_ci address = IGU_REG_MAPPING_MEMORY + sb_idx * IGU_ENTRY_SIZE; 247462306a36Sopenharmony_ci for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) { 247562306a36Sopenharmony_ci for (vfq_idx = 0; vfq_idx < num_vf_queues; vfq_idx++) { 247662306a36Sopenharmony_ci igu_entry = vf_idx << IGU_REG_MAPPING_MEMORY_FID_SHIFT | 247762306a36Sopenharmony_ci vfq_idx << IGU_REG_MAPPING_MEMORY_VECTOR_SHIFT | 247862306a36Sopenharmony_ci IGU_REG_MAPPING_MEMORY_VALID; 247962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "assigning sb %d to vf %d\n", 248062306a36Sopenharmony_ci sb_idx, vf_idx); 248162306a36Sopenharmony_ci REG_WR(bp, address, igu_entry); 248262306a36Sopenharmony_ci sb_idx++; 248362306a36Sopenharmony_ci address += IGU_ENTRY_SIZE; 248462306a36Sopenharmony_ci } 248562306a36Sopenharmony_ci } 248662306a36Sopenharmony_ci 248762306a36Sopenharmony_ci /* Reinitialize vf database according to igu cam */ 248862306a36Sopenharmony_ci bnx2x_get_vf_igu_cam_info(bp); 248962306a36Sopenharmony_ci 249062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "vf_sbs_pool %d, num_vf_queues %d\n", 249162306a36Sopenharmony_ci BP_VFDB(bp)->vf_sbs_pool, num_vf_queues); 249262306a36Sopenharmony_ci 249362306a36Sopenharmony_ci qcount = 0; 249462306a36Sopenharmony_ci for_each_vf(bp, vf_idx) { 249562306a36Sopenharmony_ci struct bnx2x_virtf *vf = BP_VF(bp, vf_idx); 249662306a36Sopenharmony_ci 249762306a36Sopenharmony_ci /* set local queue arrays */ 249862306a36Sopenharmony_ci vf->vfqs = &bp->vfdb->vfqs[qcount]; 249962306a36Sopenharmony_ci qcount += vf_sb_count(vf); 250062306a36Sopenharmony_ci bnx2x_iov_static_resc(bp, vf); 250162306a36Sopenharmony_ci } 250262306a36Sopenharmony_ci 250362306a36Sopenharmony_ci /* prepare msix vectors in VF configuration space - the value in the 250462306a36Sopenharmony_ci * PCI configuration space should be the index of the last entry, 250562306a36Sopenharmony_ci * namely one less than the actual size of the table 250662306a36Sopenharmony_ci */ 250762306a36Sopenharmony_ci for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) { 250862306a36Sopenharmony_ci bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf_idx)); 250962306a36Sopenharmony_ci REG_WR(bp, PCICFG_OFFSET + GRC_CONFIG_REG_VF_MSIX_CONTROL, 251062306a36Sopenharmony_ci num_vf_queues - 1); 251162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "set msix vec num in VF %d cfg space to %d\n", 251262306a36Sopenharmony_ci vf_idx, num_vf_queues - 1); 251362306a36Sopenharmony_ci } 251462306a36Sopenharmony_ci bnx2x_pretend_func(bp, BP_ABS_FUNC(bp)); 251562306a36Sopenharmony_ci 251662306a36Sopenharmony_ci /* enable sriov. This will probe all the VFs, and consequentially cause 251762306a36Sopenharmony_ci * the "acquire" messages to appear on the VF PF channel. 251862306a36Sopenharmony_ci */ 251962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "about to call enable sriov\n"); 252062306a36Sopenharmony_ci bnx2x_disable_sriov(bp); 252162306a36Sopenharmony_ci 252262306a36Sopenharmony_ci rc = bnx2x_set_pf_tx_switching(bp, true); 252362306a36Sopenharmony_ci if (rc) 252462306a36Sopenharmony_ci return rc; 252562306a36Sopenharmony_ci 252662306a36Sopenharmony_ci rc = pci_enable_sriov(bp->pdev, req_vfs); 252762306a36Sopenharmony_ci if (rc) { 252862306a36Sopenharmony_ci BNX2X_ERR("pci_enable_sriov failed with %d\n", rc); 252962306a36Sopenharmony_ci return rc; 253062306a36Sopenharmony_ci } 253162306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "sriov enabled (%d vfs)\n", req_vfs); 253262306a36Sopenharmony_ci return req_vfs; 253362306a36Sopenharmony_ci} 253462306a36Sopenharmony_ci 253562306a36Sopenharmony_civoid bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) 253662306a36Sopenharmony_ci{ 253762306a36Sopenharmony_ci int vfidx; 253862306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin; 253962306a36Sopenharmony_ci 254062306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "configuring vlan for VFs from sp-task\n"); 254162306a36Sopenharmony_ci for_each_vf(bp, vfidx) { 254262306a36Sopenharmony_ci bulletin = BP_VF_BULLETIN(bp, vfidx); 254362306a36Sopenharmony_ci if (bulletin->valid_bitmap & (1 << VLAN_VALID)) 254462306a36Sopenharmony_ci bnx2x_set_vf_vlan(bp->dev, vfidx, bulletin->vlan, 0, 254562306a36Sopenharmony_ci htons(ETH_P_8021Q)); 254662306a36Sopenharmony_ci } 254762306a36Sopenharmony_ci} 254862306a36Sopenharmony_ci 254962306a36Sopenharmony_civoid bnx2x_disable_sriov(struct bnx2x *bp) 255062306a36Sopenharmony_ci{ 255162306a36Sopenharmony_ci if (pci_vfs_assigned(bp->pdev)) { 255262306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 255362306a36Sopenharmony_ci "Unloading driver while VFs are assigned - VFs will not be deallocated\n"); 255462306a36Sopenharmony_ci return; 255562306a36Sopenharmony_ci } 255662306a36Sopenharmony_ci 255762306a36Sopenharmony_ci pci_disable_sriov(bp->pdev); 255862306a36Sopenharmony_ci} 255962306a36Sopenharmony_ci 256062306a36Sopenharmony_cistatic int bnx2x_vf_op_prep(struct bnx2x *bp, int vfidx, 256162306a36Sopenharmony_ci struct bnx2x_virtf **vf, 256262306a36Sopenharmony_ci struct pf_vf_bulletin_content **bulletin, 256362306a36Sopenharmony_ci bool test_queue) 256462306a36Sopenharmony_ci{ 256562306a36Sopenharmony_ci if (bp->state != BNX2X_STATE_OPEN) { 256662306a36Sopenharmony_ci BNX2X_ERR("PF is down - can't utilize iov-related functionality\n"); 256762306a36Sopenharmony_ci return -EINVAL; 256862306a36Sopenharmony_ci } 256962306a36Sopenharmony_ci 257062306a36Sopenharmony_ci if (!IS_SRIOV(bp)) { 257162306a36Sopenharmony_ci BNX2X_ERR("sriov is disabled - can't utilize iov-related functionality\n"); 257262306a36Sopenharmony_ci return -EINVAL; 257362306a36Sopenharmony_ci } 257462306a36Sopenharmony_ci 257562306a36Sopenharmony_ci if (vfidx >= BNX2X_NR_VIRTFN(bp)) { 257662306a36Sopenharmony_ci BNX2X_ERR("VF is uninitialized - can't utilize iov-related functionality. vfidx was %d BNX2X_NR_VIRTFN was %d\n", 257762306a36Sopenharmony_ci vfidx, BNX2X_NR_VIRTFN(bp)); 257862306a36Sopenharmony_ci return -EINVAL; 257962306a36Sopenharmony_ci } 258062306a36Sopenharmony_ci 258162306a36Sopenharmony_ci /* init members */ 258262306a36Sopenharmony_ci *vf = BP_VF(bp, vfidx); 258362306a36Sopenharmony_ci *bulletin = BP_VF_BULLETIN(bp, vfidx); 258462306a36Sopenharmony_ci 258562306a36Sopenharmony_ci if (!*vf) { 258662306a36Sopenharmony_ci BNX2X_ERR("Unable to get VF structure for vfidx %d\n", vfidx); 258762306a36Sopenharmony_ci return -EINVAL; 258862306a36Sopenharmony_ci } 258962306a36Sopenharmony_ci 259062306a36Sopenharmony_ci if (test_queue && !(*vf)->vfqs) { 259162306a36Sopenharmony_ci BNX2X_ERR("vfqs struct is null. Was this invoked before dynamically enabling SR-IOV? vfidx was %d\n", 259262306a36Sopenharmony_ci vfidx); 259362306a36Sopenharmony_ci return -EINVAL; 259462306a36Sopenharmony_ci } 259562306a36Sopenharmony_ci 259662306a36Sopenharmony_ci if (!*bulletin) { 259762306a36Sopenharmony_ci BNX2X_ERR("Bulletin Board struct is null for vfidx %d\n", 259862306a36Sopenharmony_ci vfidx); 259962306a36Sopenharmony_ci return -EINVAL; 260062306a36Sopenharmony_ci } 260162306a36Sopenharmony_ci 260262306a36Sopenharmony_ci return 0; 260362306a36Sopenharmony_ci} 260462306a36Sopenharmony_ci 260562306a36Sopenharmony_ciint bnx2x_get_vf_config(struct net_device *dev, int vfidx, 260662306a36Sopenharmony_ci struct ifla_vf_info *ivi) 260762306a36Sopenharmony_ci{ 260862306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(dev); 260962306a36Sopenharmony_ci struct bnx2x_virtf *vf = NULL; 261062306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin = NULL; 261162306a36Sopenharmony_ci struct bnx2x_vlan_mac_obj *mac_obj; 261262306a36Sopenharmony_ci struct bnx2x_vlan_mac_obj *vlan_obj; 261362306a36Sopenharmony_ci int rc; 261462306a36Sopenharmony_ci 261562306a36Sopenharmony_ci /* sanity and init */ 261662306a36Sopenharmony_ci rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true); 261762306a36Sopenharmony_ci if (rc) 261862306a36Sopenharmony_ci return rc; 261962306a36Sopenharmony_ci 262062306a36Sopenharmony_ci mac_obj = &bnx2x_leading_vfq(vf, mac_obj); 262162306a36Sopenharmony_ci vlan_obj = &bnx2x_leading_vfq(vf, vlan_obj); 262262306a36Sopenharmony_ci if (!mac_obj || !vlan_obj) { 262362306a36Sopenharmony_ci BNX2X_ERR("VF partially initialized\n"); 262462306a36Sopenharmony_ci return -EINVAL; 262562306a36Sopenharmony_ci } 262662306a36Sopenharmony_ci 262762306a36Sopenharmony_ci ivi->vf = vfidx; 262862306a36Sopenharmony_ci ivi->qos = 0; 262962306a36Sopenharmony_ci ivi->max_tx_rate = 10000; /* always 10G. TBA take from link struct */ 263062306a36Sopenharmony_ci ivi->min_tx_rate = 0; 263162306a36Sopenharmony_ci ivi->spoofchk = vf->spoofchk ? 1 : 0; 263262306a36Sopenharmony_ci ivi->linkstate = vf->link_cfg; 263362306a36Sopenharmony_ci if (vf->state == VF_ENABLED) { 263462306a36Sopenharmony_ci /* mac and vlan are in vlan_mac objects */ 263562306a36Sopenharmony_ci if (bnx2x_validate_vf_sp_objs(bp, vf, false)) { 263662306a36Sopenharmony_ci mac_obj->get_n_elements(bp, mac_obj, 1, (u8 *)&ivi->mac, 263762306a36Sopenharmony_ci 0, ETH_ALEN); 263862306a36Sopenharmony_ci vlan_obj->get_n_elements(bp, vlan_obj, 1, 263962306a36Sopenharmony_ci (u8 *)&ivi->vlan, 0, 264062306a36Sopenharmony_ci VLAN_HLEN); 264162306a36Sopenharmony_ci } 264262306a36Sopenharmony_ci } else { 264362306a36Sopenharmony_ci mutex_lock(&bp->vfdb->bulletin_mutex); 264462306a36Sopenharmony_ci /* mac */ 264562306a36Sopenharmony_ci if (bulletin->valid_bitmap & (1 << MAC_ADDR_VALID)) 264662306a36Sopenharmony_ci /* mac configured by ndo so its in bulletin board */ 264762306a36Sopenharmony_ci memcpy(&ivi->mac, bulletin->mac, ETH_ALEN); 264862306a36Sopenharmony_ci else 264962306a36Sopenharmony_ci /* function has not been loaded yet. Show mac as 0s */ 265062306a36Sopenharmony_ci eth_zero_addr(ivi->mac); 265162306a36Sopenharmony_ci 265262306a36Sopenharmony_ci /* vlan */ 265362306a36Sopenharmony_ci if (bulletin->valid_bitmap & (1 << VLAN_VALID)) 265462306a36Sopenharmony_ci /* vlan configured by ndo so its in bulletin board */ 265562306a36Sopenharmony_ci memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN); 265662306a36Sopenharmony_ci else 265762306a36Sopenharmony_ci /* function has not been loaded yet. Show vlans as 0s */ 265862306a36Sopenharmony_ci memset(&ivi->vlan, 0, VLAN_HLEN); 265962306a36Sopenharmony_ci 266062306a36Sopenharmony_ci mutex_unlock(&bp->vfdb->bulletin_mutex); 266162306a36Sopenharmony_ci } 266262306a36Sopenharmony_ci 266362306a36Sopenharmony_ci return 0; 266462306a36Sopenharmony_ci} 266562306a36Sopenharmony_ci 266662306a36Sopenharmony_ci/* New mac for VF. Consider these cases: 266762306a36Sopenharmony_ci * 1. VF hasn't been acquired yet - save the mac in local bulletin board and 266862306a36Sopenharmony_ci * supply at acquire. 266962306a36Sopenharmony_ci * 2. VF has already been acquired but has not yet initialized - store in local 267062306a36Sopenharmony_ci * bulletin board. mac will be posted on VF bulletin board after VF init. VF 267162306a36Sopenharmony_ci * will configure this mac when it is ready. 267262306a36Sopenharmony_ci * 3. VF has already initialized but has not yet setup a queue - post the new 267362306a36Sopenharmony_ci * mac on VF's bulletin board right now. VF will configure this mac when it 267462306a36Sopenharmony_ci * is ready. 267562306a36Sopenharmony_ci * 4. VF has already set a queue - delete any macs already configured for this 267662306a36Sopenharmony_ci * queue and manually config the new mac. 267762306a36Sopenharmony_ci * In any event, once this function has been called refuse any attempts by the 267862306a36Sopenharmony_ci * VF to configure any mac for itself except for this mac. In case of a race 267962306a36Sopenharmony_ci * where the VF fails to see the new post on its bulletin board before sending a 268062306a36Sopenharmony_ci * mac configuration request, the PF will simply fail the request and VF can try 268162306a36Sopenharmony_ci * again after consulting its bulletin board. 268262306a36Sopenharmony_ci */ 268362306a36Sopenharmony_ciint bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac) 268462306a36Sopenharmony_ci{ 268562306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(dev); 268662306a36Sopenharmony_ci int rc, q_logical_state; 268762306a36Sopenharmony_ci struct bnx2x_virtf *vf = NULL; 268862306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin = NULL; 268962306a36Sopenharmony_ci 269062306a36Sopenharmony_ci if (!is_valid_ether_addr(mac)) { 269162306a36Sopenharmony_ci BNX2X_ERR("mac address invalid\n"); 269262306a36Sopenharmony_ci return -EINVAL; 269362306a36Sopenharmony_ci } 269462306a36Sopenharmony_ci 269562306a36Sopenharmony_ci /* sanity and init */ 269662306a36Sopenharmony_ci rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true); 269762306a36Sopenharmony_ci if (rc) 269862306a36Sopenharmony_ci return rc; 269962306a36Sopenharmony_ci 270062306a36Sopenharmony_ci mutex_lock(&bp->vfdb->bulletin_mutex); 270162306a36Sopenharmony_ci 270262306a36Sopenharmony_ci /* update PF's copy of the VF's bulletin. Will no longer accept mac 270362306a36Sopenharmony_ci * configuration requests from vf unless match this mac 270462306a36Sopenharmony_ci */ 270562306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << MAC_ADDR_VALID; 270662306a36Sopenharmony_ci memcpy(bulletin->mac, mac, ETH_ALEN); 270762306a36Sopenharmony_ci 270862306a36Sopenharmony_ci /* Post update on VF's bulletin board */ 270962306a36Sopenharmony_ci rc = bnx2x_post_vf_bulletin(bp, vfidx); 271062306a36Sopenharmony_ci 271162306a36Sopenharmony_ci /* release lock before checking return code */ 271262306a36Sopenharmony_ci mutex_unlock(&bp->vfdb->bulletin_mutex); 271362306a36Sopenharmony_ci 271462306a36Sopenharmony_ci if (rc) { 271562306a36Sopenharmony_ci BNX2X_ERR("failed to update VF[%d] bulletin\n", vfidx); 271662306a36Sopenharmony_ci return rc; 271762306a36Sopenharmony_ci } 271862306a36Sopenharmony_ci 271962306a36Sopenharmony_ci q_logical_state = 272062306a36Sopenharmony_ci bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj)); 272162306a36Sopenharmony_ci if (vf->state == VF_ENABLED && 272262306a36Sopenharmony_ci q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) { 272362306a36Sopenharmony_ci /* configure the mac in device on this vf's queue */ 272462306a36Sopenharmony_ci unsigned long ramrod_flags = 0; 272562306a36Sopenharmony_ci struct bnx2x_vlan_mac_obj *mac_obj; 272662306a36Sopenharmony_ci 272762306a36Sopenharmony_ci /* User should be able to see failure reason in system logs */ 272862306a36Sopenharmony_ci if (!bnx2x_validate_vf_sp_objs(bp, vf, true)) 272962306a36Sopenharmony_ci return -EINVAL; 273062306a36Sopenharmony_ci 273162306a36Sopenharmony_ci /* must lock vfpf channel to protect against vf flows */ 273262306a36Sopenharmony_ci bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC); 273362306a36Sopenharmony_ci 273462306a36Sopenharmony_ci /* remove existing eth macs */ 273562306a36Sopenharmony_ci mac_obj = &bnx2x_leading_vfq(vf, mac_obj); 273662306a36Sopenharmony_ci rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true); 273762306a36Sopenharmony_ci if (rc) { 273862306a36Sopenharmony_ci BNX2X_ERR("failed to delete eth macs\n"); 273962306a36Sopenharmony_ci rc = -EINVAL; 274062306a36Sopenharmony_ci goto out; 274162306a36Sopenharmony_ci } 274262306a36Sopenharmony_ci 274362306a36Sopenharmony_ci /* remove existing uc list macs */ 274462306a36Sopenharmony_ci rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true); 274562306a36Sopenharmony_ci if (rc) { 274662306a36Sopenharmony_ci BNX2X_ERR("failed to delete uc_list macs\n"); 274762306a36Sopenharmony_ci rc = -EINVAL; 274862306a36Sopenharmony_ci goto out; 274962306a36Sopenharmony_ci } 275062306a36Sopenharmony_ci 275162306a36Sopenharmony_ci /* configure the new mac to device */ 275262306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 275362306a36Sopenharmony_ci bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true, 275462306a36Sopenharmony_ci BNX2X_ETH_MAC, &ramrod_flags); 275562306a36Sopenharmony_ci 275662306a36Sopenharmony_ciout: 275762306a36Sopenharmony_ci bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC); 275862306a36Sopenharmony_ci } 275962306a36Sopenharmony_ci 276062306a36Sopenharmony_ci return rc; 276162306a36Sopenharmony_ci} 276262306a36Sopenharmony_ci 276362306a36Sopenharmony_cistatic void bnx2x_set_vf_vlan_acceptance(struct bnx2x *bp, 276462306a36Sopenharmony_ci struct bnx2x_virtf *vf, bool accept) 276562306a36Sopenharmony_ci{ 276662306a36Sopenharmony_ci struct bnx2x_rx_mode_ramrod_params rx_ramrod; 276762306a36Sopenharmony_ci unsigned long accept_flags; 276862306a36Sopenharmony_ci 276962306a36Sopenharmony_ci /* need to remove/add the VF's accept_any_vlan bit */ 277062306a36Sopenharmony_ci accept_flags = bnx2x_leading_vfq(vf, accept_flags); 277162306a36Sopenharmony_ci if (accept) 277262306a36Sopenharmony_ci set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); 277362306a36Sopenharmony_ci else 277462306a36Sopenharmony_ci clear_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags); 277562306a36Sopenharmony_ci 277662306a36Sopenharmony_ci bnx2x_vf_prep_rx_mode(bp, LEADING_IDX, &rx_ramrod, vf, 277762306a36Sopenharmony_ci accept_flags); 277862306a36Sopenharmony_ci bnx2x_leading_vfq(vf, accept_flags) = accept_flags; 277962306a36Sopenharmony_ci bnx2x_config_rx_mode(bp, &rx_ramrod); 278062306a36Sopenharmony_ci} 278162306a36Sopenharmony_ci 278262306a36Sopenharmony_cistatic int bnx2x_set_vf_vlan_filter(struct bnx2x *bp, struct bnx2x_virtf *vf, 278362306a36Sopenharmony_ci u16 vlan, bool add) 278462306a36Sopenharmony_ci{ 278562306a36Sopenharmony_ci struct bnx2x_vlan_mac_ramrod_params ramrod_param; 278662306a36Sopenharmony_ci unsigned long ramrod_flags = 0; 278762306a36Sopenharmony_ci int rc = 0; 278862306a36Sopenharmony_ci 278962306a36Sopenharmony_ci /* configure the new vlan to device */ 279062306a36Sopenharmony_ci memset(&ramrod_param, 0, sizeof(ramrod_param)); 279162306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 279262306a36Sopenharmony_ci ramrod_param.vlan_mac_obj = &bnx2x_leading_vfq(vf, vlan_obj); 279362306a36Sopenharmony_ci ramrod_param.ramrod_flags = ramrod_flags; 279462306a36Sopenharmony_ci ramrod_param.user_req.u.vlan.vlan = vlan; 279562306a36Sopenharmony_ci ramrod_param.user_req.cmd = add ? BNX2X_VLAN_MAC_ADD 279662306a36Sopenharmony_ci : BNX2X_VLAN_MAC_DEL; 279762306a36Sopenharmony_ci rc = bnx2x_config_vlan_mac(bp, &ramrod_param); 279862306a36Sopenharmony_ci if (rc) { 279962306a36Sopenharmony_ci BNX2X_ERR("failed to configure vlan\n"); 280062306a36Sopenharmony_ci return -EINVAL; 280162306a36Sopenharmony_ci } 280262306a36Sopenharmony_ci 280362306a36Sopenharmony_ci return 0; 280462306a36Sopenharmony_ci} 280562306a36Sopenharmony_ci 280662306a36Sopenharmony_ciint bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos, 280762306a36Sopenharmony_ci __be16 vlan_proto) 280862306a36Sopenharmony_ci{ 280962306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin = NULL; 281062306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(dev); 281162306a36Sopenharmony_ci struct bnx2x_vlan_mac_obj *vlan_obj; 281262306a36Sopenharmony_ci unsigned long vlan_mac_flags = 0; 281362306a36Sopenharmony_ci unsigned long ramrod_flags = 0; 281462306a36Sopenharmony_ci struct bnx2x_virtf *vf = NULL; 281562306a36Sopenharmony_ci int i, rc; 281662306a36Sopenharmony_ci 281762306a36Sopenharmony_ci if (vlan > 4095) { 281862306a36Sopenharmony_ci BNX2X_ERR("illegal vlan value %d\n", vlan); 281962306a36Sopenharmony_ci return -EINVAL; 282062306a36Sopenharmony_ci } 282162306a36Sopenharmony_ci 282262306a36Sopenharmony_ci if (vlan_proto != htons(ETH_P_8021Q)) 282362306a36Sopenharmony_ci return -EPROTONOSUPPORT; 282462306a36Sopenharmony_ci 282562306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "configuring VF %d with VLAN %d qos %d\n", 282662306a36Sopenharmony_ci vfidx, vlan, 0); 282762306a36Sopenharmony_ci 282862306a36Sopenharmony_ci /* sanity and init */ 282962306a36Sopenharmony_ci rc = bnx2x_vf_op_prep(bp, vfidx, &vf, &bulletin, true); 283062306a36Sopenharmony_ci if (rc) 283162306a36Sopenharmony_ci return rc; 283262306a36Sopenharmony_ci 283362306a36Sopenharmony_ci /* update PF's copy of the VF's bulletin. No point in posting the vlan 283462306a36Sopenharmony_ci * to the VF since it doesn't have anything to do with it. But it useful 283562306a36Sopenharmony_ci * to store it here in case the VF is not up yet and we can only 283662306a36Sopenharmony_ci * configure the vlan later when it does. Treat vlan id 0 as remove the 283762306a36Sopenharmony_ci * Host tag. 283862306a36Sopenharmony_ci */ 283962306a36Sopenharmony_ci mutex_lock(&bp->vfdb->bulletin_mutex); 284062306a36Sopenharmony_ci 284162306a36Sopenharmony_ci if (vlan > 0) 284262306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << VLAN_VALID; 284362306a36Sopenharmony_ci else 284462306a36Sopenharmony_ci bulletin->valid_bitmap &= ~(1 << VLAN_VALID); 284562306a36Sopenharmony_ci bulletin->vlan = vlan; 284662306a36Sopenharmony_ci 284762306a36Sopenharmony_ci /* Post update on VF's bulletin board */ 284862306a36Sopenharmony_ci rc = bnx2x_post_vf_bulletin(bp, vfidx); 284962306a36Sopenharmony_ci if (rc) 285062306a36Sopenharmony_ci BNX2X_ERR("failed to update VF[%d] bulletin\n", vfidx); 285162306a36Sopenharmony_ci mutex_unlock(&bp->vfdb->bulletin_mutex); 285262306a36Sopenharmony_ci 285362306a36Sopenharmony_ci /* is vf initialized and queue set up? */ 285462306a36Sopenharmony_ci if (vf->state != VF_ENABLED || 285562306a36Sopenharmony_ci bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj)) != 285662306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE) 285762306a36Sopenharmony_ci return rc; 285862306a36Sopenharmony_ci 285962306a36Sopenharmony_ci /* User should be able to see error in system logs */ 286062306a36Sopenharmony_ci if (!bnx2x_validate_vf_sp_objs(bp, vf, true)) 286162306a36Sopenharmony_ci return -EINVAL; 286262306a36Sopenharmony_ci 286362306a36Sopenharmony_ci /* must lock vfpf channel to protect against vf flows */ 286462306a36Sopenharmony_ci bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN); 286562306a36Sopenharmony_ci 286662306a36Sopenharmony_ci /* remove existing vlans */ 286762306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &ramrod_flags); 286862306a36Sopenharmony_ci vlan_obj = &bnx2x_leading_vfq(vf, vlan_obj); 286962306a36Sopenharmony_ci rc = vlan_obj->delete_all(bp, vlan_obj, &vlan_mac_flags, 287062306a36Sopenharmony_ci &ramrod_flags); 287162306a36Sopenharmony_ci if (rc) { 287262306a36Sopenharmony_ci BNX2X_ERR("failed to delete vlans\n"); 287362306a36Sopenharmony_ci rc = -EINVAL; 287462306a36Sopenharmony_ci goto out; 287562306a36Sopenharmony_ci } 287662306a36Sopenharmony_ci 287762306a36Sopenharmony_ci /* clear accept_any_vlan when HV forces vlan, otherwise 287862306a36Sopenharmony_ci * according to VF capabilities 287962306a36Sopenharmony_ci */ 288062306a36Sopenharmony_ci if (vlan || !(vf->cfg_flags & VF_CFG_VLAN_FILTER)) 288162306a36Sopenharmony_ci bnx2x_set_vf_vlan_acceptance(bp, vf, !vlan); 288262306a36Sopenharmony_ci 288362306a36Sopenharmony_ci rc = bnx2x_set_vf_vlan_filter(bp, vf, vlan, true); 288462306a36Sopenharmony_ci if (rc) 288562306a36Sopenharmony_ci goto out; 288662306a36Sopenharmony_ci 288762306a36Sopenharmony_ci /* send queue update ramrods to configure default vlan and 288862306a36Sopenharmony_ci * silent vlan removal 288962306a36Sopenharmony_ci */ 289062306a36Sopenharmony_ci for_each_vfq(vf, i) { 289162306a36Sopenharmony_ci struct bnx2x_queue_state_params q_params = {NULL}; 289262306a36Sopenharmony_ci struct bnx2x_queue_update_params *update_params; 289362306a36Sopenharmony_ci 289462306a36Sopenharmony_ci q_params.q_obj = &bnx2x_vfq(vf, i, sp_obj); 289562306a36Sopenharmony_ci 289662306a36Sopenharmony_ci /* validate the Q is UP */ 289762306a36Sopenharmony_ci if (bnx2x_get_q_logical_state(bp, q_params.q_obj) != 289862306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE) 289962306a36Sopenharmony_ci continue; 290062306a36Sopenharmony_ci 290162306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 290262306a36Sopenharmony_ci q_params.cmd = BNX2X_Q_CMD_UPDATE; 290362306a36Sopenharmony_ci update_params = &q_params.params.update; 290462306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG, 290562306a36Sopenharmony_ci &update_params->update_flags); 290662306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG, 290762306a36Sopenharmony_ci &update_params->update_flags); 290862306a36Sopenharmony_ci if (vlan == 0) { 290962306a36Sopenharmony_ci /* if vlan is 0 then we want to leave the VF traffic 291062306a36Sopenharmony_ci * untagged, and leave the incoming traffic untouched 291162306a36Sopenharmony_ci * (i.e. do not remove any vlan tags). 291262306a36Sopenharmony_ci */ 291362306a36Sopenharmony_ci __clear_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, 291462306a36Sopenharmony_ci &update_params->update_flags); 291562306a36Sopenharmony_ci __clear_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, 291662306a36Sopenharmony_ci &update_params->update_flags); 291762306a36Sopenharmony_ci } else { 291862306a36Sopenharmony_ci /* configure default vlan to vf queue and set silent 291962306a36Sopenharmony_ci * vlan removal (the vf remains unaware of this vlan). 292062306a36Sopenharmony_ci */ 292162306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, 292262306a36Sopenharmony_ci &update_params->update_flags); 292362306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, 292462306a36Sopenharmony_ci &update_params->update_flags); 292562306a36Sopenharmony_ci update_params->def_vlan = vlan; 292662306a36Sopenharmony_ci update_params->silent_removal_value = 292762306a36Sopenharmony_ci vlan & VLAN_VID_MASK; 292862306a36Sopenharmony_ci update_params->silent_removal_mask = VLAN_VID_MASK; 292962306a36Sopenharmony_ci } 293062306a36Sopenharmony_ci 293162306a36Sopenharmony_ci /* Update the Queue state */ 293262306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &q_params); 293362306a36Sopenharmony_ci if (rc) { 293462306a36Sopenharmony_ci BNX2X_ERR("Failed to configure default VLAN queue %d\n", 293562306a36Sopenharmony_ci i); 293662306a36Sopenharmony_ci goto out; 293762306a36Sopenharmony_ci } 293862306a36Sopenharmony_ci } 293962306a36Sopenharmony_ciout: 294062306a36Sopenharmony_ci bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN); 294162306a36Sopenharmony_ci 294262306a36Sopenharmony_ci if (rc) 294362306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 294462306a36Sopenharmony_ci "updated VF[%d] vlan configuration (vlan = %d)\n", 294562306a36Sopenharmony_ci vfidx, vlan); 294662306a36Sopenharmony_ci 294762306a36Sopenharmony_ci return rc; 294862306a36Sopenharmony_ci} 294962306a36Sopenharmony_ci 295062306a36Sopenharmony_ciint bnx2x_set_vf_spoofchk(struct net_device *dev, int idx, bool val) 295162306a36Sopenharmony_ci{ 295262306a36Sopenharmony_ci struct bnx2x *bp = netdev_priv(dev); 295362306a36Sopenharmony_ci struct bnx2x_virtf *vf; 295462306a36Sopenharmony_ci int i, rc = 0; 295562306a36Sopenharmony_ci 295662306a36Sopenharmony_ci vf = BP_VF(bp, idx); 295762306a36Sopenharmony_ci if (!vf) 295862306a36Sopenharmony_ci return -EINVAL; 295962306a36Sopenharmony_ci 296062306a36Sopenharmony_ci /* nothing to do */ 296162306a36Sopenharmony_ci if (vf->spoofchk == val) 296262306a36Sopenharmony_ci return 0; 296362306a36Sopenharmony_ci 296462306a36Sopenharmony_ci vf->spoofchk = val ? 1 : 0; 296562306a36Sopenharmony_ci 296662306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "%s spoofchk for VF %d\n", 296762306a36Sopenharmony_ci val ? "enabling" : "disabling", idx); 296862306a36Sopenharmony_ci 296962306a36Sopenharmony_ci /* is vf initialized and queue set up? */ 297062306a36Sopenharmony_ci if (vf->state != VF_ENABLED || 297162306a36Sopenharmony_ci bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj)) != 297262306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE) 297362306a36Sopenharmony_ci return rc; 297462306a36Sopenharmony_ci 297562306a36Sopenharmony_ci /* User should be able to see error in system logs */ 297662306a36Sopenharmony_ci if (!bnx2x_validate_vf_sp_objs(bp, vf, true)) 297762306a36Sopenharmony_ci return -EINVAL; 297862306a36Sopenharmony_ci 297962306a36Sopenharmony_ci /* send queue update ramrods to configure spoofchk */ 298062306a36Sopenharmony_ci for_each_vfq(vf, i) { 298162306a36Sopenharmony_ci struct bnx2x_queue_state_params q_params = {NULL}; 298262306a36Sopenharmony_ci struct bnx2x_queue_update_params *update_params; 298362306a36Sopenharmony_ci 298462306a36Sopenharmony_ci q_params.q_obj = &bnx2x_vfq(vf, i, sp_obj); 298562306a36Sopenharmony_ci 298662306a36Sopenharmony_ci /* validate the Q is UP */ 298762306a36Sopenharmony_ci if (bnx2x_get_q_logical_state(bp, q_params.q_obj) != 298862306a36Sopenharmony_ci BNX2X_Q_LOGICAL_STATE_ACTIVE) 298962306a36Sopenharmony_ci continue; 299062306a36Sopenharmony_ci 299162306a36Sopenharmony_ci __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags); 299262306a36Sopenharmony_ci q_params.cmd = BNX2X_Q_CMD_UPDATE; 299362306a36Sopenharmony_ci update_params = &q_params.params.update; 299462306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, 299562306a36Sopenharmony_ci &update_params->update_flags); 299662306a36Sopenharmony_ci if (val) { 299762306a36Sopenharmony_ci __set_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, 299862306a36Sopenharmony_ci &update_params->update_flags); 299962306a36Sopenharmony_ci } else { 300062306a36Sopenharmony_ci __clear_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, 300162306a36Sopenharmony_ci &update_params->update_flags); 300262306a36Sopenharmony_ci } 300362306a36Sopenharmony_ci 300462306a36Sopenharmony_ci /* Update the Queue state */ 300562306a36Sopenharmony_ci rc = bnx2x_queue_state_change(bp, &q_params); 300662306a36Sopenharmony_ci if (rc) { 300762306a36Sopenharmony_ci BNX2X_ERR("Failed to %s spoofchk on VF %d - vfq %d\n", 300862306a36Sopenharmony_ci val ? "enable" : "disable", idx, i); 300962306a36Sopenharmony_ci goto out; 301062306a36Sopenharmony_ci } 301162306a36Sopenharmony_ci } 301262306a36Sopenharmony_ciout: 301362306a36Sopenharmony_ci if (!rc) 301462306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, 301562306a36Sopenharmony_ci "%s spoofchk for VF[%d]\n", val ? "Enabled" : "Disabled", 301662306a36Sopenharmony_ci idx); 301762306a36Sopenharmony_ci 301862306a36Sopenharmony_ci return rc; 301962306a36Sopenharmony_ci} 302062306a36Sopenharmony_ci 302162306a36Sopenharmony_ci/* crc is the first field in the bulletin board. Compute the crc over the 302262306a36Sopenharmony_ci * entire bulletin board excluding the crc field itself. Use the length field 302362306a36Sopenharmony_ci * as the Bulletin Board was posted by a PF with possibly a different version 302462306a36Sopenharmony_ci * from the vf which will sample it. Therefore, the length is computed by the 302562306a36Sopenharmony_ci * PF and then used blindly by the VF. 302662306a36Sopenharmony_ci */ 302762306a36Sopenharmony_ciu32 bnx2x_crc_vf_bulletin(struct pf_vf_bulletin_content *bulletin) 302862306a36Sopenharmony_ci{ 302962306a36Sopenharmony_ci return crc32(BULLETIN_CRC_SEED, 303062306a36Sopenharmony_ci ((u8 *)bulletin) + sizeof(bulletin->crc), 303162306a36Sopenharmony_ci bulletin->length - sizeof(bulletin->crc)); 303262306a36Sopenharmony_ci} 303362306a36Sopenharmony_ci 303462306a36Sopenharmony_ci/* Check for new posts on the bulletin board */ 303562306a36Sopenharmony_cienum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp) 303662306a36Sopenharmony_ci{ 303762306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin; 303862306a36Sopenharmony_ci int attempts; 303962306a36Sopenharmony_ci 304062306a36Sopenharmony_ci /* sampling structure in mid post may result with corrupted data 304162306a36Sopenharmony_ci * validate crc to ensure coherency. 304262306a36Sopenharmony_ci */ 304362306a36Sopenharmony_ci for (attempts = 0; attempts < BULLETIN_ATTEMPTS; attempts++) { 304462306a36Sopenharmony_ci u32 crc; 304562306a36Sopenharmony_ci 304662306a36Sopenharmony_ci /* sample the bulletin board */ 304762306a36Sopenharmony_ci memcpy(&bp->shadow_bulletin, bp->pf2vf_bulletin, 304862306a36Sopenharmony_ci sizeof(union pf_vf_bulletin)); 304962306a36Sopenharmony_ci 305062306a36Sopenharmony_ci crc = bnx2x_crc_vf_bulletin(&bp->shadow_bulletin.content); 305162306a36Sopenharmony_ci 305262306a36Sopenharmony_ci if (bp->shadow_bulletin.content.crc == crc) 305362306a36Sopenharmony_ci break; 305462306a36Sopenharmony_ci 305562306a36Sopenharmony_ci BNX2X_ERR("bad crc on bulletin board. Contained %x computed %x\n", 305662306a36Sopenharmony_ci bp->shadow_bulletin.content.crc, crc); 305762306a36Sopenharmony_ci } 305862306a36Sopenharmony_ci 305962306a36Sopenharmony_ci if (attempts >= BULLETIN_ATTEMPTS) { 306062306a36Sopenharmony_ci BNX2X_ERR("pf to vf bulletin board crc was wrong %d consecutive times. Aborting\n", 306162306a36Sopenharmony_ci attempts); 306262306a36Sopenharmony_ci return PFVF_BULLETIN_CRC_ERR; 306362306a36Sopenharmony_ci } 306462306a36Sopenharmony_ci bulletin = &bp->shadow_bulletin.content; 306562306a36Sopenharmony_ci 306662306a36Sopenharmony_ci /* bulletin board hasn't changed since last sample */ 306762306a36Sopenharmony_ci if (bp->old_bulletin.version == bulletin->version) 306862306a36Sopenharmony_ci return PFVF_BULLETIN_UNCHANGED; 306962306a36Sopenharmony_ci 307062306a36Sopenharmony_ci /* the mac address in bulletin board is valid and is new */ 307162306a36Sopenharmony_ci if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID && 307262306a36Sopenharmony_ci !ether_addr_equal(bulletin->mac, bp->old_bulletin.mac)) { 307362306a36Sopenharmony_ci /* update new mac to net device */ 307462306a36Sopenharmony_ci eth_hw_addr_set(bp->dev, bulletin->mac); 307562306a36Sopenharmony_ci } 307662306a36Sopenharmony_ci 307762306a36Sopenharmony_ci if (bulletin->valid_bitmap & (1 << LINK_VALID)) { 307862306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "link update speed %d flags %x\n", 307962306a36Sopenharmony_ci bulletin->link_speed, bulletin->link_flags); 308062306a36Sopenharmony_ci 308162306a36Sopenharmony_ci bp->vf_link_vars.line_speed = bulletin->link_speed; 308262306a36Sopenharmony_ci bp->vf_link_vars.link_report_flags = 0; 308362306a36Sopenharmony_ci /* Link is down */ 308462306a36Sopenharmony_ci if (bulletin->link_flags & VFPF_LINK_REPORT_LINK_DOWN) 308562306a36Sopenharmony_ci __set_bit(BNX2X_LINK_REPORT_LINK_DOWN, 308662306a36Sopenharmony_ci &bp->vf_link_vars.link_report_flags); 308762306a36Sopenharmony_ci /* Full DUPLEX */ 308862306a36Sopenharmony_ci if (bulletin->link_flags & VFPF_LINK_REPORT_FULL_DUPLEX) 308962306a36Sopenharmony_ci __set_bit(BNX2X_LINK_REPORT_FD, 309062306a36Sopenharmony_ci &bp->vf_link_vars.link_report_flags); 309162306a36Sopenharmony_ci /* Rx Flow Control is ON */ 309262306a36Sopenharmony_ci if (bulletin->link_flags & VFPF_LINK_REPORT_RX_FC_ON) 309362306a36Sopenharmony_ci __set_bit(BNX2X_LINK_REPORT_RX_FC_ON, 309462306a36Sopenharmony_ci &bp->vf_link_vars.link_report_flags); 309562306a36Sopenharmony_ci /* Tx Flow Control is ON */ 309662306a36Sopenharmony_ci if (bulletin->link_flags & VFPF_LINK_REPORT_TX_FC_ON) 309762306a36Sopenharmony_ci __set_bit(BNX2X_LINK_REPORT_TX_FC_ON, 309862306a36Sopenharmony_ci &bp->vf_link_vars.link_report_flags); 309962306a36Sopenharmony_ci __bnx2x_link_report(bp); 310062306a36Sopenharmony_ci } 310162306a36Sopenharmony_ci 310262306a36Sopenharmony_ci /* copy new bulletin board to bp */ 310362306a36Sopenharmony_ci memcpy(&bp->old_bulletin, bulletin, 310462306a36Sopenharmony_ci sizeof(struct pf_vf_bulletin_content)); 310562306a36Sopenharmony_ci 310662306a36Sopenharmony_ci return PFVF_BULLETIN_UPDATED; 310762306a36Sopenharmony_ci} 310862306a36Sopenharmony_ci 310962306a36Sopenharmony_civoid bnx2x_timer_sriov(struct bnx2x *bp) 311062306a36Sopenharmony_ci{ 311162306a36Sopenharmony_ci bnx2x_sample_bulletin(bp); 311262306a36Sopenharmony_ci 311362306a36Sopenharmony_ci /* if channel is down we need to self destruct */ 311462306a36Sopenharmony_ci if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) 311562306a36Sopenharmony_ci bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN, 311662306a36Sopenharmony_ci BNX2X_MSG_IOV); 311762306a36Sopenharmony_ci} 311862306a36Sopenharmony_ci 311962306a36Sopenharmony_civoid __iomem *bnx2x_vf_doorbells(struct bnx2x *bp) 312062306a36Sopenharmony_ci{ 312162306a36Sopenharmony_ci /* vf doorbells are embedded within the regview */ 312262306a36Sopenharmony_ci return bp->regview + PXP_VF_ADDR_DB_START; 312362306a36Sopenharmony_ci} 312462306a36Sopenharmony_ci 312562306a36Sopenharmony_civoid bnx2x_vf_pci_dealloc(struct bnx2x *bp) 312662306a36Sopenharmony_ci{ 312762306a36Sopenharmony_ci BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping, 312862306a36Sopenharmony_ci sizeof(struct bnx2x_vf_mbx_msg)); 312962306a36Sopenharmony_ci BNX2X_PCI_FREE(bp->pf2vf_bulletin, bp->pf2vf_bulletin_mapping, 313062306a36Sopenharmony_ci sizeof(union pf_vf_bulletin)); 313162306a36Sopenharmony_ci} 313262306a36Sopenharmony_ci 313362306a36Sopenharmony_ciint bnx2x_vf_pci_alloc(struct bnx2x *bp) 313462306a36Sopenharmony_ci{ 313562306a36Sopenharmony_ci mutex_init(&bp->vf2pf_mutex); 313662306a36Sopenharmony_ci 313762306a36Sopenharmony_ci /* allocate vf2pf mailbox for vf to pf channel */ 313862306a36Sopenharmony_ci bp->vf2pf_mbox = BNX2X_PCI_ALLOC(&bp->vf2pf_mbox_mapping, 313962306a36Sopenharmony_ci sizeof(struct bnx2x_vf_mbx_msg)); 314062306a36Sopenharmony_ci if (!bp->vf2pf_mbox) 314162306a36Sopenharmony_ci goto alloc_mem_err; 314262306a36Sopenharmony_ci 314362306a36Sopenharmony_ci /* allocate pf 2 vf bulletin board */ 314462306a36Sopenharmony_ci bp->pf2vf_bulletin = BNX2X_PCI_ALLOC(&bp->pf2vf_bulletin_mapping, 314562306a36Sopenharmony_ci sizeof(union pf_vf_bulletin)); 314662306a36Sopenharmony_ci if (!bp->pf2vf_bulletin) 314762306a36Sopenharmony_ci goto alloc_mem_err; 314862306a36Sopenharmony_ci 314962306a36Sopenharmony_ci bnx2x_vf_bulletin_finalize(&bp->pf2vf_bulletin->content, true); 315062306a36Sopenharmony_ci 315162306a36Sopenharmony_ci return 0; 315262306a36Sopenharmony_ci 315362306a36Sopenharmony_cialloc_mem_err: 315462306a36Sopenharmony_ci bnx2x_vf_pci_dealloc(bp); 315562306a36Sopenharmony_ci return -ENOMEM; 315662306a36Sopenharmony_ci} 315762306a36Sopenharmony_ci 315862306a36Sopenharmony_civoid bnx2x_iov_channel_down(struct bnx2x *bp) 315962306a36Sopenharmony_ci{ 316062306a36Sopenharmony_ci int vf_idx; 316162306a36Sopenharmony_ci struct pf_vf_bulletin_content *bulletin; 316262306a36Sopenharmony_ci 316362306a36Sopenharmony_ci if (!IS_SRIOV(bp)) 316462306a36Sopenharmony_ci return; 316562306a36Sopenharmony_ci 316662306a36Sopenharmony_ci for_each_vf(bp, vf_idx) { 316762306a36Sopenharmony_ci /* locate this VFs bulletin board and update the channel down 316862306a36Sopenharmony_ci * bit 316962306a36Sopenharmony_ci */ 317062306a36Sopenharmony_ci bulletin = BP_VF_BULLETIN(bp, vf_idx); 317162306a36Sopenharmony_ci bulletin->valid_bitmap |= 1 << CHANNEL_DOWN; 317262306a36Sopenharmony_ci 317362306a36Sopenharmony_ci /* update vf bulletin board */ 317462306a36Sopenharmony_ci bnx2x_post_vf_bulletin(bp, vf_idx); 317562306a36Sopenharmony_ci } 317662306a36Sopenharmony_ci} 317762306a36Sopenharmony_ci 317862306a36Sopenharmony_civoid bnx2x_iov_task(struct work_struct *work) 317962306a36Sopenharmony_ci{ 318062306a36Sopenharmony_ci struct bnx2x *bp = container_of(work, struct bnx2x, iov_task.work); 318162306a36Sopenharmony_ci 318262306a36Sopenharmony_ci if (!netif_running(bp->dev)) 318362306a36Sopenharmony_ci return; 318462306a36Sopenharmony_ci 318562306a36Sopenharmony_ci if (test_and_clear_bit(BNX2X_IOV_HANDLE_FLR, 318662306a36Sopenharmony_ci &bp->iov_task_state)) 318762306a36Sopenharmony_ci bnx2x_vf_handle_flr_event(bp); 318862306a36Sopenharmony_ci 318962306a36Sopenharmony_ci if (test_and_clear_bit(BNX2X_IOV_HANDLE_VF_MSG, 319062306a36Sopenharmony_ci &bp->iov_task_state)) 319162306a36Sopenharmony_ci bnx2x_vf_mbx(bp); 319262306a36Sopenharmony_ci} 319362306a36Sopenharmony_ci 319462306a36Sopenharmony_civoid bnx2x_schedule_iov_task(struct bnx2x *bp, enum bnx2x_iov_flag flag) 319562306a36Sopenharmony_ci{ 319662306a36Sopenharmony_ci smp_mb__before_atomic(); 319762306a36Sopenharmony_ci set_bit(flag, &bp->iov_task_state); 319862306a36Sopenharmony_ci smp_mb__after_atomic(); 319962306a36Sopenharmony_ci DP(BNX2X_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag); 320062306a36Sopenharmony_ci queue_delayed_work(bnx2x_iov_wq, &bp->iov_task, 0); 320162306a36Sopenharmony_ci} 3202