1be1f1ffaSAriel Elior /* bnx2x_vfpf.c: Broadcom Everest network driver.
2be1f1ffaSAriel Elior  *
3247fa82bSYuval Mintz  * Copyright 2009-2013 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"
216411280aSAriel Elior #include "bnx2x_cmn.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 {
391d6f3cd8SDmitry Kravkov 	mutex_lock(&bp->vf2pf_mutex);
401d6f3cd8SDmitry Kravkov 
41be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
42be1f1ffaSAriel Elior 	   type);
43be1f1ffaSAriel Elior 
44be1f1ffaSAriel Elior 	/* Clear mailbox */
45be1f1ffaSAriel Elior 	memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
46be1f1ffaSAriel Elior 
47be1f1ffaSAriel Elior 	/* init type and length */
48be1f1ffaSAriel Elior 	bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
49be1f1ffaSAriel Elior 
50be1f1ffaSAriel Elior 	/* init first tlv header */
51be1f1ffaSAriel Elior 	first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
52be1f1ffaSAriel Elior }
53be1f1ffaSAriel Elior 
541d6f3cd8SDmitry Kravkov /* releases the mailbox */
551d6f3cd8SDmitry Kravkov void bnx2x_vfpf_finalize(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv)
561d6f3cd8SDmitry Kravkov {
571d6f3cd8SDmitry Kravkov 	DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
581d6f3cd8SDmitry Kravkov 	   first_tlv->tl.type);
591d6f3cd8SDmitry Kravkov 
601d6f3cd8SDmitry Kravkov 	mutex_unlock(&bp->vf2pf_mutex);
611d6f3cd8SDmitry Kravkov }
621d6f3cd8SDmitry Kravkov 
63be1f1ffaSAriel Elior /* list the types and lengths of the tlvs on the buffer */
64be1f1ffaSAriel Elior void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
65be1f1ffaSAriel Elior {
66be1f1ffaSAriel Elior 	int i = 1;
67be1f1ffaSAriel Elior 	struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
68be1f1ffaSAriel Elior 
69be1f1ffaSAriel Elior 	while (tlv->type != CHANNEL_TLV_LIST_END) {
70be1f1ffaSAriel Elior 		/* output tlv */
71be1f1ffaSAriel Elior 		DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
72be1f1ffaSAriel Elior 		   tlv->type, tlv->length);
73be1f1ffaSAriel Elior 
74be1f1ffaSAriel Elior 		/* advance to next tlv */
75be1f1ffaSAriel Elior 		tlvs_list += tlv->length;
76be1f1ffaSAriel Elior 
77be1f1ffaSAriel Elior 		/* cast general tlv list pointer to channel tlv header*/
78be1f1ffaSAriel Elior 		tlv = (struct channel_tlv *)tlvs_list;
79be1f1ffaSAriel Elior 
80be1f1ffaSAriel Elior 		i++;
81be1f1ffaSAriel Elior 
82be1f1ffaSAriel Elior 		/* break condition for this loop */
83be1f1ffaSAriel Elior 		if (i > MAX_TLVS_IN_LIST) {
84be1f1ffaSAriel Elior 			WARN(true, "corrupt tlvs");
85be1f1ffaSAriel Elior 			return;
86be1f1ffaSAriel Elior 		}
87be1f1ffaSAriel Elior 	}
88be1f1ffaSAriel Elior 
89be1f1ffaSAriel Elior 	/* output last tlv */
90be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
91be1f1ffaSAriel Elior 	   tlv->type, tlv->length);
92be1f1ffaSAriel Elior }
93b56e9670SAriel Elior 
94fd1fc79dSAriel Elior /* test whether we support a tlv type */
95fd1fc79dSAriel Elior bool bnx2x_tlv_supported(u16 tlvtype)
96fd1fc79dSAriel Elior {
97fd1fc79dSAriel Elior 	return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
98fd1fc79dSAriel Elior }
99fd1fc79dSAriel Elior 
100fd1fc79dSAriel Elior static inline int bnx2x_pfvf_status_codes(int rc)
101fd1fc79dSAriel Elior {
102fd1fc79dSAriel Elior 	switch (rc) {
103fd1fc79dSAriel Elior 	case 0:
104fd1fc79dSAriel Elior 		return PFVF_STATUS_SUCCESS;
105fd1fc79dSAriel Elior 	case -ENOMEM:
106fd1fc79dSAriel Elior 		return PFVF_STATUS_NO_RESOURCE;
107fd1fc79dSAriel Elior 	default:
108fd1fc79dSAriel Elior 		return PFVF_STATUS_FAILURE;
109fd1fc79dSAriel Elior 	}
110fd1fc79dSAriel Elior }
111fd1fc79dSAriel Elior 
112732ac8caSstephen hemminger static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
1136411280aSAriel Elior {
1146411280aSAriel Elior 	struct cstorm_vf_zone_data __iomem *zone_data =
1156411280aSAriel Elior 		REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
1166411280aSAriel Elior 	int tout = 600, interval = 100; /* wait for 60 seconds */
1176411280aSAriel Elior 
1186411280aSAriel Elior 	if (*done) {
1196411280aSAriel Elior 		BNX2X_ERR("done was non zero before message to pf was sent\n");
1206411280aSAriel Elior 		WARN_ON(true);
1216411280aSAriel Elior 		return -EINVAL;
1226411280aSAriel Elior 	}
1236411280aSAriel Elior 
1246411280aSAriel Elior 	/* Write message address */
1256411280aSAriel Elior 	writel(U64_LO(msg_mapping),
1266411280aSAriel Elior 	       &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
1276411280aSAriel Elior 	writel(U64_HI(msg_mapping),
1286411280aSAriel Elior 	       &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
1296411280aSAriel Elior 
1306411280aSAriel Elior 	/* make sure the address is written before FW accesses it */
1316411280aSAriel Elior 	wmb();
1326411280aSAriel Elior 
1336411280aSAriel Elior 	/* Trigger the PF FW */
1346411280aSAriel Elior 	writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
1356411280aSAriel Elior 
1366411280aSAriel Elior 	/* Wait for PF to complete */
1376411280aSAriel Elior 	while ((tout >= 0) && (!*done)) {
1386411280aSAriel Elior 		msleep(interval);
1396411280aSAriel Elior 		tout -= 1;
1406411280aSAriel Elior 
1416411280aSAriel Elior 		/* progress indicator - HV can take its own sweet time in
1426411280aSAriel Elior 		 * answering VFs...
1436411280aSAriel Elior 		 */
1446411280aSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, ".");
1456411280aSAriel Elior 	}
1466411280aSAriel Elior 
1476411280aSAriel Elior 	if (!*done) {
1486411280aSAriel Elior 		BNX2X_ERR("PF response has timed out\n");
1496411280aSAriel Elior 		return -EAGAIN;
1506411280aSAriel Elior 	}
1516411280aSAriel Elior 	DP(BNX2X_MSG_SP, "Got a response from PF\n");
1526411280aSAriel Elior 	return 0;
1536411280aSAriel Elior }
1546411280aSAriel Elior 
155732ac8caSstephen hemminger static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
1566411280aSAriel Elior {
1576411280aSAriel Elior 	u32 me_reg;
1586411280aSAriel Elior 	int tout = 10, interval = 100; /* Wait for 1 sec */
1596411280aSAriel Elior 
1606411280aSAriel Elior 	do {
1616411280aSAriel Elior 		/* pxp traps vf read of doorbells and returns me reg value */
1626411280aSAriel Elior 		me_reg = readl(bp->doorbells);
1636411280aSAriel Elior 		if (GOOD_ME_REG(me_reg))
1646411280aSAriel Elior 			break;
1656411280aSAriel Elior 
1666411280aSAriel Elior 		msleep(interval);
1676411280aSAriel Elior 
1686411280aSAriel Elior 		BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
1696411280aSAriel Elior 			  me_reg);
1706411280aSAriel Elior 	} while (tout-- > 0);
1716411280aSAriel Elior 
1726411280aSAriel Elior 	if (!GOOD_ME_REG(me_reg)) {
1736411280aSAriel Elior 		BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
1746411280aSAriel Elior 		return -EINVAL;
1756411280aSAriel Elior 	}
1766411280aSAriel Elior 
1776411280aSAriel Elior 	BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
1786411280aSAriel Elior 
1796411280aSAriel Elior 	*vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
1806411280aSAriel Elior 
1816411280aSAriel Elior 	return 0;
1826411280aSAriel Elior }
1836411280aSAriel Elior 
1846411280aSAriel Elior int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
1856411280aSAriel Elior {
1866411280aSAriel Elior 	int rc = 0, attempts = 0;
1876411280aSAriel Elior 	struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
1886411280aSAriel Elior 	struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
1896411280aSAriel Elior 	u32 vf_id;
1906411280aSAriel Elior 	bool resources_acquired = false;
1916411280aSAriel Elior 
1926411280aSAriel Elior 	/* clear mailbox and prep first tlv */
1936411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
1946411280aSAriel Elior 
1951d6f3cd8SDmitry Kravkov 	if (bnx2x_get_vf_id(bp, &vf_id)) {
1961d6f3cd8SDmitry Kravkov 		rc = -EAGAIN;
1971d6f3cd8SDmitry Kravkov 		goto out;
1981d6f3cd8SDmitry Kravkov 	}
1996411280aSAriel Elior 
2006411280aSAriel Elior 	req->vfdev_info.vf_id = vf_id;
2016411280aSAriel Elior 	req->vfdev_info.vf_os = 0;
2026411280aSAriel Elior 
2036411280aSAriel Elior 	req->resc_request.num_rxqs = rx_count;
2046411280aSAriel Elior 	req->resc_request.num_txqs = tx_count;
2056411280aSAriel Elior 	req->resc_request.num_sbs = bp->igu_sb_cnt;
2066411280aSAriel Elior 	req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
2076411280aSAriel Elior 	req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
2086411280aSAriel Elior 
2096411280aSAriel Elior 	/* pf 2 vf bulletin board address */
2106411280aSAriel Elior 	req->bulletin_addr = bp->pf2vf_bulletin_mapping;
2116411280aSAriel Elior 
2126411280aSAriel Elior 	/* add list termination tlv */
2136411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
2146411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
2156411280aSAriel Elior 
2166411280aSAriel Elior 	/* output tlvs list */
2176411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
2186411280aSAriel Elior 
2196411280aSAriel Elior 	while (!resources_acquired) {
2206411280aSAriel Elior 		DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
2216411280aSAriel Elior 
2226411280aSAriel Elior 		/* send acquire request */
2236411280aSAriel Elior 		rc = bnx2x_send_msg2pf(bp,
2246411280aSAriel Elior 				       &resp->hdr.status,
2256411280aSAriel Elior 				       bp->vf2pf_mbox_mapping);
2266411280aSAriel Elior 
2276411280aSAriel Elior 		/* PF timeout */
2286411280aSAriel Elior 		if (rc)
2291d6f3cd8SDmitry Kravkov 			goto out;
2306411280aSAriel Elior 
2316411280aSAriel Elior 		/* copy acquire response from buffer to bp */
2326411280aSAriel Elior 		memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
2336411280aSAriel Elior 
2346411280aSAriel Elior 		attempts++;
2356411280aSAriel Elior 
2366411280aSAriel Elior 		/* test whether the PF accepted our request. If not, humble the
2376411280aSAriel Elior 		 * the request and try again.
2386411280aSAriel Elior 		 */
2396411280aSAriel Elior 		if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
2406411280aSAriel Elior 			DP(BNX2X_MSG_SP, "resources acquired\n");
2416411280aSAriel Elior 			resources_acquired = true;
2426411280aSAriel Elior 		} else if (bp->acquire_resp.hdr.status ==
2436411280aSAriel Elior 			   PFVF_STATUS_NO_RESOURCE &&
2446411280aSAriel Elior 			   attempts < VF_ACQUIRE_THRESH) {
2456411280aSAriel Elior 			DP(BNX2X_MSG_SP,
2466411280aSAriel Elior 			   "PF unwilling to fulfill resource request. Try PF recommended amount\n");
2476411280aSAriel Elior 
2486411280aSAriel Elior 			/* humble our request */
2496411280aSAriel Elior 			req->resc_request.num_txqs =
2506411280aSAriel Elior 				bp->acquire_resp.resc.num_txqs;
2516411280aSAriel Elior 			req->resc_request.num_rxqs =
2526411280aSAriel Elior 				bp->acquire_resp.resc.num_rxqs;
2536411280aSAriel Elior 			req->resc_request.num_sbs =
2546411280aSAriel Elior 				bp->acquire_resp.resc.num_sbs;
2556411280aSAriel Elior 			req->resc_request.num_mac_filters =
2566411280aSAriel Elior 				bp->acquire_resp.resc.num_mac_filters;
2576411280aSAriel Elior 			req->resc_request.num_vlan_filters =
2586411280aSAriel Elior 				bp->acquire_resp.resc.num_vlan_filters;
2596411280aSAriel Elior 			req->resc_request.num_mc_filters =
2606411280aSAriel Elior 				bp->acquire_resp.resc.num_mc_filters;
2616411280aSAriel Elior 
2626411280aSAriel Elior 			/* Clear response buffer */
2636411280aSAriel Elior 			memset(&bp->vf2pf_mbox->resp, 0,
2646411280aSAriel Elior 			       sizeof(union pfvf_tlvs));
2656411280aSAriel Elior 		} else {
2666411280aSAriel Elior 			/* PF reports error */
2676411280aSAriel Elior 			BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
2686411280aSAriel Elior 				  bp->acquire_resp.hdr.status);
2691d6f3cd8SDmitry Kravkov 			rc = -EAGAIN;
2701d6f3cd8SDmitry Kravkov 			goto out;
2716411280aSAriel Elior 		}
2726411280aSAriel Elior 	}
2736411280aSAriel Elior 
2746411280aSAriel Elior 	/* get HW info */
2756411280aSAriel Elior 	bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
2766411280aSAriel Elior 	bp->link_params.chip_id = bp->common.chip_id;
2776411280aSAriel Elior 	bp->db_size = bp->acquire_resp.pfdev_info.db_size;
2786411280aSAriel Elior 	bp->common.int_block = INT_BLOCK_IGU;
2796411280aSAriel Elior 	bp->common.chip_port_mode = CHIP_2_PORT_MODE;
2806411280aSAriel Elior 	bp->igu_dsb_id = -1;
2816411280aSAriel Elior 	bp->mf_ov = 0;
2826411280aSAriel Elior 	bp->mf_mode = 0;
2836411280aSAriel Elior 	bp->common.flash_size = 0;
2846411280aSAriel Elior 	bp->flags |=
2856411280aSAriel Elior 		NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
2866411280aSAriel Elior 	bp->igu_sb_cnt = 1;
2876411280aSAriel Elior 	bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
2886411280aSAriel Elior 	strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
2896411280aSAriel Elior 		sizeof(bp->fw_ver));
2906411280aSAriel Elior 
2916411280aSAriel Elior 	if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
2926411280aSAriel Elior 		memcpy(bp->dev->dev_addr,
2936411280aSAriel Elior 		       bp->acquire_resp.resc.current_mac_addr,
2946411280aSAriel Elior 		       ETH_ALEN);
2956411280aSAriel Elior 
2961d6f3cd8SDmitry Kravkov out:
2971d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
2981d6f3cd8SDmitry Kravkov 	return rc;
2996411280aSAriel Elior }
3006411280aSAriel Elior 
3016411280aSAriel Elior int bnx2x_vfpf_release(struct bnx2x *bp)
3026411280aSAriel Elior {
3036411280aSAriel Elior 	struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
3046411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
3051d6f3cd8SDmitry Kravkov 	u32 rc, vf_id;
3066411280aSAriel Elior 
3076411280aSAriel Elior 	/* clear mailbox and prep first tlv */
3086411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
3096411280aSAriel Elior 
3101d6f3cd8SDmitry Kravkov 	if (bnx2x_get_vf_id(bp, &vf_id)) {
3111d6f3cd8SDmitry Kravkov 		rc = -EAGAIN;
3121d6f3cd8SDmitry Kravkov 		goto out;
3131d6f3cd8SDmitry Kravkov 	}
3146411280aSAriel Elior 
3156411280aSAriel Elior 	req->vf_id = vf_id;
3166411280aSAriel Elior 
3176411280aSAriel Elior 	/* add list termination tlv */
3186411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
3196411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
3206411280aSAriel Elior 
3216411280aSAriel Elior 	/* output tlvs list */
3226411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
3236411280aSAriel Elior 
3246411280aSAriel Elior 	/* send release request */
3256411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
3266411280aSAriel Elior 
3276411280aSAriel Elior 	if (rc)
3286411280aSAriel Elior 		/* PF timeout */
3291d6f3cd8SDmitry Kravkov 		goto out;
3301d6f3cd8SDmitry Kravkov 
3316411280aSAriel Elior 	if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
3326411280aSAriel Elior 		/* PF released us */
3336411280aSAriel Elior 		DP(BNX2X_MSG_SP, "vf released\n");
3346411280aSAriel Elior 	} else {
3356411280aSAriel Elior 		/* PF reports error */
3366411280aSAriel Elior 		BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
3376411280aSAriel Elior 			  resp->hdr.status);
3381d6f3cd8SDmitry Kravkov 		rc = -EAGAIN;
3391d6f3cd8SDmitry Kravkov 		goto out;
3406411280aSAriel Elior 	}
3411d6f3cd8SDmitry Kravkov out:
3421d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
3436411280aSAriel Elior 
3441d6f3cd8SDmitry Kravkov 	return rc;
3456411280aSAriel Elior }
3466411280aSAriel Elior 
3476411280aSAriel Elior /* Tell PF about SB addresses */
3486411280aSAriel Elior int bnx2x_vfpf_init(struct bnx2x *bp)
3496411280aSAriel Elior {
3506411280aSAriel Elior 	struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
3516411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
3526411280aSAriel Elior 	int rc, i;
3536411280aSAriel Elior 
3546411280aSAriel Elior 	/* clear mailbox and prep first tlv */
3556411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
3566411280aSAriel Elior 
3576411280aSAriel Elior 	/* status blocks */
3586411280aSAriel Elior 	for_each_eth_queue(bp, i)
3596411280aSAriel Elior 		req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
3606411280aSAriel Elior 						       status_blk_mapping);
3616411280aSAriel Elior 
3626411280aSAriel Elior 	/* statistics - requests only supports single queue for now */
3636411280aSAriel Elior 	req->stats_addr = bp->fw_stats_data_mapping +
3646411280aSAriel Elior 			  offsetof(struct bnx2x_fw_stats_data, queue_stats);
3656411280aSAriel Elior 
3666411280aSAriel Elior 	/* add list termination tlv */
3676411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
3686411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
3696411280aSAriel Elior 
3706411280aSAriel Elior 	/* output tlvs list */
3716411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
3726411280aSAriel Elior 
3736411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
3746411280aSAriel Elior 	if (rc)
3751d6f3cd8SDmitry Kravkov 		goto out;
3766411280aSAriel Elior 
3776411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
3786411280aSAriel Elior 		BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
3796411280aSAriel Elior 			  resp->hdr.status);
3801d6f3cd8SDmitry Kravkov 		rc = -EAGAIN;
3811d6f3cd8SDmitry Kravkov 		goto out;
3826411280aSAriel Elior 	}
3836411280aSAriel Elior 
3846411280aSAriel Elior 	DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
3851d6f3cd8SDmitry Kravkov out:
3861d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
3871d6f3cd8SDmitry Kravkov 
3881d6f3cd8SDmitry Kravkov 	return rc;
3896411280aSAriel Elior }
3906411280aSAriel Elior 
3916411280aSAriel Elior /* CLOSE VF - opposite to INIT_VF */
3926411280aSAriel Elior void bnx2x_vfpf_close_vf(struct bnx2x *bp)
3936411280aSAriel Elior {
3946411280aSAriel Elior 	struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
3956411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
3966411280aSAriel Elior 	int i, rc;
3976411280aSAriel Elior 	u32 vf_id;
3986411280aSAriel Elior 
3996411280aSAriel Elior 	/* If we haven't got a valid VF id, there is no sense to
4006411280aSAriel Elior 	 * continue with sending messages
4016411280aSAriel Elior 	 */
4026411280aSAriel Elior 	if (bnx2x_get_vf_id(bp, &vf_id))
4036411280aSAriel Elior 		goto free_irq;
4046411280aSAriel Elior 
4056411280aSAriel Elior 	/* Close the queues */
4066411280aSAriel Elior 	for_each_queue(bp, i)
4076411280aSAriel Elior 		bnx2x_vfpf_teardown_queue(bp, i);
4086411280aSAriel Elior 
4096411280aSAriel Elior 	/* clear mailbox and prep first tlv */
4106411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
4116411280aSAriel Elior 
4126411280aSAriel Elior 	req->vf_id = vf_id;
4136411280aSAriel Elior 
4146411280aSAriel Elior 	/* add list termination tlv */
4156411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
4166411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
4176411280aSAriel Elior 
4186411280aSAriel Elior 	/* output tlvs list */
4196411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
4206411280aSAriel Elior 
4216411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
4226411280aSAriel Elior 
4236411280aSAriel Elior 	if (rc)
4246411280aSAriel Elior 		BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
4256411280aSAriel Elior 
4266411280aSAriel Elior 	else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
4276411280aSAriel Elior 		BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
4286411280aSAriel Elior 			  resp->hdr.status);
4296411280aSAriel Elior 
4301d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
4311d6f3cd8SDmitry Kravkov 
4326411280aSAriel Elior free_irq:
4336411280aSAriel Elior 	/* Disable HW interrupts, NAPI */
4346411280aSAriel Elior 	bnx2x_netif_stop(bp, 0);
4356411280aSAriel Elior 	/* Delete all NAPI objects */
4366411280aSAriel Elior 	bnx2x_del_all_napi(bp);
4376411280aSAriel Elior 
4386411280aSAriel Elior 	/* Release IRQs */
4396411280aSAriel Elior 	bnx2x_free_irq(bp);
4406411280aSAriel Elior }
4416411280aSAriel Elior 
4426411280aSAriel Elior /* ask the pf to open a queue for the vf */
4436411280aSAriel Elior int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
4446411280aSAriel Elior {
4456411280aSAriel Elior 	struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
4466411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4476411280aSAriel Elior 	struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
4486411280aSAriel Elior 	u16 tpa_agg_size = 0, flags = 0;
4496411280aSAriel Elior 	int rc;
4506411280aSAriel Elior 
4516411280aSAriel Elior 	/* clear mailbox and prep first tlv */
4526411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
4536411280aSAriel Elior 
4546411280aSAriel Elior 	/* select tpa mode to request */
4556411280aSAriel Elior 	if (!fp->disable_tpa) {
4566411280aSAriel Elior 		flags |= VFPF_QUEUE_FLG_TPA;
4576411280aSAriel Elior 		flags |= VFPF_QUEUE_FLG_TPA_IPV6;
4586411280aSAriel Elior 		if (fp->mode == TPA_MODE_GRO)
4596411280aSAriel Elior 			flags |= VFPF_QUEUE_FLG_TPA_GRO;
4606411280aSAriel Elior 		tpa_agg_size = TPA_AGG_SIZE;
4616411280aSAriel Elior 	}
4626411280aSAriel Elior 
4636411280aSAriel Elior 	/* calculate queue flags */
4646411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_STATS;
4656411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
4666411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_VLAN;
4676411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
4686411280aSAriel Elior 
4696411280aSAriel Elior 	/* Common */
4706411280aSAriel Elior 	req->vf_qid = fp_idx;
4716411280aSAriel Elior 	req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
4726411280aSAriel Elior 
4736411280aSAriel Elior 	/* Rx */
4746411280aSAriel Elior 	req->rxq.rcq_addr = fp->rx_comp_mapping;
4756411280aSAriel Elior 	req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
4766411280aSAriel Elior 	req->rxq.rxq_addr = fp->rx_desc_mapping;
4776411280aSAriel Elior 	req->rxq.sge_addr = fp->rx_sge_mapping;
4786411280aSAriel Elior 	req->rxq.vf_sb = fp_idx;
4796411280aSAriel Elior 	req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
4806411280aSAriel Elior 	req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
4816411280aSAriel Elior 	req->rxq.mtu = bp->dev->mtu;
4826411280aSAriel Elior 	req->rxq.buf_sz = fp->rx_buf_size;
4836411280aSAriel Elior 	req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
4846411280aSAriel Elior 	req->rxq.tpa_agg_sz = tpa_agg_size;
4856411280aSAriel Elior 	req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
4866411280aSAriel Elior 	req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
4876411280aSAriel Elior 			  (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
4886411280aSAriel Elior 	req->rxq.flags = flags;
4896411280aSAriel Elior 	req->rxq.drop_flags = 0;
4906411280aSAriel Elior 	req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
4916411280aSAriel Elior 	req->rxq.stat_id = -1; /* No stats at the moment */
4926411280aSAriel Elior 
4936411280aSAriel Elior 	/* Tx */
4946411280aSAriel Elior 	req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
4956411280aSAriel Elior 	req->txq.vf_sb = fp_idx;
4966411280aSAriel Elior 	req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
4976411280aSAriel Elior 	req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
4986411280aSAriel Elior 	req->txq.flags = flags;
4996411280aSAriel Elior 	req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
5006411280aSAriel Elior 
5016411280aSAriel Elior 	/* add list termination tlv */
5026411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5036411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
5046411280aSAriel Elior 
5056411280aSAriel Elior 	/* output tlvs list */
5066411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
5076411280aSAriel Elior 
5086411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5096411280aSAriel Elior 	if (rc)
5106411280aSAriel Elior 		BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
5116411280aSAriel Elior 			  fp_idx);
5126411280aSAriel Elior 
5136411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
5146411280aSAriel Elior 		BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
5156411280aSAriel Elior 			  fp_idx, resp->hdr.status);
5161d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
5176411280aSAriel Elior 	}
5181d6f3cd8SDmitry Kravkov 
5191d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
5201d6f3cd8SDmitry Kravkov 
5216411280aSAriel Elior 	return rc;
5226411280aSAriel Elior }
5236411280aSAriel Elior 
5246411280aSAriel Elior int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
5256411280aSAriel Elior {
5266411280aSAriel Elior 	struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
5276411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
5286411280aSAriel Elior 	int rc;
5296411280aSAriel Elior 
5306411280aSAriel Elior 	/* clear mailbox and prep first tlv */
5316411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
5326411280aSAriel Elior 			sizeof(*req));
5336411280aSAriel Elior 
5346411280aSAriel Elior 	req->vf_qid = qidx;
5356411280aSAriel Elior 
5366411280aSAriel Elior 	/* add list termination tlv */
5376411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5386411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
5396411280aSAriel Elior 
5406411280aSAriel Elior 	/* output tlvs list */
5416411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
5426411280aSAriel Elior 
5436411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5446411280aSAriel Elior 
5456411280aSAriel Elior 	if (rc) {
5466411280aSAriel Elior 		BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
5476411280aSAriel Elior 			  rc);
5481d6f3cd8SDmitry Kravkov 		goto out;
5496411280aSAriel Elior 	}
5506411280aSAriel Elior 
5516411280aSAriel Elior 	/* PF failed the transaction */
5526411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
5536411280aSAriel Elior 		BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
5546411280aSAriel Elior 			  resp->hdr.status);
5551d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
5566411280aSAriel Elior 	}
5576411280aSAriel Elior 
5581d6f3cd8SDmitry Kravkov out:
5591d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
5601d6f3cd8SDmitry Kravkov 	return rc;
5616411280aSAriel Elior }
5626411280aSAriel Elior 
5636411280aSAriel Elior /* request pf to add a mac for the vf */
5646411280aSAriel Elior int bnx2x_vfpf_set_mac(struct bnx2x *bp)
5656411280aSAriel Elior {
5666411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
5676411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
5681d6f3cd8SDmitry Kravkov 	int rc = 0;
5696411280aSAriel Elior 
5706411280aSAriel Elior 	/* clear mailbox and prep first tlv */
5716411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
5726411280aSAriel Elior 			sizeof(*req));
5736411280aSAriel Elior 
5746411280aSAriel Elior 	req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
5756411280aSAriel Elior 	req->vf_qid = 0;
5766411280aSAriel Elior 	req->n_mac_vlan_filters = 1;
5776411280aSAriel Elior 	req->filters[0].flags =
5786411280aSAriel Elior 		VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
5796411280aSAriel Elior 
5806411280aSAriel Elior 	/* sample bulletin board for new mac */
5816411280aSAriel Elior 	bnx2x_sample_bulletin(bp);
5826411280aSAriel Elior 
5836411280aSAriel Elior 	/* copy mac from device to request */
5846411280aSAriel Elior 	memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
5856411280aSAriel Elior 
5866411280aSAriel Elior 	/* add list termination tlv */
5876411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5886411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
5896411280aSAriel Elior 
5906411280aSAriel Elior 	/* output tlvs list */
5916411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
5926411280aSAriel Elior 
5936411280aSAriel Elior 	/* send message to pf */
5946411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5956411280aSAriel Elior 	if (rc) {
5966411280aSAriel Elior 		BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
5971d6f3cd8SDmitry Kravkov 		goto out;
5986411280aSAriel Elior 	}
5996411280aSAriel Elior 
6006411280aSAriel Elior 	/* failure may mean PF was configured with a new mac for us */
6016411280aSAriel Elior 	while (resp->hdr.status == PFVF_STATUS_FAILURE) {
6026411280aSAriel Elior 		DP(BNX2X_MSG_IOV,
6036411280aSAriel Elior 		   "vfpf SET MAC failed. Check bulletin board for new posts\n");
6046411280aSAriel Elior 
6056411280aSAriel Elior 		/* check if bulletin board was updated */
6066411280aSAriel Elior 		if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
6076411280aSAriel Elior 			/* copy mac from device to request */
6086411280aSAriel Elior 			memcpy(req->filters[0].mac, bp->dev->dev_addr,
6096411280aSAriel Elior 			       ETH_ALEN);
6106411280aSAriel Elior 
6116411280aSAriel Elior 			/* send message to pf */
6126411280aSAriel Elior 			rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
6136411280aSAriel Elior 					       bp->vf2pf_mbox_mapping);
6146411280aSAriel Elior 		} else {
6156411280aSAriel Elior 			/* no new info in bulletin */
6166411280aSAriel Elior 			break;
6176411280aSAriel Elior 		}
6186411280aSAriel Elior 	}
6196411280aSAriel Elior 
6206411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
6216411280aSAriel Elior 		BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
6221d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
6236411280aSAriel Elior 	}
6241d6f3cd8SDmitry Kravkov out:
6251d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
6266411280aSAriel Elior 
6276411280aSAriel Elior 	return 0;
6286411280aSAriel Elior }
6296411280aSAriel Elior 
6306411280aSAriel Elior int bnx2x_vfpf_set_mcast(struct net_device *dev)
6316411280aSAriel Elior {
6326411280aSAriel Elior 	struct bnx2x *bp = netdev_priv(dev);
6336411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
6346411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6356411280aSAriel Elior 	int rc, i = 0;
6366411280aSAriel Elior 	struct netdev_hw_addr *ha;
6376411280aSAriel Elior 
6386411280aSAriel Elior 	if (bp->state != BNX2X_STATE_OPEN) {
6396411280aSAriel Elior 		DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
6406411280aSAriel Elior 		return -EINVAL;
6416411280aSAriel Elior 	}
6426411280aSAriel Elior 
6436411280aSAriel Elior 	/* clear mailbox and prep first tlv */
6446411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
6456411280aSAriel Elior 			sizeof(*req));
6466411280aSAriel Elior 
6476411280aSAriel Elior 	/* Get Rx mode requested */
6486411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
6496411280aSAriel Elior 
6506411280aSAriel Elior 	netdev_for_each_mc_addr(ha, dev) {
6516411280aSAriel Elior 		DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
6526411280aSAriel Elior 		   bnx2x_mc_addr(ha));
6536411280aSAriel Elior 		memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
6546411280aSAriel Elior 		i++;
6556411280aSAriel Elior 	}
6566411280aSAriel Elior 
6576411280aSAriel Elior 	/* We support four PFVF_MAX_MULTICAST_PER_VF mcast
6586411280aSAriel Elior 	  * addresses tops
6596411280aSAriel Elior 	  */
6606411280aSAriel Elior 	if (i >= PFVF_MAX_MULTICAST_PER_VF) {
6616411280aSAriel Elior 		DP(NETIF_MSG_IFUP,
6626411280aSAriel Elior 		   "VF supports not more than %d multicast MAC addresses\n",
6636411280aSAriel Elior 		   PFVF_MAX_MULTICAST_PER_VF);
6646411280aSAriel Elior 		return -EINVAL;
6656411280aSAriel Elior 	}
6666411280aSAriel Elior 
6676411280aSAriel Elior 	req->n_multicast = i;
6686411280aSAriel Elior 	req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
6696411280aSAriel Elior 	req->vf_qid = 0;
6706411280aSAriel Elior 
6716411280aSAriel Elior 	/* add list termination tlv */
6726411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
6736411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
6746411280aSAriel Elior 
6756411280aSAriel Elior 	/* output tlvs list */
6766411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
6776411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
6786411280aSAriel Elior 	if (rc) {
6796411280aSAriel Elior 		BNX2X_ERR("Sending a message failed: %d\n", rc);
6801d6f3cd8SDmitry Kravkov 		goto out;
6816411280aSAriel Elior 	}
6826411280aSAriel Elior 
6836411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
6846411280aSAriel Elior 		BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
6856411280aSAriel Elior 			  resp->hdr.status);
6861d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
6876411280aSAriel Elior 	}
6881d6f3cd8SDmitry Kravkov out:
6891d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
6906411280aSAriel Elior 
6916411280aSAriel Elior 	return 0;
6926411280aSAriel Elior }
6936411280aSAriel Elior 
6946411280aSAriel Elior int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
6956411280aSAriel Elior {
6966411280aSAriel Elior 	int mode = bp->rx_mode;
6976411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
6986411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6996411280aSAriel Elior 	int rc;
7006411280aSAriel Elior 
7016411280aSAriel Elior 	/* clear mailbox and prep first tlv */
7026411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
7036411280aSAriel Elior 			sizeof(*req));
7046411280aSAriel Elior 
7056411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
7066411280aSAriel Elior 
7076411280aSAriel Elior 	switch (mode) {
7086411280aSAriel Elior 	case BNX2X_RX_MODE_NONE: /* no Rx */
7096411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
7106411280aSAriel Elior 		break;
7116411280aSAriel Elior 	case BNX2X_RX_MODE_NORMAL:
7126411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
7136411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
7146411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
7156411280aSAriel Elior 		break;
7166411280aSAriel Elior 	case BNX2X_RX_MODE_ALLMULTI:
7176411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
7186411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
7196411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
7206411280aSAriel Elior 		break;
7216411280aSAriel Elior 	case BNX2X_RX_MODE_PROMISC:
7226411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
7236411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
7246411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
7256411280aSAriel Elior 		break;
7266411280aSAriel Elior 	default:
7276411280aSAriel Elior 		BNX2X_ERR("BAD rx mode (%d)\n", mode);
7281d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
7291d6f3cd8SDmitry Kravkov 		goto out;
7306411280aSAriel Elior 	}
7316411280aSAriel Elior 
7326411280aSAriel Elior 	req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
7336411280aSAriel Elior 	req->vf_qid = 0;
7346411280aSAriel Elior 
7356411280aSAriel Elior 	/* add list termination tlv */
7366411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
7376411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
7386411280aSAriel Elior 
7396411280aSAriel Elior 	/* output tlvs list */
7406411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
7416411280aSAriel Elior 
7426411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
7436411280aSAriel Elior 	if (rc)
7446411280aSAriel Elior 		BNX2X_ERR("Sending a message failed: %d\n", rc);
7456411280aSAriel Elior 
7466411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
7476411280aSAriel Elior 		BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
7481d6f3cd8SDmitry Kravkov 		rc = -EINVAL;
7496411280aSAriel Elior 	}
7501d6f3cd8SDmitry Kravkov out:
7511d6f3cd8SDmitry Kravkov 	bnx2x_vfpf_finalize(bp, &req->first_tlv);
7526411280aSAriel Elior 
7536411280aSAriel Elior 	return rc;
7546411280aSAriel Elior }
7556411280aSAriel Elior 
756b56e9670SAriel Elior /* General service functions */
757b56e9670SAriel Elior static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
758b56e9670SAriel Elior {
759b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
760b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
761b56e9670SAriel Elior 
762b56e9670SAriel Elior 	REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
763b56e9670SAriel Elior }
764b56e9670SAriel Elior 
765b56e9670SAriel Elior static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
766b56e9670SAriel Elior {
767b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
768b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
769b56e9670SAriel Elior 
770b56e9670SAriel Elior 	REG_WR8(bp, addr, 1);
771b56e9670SAriel Elior }
772b56e9670SAriel Elior 
773b56e9670SAriel Elior static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
774b56e9670SAriel Elior {
775b56e9670SAriel Elior 	int i;
776b56e9670SAriel Elior 
777b56e9670SAriel Elior 	for_each_vf(bp, i)
778b56e9670SAriel Elior 		storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
779b56e9670SAriel Elior }
780b56e9670SAriel Elior 
781b56e9670SAriel Elior /* enable vf_pf mailbox (aka vf-pf-chanell) */
782b56e9670SAriel Elior void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
783b56e9670SAriel Elior {
784b56e9670SAriel Elior 	bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
785b56e9670SAriel Elior 
786b56e9670SAriel Elior 	/* enable the mailbox in the FW */
787b56e9670SAriel Elior 	storm_memset_vf_mbx_ack(bp, abs_vfid);
788b56e9670SAriel Elior 	storm_memset_vf_mbx_valid(bp, abs_vfid);
789b56e9670SAriel Elior 
790b56e9670SAriel Elior 	/* enable the VF access to the mailbox */
791b56e9670SAriel Elior 	bnx2x_vf_enable_access(bp, abs_vfid);
792b56e9670SAriel Elior }
793fd1fc79dSAriel Elior 
794fd1fc79dSAriel Elior /* this works only on !E1h */
795fd1fc79dSAriel Elior static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
796fd1fc79dSAriel Elior 				dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
797fd1fc79dSAriel Elior 				u32 vf_addr_lo, u32 len32)
798fd1fc79dSAriel Elior {
799fd1fc79dSAriel Elior 	struct dmae_command dmae;
800fd1fc79dSAriel Elior 
801fd1fc79dSAriel Elior 	if (CHIP_IS_E1x(bp)) {
802fd1fc79dSAriel Elior 		BNX2X_ERR("Chip revision does not support VFs\n");
803fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
804fd1fc79dSAriel Elior 	}
805fd1fc79dSAriel Elior 
806fd1fc79dSAriel Elior 	if (!bp->dmae_ready) {
807fd1fc79dSAriel Elior 		BNX2X_ERR("DMAE is not ready, can not copy\n");
808fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
809fd1fc79dSAriel Elior 	}
810fd1fc79dSAriel Elior 
811fd1fc79dSAriel Elior 	/* set opcode and fixed command fields */
812fd1fc79dSAriel Elior 	bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
813fd1fc79dSAriel Elior 
814fd1fc79dSAriel Elior 	if (from_vf) {
815fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
816fd1fc79dSAriel Elior 			(DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
817fd1fc79dSAriel Elior 			(DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
818fd1fc79dSAriel Elior 
819fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
820fd1fc79dSAriel Elior 
821fd1fc79dSAriel Elior 		dmae.src_addr_lo = vf_addr_lo;
822fd1fc79dSAriel Elior 		dmae.src_addr_hi = vf_addr_hi;
823fd1fc79dSAriel Elior 		dmae.dst_addr_lo = U64_LO(pf_addr);
824fd1fc79dSAriel Elior 		dmae.dst_addr_hi = U64_HI(pf_addr);
825fd1fc79dSAriel Elior 	} else {
826fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
827fd1fc79dSAriel Elior 			(DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
828fd1fc79dSAriel Elior 			(DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
829fd1fc79dSAriel Elior 
830fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
831fd1fc79dSAriel Elior 
832fd1fc79dSAriel Elior 		dmae.src_addr_lo = U64_LO(pf_addr);
833fd1fc79dSAriel Elior 		dmae.src_addr_hi = U64_HI(pf_addr);
834fd1fc79dSAriel Elior 		dmae.dst_addr_lo = vf_addr_lo;
835fd1fc79dSAriel Elior 		dmae.dst_addr_hi = vf_addr_hi;
836fd1fc79dSAriel Elior 	}
837fd1fc79dSAriel Elior 	dmae.len = len32;
838fd1fc79dSAriel Elior 	bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
839fd1fc79dSAriel Elior 
840fd1fc79dSAriel Elior 	/* issue the command and wait for completion */
841fd1fc79dSAriel Elior 	return bnx2x_issue_dmae_with_comp(bp, &dmae);
842fd1fc79dSAriel Elior }
843fd1fc79dSAriel Elior 
8448ca5e17eSAriel Elior static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
8458ca5e17eSAriel Elior {
8468ca5e17eSAriel Elior 	struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
8478ca5e17eSAriel Elior 	u64 vf_addr;
8488ca5e17eSAriel Elior 	dma_addr_t pf_addr;
8498ca5e17eSAriel Elior 	u16 length, type;
8508ca5e17eSAriel Elior 	int rc;
8518ca5e17eSAriel Elior 	struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
8528ca5e17eSAriel Elior 
8538ca5e17eSAriel Elior 	/* prepare response */
8548ca5e17eSAriel Elior 	type = mbx->first_tlv.tl.type;
8558ca5e17eSAriel Elior 	length = type == CHANNEL_TLV_ACQUIRE ?
8568ca5e17eSAriel Elior 		sizeof(struct pfvf_acquire_resp_tlv) :
8578ca5e17eSAriel Elior 		sizeof(struct pfvf_general_resp_tlv);
8588ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, 0, type, length);
8598ca5e17eSAriel Elior 	resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
8608ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
8618ca5e17eSAriel Elior 		      sizeof(struct channel_list_end_tlv));
8628ca5e17eSAriel Elior 	bnx2x_dp_tlv_list(bp, resp);
8638ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
8648ca5e17eSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
8658ca5e17eSAriel Elior 
8668ca5e17eSAriel Elior 	/* send response */
8678ca5e17eSAriel Elior 	vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
8688ca5e17eSAriel Elior 		  mbx->first_tlv.resp_msg_offset;
8698ca5e17eSAriel Elior 	pf_addr = mbx->msg_mapping +
8708ca5e17eSAriel Elior 		  offsetof(struct bnx2x_vf_mbx_msg, resp);
8718ca5e17eSAriel Elior 
8728ca5e17eSAriel Elior 	/* copy the response body, if there is one, before the header, as the vf
8738ca5e17eSAriel Elior 	 * is sensitive to the header being written
8748ca5e17eSAriel Elior 	 */
8758ca5e17eSAriel Elior 	if (resp->hdr.tl.length > sizeof(u64)) {
8768ca5e17eSAriel Elior 		length = resp->hdr.tl.length - sizeof(u64);
8778ca5e17eSAriel Elior 		vf_addr += sizeof(u64);
8788ca5e17eSAriel Elior 		pf_addr += sizeof(u64);
8798ca5e17eSAriel Elior 		rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
8808ca5e17eSAriel Elior 					  U64_HI(vf_addr),
8818ca5e17eSAriel Elior 					  U64_LO(vf_addr),
8828ca5e17eSAriel Elior 					  length/4);
8838ca5e17eSAriel Elior 		if (rc) {
8848ca5e17eSAriel Elior 			BNX2X_ERR("Failed to copy response body to VF %d\n",
8858ca5e17eSAriel Elior 				  vf->abs_vfid);
886f1929b01SAriel Elior 			goto mbx_error;
8878ca5e17eSAriel Elior 		}
8888ca5e17eSAriel Elior 		vf_addr -= sizeof(u64);
8898ca5e17eSAriel Elior 		pf_addr -= sizeof(u64);
8908ca5e17eSAriel Elior 	}
8918ca5e17eSAriel Elior 
8928ca5e17eSAriel Elior 	/* ack the FW */
8938ca5e17eSAriel Elior 	storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
8948ca5e17eSAriel Elior 	mmiowb();
8958ca5e17eSAriel Elior 
8968ca5e17eSAriel Elior 	/* initiate dmae to send the response */
8978ca5e17eSAriel Elior 	mbx->flags &= ~VF_MSG_INPROCESS;
8988ca5e17eSAriel Elior 
8998ca5e17eSAriel Elior 	/* copy the response header including status-done field,
9008ca5e17eSAriel Elior 	 * must be last dmae, must be after FW is acked
9018ca5e17eSAriel Elior 	 */
9028ca5e17eSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
9038ca5e17eSAriel Elior 				  U64_HI(vf_addr),
9048ca5e17eSAriel Elior 				  U64_LO(vf_addr),
9058ca5e17eSAriel Elior 				  sizeof(u64)/4);
9068ca5e17eSAriel Elior 
9078ca5e17eSAriel Elior 	/* unlock channel mutex */
9088ca5e17eSAriel Elior 	bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
9098ca5e17eSAriel Elior 
9108ca5e17eSAriel Elior 	if (rc) {
9118ca5e17eSAriel Elior 		BNX2X_ERR("Failed to copy response status to VF %d\n",
9128ca5e17eSAriel Elior 			  vf->abs_vfid);
913f1929b01SAriel Elior 		goto mbx_error;
9148ca5e17eSAriel Elior 	}
9158ca5e17eSAriel Elior 	return;
916f1929b01SAriel Elior 
917f1929b01SAriel Elior mbx_error:
918f1929b01SAriel Elior 	bnx2x_vf_release(bp, vf, false); /* non blocking */
9198ca5e17eSAriel Elior }
9208ca5e17eSAriel Elior 
9218ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
9228ca5e17eSAriel Elior 				      struct bnx2x_vf_mbx *mbx, int vfop_status)
9238ca5e17eSAriel Elior {
9248ca5e17eSAriel Elior 	int i;
9258ca5e17eSAriel Elior 	struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
9268ca5e17eSAriel Elior 	struct pf_vf_resc *resc = &resp->resc;
9278ca5e17eSAriel Elior 	u8 status = bnx2x_pfvf_status_codes(vfop_status);
9288ca5e17eSAriel Elior 
9298ca5e17eSAriel Elior 	memset(resp, 0, sizeof(*resp));
9308ca5e17eSAriel Elior 
9318ca5e17eSAriel Elior 	/* fill in pfdev info */
9328ca5e17eSAriel Elior 	resp->pfdev_info.chip_num = bp->common.chip_id;
9338ca5e17eSAriel Elior 	resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
9348ca5e17eSAriel Elior 	resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
9358ca5e17eSAriel Elior 	resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
9368ca5e17eSAriel Elior 				   /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
9378ca5e17eSAriel Elior 	bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
9388ca5e17eSAriel Elior 			  sizeof(resp->pfdev_info.fw_ver));
9398ca5e17eSAriel Elior 
9408ca5e17eSAriel Elior 	if (status == PFVF_STATUS_NO_RESOURCE ||
9418ca5e17eSAriel Elior 	    status == PFVF_STATUS_SUCCESS) {
9428ca5e17eSAriel Elior 		/* set resources numbers, if status equals NO_RESOURCE these
9438ca5e17eSAriel Elior 		 * are max possible numbers
9448ca5e17eSAriel Elior 		 */
9458ca5e17eSAriel Elior 		resc->num_rxqs = vf_rxq_count(vf) ? :
9468ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
9478ca5e17eSAriel Elior 		resc->num_txqs = vf_txq_count(vf) ? :
9488ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
9498ca5e17eSAriel Elior 		resc->num_sbs = vf_sb_count(vf);
9508ca5e17eSAriel Elior 		resc->num_mac_filters = vf_mac_rules_cnt(vf);
9518ca5e17eSAriel Elior 		resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
9528ca5e17eSAriel Elior 		resc->num_mc_filters = 0;
9538ca5e17eSAriel Elior 
9548ca5e17eSAriel Elior 		if (status == PFVF_STATUS_SUCCESS) {
955abc5a021SAriel Elior 			/* fill in the allocated resources */
956abc5a021SAriel Elior 			struct pf_vf_bulletin_content *bulletin =
957abc5a021SAriel Elior 				BP_VF_BULLETIN(bp, vf->index);
958abc5a021SAriel Elior 
9598ca5e17eSAriel Elior 			for_each_vfq(vf, i)
9608ca5e17eSAriel Elior 				resc->hw_qid[i] =
9618ca5e17eSAriel Elior 					vfq_qzone_id(vf, vfq_get(vf, i));
9628ca5e17eSAriel Elior 
9638ca5e17eSAriel Elior 			for_each_vf_sb(vf, i) {
9648ca5e17eSAriel Elior 				resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
9658ca5e17eSAriel Elior 				resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
9668ca5e17eSAriel Elior 			}
967abc5a021SAriel Elior 
968abc5a021SAriel Elior 			/* if a mac has been set for this vf, supply it */
969abc5a021SAriel Elior 			if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
970abc5a021SAriel Elior 				memcpy(resc->current_mac_addr, bulletin->mac,
971abc5a021SAriel Elior 				       ETH_ALEN);
972abc5a021SAriel Elior 			}
9738ca5e17eSAriel Elior 		}
9748ca5e17eSAriel Elior 	}
9758ca5e17eSAriel Elior 
9768ca5e17eSAriel 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"
9778ca5e17eSAriel Elior 	   "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
9788ca5e17eSAriel Elior 	   vf->abs_vfid,
9798ca5e17eSAriel Elior 	   resp->pfdev_info.chip_num,
9808ca5e17eSAriel Elior 	   resp->pfdev_info.db_size,
9818ca5e17eSAriel Elior 	   resp->pfdev_info.indices_per_sb,
9828ca5e17eSAriel Elior 	   resp->pfdev_info.pf_cap,
9838ca5e17eSAriel Elior 	   resc->num_rxqs,
9848ca5e17eSAriel Elior 	   resc->num_txqs,
9858ca5e17eSAriel Elior 	   resc->num_sbs,
9868ca5e17eSAriel Elior 	   resc->num_mac_filters,
9878ca5e17eSAriel Elior 	   resc->num_vlan_filters,
9888ca5e17eSAriel Elior 	   resc->num_mc_filters,
9898ca5e17eSAriel Elior 	   resp->pfdev_info.fw_ver);
9908ca5e17eSAriel Elior 
9918ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
9928ca5e17eSAriel Elior 	for (i = 0; i < vf_rxq_count(vf); i++)
9938ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
9948ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
9958ca5e17eSAriel Elior 	for (i = 0; i < vf_sb_count(vf); i++)
9968ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
9978ca5e17eSAriel Elior 			resc->hw_sbs[i].hw_sb_id,
9988ca5e17eSAriel Elior 			resc->hw_sbs[i].sb_qid);
9998ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "]\n");
10008ca5e17eSAriel Elior 
10018ca5e17eSAriel Elior 	/* send the response */
10028ca5e17eSAriel Elior 	vf->op_rc = vfop_status;
10038ca5e17eSAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
10048ca5e17eSAriel Elior }
10058ca5e17eSAriel Elior 
10068ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
10078ca5e17eSAriel Elior 				 struct bnx2x_vf_mbx *mbx)
10088ca5e17eSAriel Elior {
10098ca5e17eSAriel Elior 	int rc;
10108ca5e17eSAriel Elior 	struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
10118ca5e17eSAriel Elior 
10128ca5e17eSAriel Elior 	/* log vfdef info */
10138ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV,
10148ca5e17eSAriel 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",
10158ca5e17eSAriel Elior 	   vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
10168ca5e17eSAriel Elior 	   acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
10178ca5e17eSAriel Elior 	   acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
10188ca5e17eSAriel Elior 	   acquire->resc_request.num_vlan_filters,
10198ca5e17eSAriel Elior 	   acquire->resc_request.num_mc_filters);
10208ca5e17eSAriel Elior 
10218ca5e17eSAriel Elior 	/* acquire the resources */
10228ca5e17eSAriel Elior 	rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
10238ca5e17eSAriel Elior 
1024abc5a021SAriel Elior 	/* store address of vf's bulletin board */
1025abc5a021SAriel Elior 	vf->bulletin_map = acquire->bulletin_addr;
1026abc5a021SAriel Elior 
10278ca5e17eSAriel Elior 	/* response */
10288ca5e17eSAriel Elior 	bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
10298ca5e17eSAriel Elior }
10308ca5e17eSAriel Elior 
1031b93288d5SAriel Elior static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1032b93288d5SAriel Elior 			      struct bnx2x_vf_mbx *mbx)
1033b93288d5SAriel Elior {
1034b93288d5SAriel Elior 	struct vfpf_init_tlv *init = &mbx->msg->req.init;
1035b93288d5SAriel Elior 
1036b93288d5SAriel Elior 	/* record ghost addresses from vf message */
1037b93288d5SAriel Elior 	vf->spq_map = init->spq_addr;
1038b93288d5SAriel Elior 	vf->fw_stat_map = init->stats_addr;
1039b93288d5SAriel Elior 	vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1040b93288d5SAriel Elior 
1041b93288d5SAriel Elior 	/* response */
1042b93288d5SAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
1043b93288d5SAriel Elior }
1044b93288d5SAriel Elior 
10458db573baSAriel Elior /* convert MBX queue-flags to standard SP queue-flags */
104621776537SAriel Elior static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
10478db573baSAriel Elior 				     unsigned long *sp_q_flags)
10488db573baSAriel Elior {
10498db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
10508db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
10518db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
10528db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
10538db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
10548db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
10558db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
10568db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
10578db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
10588db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
10598db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
10608db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
10618db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
10628db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
10638db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
10648db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
106521776537SAriel Elior 
106621776537SAriel Elior 	/* outer vlan removal is set according to the PF's multi fuction mode */
106721776537SAriel Elior 	if (IS_MF_SD(bp))
106821776537SAriel Elior 		__set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
10698db573baSAriel Elior }
10708db573baSAriel Elior 
10718db573baSAriel Elior static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
10728db573baSAriel Elior 				 struct bnx2x_vf_mbx *mbx)
10738db573baSAriel Elior {
10748db573baSAriel Elior 	struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
10758db573baSAriel Elior 	struct bnx2x_vfop_cmd cmd = {
10768db573baSAriel Elior 		.done = bnx2x_vf_mbx_resp,
10778db573baSAriel Elior 		.block = false,
10788db573baSAriel Elior 	};
10798db573baSAriel Elior 
10808db573baSAriel Elior 	/* verify vf_qid */
10818db573baSAriel Elior 	if (setup_q->vf_qid >= vf_rxq_count(vf)) {
10828db573baSAriel Elior 		BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
10838db573baSAriel Elior 			  setup_q->vf_qid, vf_rxq_count(vf));
10848db573baSAriel Elior 		vf->op_rc = -EINVAL;
10858db573baSAriel Elior 		goto response;
10868db573baSAriel Elior 	}
10878db573baSAriel Elior 
10888db573baSAriel Elior 	/* tx queues must be setup alongside rx queues thus if the rx queue
10898db573baSAriel Elior 	 * is not marked as valid there's nothing to do.
10908db573baSAriel Elior 	 */
10918db573baSAriel Elior 	if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
10928db573baSAriel Elior 		struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
10938db573baSAriel Elior 		unsigned long q_type = 0;
10948db573baSAriel Elior 
10958db573baSAriel Elior 		struct bnx2x_queue_init_params *init_p;
10968db573baSAriel Elior 		struct bnx2x_queue_setup_params *setup_p;
10978db573baSAriel Elior 
10988db573baSAriel Elior 		/* reinit the VF operation context */
10998db573baSAriel Elior 		memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
11008db573baSAriel Elior 		setup_p = &vf->op_params.qctor.prep_qsetup;
11018db573baSAriel Elior 		init_p =  &vf->op_params.qctor.qstate.params.init;
11028db573baSAriel Elior 
11038db573baSAriel Elior 		/* activate immediately */
11048db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
11058db573baSAriel Elior 
11068db573baSAriel Elior 		if (setup_q->param_valid & VFPF_TXQ_VALID) {
11078db573baSAriel Elior 			struct bnx2x_txq_setup_params *txq_params =
11088db573baSAriel Elior 				&setup_p->txq_params;
11098db573baSAriel Elior 
11108db573baSAriel Elior 			__set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
11118db573baSAriel Elior 
11128db573baSAriel Elior 			/* save sb resource index */
11138db573baSAriel Elior 			q->sb_idx = setup_q->txq.vf_sb;
11148db573baSAriel Elior 
11158db573baSAriel Elior 			/* tx init */
11168db573baSAriel Elior 			init_p->tx.hc_rate = setup_q->txq.hc_rate;
11178db573baSAriel Elior 			init_p->tx.sb_cq_index = setup_q->txq.sb_index;
11188db573baSAriel Elior 
111921776537SAriel Elior 			bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
11208db573baSAriel Elior 						 &init_p->tx.flags);
11218db573baSAriel Elior 
11228db573baSAriel Elior 			/* tx setup - flags */
112321776537SAriel Elior 			bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
11248db573baSAriel Elior 						 &setup_p->flags);
11258db573baSAriel Elior 
11268db573baSAriel Elior 			/* tx setup - general, nothing */
11278db573baSAriel Elior 
11288db573baSAriel Elior 			/* tx setup - tx */
11298db573baSAriel Elior 			txq_params->dscr_map = setup_q->txq.txq_addr;
11308db573baSAriel Elior 			txq_params->sb_cq_index = setup_q->txq.sb_index;
11318db573baSAriel Elior 			txq_params->traffic_type = setup_q->txq.traffic_type;
11328db573baSAriel Elior 
11338db573baSAriel Elior 			bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
11348db573baSAriel Elior 						 q->index, q->sb_idx);
11358db573baSAriel Elior 		}
11368db573baSAriel Elior 
11378db573baSAriel Elior 		if (setup_q->param_valid & VFPF_RXQ_VALID) {
11388db573baSAriel Elior 			struct bnx2x_rxq_setup_params *rxq_params =
11398db573baSAriel Elior 							&setup_p->rxq_params;
11408db573baSAriel Elior 
11418db573baSAriel Elior 			__set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
11428db573baSAriel Elior 
11438db573baSAriel Elior 			/* Note: there is no support for different SBs
11448db573baSAriel Elior 			 * for TX and RX
11458db573baSAriel Elior 			 */
11468db573baSAriel Elior 			q->sb_idx = setup_q->rxq.vf_sb;
11478db573baSAriel Elior 
11488db573baSAriel Elior 			/* rx init */
11498db573baSAriel Elior 			init_p->rx.hc_rate = setup_q->rxq.hc_rate;
11508db573baSAriel Elior 			init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
115121776537SAriel Elior 			bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
11528db573baSAriel Elior 						 &init_p->rx.flags);
11538db573baSAriel Elior 
11548db573baSAriel Elior 			/* rx setup - flags */
115521776537SAriel Elior 			bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
11568db573baSAriel Elior 						 &setup_p->flags);
11578db573baSAriel Elior 
11588db573baSAriel Elior 			/* rx setup - general */
11598db573baSAriel Elior 			setup_p->gen_params.mtu = setup_q->rxq.mtu;
11608db573baSAriel Elior 
11618db573baSAriel Elior 			/* rx setup - rx */
11628db573baSAriel Elior 			rxq_params->drop_flags = setup_q->rxq.drop_flags;
11638db573baSAriel Elior 			rxq_params->dscr_map = setup_q->rxq.rxq_addr;
11648db573baSAriel Elior 			rxq_params->sge_map = setup_q->rxq.sge_addr;
11658db573baSAriel Elior 			rxq_params->rcq_map = setup_q->rxq.rcq_addr;
11668db573baSAriel Elior 			rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
11678db573baSAriel Elior 			rxq_params->buf_sz = setup_q->rxq.buf_sz;
11688db573baSAriel Elior 			rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
11698db573baSAriel Elior 			rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
11708db573baSAriel Elior 			rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
11718db573baSAriel Elior 			rxq_params->cache_line_log =
11728db573baSAriel Elior 				setup_q->rxq.cache_line_log;
11738db573baSAriel Elior 			rxq_params->sb_cq_index = setup_q->rxq.sb_index;
11748db573baSAriel Elior 
11758db573baSAriel Elior 			bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
11768db573baSAriel Elior 						 q->index, q->sb_idx);
11778db573baSAriel Elior 		}
11788db573baSAriel Elior 		/* complete the preparations */
11798db573baSAriel Elior 		bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
11808db573baSAriel Elior 
11818db573baSAriel Elior 		vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
11828db573baSAriel Elior 		if (vf->op_rc)
11838db573baSAriel Elior 			goto response;
11848db573baSAriel Elior 		return;
11858db573baSAriel Elior 	}
11868db573baSAriel Elior response:
11878db573baSAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
11888db573baSAriel Elior }
11898db573baSAriel Elior 
1190954ea748SAriel Elior enum bnx2x_vfop_filters_state {
1191954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1192954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1193954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1194954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1195954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_DONE
1196954ea748SAriel Elior };
1197954ea748SAriel Elior 
1198954ea748SAriel Elior static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1199954ea748SAriel Elior 				     struct bnx2x_virtf *vf,
1200954ea748SAriel Elior 				     struct vfpf_set_q_filters_tlv *tlv,
1201954ea748SAriel Elior 				     struct bnx2x_vfop_filters **pfl,
1202954ea748SAriel Elior 				     u32 type_flag)
1203954ea748SAriel Elior {
1204954ea748SAriel Elior 	int i, j;
1205954ea748SAriel Elior 	struct bnx2x_vfop_filters *fl = NULL;
1206954ea748SAriel Elior 	size_t fsz;
1207954ea748SAriel Elior 
1208954ea748SAriel Elior 	fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1209954ea748SAriel Elior 		sizeof(struct bnx2x_vfop_filters);
1210954ea748SAriel Elior 
1211954ea748SAriel Elior 	fl = kzalloc(fsz, GFP_KERNEL);
1212954ea748SAriel Elior 	if (!fl)
1213954ea748SAriel Elior 		return -ENOMEM;
1214954ea748SAriel Elior 
1215954ea748SAriel Elior 	INIT_LIST_HEAD(&fl->head);
1216954ea748SAriel Elior 
1217954ea748SAriel Elior 	for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1218954ea748SAriel Elior 		struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1219954ea748SAriel Elior 
1220954ea748SAriel Elior 		if ((msg_filter->flags & type_flag) != type_flag)
1221954ea748SAriel Elior 			continue;
1222954ea748SAriel Elior 		if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1223954ea748SAriel Elior 			fl->filters[j].mac = msg_filter->mac;
1224954ea748SAriel Elior 			fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1225954ea748SAriel Elior 		} else {
1226954ea748SAriel Elior 			fl->filters[j].vid = msg_filter->vlan_tag;
1227954ea748SAriel Elior 			fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1228954ea748SAriel Elior 		}
1229954ea748SAriel Elior 		fl->filters[j].add =
1230954ea748SAriel Elior 			(msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1231954ea748SAriel Elior 			true : false;
1232954ea748SAriel Elior 		list_add_tail(&fl->filters[j++].link, &fl->head);
1233954ea748SAriel Elior 	}
1234954ea748SAriel Elior 	if (list_empty(&fl->head))
1235954ea748SAriel Elior 		kfree(fl);
1236954ea748SAriel Elior 	else
1237954ea748SAriel Elior 		*pfl = fl;
1238954ea748SAriel Elior 
1239954ea748SAriel Elior 	return 0;
1240954ea748SAriel Elior }
1241954ea748SAriel Elior 
1242954ea748SAriel Elior static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1243954ea748SAriel Elior 				       struct vfpf_q_mac_vlan_filter *filter)
1244954ea748SAriel Elior {
1245954ea748SAriel Elior 	DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1246954ea748SAriel Elior 	if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1247954ea748SAriel Elior 		DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1248954ea748SAriel Elior 	if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1249954ea748SAriel Elior 		DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1250954ea748SAriel Elior 	DP_CONT(msglvl, "\n");
1251954ea748SAriel Elior }
1252954ea748SAriel Elior 
1253954ea748SAriel Elior static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1254954ea748SAriel Elior 				       struct vfpf_set_q_filters_tlv *filters)
1255954ea748SAriel Elior {
1256954ea748SAriel Elior 	int i;
1257954ea748SAriel Elior 
1258954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1259954ea748SAriel Elior 		for (i = 0; i < filters->n_mac_vlan_filters; i++)
1260954ea748SAriel Elior 			bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1261954ea748SAriel Elior 						 &filters->filters[i]);
1262954ea748SAriel Elior 
1263954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1264954ea748SAriel Elior 		DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1265954ea748SAriel Elior 
1266954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1267954ea748SAriel Elior 		for (i = 0; i < filters->n_multicast; i++)
1268954ea748SAriel Elior 			DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1269954ea748SAriel Elior }
1270954ea748SAriel Elior 
1271954ea748SAriel Elior #define VFPF_MAC_FILTER		VFPF_Q_FILTER_DEST_MAC_VALID
1272954ea748SAriel Elior #define VFPF_VLAN_FILTER	VFPF_Q_FILTER_VLAN_TAG_VALID
1273954ea748SAriel Elior 
1274954ea748SAriel Elior static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1275954ea748SAriel Elior {
1276954ea748SAriel Elior 	int rc;
1277954ea748SAriel Elior 
1278954ea748SAriel Elior 	struct vfpf_set_q_filters_tlv *msg =
1279954ea748SAriel Elior 		&BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1280954ea748SAriel Elior 
1281954ea748SAriel Elior 	struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1282954ea748SAriel Elior 	enum bnx2x_vfop_filters_state state = vfop->state;
1283954ea748SAriel Elior 
1284954ea748SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1285954ea748SAriel Elior 		.done = bnx2x_vfop_mbx_qfilters,
1286954ea748SAriel Elior 		.block = false,
1287954ea748SAriel Elior 	};
1288954ea748SAriel Elior 
1289954ea748SAriel Elior 	DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1290954ea748SAriel Elior 
1291954ea748SAriel Elior 	if (vfop->rc < 0)
1292954ea748SAriel Elior 		goto op_err;
1293954ea748SAriel Elior 
1294954ea748SAriel Elior 	switch (state) {
1295954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1296954ea748SAriel Elior 		/* next state */
1297954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1298954ea748SAriel Elior 
1299954ea748SAriel Elior 		/* check for any vlan/mac changes */
1300954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1301954ea748SAriel Elior 			/* build mac list */
1302954ea748SAriel Elior 			struct bnx2x_vfop_filters *fl = NULL;
1303954ea748SAriel Elior 
1304954ea748SAriel Elior 			vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1305954ea748SAriel Elior 							     VFPF_MAC_FILTER);
1306954ea748SAriel Elior 			if (vfop->rc)
1307954ea748SAriel Elior 				goto op_err;
1308954ea748SAriel Elior 
1309954ea748SAriel Elior 			if (fl) {
1310954ea748SAriel Elior 				/* set mac list */
1311954ea748SAriel Elior 				rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1312954ea748SAriel Elior 							     msg->vf_qid,
1313954ea748SAriel Elior 							     false);
1314954ea748SAriel Elior 				if (rc) {
1315954ea748SAriel Elior 					vfop->rc = rc;
1316954ea748SAriel Elior 					goto op_err;
1317954ea748SAriel Elior 				}
1318954ea748SAriel Elior 				return;
1319954ea748SAriel Elior 			}
1320954ea748SAriel Elior 		}
1321954ea748SAriel Elior 		/* fall through */
1322954ea748SAriel Elior 
1323954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1324954ea748SAriel Elior 		/* next state */
1325954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1326954ea748SAriel Elior 
1327954ea748SAriel Elior 		/* check for any vlan/mac changes */
1328954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1329954ea748SAriel Elior 			/* build vlan list */
1330954ea748SAriel Elior 			struct bnx2x_vfop_filters *fl = NULL;
1331954ea748SAriel Elior 
1332954ea748SAriel Elior 			vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1333954ea748SAriel Elior 							     VFPF_VLAN_FILTER);
1334954ea748SAriel Elior 			if (vfop->rc)
1335954ea748SAriel Elior 				goto op_err;
1336954ea748SAriel Elior 
1337954ea748SAriel Elior 			if (fl) {
1338954ea748SAriel Elior 				/* set vlan list */
1339954ea748SAriel Elior 				rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1340954ea748SAriel Elior 							      msg->vf_qid,
1341954ea748SAriel Elior 							      false);
1342954ea748SAriel Elior 				if (rc) {
1343954ea748SAriel Elior 					vfop->rc = rc;
1344954ea748SAriel Elior 					goto op_err;
1345954ea748SAriel Elior 				}
1346954ea748SAriel Elior 				return;
1347954ea748SAriel Elior 			}
1348954ea748SAriel Elior 		}
1349954ea748SAriel Elior 		/* fall through */
1350954ea748SAriel Elior 
1351954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1352954ea748SAriel Elior 		/* next state */
1353954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1354954ea748SAriel Elior 
1355954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1356954ea748SAriel Elior 			unsigned long accept = 0;
1357954ea748SAriel Elior 
1358954ea748SAriel Elior 			/* covert VF-PF if mask to bnx2x accept flags */
1359954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1360954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1361954ea748SAriel Elior 
1362954ea748SAriel Elior 			if (msg->rx_mask &
1363954ea748SAriel Elior 					VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1364954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1365954ea748SAriel Elior 
1366954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1367954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1368954ea748SAriel Elior 
1369954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1370954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1371954ea748SAriel Elior 
1372954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1373954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1374954ea748SAriel Elior 
1375954ea748SAriel Elior 			/* A packet arriving the vf's mac should be accepted
1376954ea748SAriel Elior 			 * with any vlan
1377954ea748SAriel Elior 			 */
1378954ea748SAriel Elior 			__set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1379954ea748SAriel Elior 
1380954ea748SAriel Elior 			/* set rx-mode */
1381954ea748SAriel Elior 			rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1382954ea748SAriel Elior 						   msg->vf_qid, accept);
1383954ea748SAriel Elior 			if (rc) {
1384954ea748SAriel Elior 				vfop->rc = rc;
1385954ea748SAriel Elior 				goto op_err;
1386954ea748SAriel Elior 			}
1387954ea748SAriel Elior 			return;
1388954ea748SAriel Elior 		}
1389954ea748SAriel Elior 		/* fall through */
1390954ea748SAriel Elior 
1391954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1392954ea748SAriel Elior 		/* next state */
1393954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1394954ea748SAriel Elior 
1395954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1396954ea748SAriel Elior 			/* set mcasts */
1397954ea748SAriel Elior 			rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1398954ea748SAriel Elior 						  msg->n_multicast, false);
1399954ea748SAriel Elior 			if (rc) {
1400954ea748SAriel Elior 				vfop->rc = rc;
1401954ea748SAriel Elior 				goto op_err;
1402954ea748SAriel Elior 			}
1403954ea748SAriel Elior 			return;
1404954ea748SAriel Elior 		}
1405954ea748SAriel Elior 		/* fall through */
1406954ea748SAriel Elior op_done:
1407954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1408954ea748SAriel Elior 		bnx2x_vfop_end(bp, vf, vfop);
1409954ea748SAriel Elior 		return;
1410954ea748SAriel Elior op_err:
1411954ea748SAriel Elior 	BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1412954ea748SAriel Elior 		  vf->abs_vfid, msg->vf_qid, vfop->rc);
1413954ea748SAriel Elior 	goto op_done;
1414954ea748SAriel Elior 
1415954ea748SAriel Elior 	default:
1416954ea748SAriel Elior 		bnx2x_vfop_default(state);
1417954ea748SAriel Elior 	}
1418954ea748SAriel Elior }
1419954ea748SAriel Elior 
1420954ea748SAriel Elior static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1421954ea748SAriel Elior 					struct bnx2x_virtf *vf,
1422954ea748SAriel Elior 					struct bnx2x_vfop_cmd *cmd)
1423954ea748SAriel Elior {
1424954ea748SAriel Elior 	struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1425954ea748SAriel Elior 	if (vfop) {
1426954ea748SAriel Elior 		bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1427954ea748SAriel Elior 				 bnx2x_vfop_mbx_qfilters, cmd->done);
1428954ea748SAriel Elior 		return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1429954ea748SAriel Elior 					     cmd->block);
1430954ea748SAriel Elior 	}
1431954ea748SAriel Elior 	return -ENOMEM;
1432954ea748SAriel Elior }
1433954ea748SAriel Elior 
1434954ea748SAriel Elior static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1435954ea748SAriel Elior 				       struct bnx2x_virtf *vf,
1436954ea748SAriel Elior 				       struct bnx2x_vf_mbx *mbx)
1437954ea748SAriel Elior {
1438954ea748SAriel Elior 	struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1439abc5a021SAriel Elior 	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1440954ea748SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1441954ea748SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1442954ea748SAriel Elior 		.block = false,
1443954ea748SAriel Elior 	};
1444954ea748SAriel Elior 
1445abc5a021SAriel Elior 	/* if a mac was already set for this VF via the set vf mac ndo, we only
1446abc5a021SAriel Elior 	 * accept mac configurations of that mac. Why accept them at all?
1447abc5a021SAriel Elior 	 * because PF may have been unable to configure the mac at the time
1448abc5a021SAriel Elior 	 * since queue was not set up.
1449abc5a021SAriel Elior 	 */
1450abc5a021SAriel Elior 	if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1451abc5a021SAriel Elior 		/* once a mac was set by ndo can only accept a single mac... */
1452abc5a021SAriel Elior 		if (filters->n_mac_vlan_filters > 1) {
1453abc5a021SAriel Elior 			BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1454abc5a021SAriel Elior 				  vf->abs_vfid);
1455abc5a021SAriel Elior 			vf->op_rc = -EPERM;
1456abc5a021SAriel Elior 			goto response;
1457abc5a021SAriel Elior 		}
1458abc5a021SAriel Elior 
1459abc5a021SAriel Elior 		/* ...and only the mac set by the ndo */
1460abc5a021SAriel Elior 		if (filters->n_mac_vlan_filters == 1 &&
1461abc5a021SAriel Elior 		    memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1462abc5a021SAriel Elior 			BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1463abc5a021SAriel Elior 				  vf->abs_vfid);
1464abc5a021SAriel Elior 
1465abc5a021SAriel Elior 			vf->op_rc = -EPERM;
1466abc5a021SAriel Elior 			goto response;
1467abc5a021SAriel Elior 		}
1468abc5a021SAriel Elior 	}
1469abc5a021SAriel Elior 
1470954ea748SAriel Elior 	/* verify vf_qid */
1471954ea748SAriel Elior 	if (filters->vf_qid > vf_rxq_count(vf))
1472954ea748SAriel Elior 		goto response;
1473954ea748SAriel Elior 
1474954ea748SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1475954ea748SAriel Elior 	   vf->abs_vfid,
1476954ea748SAriel Elior 	   filters->vf_qid);
1477954ea748SAriel Elior 
1478954ea748SAriel Elior 	/* print q_filter message */
1479954ea748SAriel Elior 	bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1480954ea748SAriel Elior 
1481954ea748SAriel Elior 	vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1482954ea748SAriel Elior 	if (vf->op_rc)
1483954ea748SAriel Elior 		goto response;
1484954ea748SAriel Elior 	return;
1485954ea748SAriel Elior 
1486954ea748SAriel Elior response:
1487954ea748SAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
1488954ea748SAriel Elior }
1489954ea748SAriel Elior 
1490463a68a7SAriel Elior static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1491463a68a7SAriel Elior 				    struct bnx2x_vf_mbx *mbx)
1492463a68a7SAriel Elior {
1493463a68a7SAriel Elior 	int qid = mbx->msg->req.q_op.vf_qid;
1494463a68a7SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1495463a68a7SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1496463a68a7SAriel Elior 		.block = false,
1497463a68a7SAriel Elior 	};
1498463a68a7SAriel Elior 
1499463a68a7SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1500463a68a7SAriel Elior 	   vf->abs_vfid, qid);
1501463a68a7SAriel Elior 
1502463a68a7SAriel Elior 	vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1503463a68a7SAriel Elior 	if (vf->op_rc)
1504463a68a7SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
1505463a68a7SAriel Elior }
1506463a68a7SAriel Elior 
150799e9d211SAriel Elior static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
150899e9d211SAriel Elior 				  struct bnx2x_vf_mbx *mbx)
150999e9d211SAriel Elior {
151099e9d211SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
151199e9d211SAriel Elior 		.done = bnx2x_vf_mbx_resp,
151299e9d211SAriel Elior 		.block = false,
151399e9d211SAriel Elior 	};
151499e9d211SAriel Elior 
151599e9d211SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
151699e9d211SAriel Elior 
151799e9d211SAriel Elior 	vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
151899e9d211SAriel Elior 	if (vf->op_rc)
151999e9d211SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
152099e9d211SAriel Elior }
152199e9d211SAriel Elior 
1522f1929b01SAriel Elior static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1523f1929b01SAriel Elior 				    struct bnx2x_vf_mbx *mbx)
1524f1929b01SAriel Elior {
1525f1929b01SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1526f1929b01SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1527f1929b01SAriel Elior 		.block = false,
1528f1929b01SAriel Elior 	};
1529f1929b01SAriel Elior 
1530f1929b01SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1531f1929b01SAriel Elior 
1532f1929b01SAriel Elior 	vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1533f1929b01SAriel Elior 	if (vf->op_rc)
1534f1929b01SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
1535f1929b01SAriel Elior }
1536f1929b01SAriel Elior 
1537fd1fc79dSAriel Elior /* dispatch request */
1538fd1fc79dSAriel Elior static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1539fd1fc79dSAriel Elior 				  struct bnx2x_vf_mbx *mbx)
1540fd1fc79dSAriel Elior {
1541fd1fc79dSAriel Elior 	int i;
1542fd1fc79dSAriel Elior 
1543fd1fc79dSAriel Elior 	/* check if tlv type is known */
1544fd1fc79dSAriel Elior 	if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
15458ca5e17eSAriel Elior 		/* Lock the per vf op mutex and note the locker's identity.
15468ca5e17eSAriel Elior 		 * The unlock will take place in mbx response.
15478ca5e17eSAriel Elior 		 */
15488ca5e17eSAriel Elior 		bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
15498ca5e17eSAriel Elior 
1550fd1fc79dSAriel Elior 		/* switch on the opcode */
1551fd1fc79dSAriel Elior 		switch (mbx->first_tlv.tl.type) {
15528ca5e17eSAriel Elior 		case CHANNEL_TLV_ACQUIRE:
15538ca5e17eSAriel Elior 			bnx2x_vf_mbx_acquire(bp, vf, mbx);
15548ca5e17eSAriel Elior 			break;
1555b93288d5SAriel Elior 		case CHANNEL_TLV_INIT:
1556b93288d5SAriel Elior 			bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1557b93288d5SAriel Elior 			break;
15588db573baSAriel Elior 		case CHANNEL_TLV_SETUP_Q:
15598db573baSAriel Elior 			bnx2x_vf_mbx_setup_q(bp, vf, mbx);
15608db573baSAriel Elior 			break;
1561954ea748SAriel Elior 		case CHANNEL_TLV_SET_Q_FILTERS:
1562954ea748SAriel Elior 			bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1563954ea748SAriel Elior 			break;
1564463a68a7SAriel Elior 		case CHANNEL_TLV_TEARDOWN_Q:
1565463a68a7SAriel Elior 			bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1566463a68a7SAriel Elior 			break;
156799e9d211SAriel Elior 		case CHANNEL_TLV_CLOSE:
156899e9d211SAriel Elior 			bnx2x_vf_mbx_close_vf(bp, vf, mbx);
156999e9d211SAriel Elior 			break;
1570f1929b01SAriel Elior 		case CHANNEL_TLV_RELEASE:
1571f1929b01SAriel Elior 			bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1572f1929b01SAriel Elior 			break;
1573fd1fc79dSAriel Elior 		}
1574463a68a7SAriel Elior 
1575fd1fc79dSAriel Elior 	} else {
1576fd1fc79dSAriel Elior 		/* unknown TLV - this may belong to a VF driver from the future
1577fd1fc79dSAriel Elior 		 * - a version written after this PF driver was written, which
1578fd1fc79dSAriel Elior 		 * supports features unknown as of yet. Too bad since we don't
1579fd1fc79dSAriel Elior 		 * support them. Or this may be because someone wrote a crappy
1580fd1fc79dSAriel Elior 		 * VF driver and is sending garbage over the channel.
1581fd1fc79dSAriel Elior 		 */
1582fd1fc79dSAriel Elior 		BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
1583fd1fc79dSAriel Elior 			  mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
1584fd1fc79dSAriel Elior 		for (i = 0; i < 20; i++)
1585fd1fc79dSAriel Elior 			DP_CONT(BNX2X_MSG_IOV, "%x ",
1586fd1fc79dSAriel Elior 				mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
15878ca5e17eSAriel Elior 
15888ca5e17eSAriel Elior 		/* test whether we can respond to the VF (do we have an address
15898ca5e17eSAriel Elior 		 * for it?)
15908ca5e17eSAriel Elior 		 */
15918ca5e17eSAriel Elior 		if (vf->state == VF_ACQUIRED) {
15928ca5e17eSAriel Elior 			/* mbx_resp uses the op_rc of the VF */
15938ca5e17eSAriel Elior 			vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
15948ca5e17eSAriel Elior 
15958ca5e17eSAriel Elior 			/* notify the VF that we do not support this request */
15968ca5e17eSAriel Elior 			bnx2x_vf_mbx_resp(bp, vf);
15978ca5e17eSAriel Elior 		} else {
15988ca5e17eSAriel Elior 			/* can't send a response since this VF is unknown to us
15998ca5e17eSAriel Elior 			 * just unlock the channel and be done with.
16008ca5e17eSAriel Elior 			 */
16018ca5e17eSAriel Elior 			bnx2x_unlock_vf_pf_channel(bp, vf,
16028ca5e17eSAriel Elior 						   mbx->first_tlv.tl.type);
16038ca5e17eSAriel Elior 		}
1604fd1fc79dSAriel Elior 	}
1605fd1fc79dSAriel Elior }
1606fd1fc79dSAriel Elior 
1607fd1fc79dSAriel Elior /* handle new vf-pf message */
1608fd1fc79dSAriel Elior void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1609fd1fc79dSAriel Elior {
1610fd1fc79dSAriel Elior 	struct bnx2x_virtf *vf;
1611fd1fc79dSAriel Elior 	struct bnx2x_vf_mbx *mbx;
1612fd1fc79dSAriel Elior 	u8 vf_idx;
1613fd1fc79dSAriel Elior 	int rc;
1614fd1fc79dSAriel Elior 
1615fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV,
1616fd1fc79dSAriel Elior 	   "vf pf event received: vfid %d, address_hi %x, address lo %x",
1617fd1fc79dSAriel Elior 	   vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1618fd1fc79dSAriel Elior 	/* Sanity checks consider removing later */
1619fd1fc79dSAriel Elior 
1620fd1fc79dSAriel Elior 	/* check if the vf_id is valid */
1621fd1fc79dSAriel Elior 	if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1622fd1fc79dSAriel Elior 	    BNX2X_NR_VIRTFN(bp)) {
1623fd1fc79dSAriel Elior 		BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1624fd1fc79dSAriel Elior 			  vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1625fd1fc79dSAriel Elior 		goto mbx_done;
1626fd1fc79dSAriel Elior 	}
1627fd1fc79dSAriel Elior 	vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1628fd1fc79dSAriel Elior 	mbx = BP_VF_MBX(bp, vf_idx);
1629fd1fc79dSAriel Elior 
1630fd1fc79dSAriel Elior 	/* verify an event is not currently being processed -
1631fd1fc79dSAriel Elior 	 * debug failsafe only
1632fd1fc79dSAriel Elior 	 */
1633fd1fc79dSAriel Elior 	if (mbx->flags & VF_MSG_INPROCESS) {
1634fd1fc79dSAriel Elior 		BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1635fd1fc79dSAriel Elior 			  vfpf_event->vf_id);
1636fd1fc79dSAriel Elior 		goto mbx_done;
1637fd1fc79dSAriel Elior 	}
1638fd1fc79dSAriel Elior 	vf = BP_VF(bp, vf_idx);
1639fd1fc79dSAriel Elior 
1640fd1fc79dSAriel Elior 	/* save the VF message address */
1641fd1fc79dSAriel Elior 	mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1642fd1fc79dSAriel Elior 	mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1643fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1644fd1fc79dSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1645fd1fc79dSAriel Elior 
1646fd1fc79dSAriel Elior 	/* dmae to get the VF request */
1647fd1fc79dSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1648fd1fc79dSAriel Elior 				  mbx->vf_addr_hi, mbx->vf_addr_lo,
1649fd1fc79dSAriel Elior 				  sizeof(union vfpf_tlvs)/4);
1650fd1fc79dSAriel Elior 	if (rc) {
1651fd1fc79dSAriel Elior 		BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1652fd1fc79dSAriel Elior 		goto mbx_error;
1653fd1fc79dSAriel Elior 	}
1654fd1fc79dSAriel Elior 
1655fd1fc79dSAriel Elior 	/* process the VF message header */
1656fd1fc79dSAriel Elior 	mbx->first_tlv = mbx->msg->req.first_tlv;
1657fd1fc79dSAriel Elior 
1658fd1fc79dSAriel Elior 	/* dispatch the request (will prepare the response) */
1659fd1fc79dSAriel Elior 	bnx2x_vf_mbx_request(bp, vf, mbx);
1660fd1fc79dSAriel Elior 	goto mbx_done;
1661fd1fc79dSAriel Elior 
1662fd1fc79dSAriel Elior mbx_error:
1663f1929b01SAriel Elior 	bnx2x_vf_release(bp, vf, false); /* non blocking */
1664fd1fc79dSAriel Elior mbx_done:
1665fd1fc79dSAriel Elior 	return;
1666fd1fc79dSAriel Elior }
1667abc5a021SAriel Elior 
1668abc5a021SAriel Elior /* propagate local bulletin board to vf */
1669abc5a021SAriel Elior int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1670abc5a021SAriel Elior {
1671abc5a021SAriel Elior 	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1672abc5a021SAriel Elior 	dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1673abc5a021SAriel Elior 		vf * BULLETIN_CONTENT_SIZE;
1674abc5a021SAriel Elior 	dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1675abc5a021SAriel Elior 	int rc;
1676abc5a021SAriel Elior 
1677abc5a021SAriel Elior 	/* can only update vf after init took place */
1678abc5a021SAriel Elior 	if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1679abc5a021SAriel Elior 	    bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1680abc5a021SAriel Elior 		return 0;
1681abc5a021SAriel Elior 
1682abc5a021SAriel Elior 	/* increment bulletin board version and compute crc */
1683abc5a021SAriel Elior 	bulletin->version++;
16844c133c39SAriel Elior 	bulletin->length = BULLETIN_CONTENT_SIZE;
1685abc5a021SAriel Elior 	bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1686abc5a021SAriel Elior 
1687abc5a021SAriel Elior 	/* propagate bulletin board via dmae to vm memory */
1688abc5a021SAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1689abc5a021SAriel Elior 				  bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
16904c133c39SAriel Elior 				  U64_LO(vf_addr), bulletin->length / 4);
1691abc5a021SAriel Elior 	return rc;
1692abc5a021SAriel Elior }
1693