18c2ecf20Sopenharmony_ci/* bnx2x_vfpf.c: QLogic Everest network driver.
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2009-2013 Broadcom Corporation
48c2ecf20Sopenharmony_ci * Copyright 2014 QLogic Corporation
58c2ecf20Sopenharmony_ci * All rights reserved
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Unless you and QLogic execute a separate written software license
88c2ecf20Sopenharmony_ci * agreement governing use of this software, this software is licensed to you
98c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License version 2, available
108c2ecf20Sopenharmony_ci * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * Notwithstanding the above, under no circumstances may you combine this
138c2ecf20Sopenharmony_ci * software in any way with any other QLogic software provided under a
148c2ecf20Sopenharmony_ci * license other than the GPL, without QLogic's express prior written
158c2ecf20Sopenharmony_ci * consent.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
188c2ecf20Sopenharmony_ci * Written by: Shmulik Ravid
198c2ecf20Sopenharmony_ci *	       Ariel Elior <ariel.elior@qlogic.com>
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "bnx2x.h"
238c2ecf20Sopenharmony_ci#include "bnx2x_cmn.h"
248c2ecf20Sopenharmony_ci#include <linux/crc32.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* place a given tlv on the tlv buffer at a given offset */
298c2ecf20Sopenharmony_cistatic void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
308c2ecf20Sopenharmony_ci			  u16 offset, u16 type, u16 length)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	struct channel_tlv *tl =
338c2ecf20Sopenharmony_ci		(struct channel_tlv *)(tlvs_list + offset);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	tl->type = type;
368c2ecf20Sopenharmony_ci	tl->length = length;
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Clear the mailbox and init the header of the first tlv */
408c2ecf20Sopenharmony_cistatic void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
418c2ecf20Sopenharmony_ci			    u16 type, u16 length)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	mutex_lock(&bp->vf2pf_mutex);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
468c2ecf20Sopenharmony_ci	   type);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	/* Clear mailbox */
498c2ecf20Sopenharmony_ci	memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	/* init type and length */
528c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	/* init first tlv header */
558c2ecf20Sopenharmony_ci	first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* releases the mailbox */
598c2ecf20Sopenharmony_cistatic void bnx2x_vfpf_finalize(struct bnx2x *bp,
608c2ecf20Sopenharmony_ci				struct vfpf_first_tlv *first_tlv)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
638c2ecf20Sopenharmony_ci	   first_tlv->tl.type);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	mutex_unlock(&bp->vf2pf_mutex);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
698c2ecf20Sopenharmony_cistatic void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
708c2ecf20Sopenharmony_ci				   enum channel_tlvs req_tlv)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	do {
758c2ecf20Sopenharmony_ci		if (tlv->type == req_tlv)
768c2ecf20Sopenharmony_ci			return tlv;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci		if (!tlv->length) {
798c2ecf20Sopenharmony_ci			BNX2X_ERR("Found TLV with length 0\n");
808c2ecf20Sopenharmony_ci			return NULL;
818c2ecf20Sopenharmony_ci		}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci		tlvs_list += tlv->length;
848c2ecf20Sopenharmony_ci		tlv = (struct channel_tlv *)tlvs_list;
858c2ecf20Sopenharmony_ci	} while (tlv->type != CHANNEL_TLV_LIST_END);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	return NULL;
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* list the types and lengths of the tlvs on the buffer */
938c2ecf20Sopenharmony_cistatic void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	int i = 1;
968c2ecf20Sopenharmony_ci	struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	while (tlv->type != CHANNEL_TLV_LIST_END) {
998c2ecf20Sopenharmony_ci		/* output tlv */
1008c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
1018c2ecf20Sopenharmony_ci		   tlv->type, tlv->length);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci		/* advance to next tlv */
1048c2ecf20Sopenharmony_ci		tlvs_list += tlv->length;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci		/* cast general tlv list pointer to channel tlv header*/
1078c2ecf20Sopenharmony_ci		tlv = (struct channel_tlv *)tlvs_list;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci		i++;
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci		/* break condition for this loop */
1128c2ecf20Sopenharmony_ci		if (i > MAX_TLVS_IN_LIST) {
1138c2ecf20Sopenharmony_ci			WARN(true, "corrupt tlvs");
1148c2ecf20Sopenharmony_ci			return;
1158c2ecf20Sopenharmony_ci		}
1168c2ecf20Sopenharmony_ci	}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/* output last tlv */
1198c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
1208c2ecf20Sopenharmony_ci	   tlv->type, tlv->length);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* test whether we support a tlv type */
1248c2ecf20Sopenharmony_cibool bnx2x_tlv_supported(u16 tlvtype)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline int bnx2x_pfvf_status_codes(int rc)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	switch (rc) {
1328c2ecf20Sopenharmony_ci	case 0:
1338c2ecf20Sopenharmony_ci		return PFVF_STATUS_SUCCESS;
1348c2ecf20Sopenharmony_ci	case -ENOMEM:
1358c2ecf20Sopenharmony_ci		return PFVF_STATUS_NO_RESOURCE;
1368c2ecf20Sopenharmony_ci	default:
1378c2ecf20Sopenharmony_ci		return PFVF_STATUS_FAILURE;
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	struct cstorm_vf_zone_data __iomem *zone_data =
1448c2ecf20Sopenharmony_ci		REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
1458c2ecf20Sopenharmony_ci	int tout = 100, interval = 100; /* wait for 10 seconds */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	if (*done) {
1488c2ecf20Sopenharmony_ci		BNX2X_ERR("done was non zero before message to pf was sent\n");
1498c2ecf20Sopenharmony_ci		WARN_ON(true);
1508c2ecf20Sopenharmony_ci		return -EINVAL;
1518c2ecf20Sopenharmony_ci	}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/* if PF indicated channel is down avoid sending message. Return success
1548c2ecf20Sopenharmony_ci	 * so calling flow can continue
1558c2ecf20Sopenharmony_ci	 */
1568c2ecf20Sopenharmony_ci	bnx2x_sample_bulletin(bp);
1578c2ecf20Sopenharmony_ci	if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
1588c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
1598c2ecf20Sopenharmony_ci		*done = PFVF_STATUS_SUCCESS;
1608c2ecf20Sopenharmony_ci		return -EINVAL;
1618c2ecf20Sopenharmony_ci	}
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	/* Write message address */
1648c2ecf20Sopenharmony_ci	writel(U64_LO(msg_mapping),
1658c2ecf20Sopenharmony_ci	       &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
1668c2ecf20Sopenharmony_ci	writel(U64_HI(msg_mapping),
1678c2ecf20Sopenharmony_ci	       &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	/* make sure the address is written before FW accesses it */
1708c2ecf20Sopenharmony_ci	wmb();
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	/* Trigger the PF FW */
1738c2ecf20Sopenharmony_ci	writeb_relaxed(1, &zone_data->trigger.vf_pf_channel.addr_valid);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	/* Wait for PF to complete */
1768c2ecf20Sopenharmony_ci	while ((tout >= 0) && (!*done)) {
1778c2ecf20Sopenharmony_ci		msleep(interval);
1788c2ecf20Sopenharmony_ci		tout -= 1;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci		/* progress indicator - HV can take its own sweet time in
1818c2ecf20Sopenharmony_ci		 * answering VFs...
1828c2ecf20Sopenharmony_ci		 */
1838c2ecf20Sopenharmony_ci		DP_CONT(BNX2X_MSG_IOV, ".");
1848c2ecf20Sopenharmony_ci	}
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	if (!*done) {
1878c2ecf20Sopenharmony_ci		BNX2X_ERR("PF response has timed out\n");
1888c2ecf20Sopenharmony_ci		return -EAGAIN;
1898c2ecf20Sopenharmony_ci	}
1908c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_SP, "Got a response from PF\n");
1918c2ecf20Sopenharmony_ci	return 0;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	u32 me_reg;
1978c2ecf20Sopenharmony_ci	int tout = 10, interval = 100; /* Wait for 1 sec */
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	do {
2008c2ecf20Sopenharmony_ci		/* pxp traps vf read of doorbells and returns me reg value */
2018c2ecf20Sopenharmony_ci		me_reg = readl(bp->doorbells);
2028c2ecf20Sopenharmony_ci		if (GOOD_ME_REG(me_reg))
2038c2ecf20Sopenharmony_ci			break;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci		msleep(interval);
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci		BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
2088c2ecf20Sopenharmony_ci			  me_reg);
2098c2ecf20Sopenharmony_ci	} while (tout-- > 0);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	if (!GOOD_ME_REG(me_reg)) {
2128c2ecf20Sopenharmony_ci		BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
2138c2ecf20Sopenharmony_ci		return -EINVAL;
2148c2ecf20Sopenharmony_ci	}
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	*vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	return 0;
2218c2ecf20Sopenharmony_ci}
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciint bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	int rc = 0, attempts = 0;
2268c2ecf20Sopenharmony_ci	struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
2278c2ecf20Sopenharmony_ci	struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
2288c2ecf20Sopenharmony_ci	struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
2298c2ecf20Sopenharmony_ci	struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
2308c2ecf20Sopenharmony_ci	u32 vf_id;
2318c2ecf20Sopenharmony_ci	bool resources_acquired = false;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
2348c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	if (bnx2x_get_vf_id(bp, &vf_id)) {
2378c2ecf20Sopenharmony_ci		rc = -EAGAIN;
2388c2ecf20Sopenharmony_ci		goto out;
2398c2ecf20Sopenharmony_ci	}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	req->vfdev_info.vf_id = vf_id;
2428c2ecf20Sopenharmony_ci	req->vfdev_info.vf_os = 0;
2438c2ecf20Sopenharmony_ci	req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	req->resc_request.num_rxqs = rx_count;
2468c2ecf20Sopenharmony_ci	req->resc_request.num_txqs = tx_count;
2478c2ecf20Sopenharmony_ci	req->resc_request.num_sbs = bp->igu_sb_cnt;
2488c2ecf20Sopenharmony_ci	req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
2498c2ecf20Sopenharmony_ci	req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
2508c2ecf20Sopenharmony_ci	req->resc_request.num_vlan_filters = VF_ACQUIRE_VLAN_FILTERS;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	/* pf 2 vf bulletin board address */
2538c2ecf20Sopenharmony_ci	req->bulletin_addr = bp->pf2vf_bulletin_mapping;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	/* Request physical port identifier */
2568c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
2578c2ecf20Sopenharmony_ci		      CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/* Bulletin support for bulletin board with length > legacy length */
2608c2ecf20Sopenharmony_ci	req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
2618c2ecf20Sopenharmony_ci	/* vlan filtering is supported */
2628c2ecf20Sopenharmony_ci	req->vfdev_info.caps |= VF_CAP_SUPPORT_VLAN_FILTER;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	/* add list termination tlv */
2658c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req,
2668c2ecf20Sopenharmony_ci		      req->first_tlv.tl.length + sizeof(struct channel_tlv),
2678c2ecf20Sopenharmony_ci		      CHANNEL_TLV_LIST_END,
2688c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/* output tlvs list */
2718c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	while (!resources_acquired) {
2748c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci		/* send acquire request */
2778c2ecf20Sopenharmony_ci		rc = bnx2x_send_msg2pf(bp,
2788c2ecf20Sopenharmony_ci				       &resp->hdr.status,
2798c2ecf20Sopenharmony_ci				       bp->vf2pf_mbox_mapping);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci		/* PF timeout */
2828c2ecf20Sopenharmony_ci		if (rc)
2838c2ecf20Sopenharmony_ci			goto out;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci		/* copy acquire response from buffer to bp */
2868c2ecf20Sopenharmony_ci		memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci		attempts++;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci		/* test whether the PF accepted our request. If not, humble
2918c2ecf20Sopenharmony_ci		 * the request and try again.
2928c2ecf20Sopenharmony_ci		 */
2938c2ecf20Sopenharmony_ci		if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
2948c2ecf20Sopenharmony_ci			DP(BNX2X_MSG_SP, "resources acquired\n");
2958c2ecf20Sopenharmony_ci			resources_acquired = true;
2968c2ecf20Sopenharmony_ci		} else if (bp->acquire_resp.hdr.status ==
2978c2ecf20Sopenharmony_ci			   PFVF_STATUS_NO_RESOURCE &&
2988c2ecf20Sopenharmony_ci			   attempts < VF_ACQUIRE_THRESH) {
2998c2ecf20Sopenharmony_ci			DP(BNX2X_MSG_SP,
3008c2ecf20Sopenharmony_ci			   "PF unwilling to fulfill resource request. Try PF recommended amount\n");
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci			/* humble our request */
3038c2ecf20Sopenharmony_ci			req->resc_request.num_txqs =
3048c2ecf20Sopenharmony_ci				min(req->resc_request.num_txqs,
3058c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_txqs);
3068c2ecf20Sopenharmony_ci			req->resc_request.num_rxqs =
3078c2ecf20Sopenharmony_ci				min(req->resc_request.num_rxqs,
3088c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_rxqs);
3098c2ecf20Sopenharmony_ci			req->resc_request.num_sbs =
3108c2ecf20Sopenharmony_ci				min(req->resc_request.num_sbs,
3118c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_sbs);
3128c2ecf20Sopenharmony_ci			req->resc_request.num_mac_filters =
3138c2ecf20Sopenharmony_ci				min(req->resc_request.num_mac_filters,
3148c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_mac_filters);
3158c2ecf20Sopenharmony_ci			req->resc_request.num_vlan_filters =
3168c2ecf20Sopenharmony_ci				min(req->resc_request.num_vlan_filters,
3178c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_vlan_filters);
3188c2ecf20Sopenharmony_ci			req->resc_request.num_mc_filters =
3198c2ecf20Sopenharmony_ci				min(req->resc_request.num_mc_filters,
3208c2ecf20Sopenharmony_ci				    bp->acquire_resp.resc.num_mc_filters);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci			/* Clear response buffer */
3238c2ecf20Sopenharmony_ci			memset(&bp->vf2pf_mbox->resp, 0,
3248c2ecf20Sopenharmony_ci			       sizeof(union pfvf_tlvs));
3258c2ecf20Sopenharmony_ci		} else {
3268c2ecf20Sopenharmony_ci			/* Determine reason of PF failure of acquire process */
3278c2ecf20Sopenharmony_ci			fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
3288c2ecf20Sopenharmony_ci							    CHANNEL_TLV_FP_HSI_SUPPORT);
3298c2ecf20Sopenharmony_ci			if (fp_hsi_resp && !fp_hsi_resp->is_supported)
3308c2ecf20Sopenharmony_ci				BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
3318c2ecf20Sopenharmony_ci			else
3328c2ecf20Sopenharmony_ci				BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
3338c2ecf20Sopenharmony_ci					  bp->acquire_resp.hdr.status);
3348c2ecf20Sopenharmony_ci			rc = -EAGAIN;
3358c2ecf20Sopenharmony_ci			goto out;
3368c2ecf20Sopenharmony_ci		}
3378c2ecf20Sopenharmony_ci	}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* Retrieve physical port id (if possible) */
3408c2ecf20Sopenharmony_ci	phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
3418c2ecf20Sopenharmony_ci			 bnx2x_search_tlv_list(bp, resp,
3428c2ecf20Sopenharmony_ci					       CHANNEL_TLV_PHYS_PORT_ID);
3438c2ecf20Sopenharmony_ci	if (phys_port_resp) {
3448c2ecf20Sopenharmony_ci		memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
3458c2ecf20Sopenharmony_ci		bp->flags |= HAS_PHYS_PORT_ID;
3468c2ecf20Sopenharmony_ci	}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	/* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
3498c2ecf20Sopenharmony_ci	 * If that's the case, we need to make certain required FW was
3508c2ecf20Sopenharmony_ci	 * supported by such a hypervisor [i.e., v0-v2].
3518c2ecf20Sopenharmony_ci	 */
3528c2ecf20Sopenharmony_ci	fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
3538c2ecf20Sopenharmony_ci					    CHANNEL_TLV_FP_HSI_SUPPORT);
3548c2ecf20Sopenharmony_ci	if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
3558c2ecf20Sopenharmony_ci		BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci		/* Since acquire succeeded on the PF side, we need to send a
3588c2ecf20Sopenharmony_ci		 * release message in order to allow future probes.
3598c2ecf20Sopenharmony_ci		 */
3608c2ecf20Sopenharmony_ci		bnx2x_vfpf_finalize(bp, &req->first_tlv);
3618c2ecf20Sopenharmony_ci		bnx2x_vfpf_release(bp);
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci		rc = -EINVAL;
3648c2ecf20Sopenharmony_ci		goto out;
3658c2ecf20Sopenharmony_ci	}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	/* get HW info */
3688c2ecf20Sopenharmony_ci	bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
3698c2ecf20Sopenharmony_ci	bp->link_params.chip_id = bp->common.chip_id;
3708c2ecf20Sopenharmony_ci	bp->db_size = bp->acquire_resp.pfdev_info.db_size;
3718c2ecf20Sopenharmony_ci	bp->common.int_block = INT_BLOCK_IGU;
3728c2ecf20Sopenharmony_ci	bp->common.chip_port_mode = CHIP_2_PORT_MODE;
3738c2ecf20Sopenharmony_ci	bp->igu_dsb_id = -1;
3748c2ecf20Sopenharmony_ci	bp->mf_ov = 0;
3758c2ecf20Sopenharmony_ci	bp->mf_mode = 0;
3768c2ecf20Sopenharmony_ci	bp->common.flash_size = 0;
3778c2ecf20Sopenharmony_ci	bp->flags |=
3788c2ecf20Sopenharmony_ci		NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
3798c2ecf20Sopenharmony_ci	bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
3808c2ecf20Sopenharmony_ci	bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
3818c2ecf20Sopenharmony_ci	bp->vlan_credit = bp->acquire_resp.resc.num_vlan_filters;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
3848c2ecf20Sopenharmony_ci		sizeof(bp->fw_ver));
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
3878c2ecf20Sopenharmony_ci		memcpy(bp->dev->dev_addr,
3888c2ecf20Sopenharmony_ci		       bp->acquire_resp.resc.current_mac_addr,
3898c2ecf20Sopenharmony_ci		       ETH_ALEN);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ciout:
3928c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
3938c2ecf20Sopenharmony_ci	return rc;
3948c2ecf20Sopenharmony_ci}
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ciint bnx2x_vfpf_release(struct bnx2x *bp)
3978c2ecf20Sopenharmony_ci{
3988c2ecf20Sopenharmony_ci	struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
3998c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4008c2ecf20Sopenharmony_ci	u32 rc, vf_id;
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
4038c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	if (bnx2x_get_vf_id(bp, &vf_id)) {
4068c2ecf20Sopenharmony_ci		rc = -EAGAIN;
4078c2ecf20Sopenharmony_ci		goto out;
4088c2ecf20Sopenharmony_ci	}
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	req->vf_id = vf_id;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	/* add list termination tlv */
4138c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
4148c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	/* output tlvs list */
4178c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	/* send release request */
4208c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	if (rc)
4238c2ecf20Sopenharmony_ci		/* PF timeout */
4248c2ecf20Sopenharmony_ci		goto out;
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
4278c2ecf20Sopenharmony_ci		/* PF released us */
4288c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_SP, "vf released\n");
4298c2ecf20Sopenharmony_ci	} else {
4308c2ecf20Sopenharmony_ci		/* PF reports error */
4318c2ecf20Sopenharmony_ci		BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
4328c2ecf20Sopenharmony_ci			  resp->hdr.status);
4338c2ecf20Sopenharmony_ci		rc = -EAGAIN;
4348c2ecf20Sopenharmony_ci		goto out;
4358c2ecf20Sopenharmony_ci	}
4368c2ecf20Sopenharmony_ciout:
4378c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	return rc;
4408c2ecf20Sopenharmony_ci}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci/* Tell PF about SB addresses */
4438c2ecf20Sopenharmony_ciint bnx2x_vfpf_init(struct bnx2x *bp)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
4468c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4478c2ecf20Sopenharmony_ci	int rc, i;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
4508c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	/* status blocks */
4538c2ecf20Sopenharmony_ci	for_each_eth_queue(bp, i)
4548c2ecf20Sopenharmony_ci		req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
4558c2ecf20Sopenharmony_ci						       status_blk_mapping);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	/* statistics - requests only supports single queue for now */
4588c2ecf20Sopenharmony_ci	req->stats_addr = bp->fw_stats_data_mapping +
4598c2ecf20Sopenharmony_ci			  offsetof(struct bnx2x_fw_stats_data, queue_stats);
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	req->stats_stride = sizeof(struct per_queue_stats);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	/* add list termination tlv */
4648c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
4658c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	/* output tlvs list */
4688c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
4718c2ecf20Sopenharmony_ci	if (rc)
4728c2ecf20Sopenharmony_ci		goto out;
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
4758c2ecf20Sopenharmony_ci		BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
4768c2ecf20Sopenharmony_ci			  resp->hdr.status);
4778c2ecf20Sopenharmony_ci		rc = -EAGAIN;
4788c2ecf20Sopenharmony_ci		goto out;
4798c2ecf20Sopenharmony_ci	}
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
4828c2ecf20Sopenharmony_ciout:
4838c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci	return rc;
4868c2ecf20Sopenharmony_ci}
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci/* CLOSE VF - opposite to INIT_VF */
4898c2ecf20Sopenharmony_civoid bnx2x_vfpf_close_vf(struct bnx2x *bp)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
4928c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
4938c2ecf20Sopenharmony_ci	int i, rc;
4948c2ecf20Sopenharmony_ci	u32 vf_id;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	/* If we haven't got a valid VF id, there is no sense to
4978c2ecf20Sopenharmony_ci	 * continue with sending messages
4988c2ecf20Sopenharmony_ci	 */
4998c2ecf20Sopenharmony_ci	if (bnx2x_get_vf_id(bp, &vf_id))
5008c2ecf20Sopenharmony_ci		goto free_irq;
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	/* Close the queues */
5038c2ecf20Sopenharmony_ci	for_each_queue(bp, i)
5048c2ecf20Sopenharmony_ci		bnx2x_vfpf_teardown_queue(bp, i);
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	/* remove mac */
5078c2ecf20Sopenharmony_ci	bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
5108c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	req->vf_id = vf_id;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	/* add list termination tlv */
5158c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
5168c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	/* output tlvs list */
5198c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci	if (rc)
5248c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
5278c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
5288c2ecf20Sopenharmony_ci			  resp->hdr.status);
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_cifree_irq:
5338c2ecf20Sopenharmony_ci	/* Disable HW interrupts, NAPI */
5348c2ecf20Sopenharmony_ci	bnx2x_netif_stop(bp, 0);
5358c2ecf20Sopenharmony_ci	/* Delete all NAPI objects */
5368c2ecf20Sopenharmony_ci	bnx2x_del_all_napi(bp);
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	/* Release IRQs */
5398c2ecf20Sopenharmony_ci	bnx2x_free_irq(bp);
5408c2ecf20Sopenharmony_ci}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_cistatic void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
5438c2ecf20Sopenharmony_ci				   struct bnx2x_vf_queue *q)
5448c2ecf20Sopenharmony_ci{
5458c2ecf20Sopenharmony_ci	u8 cl_id = vfq_cl_id(vf, q);
5468c2ecf20Sopenharmony_ci	u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	/* mac */
5498c2ecf20Sopenharmony_ci	bnx2x_init_mac_obj(bp, &q->mac_obj,
5508c2ecf20Sopenharmony_ci			   cl_id, q->cid, func_id,
5518c2ecf20Sopenharmony_ci			   bnx2x_vf_sp(bp, vf, mac_rdata),
5528c2ecf20Sopenharmony_ci			   bnx2x_vf_sp_map(bp, vf, mac_rdata),
5538c2ecf20Sopenharmony_ci			   BNX2X_FILTER_MAC_PENDING,
5548c2ecf20Sopenharmony_ci			   &vf->filter_state,
5558c2ecf20Sopenharmony_ci			   BNX2X_OBJ_TYPE_RX_TX,
5568c2ecf20Sopenharmony_ci			   &vf->vf_macs_pool);
5578c2ecf20Sopenharmony_ci	/* vlan */
5588c2ecf20Sopenharmony_ci	bnx2x_init_vlan_obj(bp, &q->vlan_obj,
5598c2ecf20Sopenharmony_ci			    cl_id, q->cid, func_id,
5608c2ecf20Sopenharmony_ci			    bnx2x_vf_sp(bp, vf, vlan_rdata),
5618c2ecf20Sopenharmony_ci			    bnx2x_vf_sp_map(bp, vf, vlan_rdata),
5628c2ecf20Sopenharmony_ci			    BNX2X_FILTER_VLAN_PENDING,
5638c2ecf20Sopenharmony_ci			    &vf->filter_state,
5648c2ecf20Sopenharmony_ci			    BNX2X_OBJ_TYPE_RX_TX,
5658c2ecf20Sopenharmony_ci			    &vf->vf_vlans_pool);
5668c2ecf20Sopenharmony_ci	/* vlan-mac */
5678c2ecf20Sopenharmony_ci	bnx2x_init_vlan_mac_obj(bp, &q->vlan_mac_obj,
5688c2ecf20Sopenharmony_ci				cl_id, q->cid, func_id,
5698c2ecf20Sopenharmony_ci				bnx2x_vf_sp(bp, vf, vlan_mac_rdata),
5708c2ecf20Sopenharmony_ci				bnx2x_vf_sp_map(bp, vf, vlan_mac_rdata),
5718c2ecf20Sopenharmony_ci				BNX2X_FILTER_VLAN_MAC_PENDING,
5728c2ecf20Sopenharmony_ci				&vf->filter_state,
5738c2ecf20Sopenharmony_ci				BNX2X_OBJ_TYPE_RX_TX,
5748c2ecf20Sopenharmony_ci				&vf->vf_macs_pool,
5758c2ecf20Sopenharmony_ci				&vf->vf_vlans_pool);
5768c2ecf20Sopenharmony_ci	/* mcast */
5778c2ecf20Sopenharmony_ci	bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
5788c2ecf20Sopenharmony_ci			     q->cid, func_id, func_id,
5798c2ecf20Sopenharmony_ci			     bnx2x_vf_sp(bp, vf, mcast_rdata),
5808c2ecf20Sopenharmony_ci			     bnx2x_vf_sp_map(bp, vf, mcast_rdata),
5818c2ecf20Sopenharmony_ci			     BNX2X_FILTER_MCAST_PENDING,
5828c2ecf20Sopenharmony_ci			     &vf->filter_state,
5838c2ecf20Sopenharmony_ci			     BNX2X_OBJ_TYPE_RX_TX);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	/* rss */
5868c2ecf20Sopenharmony_ci	bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
5878c2ecf20Sopenharmony_ci				  func_id, func_id,
5888c2ecf20Sopenharmony_ci				  bnx2x_vf_sp(bp, vf, rss_rdata),
5898c2ecf20Sopenharmony_ci				  bnx2x_vf_sp_map(bp, vf, rss_rdata),
5908c2ecf20Sopenharmony_ci				  BNX2X_FILTER_RSS_CONF_PENDING,
5918c2ecf20Sopenharmony_ci				  &vf->filter_state,
5928c2ecf20Sopenharmony_ci				  BNX2X_OBJ_TYPE_RX_TX);
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	vf->leading_rss = cl_id;
5958c2ecf20Sopenharmony_ci	q->is_leading = true;
5968c2ecf20Sopenharmony_ci	q->sp_initialized = true;
5978c2ecf20Sopenharmony_ci}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci/* ask the pf to open a queue for the vf */
6008c2ecf20Sopenharmony_ciint bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
6018c2ecf20Sopenharmony_ci		       bool is_leading)
6028c2ecf20Sopenharmony_ci{
6038c2ecf20Sopenharmony_ci	struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
6048c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6058c2ecf20Sopenharmony_ci	u8 fp_idx = fp->index;
6068c2ecf20Sopenharmony_ci	u16 tpa_agg_size = 0, flags = 0;
6078c2ecf20Sopenharmony_ci	int rc;
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
6108c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	/* select tpa mode to request */
6138c2ecf20Sopenharmony_ci	if (fp->mode != TPA_MODE_DISABLED) {
6148c2ecf20Sopenharmony_ci		flags |= VFPF_QUEUE_FLG_TPA;
6158c2ecf20Sopenharmony_ci		flags |= VFPF_QUEUE_FLG_TPA_IPV6;
6168c2ecf20Sopenharmony_ci		if (fp->mode == TPA_MODE_GRO)
6178c2ecf20Sopenharmony_ci			flags |= VFPF_QUEUE_FLG_TPA_GRO;
6188c2ecf20Sopenharmony_ci		tpa_agg_size = TPA_AGG_SIZE;
6198c2ecf20Sopenharmony_ci	}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	if (is_leading)
6228c2ecf20Sopenharmony_ci		flags |= VFPF_QUEUE_FLG_LEADING_RSS;
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	/* calculate queue flags */
6258c2ecf20Sopenharmony_ci	flags |= VFPF_QUEUE_FLG_STATS;
6268c2ecf20Sopenharmony_ci	flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
6278c2ecf20Sopenharmony_ci	flags |= VFPF_QUEUE_FLG_VLAN;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	/* Common */
6308c2ecf20Sopenharmony_ci	req->vf_qid = fp_idx;
6318c2ecf20Sopenharmony_ci	req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	/* Rx */
6348c2ecf20Sopenharmony_ci	req->rxq.rcq_addr = fp->rx_comp_mapping;
6358c2ecf20Sopenharmony_ci	req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
6368c2ecf20Sopenharmony_ci	req->rxq.rxq_addr = fp->rx_desc_mapping;
6378c2ecf20Sopenharmony_ci	req->rxq.sge_addr = fp->rx_sge_mapping;
6388c2ecf20Sopenharmony_ci	req->rxq.vf_sb = fp_idx;
6398c2ecf20Sopenharmony_ci	req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
6408c2ecf20Sopenharmony_ci	req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
6418c2ecf20Sopenharmony_ci	req->rxq.mtu = bp->dev->mtu;
6428c2ecf20Sopenharmony_ci	req->rxq.buf_sz = fp->rx_buf_size;
6438c2ecf20Sopenharmony_ci	req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
6448c2ecf20Sopenharmony_ci	req->rxq.tpa_agg_sz = tpa_agg_size;
6458c2ecf20Sopenharmony_ci	req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
6468c2ecf20Sopenharmony_ci	req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
6478c2ecf20Sopenharmony_ci			  (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
6488c2ecf20Sopenharmony_ci	req->rxq.flags = flags;
6498c2ecf20Sopenharmony_ci	req->rxq.drop_flags = 0;
6508c2ecf20Sopenharmony_ci	req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
6518c2ecf20Sopenharmony_ci	req->rxq.stat_id = -1; /* No stats at the moment */
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	/* Tx */
6548c2ecf20Sopenharmony_ci	req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
6558c2ecf20Sopenharmony_ci	req->txq.vf_sb = fp_idx;
6568c2ecf20Sopenharmony_ci	req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
6578c2ecf20Sopenharmony_ci	req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
6588c2ecf20Sopenharmony_ci	req->txq.flags = flags;
6598c2ecf20Sopenharmony_ci	req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_ci	/* add list termination tlv */
6628c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
6638c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_ci	/* output tlvs list */
6668c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
6698c2ecf20Sopenharmony_ci	if (rc)
6708c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
6718c2ecf20Sopenharmony_ci			  fp_idx);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
6748c2ecf20Sopenharmony_ci		BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
6758c2ecf20Sopenharmony_ci			  fp_idx, resp->hdr.status);
6768c2ecf20Sopenharmony_ci		rc = -EINVAL;
6778c2ecf20Sopenharmony_ci	}
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	return rc;
6828c2ecf20Sopenharmony_ci}
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_cistatic int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
6858c2ecf20Sopenharmony_ci{
6868c2ecf20Sopenharmony_ci	struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
6878c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
6888c2ecf20Sopenharmony_ci	int rc;
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
6918c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
6928c2ecf20Sopenharmony_ci			sizeof(*req));
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	req->vf_qid = qidx;
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	/* add list termination tlv */
6978c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
6988c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci	/* output tlvs list */
7018c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	if (rc) {
7068c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
7078c2ecf20Sopenharmony_ci			  rc);
7088c2ecf20Sopenharmony_ci		goto out;
7098c2ecf20Sopenharmony_ci	}
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	/* PF failed the transaction */
7128c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
7138c2ecf20Sopenharmony_ci		BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
7148c2ecf20Sopenharmony_ci			  resp->hdr.status);
7158c2ecf20Sopenharmony_ci		rc = -EINVAL;
7168c2ecf20Sopenharmony_ci	}
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ciout:
7198c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	return rc;
7228c2ecf20Sopenharmony_ci}
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci/* request pf to add a mac for the vf */
7258c2ecf20Sopenharmony_ciint bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
7268c2ecf20Sopenharmony_ci{
7278c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
7288c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
7298c2ecf20Sopenharmony_ci	struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
7308c2ecf20Sopenharmony_ci	int rc = 0;
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
7338c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
7348c2ecf20Sopenharmony_ci			sizeof(*req));
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
7378c2ecf20Sopenharmony_ci	req->vf_qid = vf_qid;
7388c2ecf20Sopenharmony_ci	req->n_mac_vlan_filters = 1;
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
7418c2ecf20Sopenharmony_ci	if (set)
7428c2ecf20Sopenharmony_ci		req->filters[0].flags |= VFPF_Q_FILTER_SET;
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	/* sample bulletin board for new mac */
7458c2ecf20Sopenharmony_ci	bnx2x_sample_bulletin(bp);
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_ci	/* copy mac from device to request */
7488c2ecf20Sopenharmony_ci	memcpy(req->filters[0].mac, addr, ETH_ALEN);
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	/* add list termination tlv */
7518c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
7528c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
7538c2ecf20Sopenharmony_ci
7548c2ecf20Sopenharmony_ci	/* output tlvs list */
7558c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	/* send message to pf */
7588c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
7598c2ecf20Sopenharmony_ci	if (rc) {
7608c2ecf20Sopenharmony_ci		BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
7618c2ecf20Sopenharmony_ci		goto out;
7628c2ecf20Sopenharmony_ci	}
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci	/* failure may mean PF was configured with a new mac for us */
7658c2ecf20Sopenharmony_ci	while (resp->hdr.status == PFVF_STATUS_FAILURE) {
7668c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
7678c2ecf20Sopenharmony_ci		   "vfpf SET MAC failed. Check bulletin board for new posts\n");
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci		/* copy mac from bulletin to device */
7708c2ecf20Sopenharmony_ci		memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci		/* check if bulletin board was updated */
7738c2ecf20Sopenharmony_ci		if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
7748c2ecf20Sopenharmony_ci			/* copy mac from device to request */
7758c2ecf20Sopenharmony_ci			memcpy(req->filters[0].mac, bp->dev->dev_addr,
7768c2ecf20Sopenharmony_ci			       ETH_ALEN);
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci			/* send message to pf */
7798c2ecf20Sopenharmony_ci			rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
7808c2ecf20Sopenharmony_ci					       bp->vf2pf_mbox_mapping);
7818c2ecf20Sopenharmony_ci		} else {
7828c2ecf20Sopenharmony_ci			/* no new info in bulletin */
7838c2ecf20Sopenharmony_ci			break;
7848c2ecf20Sopenharmony_ci		}
7858c2ecf20Sopenharmony_ci	}
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
7888c2ecf20Sopenharmony_ci		BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
7898c2ecf20Sopenharmony_ci		rc = -EINVAL;
7908c2ecf20Sopenharmony_ci	}
7918c2ecf20Sopenharmony_ciout:
7928c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	return rc;
7958c2ecf20Sopenharmony_ci}
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci/* request pf to config rss table for vf queues*/
7988c2ecf20Sopenharmony_ciint bnx2x_vfpf_config_rss(struct bnx2x *bp,
7998c2ecf20Sopenharmony_ci			  struct bnx2x_config_rss_params *params)
8008c2ecf20Sopenharmony_ci{
8018c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
8028c2ecf20Sopenharmony_ci	struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
8038c2ecf20Sopenharmony_ci	int rc = 0;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
8068c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
8078c2ecf20Sopenharmony_ci			sizeof(*req));
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	/* add list termination tlv */
8108c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
8118c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
8148c2ecf20Sopenharmony_ci	memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
8158c2ecf20Sopenharmony_ci	req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
8168c2ecf20Sopenharmony_ci	req->rss_key_size = T_ETH_RSS_KEY;
8178c2ecf20Sopenharmony_ci	req->rss_result_mask = params->rss_result_mask;
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci	/* flags handled individually for backward/forward compatibility */
8208c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
8218c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_MODE_DISABLED;
8228c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
8238c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_MODE_REGULAR;
8248c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
8258c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_SET_SRCH;
8268c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
8278c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV4;
8288c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
8298c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV4_TCP;
8308c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
8318c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV4_UDP;
8328c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
8338c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV6;
8348c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
8358c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV6_TCP;
8368c2ecf20Sopenharmony_ci	if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
8378c2ecf20Sopenharmony_ci		req->rss_flags |= VFPF_RSS_IPV6_UDP;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	/* output tlvs list */
8428c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	/* send message to pf */
8458c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
8468c2ecf20Sopenharmony_ci	if (rc) {
8478c2ecf20Sopenharmony_ci		BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
8488c2ecf20Sopenharmony_ci		goto out;
8498c2ecf20Sopenharmony_ci	}
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
8528c2ecf20Sopenharmony_ci		/* Since older drivers don't support this feature (and VF has
8538c2ecf20Sopenharmony_ci		 * no way of knowing other than failing this), don't propagate
8548c2ecf20Sopenharmony_ci		 * an error in this case.
8558c2ecf20Sopenharmony_ci		 */
8568c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
8578c2ecf20Sopenharmony_ci		   "Failed to send rss message to PF over VF-PF channel [%d]\n",
8588c2ecf20Sopenharmony_ci		   resp->hdr.status);
8598c2ecf20Sopenharmony_ci	}
8608c2ecf20Sopenharmony_ciout:
8618c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	return rc;
8648c2ecf20Sopenharmony_ci}
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_ciint bnx2x_vfpf_set_mcast(struct net_device *dev)
8678c2ecf20Sopenharmony_ci{
8688c2ecf20Sopenharmony_ci	struct bnx2x *bp = netdev_priv(dev);
8698c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
8708c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
8718c2ecf20Sopenharmony_ci	int rc = 0, i = 0;
8728c2ecf20Sopenharmony_ci	struct netdev_hw_addr *ha;
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_ci	if (bp->state != BNX2X_STATE_OPEN) {
8758c2ecf20Sopenharmony_ci		DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
8768c2ecf20Sopenharmony_ci		return -EINVAL;
8778c2ecf20Sopenharmony_ci	}
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
8808c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
8818c2ecf20Sopenharmony_ci			sizeof(*req));
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci	/* Get Rx mode requested */
8848c2ecf20Sopenharmony_ci	DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	/* We support PFVF_MAX_MULTICAST_PER_VF mcast addresses tops */
8878c2ecf20Sopenharmony_ci	if (netdev_mc_count(dev) > PFVF_MAX_MULTICAST_PER_VF) {
8888c2ecf20Sopenharmony_ci		DP(NETIF_MSG_IFUP,
8898c2ecf20Sopenharmony_ci		   "VF supports not more than %d multicast MAC addresses\n",
8908c2ecf20Sopenharmony_ci		   PFVF_MAX_MULTICAST_PER_VF);
8918c2ecf20Sopenharmony_ci		rc = -EINVAL;
8928c2ecf20Sopenharmony_ci		goto out;
8938c2ecf20Sopenharmony_ci	}
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci	netdev_for_each_mc_addr(ha, dev) {
8968c2ecf20Sopenharmony_ci		DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
8978c2ecf20Sopenharmony_ci		   bnx2x_mc_addr(ha));
8988c2ecf20Sopenharmony_ci		memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
8998c2ecf20Sopenharmony_ci		i++;
9008c2ecf20Sopenharmony_ci	}
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_ci	req->n_multicast = i;
9038c2ecf20Sopenharmony_ci	req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
9048c2ecf20Sopenharmony_ci	req->vf_qid = 0;
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci	/* add list termination tlv */
9078c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
9088c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	/* output tlvs list */
9118c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
9128c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
9138c2ecf20Sopenharmony_ci	if (rc) {
9148c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending a message failed: %d\n", rc);
9158c2ecf20Sopenharmony_ci		goto out;
9168c2ecf20Sopenharmony_ci	}
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
9198c2ecf20Sopenharmony_ci		BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
9208c2ecf20Sopenharmony_ci			  resp->hdr.status);
9218c2ecf20Sopenharmony_ci		rc = -EINVAL;
9228c2ecf20Sopenharmony_ci	}
9238c2ecf20Sopenharmony_ciout:
9248c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	return rc;
9278c2ecf20Sopenharmony_ci}
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci/* request pf to add a vlan for the vf */
9308c2ecf20Sopenharmony_ciint bnx2x_vfpf_update_vlan(struct bnx2x *bp, u16 vid, u8 vf_qid, bool add)
9318c2ecf20Sopenharmony_ci{
9328c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
9338c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
9348c2ecf20Sopenharmony_ci	int rc = 0;
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	if (!(bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER)) {
9378c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV, "HV does not support vlan filtering\n");
9388c2ecf20Sopenharmony_ci		return 0;
9398c2ecf20Sopenharmony_ci	}
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
9428c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
9438c2ecf20Sopenharmony_ci			sizeof(*req));
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci	req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
9468c2ecf20Sopenharmony_ci	req->vf_qid = vf_qid;
9478c2ecf20Sopenharmony_ci	req->n_mac_vlan_filters = 1;
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	req->filters[0].flags = VFPF_Q_FILTER_VLAN_TAG_VALID;
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	if (add)
9528c2ecf20Sopenharmony_ci		req->filters[0].flags |= VFPF_Q_FILTER_SET;
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci	/* sample bulletin board for hypervisor vlan */
9558c2ecf20Sopenharmony_ci	bnx2x_sample_bulletin(bp);
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	if (bp->shadow_bulletin.content.valid_bitmap & 1 << VLAN_VALID) {
9588c2ecf20Sopenharmony_ci		BNX2X_ERR("Hypervisor will decline the request, avoiding\n");
9598c2ecf20Sopenharmony_ci		rc = -EINVAL;
9608c2ecf20Sopenharmony_ci		goto out;
9618c2ecf20Sopenharmony_ci	}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci	req->filters[0].vlan_tag = vid;
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci	/* add list termination tlv */
9668c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
9678c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	/* output tlvs list */
9708c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
9718c2ecf20Sopenharmony_ci
9728c2ecf20Sopenharmony_ci	/* send message to pf */
9738c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
9748c2ecf20Sopenharmony_ci	if (rc) {
9758c2ecf20Sopenharmony_ci		BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
9768c2ecf20Sopenharmony_ci		goto out;
9778c2ecf20Sopenharmony_ci	}
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
9808c2ecf20Sopenharmony_ci		BNX2X_ERR("vfpf %s VLAN %d failed\n", add ? "add" : "del",
9818c2ecf20Sopenharmony_ci			  vid);
9828c2ecf20Sopenharmony_ci		rc = -EINVAL;
9838c2ecf20Sopenharmony_ci	}
9848c2ecf20Sopenharmony_ciout:
9858c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	return rc;
9888c2ecf20Sopenharmony_ci}
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ciint bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
9918c2ecf20Sopenharmony_ci{
9928c2ecf20Sopenharmony_ci	int mode = bp->rx_mode;
9938c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
9948c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
9958c2ecf20Sopenharmony_ci	int rc;
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_ci	/* clear mailbox and prep first tlv */
9988c2ecf20Sopenharmony_ci	bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
9998c2ecf20Sopenharmony_ci			sizeof(*req));
10008c2ecf20Sopenharmony_ci
10018c2ecf20Sopenharmony_ci	DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	/* Ignore everything accept MODE_NONE */
10048c2ecf20Sopenharmony_ci	if (mode  == BNX2X_RX_MODE_NONE) {
10058c2ecf20Sopenharmony_ci		req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
10068c2ecf20Sopenharmony_ci	} else {
10078c2ecf20Sopenharmony_ci		/* Current PF driver will not look at the specific flags,
10088c2ecf20Sopenharmony_ci		 * but they are required when working with older drivers on hv.
10098c2ecf20Sopenharmony_ci		 */
10108c2ecf20Sopenharmony_ci		req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
10118c2ecf20Sopenharmony_ci		req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
10128c2ecf20Sopenharmony_ci		req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
10138c2ecf20Sopenharmony_ci		if (mode == BNX2X_RX_MODE_PROMISC)
10148c2ecf20Sopenharmony_ci			req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
10158c2ecf20Sopenharmony_ci	}
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_ci	if (bp->accept_any_vlan)
10188c2ecf20Sopenharmony_ci		req->rx_mask |= VFPF_RX_MASK_ACCEPT_ANY_VLAN;
10198c2ecf20Sopenharmony_ci
10208c2ecf20Sopenharmony_ci	req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
10218c2ecf20Sopenharmony_ci	req->vf_qid = 0;
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci	/* add list termination tlv */
10248c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
10258c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	/* output tlvs list */
10288c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, req);
10298c2ecf20Sopenharmony_ci
10308c2ecf20Sopenharmony_ci	rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
10318c2ecf20Sopenharmony_ci	if (rc)
10328c2ecf20Sopenharmony_ci		BNX2X_ERR("Sending a message failed: %d\n", rc);
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_ci	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
10358c2ecf20Sopenharmony_ci		BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
10368c2ecf20Sopenharmony_ci		rc = -EINVAL;
10378c2ecf20Sopenharmony_ci	}
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ci	bnx2x_vfpf_finalize(bp, &req->first_tlv);
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci	return rc;
10428c2ecf20Sopenharmony_ci}
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_ci/* General service functions */
10458c2ecf20Sopenharmony_cistatic void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
10468c2ecf20Sopenharmony_ci{
10478c2ecf20Sopenharmony_ci	u32 addr = BAR_CSTRORM_INTMEM +
10488c2ecf20Sopenharmony_ci		   CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
10518c2ecf20Sopenharmony_ci}
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_cistatic void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
10548c2ecf20Sopenharmony_ci{
10558c2ecf20Sopenharmony_ci	u32 addr = BAR_CSTRORM_INTMEM +
10568c2ecf20Sopenharmony_ci		   CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci	REG_WR8(bp, addr, 1);
10598c2ecf20Sopenharmony_ci}
10608c2ecf20Sopenharmony_ci
10618c2ecf20Sopenharmony_ci/* enable vf_pf mailbox (aka vf-pf-channel) */
10628c2ecf20Sopenharmony_civoid bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
10638c2ecf20Sopenharmony_ci{
10648c2ecf20Sopenharmony_ci	bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci	/* enable the mailbox in the FW */
10678c2ecf20Sopenharmony_ci	storm_memset_vf_mbx_ack(bp, abs_vfid);
10688c2ecf20Sopenharmony_ci	storm_memset_vf_mbx_valid(bp, abs_vfid);
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_ci	/* enable the VF access to the mailbox */
10718c2ecf20Sopenharmony_ci	bnx2x_vf_enable_access(bp, abs_vfid);
10728c2ecf20Sopenharmony_ci}
10738c2ecf20Sopenharmony_ci
10748c2ecf20Sopenharmony_ci/* this works only on !E1h */
10758c2ecf20Sopenharmony_cistatic int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
10768c2ecf20Sopenharmony_ci				dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
10778c2ecf20Sopenharmony_ci				u32 vf_addr_lo, u32 len32)
10788c2ecf20Sopenharmony_ci{
10798c2ecf20Sopenharmony_ci	struct dmae_command dmae;
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	if (CHIP_IS_E1x(bp)) {
10828c2ecf20Sopenharmony_ci		BNX2X_ERR("Chip revision does not support VFs\n");
10838c2ecf20Sopenharmony_ci		return DMAE_NOT_RDY;
10848c2ecf20Sopenharmony_ci	}
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_ci	if (!bp->dmae_ready) {
10878c2ecf20Sopenharmony_ci		BNX2X_ERR("DMAE is not ready, can not copy\n");
10888c2ecf20Sopenharmony_ci		return DMAE_NOT_RDY;
10898c2ecf20Sopenharmony_ci	}
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci	/* set opcode and fixed command fields */
10928c2ecf20Sopenharmony_ci	bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci	if (from_vf) {
10958c2ecf20Sopenharmony_ci		dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
10968c2ecf20Sopenharmony_ci			(DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
10978c2ecf20Sopenharmony_ci			(DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_ci		dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci		dmae.src_addr_lo = vf_addr_lo;
11028c2ecf20Sopenharmony_ci		dmae.src_addr_hi = vf_addr_hi;
11038c2ecf20Sopenharmony_ci		dmae.dst_addr_lo = U64_LO(pf_addr);
11048c2ecf20Sopenharmony_ci		dmae.dst_addr_hi = U64_HI(pf_addr);
11058c2ecf20Sopenharmony_ci	} else {
11068c2ecf20Sopenharmony_ci		dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
11078c2ecf20Sopenharmony_ci			(DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
11088c2ecf20Sopenharmony_ci			(DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
11098c2ecf20Sopenharmony_ci
11108c2ecf20Sopenharmony_ci		dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_ci		dmae.src_addr_lo = U64_LO(pf_addr);
11138c2ecf20Sopenharmony_ci		dmae.src_addr_hi = U64_HI(pf_addr);
11148c2ecf20Sopenharmony_ci		dmae.dst_addr_lo = vf_addr_lo;
11158c2ecf20Sopenharmony_ci		dmae.dst_addr_hi = vf_addr_hi;
11168c2ecf20Sopenharmony_ci	}
11178c2ecf20Sopenharmony_ci	dmae.len = len32;
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	/* issue the command and wait for completion */
11208c2ecf20Sopenharmony_ci	return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
11218c2ecf20Sopenharmony_ci}
11228c2ecf20Sopenharmony_ci
11238c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
11248c2ecf20Sopenharmony_ci					 struct bnx2x_virtf *vf)
11258c2ecf20Sopenharmony_ci{
11268c2ecf20Sopenharmony_ci	struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
11278c2ecf20Sopenharmony_ci	u16 length, type;
11288c2ecf20Sopenharmony_ci
11298c2ecf20Sopenharmony_ci	/* prepare response */
11308c2ecf20Sopenharmony_ci	type = mbx->first_tlv.tl.type;
11318c2ecf20Sopenharmony_ci	length = type == CHANNEL_TLV_ACQUIRE ?
11328c2ecf20Sopenharmony_ci		sizeof(struct pfvf_acquire_resp_tlv) :
11338c2ecf20Sopenharmony_ci		sizeof(struct pfvf_general_resp_tlv);
11348c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
11358c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
11368c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
11378c2ecf20Sopenharmony_ci}
11388c2ecf20Sopenharmony_ci
11398c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
11408c2ecf20Sopenharmony_ci				       struct bnx2x_virtf *vf,
11418c2ecf20Sopenharmony_ci				       int vf_rc)
11428c2ecf20Sopenharmony_ci{
11438c2ecf20Sopenharmony_ci	struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
11448c2ecf20Sopenharmony_ci	struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
11458c2ecf20Sopenharmony_ci	dma_addr_t pf_addr;
11468c2ecf20Sopenharmony_ci	u64 vf_addr;
11478c2ecf20Sopenharmony_ci	int rc;
11488c2ecf20Sopenharmony_ci
11498c2ecf20Sopenharmony_ci	bnx2x_dp_tlv_list(bp, resp);
11508c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
11518c2ecf20Sopenharmony_ci	   mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
11528c2ecf20Sopenharmony_ci
11538c2ecf20Sopenharmony_ci	resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	/* send response */
11568c2ecf20Sopenharmony_ci	vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
11578c2ecf20Sopenharmony_ci		  mbx->first_tlv.resp_msg_offset;
11588c2ecf20Sopenharmony_ci	pf_addr = mbx->msg_mapping +
11598c2ecf20Sopenharmony_ci		  offsetof(struct bnx2x_vf_mbx_msg, resp);
11608c2ecf20Sopenharmony_ci
11618c2ecf20Sopenharmony_ci	/* Copy the response buffer. The first u64 is written afterwards, as
11628c2ecf20Sopenharmony_ci	 * the vf is sensitive to the header being written
11638c2ecf20Sopenharmony_ci	 */
11648c2ecf20Sopenharmony_ci	vf_addr += sizeof(u64);
11658c2ecf20Sopenharmony_ci	pf_addr += sizeof(u64);
11668c2ecf20Sopenharmony_ci	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
11678c2ecf20Sopenharmony_ci				  U64_HI(vf_addr),
11688c2ecf20Sopenharmony_ci				  U64_LO(vf_addr),
11698c2ecf20Sopenharmony_ci				  (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
11708c2ecf20Sopenharmony_ci	if (rc) {
11718c2ecf20Sopenharmony_ci		BNX2X_ERR("Failed to copy response body to VF %d\n",
11728c2ecf20Sopenharmony_ci			  vf->abs_vfid);
11738c2ecf20Sopenharmony_ci		goto mbx_error;
11748c2ecf20Sopenharmony_ci	}
11758c2ecf20Sopenharmony_ci	vf_addr -= sizeof(u64);
11768c2ecf20Sopenharmony_ci	pf_addr -= sizeof(u64);
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ci	/* ack the FW */
11798c2ecf20Sopenharmony_ci	storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
11808c2ecf20Sopenharmony_ci
11818c2ecf20Sopenharmony_ci	/* copy the response header including status-done field,
11828c2ecf20Sopenharmony_ci	 * must be last dmae, must be after FW is acked
11838c2ecf20Sopenharmony_ci	 */
11848c2ecf20Sopenharmony_ci	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
11858c2ecf20Sopenharmony_ci				  U64_HI(vf_addr),
11868c2ecf20Sopenharmony_ci				  U64_LO(vf_addr),
11878c2ecf20Sopenharmony_ci				  sizeof(u64)/4);
11888c2ecf20Sopenharmony_ci
11898c2ecf20Sopenharmony_ci	/* unlock channel mutex */
11908c2ecf20Sopenharmony_ci	bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci	if (rc) {
11938c2ecf20Sopenharmony_ci		BNX2X_ERR("Failed to copy response status to VF %d\n",
11948c2ecf20Sopenharmony_ci			  vf->abs_vfid);
11958c2ecf20Sopenharmony_ci		goto mbx_error;
11968c2ecf20Sopenharmony_ci	}
11978c2ecf20Sopenharmony_ci	return;
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_cimbx_error:
12008c2ecf20Sopenharmony_ci	bnx2x_vf_release(bp, vf);
12018c2ecf20Sopenharmony_ci}
12028c2ecf20Sopenharmony_ci
12038c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_resp(struct bnx2x *bp,
12048c2ecf20Sopenharmony_ci			      struct bnx2x_virtf *vf,
12058c2ecf20Sopenharmony_ci			      int rc)
12068c2ecf20Sopenharmony_ci{
12078c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp_single_tlv(bp, vf);
12088c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
12098c2ecf20Sopenharmony_ci}
12108c2ecf20Sopenharmony_ci
12118c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
12128c2ecf20Sopenharmony_ci					struct bnx2x_virtf *vf,
12138c2ecf20Sopenharmony_ci					void *buffer,
12148c2ecf20Sopenharmony_ci					u16 *offset)
12158c2ecf20Sopenharmony_ci{
12168c2ecf20Sopenharmony_ci	struct vfpf_port_phys_id_resp_tlv *port_id;
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	if (!(bp->flags & HAS_PHYS_PORT_ID))
12198c2ecf20Sopenharmony_ci		return;
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
12228c2ecf20Sopenharmony_ci		      sizeof(struct vfpf_port_phys_id_resp_tlv));
12238c2ecf20Sopenharmony_ci
12248c2ecf20Sopenharmony_ci	port_id = (struct vfpf_port_phys_id_resp_tlv *)
12258c2ecf20Sopenharmony_ci		  (((u8 *)buffer) + *offset);
12268c2ecf20Sopenharmony_ci	memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	/* Offset should continue representing the offset to the tail
12298c2ecf20Sopenharmony_ci	 * of TLV data (outside this function scope)
12308c2ecf20Sopenharmony_ci	 */
12318c2ecf20Sopenharmony_ci	*offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
12328c2ecf20Sopenharmony_ci}
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
12358c2ecf20Sopenharmony_ci					 struct bnx2x_virtf *vf,
12368c2ecf20Sopenharmony_ci					 void *buffer,
12378c2ecf20Sopenharmony_ci					 u16 *offset)
12388c2ecf20Sopenharmony_ci{
12398c2ecf20Sopenharmony_ci	struct vfpf_fp_hsi_resp_tlv *fp_hsi;
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
12428c2ecf20Sopenharmony_ci		      sizeof(struct vfpf_fp_hsi_resp_tlv));
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci	fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
12458c2ecf20Sopenharmony_ci		 (((u8 *)buffer) + *offset);
12468c2ecf20Sopenharmony_ci	fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
12478c2ecf20Sopenharmony_ci
12488c2ecf20Sopenharmony_ci	/* Offset should continue representing the offset to the tail
12498c2ecf20Sopenharmony_ci	 * of TLV data (outside this function scope)
12508c2ecf20Sopenharmony_ci	 */
12518c2ecf20Sopenharmony_ci	*offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
12528c2ecf20Sopenharmony_ci}
12538c2ecf20Sopenharmony_ci
12548c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
12558c2ecf20Sopenharmony_ci				      struct bnx2x_vf_mbx *mbx, int vfop_status)
12568c2ecf20Sopenharmony_ci{
12578c2ecf20Sopenharmony_ci	int i;
12588c2ecf20Sopenharmony_ci	struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
12598c2ecf20Sopenharmony_ci	struct pf_vf_resc *resc = &resp->resc;
12608c2ecf20Sopenharmony_ci	u8 status = bnx2x_pfvf_status_codes(vfop_status);
12618c2ecf20Sopenharmony_ci	u16 length;
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_ci	memset(resp, 0, sizeof(*resp));
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci	/* fill in pfdev info */
12668c2ecf20Sopenharmony_ci	resp->pfdev_info.chip_num = bp->common.chip_id;
12678c2ecf20Sopenharmony_ci	resp->pfdev_info.db_size = bp->db_size;
12688c2ecf20Sopenharmony_ci	resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
12698c2ecf20Sopenharmony_ci	resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
12708c2ecf20Sopenharmony_ci				   PFVF_CAP_TPA |
12718c2ecf20Sopenharmony_ci				   PFVF_CAP_TPA_UPDATE |
12728c2ecf20Sopenharmony_ci				   PFVF_CAP_VLAN_FILTER);
12738c2ecf20Sopenharmony_ci	bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
12748c2ecf20Sopenharmony_ci			  sizeof(resp->pfdev_info.fw_ver));
12758c2ecf20Sopenharmony_ci
12768c2ecf20Sopenharmony_ci	if (status == PFVF_STATUS_NO_RESOURCE ||
12778c2ecf20Sopenharmony_ci	    status == PFVF_STATUS_SUCCESS) {
12788c2ecf20Sopenharmony_ci		/* set resources numbers, if status equals NO_RESOURCE these
12798c2ecf20Sopenharmony_ci		 * are max possible numbers
12808c2ecf20Sopenharmony_ci		 */
12818c2ecf20Sopenharmony_ci		resc->num_rxqs = vf_rxq_count(vf) ? :
12828c2ecf20Sopenharmony_ci			bnx2x_vf_max_queue_cnt(bp, vf);
12838c2ecf20Sopenharmony_ci		resc->num_txqs = vf_txq_count(vf) ? :
12848c2ecf20Sopenharmony_ci			bnx2x_vf_max_queue_cnt(bp, vf);
12858c2ecf20Sopenharmony_ci		resc->num_sbs = vf_sb_count(vf);
12868c2ecf20Sopenharmony_ci		resc->num_mac_filters = vf_mac_rules_cnt(vf);
12878c2ecf20Sopenharmony_ci		resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
12888c2ecf20Sopenharmony_ci		resc->num_mc_filters = 0;
12898c2ecf20Sopenharmony_ci
12908c2ecf20Sopenharmony_ci		if (status == PFVF_STATUS_SUCCESS) {
12918c2ecf20Sopenharmony_ci			/* fill in the allocated resources */
12928c2ecf20Sopenharmony_ci			struct pf_vf_bulletin_content *bulletin =
12938c2ecf20Sopenharmony_ci				BP_VF_BULLETIN(bp, vf->index);
12948c2ecf20Sopenharmony_ci
12958c2ecf20Sopenharmony_ci			for_each_vfq(vf, i)
12968c2ecf20Sopenharmony_ci				resc->hw_qid[i] =
12978c2ecf20Sopenharmony_ci					vfq_qzone_id(vf, vfq_get(vf, i));
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_ci			for_each_vf_sb(vf, i) {
13008c2ecf20Sopenharmony_ci				resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
13018c2ecf20Sopenharmony_ci				resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
13028c2ecf20Sopenharmony_ci			}
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci			/* if a mac has been set for this vf, supply it */
13058c2ecf20Sopenharmony_ci			if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
13068c2ecf20Sopenharmony_ci				memcpy(resc->current_mac_addr, bulletin->mac,
13078c2ecf20Sopenharmony_ci				       ETH_ALEN);
13088c2ecf20Sopenharmony_ci			}
13098c2ecf20Sopenharmony_ci		}
13108c2ecf20Sopenharmony_ci	}
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci	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"
13138c2ecf20Sopenharmony_ci	   "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
13148c2ecf20Sopenharmony_ci	   vf->abs_vfid,
13158c2ecf20Sopenharmony_ci	   resp->pfdev_info.chip_num,
13168c2ecf20Sopenharmony_ci	   resp->pfdev_info.db_size,
13178c2ecf20Sopenharmony_ci	   resp->pfdev_info.indices_per_sb,
13188c2ecf20Sopenharmony_ci	   resp->pfdev_info.pf_cap,
13198c2ecf20Sopenharmony_ci	   resc->num_rxqs,
13208c2ecf20Sopenharmony_ci	   resc->num_txqs,
13218c2ecf20Sopenharmony_ci	   resc->num_sbs,
13228c2ecf20Sopenharmony_ci	   resc->num_mac_filters,
13238c2ecf20Sopenharmony_ci	   resc->num_vlan_filters,
13248c2ecf20Sopenharmony_ci	   resc->num_mc_filters,
13258c2ecf20Sopenharmony_ci	   resp->pfdev_info.fw_ver);
13268c2ecf20Sopenharmony_ci
13278c2ecf20Sopenharmony_ci	DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
13288c2ecf20Sopenharmony_ci	for (i = 0; i < vf_rxq_count(vf); i++)
13298c2ecf20Sopenharmony_ci		DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
13308c2ecf20Sopenharmony_ci	DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
13318c2ecf20Sopenharmony_ci	for (i = 0; i < vf_sb_count(vf); i++)
13328c2ecf20Sopenharmony_ci		DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
13338c2ecf20Sopenharmony_ci			resc->hw_sbs[i].hw_sb_id,
13348c2ecf20Sopenharmony_ci			resc->hw_sbs[i].sb_qid);
13358c2ecf20Sopenharmony_ci	DP_CONT(BNX2X_MSG_IOV, "]\n");
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci	/* prepare response */
13388c2ecf20Sopenharmony_ci	length = sizeof(struct pfvf_acquire_resp_tlv);
13398c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci	/* Handle possible VF requests for physical port identifiers.
13428c2ecf20Sopenharmony_ci	 * 'length' should continue to indicate the offset of the first empty
13438c2ecf20Sopenharmony_ci	 * place in the buffer (i.e., where next TLV should be inserted)
13448c2ecf20Sopenharmony_ci	 */
13458c2ecf20Sopenharmony_ci	if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
13468c2ecf20Sopenharmony_ci				  CHANNEL_TLV_PHYS_PORT_ID))
13478c2ecf20Sopenharmony_ci		bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
13488c2ecf20Sopenharmony_ci
13498c2ecf20Sopenharmony_ci	/* `New' vfs will want to know if fastpath HSI is supported, since
13508c2ecf20Sopenharmony_ci	 * if that's not the case they could print into system log the fact
13518c2ecf20Sopenharmony_ci	 * the driver version must be updated.
13528c2ecf20Sopenharmony_ci	 */
13538c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
13548c2ecf20Sopenharmony_ci
13558c2ecf20Sopenharmony_ci	bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
13568c2ecf20Sopenharmony_ci		      sizeof(struct channel_list_end_tlv));
13578c2ecf20Sopenharmony_ci
13588c2ecf20Sopenharmony_ci	/* send the response */
13598c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
13608c2ecf20Sopenharmony_ci}
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_cistatic bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
13638c2ecf20Sopenharmony_ci				       struct vfpf_acquire_tlv *acquire)
13648c2ecf20Sopenharmony_ci{
13658c2ecf20Sopenharmony_ci	/* Windows driver does one of three things:
13668c2ecf20Sopenharmony_ci	 * 1. Old driver doesn't have bulletin board address set.
13678c2ecf20Sopenharmony_ci	 * 2. 'Middle' driver sends mc_num == 32.
13688c2ecf20Sopenharmony_ci	 * 3. New driver sets the OS field.
13698c2ecf20Sopenharmony_ci	 */
13708c2ecf20Sopenharmony_ci	if (!acquire->bulletin_addr ||
13718c2ecf20Sopenharmony_ci	    acquire->resc_request.num_mc_filters == 32 ||
13728c2ecf20Sopenharmony_ci	    ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
13738c2ecf20Sopenharmony_ci	     VF_OS_WINDOWS))
13748c2ecf20Sopenharmony_ci		return true;
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci	return false;
13778c2ecf20Sopenharmony_ci}
13788c2ecf20Sopenharmony_ci
13798c2ecf20Sopenharmony_cistatic int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
13808c2ecf20Sopenharmony_ci					 struct bnx2x_virtf *vf,
13818c2ecf20Sopenharmony_ci					 struct bnx2x_vf_mbx *mbx)
13828c2ecf20Sopenharmony_ci{
13838c2ecf20Sopenharmony_ci	/* Linux drivers which correctly set the doorbell size also
13848c2ecf20Sopenharmony_ci	 * send a physical port request
13858c2ecf20Sopenharmony_ci	 */
13868c2ecf20Sopenharmony_ci	if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
13878c2ecf20Sopenharmony_ci				  CHANNEL_TLV_PHYS_PORT_ID))
13888c2ecf20Sopenharmony_ci		return 0;
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci	/* Issue does not exist in windows VMs */
13918c2ecf20Sopenharmony_ci	if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
13928c2ecf20Sopenharmony_ci		return 0;
13938c2ecf20Sopenharmony_ci
13948c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
13958c2ecf20Sopenharmony_ci}
13968c2ecf20Sopenharmony_ci
13978c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
13988c2ecf20Sopenharmony_ci				 struct bnx2x_vf_mbx *mbx)
13998c2ecf20Sopenharmony_ci{
14008c2ecf20Sopenharmony_ci	int rc;
14018c2ecf20Sopenharmony_ci	struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
14028c2ecf20Sopenharmony_ci
14038c2ecf20Sopenharmony_ci	/* log vfdef info */
14048c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV,
14058c2ecf20Sopenharmony_ci	   "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",
14068c2ecf20Sopenharmony_ci	   vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
14078c2ecf20Sopenharmony_ci	   acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
14088c2ecf20Sopenharmony_ci	   acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
14098c2ecf20Sopenharmony_ci	   acquire->resc_request.num_vlan_filters,
14108c2ecf20Sopenharmony_ci	   acquire->resc_request.num_mc_filters);
14118c2ecf20Sopenharmony_ci
14128c2ecf20Sopenharmony_ci	/* Prevent VFs with old drivers from loading, since they calculate
14138c2ecf20Sopenharmony_ci	 * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
14148c2ecf20Sopenharmony_ci	 * while being upgraded.
14158c2ecf20Sopenharmony_ci	 */
14168c2ecf20Sopenharmony_ci	rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
14178c2ecf20Sopenharmony_ci	if (rc) {
14188c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
14198c2ecf20Sopenharmony_ci		   "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
14208c2ecf20Sopenharmony_ci		   vf->abs_vfid);
14218c2ecf20Sopenharmony_ci		goto out;
14228c2ecf20Sopenharmony_ci	}
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci	/* Verify the VF fastpath HSI can be supported by the loaded FW.
14258c2ecf20Sopenharmony_ci	 * Linux vfs should be oblivious to changes between v0 and v2.
14268c2ecf20Sopenharmony_ci	 */
14278c2ecf20Sopenharmony_ci	if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
14288c2ecf20Sopenharmony_ci		vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
14298c2ecf20Sopenharmony_ci	else
14308c2ecf20Sopenharmony_ci		vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
14318c2ecf20Sopenharmony_ci				   ETH_FP_HSI_VER_2);
14328c2ecf20Sopenharmony_ci	if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
14338c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
14348c2ecf20Sopenharmony_ci		   "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
14358c2ecf20Sopenharmony_ci		   vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
14368c2ecf20Sopenharmony_ci		   ETH_FP_HSI_VERSION);
14378c2ecf20Sopenharmony_ci		rc = -EINVAL;
14388c2ecf20Sopenharmony_ci		goto out;
14398c2ecf20Sopenharmony_ci	}
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci	/* acquire the resources */
14428c2ecf20Sopenharmony_ci	rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	/* store address of vf's bulletin board */
14458c2ecf20Sopenharmony_ci	vf->bulletin_map = acquire->bulletin_addr;
14468c2ecf20Sopenharmony_ci	if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
14478c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
14488c2ecf20Sopenharmony_ci		   vf->abs_vfid);
14498c2ecf20Sopenharmony_ci		vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
14508c2ecf20Sopenharmony_ci	} else {
14518c2ecf20Sopenharmony_ci		vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
14528c2ecf20Sopenharmony_ci	}
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci	if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_VLAN_FILTER) {
14558c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV, "VF[%d] supports vlan filtering\n",
14568c2ecf20Sopenharmony_ci		   vf->abs_vfid);
14578c2ecf20Sopenharmony_ci		vf->cfg_flags |= VF_CFG_VLAN_FILTER;
14588c2ecf20Sopenharmony_ci	} else {
14598c2ecf20Sopenharmony_ci		vf->cfg_flags &= ~VF_CFG_VLAN_FILTER;
14608c2ecf20Sopenharmony_ci	}
14618c2ecf20Sopenharmony_ci
14628c2ecf20Sopenharmony_ciout:
14638c2ecf20Sopenharmony_ci	/* response */
14648c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
14658c2ecf20Sopenharmony_ci}
14668c2ecf20Sopenharmony_ci
14678c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
14688c2ecf20Sopenharmony_ci			      struct bnx2x_vf_mbx *mbx)
14698c2ecf20Sopenharmony_ci{
14708c2ecf20Sopenharmony_ci	struct vfpf_init_tlv *init = &mbx->msg->req.init;
14718c2ecf20Sopenharmony_ci	int rc;
14728c2ecf20Sopenharmony_ci
14738c2ecf20Sopenharmony_ci	/* record ghost addresses from vf message */
14748c2ecf20Sopenharmony_ci	vf->fw_stat_map = init->stats_addr;
14758c2ecf20Sopenharmony_ci	vf->stats_stride = init->stats_stride;
14768c2ecf20Sopenharmony_ci	rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
14778c2ecf20Sopenharmony_ci
14788c2ecf20Sopenharmony_ci	/* set VF multiqueue statistics collection mode */
14798c2ecf20Sopenharmony_ci	if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
14808c2ecf20Sopenharmony_ci		vf->cfg_flags |= VF_CFG_STATS_COALESCE;
14818c2ecf20Sopenharmony_ci
14828c2ecf20Sopenharmony_ci	/* Update VF's view of link state */
14838c2ecf20Sopenharmony_ci	if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
14848c2ecf20Sopenharmony_ci		bnx2x_iov_link_update_vf(bp, vf->index);
14858c2ecf20Sopenharmony_ci
14868c2ecf20Sopenharmony_ci	/* response */
14878c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
14888c2ecf20Sopenharmony_ci}
14898c2ecf20Sopenharmony_ci
14908c2ecf20Sopenharmony_ci/* convert MBX queue-flags to standard SP queue-flags */
14918c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
14928c2ecf20Sopenharmony_ci				     unsigned long *sp_q_flags)
14938c2ecf20Sopenharmony_ci{
14948c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
14958c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
14968c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
14978c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
14988c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
14998c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
15008c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
15018c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
15028c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
15038c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
15048c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
15058c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
15068c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
15078c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
15088c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
15098c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
15108c2ecf20Sopenharmony_ci	if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
15118c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
15128c2ecf20Sopenharmony_ci
15138c2ecf20Sopenharmony_ci	/* outer vlan removal is set according to PF's multi function mode */
15148c2ecf20Sopenharmony_ci	if (IS_MF_SD(bp))
15158c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
15168c2ecf20Sopenharmony_ci}
15178c2ecf20Sopenharmony_ci
15188c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
15198c2ecf20Sopenharmony_ci				 struct bnx2x_vf_mbx *mbx)
15208c2ecf20Sopenharmony_ci{
15218c2ecf20Sopenharmony_ci	struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
15228c2ecf20Sopenharmony_ci	struct bnx2x_vf_queue_construct_params qctor;
15238c2ecf20Sopenharmony_ci	int rc = 0;
15248c2ecf20Sopenharmony_ci
15258c2ecf20Sopenharmony_ci	/* verify vf_qid */
15268c2ecf20Sopenharmony_ci	if (setup_q->vf_qid >= vf_rxq_count(vf)) {
15278c2ecf20Sopenharmony_ci		BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
15288c2ecf20Sopenharmony_ci			  setup_q->vf_qid, vf_rxq_count(vf));
15298c2ecf20Sopenharmony_ci		rc = -EINVAL;
15308c2ecf20Sopenharmony_ci		goto response;
15318c2ecf20Sopenharmony_ci	}
15328c2ecf20Sopenharmony_ci
15338c2ecf20Sopenharmony_ci	/* tx queues must be setup alongside rx queues thus if the rx queue
15348c2ecf20Sopenharmony_ci	 * is not marked as valid there's nothing to do.
15358c2ecf20Sopenharmony_ci	 */
15368c2ecf20Sopenharmony_ci	if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
15378c2ecf20Sopenharmony_ci		struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
15388c2ecf20Sopenharmony_ci		unsigned long q_type = 0;
15398c2ecf20Sopenharmony_ci
15408c2ecf20Sopenharmony_ci		struct bnx2x_queue_init_params *init_p;
15418c2ecf20Sopenharmony_ci		struct bnx2x_queue_setup_params *setup_p;
15428c2ecf20Sopenharmony_ci
15438c2ecf20Sopenharmony_ci		if (bnx2x_vfq_is_leading(q))
15448c2ecf20Sopenharmony_ci			bnx2x_leading_vfq_init(bp, vf, q);
15458c2ecf20Sopenharmony_ci
15468c2ecf20Sopenharmony_ci		/* re-init the VF operation context */
15478c2ecf20Sopenharmony_ci		memset(&qctor, 0 ,
15488c2ecf20Sopenharmony_ci		       sizeof(struct bnx2x_vf_queue_construct_params));
15498c2ecf20Sopenharmony_ci		setup_p = &qctor.prep_qsetup;
15508c2ecf20Sopenharmony_ci		init_p =  &qctor.qstate.params.init;
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci		/* activate immediately */
15538c2ecf20Sopenharmony_ci		__set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
15548c2ecf20Sopenharmony_ci
15558c2ecf20Sopenharmony_ci		if (setup_q->param_valid & VFPF_TXQ_VALID) {
15568c2ecf20Sopenharmony_ci			struct bnx2x_txq_setup_params *txq_params =
15578c2ecf20Sopenharmony_ci				&setup_p->txq_params;
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci			__set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
15608c2ecf20Sopenharmony_ci
15618c2ecf20Sopenharmony_ci			/* save sb resource index */
15628c2ecf20Sopenharmony_ci			q->sb_idx = setup_q->txq.vf_sb;
15638c2ecf20Sopenharmony_ci
15648c2ecf20Sopenharmony_ci			/* tx init */
15658c2ecf20Sopenharmony_ci			init_p->tx.hc_rate = setup_q->txq.hc_rate;
15668c2ecf20Sopenharmony_ci			init_p->tx.sb_cq_index = setup_q->txq.sb_index;
15678c2ecf20Sopenharmony_ci
15688c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
15698c2ecf20Sopenharmony_ci						 &init_p->tx.flags);
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci			/* tx setup - flags */
15728c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
15738c2ecf20Sopenharmony_ci						 &setup_p->flags);
15748c2ecf20Sopenharmony_ci
15758c2ecf20Sopenharmony_ci			/* tx setup - general, nothing */
15768c2ecf20Sopenharmony_ci
15778c2ecf20Sopenharmony_ci			/* tx setup - tx */
15788c2ecf20Sopenharmony_ci			txq_params->dscr_map = setup_q->txq.txq_addr;
15798c2ecf20Sopenharmony_ci			txq_params->sb_cq_index = setup_q->txq.sb_index;
15808c2ecf20Sopenharmony_ci			txq_params->traffic_type = setup_q->txq.traffic_type;
15818c2ecf20Sopenharmony_ci
15828c2ecf20Sopenharmony_ci			bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
15838c2ecf20Sopenharmony_ci						 q->index, q->sb_idx);
15848c2ecf20Sopenharmony_ci		}
15858c2ecf20Sopenharmony_ci
15868c2ecf20Sopenharmony_ci		if (setup_q->param_valid & VFPF_RXQ_VALID) {
15878c2ecf20Sopenharmony_ci			struct bnx2x_rxq_setup_params *rxq_params =
15888c2ecf20Sopenharmony_ci							&setup_p->rxq_params;
15898c2ecf20Sopenharmony_ci
15908c2ecf20Sopenharmony_ci			__set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
15918c2ecf20Sopenharmony_ci
15928c2ecf20Sopenharmony_ci			/* Note: there is no support for different SBs
15938c2ecf20Sopenharmony_ci			 * for TX and RX
15948c2ecf20Sopenharmony_ci			 */
15958c2ecf20Sopenharmony_ci			q->sb_idx = setup_q->rxq.vf_sb;
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci			/* rx init */
15988c2ecf20Sopenharmony_ci			init_p->rx.hc_rate = setup_q->rxq.hc_rate;
15998c2ecf20Sopenharmony_ci			init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
16008c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
16018c2ecf20Sopenharmony_ci						 &init_p->rx.flags);
16028c2ecf20Sopenharmony_ci
16038c2ecf20Sopenharmony_ci			/* rx setup - flags */
16048c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
16058c2ecf20Sopenharmony_ci						 &setup_p->flags);
16068c2ecf20Sopenharmony_ci
16078c2ecf20Sopenharmony_ci			/* rx setup - general */
16088c2ecf20Sopenharmony_ci			setup_p->gen_params.mtu = setup_q->rxq.mtu;
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_ci			/* rx setup - rx */
16118c2ecf20Sopenharmony_ci			rxq_params->drop_flags = setup_q->rxq.drop_flags;
16128c2ecf20Sopenharmony_ci			rxq_params->dscr_map = setup_q->rxq.rxq_addr;
16138c2ecf20Sopenharmony_ci			rxq_params->sge_map = setup_q->rxq.sge_addr;
16148c2ecf20Sopenharmony_ci			rxq_params->rcq_map = setup_q->rxq.rcq_addr;
16158c2ecf20Sopenharmony_ci			rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
16168c2ecf20Sopenharmony_ci			rxq_params->buf_sz = setup_q->rxq.buf_sz;
16178c2ecf20Sopenharmony_ci			rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
16188c2ecf20Sopenharmony_ci			rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
16198c2ecf20Sopenharmony_ci			rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
16208c2ecf20Sopenharmony_ci			rxq_params->cache_line_log =
16218c2ecf20Sopenharmony_ci				setup_q->rxq.cache_line_log;
16228c2ecf20Sopenharmony_ci			rxq_params->sb_cq_index = setup_q->rxq.sb_index;
16238c2ecf20Sopenharmony_ci
16248c2ecf20Sopenharmony_ci			/* rx setup - multicast engine */
16258c2ecf20Sopenharmony_ci			if (bnx2x_vfq_is_leading(q)) {
16268c2ecf20Sopenharmony_ci				u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
16278c2ecf20Sopenharmony_ci
16288c2ecf20Sopenharmony_ci				rxq_params->mcast_engine_id = mcast_id;
16298c2ecf20Sopenharmony_ci				__set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
16308c2ecf20Sopenharmony_ci			}
16318c2ecf20Sopenharmony_ci
16328c2ecf20Sopenharmony_ci			bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
16338c2ecf20Sopenharmony_ci						 q->index, q->sb_idx);
16348c2ecf20Sopenharmony_ci		}
16358c2ecf20Sopenharmony_ci		/* complete the preparations */
16368c2ecf20Sopenharmony_ci		bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
16378c2ecf20Sopenharmony_ci
16388c2ecf20Sopenharmony_ci		rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
16398c2ecf20Sopenharmony_ci		if (rc)
16408c2ecf20Sopenharmony_ci			goto response;
16418c2ecf20Sopenharmony_ci	}
16428c2ecf20Sopenharmony_ciresponse:
16438c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
16448c2ecf20Sopenharmony_ci}
16458c2ecf20Sopenharmony_ci
16468c2ecf20Sopenharmony_cistatic int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
16478c2ecf20Sopenharmony_ci				     struct bnx2x_virtf *vf,
16488c2ecf20Sopenharmony_ci				     struct vfpf_set_q_filters_tlv *tlv,
16498c2ecf20Sopenharmony_ci				     struct bnx2x_vf_mac_vlan_filters **pfl,
16508c2ecf20Sopenharmony_ci				     u32 type_flag)
16518c2ecf20Sopenharmony_ci{
16528c2ecf20Sopenharmony_ci	int i, j;
16538c2ecf20Sopenharmony_ci	struct bnx2x_vf_mac_vlan_filters *fl = NULL;
16548c2ecf20Sopenharmony_ci
16558c2ecf20Sopenharmony_ci	fl = kzalloc(struct_size(fl, filters, tlv->n_mac_vlan_filters),
16568c2ecf20Sopenharmony_ci		     GFP_KERNEL);
16578c2ecf20Sopenharmony_ci	if (!fl)
16588c2ecf20Sopenharmony_ci		return -ENOMEM;
16598c2ecf20Sopenharmony_ci
16608c2ecf20Sopenharmony_ci	for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
16618c2ecf20Sopenharmony_ci		struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
16628c2ecf20Sopenharmony_ci
16638c2ecf20Sopenharmony_ci		if ((msg_filter->flags & type_flag) != type_flag)
16648c2ecf20Sopenharmony_ci			continue;
16658c2ecf20Sopenharmony_ci		memset(&fl->filters[j], 0, sizeof(fl->filters[j]));
16668c2ecf20Sopenharmony_ci		if (type_flag & VFPF_Q_FILTER_DEST_MAC_VALID) {
16678c2ecf20Sopenharmony_ci			fl->filters[j].mac = msg_filter->mac;
16688c2ecf20Sopenharmony_ci			fl->filters[j].type |= BNX2X_VF_FILTER_MAC;
16698c2ecf20Sopenharmony_ci		}
16708c2ecf20Sopenharmony_ci		if (type_flag & VFPF_Q_FILTER_VLAN_TAG_VALID) {
16718c2ecf20Sopenharmony_ci			fl->filters[j].vid = msg_filter->vlan_tag;
16728c2ecf20Sopenharmony_ci			fl->filters[j].type |= BNX2X_VF_FILTER_VLAN;
16738c2ecf20Sopenharmony_ci		}
16748c2ecf20Sopenharmony_ci		fl->filters[j].add = !!(msg_filter->flags & VFPF_Q_FILTER_SET);
16758c2ecf20Sopenharmony_ci		fl->count++;
16768c2ecf20Sopenharmony_ci		j++;
16778c2ecf20Sopenharmony_ci	}
16788c2ecf20Sopenharmony_ci	if (!fl->count)
16798c2ecf20Sopenharmony_ci		kfree(fl);
16808c2ecf20Sopenharmony_ci	else
16818c2ecf20Sopenharmony_ci		*pfl = fl;
16828c2ecf20Sopenharmony_ci
16838c2ecf20Sopenharmony_ci	return 0;
16848c2ecf20Sopenharmony_ci}
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_cistatic int bnx2x_vf_filters_contain(struct vfpf_set_q_filters_tlv *filters,
16878c2ecf20Sopenharmony_ci				    u32 flags)
16888c2ecf20Sopenharmony_ci{
16898c2ecf20Sopenharmony_ci	int i, cnt = 0;
16908c2ecf20Sopenharmony_ci
16918c2ecf20Sopenharmony_ci	for (i = 0; i < filters->n_mac_vlan_filters; i++)
16928c2ecf20Sopenharmony_ci		if  ((filters->filters[i].flags & flags) == flags)
16938c2ecf20Sopenharmony_ci			cnt++;
16948c2ecf20Sopenharmony_ci
16958c2ecf20Sopenharmony_ci	return cnt;
16968c2ecf20Sopenharmony_ci}
16978c2ecf20Sopenharmony_ci
16988c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
16998c2ecf20Sopenharmony_ci				       struct vfpf_q_mac_vlan_filter *filter)
17008c2ecf20Sopenharmony_ci{
17018c2ecf20Sopenharmony_ci	DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
17028c2ecf20Sopenharmony_ci	if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
17038c2ecf20Sopenharmony_ci		DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
17048c2ecf20Sopenharmony_ci	if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
17058c2ecf20Sopenharmony_ci		DP_CONT(msglvl, ", MAC=%pM", filter->mac);
17068c2ecf20Sopenharmony_ci	DP_CONT(msglvl, "\n");
17078c2ecf20Sopenharmony_ci}
17088c2ecf20Sopenharmony_ci
17098c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
17108c2ecf20Sopenharmony_ci				       struct vfpf_set_q_filters_tlv *filters)
17118c2ecf20Sopenharmony_ci{
17128c2ecf20Sopenharmony_ci	int i;
17138c2ecf20Sopenharmony_ci
17148c2ecf20Sopenharmony_ci	if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
17158c2ecf20Sopenharmony_ci		for (i = 0; i < filters->n_mac_vlan_filters; i++)
17168c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
17178c2ecf20Sopenharmony_ci						 &filters->filters[i]);
17188c2ecf20Sopenharmony_ci
17198c2ecf20Sopenharmony_ci	if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
17208c2ecf20Sopenharmony_ci		DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
17218c2ecf20Sopenharmony_ci
17228c2ecf20Sopenharmony_ci	if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
17238c2ecf20Sopenharmony_ci		for (i = 0; i < filters->n_multicast; i++)
17248c2ecf20Sopenharmony_ci			DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
17258c2ecf20Sopenharmony_ci}
17268c2ecf20Sopenharmony_ci
17278c2ecf20Sopenharmony_ci#define VFPF_MAC_FILTER		VFPF_Q_FILTER_DEST_MAC_VALID
17288c2ecf20Sopenharmony_ci#define VFPF_VLAN_FILTER	VFPF_Q_FILTER_VLAN_TAG_VALID
17298c2ecf20Sopenharmony_ci#define VFPF_VLAN_MAC_FILTER	(VFPF_VLAN_FILTER | VFPF_MAC_FILTER)
17308c2ecf20Sopenharmony_ci
17318c2ecf20Sopenharmony_cistatic int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
17328c2ecf20Sopenharmony_ci{
17338c2ecf20Sopenharmony_ci	int rc = 0;
17348c2ecf20Sopenharmony_ci
17358c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *msg =
17368c2ecf20Sopenharmony_ci		&BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ci	/* check for any mac/vlan changes */
17398c2ecf20Sopenharmony_ci	if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
17408c2ecf20Sopenharmony_ci		struct bnx2x_vf_mac_vlan_filters *fl = NULL;
17418c2ecf20Sopenharmony_ci
17428c2ecf20Sopenharmony_ci		/* build vlan-mac list */
17438c2ecf20Sopenharmony_ci		rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
17448c2ecf20Sopenharmony_ci					       VFPF_VLAN_MAC_FILTER);
17458c2ecf20Sopenharmony_ci		if (rc)
17468c2ecf20Sopenharmony_ci			goto op_err;
17478c2ecf20Sopenharmony_ci
17488c2ecf20Sopenharmony_ci		if (fl) {
17498c2ecf20Sopenharmony_ci
17508c2ecf20Sopenharmony_ci			/* set vlan-mac list */
17518c2ecf20Sopenharmony_ci			rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
17528c2ecf20Sopenharmony_ci							   msg->vf_qid,
17538c2ecf20Sopenharmony_ci							   false);
17548c2ecf20Sopenharmony_ci			if (rc)
17558c2ecf20Sopenharmony_ci				goto op_err;
17568c2ecf20Sopenharmony_ci		}
17578c2ecf20Sopenharmony_ci
17588c2ecf20Sopenharmony_ci		/* build mac list */
17598c2ecf20Sopenharmony_ci		fl = NULL;
17608c2ecf20Sopenharmony_ci
17618c2ecf20Sopenharmony_ci		rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
17628c2ecf20Sopenharmony_ci					       VFPF_MAC_FILTER);
17638c2ecf20Sopenharmony_ci		if (rc)
17648c2ecf20Sopenharmony_ci			goto op_err;
17658c2ecf20Sopenharmony_ci
17668c2ecf20Sopenharmony_ci		if (fl) {
17678c2ecf20Sopenharmony_ci			/* set mac list */
17688c2ecf20Sopenharmony_ci			rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
17698c2ecf20Sopenharmony_ci							   msg->vf_qid,
17708c2ecf20Sopenharmony_ci							   false);
17718c2ecf20Sopenharmony_ci			if (rc)
17728c2ecf20Sopenharmony_ci				goto op_err;
17738c2ecf20Sopenharmony_ci		}
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_ci		/* build vlan list */
17768c2ecf20Sopenharmony_ci		fl = NULL;
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_ci		rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
17798c2ecf20Sopenharmony_ci					       VFPF_VLAN_FILTER);
17808c2ecf20Sopenharmony_ci		if (rc)
17818c2ecf20Sopenharmony_ci			goto op_err;
17828c2ecf20Sopenharmony_ci
17838c2ecf20Sopenharmony_ci		if (fl) {
17848c2ecf20Sopenharmony_ci			/* set vlan list */
17858c2ecf20Sopenharmony_ci			rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
17868c2ecf20Sopenharmony_ci							   msg->vf_qid,
17878c2ecf20Sopenharmony_ci							   false);
17888c2ecf20Sopenharmony_ci			if (rc)
17898c2ecf20Sopenharmony_ci				goto op_err;
17908c2ecf20Sopenharmony_ci		}
17918c2ecf20Sopenharmony_ci
17928c2ecf20Sopenharmony_ci	}
17938c2ecf20Sopenharmony_ci
17948c2ecf20Sopenharmony_ci	if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
17958c2ecf20Sopenharmony_ci		unsigned long accept = 0;
17968c2ecf20Sopenharmony_ci		struct pf_vf_bulletin_content *bulletin =
17978c2ecf20Sopenharmony_ci					BP_VF_BULLETIN(bp, vf->index);
17988c2ecf20Sopenharmony_ci
17998c2ecf20Sopenharmony_ci		/* Ignore VF requested mode; instead set a regular mode */
18008c2ecf20Sopenharmony_ci		if (msg->rx_mask !=  VFPF_RX_MASK_ACCEPT_NONE) {
18018c2ecf20Sopenharmony_ci			__set_bit(BNX2X_ACCEPT_UNICAST, &accept);
18028c2ecf20Sopenharmony_ci			__set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
18038c2ecf20Sopenharmony_ci			__set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
18048c2ecf20Sopenharmony_ci		}
18058c2ecf20Sopenharmony_ci
18068c2ecf20Sopenharmony_ci		/* any_vlan is not configured if HV is forcing VLAN
18078c2ecf20Sopenharmony_ci		 * any_vlan is configured if
18088c2ecf20Sopenharmony_ci		 *   1. VF does not support vlan filtering
18098c2ecf20Sopenharmony_ci		 *   OR
18108c2ecf20Sopenharmony_ci		 *   2. VF supports vlan filtering and explicitly requested it
18118c2ecf20Sopenharmony_ci		 */
18128c2ecf20Sopenharmony_ci		if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)) &&
18138c2ecf20Sopenharmony_ci		    (!(vf->cfg_flags & VF_CFG_VLAN_FILTER) ||
18148c2ecf20Sopenharmony_ci		     msg->rx_mask & VFPF_RX_MASK_ACCEPT_ANY_VLAN))
18158c2ecf20Sopenharmony_ci			__set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
18168c2ecf20Sopenharmony_ci
18178c2ecf20Sopenharmony_ci		/* set rx-mode */
18188c2ecf20Sopenharmony_ci		rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
18198c2ecf20Sopenharmony_ci		if (rc)
18208c2ecf20Sopenharmony_ci			goto op_err;
18218c2ecf20Sopenharmony_ci	}
18228c2ecf20Sopenharmony_ci
18238c2ecf20Sopenharmony_ci	if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
18248c2ecf20Sopenharmony_ci		/* set mcasts */
18258c2ecf20Sopenharmony_ci		rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
18268c2ecf20Sopenharmony_ci				    msg->n_multicast, false);
18278c2ecf20Sopenharmony_ci		if (rc)
18288c2ecf20Sopenharmony_ci			goto op_err;
18298c2ecf20Sopenharmony_ci	}
18308c2ecf20Sopenharmony_ciop_err:
18318c2ecf20Sopenharmony_ci	if (rc)
18328c2ecf20Sopenharmony_ci		BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
18338c2ecf20Sopenharmony_ci			  vf->abs_vfid, msg->vf_qid, rc);
18348c2ecf20Sopenharmony_ci	return rc;
18358c2ecf20Sopenharmony_ci}
18368c2ecf20Sopenharmony_ci
18378c2ecf20Sopenharmony_cistatic int bnx2x_filters_validate_mac(struct bnx2x *bp,
18388c2ecf20Sopenharmony_ci				      struct bnx2x_virtf *vf,
18398c2ecf20Sopenharmony_ci				      struct vfpf_set_q_filters_tlv *filters)
18408c2ecf20Sopenharmony_ci{
18418c2ecf20Sopenharmony_ci	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
18428c2ecf20Sopenharmony_ci	int rc = 0;
18438c2ecf20Sopenharmony_ci
18448c2ecf20Sopenharmony_ci	/* if a mac was already set for this VF via the set vf mac ndo, we only
18458c2ecf20Sopenharmony_ci	 * accept mac configurations of that mac. Why accept them at all?
18468c2ecf20Sopenharmony_ci	 * because PF may have been unable to configure the mac at the time
18478c2ecf20Sopenharmony_ci	 * since queue was not set up.
18488c2ecf20Sopenharmony_ci	 */
18498c2ecf20Sopenharmony_ci	if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
18508c2ecf20Sopenharmony_ci		struct vfpf_q_mac_vlan_filter *filter = NULL;
18518c2ecf20Sopenharmony_ci		int i;
18528c2ecf20Sopenharmony_ci
18538c2ecf20Sopenharmony_ci		for (i = 0; i < filters->n_mac_vlan_filters; i++) {
18548c2ecf20Sopenharmony_ci			if (!(filters->filters[i].flags &
18558c2ecf20Sopenharmony_ci			      VFPF_Q_FILTER_DEST_MAC_VALID))
18568c2ecf20Sopenharmony_ci				continue;
18578c2ecf20Sopenharmony_ci
18588c2ecf20Sopenharmony_ci			/* once a mac was set by ndo can only accept
18598c2ecf20Sopenharmony_ci			 * a single mac...
18608c2ecf20Sopenharmony_ci			 */
18618c2ecf20Sopenharmony_ci			if (filter) {
18628c2ecf20Sopenharmony_ci				BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called [%d filters]\n",
18638c2ecf20Sopenharmony_ci					  vf->abs_vfid,
18648c2ecf20Sopenharmony_ci					  filters->n_mac_vlan_filters);
18658c2ecf20Sopenharmony_ci				rc = -EPERM;
18668c2ecf20Sopenharmony_ci				goto response;
18678c2ecf20Sopenharmony_ci			}
18688c2ecf20Sopenharmony_ci
18698c2ecf20Sopenharmony_ci			filter = &filters->filters[i];
18708c2ecf20Sopenharmony_ci		}
18718c2ecf20Sopenharmony_ci
18728c2ecf20Sopenharmony_ci		/* ...and only the mac set by the ndo */
18738c2ecf20Sopenharmony_ci		if (filter &&
18748c2ecf20Sopenharmony_ci		    !ether_addr_equal(filter->mac, bulletin->mac)) {
18758c2ecf20Sopenharmony_ci			BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
18768c2ecf20Sopenharmony_ci				  vf->abs_vfid);
18778c2ecf20Sopenharmony_ci
18788c2ecf20Sopenharmony_ci			rc = -EPERM;
18798c2ecf20Sopenharmony_ci			goto response;
18808c2ecf20Sopenharmony_ci		}
18818c2ecf20Sopenharmony_ci	}
18828c2ecf20Sopenharmony_ci
18838c2ecf20Sopenharmony_ciresponse:
18848c2ecf20Sopenharmony_ci	return rc;
18858c2ecf20Sopenharmony_ci}
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_cistatic int bnx2x_filters_validate_vlan(struct bnx2x *bp,
18888c2ecf20Sopenharmony_ci				       struct bnx2x_virtf *vf,
18898c2ecf20Sopenharmony_ci				       struct vfpf_set_q_filters_tlv *filters)
18908c2ecf20Sopenharmony_ci{
18918c2ecf20Sopenharmony_ci	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
18928c2ecf20Sopenharmony_ci	int rc = 0;
18938c2ecf20Sopenharmony_ci
18948c2ecf20Sopenharmony_ci	/* if vlan was set by hypervisor we don't allow guest to config vlan */
18958c2ecf20Sopenharmony_ci	if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
18968c2ecf20Sopenharmony_ci		/* search for vlan filters */
18978c2ecf20Sopenharmony_ci
18988c2ecf20Sopenharmony_ci		if (bnx2x_vf_filters_contain(filters,
18998c2ecf20Sopenharmony_ci					     VFPF_Q_FILTER_VLAN_TAG_VALID)) {
19008c2ecf20Sopenharmony_ci			BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
19018c2ecf20Sopenharmony_ci				  vf->abs_vfid);
19028c2ecf20Sopenharmony_ci			rc = -EPERM;
19038c2ecf20Sopenharmony_ci			goto response;
19048c2ecf20Sopenharmony_ci		}
19058c2ecf20Sopenharmony_ci	}
19068c2ecf20Sopenharmony_ci
19078c2ecf20Sopenharmony_ci	/* verify vf_qid */
19088c2ecf20Sopenharmony_ci	if (filters->vf_qid > vf_rxq_count(vf)) {
19098c2ecf20Sopenharmony_ci		rc = -EPERM;
19108c2ecf20Sopenharmony_ci		goto response;
19118c2ecf20Sopenharmony_ci	}
19128c2ecf20Sopenharmony_ci
19138c2ecf20Sopenharmony_ciresponse:
19148c2ecf20Sopenharmony_ci	return rc;
19158c2ecf20Sopenharmony_ci}
19168c2ecf20Sopenharmony_ci
19178c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
19188c2ecf20Sopenharmony_ci				       struct bnx2x_virtf *vf,
19198c2ecf20Sopenharmony_ci				       struct bnx2x_vf_mbx *mbx)
19208c2ecf20Sopenharmony_ci{
19218c2ecf20Sopenharmony_ci	struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
19228c2ecf20Sopenharmony_ci	int rc;
19238c2ecf20Sopenharmony_ci
19248c2ecf20Sopenharmony_ci	rc = bnx2x_filters_validate_mac(bp, vf, filters);
19258c2ecf20Sopenharmony_ci	if (rc)
19268c2ecf20Sopenharmony_ci		goto response;
19278c2ecf20Sopenharmony_ci
19288c2ecf20Sopenharmony_ci	rc = bnx2x_filters_validate_vlan(bp, vf, filters);
19298c2ecf20Sopenharmony_ci	if (rc)
19308c2ecf20Sopenharmony_ci		goto response;
19318c2ecf20Sopenharmony_ci
19328c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
19338c2ecf20Sopenharmony_ci	   vf->abs_vfid,
19348c2ecf20Sopenharmony_ci	   filters->vf_qid);
19358c2ecf20Sopenharmony_ci
19368c2ecf20Sopenharmony_ci	/* print q_filter message */
19378c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
19388c2ecf20Sopenharmony_ci
19398c2ecf20Sopenharmony_ci	rc = bnx2x_vf_mbx_qfilters(bp, vf);
19408c2ecf20Sopenharmony_ciresponse:
19418c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
19428c2ecf20Sopenharmony_ci}
19438c2ecf20Sopenharmony_ci
19448c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
19458c2ecf20Sopenharmony_ci				    struct bnx2x_vf_mbx *mbx)
19468c2ecf20Sopenharmony_ci{
19478c2ecf20Sopenharmony_ci	int qid = mbx->msg->req.q_op.vf_qid;
19488c2ecf20Sopenharmony_ci	int rc;
19498c2ecf20Sopenharmony_ci
19508c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
19518c2ecf20Sopenharmony_ci	   vf->abs_vfid, qid);
19528c2ecf20Sopenharmony_ci
19538c2ecf20Sopenharmony_ci	rc = bnx2x_vf_queue_teardown(bp, vf, qid);
19548c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
19558c2ecf20Sopenharmony_ci}
19568c2ecf20Sopenharmony_ci
19578c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
19588c2ecf20Sopenharmony_ci				  struct bnx2x_vf_mbx *mbx)
19598c2ecf20Sopenharmony_ci{
19608c2ecf20Sopenharmony_ci	int rc;
19618c2ecf20Sopenharmony_ci
19628c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
19638c2ecf20Sopenharmony_ci
19648c2ecf20Sopenharmony_ci	rc = bnx2x_vf_close(bp, vf);
19658c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
19668c2ecf20Sopenharmony_ci}
19678c2ecf20Sopenharmony_ci
19688c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
19698c2ecf20Sopenharmony_ci				    struct bnx2x_vf_mbx *mbx)
19708c2ecf20Sopenharmony_ci{
19718c2ecf20Sopenharmony_ci	int rc;
19728c2ecf20Sopenharmony_ci
19738c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
19748c2ecf20Sopenharmony_ci
19758c2ecf20Sopenharmony_ci	rc = bnx2x_vf_free(bp, vf);
19768c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
19778c2ecf20Sopenharmony_ci}
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
19808c2ecf20Sopenharmony_ci				    struct bnx2x_vf_mbx *mbx)
19818c2ecf20Sopenharmony_ci{
19828c2ecf20Sopenharmony_ci	struct bnx2x_config_rss_params rss;
19838c2ecf20Sopenharmony_ci	struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
19848c2ecf20Sopenharmony_ci	int rc = 0;
19858c2ecf20Sopenharmony_ci
19868c2ecf20Sopenharmony_ci	if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
19878c2ecf20Sopenharmony_ci	    rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
19888c2ecf20Sopenharmony_ci		BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
19898c2ecf20Sopenharmony_ci			  vf->index);
19908c2ecf20Sopenharmony_ci		rc = -EINVAL;
19918c2ecf20Sopenharmony_ci		goto mbx_resp;
19928c2ecf20Sopenharmony_ci	}
19938c2ecf20Sopenharmony_ci
19948c2ecf20Sopenharmony_ci	memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
19958c2ecf20Sopenharmony_ci
19968c2ecf20Sopenharmony_ci	/* set vfop params according to rss tlv */
19978c2ecf20Sopenharmony_ci	memcpy(rss.ind_table, rss_tlv->ind_table,
19988c2ecf20Sopenharmony_ci	       T_ETH_INDIRECTION_TABLE_SIZE);
19998c2ecf20Sopenharmony_ci	memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
20008c2ecf20Sopenharmony_ci	rss.rss_obj = &vf->rss_conf_obj;
20018c2ecf20Sopenharmony_ci	rss.rss_result_mask = rss_tlv->rss_result_mask;
20028c2ecf20Sopenharmony_ci
20038c2ecf20Sopenharmony_ci	/* flags handled individually for backward/forward compatibility */
20048c2ecf20Sopenharmony_ci	rss.rss_flags = 0;
20058c2ecf20Sopenharmony_ci	rss.ramrod_flags = 0;
20068c2ecf20Sopenharmony_ci
20078c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
20088c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
20098c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
20108c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
20118c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
20128c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
20138c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
20148c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
20158c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
20168c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
20178c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
20188c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
20198c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
20208c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
20218c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
20228c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
20238c2ecf20Sopenharmony_ci	if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
20248c2ecf20Sopenharmony_ci		__set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
20258c2ecf20Sopenharmony_ci
20268c2ecf20Sopenharmony_ci	if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
20278c2ecf20Sopenharmony_ci	     rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
20288c2ecf20Sopenharmony_ci	    (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
20298c2ecf20Sopenharmony_ci	     rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
20308c2ecf20Sopenharmony_ci		BNX2X_ERR("about to hit a FW assert. aborting...\n");
20318c2ecf20Sopenharmony_ci		rc = -EINVAL;
20328c2ecf20Sopenharmony_ci		goto mbx_resp;
20338c2ecf20Sopenharmony_ci	}
20348c2ecf20Sopenharmony_ci
20358c2ecf20Sopenharmony_ci	rc = bnx2x_vf_rss_update(bp, vf, &rss);
20368c2ecf20Sopenharmony_cimbx_resp:
20378c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
20388c2ecf20Sopenharmony_ci}
20398c2ecf20Sopenharmony_ci
20408c2ecf20Sopenharmony_cistatic int bnx2x_validate_tpa_params(struct bnx2x *bp,
20418c2ecf20Sopenharmony_ci				       struct vfpf_tpa_tlv *tpa_tlv)
20428c2ecf20Sopenharmony_ci{
20438c2ecf20Sopenharmony_ci	int rc = 0;
20448c2ecf20Sopenharmony_ci
20458c2ecf20Sopenharmony_ci	if (tpa_tlv->tpa_client_info.max_sges_for_packet >
20468c2ecf20Sopenharmony_ci	    U_ETH_MAX_SGES_FOR_PACKET) {
20478c2ecf20Sopenharmony_ci		rc = -EINVAL;
20488c2ecf20Sopenharmony_ci		BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
20498c2ecf20Sopenharmony_ci			  tpa_tlv->tpa_client_info.max_sges_for_packet,
20508c2ecf20Sopenharmony_ci			  U_ETH_MAX_SGES_FOR_PACKET);
20518c2ecf20Sopenharmony_ci	}
20528c2ecf20Sopenharmony_ci
20538c2ecf20Sopenharmony_ci	if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
20548c2ecf20Sopenharmony_ci		rc = -EINVAL;
20558c2ecf20Sopenharmony_ci		BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
20568c2ecf20Sopenharmony_ci			  tpa_tlv->tpa_client_info.max_tpa_queues,
20578c2ecf20Sopenharmony_ci			  MAX_AGG_QS(bp));
20588c2ecf20Sopenharmony_ci	}
20598c2ecf20Sopenharmony_ci
20608c2ecf20Sopenharmony_ci	return rc;
20618c2ecf20Sopenharmony_ci}
20628c2ecf20Sopenharmony_ci
20638c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
20648c2ecf20Sopenharmony_ci				    struct bnx2x_vf_mbx *mbx)
20658c2ecf20Sopenharmony_ci{
20668c2ecf20Sopenharmony_ci	struct bnx2x_queue_update_tpa_params vf_op_params;
20678c2ecf20Sopenharmony_ci	struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
20688c2ecf20Sopenharmony_ci	int rc = 0;
20698c2ecf20Sopenharmony_ci
20708c2ecf20Sopenharmony_ci	memset(&vf_op_params, 0, sizeof(vf_op_params));
20718c2ecf20Sopenharmony_ci
20728c2ecf20Sopenharmony_ci	if (bnx2x_validate_tpa_params(bp, tpa_tlv))
20738c2ecf20Sopenharmony_ci		goto mbx_resp;
20748c2ecf20Sopenharmony_ci
20758c2ecf20Sopenharmony_ci	vf_op_params.complete_on_both_clients =
20768c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.complete_on_both_clients;
20778c2ecf20Sopenharmony_ci	vf_op_params.dont_verify_thr =
20788c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.dont_verify_thr;
20798c2ecf20Sopenharmony_ci	vf_op_params.max_agg_sz =
20808c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.max_agg_size;
20818c2ecf20Sopenharmony_ci	vf_op_params.max_sges_pkt =
20828c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.max_sges_for_packet;
20838c2ecf20Sopenharmony_ci	vf_op_params.max_tpa_queues =
20848c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.max_tpa_queues;
20858c2ecf20Sopenharmony_ci	vf_op_params.sge_buff_sz =
20868c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.sge_buff_size;
20878c2ecf20Sopenharmony_ci	vf_op_params.sge_pause_thr_high =
20888c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.sge_pause_thr_high;
20898c2ecf20Sopenharmony_ci	vf_op_params.sge_pause_thr_low =
20908c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.sge_pause_thr_low;
20918c2ecf20Sopenharmony_ci	vf_op_params.tpa_mode =
20928c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.tpa_mode;
20938c2ecf20Sopenharmony_ci	vf_op_params.update_ipv4 =
20948c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.update_ipv4;
20958c2ecf20Sopenharmony_ci	vf_op_params.update_ipv6 =
20968c2ecf20Sopenharmony_ci		tpa_tlv->tpa_client_info.update_ipv6;
20978c2ecf20Sopenharmony_ci
20988c2ecf20Sopenharmony_ci	rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
20998c2ecf20Sopenharmony_ci
21008c2ecf20Sopenharmony_cimbx_resp:
21018c2ecf20Sopenharmony_ci	bnx2x_vf_mbx_resp(bp, vf, rc);
21028c2ecf20Sopenharmony_ci}
21038c2ecf20Sopenharmony_ci
21048c2ecf20Sopenharmony_ci/* dispatch request */
21058c2ecf20Sopenharmony_cistatic void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
21068c2ecf20Sopenharmony_ci				  struct bnx2x_vf_mbx *mbx)
21078c2ecf20Sopenharmony_ci{
21088c2ecf20Sopenharmony_ci	int i;
21098c2ecf20Sopenharmony_ci
21108c2ecf20Sopenharmony_ci	if (vf->state == VF_LOST) {
21118c2ecf20Sopenharmony_ci		/* Just ack the FW and return if VFs are lost
21128c2ecf20Sopenharmony_ci		 * in case of parity error. VFs are supposed to be timedout
21138c2ecf20Sopenharmony_ci		 * on waiting for PF response.
21148c2ecf20Sopenharmony_ci		 */
21158c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
21168c2ecf20Sopenharmony_ci		   "VF 0x%x lost, not handling the request\n", vf->abs_vfid);
21178c2ecf20Sopenharmony_ci
21188c2ecf20Sopenharmony_ci		storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
21198c2ecf20Sopenharmony_ci		return;
21208c2ecf20Sopenharmony_ci	}
21218c2ecf20Sopenharmony_ci
21228c2ecf20Sopenharmony_ci	/* check if tlv type is known */
21238c2ecf20Sopenharmony_ci	if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
21248c2ecf20Sopenharmony_ci		/* Lock the per vf op mutex and note the locker's identity.
21258c2ecf20Sopenharmony_ci		 * The unlock will take place in mbx response.
21268c2ecf20Sopenharmony_ci		 */
21278c2ecf20Sopenharmony_ci		bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
21288c2ecf20Sopenharmony_ci
21298c2ecf20Sopenharmony_ci		/* switch on the opcode */
21308c2ecf20Sopenharmony_ci		switch (mbx->first_tlv.tl.type) {
21318c2ecf20Sopenharmony_ci		case CHANNEL_TLV_ACQUIRE:
21328c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_acquire(bp, vf, mbx);
21338c2ecf20Sopenharmony_ci			return;
21348c2ecf20Sopenharmony_ci		case CHANNEL_TLV_INIT:
21358c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_init_vf(bp, vf, mbx);
21368c2ecf20Sopenharmony_ci			return;
21378c2ecf20Sopenharmony_ci		case CHANNEL_TLV_SETUP_Q:
21388c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_setup_q(bp, vf, mbx);
21398c2ecf20Sopenharmony_ci			return;
21408c2ecf20Sopenharmony_ci		case CHANNEL_TLV_SET_Q_FILTERS:
21418c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
21428c2ecf20Sopenharmony_ci			return;
21438c2ecf20Sopenharmony_ci		case CHANNEL_TLV_TEARDOWN_Q:
21448c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
21458c2ecf20Sopenharmony_ci			return;
21468c2ecf20Sopenharmony_ci		case CHANNEL_TLV_CLOSE:
21478c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_close_vf(bp, vf, mbx);
21488c2ecf20Sopenharmony_ci			return;
21498c2ecf20Sopenharmony_ci		case CHANNEL_TLV_RELEASE:
21508c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_release_vf(bp, vf, mbx);
21518c2ecf20Sopenharmony_ci			return;
21528c2ecf20Sopenharmony_ci		case CHANNEL_TLV_UPDATE_RSS:
21538c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_update_rss(bp, vf, mbx);
21548c2ecf20Sopenharmony_ci			return;
21558c2ecf20Sopenharmony_ci		case CHANNEL_TLV_UPDATE_TPA:
21568c2ecf20Sopenharmony_ci			bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
21578c2ecf20Sopenharmony_ci			return;
21588c2ecf20Sopenharmony_ci		}
21598c2ecf20Sopenharmony_ci
21608c2ecf20Sopenharmony_ci	} else {
21618c2ecf20Sopenharmony_ci		/* unknown TLV - this may belong to a VF driver from the future
21628c2ecf20Sopenharmony_ci		 * - a version written after this PF driver was written, which
21638c2ecf20Sopenharmony_ci		 * supports features unknown as of yet. Too bad since we don't
21648c2ecf20Sopenharmony_ci		 * support them. Or this may be because someone wrote a crappy
21658c2ecf20Sopenharmony_ci		 * VF driver and is sending garbage over the channel.
21668c2ecf20Sopenharmony_ci		 */
21678c2ecf20Sopenharmony_ci		BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
21688c2ecf20Sopenharmony_ci			  mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
21698c2ecf20Sopenharmony_ci			  vf->state);
21708c2ecf20Sopenharmony_ci		for (i = 0; i < 20; i++)
21718c2ecf20Sopenharmony_ci			DP_CONT(BNX2X_MSG_IOV, "%x ",
21728c2ecf20Sopenharmony_ci				mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
21738c2ecf20Sopenharmony_ci	}
21748c2ecf20Sopenharmony_ci
21758c2ecf20Sopenharmony_ci	/* can we respond to VF (do we have an address for it?) */
21768c2ecf20Sopenharmony_ci	if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
21778c2ecf20Sopenharmony_ci		/* notify the VF that we do not support this request */
21788c2ecf20Sopenharmony_ci		bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
21798c2ecf20Sopenharmony_ci	} else {
21808c2ecf20Sopenharmony_ci		/* can't send a response since this VF is unknown to us
21818c2ecf20Sopenharmony_ci		 * just ack the FW to release the mailbox and unlock
21828c2ecf20Sopenharmony_ci		 * the channel.
21838c2ecf20Sopenharmony_ci		 */
21848c2ecf20Sopenharmony_ci		storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
21858c2ecf20Sopenharmony_ci		/* Firmware ack should be written before unlocking channel */
21868c2ecf20Sopenharmony_ci		bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
21878c2ecf20Sopenharmony_ci	}
21888c2ecf20Sopenharmony_ci}
21898c2ecf20Sopenharmony_ci
21908c2ecf20Sopenharmony_civoid bnx2x_vf_mbx_schedule(struct bnx2x *bp,
21918c2ecf20Sopenharmony_ci			   struct vf_pf_event_data *vfpf_event)
21928c2ecf20Sopenharmony_ci{
21938c2ecf20Sopenharmony_ci	u8 vf_idx;
21948c2ecf20Sopenharmony_ci
21958c2ecf20Sopenharmony_ci	DP(BNX2X_MSG_IOV,
21968c2ecf20Sopenharmony_ci	   "vf pf event received: vfid %d, address_hi %x, address lo %x",
21978c2ecf20Sopenharmony_ci	   vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
21988c2ecf20Sopenharmony_ci	/* Sanity checks consider removing later */
21998c2ecf20Sopenharmony_ci
22008c2ecf20Sopenharmony_ci	/* check if the vf_id is valid */
22018c2ecf20Sopenharmony_ci	if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
22028c2ecf20Sopenharmony_ci	    BNX2X_NR_VIRTFN(bp)) {
22038c2ecf20Sopenharmony_ci		BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
22048c2ecf20Sopenharmony_ci			  vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
22058c2ecf20Sopenharmony_ci		return;
22068c2ecf20Sopenharmony_ci	}
22078c2ecf20Sopenharmony_ci
22088c2ecf20Sopenharmony_ci	vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
22098c2ecf20Sopenharmony_ci
22108c2ecf20Sopenharmony_ci	/* Update VFDB with current message and schedule its handling */
22118c2ecf20Sopenharmony_ci	mutex_lock(&BP_VFDB(bp)->event_mutex);
22128c2ecf20Sopenharmony_ci	BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
22138c2ecf20Sopenharmony_ci		le32_to_cpu(vfpf_event->msg_addr_hi);
22148c2ecf20Sopenharmony_ci	BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
22158c2ecf20Sopenharmony_ci		le32_to_cpu(vfpf_event->msg_addr_lo);
22168c2ecf20Sopenharmony_ci	BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
22178c2ecf20Sopenharmony_ci	mutex_unlock(&BP_VFDB(bp)->event_mutex);
22188c2ecf20Sopenharmony_ci
22198c2ecf20Sopenharmony_ci	bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
22208c2ecf20Sopenharmony_ci}
22218c2ecf20Sopenharmony_ci
22228c2ecf20Sopenharmony_ci/* handle new vf-pf messages */
22238c2ecf20Sopenharmony_civoid bnx2x_vf_mbx(struct bnx2x *bp)
22248c2ecf20Sopenharmony_ci{
22258c2ecf20Sopenharmony_ci	struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
22268c2ecf20Sopenharmony_ci	u64 events;
22278c2ecf20Sopenharmony_ci	u8 vf_idx;
22288c2ecf20Sopenharmony_ci	int rc;
22298c2ecf20Sopenharmony_ci
22308c2ecf20Sopenharmony_ci	if (!vfdb)
22318c2ecf20Sopenharmony_ci		return;
22328c2ecf20Sopenharmony_ci
22338c2ecf20Sopenharmony_ci	mutex_lock(&vfdb->event_mutex);
22348c2ecf20Sopenharmony_ci	events = vfdb->event_occur;
22358c2ecf20Sopenharmony_ci	vfdb->event_occur = 0;
22368c2ecf20Sopenharmony_ci	mutex_unlock(&vfdb->event_mutex);
22378c2ecf20Sopenharmony_ci
22388c2ecf20Sopenharmony_ci	for_each_vf(bp, vf_idx) {
22398c2ecf20Sopenharmony_ci		struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
22408c2ecf20Sopenharmony_ci		struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
22418c2ecf20Sopenharmony_ci
22428c2ecf20Sopenharmony_ci		/* Handle VFs which have pending events */
22438c2ecf20Sopenharmony_ci		if (!(events & (1ULL << vf_idx)))
22448c2ecf20Sopenharmony_ci			continue;
22458c2ecf20Sopenharmony_ci
22468c2ecf20Sopenharmony_ci		DP(BNX2X_MSG_IOV,
22478c2ecf20Sopenharmony_ci		   "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
22488c2ecf20Sopenharmony_ci		   vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
22498c2ecf20Sopenharmony_ci		   mbx->first_tlv.resp_msg_offset);
22508c2ecf20Sopenharmony_ci
22518c2ecf20Sopenharmony_ci		/* dmae to get the VF request */
22528c2ecf20Sopenharmony_ci		rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
22538c2ecf20Sopenharmony_ci					  vf->abs_vfid, mbx->vf_addr_hi,
22548c2ecf20Sopenharmony_ci					  mbx->vf_addr_lo,
22558c2ecf20Sopenharmony_ci					  sizeof(union vfpf_tlvs)/4);
22568c2ecf20Sopenharmony_ci		if (rc) {
22578c2ecf20Sopenharmony_ci			BNX2X_ERR("Failed to copy request VF %d\n",
22588c2ecf20Sopenharmony_ci				  vf->abs_vfid);
22598c2ecf20Sopenharmony_ci			bnx2x_vf_release(bp, vf);
22608c2ecf20Sopenharmony_ci			return;
22618c2ecf20Sopenharmony_ci		}
22628c2ecf20Sopenharmony_ci
22638c2ecf20Sopenharmony_ci		/* process the VF message header */
22648c2ecf20Sopenharmony_ci		mbx->first_tlv = mbx->msg->req.first_tlv;
22658c2ecf20Sopenharmony_ci
22668c2ecf20Sopenharmony_ci		/* Clean response buffer to refrain from falsely
22678c2ecf20Sopenharmony_ci		 * seeing chains.
22688c2ecf20Sopenharmony_ci		 */
22698c2ecf20Sopenharmony_ci		memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
22708c2ecf20Sopenharmony_ci
22718c2ecf20Sopenharmony_ci		/* dispatch the request (will prepare the response) */
22728c2ecf20Sopenharmony_ci		bnx2x_vf_mbx_request(bp, vf, mbx);
22738c2ecf20Sopenharmony_ci	}
22748c2ecf20Sopenharmony_ci}
22758c2ecf20Sopenharmony_ci
22768c2ecf20Sopenharmony_civoid bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
22778c2ecf20Sopenharmony_ci				bool support_long)
22788c2ecf20Sopenharmony_ci{
22798c2ecf20Sopenharmony_ci	/* Older VFs contain a bug where they can't check CRC for bulletin
22808c2ecf20Sopenharmony_ci	 * boards of length greater than legacy size.
22818c2ecf20Sopenharmony_ci	 */
22828c2ecf20Sopenharmony_ci	bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
22838c2ecf20Sopenharmony_ci					  BULLETIN_CONTENT_LEGACY_SIZE;
22848c2ecf20Sopenharmony_ci	bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
22858c2ecf20Sopenharmony_ci}
22868c2ecf20Sopenharmony_ci
22878c2ecf20Sopenharmony_ci/* propagate local bulletin board to vf */
22888c2ecf20Sopenharmony_ciint bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
22898c2ecf20Sopenharmony_ci{
22908c2ecf20Sopenharmony_ci	struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
22918c2ecf20Sopenharmony_ci	dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
22928c2ecf20Sopenharmony_ci		vf * BULLETIN_CONTENT_SIZE;
22938c2ecf20Sopenharmony_ci	dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
22948c2ecf20Sopenharmony_ci	int rc;
22958c2ecf20Sopenharmony_ci
22968c2ecf20Sopenharmony_ci	/* can only update vf after init took place */
22978c2ecf20Sopenharmony_ci	if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
22988c2ecf20Sopenharmony_ci	    bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
22998c2ecf20Sopenharmony_ci		return 0;
23008c2ecf20Sopenharmony_ci
23018c2ecf20Sopenharmony_ci	/* increment bulletin board version and compute crc */
23028c2ecf20Sopenharmony_ci	bulletin->version++;
23038c2ecf20Sopenharmony_ci	bnx2x_vf_bulletin_finalize(bulletin,
23048c2ecf20Sopenharmony_ci				   (bnx2x_vf(bp, vf, cfg_flags) &
23058c2ecf20Sopenharmony_ci				    VF_CFG_EXT_BULLETIN) ? true : false);
23068c2ecf20Sopenharmony_ci
23078c2ecf20Sopenharmony_ci	/* propagate bulletin board via dmae to vm memory */
23088c2ecf20Sopenharmony_ci	rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
23098c2ecf20Sopenharmony_ci				  bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
23108c2ecf20Sopenharmony_ci				  U64_LO(vf_addr), bulletin->length / 4);
23118c2ecf20Sopenharmony_ci	return rc;
23128c2ecf20Sopenharmony_ci}
2313