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"
22be1f1ffaSAriel Elior 
23be1f1ffaSAriel Elior /* place a given tlv on the tlv buffer at a given offset */
24be1f1ffaSAriel Elior void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
25be1f1ffaSAriel Elior 		   u16 length)
26be1f1ffaSAriel Elior {
27be1f1ffaSAriel Elior 	struct channel_tlv *tl =
28be1f1ffaSAriel Elior 		(struct channel_tlv *)(tlvs_list + offset);
29be1f1ffaSAriel Elior 
30be1f1ffaSAriel Elior 	tl->type = type;
31be1f1ffaSAriel Elior 	tl->length = length;
32be1f1ffaSAriel Elior }
33be1f1ffaSAriel Elior 
34be1f1ffaSAriel Elior /* Clear the mailbox and init the header of the first tlv */
35be1f1ffaSAriel Elior void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
36be1f1ffaSAriel Elior 		     u16 type, u16 length)
37be1f1ffaSAriel Elior {
38be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
39be1f1ffaSAriel Elior 	   type);
40be1f1ffaSAriel Elior 
41be1f1ffaSAriel Elior 	/* Clear mailbox */
42be1f1ffaSAriel Elior 	memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
43be1f1ffaSAriel Elior 
44be1f1ffaSAriel Elior 	/* init type and length */
45be1f1ffaSAriel Elior 	bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
46be1f1ffaSAriel Elior 
47be1f1ffaSAriel Elior 	/* init first tlv header */
48be1f1ffaSAriel Elior 	first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
49be1f1ffaSAriel Elior }
50be1f1ffaSAriel Elior 
51be1f1ffaSAriel Elior /* list the types and lengths of the tlvs on the buffer */
52be1f1ffaSAriel Elior void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
53be1f1ffaSAriel Elior {
54be1f1ffaSAriel Elior 	int i = 1;
55be1f1ffaSAriel Elior 	struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
56be1f1ffaSAriel Elior 
57be1f1ffaSAriel Elior 	while (tlv->type != CHANNEL_TLV_LIST_END) {
58be1f1ffaSAriel Elior 		/* output tlv */
59be1f1ffaSAriel Elior 		DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
60be1f1ffaSAriel Elior 		   tlv->type, tlv->length);
61be1f1ffaSAriel Elior 
62be1f1ffaSAriel Elior 		/* advance to next tlv */
63be1f1ffaSAriel Elior 		tlvs_list += tlv->length;
64be1f1ffaSAriel Elior 
65be1f1ffaSAriel Elior 		/* cast general tlv list pointer to channel tlv header*/
66be1f1ffaSAriel Elior 		tlv = (struct channel_tlv *)tlvs_list;
67be1f1ffaSAriel Elior 
68be1f1ffaSAriel Elior 		i++;
69be1f1ffaSAriel Elior 
70be1f1ffaSAriel Elior 		/* break condition for this loop */
71be1f1ffaSAriel Elior 		if (i > MAX_TLVS_IN_LIST) {
72be1f1ffaSAriel Elior 			WARN(true, "corrupt tlvs");
73be1f1ffaSAriel Elior 			return;
74be1f1ffaSAriel Elior 		}
75be1f1ffaSAriel Elior 	}
76be1f1ffaSAriel Elior 
77be1f1ffaSAriel Elior 	/* output last tlv */
78be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
79be1f1ffaSAriel Elior 	   tlv->type, tlv->length);
80be1f1ffaSAriel Elior }
81b56e9670SAriel Elior 
82fd1fc79dSAriel Elior /* test whether we support a tlv type */
83fd1fc79dSAriel Elior bool bnx2x_tlv_supported(u16 tlvtype)
84fd1fc79dSAriel Elior {
85fd1fc79dSAriel Elior 	return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
86fd1fc79dSAriel Elior }
87fd1fc79dSAriel Elior 
88fd1fc79dSAriel Elior static inline int bnx2x_pfvf_status_codes(int rc)
89fd1fc79dSAriel Elior {
90fd1fc79dSAriel Elior 	switch (rc) {
91fd1fc79dSAriel Elior 	case 0:
92fd1fc79dSAriel Elior 		return PFVF_STATUS_SUCCESS;
93fd1fc79dSAriel Elior 	case -ENOMEM:
94fd1fc79dSAriel Elior 		return PFVF_STATUS_NO_RESOURCE;
95fd1fc79dSAriel Elior 	default:
96fd1fc79dSAriel Elior 		return PFVF_STATUS_FAILURE;
97fd1fc79dSAriel Elior 	}
98fd1fc79dSAriel Elior }
99fd1fc79dSAriel Elior 
100b56e9670SAriel Elior /* General service functions */
101b56e9670SAriel Elior static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
102b56e9670SAriel Elior {
103b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
104b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
105b56e9670SAriel Elior 
106b56e9670SAriel Elior 	REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
107b56e9670SAriel Elior }
108b56e9670SAriel Elior 
109b56e9670SAriel Elior static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
110b56e9670SAriel Elior {
111b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
112b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
113b56e9670SAriel Elior 
114b56e9670SAriel Elior 	REG_WR8(bp, addr, 1);
115b56e9670SAriel Elior }
116b56e9670SAriel Elior 
117b56e9670SAriel Elior static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
118b56e9670SAriel Elior {
119b56e9670SAriel Elior 	int i;
120b56e9670SAriel Elior 
121b56e9670SAriel Elior 	for_each_vf(bp, i)
122b56e9670SAriel Elior 		storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
123b56e9670SAriel Elior }
124b56e9670SAriel Elior 
125b56e9670SAriel Elior /* enable vf_pf mailbox (aka vf-pf-chanell) */
126b56e9670SAriel Elior void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
127b56e9670SAriel Elior {
128b56e9670SAriel Elior 	bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
129b56e9670SAriel Elior 
130b56e9670SAriel Elior 	/* enable the mailbox in the FW */
131b56e9670SAriel Elior 	storm_memset_vf_mbx_ack(bp, abs_vfid);
132b56e9670SAriel Elior 	storm_memset_vf_mbx_valid(bp, abs_vfid);
133b56e9670SAriel Elior 
134b56e9670SAriel Elior 	/* enable the VF access to the mailbox */
135b56e9670SAriel Elior 	bnx2x_vf_enable_access(bp, abs_vfid);
136b56e9670SAriel Elior }
137fd1fc79dSAriel Elior 
138fd1fc79dSAriel Elior /* this works only on !E1h */
139fd1fc79dSAriel Elior static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
140fd1fc79dSAriel Elior 				dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
141fd1fc79dSAriel Elior 				u32 vf_addr_lo, u32 len32)
142fd1fc79dSAriel Elior {
143fd1fc79dSAriel Elior 	struct dmae_command dmae;
144fd1fc79dSAriel Elior 
145fd1fc79dSAriel Elior 	if (CHIP_IS_E1x(bp)) {
146fd1fc79dSAriel Elior 		BNX2X_ERR("Chip revision does not support VFs\n");
147fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
148fd1fc79dSAriel Elior 	}
149fd1fc79dSAriel Elior 
150fd1fc79dSAriel Elior 	if (!bp->dmae_ready) {
151fd1fc79dSAriel Elior 		BNX2X_ERR("DMAE is not ready, can not copy\n");
152fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
153fd1fc79dSAriel Elior 	}
154fd1fc79dSAriel Elior 
155fd1fc79dSAriel Elior 	/* set opcode and fixed command fields */
156fd1fc79dSAriel Elior 	bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
157fd1fc79dSAriel Elior 
158fd1fc79dSAriel Elior 	if (from_vf) {
159fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
160fd1fc79dSAriel Elior 			(DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
161fd1fc79dSAriel Elior 			(DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
162fd1fc79dSAriel Elior 
163fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
164fd1fc79dSAriel Elior 
165fd1fc79dSAriel Elior 		dmae.src_addr_lo = vf_addr_lo;
166fd1fc79dSAriel Elior 		dmae.src_addr_hi = vf_addr_hi;
167fd1fc79dSAriel Elior 		dmae.dst_addr_lo = U64_LO(pf_addr);
168fd1fc79dSAriel Elior 		dmae.dst_addr_hi = U64_HI(pf_addr);
169fd1fc79dSAriel Elior 	} else {
170fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
171fd1fc79dSAriel Elior 			(DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
172fd1fc79dSAriel Elior 			(DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
173fd1fc79dSAriel Elior 
174fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
175fd1fc79dSAriel Elior 
176fd1fc79dSAriel Elior 		dmae.src_addr_lo = U64_LO(pf_addr);
177fd1fc79dSAriel Elior 		dmae.src_addr_hi = U64_HI(pf_addr);
178fd1fc79dSAriel Elior 		dmae.dst_addr_lo = vf_addr_lo;
179fd1fc79dSAriel Elior 		dmae.dst_addr_hi = vf_addr_hi;
180fd1fc79dSAriel Elior 	}
181fd1fc79dSAriel Elior 	dmae.len = len32;
182fd1fc79dSAriel Elior 	bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
183fd1fc79dSAriel Elior 
184fd1fc79dSAriel Elior 	/* issue the command and wait for completion */
185fd1fc79dSAriel Elior 	return bnx2x_issue_dmae_with_comp(bp, &dmae);
186fd1fc79dSAriel Elior }
187fd1fc79dSAriel Elior 
1888ca5e17eSAriel Elior static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
1898ca5e17eSAriel Elior {
1908ca5e17eSAriel Elior 	struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1918ca5e17eSAriel Elior 	u64 vf_addr;
1928ca5e17eSAriel Elior 	dma_addr_t pf_addr;
1938ca5e17eSAriel Elior 	u16 length, type;
1948ca5e17eSAriel Elior 	int rc;
1958ca5e17eSAriel Elior 	struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1968ca5e17eSAriel Elior 
1978ca5e17eSAriel Elior 	/* prepare response */
1988ca5e17eSAriel Elior 	type = mbx->first_tlv.tl.type;
1998ca5e17eSAriel Elior 	length = type == CHANNEL_TLV_ACQUIRE ?
2008ca5e17eSAriel Elior 		sizeof(struct pfvf_acquire_resp_tlv) :
2018ca5e17eSAriel Elior 		sizeof(struct pfvf_general_resp_tlv);
2028ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, 0, type, length);
2038ca5e17eSAriel Elior 	resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
2048ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
2058ca5e17eSAriel Elior 		      sizeof(struct channel_list_end_tlv));
2068ca5e17eSAriel Elior 	bnx2x_dp_tlv_list(bp, resp);
2078ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
2088ca5e17eSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
2098ca5e17eSAriel Elior 
2108ca5e17eSAriel Elior 	/* send response */
2118ca5e17eSAriel Elior 	vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
2128ca5e17eSAriel Elior 		  mbx->first_tlv.resp_msg_offset;
2138ca5e17eSAriel Elior 	pf_addr = mbx->msg_mapping +
2148ca5e17eSAriel Elior 		  offsetof(struct bnx2x_vf_mbx_msg, resp);
2158ca5e17eSAriel Elior 
2168ca5e17eSAriel Elior 	/* copy the response body, if there is one, before the header, as the vf
2178ca5e17eSAriel Elior 	 * is sensitive to the header being written
2188ca5e17eSAriel Elior 	 */
2198ca5e17eSAriel Elior 	if (resp->hdr.tl.length > sizeof(u64)) {
2208ca5e17eSAriel Elior 		length = resp->hdr.tl.length - sizeof(u64);
2218ca5e17eSAriel Elior 		vf_addr += sizeof(u64);
2228ca5e17eSAriel Elior 		pf_addr += sizeof(u64);
2238ca5e17eSAriel Elior 		rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
2248ca5e17eSAriel Elior 					  U64_HI(vf_addr),
2258ca5e17eSAriel Elior 					  U64_LO(vf_addr),
2268ca5e17eSAriel Elior 					  length/4);
2278ca5e17eSAriel Elior 		if (rc) {
2288ca5e17eSAriel Elior 			BNX2X_ERR("Failed to copy response body to VF %d\n",
2298ca5e17eSAriel Elior 				  vf->abs_vfid);
2308ca5e17eSAriel Elior 			return;
2318ca5e17eSAriel Elior 		}
2328ca5e17eSAriel Elior 		vf_addr -= sizeof(u64);
2338ca5e17eSAriel Elior 		pf_addr -= sizeof(u64);
2348ca5e17eSAriel Elior 	}
2358ca5e17eSAriel Elior 
2368ca5e17eSAriel Elior 	/* ack the FW */
2378ca5e17eSAriel Elior 	storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2388ca5e17eSAriel Elior 	mmiowb();
2398ca5e17eSAriel Elior 
2408ca5e17eSAriel Elior 	/* initiate dmae to send the response */
2418ca5e17eSAriel Elior 	mbx->flags &= ~VF_MSG_INPROCESS;
2428ca5e17eSAriel Elior 
2438ca5e17eSAriel Elior 	/* copy the response header including status-done field,
2448ca5e17eSAriel Elior 	 * must be last dmae, must be after FW is acked
2458ca5e17eSAriel Elior 	 */
2468ca5e17eSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
2478ca5e17eSAriel Elior 				  U64_HI(vf_addr),
2488ca5e17eSAriel Elior 				  U64_LO(vf_addr),
2498ca5e17eSAriel Elior 				  sizeof(u64)/4);
2508ca5e17eSAriel Elior 
2518ca5e17eSAriel Elior 	/* unlock channel mutex */
2528ca5e17eSAriel Elior 	bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2538ca5e17eSAriel Elior 
2548ca5e17eSAriel Elior 	if (rc) {
2558ca5e17eSAriel Elior 		BNX2X_ERR("Failed to copy response status to VF %d\n",
2568ca5e17eSAriel Elior 			  vf->abs_vfid);
2578ca5e17eSAriel Elior 	}
2588ca5e17eSAriel Elior 	return;
2598ca5e17eSAriel Elior }
2608ca5e17eSAriel Elior 
2618ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
2628ca5e17eSAriel Elior 				      struct bnx2x_vf_mbx *mbx, int vfop_status)
2638ca5e17eSAriel Elior {
2648ca5e17eSAriel Elior 	int i;
2658ca5e17eSAriel Elior 	struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
2668ca5e17eSAriel Elior 	struct pf_vf_resc *resc = &resp->resc;
2678ca5e17eSAriel Elior 	u8 status = bnx2x_pfvf_status_codes(vfop_status);
2688ca5e17eSAriel Elior 
2698ca5e17eSAriel Elior 	memset(resp, 0, sizeof(*resp));
2708ca5e17eSAriel Elior 
2718ca5e17eSAriel Elior 	/* fill in pfdev info */
2728ca5e17eSAriel Elior 	resp->pfdev_info.chip_num = bp->common.chip_id;
2738ca5e17eSAriel Elior 	resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
2748ca5e17eSAriel Elior 	resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
2758ca5e17eSAriel Elior 	resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
2768ca5e17eSAriel Elior 				   /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
2778ca5e17eSAriel Elior 	bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
2788ca5e17eSAriel Elior 			  sizeof(resp->pfdev_info.fw_ver));
2798ca5e17eSAriel Elior 
2808ca5e17eSAriel Elior 	if (status == PFVF_STATUS_NO_RESOURCE ||
2818ca5e17eSAriel Elior 	    status == PFVF_STATUS_SUCCESS) {
2828ca5e17eSAriel Elior 		/* set resources numbers, if status equals NO_RESOURCE these
2838ca5e17eSAriel Elior 		 * are max possible numbers
2848ca5e17eSAriel Elior 		 */
2858ca5e17eSAriel Elior 		resc->num_rxqs = vf_rxq_count(vf) ? :
2868ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
2878ca5e17eSAriel Elior 		resc->num_txqs = vf_txq_count(vf) ? :
2888ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
2898ca5e17eSAriel Elior 		resc->num_sbs = vf_sb_count(vf);
2908ca5e17eSAriel Elior 		resc->num_mac_filters = vf_mac_rules_cnt(vf);
2918ca5e17eSAriel Elior 		resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
2928ca5e17eSAriel Elior 		resc->num_mc_filters = 0;
2938ca5e17eSAriel Elior 
2948ca5e17eSAriel Elior 		if (status == PFVF_STATUS_SUCCESS) {
2958ca5e17eSAriel Elior 			for_each_vfq(vf, i)
2968ca5e17eSAriel Elior 				resc->hw_qid[i] =
2978ca5e17eSAriel Elior 					vfq_qzone_id(vf, vfq_get(vf, i));
2988ca5e17eSAriel Elior 
2998ca5e17eSAriel Elior 			for_each_vf_sb(vf, i) {
3008ca5e17eSAriel Elior 				resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
3018ca5e17eSAriel Elior 				resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
3028ca5e17eSAriel Elior 			}
3038ca5e17eSAriel Elior 		}
3048ca5e17eSAriel Elior 	}
3058ca5e17eSAriel Elior 
3068ca5e17eSAriel 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"
3078ca5e17eSAriel Elior 	   "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
3088ca5e17eSAriel Elior 	   vf->abs_vfid,
3098ca5e17eSAriel Elior 	   resp->pfdev_info.chip_num,
3108ca5e17eSAriel Elior 	   resp->pfdev_info.db_size,
3118ca5e17eSAriel Elior 	   resp->pfdev_info.indices_per_sb,
3128ca5e17eSAriel Elior 	   resp->pfdev_info.pf_cap,
3138ca5e17eSAriel Elior 	   resc->num_rxqs,
3148ca5e17eSAriel Elior 	   resc->num_txqs,
3158ca5e17eSAriel Elior 	   resc->num_sbs,
3168ca5e17eSAriel Elior 	   resc->num_mac_filters,
3178ca5e17eSAriel Elior 	   resc->num_vlan_filters,
3188ca5e17eSAriel Elior 	   resc->num_mc_filters,
3198ca5e17eSAriel Elior 	   resp->pfdev_info.fw_ver);
3208ca5e17eSAriel Elior 
3218ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
3228ca5e17eSAriel Elior 	for (i = 0; i < vf_rxq_count(vf); i++)
3238ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
3248ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
3258ca5e17eSAriel Elior 	for (i = 0; i < vf_sb_count(vf); i++)
3268ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
3278ca5e17eSAriel Elior 			resc->hw_sbs[i].hw_sb_id,
3288ca5e17eSAriel Elior 			resc->hw_sbs[i].sb_qid);
3298ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "]\n");
3308ca5e17eSAriel Elior 
3318ca5e17eSAriel Elior 	/* send the response */
3328ca5e17eSAriel Elior 	vf->op_rc = vfop_status;
3338ca5e17eSAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
3348ca5e17eSAriel Elior }
3358ca5e17eSAriel Elior 
3368ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
3378ca5e17eSAriel Elior 				 struct bnx2x_vf_mbx *mbx)
3388ca5e17eSAriel Elior {
3398ca5e17eSAriel Elior 	int rc;
3408ca5e17eSAriel Elior 	struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
3418ca5e17eSAriel Elior 
3428ca5e17eSAriel Elior 	/* log vfdef info */
3438ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV,
3448ca5e17eSAriel 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",
3458ca5e17eSAriel Elior 	   vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
3468ca5e17eSAriel Elior 	   acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
3478ca5e17eSAriel Elior 	   acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
3488ca5e17eSAriel Elior 	   acquire->resc_request.num_vlan_filters,
3498ca5e17eSAriel Elior 	   acquire->resc_request.num_mc_filters);
3508ca5e17eSAriel Elior 
3518ca5e17eSAriel Elior 	/* acquire the resources */
3528ca5e17eSAriel Elior 	rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
3538ca5e17eSAriel Elior 
3548ca5e17eSAriel Elior 	/* response */
3558ca5e17eSAriel Elior 	bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
3568ca5e17eSAriel Elior }
3578ca5e17eSAriel Elior 
358fd1fc79dSAriel Elior /* dispatch request */
359fd1fc79dSAriel Elior static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
360fd1fc79dSAriel Elior 				  struct bnx2x_vf_mbx *mbx)
361fd1fc79dSAriel Elior {
362fd1fc79dSAriel Elior 	int i;
363fd1fc79dSAriel Elior 
364fd1fc79dSAriel Elior 	/* check if tlv type is known */
365fd1fc79dSAriel Elior 	if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
3668ca5e17eSAriel Elior 		/* Lock the per vf op mutex and note the locker's identity.
3678ca5e17eSAriel Elior 		 * The unlock will take place in mbx response.
3688ca5e17eSAriel Elior 		 */
3698ca5e17eSAriel Elior 		bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
3708ca5e17eSAriel Elior 
371fd1fc79dSAriel Elior 		/* switch on the opcode */
372fd1fc79dSAriel Elior 		switch (mbx->first_tlv.tl.type) {
3738ca5e17eSAriel Elior 		case CHANNEL_TLV_ACQUIRE:
3748ca5e17eSAriel Elior 			bnx2x_vf_mbx_acquire(bp, vf, mbx);
3758ca5e17eSAriel Elior 			break;
376fd1fc79dSAriel Elior 		}
377fd1fc79dSAriel Elior 	} else {
378fd1fc79dSAriel Elior 		/* unknown TLV - this may belong to a VF driver from the future
379fd1fc79dSAriel Elior 		 * - a version written after this PF driver was written, which
380fd1fc79dSAriel Elior 		 * supports features unknown as of yet. Too bad since we don't
381fd1fc79dSAriel Elior 		 * support them. Or this may be because someone wrote a crappy
382fd1fc79dSAriel Elior 		 * VF driver and is sending garbage over the channel.
383fd1fc79dSAriel Elior 		 */
384fd1fc79dSAriel Elior 		BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
385fd1fc79dSAriel Elior 			  mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
386fd1fc79dSAriel Elior 		for (i = 0; i < 20; i++)
387fd1fc79dSAriel Elior 			DP_CONT(BNX2X_MSG_IOV, "%x ",
388fd1fc79dSAriel Elior 				mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
3898ca5e17eSAriel Elior 
3908ca5e17eSAriel Elior 		/* test whether we can respond to the VF (do we have an address
3918ca5e17eSAriel Elior 		 * for it?)
3928ca5e17eSAriel Elior 		 */
3938ca5e17eSAriel Elior 		if (vf->state == VF_ACQUIRED) {
3948ca5e17eSAriel Elior 			/* mbx_resp uses the op_rc of the VF */
3958ca5e17eSAriel Elior 			vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
3968ca5e17eSAriel Elior 
3978ca5e17eSAriel Elior 			/* notify the VF that we do not support this request */
3988ca5e17eSAriel Elior 			bnx2x_vf_mbx_resp(bp, vf);
3998ca5e17eSAriel Elior 		} else {
4008ca5e17eSAriel Elior 			/* can't send a response since this VF is unknown to us
4018ca5e17eSAriel Elior 			 * just unlock the channel and be done with.
4028ca5e17eSAriel Elior 			 */
4038ca5e17eSAriel Elior 			bnx2x_unlock_vf_pf_channel(bp, vf,
4048ca5e17eSAriel Elior 						   mbx->first_tlv.tl.type);
4058ca5e17eSAriel Elior 		}
406fd1fc79dSAriel Elior 	}
407fd1fc79dSAriel Elior }
408fd1fc79dSAriel Elior 
409fd1fc79dSAriel Elior /* handle new vf-pf message */
410fd1fc79dSAriel Elior void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
411fd1fc79dSAriel Elior {
412fd1fc79dSAriel Elior 	struct bnx2x_virtf *vf;
413fd1fc79dSAriel Elior 	struct bnx2x_vf_mbx *mbx;
414fd1fc79dSAriel Elior 	u8 vf_idx;
415fd1fc79dSAriel Elior 	int rc;
416fd1fc79dSAriel Elior 
417fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV,
418fd1fc79dSAriel Elior 	   "vf pf event received: vfid %d, address_hi %x, address lo %x",
419fd1fc79dSAriel Elior 	   vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
420fd1fc79dSAriel Elior 	/* Sanity checks consider removing later */
421fd1fc79dSAriel Elior 
422fd1fc79dSAriel Elior 	/* check if the vf_id is valid */
423fd1fc79dSAriel Elior 	if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
424fd1fc79dSAriel Elior 	    BNX2X_NR_VIRTFN(bp)) {
425fd1fc79dSAriel Elior 		BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
426fd1fc79dSAriel Elior 			  vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
427fd1fc79dSAriel Elior 		goto mbx_done;
428fd1fc79dSAriel Elior 	}
429fd1fc79dSAriel Elior 	vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
430fd1fc79dSAriel Elior 	mbx = BP_VF_MBX(bp, vf_idx);
431fd1fc79dSAriel Elior 
432fd1fc79dSAriel Elior 	/* verify an event is not currently being processed -
433fd1fc79dSAriel Elior 	 * debug failsafe only
434fd1fc79dSAriel Elior 	 */
435fd1fc79dSAriel Elior 	if (mbx->flags & VF_MSG_INPROCESS) {
436fd1fc79dSAriel Elior 		BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
437fd1fc79dSAriel Elior 			  vfpf_event->vf_id);
438fd1fc79dSAriel Elior 		goto mbx_done;
439fd1fc79dSAriel Elior 	}
440fd1fc79dSAriel Elior 	vf = BP_VF(bp, vf_idx);
441fd1fc79dSAriel Elior 
442fd1fc79dSAriel Elior 	/* save the VF message address */
443fd1fc79dSAriel Elior 	mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
444fd1fc79dSAriel Elior 	mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
445fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
446fd1fc79dSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
447fd1fc79dSAriel Elior 
448fd1fc79dSAriel Elior 	/* dmae to get the VF request */
449fd1fc79dSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
450fd1fc79dSAriel Elior 				  mbx->vf_addr_hi, mbx->vf_addr_lo,
451fd1fc79dSAriel Elior 				  sizeof(union vfpf_tlvs)/4);
452fd1fc79dSAriel Elior 	if (rc) {
453fd1fc79dSAriel Elior 		BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
454fd1fc79dSAriel Elior 		goto mbx_error;
455fd1fc79dSAriel Elior 	}
456fd1fc79dSAriel Elior 
457fd1fc79dSAriel Elior 	/* process the VF message header */
458fd1fc79dSAriel Elior 	mbx->first_tlv = mbx->msg->req.first_tlv;
459fd1fc79dSAriel Elior 
460fd1fc79dSAriel Elior 	/* dispatch the request (will prepare the response) */
461fd1fc79dSAriel Elior 	bnx2x_vf_mbx_request(bp, vf, mbx);
462fd1fc79dSAriel Elior 	goto mbx_done;
463fd1fc79dSAriel Elior 
464fd1fc79dSAriel Elior mbx_error:
465fd1fc79dSAriel Elior mbx_done:
466fd1fc79dSAriel Elior 	return;
467fd1fc79dSAriel Elior }
468