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 {
39be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
40be1f1ffaSAriel Elior 	   type);
41be1f1ffaSAriel Elior 
42be1f1ffaSAriel Elior 	/* Clear mailbox */
43be1f1ffaSAriel Elior 	memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
44be1f1ffaSAriel Elior 
45be1f1ffaSAriel Elior 	/* init type and length */
46be1f1ffaSAriel Elior 	bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
47be1f1ffaSAriel Elior 
48be1f1ffaSAriel Elior 	/* init first tlv header */
49be1f1ffaSAriel Elior 	first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
50be1f1ffaSAriel Elior }
51be1f1ffaSAriel Elior 
52be1f1ffaSAriel Elior /* list the types and lengths of the tlvs on the buffer */
53be1f1ffaSAriel Elior void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
54be1f1ffaSAriel Elior {
55be1f1ffaSAriel Elior 	int i = 1;
56be1f1ffaSAriel Elior 	struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
57be1f1ffaSAriel Elior 
58be1f1ffaSAriel Elior 	while (tlv->type != CHANNEL_TLV_LIST_END) {
59be1f1ffaSAriel Elior 		/* output tlv */
60be1f1ffaSAriel Elior 		DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
61be1f1ffaSAriel Elior 		   tlv->type, tlv->length);
62be1f1ffaSAriel Elior 
63be1f1ffaSAriel Elior 		/* advance to next tlv */
64be1f1ffaSAriel Elior 		tlvs_list += tlv->length;
65be1f1ffaSAriel Elior 
66be1f1ffaSAriel Elior 		/* cast general tlv list pointer to channel tlv header*/
67be1f1ffaSAriel Elior 		tlv = (struct channel_tlv *)tlvs_list;
68be1f1ffaSAriel Elior 
69be1f1ffaSAriel Elior 		i++;
70be1f1ffaSAriel Elior 
71be1f1ffaSAriel Elior 		/* break condition for this loop */
72be1f1ffaSAriel Elior 		if (i > MAX_TLVS_IN_LIST) {
73be1f1ffaSAriel Elior 			WARN(true, "corrupt tlvs");
74be1f1ffaSAriel Elior 			return;
75be1f1ffaSAriel Elior 		}
76be1f1ffaSAriel Elior 	}
77be1f1ffaSAriel Elior 
78be1f1ffaSAriel Elior 	/* output last tlv */
79be1f1ffaSAriel Elior 	DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
80be1f1ffaSAriel Elior 	   tlv->type, tlv->length);
81be1f1ffaSAriel Elior }
82b56e9670SAriel Elior 
83fd1fc79dSAriel Elior /* test whether we support a tlv type */
84fd1fc79dSAriel Elior bool bnx2x_tlv_supported(u16 tlvtype)
85fd1fc79dSAriel Elior {
86fd1fc79dSAriel Elior 	return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
87fd1fc79dSAriel Elior }
88fd1fc79dSAriel Elior 
89fd1fc79dSAriel Elior static inline int bnx2x_pfvf_status_codes(int rc)
90fd1fc79dSAriel Elior {
91fd1fc79dSAriel Elior 	switch (rc) {
92fd1fc79dSAriel Elior 	case 0:
93fd1fc79dSAriel Elior 		return PFVF_STATUS_SUCCESS;
94fd1fc79dSAriel Elior 	case -ENOMEM:
95fd1fc79dSAriel Elior 		return PFVF_STATUS_NO_RESOURCE;
96fd1fc79dSAriel Elior 	default:
97fd1fc79dSAriel Elior 		return PFVF_STATUS_FAILURE;
98fd1fc79dSAriel Elior 	}
99fd1fc79dSAriel Elior }
100fd1fc79dSAriel Elior 
1016411280aSAriel Elior int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
1026411280aSAriel Elior {
1036411280aSAriel Elior 	struct cstorm_vf_zone_data __iomem *zone_data =
1046411280aSAriel Elior 		REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
1056411280aSAriel Elior 	int tout = 600, interval = 100; /* wait for 60 seconds */
1066411280aSAriel Elior 
1076411280aSAriel Elior 	if (*done) {
1086411280aSAriel Elior 		BNX2X_ERR("done was non zero before message to pf was sent\n");
1096411280aSAriel Elior 		WARN_ON(true);
1106411280aSAriel Elior 		return -EINVAL;
1116411280aSAriel Elior 	}
1126411280aSAriel Elior 
1136411280aSAriel Elior 	/* Write message address */
1146411280aSAriel Elior 	writel(U64_LO(msg_mapping),
1156411280aSAriel Elior 	       &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
1166411280aSAriel Elior 	writel(U64_HI(msg_mapping),
1176411280aSAriel Elior 	       &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
1186411280aSAriel Elior 
1196411280aSAriel Elior 	/* make sure the address is written before FW accesses it */
1206411280aSAriel Elior 	wmb();
1216411280aSAriel Elior 
1226411280aSAriel Elior 	/* Trigger the PF FW */
1236411280aSAriel Elior 	writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
1246411280aSAriel Elior 
1256411280aSAriel Elior 	/* Wait for PF to complete */
1266411280aSAriel Elior 	while ((tout >= 0) && (!*done)) {
1276411280aSAriel Elior 		msleep(interval);
1286411280aSAriel Elior 		tout -= 1;
1296411280aSAriel Elior 
1306411280aSAriel Elior 		/* progress indicator - HV can take its own sweet time in
1316411280aSAriel Elior 		 * answering VFs...
1326411280aSAriel Elior 		 */
1336411280aSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, ".");
1346411280aSAriel Elior 	}
1356411280aSAriel Elior 
1366411280aSAriel Elior 	if (!*done) {
1376411280aSAriel Elior 		BNX2X_ERR("PF response has timed out\n");
1386411280aSAriel Elior 		return -EAGAIN;
1396411280aSAriel Elior 	}
1406411280aSAriel Elior 	DP(BNX2X_MSG_SP, "Got a response from PF\n");
1416411280aSAriel Elior 	return 0;
1426411280aSAriel Elior }
1436411280aSAriel Elior 
1446411280aSAriel Elior int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
1456411280aSAriel Elior {
1466411280aSAriel Elior 	u32 me_reg;
1476411280aSAriel Elior 	int tout = 10, interval = 100; /* Wait for 1 sec */
1486411280aSAriel Elior 
1496411280aSAriel Elior 	do {
1506411280aSAriel Elior 		/* pxp traps vf read of doorbells and returns me reg value */
1516411280aSAriel Elior 		me_reg = readl(bp->doorbells);
1526411280aSAriel Elior 		if (GOOD_ME_REG(me_reg))
1536411280aSAriel Elior 			break;
1546411280aSAriel Elior 
1556411280aSAriel Elior 		msleep(interval);
1566411280aSAriel Elior 
1576411280aSAriel Elior 		BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
1586411280aSAriel Elior 			  me_reg);
1596411280aSAriel Elior 	} while (tout-- > 0);
1606411280aSAriel Elior 
1616411280aSAriel Elior 	if (!GOOD_ME_REG(me_reg)) {
1626411280aSAriel Elior 		BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
1636411280aSAriel Elior 		return -EINVAL;
1646411280aSAriel Elior 	}
1656411280aSAriel Elior 
1666411280aSAriel Elior 	BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
1676411280aSAriel Elior 
1686411280aSAriel Elior 	*vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
1696411280aSAriel Elior 
1706411280aSAriel Elior 	return 0;
1716411280aSAriel Elior }
1726411280aSAriel Elior 
1736411280aSAriel Elior int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
1746411280aSAriel Elior {
1756411280aSAriel Elior 	int rc = 0, attempts = 0;
1766411280aSAriel Elior 	struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
1776411280aSAriel Elior 	struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
1786411280aSAriel Elior 	u32 vf_id;
1796411280aSAriel Elior 	bool resources_acquired = false;
1806411280aSAriel Elior 
1816411280aSAriel Elior 	/* clear mailbox and prep first tlv */
1826411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
1836411280aSAriel Elior 
1846411280aSAriel Elior 	if (bnx2x_get_vf_id(bp, &vf_id))
1856411280aSAriel Elior 		return -EAGAIN;
1866411280aSAriel Elior 
1876411280aSAriel Elior 	req->vfdev_info.vf_id = vf_id;
1886411280aSAriel Elior 	req->vfdev_info.vf_os = 0;
1896411280aSAriel Elior 
1906411280aSAriel Elior 	req->resc_request.num_rxqs = rx_count;
1916411280aSAriel Elior 	req->resc_request.num_txqs = tx_count;
1926411280aSAriel Elior 	req->resc_request.num_sbs = bp->igu_sb_cnt;
1936411280aSAriel Elior 	req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
1946411280aSAriel Elior 	req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
1956411280aSAriel Elior 
1966411280aSAriel Elior 	/* pf 2 vf bulletin board address */
1976411280aSAriel Elior 	req->bulletin_addr = bp->pf2vf_bulletin_mapping;
1986411280aSAriel Elior 
1996411280aSAriel Elior 	/* add list termination tlv */
2006411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
2016411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
2026411280aSAriel Elior 
2036411280aSAriel Elior 	/* output tlvs list */
2046411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
2056411280aSAriel Elior 
2066411280aSAriel Elior 	while (!resources_acquired) {
2076411280aSAriel Elior 		DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
2086411280aSAriel Elior 
2096411280aSAriel Elior 		/* send acquire request */
2106411280aSAriel Elior 		rc = bnx2x_send_msg2pf(bp,
2116411280aSAriel Elior 				       &resp->hdr.status,
2126411280aSAriel Elior 				       bp->vf2pf_mbox_mapping);
2136411280aSAriel Elior 
2146411280aSAriel Elior 		/* PF timeout */
2156411280aSAriel Elior 		if (rc)
2166411280aSAriel Elior 			return rc;
2176411280aSAriel Elior 
2186411280aSAriel Elior 		/* copy acquire response from buffer to bp */
2196411280aSAriel Elior 		memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
2206411280aSAriel Elior 
2216411280aSAriel Elior 		attempts++;
2226411280aSAriel Elior 
2236411280aSAriel Elior 		/* test whether the PF accepted our request. If not, humble the
2246411280aSAriel Elior 		 * the request and try again.
2256411280aSAriel Elior 		 */
2266411280aSAriel Elior 		if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
2276411280aSAriel Elior 			DP(BNX2X_MSG_SP, "resources acquired\n");
2286411280aSAriel Elior 			resources_acquired = true;
2296411280aSAriel Elior 		} else if (bp->acquire_resp.hdr.status ==
2306411280aSAriel Elior 			   PFVF_STATUS_NO_RESOURCE &&
2316411280aSAriel Elior 			   attempts < VF_ACQUIRE_THRESH) {
2326411280aSAriel Elior 			DP(BNX2X_MSG_SP,
2336411280aSAriel Elior 			   "PF unwilling to fulfill resource request. Try PF recommended amount\n");
2346411280aSAriel Elior 
2356411280aSAriel Elior 			/* humble our request */
2366411280aSAriel Elior 			req->resc_request.num_txqs =
2376411280aSAriel Elior 				bp->acquire_resp.resc.num_txqs;
2386411280aSAriel Elior 			req->resc_request.num_rxqs =
2396411280aSAriel Elior 				bp->acquire_resp.resc.num_rxqs;
2406411280aSAriel Elior 			req->resc_request.num_sbs =
2416411280aSAriel Elior 				bp->acquire_resp.resc.num_sbs;
2426411280aSAriel Elior 			req->resc_request.num_mac_filters =
2436411280aSAriel Elior 				bp->acquire_resp.resc.num_mac_filters;
2446411280aSAriel Elior 			req->resc_request.num_vlan_filters =
2456411280aSAriel Elior 				bp->acquire_resp.resc.num_vlan_filters;
2466411280aSAriel Elior 			req->resc_request.num_mc_filters =
2476411280aSAriel Elior 				bp->acquire_resp.resc.num_mc_filters;
2486411280aSAriel Elior 
2496411280aSAriel Elior 			/* Clear response buffer */
2506411280aSAriel Elior 			memset(&bp->vf2pf_mbox->resp, 0,
2516411280aSAriel Elior 			       sizeof(union pfvf_tlvs));
2526411280aSAriel Elior 		} else {
2536411280aSAriel Elior 			/* PF reports error */
2546411280aSAriel Elior 			BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
2556411280aSAriel Elior 				  bp->acquire_resp.hdr.status);
2566411280aSAriel Elior 			return -EAGAIN;
2576411280aSAriel Elior 		}
2586411280aSAriel Elior 	}
2596411280aSAriel Elior 
2606411280aSAriel Elior 	/* get HW info */
2616411280aSAriel Elior 	bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
2626411280aSAriel Elior 	bp->link_params.chip_id = bp->common.chip_id;
2636411280aSAriel Elior 	bp->db_size = bp->acquire_resp.pfdev_info.db_size;
2646411280aSAriel Elior 	bp->common.int_block = INT_BLOCK_IGU;
2656411280aSAriel Elior 	bp->common.chip_port_mode = CHIP_2_PORT_MODE;
2666411280aSAriel Elior 	bp->igu_dsb_id = -1;
2676411280aSAriel Elior 	bp->mf_ov = 0;
2686411280aSAriel Elior 	bp->mf_mode = 0;
2696411280aSAriel Elior 	bp->common.flash_size = 0;
2706411280aSAriel Elior 	bp->flags |=
2716411280aSAriel Elior 		NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
2726411280aSAriel Elior 	bp->igu_sb_cnt = 1;
2736411280aSAriel Elior 	bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
2746411280aSAriel Elior 	strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
2756411280aSAriel Elior 		sizeof(bp->fw_ver));
2766411280aSAriel Elior 
2776411280aSAriel Elior 	if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
2786411280aSAriel Elior 		memcpy(bp->dev->dev_addr,
2796411280aSAriel Elior 		       bp->acquire_resp.resc.current_mac_addr,
2806411280aSAriel Elior 		       ETH_ALEN);
2816411280aSAriel Elior 
2826411280aSAriel Elior 	return 0;
2836411280aSAriel Elior }
2846411280aSAriel Elior 
2856411280aSAriel Elior int bnx2x_vfpf_release(struct bnx2x *bp)
2866411280aSAriel Elior {
2876411280aSAriel Elior 	struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
2886411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
2896411280aSAriel Elior 	u32 rc = 0, vf_id;
2906411280aSAriel Elior 
2916411280aSAriel Elior 	/* clear mailbox and prep first tlv */
2926411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
2936411280aSAriel Elior 
2946411280aSAriel Elior 	if (bnx2x_get_vf_id(bp, &vf_id))
2956411280aSAriel Elior 		return -EAGAIN;
2966411280aSAriel Elior 
2976411280aSAriel Elior 	req->vf_id = vf_id;
2986411280aSAriel Elior 
2996411280aSAriel Elior 	/* add list termination tlv */
3006411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
3016411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
3026411280aSAriel Elior 
3036411280aSAriel Elior 	/* output tlvs list */
3046411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
3056411280aSAriel Elior 
3066411280aSAriel Elior 	/* send release request */
3076411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
3086411280aSAriel Elior 
3096411280aSAriel Elior 	if (rc)
3106411280aSAriel Elior 		/* PF timeout */
3116411280aSAriel Elior 		return rc;
3126411280aSAriel Elior 	if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
3136411280aSAriel Elior 		/* PF released us */
3146411280aSAriel Elior 		DP(BNX2X_MSG_SP, "vf released\n");
3156411280aSAriel Elior 	} else {
3166411280aSAriel Elior 		/* PF reports error */
3176411280aSAriel Elior 		BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
3186411280aSAriel Elior 			  resp->hdr.status);
3196411280aSAriel Elior 		return -EAGAIN;
3206411280aSAriel Elior 	}
3216411280aSAriel Elior 
3226411280aSAriel Elior 	return 0;
3236411280aSAriel Elior }
3246411280aSAriel Elior 
3256411280aSAriel Elior /* Tell PF about SB addresses */
3266411280aSAriel Elior int bnx2x_vfpf_init(struct bnx2x *bp)
3276411280aSAriel Elior {
3286411280aSAriel Elior 	struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
3296411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
3306411280aSAriel Elior 	int rc, i;
3316411280aSAriel Elior 
3326411280aSAriel Elior 	/* clear mailbox and prep first tlv */
3336411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
3346411280aSAriel Elior 
3356411280aSAriel Elior 	/* status blocks */
3366411280aSAriel Elior 	for_each_eth_queue(bp, i)
3376411280aSAriel Elior 		req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
3386411280aSAriel Elior 						       status_blk_mapping);
3396411280aSAriel Elior 
3406411280aSAriel Elior 	/* statistics - requests only supports single queue for now */
3416411280aSAriel Elior 	req->stats_addr = bp->fw_stats_data_mapping +
3426411280aSAriel Elior 			  offsetof(struct bnx2x_fw_stats_data, queue_stats);
3436411280aSAriel Elior 
3446411280aSAriel Elior 	/* add list termination tlv */
3456411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
3466411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
3476411280aSAriel Elior 
3486411280aSAriel Elior 	/* output tlvs list */
3496411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
3506411280aSAriel Elior 
3516411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
3526411280aSAriel Elior 	if (rc)
3536411280aSAriel Elior 		return rc;
3546411280aSAriel Elior 
3556411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
3566411280aSAriel Elior 		BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
3576411280aSAriel Elior 			  resp->hdr.status);
3586411280aSAriel Elior 		return -EAGAIN;
3596411280aSAriel Elior 	}
3606411280aSAriel Elior 
3616411280aSAriel Elior 	DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
3626411280aSAriel Elior 	return 0;
3636411280aSAriel Elior }
3646411280aSAriel Elior 
3656411280aSAriel Elior /* CLOSE VF - opposite to INIT_VF */
3666411280aSAriel Elior void bnx2x_vfpf_close_vf(struct bnx2x *bp)
3676411280aSAriel Elior {
3686411280aSAriel Elior 	struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
3696411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
3706411280aSAriel Elior 	int i, rc;
3716411280aSAriel Elior 	u32 vf_id;
3726411280aSAriel Elior 
3736411280aSAriel Elior 	/* If we haven't got a valid VF id, there is no sense to
3746411280aSAriel Elior 	 * continue with sending messages
3756411280aSAriel Elior 	 */
3766411280aSAriel Elior 	if (bnx2x_get_vf_id(bp, &vf_id))
3776411280aSAriel Elior 		goto free_irq;
3786411280aSAriel Elior 
3796411280aSAriel Elior 	/* Close the queues */
3806411280aSAriel Elior 	for_each_queue(bp, i)
3816411280aSAriel Elior 		bnx2x_vfpf_teardown_queue(bp, i);
3826411280aSAriel Elior 
3836411280aSAriel Elior 	/* clear mailbox and prep first tlv */
3846411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
3856411280aSAriel Elior 
3866411280aSAriel Elior 	req->vf_id = vf_id;
3876411280aSAriel Elior 
3886411280aSAriel Elior 	/* add list termination tlv */
3896411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
3906411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
3916411280aSAriel Elior 
3926411280aSAriel Elior 	/* output tlvs list */
3936411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
3946411280aSAriel Elior 
3956411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
3966411280aSAriel Elior 
3976411280aSAriel Elior 	if (rc)
3986411280aSAriel Elior 		BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
3996411280aSAriel Elior 
4006411280aSAriel Elior 	else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
4016411280aSAriel Elior 		BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
4026411280aSAriel Elior 			  resp->hdr.status);
4036411280aSAriel Elior 
4046411280aSAriel Elior free_irq:
4056411280aSAriel Elior 	/* Disable HW interrupts, NAPI */
4066411280aSAriel Elior 	bnx2x_netif_stop(bp, 0);
4076411280aSAriel Elior 	/* Delete all NAPI objects */
4086411280aSAriel Elior 	bnx2x_del_all_napi(bp);
4096411280aSAriel Elior 
4106411280aSAriel Elior 	/* Release IRQs */
4116411280aSAriel Elior 	bnx2x_free_irq(bp);
4126411280aSAriel Elior }
4136411280aSAriel Elior 
4146411280aSAriel Elior /* ask the pf to open a queue for the vf */
4156411280aSAriel Elior int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
4166411280aSAriel Elior {
4176411280aSAriel Elior 	struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
4186411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4196411280aSAriel Elior 	struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
4206411280aSAriel Elior 	u16 tpa_agg_size = 0, flags = 0;
4216411280aSAriel Elior 	int rc;
4226411280aSAriel Elior 
4236411280aSAriel Elior 	/* clear mailbox and prep first tlv */
4246411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
4256411280aSAriel Elior 
4266411280aSAriel Elior 	/* select tpa mode to request */
4276411280aSAriel Elior 	if (!fp->disable_tpa) {
4286411280aSAriel Elior 		flags |= VFPF_QUEUE_FLG_TPA;
4296411280aSAriel Elior 		flags |= VFPF_QUEUE_FLG_TPA_IPV6;
4306411280aSAriel Elior 		if (fp->mode == TPA_MODE_GRO)
4316411280aSAriel Elior 			flags |= VFPF_QUEUE_FLG_TPA_GRO;
4326411280aSAriel Elior 		tpa_agg_size = TPA_AGG_SIZE;
4336411280aSAriel Elior 	}
4346411280aSAriel Elior 
4356411280aSAriel Elior 	/* calculate queue flags */
4366411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_STATS;
4376411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
4386411280aSAriel Elior 	flags |= IS_MF_SD(bp) ? VFPF_QUEUE_FLG_OV : 0;
4396411280aSAriel Elior 	flags |= VFPF_QUEUE_FLG_VLAN;
4406411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
4416411280aSAriel Elior 
4426411280aSAriel Elior 	/* Common */
4436411280aSAriel Elior 	req->vf_qid = fp_idx;
4446411280aSAriel Elior 	req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
4456411280aSAriel Elior 
4466411280aSAriel Elior 	/* Rx */
4476411280aSAriel Elior 	req->rxq.rcq_addr = fp->rx_comp_mapping;
4486411280aSAriel Elior 	req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
4496411280aSAriel Elior 	req->rxq.rxq_addr = fp->rx_desc_mapping;
4506411280aSAriel Elior 	req->rxq.sge_addr = fp->rx_sge_mapping;
4516411280aSAriel Elior 	req->rxq.vf_sb = fp_idx;
4526411280aSAriel Elior 	req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
4536411280aSAriel Elior 	req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
4546411280aSAriel Elior 	req->rxq.mtu = bp->dev->mtu;
4556411280aSAriel Elior 	req->rxq.buf_sz = fp->rx_buf_size;
4566411280aSAriel Elior 	req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
4576411280aSAriel Elior 	req->rxq.tpa_agg_sz = tpa_agg_size;
4586411280aSAriel Elior 	req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
4596411280aSAriel Elior 	req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
4606411280aSAriel Elior 			  (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
4616411280aSAriel Elior 	req->rxq.flags = flags;
4626411280aSAriel Elior 	req->rxq.drop_flags = 0;
4636411280aSAriel Elior 	req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
4646411280aSAriel Elior 	req->rxq.stat_id = -1; /* No stats at the moment */
4656411280aSAriel Elior 
4666411280aSAriel Elior 	/* Tx */
4676411280aSAriel Elior 	req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
4686411280aSAriel Elior 	req->txq.vf_sb = fp_idx;
4696411280aSAriel Elior 	req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
4706411280aSAriel Elior 	req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
4716411280aSAriel Elior 	req->txq.flags = flags;
4726411280aSAriel Elior 	req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
4736411280aSAriel Elior 
4746411280aSAriel Elior 	/* add list termination tlv */
4756411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
4766411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
4776411280aSAriel Elior 
4786411280aSAriel Elior 	/* output tlvs list */
4796411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
4806411280aSAriel Elior 
4816411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
4826411280aSAriel Elior 	if (rc)
4836411280aSAriel Elior 		BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
4846411280aSAriel Elior 			  fp_idx);
4856411280aSAriel Elior 
4866411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
4876411280aSAriel Elior 		BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
4886411280aSAriel Elior 			  fp_idx, resp->hdr.status);
4896411280aSAriel Elior 		return -EINVAL;
4906411280aSAriel Elior 	}
4916411280aSAriel Elior 	return rc;
4926411280aSAriel Elior }
4936411280aSAriel Elior 
4946411280aSAriel Elior int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
4956411280aSAriel Elior {
4966411280aSAriel Elior 	struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
4976411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4986411280aSAriel Elior 	int rc;
4996411280aSAriel Elior 
5006411280aSAriel Elior 	/* clear mailbox and prep first tlv */
5016411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
5026411280aSAriel Elior 			sizeof(*req));
5036411280aSAriel Elior 
5046411280aSAriel Elior 	req->vf_qid = qidx;
5056411280aSAriel Elior 
5066411280aSAriel Elior 	/* add list termination tlv */
5076411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5086411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
5096411280aSAriel Elior 
5106411280aSAriel Elior 	/* output tlvs list */
5116411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
5126411280aSAriel Elior 
5136411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5146411280aSAriel Elior 
5156411280aSAriel Elior 	if (rc) {
5166411280aSAriel Elior 		BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
5176411280aSAriel Elior 			  rc);
5186411280aSAriel Elior 		return rc;
5196411280aSAriel Elior 	}
5206411280aSAriel Elior 
5216411280aSAriel Elior 	/* PF failed the transaction */
5226411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
5236411280aSAriel Elior 		BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
5246411280aSAriel Elior 			  resp->hdr.status);
5256411280aSAriel Elior 		return -EINVAL;
5266411280aSAriel Elior 	}
5276411280aSAriel Elior 
5286411280aSAriel Elior 	return 0;
5296411280aSAriel Elior }
5306411280aSAriel Elior 
5316411280aSAriel Elior /* request pf to add a mac for the vf */
5326411280aSAriel Elior int bnx2x_vfpf_set_mac(struct bnx2x *bp)
5336411280aSAriel Elior {
5346411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
5356411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
5366411280aSAriel Elior 	int rc;
5376411280aSAriel Elior 
5386411280aSAriel Elior 	/* clear mailbox and prep first tlv */
5396411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
5406411280aSAriel Elior 			sizeof(*req));
5416411280aSAriel Elior 
5426411280aSAriel Elior 	req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
5436411280aSAriel Elior 	req->vf_qid = 0;
5446411280aSAriel Elior 	req->n_mac_vlan_filters = 1;
5456411280aSAriel Elior 	req->filters[0].flags =
5466411280aSAriel Elior 		VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
5476411280aSAriel Elior 
5486411280aSAriel Elior 	/* sample bulletin board for new mac */
5496411280aSAriel Elior 	bnx2x_sample_bulletin(bp);
5506411280aSAriel Elior 
5516411280aSAriel Elior 	/* copy mac from device to request */
5526411280aSAriel Elior 	memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
5536411280aSAriel Elior 
5546411280aSAriel Elior 	/* add list termination tlv */
5556411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5566411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
5576411280aSAriel Elior 
5586411280aSAriel Elior 	/* output tlvs list */
5596411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
5606411280aSAriel Elior 
5616411280aSAriel Elior 	/* send message to pf */
5626411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5636411280aSAriel Elior 	if (rc) {
5646411280aSAriel Elior 		BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
5656411280aSAriel Elior 		return rc;
5666411280aSAriel Elior 	}
5676411280aSAriel Elior 
5686411280aSAriel Elior 	/* failure may mean PF was configured with a new mac for us */
5696411280aSAriel Elior 	while (resp->hdr.status == PFVF_STATUS_FAILURE) {
5706411280aSAriel Elior 		DP(BNX2X_MSG_IOV,
5716411280aSAriel Elior 		   "vfpf SET MAC failed. Check bulletin board for new posts\n");
5726411280aSAriel Elior 
5736411280aSAriel Elior 		/* check if bulletin board was updated */
5746411280aSAriel Elior 		if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
5756411280aSAriel Elior 			/* copy mac from device to request */
5766411280aSAriel Elior 			memcpy(req->filters[0].mac, bp->dev->dev_addr,
5776411280aSAriel Elior 			       ETH_ALEN);
5786411280aSAriel Elior 
5796411280aSAriel Elior 			/* send message to pf */
5806411280aSAriel Elior 			rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
5816411280aSAriel Elior 					       bp->vf2pf_mbox_mapping);
5826411280aSAriel Elior 		} else {
5836411280aSAriel Elior 			/* no new info in bulletin */
5846411280aSAriel Elior 			break;
5856411280aSAriel Elior 		}
5866411280aSAriel Elior 	}
5876411280aSAriel Elior 
5886411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
5896411280aSAriel Elior 		BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
5906411280aSAriel Elior 		return -EINVAL;
5916411280aSAriel Elior 	}
5926411280aSAriel Elior 
5936411280aSAriel Elior 	return 0;
5946411280aSAriel Elior }
5956411280aSAriel Elior 
5966411280aSAriel Elior int bnx2x_vfpf_set_mcast(struct net_device *dev)
5976411280aSAriel Elior {
5986411280aSAriel Elior 	struct bnx2x *bp = netdev_priv(dev);
5996411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
6006411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6016411280aSAriel Elior 	int rc, i = 0;
6026411280aSAriel Elior 	struct netdev_hw_addr *ha;
6036411280aSAriel Elior 
6046411280aSAriel Elior 	if (bp->state != BNX2X_STATE_OPEN) {
6056411280aSAriel Elior 		DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
6066411280aSAriel Elior 		return -EINVAL;
6076411280aSAriel Elior 	}
6086411280aSAriel Elior 
6096411280aSAriel Elior 	/* clear mailbox and prep first tlv */
6106411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
6116411280aSAriel Elior 			sizeof(*req));
6126411280aSAriel Elior 
6136411280aSAriel Elior 	/* Get Rx mode requested */
6146411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
6156411280aSAriel Elior 
6166411280aSAriel Elior 	netdev_for_each_mc_addr(ha, dev) {
6176411280aSAriel Elior 		DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
6186411280aSAriel Elior 		   bnx2x_mc_addr(ha));
6196411280aSAriel Elior 		memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
6206411280aSAriel Elior 		i++;
6216411280aSAriel Elior 	}
6226411280aSAriel Elior 
6236411280aSAriel Elior 	/* We support four PFVF_MAX_MULTICAST_PER_VF mcast
6246411280aSAriel Elior 	  * addresses tops
6256411280aSAriel Elior 	  */
6266411280aSAriel Elior 	if (i >= PFVF_MAX_MULTICAST_PER_VF) {
6276411280aSAriel Elior 		DP(NETIF_MSG_IFUP,
6286411280aSAriel Elior 		   "VF supports not more than %d multicast MAC addresses\n",
6296411280aSAriel Elior 		   PFVF_MAX_MULTICAST_PER_VF);
6306411280aSAriel Elior 		return -EINVAL;
6316411280aSAriel Elior 	}
6326411280aSAriel Elior 
6336411280aSAriel Elior 	req->n_multicast = i;
6346411280aSAriel Elior 	req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
6356411280aSAriel Elior 	req->vf_qid = 0;
6366411280aSAriel Elior 
6376411280aSAriel Elior 	/* add list termination tlv */
6386411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
6396411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
6406411280aSAriel Elior 
6416411280aSAriel Elior 	/* output tlvs list */
6426411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
6436411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
6446411280aSAriel Elior 	if (rc) {
6456411280aSAriel Elior 		BNX2X_ERR("Sending a message failed: %d\n", rc);
6466411280aSAriel Elior 		return rc;
6476411280aSAriel Elior 	}
6486411280aSAriel Elior 
6496411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
6506411280aSAriel Elior 		BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
6516411280aSAriel Elior 			  resp->hdr.status);
6526411280aSAriel Elior 		return -EINVAL;
6536411280aSAriel Elior 	}
6546411280aSAriel Elior 
6556411280aSAriel Elior 	return 0;
6566411280aSAriel Elior }
6576411280aSAriel Elior 
6586411280aSAriel Elior int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
6596411280aSAriel Elior {
6606411280aSAriel Elior 	int mode = bp->rx_mode;
6616411280aSAriel Elior 	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
6626411280aSAriel Elior 	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6636411280aSAriel Elior 	int rc;
6646411280aSAriel Elior 
6656411280aSAriel Elior 	/* clear mailbox and prep first tlv */
6666411280aSAriel Elior 	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
6676411280aSAriel Elior 			sizeof(*req));
6686411280aSAriel Elior 
6696411280aSAriel Elior 	DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
6706411280aSAriel Elior 
6716411280aSAriel Elior 	switch (mode) {
6726411280aSAriel Elior 	case BNX2X_RX_MODE_NONE: /* no Rx */
6736411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
6746411280aSAriel Elior 		break;
6756411280aSAriel Elior 	case BNX2X_RX_MODE_NORMAL:
6766411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
6776411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
6786411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
6796411280aSAriel Elior 		break;
6806411280aSAriel Elior 	case BNX2X_RX_MODE_ALLMULTI:
6816411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
6826411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
6836411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
6846411280aSAriel Elior 		break;
6856411280aSAriel Elior 	case BNX2X_RX_MODE_PROMISC:
6866411280aSAriel Elior 		req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
6876411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
6886411280aSAriel Elior 		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
6896411280aSAriel Elior 		break;
6906411280aSAriel Elior 	default:
6916411280aSAriel Elior 		BNX2X_ERR("BAD rx mode (%d)\n", mode);
6926411280aSAriel Elior 		return -EINVAL;
6936411280aSAriel Elior 	}
6946411280aSAriel Elior 
6956411280aSAriel Elior 	req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
6966411280aSAriel Elior 	req->vf_qid = 0;
6976411280aSAriel Elior 
6986411280aSAriel Elior 	/* add list termination tlv */
6996411280aSAriel Elior 	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
7006411280aSAriel Elior 		      sizeof(struct channel_list_end_tlv));
7016411280aSAriel Elior 
7026411280aSAriel Elior 	/* output tlvs list */
7036411280aSAriel Elior 	bnx2x_dp_tlv_list(bp, req);
7046411280aSAriel Elior 
7056411280aSAriel Elior 	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
7066411280aSAriel Elior 	if (rc)
7076411280aSAriel Elior 		BNX2X_ERR("Sending a message failed: %d\n", rc);
7086411280aSAriel Elior 
7096411280aSAriel Elior 	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
7106411280aSAriel Elior 		BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
7116411280aSAriel Elior 		return -EINVAL;
7126411280aSAriel Elior 	}
7136411280aSAriel Elior 
7146411280aSAriel Elior 	return rc;
7156411280aSAriel Elior }
7166411280aSAriel Elior 
717b56e9670SAriel Elior /* General service functions */
718b56e9670SAriel Elior static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
719b56e9670SAriel Elior {
720b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
721b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
722b56e9670SAriel Elior 
723b56e9670SAriel Elior 	REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
724b56e9670SAriel Elior }
725b56e9670SAriel Elior 
726b56e9670SAriel Elior static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
727b56e9670SAriel Elior {
728b56e9670SAriel Elior 	u32 addr = BAR_CSTRORM_INTMEM +
729b56e9670SAriel Elior 		   CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
730b56e9670SAriel Elior 
731b56e9670SAriel Elior 	REG_WR8(bp, addr, 1);
732b56e9670SAriel Elior }
733b56e9670SAriel Elior 
734b56e9670SAriel Elior static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
735b56e9670SAriel Elior {
736b56e9670SAriel Elior 	int i;
737b56e9670SAriel Elior 
738b56e9670SAriel Elior 	for_each_vf(bp, i)
739b56e9670SAriel Elior 		storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
740b56e9670SAriel Elior }
741b56e9670SAriel Elior 
742b56e9670SAriel Elior /* enable vf_pf mailbox (aka vf-pf-chanell) */
743b56e9670SAriel Elior void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
744b56e9670SAriel Elior {
745b56e9670SAriel Elior 	bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
746b56e9670SAriel Elior 
747b56e9670SAriel Elior 	/* enable the mailbox in the FW */
748b56e9670SAriel Elior 	storm_memset_vf_mbx_ack(bp, abs_vfid);
749b56e9670SAriel Elior 	storm_memset_vf_mbx_valid(bp, abs_vfid);
750b56e9670SAriel Elior 
751b56e9670SAriel Elior 	/* enable the VF access to the mailbox */
752b56e9670SAriel Elior 	bnx2x_vf_enable_access(bp, abs_vfid);
753b56e9670SAriel Elior }
754fd1fc79dSAriel Elior 
755fd1fc79dSAriel Elior /* this works only on !E1h */
756fd1fc79dSAriel Elior static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
757fd1fc79dSAriel Elior 				dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
758fd1fc79dSAriel Elior 				u32 vf_addr_lo, u32 len32)
759fd1fc79dSAriel Elior {
760fd1fc79dSAriel Elior 	struct dmae_command dmae;
761fd1fc79dSAriel Elior 
762fd1fc79dSAriel Elior 	if (CHIP_IS_E1x(bp)) {
763fd1fc79dSAriel Elior 		BNX2X_ERR("Chip revision does not support VFs\n");
764fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
765fd1fc79dSAriel Elior 	}
766fd1fc79dSAriel Elior 
767fd1fc79dSAriel Elior 	if (!bp->dmae_ready) {
768fd1fc79dSAriel Elior 		BNX2X_ERR("DMAE is not ready, can not copy\n");
769fd1fc79dSAriel Elior 		return DMAE_NOT_RDY;
770fd1fc79dSAriel Elior 	}
771fd1fc79dSAriel Elior 
772fd1fc79dSAriel Elior 	/* set opcode and fixed command fields */
773fd1fc79dSAriel Elior 	bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
774fd1fc79dSAriel Elior 
775fd1fc79dSAriel Elior 	if (from_vf) {
776fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
777fd1fc79dSAriel Elior 			(DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
778fd1fc79dSAriel Elior 			(DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
779fd1fc79dSAriel Elior 
780fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
781fd1fc79dSAriel Elior 
782fd1fc79dSAriel Elior 		dmae.src_addr_lo = vf_addr_lo;
783fd1fc79dSAriel Elior 		dmae.src_addr_hi = vf_addr_hi;
784fd1fc79dSAriel Elior 		dmae.dst_addr_lo = U64_LO(pf_addr);
785fd1fc79dSAriel Elior 		dmae.dst_addr_hi = U64_HI(pf_addr);
786fd1fc79dSAriel Elior 	} else {
787fd1fc79dSAriel Elior 		dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
788fd1fc79dSAriel Elior 			(DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
789fd1fc79dSAriel Elior 			(DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
790fd1fc79dSAriel Elior 
791fd1fc79dSAriel Elior 		dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
792fd1fc79dSAriel Elior 
793fd1fc79dSAriel Elior 		dmae.src_addr_lo = U64_LO(pf_addr);
794fd1fc79dSAriel Elior 		dmae.src_addr_hi = U64_HI(pf_addr);
795fd1fc79dSAriel Elior 		dmae.dst_addr_lo = vf_addr_lo;
796fd1fc79dSAriel Elior 		dmae.dst_addr_hi = vf_addr_hi;
797fd1fc79dSAriel Elior 	}
798fd1fc79dSAriel Elior 	dmae.len = len32;
799fd1fc79dSAriel Elior 	bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
800fd1fc79dSAriel Elior 
801fd1fc79dSAriel Elior 	/* issue the command and wait for completion */
802fd1fc79dSAriel Elior 	return bnx2x_issue_dmae_with_comp(bp, &dmae);
803fd1fc79dSAriel Elior }
804fd1fc79dSAriel Elior 
8058ca5e17eSAriel Elior static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
8068ca5e17eSAriel Elior {
8078ca5e17eSAriel Elior 	struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
8088ca5e17eSAriel Elior 	u64 vf_addr;
8098ca5e17eSAriel Elior 	dma_addr_t pf_addr;
8108ca5e17eSAriel Elior 	u16 length, type;
8118ca5e17eSAriel Elior 	int rc;
8128ca5e17eSAriel Elior 	struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
8138ca5e17eSAriel Elior 
8148ca5e17eSAriel Elior 	/* prepare response */
8158ca5e17eSAriel Elior 	type = mbx->first_tlv.tl.type;
8168ca5e17eSAriel Elior 	length = type == CHANNEL_TLV_ACQUIRE ?
8178ca5e17eSAriel Elior 		sizeof(struct pfvf_acquire_resp_tlv) :
8188ca5e17eSAriel Elior 		sizeof(struct pfvf_general_resp_tlv);
8198ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, 0, type, length);
8208ca5e17eSAriel Elior 	resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
8218ca5e17eSAriel Elior 	bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
8228ca5e17eSAriel Elior 		      sizeof(struct channel_list_end_tlv));
8238ca5e17eSAriel Elior 	bnx2x_dp_tlv_list(bp, resp);
8248ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
8258ca5e17eSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
8268ca5e17eSAriel Elior 
8278ca5e17eSAriel Elior 	/* send response */
8288ca5e17eSAriel Elior 	vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
8298ca5e17eSAriel Elior 		  mbx->first_tlv.resp_msg_offset;
8308ca5e17eSAriel Elior 	pf_addr = mbx->msg_mapping +
8318ca5e17eSAriel Elior 		  offsetof(struct bnx2x_vf_mbx_msg, resp);
8328ca5e17eSAriel Elior 
8338ca5e17eSAriel Elior 	/* copy the response body, if there is one, before the header, as the vf
8348ca5e17eSAriel Elior 	 * is sensitive to the header being written
8358ca5e17eSAriel Elior 	 */
8368ca5e17eSAriel Elior 	if (resp->hdr.tl.length > sizeof(u64)) {
8378ca5e17eSAriel Elior 		length = resp->hdr.tl.length - sizeof(u64);
8388ca5e17eSAriel Elior 		vf_addr += sizeof(u64);
8398ca5e17eSAriel Elior 		pf_addr += sizeof(u64);
8408ca5e17eSAriel Elior 		rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
8418ca5e17eSAriel Elior 					  U64_HI(vf_addr),
8428ca5e17eSAriel Elior 					  U64_LO(vf_addr),
8438ca5e17eSAriel Elior 					  length/4);
8448ca5e17eSAriel Elior 		if (rc) {
8458ca5e17eSAriel Elior 			BNX2X_ERR("Failed to copy response body to VF %d\n",
8468ca5e17eSAriel Elior 				  vf->abs_vfid);
847f1929b01SAriel Elior 			goto mbx_error;
8488ca5e17eSAriel Elior 		}
8498ca5e17eSAriel Elior 		vf_addr -= sizeof(u64);
8508ca5e17eSAriel Elior 		pf_addr -= sizeof(u64);
8518ca5e17eSAriel Elior 	}
8528ca5e17eSAriel Elior 
8538ca5e17eSAriel Elior 	/* ack the FW */
8548ca5e17eSAriel Elior 	storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
8558ca5e17eSAriel Elior 	mmiowb();
8568ca5e17eSAriel Elior 
8578ca5e17eSAriel Elior 	/* initiate dmae to send the response */
8588ca5e17eSAriel Elior 	mbx->flags &= ~VF_MSG_INPROCESS;
8598ca5e17eSAriel Elior 
8608ca5e17eSAriel Elior 	/* copy the response header including status-done field,
8618ca5e17eSAriel Elior 	 * must be last dmae, must be after FW is acked
8628ca5e17eSAriel Elior 	 */
8638ca5e17eSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
8648ca5e17eSAriel Elior 				  U64_HI(vf_addr),
8658ca5e17eSAriel Elior 				  U64_LO(vf_addr),
8668ca5e17eSAriel Elior 				  sizeof(u64)/4);
8678ca5e17eSAriel Elior 
8688ca5e17eSAriel Elior 	/* unlock channel mutex */
8698ca5e17eSAriel Elior 	bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
8708ca5e17eSAriel Elior 
8718ca5e17eSAriel Elior 	if (rc) {
8728ca5e17eSAriel Elior 		BNX2X_ERR("Failed to copy response status to VF %d\n",
8738ca5e17eSAriel Elior 			  vf->abs_vfid);
874f1929b01SAriel Elior 		goto mbx_error;
8758ca5e17eSAriel Elior 	}
8768ca5e17eSAriel Elior 	return;
877f1929b01SAriel Elior 
878f1929b01SAriel Elior mbx_error:
879f1929b01SAriel Elior 	bnx2x_vf_release(bp, vf, false); /* non blocking */
8808ca5e17eSAriel Elior }
8818ca5e17eSAriel Elior 
8828ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
8838ca5e17eSAriel Elior 				      struct bnx2x_vf_mbx *mbx, int vfop_status)
8848ca5e17eSAriel Elior {
8858ca5e17eSAriel Elior 	int i;
8868ca5e17eSAriel Elior 	struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
8878ca5e17eSAriel Elior 	struct pf_vf_resc *resc = &resp->resc;
8888ca5e17eSAriel Elior 	u8 status = bnx2x_pfvf_status_codes(vfop_status);
8898ca5e17eSAriel Elior 
8908ca5e17eSAriel Elior 	memset(resp, 0, sizeof(*resp));
8918ca5e17eSAriel Elior 
8928ca5e17eSAriel Elior 	/* fill in pfdev info */
8938ca5e17eSAriel Elior 	resp->pfdev_info.chip_num = bp->common.chip_id;
8948ca5e17eSAriel Elior 	resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
8958ca5e17eSAriel Elior 	resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
8968ca5e17eSAriel Elior 	resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
8978ca5e17eSAriel Elior 				   /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
8988ca5e17eSAriel Elior 	bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
8998ca5e17eSAriel Elior 			  sizeof(resp->pfdev_info.fw_ver));
9008ca5e17eSAriel Elior 
9018ca5e17eSAriel Elior 	if (status == PFVF_STATUS_NO_RESOURCE ||
9028ca5e17eSAriel Elior 	    status == PFVF_STATUS_SUCCESS) {
9038ca5e17eSAriel Elior 		/* set resources numbers, if status equals NO_RESOURCE these
9048ca5e17eSAriel Elior 		 * are max possible numbers
9058ca5e17eSAriel Elior 		 */
9068ca5e17eSAriel Elior 		resc->num_rxqs = vf_rxq_count(vf) ? :
9078ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
9088ca5e17eSAriel Elior 		resc->num_txqs = vf_txq_count(vf) ? :
9098ca5e17eSAriel Elior 			bnx2x_vf_max_queue_cnt(bp, vf);
9108ca5e17eSAriel Elior 		resc->num_sbs = vf_sb_count(vf);
9118ca5e17eSAriel Elior 		resc->num_mac_filters = vf_mac_rules_cnt(vf);
9128ca5e17eSAriel Elior 		resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
9138ca5e17eSAriel Elior 		resc->num_mc_filters = 0;
9148ca5e17eSAriel Elior 
9158ca5e17eSAriel Elior 		if (status == PFVF_STATUS_SUCCESS) {
916abc5a021SAriel Elior 			/* fill in the allocated resources */
917abc5a021SAriel Elior 			struct pf_vf_bulletin_content *bulletin =
918abc5a021SAriel Elior 				BP_VF_BULLETIN(bp, vf->index);
919abc5a021SAriel Elior 
9208ca5e17eSAriel Elior 			for_each_vfq(vf, i)
9218ca5e17eSAriel Elior 				resc->hw_qid[i] =
9228ca5e17eSAriel Elior 					vfq_qzone_id(vf, vfq_get(vf, i));
9238ca5e17eSAriel Elior 
9248ca5e17eSAriel Elior 			for_each_vf_sb(vf, i) {
9258ca5e17eSAriel Elior 				resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
9268ca5e17eSAriel Elior 				resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
9278ca5e17eSAriel Elior 			}
928abc5a021SAriel Elior 
929abc5a021SAriel Elior 			/* if a mac has been set for this vf, supply it */
930abc5a021SAriel Elior 			if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
931abc5a021SAriel Elior 				memcpy(resc->current_mac_addr, bulletin->mac,
932abc5a021SAriel Elior 				       ETH_ALEN);
933abc5a021SAriel Elior 			}
9348ca5e17eSAriel Elior 		}
9358ca5e17eSAriel Elior 	}
9368ca5e17eSAriel Elior 
9378ca5e17eSAriel 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"
9388ca5e17eSAriel Elior 	   "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
9398ca5e17eSAriel Elior 	   vf->abs_vfid,
9408ca5e17eSAriel Elior 	   resp->pfdev_info.chip_num,
9418ca5e17eSAriel Elior 	   resp->pfdev_info.db_size,
9428ca5e17eSAriel Elior 	   resp->pfdev_info.indices_per_sb,
9438ca5e17eSAriel Elior 	   resp->pfdev_info.pf_cap,
9448ca5e17eSAriel Elior 	   resc->num_rxqs,
9458ca5e17eSAriel Elior 	   resc->num_txqs,
9468ca5e17eSAriel Elior 	   resc->num_sbs,
9478ca5e17eSAriel Elior 	   resc->num_mac_filters,
9488ca5e17eSAriel Elior 	   resc->num_vlan_filters,
9498ca5e17eSAriel Elior 	   resc->num_mc_filters,
9508ca5e17eSAriel Elior 	   resp->pfdev_info.fw_ver);
9518ca5e17eSAriel Elior 
9528ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
9538ca5e17eSAriel Elior 	for (i = 0; i < vf_rxq_count(vf); i++)
9548ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
9558ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
9568ca5e17eSAriel Elior 	for (i = 0; i < vf_sb_count(vf); i++)
9578ca5e17eSAriel Elior 		DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
9588ca5e17eSAriel Elior 			resc->hw_sbs[i].hw_sb_id,
9598ca5e17eSAriel Elior 			resc->hw_sbs[i].sb_qid);
9608ca5e17eSAriel Elior 	DP_CONT(BNX2X_MSG_IOV, "]\n");
9618ca5e17eSAriel Elior 
9628ca5e17eSAriel Elior 	/* send the response */
9638ca5e17eSAriel Elior 	vf->op_rc = vfop_status;
9648ca5e17eSAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
9658ca5e17eSAriel Elior }
9668ca5e17eSAriel Elior 
9678ca5e17eSAriel Elior static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
9688ca5e17eSAriel Elior 				 struct bnx2x_vf_mbx *mbx)
9698ca5e17eSAriel Elior {
9708ca5e17eSAriel Elior 	int rc;
9718ca5e17eSAriel Elior 	struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
9728ca5e17eSAriel Elior 
9738ca5e17eSAriel Elior 	/* log vfdef info */
9748ca5e17eSAriel Elior 	DP(BNX2X_MSG_IOV,
9758ca5e17eSAriel 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",
9768ca5e17eSAriel Elior 	   vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
9778ca5e17eSAriel Elior 	   acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
9788ca5e17eSAriel Elior 	   acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
9798ca5e17eSAriel Elior 	   acquire->resc_request.num_vlan_filters,
9808ca5e17eSAriel Elior 	   acquire->resc_request.num_mc_filters);
9818ca5e17eSAriel Elior 
9828ca5e17eSAriel Elior 	/* acquire the resources */
9838ca5e17eSAriel Elior 	rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
9848ca5e17eSAriel Elior 
985abc5a021SAriel Elior 	/* store address of vf's bulletin board */
986abc5a021SAriel Elior 	vf->bulletin_map = acquire->bulletin_addr;
987abc5a021SAriel Elior 
9888ca5e17eSAriel Elior 	/* response */
9898ca5e17eSAriel Elior 	bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
9908ca5e17eSAriel Elior }
9918ca5e17eSAriel Elior 
992b93288d5SAriel Elior static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
993b93288d5SAriel Elior 			      struct bnx2x_vf_mbx *mbx)
994b93288d5SAriel Elior {
995b93288d5SAriel Elior 	struct vfpf_init_tlv *init = &mbx->msg->req.init;
996b93288d5SAriel Elior 
997b93288d5SAriel Elior 	/* record ghost addresses from vf message */
998b93288d5SAriel Elior 	vf->spq_map = init->spq_addr;
999b93288d5SAriel Elior 	vf->fw_stat_map = init->stats_addr;
1000b93288d5SAriel Elior 	vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1001b93288d5SAriel Elior 
1002b93288d5SAriel Elior 	/* response */
1003b93288d5SAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
1004b93288d5SAriel Elior }
1005b93288d5SAriel Elior 
10068db573baSAriel Elior /* convert MBX queue-flags to standard SP queue-flags */
10078db573baSAriel Elior static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags,
10088db573baSAriel Elior 				     unsigned long *sp_q_flags)
10098db573baSAriel Elior {
10108db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
10118db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
10128db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
10138db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
10148db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
10158db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
10168db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
10178db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
10188db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_OV)
10198db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
10208db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
10218db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
10228db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
10238db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
10248db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
10258db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
10268db573baSAriel Elior 	if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
10278db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
10288db573baSAriel Elior }
10298db573baSAriel Elior 
10308db573baSAriel Elior static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
10318db573baSAriel Elior 				 struct bnx2x_vf_mbx *mbx)
10328db573baSAriel Elior {
10338db573baSAriel Elior 	struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
10348db573baSAriel Elior 	struct bnx2x_vfop_cmd cmd = {
10358db573baSAriel Elior 		.done = bnx2x_vf_mbx_resp,
10368db573baSAriel Elior 		.block = false,
10378db573baSAriel Elior 	};
10388db573baSAriel Elior 
10398db573baSAriel Elior 	/* verify vf_qid */
10408db573baSAriel Elior 	if (setup_q->vf_qid >= vf_rxq_count(vf)) {
10418db573baSAriel Elior 		BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
10428db573baSAriel Elior 			  setup_q->vf_qid, vf_rxq_count(vf));
10438db573baSAriel Elior 		vf->op_rc = -EINVAL;
10448db573baSAriel Elior 		goto response;
10458db573baSAriel Elior 	}
10468db573baSAriel Elior 
10478db573baSAriel Elior 	/* tx queues must be setup alongside rx queues thus if the rx queue
10488db573baSAriel Elior 	 * is not marked as valid there's nothing to do.
10498db573baSAriel Elior 	 */
10508db573baSAriel Elior 	if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
10518db573baSAriel Elior 		struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
10528db573baSAriel Elior 		unsigned long q_type = 0;
10538db573baSAriel Elior 
10548db573baSAriel Elior 		struct bnx2x_queue_init_params *init_p;
10558db573baSAriel Elior 		struct bnx2x_queue_setup_params *setup_p;
10568db573baSAriel Elior 
10578db573baSAriel Elior 		/* reinit the VF operation context */
10588db573baSAriel Elior 		memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
10598db573baSAriel Elior 		setup_p = &vf->op_params.qctor.prep_qsetup;
10608db573baSAriel Elior 		init_p =  &vf->op_params.qctor.qstate.params.init;
10618db573baSAriel Elior 
10628db573baSAriel Elior 		/* activate immediately */
10638db573baSAriel Elior 		__set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
10648db573baSAriel Elior 
10658db573baSAriel Elior 		if (setup_q->param_valid & VFPF_TXQ_VALID) {
10668db573baSAriel Elior 			struct bnx2x_txq_setup_params *txq_params =
10678db573baSAriel Elior 				&setup_p->txq_params;
10688db573baSAriel Elior 
10698db573baSAriel Elior 			__set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
10708db573baSAriel Elior 
10718db573baSAriel Elior 			/* save sb resource index */
10728db573baSAriel Elior 			q->sb_idx = setup_q->txq.vf_sb;
10738db573baSAriel Elior 
10748db573baSAriel Elior 			/* tx init */
10758db573baSAriel Elior 			init_p->tx.hc_rate = setup_q->txq.hc_rate;
10768db573baSAriel Elior 			init_p->tx.sb_cq_index = setup_q->txq.sb_index;
10778db573baSAriel Elior 
10788db573baSAriel Elior 			bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
10798db573baSAriel Elior 						 &init_p->tx.flags);
10808db573baSAriel Elior 
10818db573baSAriel Elior 			/* tx setup - flags */
10828db573baSAriel Elior 			bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
10838db573baSAriel Elior 						 &setup_p->flags);
10848db573baSAriel Elior 
10858db573baSAriel Elior 			/* tx setup - general, nothing */
10868db573baSAriel Elior 
10878db573baSAriel Elior 			/* tx setup - tx */
10888db573baSAriel Elior 			txq_params->dscr_map = setup_q->txq.txq_addr;
10898db573baSAriel Elior 			txq_params->sb_cq_index = setup_q->txq.sb_index;
10908db573baSAriel Elior 			txq_params->traffic_type = setup_q->txq.traffic_type;
10918db573baSAriel Elior 
10928db573baSAriel Elior 			bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
10938db573baSAriel Elior 						 q->index, q->sb_idx);
10948db573baSAriel Elior 		}
10958db573baSAriel Elior 
10968db573baSAriel Elior 		if (setup_q->param_valid & VFPF_RXQ_VALID) {
10978db573baSAriel Elior 			struct bnx2x_rxq_setup_params *rxq_params =
10988db573baSAriel Elior 							&setup_p->rxq_params;
10998db573baSAriel Elior 
11008db573baSAriel Elior 			__set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
11018db573baSAriel Elior 
11028db573baSAriel Elior 			/* Note: there is no support for different SBs
11038db573baSAriel Elior 			 * for TX and RX
11048db573baSAriel Elior 			 */
11058db573baSAriel Elior 			q->sb_idx = setup_q->rxq.vf_sb;
11068db573baSAriel Elior 
11078db573baSAriel Elior 			/* rx init */
11088db573baSAriel Elior 			init_p->rx.hc_rate = setup_q->rxq.hc_rate;
11098db573baSAriel Elior 			init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
11108db573baSAriel Elior 			bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
11118db573baSAriel Elior 						 &init_p->rx.flags);
11128db573baSAriel Elior 
11138db573baSAriel Elior 			/* rx setup - flags */
11148db573baSAriel Elior 			bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
11158db573baSAriel Elior 						 &setup_p->flags);
11168db573baSAriel Elior 
11178db573baSAriel Elior 			/* rx setup - general */
11188db573baSAriel Elior 			setup_p->gen_params.mtu = setup_q->rxq.mtu;
11198db573baSAriel Elior 
11208db573baSAriel Elior 			/* rx setup - rx */
11218db573baSAriel Elior 			rxq_params->drop_flags = setup_q->rxq.drop_flags;
11228db573baSAriel Elior 			rxq_params->dscr_map = setup_q->rxq.rxq_addr;
11238db573baSAriel Elior 			rxq_params->sge_map = setup_q->rxq.sge_addr;
11248db573baSAriel Elior 			rxq_params->rcq_map = setup_q->rxq.rcq_addr;
11258db573baSAriel Elior 			rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
11268db573baSAriel Elior 			rxq_params->buf_sz = setup_q->rxq.buf_sz;
11278db573baSAriel Elior 			rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
11288db573baSAriel Elior 			rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
11298db573baSAriel Elior 			rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
11308db573baSAriel Elior 			rxq_params->cache_line_log =
11318db573baSAriel Elior 				setup_q->rxq.cache_line_log;
11328db573baSAriel Elior 			rxq_params->sb_cq_index = setup_q->rxq.sb_index;
11338db573baSAriel Elior 
11348db573baSAriel Elior 			bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
11358db573baSAriel Elior 						 q->index, q->sb_idx);
11368db573baSAriel Elior 		}
11378db573baSAriel Elior 		/* complete the preparations */
11388db573baSAriel Elior 		bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
11398db573baSAriel Elior 
11408db573baSAriel Elior 		vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
11418db573baSAriel Elior 		if (vf->op_rc)
11428db573baSAriel Elior 			goto response;
11438db573baSAriel Elior 		return;
11448db573baSAriel Elior 	}
11458db573baSAriel Elior response:
11468db573baSAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
11478db573baSAriel Elior }
11488db573baSAriel Elior 
1149954ea748SAriel Elior enum bnx2x_vfop_filters_state {
1150954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1151954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1152954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1153954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1154954ea748SAriel Elior 	   BNX2X_VFOP_MBX_Q_FILTERS_DONE
1155954ea748SAriel Elior };
1156954ea748SAriel Elior 
1157954ea748SAriel Elior static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1158954ea748SAriel Elior 				     struct bnx2x_virtf *vf,
1159954ea748SAriel Elior 				     struct vfpf_set_q_filters_tlv *tlv,
1160954ea748SAriel Elior 				     struct bnx2x_vfop_filters **pfl,
1161954ea748SAriel Elior 				     u32 type_flag)
1162954ea748SAriel Elior {
1163954ea748SAriel Elior 	int i, j;
1164954ea748SAriel Elior 	struct bnx2x_vfop_filters *fl = NULL;
1165954ea748SAriel Elior 	size_t fsz;
1166954ea748SAriel Elior 
1167954ea748SAriel Elior 	fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1168954ea748SAriel Elior 		sizeof(struct bnx2x_vfop_filters);
1169954ea748SAriel Elior 
1170954ea748SAriel Elior 	fl = kzalloc(fsz, GFP_KERNEL);
1171954ea748SAriel Elior 	if (!fl)
1172954ea748SAriel Elior 		return -ENOMEM;
1173954ea748SAriel Elior 
1174954ea748SAriel Elior 	INIT_LIST_HEAD(&fl->head);
1175954ea748SAriel Elior 
1176954ea748SAriel Elior 	for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1177954ea748SAriel Elior 		struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1178954ea748SAriel Elior 
1179954ea748SAriel Elior 		if ((msg_filter->flags & type_flag) != type_flag)
1180954ea748SAriel Elior 			continue;
1181954ea748SAriel Elior 		if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1182954ea748SAriel Elior 			fl->filters[j].mac = msg_filter->mac;
1183954ea748SAriel Elior 			fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1184954ea748SAriel Elior 		} else {
1185954ea748SAriel Elior 			fl->filters[j].vid = msg_filter->vlan_tag;
1186954ea748SAriel Elior 			fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1187954ea748SAriel Elior 		}
1188954ea748SAriel Elior 		fl->filters[j].add =
1189954ea748SAriel Elior 			(msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1190954ea748SAriel Elior 			true : false;
1191954ea748SAriel Elior 		list_add_tail(&fl->filters[j++].link, &fl->head);
1192954ea748SAriel Elior 	}
1193954ea748SAriel Elior 	if (list_empty(&fl->head))
1194954ea748SAriel Elior 		kfree(fl);
1195954ea748SAriel Elior 	else
1196954ea748SAriel Elior 		*pfl = fl;
1197954ea748SAriel Elior 
1198954ea748SAriel Elior 	return 0;
1199954ea748SAriel Elior }
1200954ea748SAriel Elior 
1201954ea748SAriel Elior static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1202954ea748SAriel Elior 				       struct vfpf_q_mac_vlan_filter *filter)
1203954ea748SAriel Elior {
1204954ea748SAriel Elior 	DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1205954ea748SAriel Elior 	if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1206954ea748SAriel Elior 		DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1207954ea748SAriel Elior 	if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1208954ea748SAriel Elior 		DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1209954ea748SAriel Elior 	DP_CONT(msglvl, "\n");
1210954ea748SAriel Elior }
1211954ea748SAriel Elior 
1212954ea748SAriel Elior static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1213954ea748SAriel Elior 				       struct vfpf_set_q_filters_tlv *filters)
1214954ea748SAriel Elior {
1215954ea748SAriel Elior 	int i;
1216954ea748SAriel Elior 
1217954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1218954ea748SAriel Elior 		for (i = 0; i < filters->n_mac_vlan_filters; i++)
1219954ea748SAriel Elior 			bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1220954ea748SAriel Elior 						 &filters->filters[i]);
1221954ea748SAriel Elior 
1222954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1223954ea748SAriel Elior 		DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1224954ea748SAriel Elior 
1225954ea748SAriel Elior 	if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1226954ea748SAriel Elior 		for (i = 0; i < filters->n_multicast; i++)
1227954ea748SAriel Elior 			DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1228954ea748SAriel Elior }
1229954ea748SAriel Elior 
1230954ea748SAriel Elior #define VFPF_MAC_FILTER		VFPF_Q_FILTER_DEST_MAC_VALID
1231954ea748SAriel Elior #define VFPF_VLAN_FILTER	VFPF_Q_FILTER_VLAN_TAG_VALID
1232954ea748SAriel Elior 
1233954ea748SAriel Elior static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1234954ea748SAriel Elior {
1235954ea748SAriel Elior 	int rc;
1236954ea748SAriel Elior 
1237954ea748SAriel Elior 	struct vfpf_set_q_filters_tlv *msg =
1238954ea748SAriel Elior 		&BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1239954ea748SAriel Elior 
1240954ea748SAriel Elior 	struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1241954ea748SAriel Elior 	enum bnx2x_vfop_filters_state state = vfop->state;
1242954ea748SAriel Elior 
1243954ea748SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1244954ea748SAriel Elior 		.done = bnx2x_vfop_mbx_qfilters,
1245954ea748SAriel Elior 		.block = false,
1246954ea748SAriel Elior 	};
1247954ea748SAriel Elior 
1248954ea748SAriel Elior 	DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1249954ea748SAriel Elior 
1250954ea748SAriel Elior 	if (vfop->rc < 0)
1251954ea748SAriel Elior 		goto op_err;
1252954ea748SAriel Elior 
1253954ea748SAriel Elior 	switch (state) {
1254954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1255954ea748SAriel Elior 		/* next state */
1256954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1257954ea748SAriel Elior 
1258954ea748SAriel Elior 		/* check for any vlan/mac changes */
1259954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1260954ea748SAriel Elior 			/* build mac list */
1261954ea748SAriel Elior 			struct bnx2x_vfop_filters *fl = NULL;
1262954ea748SAriel Elior 
1263954ea748SAriel Elior 			vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1264954ea748SAriel Elior 							     VFPF_MAC_FILTER);
1265954ea748SAriel Elior 			if (vfop->rc)
1266954ea748SAriel Elior 				goto op_err;
1267954ea748SAriel Elior 
1268954ea748SAriel Elior 			if (fl) {
1269954ea748SAriel Elior 				/* set mac list */
1270954ea748SAriel Elior 				rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1271954ea748SAriel Elior 							     msg->vf_qid,
1272954ea748SAriel Elior 							     false);
1273954ea748SAriel Elior 				if (rc) {
1274954ea748SAriel Elior 					vfop->rc = rc;
1275954ea748SAriel Elior 					goto op_err;
1276954ea748SAriel Elior 				}
1277954ea748SAriel Elior 				return;
1278954ea748SAriel Elior 			}
1279954ea748SAriel Elior 		}
1280954ea748SAriel Elior 		/* fall through */
1281954ea748SAriel Elior 
1282954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1283954ea748SAriel Elior 		/* next state */
1284954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1285954ea748SAriel Elior 
1286954ea748SAriel Elior 		/* check for any vlan/mac changes */
1287954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1288954ea748SAriel Elior 			/* build vlan list */
1289954ea748SAriel Elior 			struct bnx2x_vfop_filters *fl = NULL;
1290954ea748SAriel Elior 
1291954ea748SAriel Elior 			vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1292954ea748SAriel Elior 							     VFPF_VLAN_FILTER);
1293954ea748SAriel Elior 			if (vfop->rc)
1294954ea748SAriel Elior 				goto op_err;
1295954ea748SAriel Elior 
1296954ea748SAriel Elior 			if (fl) {
1297954ea748SAriel Elior 				/* set vlan list */
1298954ea748SAriel Elior 				rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1299954ea748SAriel Elior 							      msg->vf_qid,
1300954ea748SAriel Elior 							      false);
1301954ea748SAriel Elior 				if (rc) {
1302954ea748SAriel Elior 					vfop->rc = rc;
1303954ea748SAriel Elior 					goto op_err;
1304954ea748SAriel Elior 				}
1305954ea748SAriel Elior 				return;
1306954ea748SAriel Elior 			}
1307954ea748SAriel Elior 		}
1308954ea748SAriel Elior 		/* fall through */
1309954ea748SAriel Elior 
1310954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1311954ea748SAriel Elior 		/* next state */
1312954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1313954ea748SAriel Elior 
1314954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1315954ea748SAriel Elior 			unsigned long accept = 0;
1316954ea748SAriel Elior 
1317954ea748SAriel Elior 			/* covert VF-PF if mask to bnx2x accept flags */
1318954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1319954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1320954ea748SAriel Elior 
1321954ea748SAriel Elior 			if (msg->rx_mask &
1322954ea748SAriel Elior 					VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1323954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1324954ea748SAriel Elior 
1325954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1326954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1327954ea748SAriel Elior 
1328954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1329954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1330954ea748SAriel Elior 
1331954ea748SAriel Elior 			if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1332954ea748SAriel Elior 				__set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1333954ea748SAriel Elior 
1334954ea748SAriel Elior 			/* A packet arriving the vf's mac should be accepted
1335954ea748SAriel Elior 			 * with any vlan
1336954ea748SAriel Elior 			 */
1337954ea748SAriel Elior 			__set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1338954ea748SAriel Elior 
1339954ea748SAriel Elior 			/* set rx-mode */
1340954ea748SAriel Elior 			rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1341954ea748SAriel Elior 						   msg->vf_qid, accept);
1342954ea748SAriel Elior 			if (rc) {
1343954ea748SAriel Elior 				vfop->rc = rc;
1344954ea748SAriel Elior 				goto op_err;
1345954ea748SAriel Elior 			}
1346954ea748SAriel Elior 			return;
1347954ea748SAriel Elior 		}
1348954ea748SAriel Elior 		/* fall through */
1349954ea748SAriel Elior 
1350954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1351954ea748SAriel Elior 		/* next state */
1352954ea748SAriel Elior 		vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1353954ea748SAriel Elior 
1354954ea748SAriel Elior 		if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1355954ea748SAriel Elior 			/* set mcasts */
1356954ea748SAriel Elior 			rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1357954ea748SAriel Elior 						  msg->n_multicast, false);
1358954ea748SAriel Elior 			if (rc) {
1359954ea748SAriel Elior 				vfop->rc = rc;
1360954ea748SAriel Elior 				goto op_err;
1361954ea748SAriel Elior 			}
1362954ea748SAriel Elior 			return;
1363954ea748SAriel Elior 		}
1364954ea748SAriel Elior 		/* fall through */
1365954ea748SAriel Elior op_done:
1366954ea748SAriel Elior 	case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1367954ea748SAriel Elior 		bnx2x_vfop_end(bp, vf, vfop);
1368954ea748SAriel Elior 		return;
1369954ea748SAriel Elior op_err:
1370954ea748SAriel Elior 	BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1371954ea748SAriel Elior 		  vf->abs_vfid, msg->vf_qid, vfop->rc);
1372954ea748SAriel Elior 	goto op_done;
1373954ea748SAriel Elior 
1374954ea748SAriel Elior 	default:
1375954ea748SAriel Elior 		bnx2x_vfop_default(state);
1376954ea748SAriel Elior 	}
1377954ea748SAriel Elior }
1378954ea748SAriel Elior 
1379954ea748SAriel Elior static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1380954ea748SAriel Elior 					struct bnx2x_virtf *vf,
1381954ea748SAriel Elior 					struct bnx2x_vfop_cmd *cmd)
1382954ea748SAriel Elior {
1383954ea748SAriel Elior 	struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1384954ea748SAriel Elior 	if (vfop) {
1385954ea748SAriel Elior 		bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1386954ea748SAriel Elior 				 bnx2x_vfop_mbx_qfilters, cmd->done);
1387954ea748SAriel Elior 		return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1388954ea748SAriel Elior 					     cmd->block);
1389954ea748SAriel Elior 	}
1390954ea748SAriel Elior 	return -ENOMEM;
1391954ea748SAriel Elior }
1392954ea748SAriel Elior 
1393954ea748SAriel Elior static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1394954ea748SAriel Elior 				       struct bnx2x_virtf *vf,
1395954ea748SAriel Elior 				       struct bnx2x_vf_mbx *mbx)
1396954ea748SAriel Elior {
1397954ea748SAriel Elior 	struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1398abc5a021SAriel Elior 	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1399954ea748SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1400954ea748SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1401954ea748SAriel Elior 		.block = false,
1402954ea748SAriel Elior 	};
1403954ea748SAriel Elior 
1404abc5a021SAriel Elior 	/* if a mac was already set for this VF via the set vf mac ndo, we only
1405abc5a021SAriel Elior 	 * accept mac configurations of that mac. Why accept them at all?
1406abc5a021SAriel Elior 	 * because PF may have been unable to configure the mac at the time
1407abc5a021SAriel Elior 	 * since queue was not set up.
1408abc5a021SAriel Elior 	 */
1409abc5a021SAriel Elior 	if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1410abc5a021SAriel Elior 		/* once a mac was set by ndo can only accept a single mac... */
1411abc5a021SAriel Elior 		if (filters->n_mac_vlan_filters > 1) {
1412abc5a021SAriel Elior 			BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1413abc5a021SAriel Elior 				  vf->abs_vfid);
1414abc5a021SAriel Elior 			vf->op_rc = -EPERM;
1415abc5a021SAriel Elior 			goto response;
1416abc5a021SAriel Elior 		}
1417abc5a021SAriel Elior 
1418abc5a021SAriel Elior 		/* ...and only the mac set by the ndo */
1419abc5a021SAriel Elior 		if (filters->n_mac_vlan_filters == 1 &&
1420abc5a021SAriel Elior 		    memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1421abc5a021SAriel Elior 			BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1422abc5a021SAriel Elior 				  vf->abs_vfid);
1423abc5a021SAriel Elior 
1424abc5a021SAriel Elior 			vf->op_rc = -EPERM;
1425abc5a021SAriel Elior 			goto response;
1426abc5a021SAriel Elior 		}
1427abc5a021SAriel Elior 	}
1428abc5a021SAriel Elior 
1429954ea748SAriel Elior 	/* verify vf_qid */
1430954ea748SAriel Elior 	if (filters->vf_qid > vf_rxq_count(vf))
1431954ea748SAriel Elior 		goto response;
1432954ea748SAriel Elior 
1433954ea748SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1434954ea748SAriel Elior 	   vf->abs_vfid,
1435954ea748SAriel Elior 	   filters->vf_qid);
1436954ea748SAriel Elior 
1437954ea748SAriel Elior 	/* print q_filter message */
1438954ea748SAriel Elior 	bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1439954ea748SAriel Elior 
1440954ea748SAriel Elior 	vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1441954ea748SAriel Elior 	if (vf->op_rc)
1442954ea748SAriel Elior 		goto response;
1443954ea748SAriel Elior 	return;
1444954ea748SAriel Elior 
1445954ea748SAriel Elior response:
1446954ea748SAriel Elior 	bnx2x_vf_mbx_resp(bp, vf);
1447954ea748SAriel Elior }
1448954ea748SAriel Elior 
1449463a68a7SAriel Elior static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1450463a68a7SAriel Elior 				    struct bnx2x_vf_mbx *mbx)
1451463a68a7SAriel Elior {
1452463a68a7SAriel Elior 	int qid = mbx->msg->req.q_op.vf_qid;
1453463a68a7SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1454463a68a7SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1455463a68a7SAriel Elior 		.block = false,
1456463a68a7SAriel Elior 	};
1457463a68a7SAriel Elior 
1458463a68a7SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1459463a68a7SAriel Elior 	   vf->abs_vfid, qid);
1460463a68a7SAriel Elior 
1461463a68a7SAriel Elior 	vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1462463a68a7SAriel Elior 	if (vf->op_rc)
1463463a68a7SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
1464463a68a7SAriel Elior }
1465463a68a7SAriel Elior 
146699e9d211SAriel Elior static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
146799e9d211SAriel Elior 				  struct bnx2x_vf_mbx *mbx)
146899e9d211SAriel Elior {
146999e9d211SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
147099e9d211SAriel Elior 		.done = bnx2x_vf_mbx_resp,
147199e9d211SAriel Elior 		.block = false,
147299e9d211SAriel Elior 	};
147399e9d211SAriel Elior 
147499e9d211SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
147599e9d211SAriel Elior 
147699e9d211SAriel Elior 	vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
147799e9d211SAriel Elior 	if (vf->op_rc)
147899e9d211SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
147999e9d211SAriel Elior }
148099e9d211SAriel Elior 
1481f1929b01SAriel Elior static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1482f1929b01SAriel Elior 				    struct bnx2x_vf_mbx *mbx)
1483f1929b01SAriel Elior {
1484f1929b01SAriel Elior 	struct bnx2x_vfop_cmd cmd = {
1485f1929b01SAriel Elior 		.done = bnx2x_vf_mbx_resp,
1486f1929b01SAriel Elior 		.block = false,
1487f1929b01SAriel Elior 	};
1488f1929b01SAriel Elior 
1489f1929b01SAriel Elior 	DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1490f1929b01SAriel Elior 
1491f1929b01SAriel Elior 	vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1492f1929b01SAriel Elior 	if (vf->op_rc)
1493f1929b01SAriel Elior 		bnx2x_vf_mbx_resp(bp, vf);
1494f1929b01SAriel Elior }
1495f1929b01SAriel Elior 
1496fd1fc79dSAriel Elior /* dispatch request */
1497fd1fc79dSAriel Elior static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1498fd1fc79dSAriel Elior 				  struct bnx2x_vf_mbx *mbx)
1499fd1fc79dSAriel Elior {
1500fd1fc79dSAriel Elior 	int i;
1501fd1fc79dSAriel Elior 
1502fd1fc79dSAriel Elior 	/* check if tlv type is known */
1503fd1fc79dSAriel Elior 	if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
15048ca5e17eSAriel Elior 		/* Lock the per vf op mutex and note the locker's identity.
15058ca5e17eSAriel Elior 		 * The unlock will take place in mbx response.
15068ca5e17eSAriel Elior 		 */
15078ca5e17eSAriel Elior 		bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
15088ca5e17eSAriel Elior 
1509fd1fc79dSAriel Elior 		/* switch on the opcode */
1510fd1fc79dSAriel Elior 		switch (mbx->first_tlv.tl.type) {
15118ca5e17eSAriel Elior 		case CHANNEL_TLV_ACQUIRE:
15128ca5e17eSAriel Elior 			bnx2x_vf_mbx_acquire(bp, vf, mbx);
15138ca5e17eSAriel Elior 			break;
1514b93288d5SAriel Elior 		case CHANNEL_TLV_INIT:
1515b93288d5SAriel Elior 			bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1516b93288d5SAriel Elior 			break;
15178db573baSAriel Elior 		case CHANNEL_TLV_SETUP_Q:
15188db573baSAriel Elior 			bnx2x_vf_mbx_setup_q(bp, vf, mbx);
15198db573baSAriel Elior 			break;
1520954ea748SAriel Elior 		case CHANNEL_TLV_SET_Q_FILTERS:
1521954ea748SAriel Elior 			bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1522954ea748SAriel Elior 			break;
1523463a68a7SAriel Elior 		case CHANNEL_TLV_TEARDOWN_Q:
1524463a68a7SAriel Elior 			bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1525463a68a7SAriel Elior 			break;
152699e9d211SAriel Elior 		case CHANNEL_TLV_CLOSE:
152799e9d211SAriel Elior 			bnx2x_vf_mbx_close_vf(bp, vf, mbx);
152899e9d211SAriel Elior 			break;
1529f1929b01SAriel Elior 		case CHANNEL_TLV_RELEASE:
1530f1929b01SAriel Elior 			bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1531f1929b01SAriel Elior 			break;
1532fd1fc79dSAriel Elior 		}
1533463a68a7SAriel Elior 
1534fd1fc79dSAriel Elior 	} else {
1535fd1fc79dSAriel Elior 		/* unknown TLV - this may belong to a VF driver from the future
1536fd1fc79dSAriel Elior 		 * - a version written after this PF driver was written, which
1537fd1fc79dSAriel Elior 		 * supports features unknown as of yet. Too bad since we don't
1538fd1fc79dSAriel Elior 		 * support them. Or this may be because someone wrote a crappy
1539fd1fc79dSAriel Elior 		 * VF driver and is sending garbage over the channel.
1540fd1fc79dSAriel Elior 		 */
1541fd1fc79dSAriel Elior 		BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
1542fd1fc79dSAriel Elior 			  mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
1543fd1fc79dSAriel Elior 		for (i = 0; i < 20; i++)
1544fd1fc79dSAriel Elior 			DP_CONT(BNX2X_MSG_IOV, "%x ",
1545fd1fc79dSAriel Elior 				mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
15468ca5e17eSAriel Elior 
15478ca5e17eSAriel Elior 		/* test whether we can respond to the VF (do we have an address
15488ca5e17eSAriel Elior 		 * for it?)
15498ca5e17eSAriel Elior 		 */
15508ca5e17eSAriel Elior 		if (vf->state == VF_ACQUIRED) {
15518ca5e17eSAriel Elior 			/* mbx_resp uses the op_rc of the VF */
15528ca5e17eSAriel Elior 			vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
15538ca5e17eSAriel Elior 
15548ca5e17eSAriel Elior 			/* notify the VF that we do not support this request */
15558ca5e17eSAriel Elior 			bnx2x_vf_mbx_resp(bp, vf);
15568ca5e17eSAriel Elior 		} else {
15578ca5e17eSAriel Elior 			/* can't send a response since this VF is unknown to us
15588ca5e17eSAriel Elior 			 * just unlock the channel and be done with.
15598ca5e17eSAriel Elior 			 */
15608ca5e17eSAriel Elior 			bnx2x_unlock_vf_pf_channel(bp, vf,
15618ca5e17eSAriel Elior 						   mbx->first_tlv.tl.type);
15628ca5e17eSAriel Elior 		}
1563fd1fc79dSAriel Elior 	}
1564fd1fc79dSAriel Elior }
1565fd1fc79dSAriel Elior 
1566fd1fc79dSAriel Elior /* handle new vf-pf message */
1567fd1fc79dSAriel Elior void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1568fd1fc79dSAriel Elior {
1569fd1fc79dSAriel Elior 	struct bnx2x_virtf *vf;
1570fd1fc79dSAriel Elior 	struct bnx2x_vf_mbx *mbx;
1571fd1fc79dSAriel Elior 	u8 vf_idx;
1572fd1fc79dSAriel Elior 	int rc;
1573fd1fc79dSAriel Elior 
1574fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV,
1575fd1fc79dSAriel Elior 	   "vf pf event received: vfid %d, address_hi %x, address lo %x",
1576fd1fc79dSAriel Elior 	   vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1577fd1fc79dSAriel Elior 	/* Sanity checks consider removing later */
1578fd1fc79dSAriel Elior 
1579fd1fc79dSAriel Elior 	/* check if the vf_id is valid */
1580fd1fc79dSAriel Elior 	if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1581fd1fc79dSAriel Elior 	    BNX2X_NR_VIRTFN(bp)) {
1582fd1fc79dSAriel Elior 		BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1583fd1fc79dSAriel Elior 			  vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1584fd1fc79dSAriel Elior 		goto mbx_done;
1585fd1fc79dSAriel Elior 	}
1586fd1fc79dSAriel Elior 	vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1587fd1fc79dSAriel Elior 	mbx = BP_VF_MBX(bp, vf_idx);
1588fd1fc79dSAriel Elior 
1589fd1fc79dSAriel Elior 	/* verify an event is not currently being processed -
1590fd1fc79dSAriel Elior 	 * debug failsafe only
1591fd1fc79dSAriel Elior 	 */
1592fd1fc79dSAriel Elior 	if (mbx->flags & VF_MSG_INPROCESS) {
1593fd1fc79dSAriel Elior 		BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1594fd1fc79dSAriel Elior 			  vfpf_event->vf_id);
1595fd1fc79dSAriel Elior 		goto mbx_done;
1596fd1fc79dSAriel Elior 	}
1597fd1fc79dSAriel Elior 	vf = BP_VF(bp, vf_idx);
1598fd1fc79dSAriel Elior 
1599fd1fc79dSAriel Elior 	/* save the VF message address */
1600fd1fc79dSAriel Elior 	mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1601fd1fc79dSAriel Elior 	mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1602fd1fc79dSAriel Elior 	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1603fd1fc79dSAriel Elior 	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1604fd1fc79dSAriel Elior 
1605fd1fc79dSAriel Elior 	/* dmae to get the VF request */
1606fd1fc79dSAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1607fd1fc79dSAriel Elior 				  mbx->vf_addr_hi, mbx->vf_addr_lo,
1608fd1fc79dSAriel Elior 				  sizeof(union vfpf_tlvs)/4);
1609fd1fc79dSAriel Elior 	if (rc) {
1610fd1fc79dSAriel Elior 		BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1611fd1fc79dSAriel Elior 		goto mbx_error;
1612fd1fc79dSAriel Elior 	}
1613fd1fc79dSAriel Elior 
1614fd1fc79dSAriel Elior 	/* process the VF message header */
1615fd1fc79dSAriel Elior 	mbx->first_tlv = mbx->msg->req.first_tlv;
1616fd1fc79dSAriel Elior 
1617fd1fc79dSAriel Elior 	/* dispatch the request (will prepare the response) */
1618fd1fc79dSAriel Elior 	bnx2x_vf_mbx_request(bp, vf, mbx);
1619fd1fc79dSAriel Elior 	goto mbx_done;
1620fd1fc79dSAriel Elior 
1621fd1fc79dSAriel Elior mbx_error:
1622f1929b01SAriel Elior 	bnx2x_vf_release(bp, vf, false); /* non blocking */
1623fd1fc79dSAriel Elior mbx_done:
1624fd1fc79dSAriel Elior 	return;
1625fd1fc79dSAriel Elior }
1626abc5a021SAriel Elior 
1627abc5a021SAriel Elior /* propagate local bulletin board to vf */
1628abc5a021SAriel Elior int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1629abc5a021SAriel Elior {
1630abc5a021SAriel Elior 	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1631abc5a021SAriel Elior 	dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1632abc5a021SAriel Elior 		vf * BULLETIN_CONTENT_SIZE;
1633abc5a021SAriel Elior 	dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1634abc5a021SAriel Elior 	int rc;
1635abc5a021SAriel Elior 
1636abc5a021SAriel Elior 	/* can only update vf after init took place */
1637abc5a021SAriel Elior 	if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1638abc5a021SAriel Elior 	    bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1639abc5a021SAriel Elior 		return 0;
1640abc5a021SAriel Elior 
1641abc5a021SAriel Elior 	/* increment bulletin board version and compute crc */
1642abc5a021SAriel Elior 	bulletin->version++;
16434c133c39SAriel Elior 	bulletin->length = BULLETIN_CONTENT_SIZE;
1644abc5a021SAriel Elior 	bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1645abc5a021SAriel Elior 
1646abc5a021SAriel Elior 	/* propagate bulletin board via dmae to vm memory */
1647abc5a021SAriel Elior 	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1648abc5a021SAriel Elior 				  bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
16494c133c39SAriel Elior 				  U64_LO(vf_addr), bulletin->length / 4);
1650abc5a021SAriel Elior 	return rc;
1651abc5a021SAriel Elior }
1652