1be1f1ffaSAriel Elior /* bnx2x_vfpf.c: Broadcom Everest network driver. 2be1f1ffaSAriel Elior * 3be1f1ffaSAriel Elior * Copyright 2009-2012 Broadcom Corporation 4be1f1ffaSAriel Elior * 5be1f1ffaSAriel Elior * Unless you and Broadcom execute a separate written software license 6be1f1ffaSAriel Elior * agreement governing use of this software, this software is licensed to you 7be1f1ffaSAriel Elior * under the terms of the GNU General Public License version 2, available 8be1f1ffaSAriel Elior * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"). 9be1f1ffaSAriel Elior * 10be1f1ffaSAriel Elior * Notwithstanding the above, under no circumstances may you combine this 11be1f1ffaSAriel Elior * software in any way with any other Broadcom software provided under a 12be1f1ffaSAriel Elior * license other than the GPL, without Broadcom's express prior written 13be1f1ffaSAriel Elior * consent. 14be1f1ffaSAriel Elior * 15be1f1ffaSAriel Elior * Maintained by: Eilon Greenstein <eilong@broadcom.com> 16be1f1ffaSAriel Elior * Written by: Shmulik Ravid <shmulikr@broadcom.com> 17be1f1ffaSAriel Elior * Ariel Elior <ariele@broadcom.com> 18be1f1ffaSAriel Elior */ 19be1f1ffaSAriel Elior 20be1f1ffaSAriel Elior #include "bnx2x.h" 21be1f1ffaSAriel Elior #include "bnx2x_sriov.h" 22b93288d5SAriel Elior #include <linux/crc32.h> 23be1f1ffaSAriel Elior 24be1f1ffaSAriel Elior /* place a given tlv on the tlv buffer at a given offset */ 25be1f1ffaSAriel Elior void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type, 26be1f1ffaSAriel Elior u16 length) 27be1f1ffaSAriel Elior { 28be1f1ffaSAriel Elior struct channel_tlv *tl = 29be1f1ffaSAriel Elior (struct channel_tlv *)(tlvs_list + offset); 30be1f1ffaSAriel Elior 31be1f1ffaSAriel Elior tl->type = type; 32be1f1ffaSAriel Elior tl->length = length; 33be1f1ffaSAriel Elior } 34be1f1ffaSAriel Elior 35be1f1ffaSAriel Elior /* Clear the mailbox and init the header of the first tlv */ 36be1f1ffaSAriel Elior void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv, 37be1f1ffaSAriel Elior u16 type, u16 length) 38be1f1ffaSAriel Elior { 39be1f1ffaSAriel Elior DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n", 40be1f1ffaSAriel Elior type); 41be1f1ffaSAriel Elior 42be1f1ffaSAriel Elior /* Clear mailbox */ 43be1f1ffaSAriel Elior memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg)); 44be1f1ffaSAriel Elior 45be1f1ffaSAriel Elior /* init type and length */ 46be1f1ffaSAriel Elior bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length); 47be1f1ffaSAriel Elior 48be1f1ffaSAriel Elior /* init first tlv header */ 49be1f1ffaSAriel Elior first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req); 50be1f1ffaSAriel Elior } 51be1f1ffaSAriel Elior 52be1f1ffaSAriel Elior /* list the types and lengths of the tlvs on the buffer */ 53be1f1ffaSAriel Elior void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list) 54be1f1ffaSAriel Elior { 55be1f1ffaSAriel Elior int i = 1; 56be1f1ffaSAriel Elior struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list; 57be1f1ffaSAriel Elior 58be1f1ffaSAriel Elior while (tlv->type != CHANNEL_TLV_LIST_END) { 59be1f1ffaSAriel Elior /* output tlv */ 60be1f1ffaSAriel Elior DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, 61be1f1ffaSAriel Elior tlv->type, tlv->length); 62be1f1ffaSAriel Elior 63be1f1ffaSAriel Elior /* advance to next tlv */ 64be1f1ffaSAriel Elior tlvs_list += tlv->length; 65be1f1ffaSAriel Elior 66be1f1ffaSAriel Elior /* cast general tlv list pointer to channel tlv header*/ 67be1f1ffaSAriel Elior tlv = (struct channel_tlv *)tlvs_list; 68be1f1ffaSAriel Elior 69be1f1ffaSAriel Elior i++; 70be1f1ffaSAriel Elior 71be1f1ffaSAriel Elior /* break condition for this loop */ 72be1f1ffaSAriel Elior if (i > MAX_TLVS_IN_LIST) { 73be1f1ffaSAriel Elior WARN(true, "corrupt tlvs"); 74be1f1ffaSAriel Elior return; 75be1f1ffaSAriel Elior } 76be1f1ffaSAriel Elior } 77be1f1ffaSAriel Elior 78be1f1ffaSAriel Elior /* output last tlv */ 79be1f1ffaSAriel Elior DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i, 80be1f1ffaSAriel Elior tlv->type, tlv->length); 81be1f1ffaSAriel Elior } 82b56e9670SAriel Elior 83fd1fc79dSAriel Elior /* test whether we support a tlv type */ 84fd1fc79dSAriel Elior bool bnx2x_tlv_supported(u16 tlvtype) 85fd1fc79dSAriel Elior { 86fd1fc79dSAriel Elior return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX; 87fd1fc79dSAriel Elior } 88fd1fc79dSAriel Elior 89fd1fc79dSAriel Elior static inline int bnx2x_pfvf_status_codes(int rc) 90fd1fc79dSAriel Elior { 91fd1fc79dSAriel Elior switch (rc) { 92fd1fc79dSAriel Elior case 0: 93fd1fc79dSAriel Elior return PFVF_STATUS_SUCCESS; 94fd1fc79dSAriel Elior case -ENOMEM: 95fd1fc79dSAriel Elior return PFVF_STATUS_NO_RESOURCE; 96fd1fc79dSAriel Elior default: 97fd1fc79dSAriel Elior return PFVF_STATUS_FAILURE; 98fd1fc79dSAriel Elior } 99fd1fc79dSAriel Elior } 100fd1fc79dSAriel Elior 101b56e9670SAriel Elior /* General service functions */ 102b56e9670SAriel Elior static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid) 103b56e9670SAriel Elior { 104b56e9670SAriel Elior u32 addr = BAR_CSTRORM_INTMEM + 105b56e9670SAriel Elior CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid); 106b56e9670SAriel Elior 107b56e9670SAriel Elior REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY); 108b56e9670SAriel Elior } 109b56e9670SAriel Elior 110b56e9670SAriel Elior static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid) 111b56e9670SAriel Elior { 112b56e9670SAriel Elior u32 addr = BAR_CSTRORM_INTMEM + 113b56e9670SAriel Elior CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid); 114b56e9670SAriel Elior 115b56e9670SAriel Elior REG_WR8(bp, addr, 1); 116b56e9670SAriel Elior } 117b56e9670SAriel Elior 118b56e9670SAriel Elior static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp) 119b56e9670SAriel Elior { 120b56e9670SAriel Elior int i; 121b56e9670SAriel Elior 122b56e9670SAriel Elior for_each_vf(bp, i) 123b56e9670SAriel Elior storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid)); 124b56e9670SAriel Elior } 125b56e9670SAriel Elior 126b56e9670SAriel Elior /* enable vf_pf mailbox (aka vf-pf-chanell) */ 127b56e9670SAriel Elior void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid) 128b56e9670SAriel Elior { 129b56e9670SAriel Elior bnx2x_vf_flr_clnup_epilog(bp, abs_vfid); 130b56e9670SAriel Elior 131b56e9670SAriel Elior /* enable the mailbox in the FW */ 132b56e9670SAriel Elior storm_memset_vf_mbx_ack(bp, abs_vfid); 133b56e9670SAriel Elior storm_memset_vf_mbx_valid(bp, abs_vfid); 134b56e9670SAriel Elior 135b56e9670SAriel Elior /* enable the VF access to the mailbox */ 136b56e9670SAriel Elior bnx2x_vf_enable_access(bp, abs_vfid); 137b56e9670SAriel Elior } 138fd1fc79dSAriel Elior 139fd1fc79dSAriel Elior /* this works only on !E1h */ 140fd1fc79dSAriel Elior static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf, 141fd1fc79dSAriel Elior dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi, 142fd1fc79dSAriel Elior u32 vf_addr_lo, u32 len32) 143fd1fc79dSAriel Elior { 144fd1fc79dSAriel Elior struct dmae_command dmae; 145fd1fc79dSAriel Elior 146fd1fc79dSAriel Elior if (CHIP_IS_E1x(bp)) { 147fd1fc79dSAriel Elior BNX2X_ERR("Chip revision does not support VFs\n"); 148fd1fc79dSAriel Elior return DMAE_NOT_RDY; 149fd1fc79dSAriel Elior } 150fd1fc79dSAriel Elior 151fd1fc79dSAriel Elior if (!bp->dmae_ready) { 152fd1fc79dSAriel Elior BNX2X_ERR("DMAE is not ready, can not copy\n"); 153fd1fc79dSAriel Elior return DMAE_NOT_RDY; 154fd1fc79dSAriel Elior } 155fd1fc79dSAriel Elior 156fd1fc79dSAriel Elior /* set opcode and fixed command fields */ 157fd1fc79dSAriel Elior bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI); 158fd1fc79dSAriel Elior 159fd1fc79dSAriel Elior if (from_vf) { 160fd1fc79dSAriel Elior dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) | 161fd1fc79dSAriel Elior (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) | 162fd1fc79dSAriel Elior (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT); 163fd1fc79dSAriel Elior 164fd1fc79dSAriel Elior dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT); 165fd1fc79dSAriel Elior 166fd1fc79dSAriel Elior dmae.src_addr_lo = vf_addr_lo; 167fd1fc79dSAriel Elior dmae.src_addr_hi = vf_addr_hi; 168fd1fc79dSAriel Elior dmae.dst_addr_lo = U64_LO(pf_addr); 169fd1fc79dSAriel Elior dmae.dst_addr_hi = U64_HI(pf_addr); 170fd1fc79dSAriel Elior } else { 171fd1fc79dSAriel Elior dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) | 172fd1fc79dSAriel Elior (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) | 173fd1fc79dSAriel Elior (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT); 174fd1fc79dSAriel Elior 175fd1fc79dSAriel Elior dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT); 176fd1fc79dSAriel Elior 177fd1fc79dSAriel Elior dmae.src_addr_lo = U64_LO(pf_addr); 178fd1fc79dSAriel Elior dmae.src_addr_hi = U64_HI(pf_addr); 179fd1fc79dSAriel Elior dmae.dst_addr_lo = vf_addr_lo; 180fd1fc79dSAriel Elior dmae.dst_addr_hi = vf_addr_hi; 181fd1fc79dSAriel Elior } 182fd1fc79dSAriel Elior dmae.len = len32; 183fd1fc79dSAriel Elior bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE); 184fd1fc79dSAriel Elior 185fd1fc79dSAriel Elior /* issue the command and wait for completion */ 186fd1fc79dSAriel Elior return bnx2x_issue_dmae_with_comp(bp, &dmae); 187fd1fc79dSAriel Elior } 188fd1fc79dSAriel Elior 1898ca5e17eSAriel Elior static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf) 1908ca5e17eSAriel Elior { 1918ca5e17eSAriel Elior struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index); 1928ca5e17eSAriel Elior u64 vf_addr; 1938ca5e17eSAriel Elior dma_addr_t pf_addr; 1948ca5e17eSAriel Elior u16 length, type; 1958ca5e17eSAriel Elior int rc; 1968ca5e17eSAriel Elior struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp; 1978ca5e17eSAriel Elior 1988ca5e17eSAriel Elior /* prepare response */ 1998ca5e17eSAriel Elior type = mbx->first_tlv.tl.type; 2008ca5e17eSAriel Elior length = type == CHANNEL_TLV_ACQUIRE ? 2018ca5e17eSAriel Elior sizeof(struct pfvf_acquire_resp_tlv) : 2028ca5e17eSAriel Elior sizeof(struct pfvf_general_resp_tlv); 2038ca5e17eSAriel Elior bnx2x_add_tlv(bp, resp, 0, type, length); 2048ca5e17eSAriel Elior resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc); 2058ca5e17eSAriel Elior bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END, 2068ca5e17eSAriel Elior sizeof(struct channel_list_end_tlv)); 2078ca5e17eSAriel Elior bnx2x_dp_tlv_list(bp, resp); 2088ca5e17eSAriel Elior DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", 2098ca5e17eSAriel Elior mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); 2108ca5e17eSAriel Elior 2118ca5e17eSAriel Elior /* send response */ 2128ca5e17eSAriel Elior vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) + 2138ca5e17eSAriel Elior mbx->first_tlv.resp_msg_offset; 2148ca5e17eSAriel Elior pf_addr = mbx->msg_mapping + 2158ca5e17eSAriel Elior offsetof(struct bnx2x_vf_mbx_msg, resp); 2168ca5e17eSAriel Elior 2178ca5e17eSAriel Elior /* copy the response body, if there is one, before the header, as the vf 2188ca5e17eSAriel Elior * is sensitive to the header being written 2198ca5e17eSAriel Elior */ 2208ca5e17eSAriel Elior if (resp->hdr.tl.length > sizeof(u64)) { 2218ca5e17eSAriel Elior length = resp->hdr.tl.length - sizeof(u64); 2228ca5e17eSAriel Elior vf_addr += sizeof(u64); 2238ca5e17eSAriel Elior pf_addr += sizeof(u64); 2248ca5e17eSAriel Elior rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, 2258ca5e17eSAriel Elior U64_HI(vf_addr), 2268ca5e17eSAriel Elior U64_LO(vf_addr), 2278ca5e17eSAriel Elior length/4); 2288ca5e17eSAriel Elior if (rc) { 2298ca5e17eSAriel Elior BNX2X_ERR("Failed to copy response body to VF %d\n", 2308ca5e17eSAriel Elior vf->abs_vfid); 2318ca5e17eSAriel Elior return; 2328ca5e17eSAriel Elior } 2338ca5e17eSAriel Elior vf_addr -= sizeof(u64); 2348ca5e17eSAriel Elior pf_addr -= sizeof(u64); 2358ca5e17eSAriel Elior } 2368ca5e17eSAriel Elior 2378ca5e17eSAriel Elior /* ack the FW */ 2388ca5e17eSAriel Elior storm_memset_vf_mbx_ack(bp, vf->abs_vfid); 2398ca5e17eSAriel Elior mmiowb(); 2408ca5e17eSAriel Elior 2418ca5e17eSAriel Elior /* initiate dmae to send the response */ 2428ca5e17eSAriel Elior mbx->flags &= ~VF_MSG_INPROCESS; 2438ca5e17eSAriel Elior 2448ca5e17eSAriel Elior /* copy the response header including status-done field, 2458ca5e17eSAriel Elior * must be last dmae, must be after FW is acked 2468ca5e17eSAriel Elior */ 2478ca5e17eSAriel Elior rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid, 2488ca5e17eSAriel Elior U64_HI(vf_addr), 2498ca5e17eSAriel Elior U64_LO(vf_addr), 2508ca5e17eSAriel Elior sizeof(u64)/4); 2518ca5e17eSAriel Elior 2528ca5e17eSAriel Elior /* unlock channel mutex */ 2538ca5e17eSAriel Elior bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); 2548ca5e17eSAriel Elior 2558ca5e17eSAriel Elior if (rc) { 2568ca5e17eSAriel Elior BNX2X_ERR("Failed to copy response status to VF %d\n", 2578ca5e17eSAriel Elior vf->abs_vfid); 2588ca5e17eSAriel Elior } 2598ca5e17eSAriel Elior return; 2608ca5e17eSAriel Elior } 2618ca5e17eSAriel Elior 2628ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf, 2638ca5e17eSAriel Elior struct bnx2x_vf_mbx *mbx, int vfop_status) 2648ca5e17eSAriel Elior { 2658ca5e17eSAriel Elior int i; 2668ca5e17eSAriel Elior struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp; 2678ca5e17eSAriel Elior struct pf_vf_resc *resc = &resp->resc; 2688ca5e17eSAriel Elior u8 status = bnx2x_pfvf_status_codes(vfop_status); 2698ca5e17eSAriel Elior 2708ca5e17eSAriel Elior memset(resp, 0, sizeof(*resp)); 2718ca5e17eSAriel Elior 2728ca5e17eSAriel Elior /* fill in pfdev info */ 2738ca5e17eSAriel Elior resp->pfdev_info.chip_num = bp->common.chip_id; 2748ca5e17eSAriel Elior resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT); 2758ca5e17eSAriel Elior resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2; 2768ca5e17eSAriel Elior resp->pfdev_info.pf_cap = (PFVF_CAP_RSS | 2778ca5e17eSAriel Elior /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA); 2788ca5e17eSAriel Elior bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver, 2798ca5e17eSAriel Elior sizeof(resp->pfdev_info.fw_ver)); 2808ca5e17eSAriel Elior 2818ca5e17eSAriel Elior if (status == PFVF_STATUS_NO_RESOURCE || 2828ca5e17eSAriel Elior status == PFVF_STATUS_SUCCESS) { 2838ca5e17eSAriel Elior /* set resources numbers, if status equals NO_RESOURCE these 2848ca5e17eSAriel Elior * are max possible numbers 2858ca5e17eSAriel Elior */ 2868ca5e17eSAriel Elior resc->num_rxqs = vf_rxq_count(vf) ? : 2878ca5e17eSAriel Elior bnx2x_vf_max_queue_cnt(bp, vf); 2888ca5e17eSAriel Elior resc->num_txqs = vf_txq_count(vf) ? : 2898ca5e17eSAriel Elior bnx2x_vf_max_queue_cnt(bp, vf); 2908ca5e17eSAriel Elior resc->num_sbs = vf_sb_count(vf); 2918ca5e17eSAriel Elior resc->num_mac_filters = vf_mac_rules_cnt(vf); 2928ca5e17eSAriel Elior resc->num_vlan_filters = vf_vlan_rules_cnt(vf); 2938ca5e17eSAriel Elior resc->num_mc_filters = 0; 2948ca5e17eSAriel Elior 2958ca5e17eSAriel Elior if (status == PFVF_STATUS_SUCCESS) { 2968ca5e17eSAriel Elior for_each_vfq(vf, i) 2978ca5e17eSAriel Elior resc->hw_qid[i] = 2988ca5e17eSAriel Elior vfq_qzone_id(vf, vfq_get(vf, i)); 2998ca5e17eSAriel Elior 3008ca5e17eSAriel Elior for_each_vf_sb(vf, i) { 3018ca5e17eSAriel Elior resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i); 3028ca5e17eSAriel Elior resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i); 3038ca5e17eSAriel Elior } 3048ca5e17eSAriel Elior } 3058ca5e17eSAriel Elior } 3068ca5e17eSAriel Elior 3078ca5e17eSAriel Elior DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n" 3088ca5e17eSAriel Elior "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n", 3098ca5e17eSAriel Elior vf->abs_vfid, 3108ca5e17eSAriel Elior resp->pfdev_info.chip_num, 3118ca5e17eSAriel Elior resp->pfdev_info.db_size, 3128ca5e17eSAriel Elior resp->pfdev_info.indices_per_sb, 3138ca5e17eSAriel Elior resp->pfdev_info.pf_cap, 3148ca5e17eSAriel Elior resc->num_rxqs, 3158ca5e17eSAriel Elior resc->num_txqs, 3168ca5e17eSAriel Elior resc->num_sbs, 3178ca5e17eSAriel Elior resc->num_mac_filters, 3188ca5e17eSAriel Elior resc->num_vlan_filters, 3198ca5e17eSAriel Elior resc->num_mc_filters, 3208ca5e17eSAriel Elior resp->pfdev_info.fw_ver); 3218ca5e17eSAriel Elior 3228ca5e17eSAriel Elior DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ "); 3238ca5e17eSAriel Elior for (i = 0; i < vf_rxq_count(vf); i++) 3248ca5e17eSAriel Elior DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]); 3258ca5e17eSAriel Elior DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ "); 3268ca5e17eSAriel Elior for (i = 0; i < vf_sb_count(vf); i++) 3278ca5e17eSAriel Elior DP_CONT(BNX2X_MSG_IOV, "%d:%d ", 3288ca5e17eSAriel Elior resc->hw_sbs[i].hw_sb_id, 3298ca5e17eSAriel Elior resc->hw_sbs[i].sb_qid); 3308ca5e17eSAriel Elior DP_CONT(BNX2X_MSG_IOV, "]\n"); 3318ca5e17eSAriel Elior 3328ca5e17eSAriel Elior /* send the response */ 3338ca5e17eSAriel Elior vf->op_rc = vfop_status; 3348ca5e17eSAriel Elior bnx2x_vf_mbx_resp(bp, vf); 3358ca5e17eSAriel Elior } 3368ca5e17eSAriel Elior 3378ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf, 3388ca5e17eSAriel Elior struct bnx2x_vf_mbx *mbx) 3398ca5e17eSAriel Elior { 3408ca5e17eSAriel Elior int rc; 3418ca5e17eSAriel Elior struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire; 3428ca5e17eSAriel Elior 3438ca5e17eSAriel Elior /* log vfdef info */ 3448ca5e17eSAriel Elior DP(BNX2X_MSG_IOV, 3458ca5e17eSAriel Elior "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n", 3468ca5e17eSAriel Elior vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os, 3478ca5e17eSAriel Elior acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs, 3488ca5e17eSAriel Elior acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters, 3498ca5e17eSAriel Elior acquire->resc_request.num_vlan_filters, 3508ca5e17eSAriel Elior acquire->resc_request.num_mc_filters); 3518ca5e17eSAriel Elior 3528ca5e17eSAriel Elior /* acquire the resources */ 3538ca5e17eSAriel Elior rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request); 3548ca5e17eSAriel Elior 3558ca5e17eSAriel Elior /* response */ 3568ca5e17eSAriel Elior bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc); 3578ca5e17eSAriel Elior } 3588ca5e17eSAriel Elior 359b93288d5SAriel Elior static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf, 360b93288d5SAriel Elior struct bnx2x_vf_mbx *mbx) 361b93288d5SAriel Elior { 362b93288d5SAriel Elior struct vfpf_init_tlv *init = &mbx->msg->req.init; 363b93288d5SAriel Elior 364b93288d5SAriel Elior /* record ghost addresses from vf message */ 365b93288d5SAriel Elior vf->spq_map = init->spq_addr; 366b93288d5SAriel Elior vf->fw_stat_map = init->stats_addr; 367b93288d5SAriel Elior vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr); 368b93288d5SAriel Elior 369b93288d5SAriel Elior /* response */ 370b93288d5SAriel Elior bnx2x_vf_mbx_resp(bp, vf); 371b93288d5SAriel Elior } 372b93288d5SAriel Elior 3738db573baSAriel Elior /* convert MBX queue-flags to standard SP queue-flags */ 3748db573baSAriel Elior static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags, 3758db573baSAriel Elior unsigned long *sp_q_flags) 3768db573baSAriel Elior { 3778db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_TPA) 3788db573baSAriel Elior __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags); 3798db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6) 3808db573baSAriel Elior __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags); 3818db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO) 3828db573baSAriel Elior __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags); 3838db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_STATS) 3848db573baSAriel Elior __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags); 3858db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_OV) 3868db573baSAriel Elior __set_bit(BNX2X_Q_FLG_OV, sp_q_flags); 3878db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN) 3888db573baSAriel Elior __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags); 3898db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_COS) 3908db573baSAriel Elior __set_bit(BNX2X_Q_FLG_COS, sp_q_flags); 3918db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_HC) 3928db573baSAriel Elior __set_bit(BNX2X_Q_FLG_HC, sp_q_flags); 3938db573baSAriel Elior if (mbx_q_flags & VFPF_QUEUE_FLG_DHC) 3948db573baSAriel Elior __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags); 3958db573baSAriel Elior } 3968db573baSAriel Elior 3978db573baSAriel Elior static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf, 3988db573baSAriel Elior struct bnx2x_vf_mbx *mbx) 3998db573baSAriel Elior { 4008db573baSAriel Elior struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q; 4018db573baSAriel Elior struct bnx2x_vfop_cmd cmd = { 4028db573baSAriel Elior .done = bnx2x_vf_mbx_resp, 4038db573baSAriel Elior .block = false, 4048db573baSAriel Elior }; 4058db573baSAriel Elior 4068db573baSAriel Elior /* verify vf_qid */ 4078db573baSAriel Elior if (setup_q->vf_qid >= vf_rxq_count(vf)) { 4088db573baSAriel Elior BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n", 4098db573baSAriel Elior setup_q->vf_qid, vf_rxq_count(vf)); 4108db573baSAriel Elior vf->op_rc = -EINVAL; 4118db573baSAriel Elior goto response; 4128db573baSAriel Elior } 4138db573baSAriel Elior 4148db573baSAriel Elior /* tx queues must be setup alongside rx queues thus if the rx queue 4158db573baSAriel Elior * is not marked as valid there's nothing to do. 4168db573baSAriel Elior */ 4178db573baSAriel Elior if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) { 4188db573baSAriel Elior struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid); 4198db573baSAriel Elior unsigned long q_type = 0; 4208db573baSAriel Elior 4218db573baSAriel Elior struct bnx2x_queue_init_params *init_p; 4228db573baSAriel Elior struct bnx2x_queue_setup_params *setup_p; 4238db573baSAriel Elior 4248db573baSAriel Elior /* reinit the VF operation context */ 4258db573baSAriel Elior memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor)); 4268db573baSAriel Elior setup_p = &vf->op_params.qctor.prep_qsetup; 4278db573baSAriel Elior init_p = &vf->op_params.qctor.qstate.params.init; 4288db573baSAriel Elior 4298db573baSAriel Elior /* activate immediately */ 4308db573baSAriel Elior __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags); 4318db573baSAriel Elior 4328db573baSAriel Elior if (setup_q->param_valid & VFPF_TXQ_VALID) { 4338db573baSAriel Elior struct bnx2x_txq_setup_params *txq_params = 4348db573baSAriel Elior &setup_p->txq_params; 4358db573baSAriel Elior 4368db573baSAriel Elior __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type); 4378db573baSAriel Elior 4388db573baSAriel Elior /* save sb resource index */ 4398db573baSAriel Elior q->sb_idx = setup_q->txq.vf_sb; 4408db573baSAriel Elior 4418db573baSAriel Elior /* tx init */ 4428db573baSAriel Elior init_p->tx.hc_rate = setup_q->txq.hc_rate; 4438db573baSAriel Elior init_p->tx.sb_cq_index = setup_q->txq.sb_index; 4448db573baSAriel Elior 4458db573baSAriel Elior bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags, 4468db573baSAriel Elior &init_p->tx.flags); 4478db573baSAriel Elior 4488db573baSAriel Elior /* tx setup - flags */ 4498db573baSAriel Elior bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags, 4508db573baSAriel Elior &setup_p->flags); 4518db573baSAriel Elior 4528db573baSAriel Elior /* tx setup - general, nothing */ 4538db573baSAriel Elior 4548db573baSAriel Elior /* tx setup - tx */ 4558db573baSAriel Elior txq_params->dscr_map = setup_q->txq.txq_addr; 4568db573baSAriel Elior txq_params->sb_cq_index = setup_q->txq.sb_index; 4578db573baSAriel Elior txq_params->traffic_type = setup_q->txq.traffic_type; 4588db573baSAriel Elior 4598db573baSAriel Elior bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p, 4608db573baSAriel Elior q->index, q->sb_idx); 4618db573baSAriel Elior } 4628db573baSAriel Elior 4638db573baSAriel Elior if (setup_q->param_valid & VFPF_RXQ_VALID) { 4648db573baSAriel Elior struct bnx2x_rxq_setup_params *rxq_params = 4658db573baSAriel Elior &setup_p->rxq_params; 4668db573baSAriel Elior 4678db573baSAriel Elior __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type); 4688db573baSAriel Elior 4698db573baSAriel Elior /* Note: there is no support for different SBs 4708db573baSAriel Elior * for TX and RX 4718db573baSAriel Elior */ 4728db573baSAriel Elior q->sb_idx = setup_q->rxq.vf_sb; 4738db573baSAriel Elior 4748db573baSAriel Elior /* rx init */ 4758db573baSAriel Elior init_p->rx.hc_rate = setup_q->rxq.hc_rate; 4768db573baSAriel Elior init_p->rx.sb_cq_index = setup_q->rxq.sb_index; 4778db573baSAriel Elior bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags, 4788db573baSAriel Elior &init_p->rx.flags); 4798db573baSAriel Elior 4808db573baSAriel Elior /* rx setup - flags */ 4818db573baSAriel Elior bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags, 4828db573baSAriel Elior &setup_p->flags); 4838db573baSAriel Elior 4848db573baSAriel Elior /* rx setup - general */ 4858db573baSAriel Elior setup_p->gen_params.mtu = setup_q->rxq.mtu; 4868db573baSAriel Elior 4878db573baSAriel Elior /* rx setup - rx */ 4888db573baSAriel Elior rxq_params->drop_flags = setup_q->rxq.drop_flags; 4898db573baSAriel Elior rxq_params->dscr_map = setup_q->rxq.rxq_addr; 4908db573baSAriel Elior rxq_params->sge_map = setup_q->rxq.sge_addr; 4918db573baSAriel Elior rxq_params->rcq_map = setup_q->rxq.rcq_addr; 4928db573baSAriel Elior rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr; 4938db573baSAriel Elior rxq_params->buf_sz = setup_q->rxq.buf_sz; 4948db573baSAriel Elior rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz; 4958db573baSAriel Elior rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt; 4968db573baSAriel Elior rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz; 4978db573baSAriel Elior rxq_params->cache_line_log = 4988db573baSAriel Elior setup_q->rxq.cache_line_log; 4998db573baSAriel Elior rxq_params->sb_cq_index = setup_q->rxq.sb_index; 5008db573baSAriel Elior 5018db573baSAriel Elior bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p, 5028db573baSAriel Elior q->index, q->sb_idx); 5038db573baSAriel Elior } 5048db573baSAriel Elior /* complete the preparations */ 5058db573baSAriel Elior bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type); 5068db573baSAriel Elior 5078db573baSAriel Elior vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index); 5088db573baSAriel Elior if (vf->op_rc) 5098db573baSAriel Elior goto response; 5108db573baSAriel Elior return; 5118db573baSAriel Elior } 5128db573baSAriel Elior response: 5138db573baSAriel Elior bnx2x_vf_mbx_resp(bp, vf); 5148db573baSAriel Elior } 5158db573baSAriel Elior 516fd1fc79dSAriel Elior /* dispatch request */ 517fd1fc79dSAriel Elior static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf, 518fd1fc79dSAriel Elior struct bnx2x_vf_mbx *mbx) 519fd1fc79dSAriel Elior { 520fd1fc79dSAriel Elior int i; 521fd1fc79dSAriel Elior 522fd1fc79dSAriel Elior /* check if tlv type is known */ 523fd1fc79dSAriel Elior if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) { 5248ca5e17eSAriel Elior /* Lock the per vf op mutex and note the locker's identity. 5258ca5e17eSAriel Elior * The unlock will take place in mbx response. 5268ca5e17eSAriel Elior */ 5278ca5e17eSAriel Elior bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type); 5288ca5e17eSAriel Elior 529fd1fc79dSAriel Elior /* switch on the opcode */ 530fd1fc79dSAriel Elior switch (mbx->first_tlv.tl.type) { 5318ca5e17eSAriel Elior case CHANNEL_TLV_ACQUIRE: 5328ca5e17eSAriel Elior bnx2x_vf_mbx_acquire(bp, vf, mbx); 5338ca5e17eSAriel Elior break; 534b93288d5SAriel Elior case CHANNEL_TLV_INIT: 535b93288d5SAriel Elior bnx2x_vf_mbx_init_vf(bp, vf, mbx); 536b93288d5SAriel Elior break; 5378db573baSAriel Elior case CHANNEL_TLV_SETUP_Q: 5388db573baSAriel Elior bnx2x_vf_mbx_setup_q(bp, vf, mbx); 5398db573baSAriel Elior break; 540fd1fc79dSAriel Elior } 541fd1fc79dSAriel Elior } else { 542fd1fc79dSAriel Elior /* unknown TLV - this may belong to a VF driver from the future 543fd1fc79dSAriel Elior * - a version written after this PF driver was written, which 544fd1fc79dSAriel Elior * supports features unknown as of yet. Too bad since we don't 545fd1fc79dSAriel Elior * support them. Or this may be because someone wrote a crappy 546fd1fc79dSAriel Elior * VF driver and is sending garbage over the channel. 547fd1fc79dSAriel Elior */ 548fd1fc79dSAriel Elior BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n", 549fd1fc79dSAriel Elior mbx->first_tlv.tl.type, mbx->first_tlv.tl.length); 550fd1fc79dSAriel Elior for (i = 0; i < 20; i++) 551fd1fc79dSAriel Elior DP_CONT(BNX2X_MSG_IOV, "%x ", 552fd1fc79dSAriel Elior mbx->msg->req.tlv_buf_size.tlv_buffer[i]); 5538ca5e17eSAriel Elior 5548ca5e17eSAriel Elior /* test whether we can respond to the VF (do we have an address 5558ca5e17eSAriel Elior * for it?) 5568ca5e17eSAriel Elior */ 5578ca5e17eSAriel Elior if (vf->state == VF_ACQUIRED) { 5588ca5e17eSAriel Elior /* mbx_resp uses the op_rc of the VF */ 5598ca5e17eSAriel Elior vf->op_rc = PFVF_STATUS_NOT_SUPPORTED; 5608ca5e17eSAriel Elior 5618ca5e17eSAriel Elior /* notify the VF that we do not support this request */ 5628ca5e17eSAriel Elior bnx2x_vf_mbx_resp(bp, vf); 5638ca5e17eSAriel Elior } else { 5648ca5e17eSAriel Elior /* can't send a response since this VF is unknown to us 5658ca5e17eSAriel Elior * just unlock the channel and be done with. 5668ca5e17eSAriel Elior */ 5678ca5e17eSAriel Elior bnx2x_unlock_vf_pf_channel(bp, vf, 5688ca5e17eSAriel Elior mbx->first_tlv.tl.type); 5698ca5e17eSAriel Elior } 570fd1fc79dSAriel Elior } 571fd1fc79dSAriel Elior } 572fd1fc79dSAriel Elior 573fd1fc79dSAriel Elior /* handle new vf-pf message */ 574fd1fc79dSAriel Elior void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event) 575fd1fc79dSAriel Elior { 576fd1fc79dSAriel Elior struct bnx2x_virtf *vf; 577fd1fc79dSAriel Elior struct bnx2x_vf_mbx *mbx; 578fd1fc79dSAriel Elior u8 vf_idx; 579fd1fc79dSAriel Elior int rc; 580fd1fc79dSAriel Elior 581fd1fc79dSAriel Elior DP(BNX2X_MSG_IOV, 582fd1fc79dSAriel Elior "vf pf event received: vfid %d, address_hi %x, address lo %x", 583fd1fc79dSAriel Elior vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo); 584fd1fc79dSAriel Elior /* Sanity checks consider removing later */ 585fd1fc79dSAriel Elior 586fd1fc79dSAriel Elior /* check if the vf_id is valid */ 587fd1fc79dSAriel Elior if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf > 588fd1fc79dSAriel Elior BNX2X_NR_VIRTFN(bp)) { 589fd1fc79dSAriel Elior BNX2X_ERR("Illegal vf_id %d max allowed: %d\n", 590fd1fc79dSAriel Elior vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp)); 591fd1fc79dSAriel Elior goto mbx_done; 592fd1fc79dSAriel Elior } 593fd1fc79dSAriel Elior vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id); 594fd1fc79dSAriel Elior mbx = BP_VF_MBX(bp, vf_idx); 595fd1fc79dSAriel Elior 596fd1fc79dSAriel Elior /* verify an event is not currently being processed - 597fd1fc79dSAriel Elior * debug failsafe only 598fd1fc79dSAriel Elior */ 599fd1fc79dSAriel Elior if (mbx->flags & VF_MSG_INPROCESS) { 600fd1fc79dSAriel Elior BNX2X_ERR("Previous message is still being processed, vf_id %d\n", 601fd1fc79dSAriel Elior vfpf_event->vf_id); 602fd1fc79dSAriel Elior goto mbx_done; 603fd1fc79dSAriel Elior } 604fd1fc79dSAriel Elior vf = BP_VF(bp, vf_idx); 605fd1fc79dSAriel Elior 606fd1fc79dSAriel Elior /* save the VF message address */ 607fd1fc79dSAriel Elior mbx->vf_addr_hi = vfpf_event->msg_addr_hi; 608fd1fc79dSAriel Elior mbx->vf_addr_lo = vfpf_event->msg_addr_lo; 609fd1fc79dSAriel Elior DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n", 610fd1fc79dSAriel Elior mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset); 611fd1fc79dSAriel Elior 612fd1fc79dSAriel Elior /* dmae to get the VF request */ 613fd1fc79dSAriel Elior rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid, 614fd1fc79dSAriel Elior mbx->vf_addr_hi, mbx->vf_addr_lo, 615fd1fc79dSAriel Elior sizeof(union vfpf_tlvs)/4); 616fd1fc79dSAriel Elior if (rc) { 617fd1fc79dSAriel Elior BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid); 618fd1fc79dSAriel Elior goto mbx_error; 619fd1fc79dSAriel Elior } 620fd1fc79dSAriel Elior 621fd1fc79dSAriel Elior /* process the VF message header */ 622fd1fc79dSAriel Elior mbx->first_tlv = mbx->msg->req.first_tlv; 623fd1fc79dSAriel Elior 624fd1fc79dSAriel Elior /* dispatch the request (will prepare the response) */ 625fd1fc79dSAriel Elior bnx2x_vf_mbx_request(bp, vf, mbx); 626fd1fc79dSAriel Elior goto mbx_done; 627fd1fc79dSAriel Elior 628fd1fc79dSAriel Elior mbx_error: 629fd1fc79dSAriel Elior mbx_done: 630fd1fc79dSAriel Elior return; 631fd1fc79dSAriel Elior } 632