xref: /freebsd/sys/dev/bnxt/bnxt_re/qplib_sp.c (revision bbe42332e5b2cbe16a885360fad4462d13c7b357)
1acd884deSSumit Saxena /*
2acd884deSSumit Saxena  * Copyright (c) 2015-2024, Broadcom. All rights reserved.  The term
3acd884deSSumit Saxena  * Broadcom refers to Broadcom Limited and/or its subsidiaries.
4acd884deSSumit Saxena  *
5acd884deSSumit Saxena  * Redistribution and use in source and binary forms, with or without
6acd884deSSumit Saxena  * modification, are permitted provided that the following conditions
7acd884deSSumit Saxena  * are met:
8acd884deSSumit Saxena  *
9acd884deSSumit Saxena  * 1. Redistributions of source code must retain the above copyright
10acd884deSSumit Saxena  *    notice, this list of conditions and the following disclaimer.
11acd884deSSumit Saxena  * 2. Redistributions in binary form must reproduce the above copyright
12acd884deSSumit Saxena  *    notice, this list of conditions and the following disclaimer in
13acd884deSSumit Saxena  *    the documentation and/or other materials provided with the
14acd884deSSumit Saxena  *    distribution.
15acd884deSSumit Saxena  *
16acd884deSSumit Saxena  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
17acd884deSSumit Saxena  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18acd884deSSumit Saxena  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19acd884deSSumit Saxena  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
20acd884deSSumit Saxena  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21acd884deSSumit Saxena  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22acd884deSSumit Saxena  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23acd884deSSumit Saxena  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24acd884deSSumit Saxena  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25acd884deSSumit Saxena  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26acd884deSSumit Saxena  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27acd884deSSumit Saxena  *
28acd884deSSumit Saxena  * Description: Slow Path Operators
29acd884deSSumit Saxena  */
30acd884deSSumit Saxena 
31acd884deSSumit Saxena #include <linux/interrupt.h>
32acd884deSSumit Saxena #include <linux/spinlock.h>
33acd884deSSumit Saxena #include <linux/sched.h>
34acd884deSSumit Saxena #include <linux/pci.h>
35acd884deSSumit Saxena #include <linux/if_ether.h>
36acd884deSSumit Saxena #include <linux/printk.h>
37acd884deSSumit Saxena 
38acd884deSSumit Saxena #include "hsi_struct_def.h"
39acd884deSSumit Saxena #include "qplib_tlv.h"
40acd884deSSumit Saxena #include "qplib_res.h"
41acd884deSSumit Saxena #include "qplib_rcfw.h"
42acd884deSSumit Saxena #include "qplib_sp.h"
43acd884deSSumit Saxena 
44acd884deSSumit Saxena const struct bnxt_qplib_gid bnxt_qplib_gid_zero = {{ 0, 0, 0, 0, 0, 0, 0, 0,
45acd884deSSumit Saxena 						     0, 0, 0, 0, 0, 0, 0, 0 }};
46acd884deSSumit Saxena 
47acd884deSSumit Saxena /* Device */
bnxt_qplib_is_atomic_cap(struct bnxt_qplib_rcfw * rcfw)48acd884deSSumit Saxena static u8 bnxt_qplib_is_atomic_cap(struct bnxt_qplib_rcfw *rcfw)
49acd884deSSumit Saxena {
50acd884deSSumit Saxena 	u16 pcie_ctl2 = 0;
51acd884deSSumit Saxena 
52acd884deSSumit Saxena 	if (!_is_chip_gen_p5_p7(rcfw->res->cctx))
53acd884deSSumit Saxena 		return false;
54acd884deSSumit Saxena 	pcie_capability_read_word(rcfw->pdev, PCI_EXP_DEVCTL2, &pcie_ctl2);
55acd884deSSumit Saxena 	return (pcie_ctl2 & PCI_EXP_DEVCTL2_ATOMIC_REQ);
56acd884deSSumit Saxena }
57acd884deSSumit Saxena 
bnxt_qplib_query_version(struct bnxt_qplib_rcfw * rcfw,char * fw_ver)58acd884deSSumit Saxena static void bnxt_qplib_query_version(struct bnxt_qplib_rcfw *rcfw, char *fw_ver)
59acd884deSSumit Saxena {
60acd884deSSumit Saxena 	struct creq_query_version_resp resp = {};
61acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
62acd884deSSumit Saxena 	struct cmdq_query_version req = {};
63acd884deSSumit Saxena 	int rc = 0;
64acd884deSSumit Saxena 
65acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_QUERY_VERSION,
66acd884deSSumit Saxena 				 sizeof(req));
67acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
68acd884deSSumit Saxena 				sizeof(resp), 0);
69acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
70acd884deSSumit Saxena 	if (rc) {
71acd884deSSumit Saxena 		dev_err(&rcfw->pdev->dev, "QPLIB: Failed to query version\n");
72acd884deSSumit Saxena 		return;
73acd884deSSumit Saxena 	}
74acd884deSSumit Saxena 	fw_ver[0] = resp.fw_maj;
75acd884deSSumit Saxena 	fw_ver[1] = resp.fw_minor;
76acd884deSSumit Saxena 	fw_ver[2] = resp.fw_bld;
77acd884deSSumit Saxena 	fw_ver[3] = resp.fw_rsvd;
78acd884deSSumit Saxena }
79acd884deSSumit Saxena 
bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw * rcfw)80acd884deSSumit Saxena int bnxt_qplib_get_dev_attr(struct bnxt_qplib_rcfw *rcfw)
81acd884deSSumit Saxena {
82acd884deSSumit Saxena 	struct creq_query_func_resp resp = {};
83acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
84acd884deSSumit Saxena 	struct creq_query_func_resp_sb *sb;
85acd884deSSumit Saxena 	struct bnxt_qplib_rcfw_sbuf sbuf;
86acd884deSSumit Saxena 	struct bnxt_qplib_dev_attr *attr;
87acd884deSSumit Saxena 	struct bnxt_qplib_chip_ctx *cctx;
88acd884deSSumit Saxena 	struct cmdq_query_func req = {};
89acd884deSSumit Saxena 	u8 *tqm_alloc;
90acd884deSSumit Saxena 	int i, rc = 0;
91acd884deSSumit Saxena 	u32 temp;
92acd884deSSumit Saxena 	u8 chip_gen = BNXT_RE_DEFAULT;
93acd884deSSumit Saxena 
94acd884deSSumit Saxena 	cctx = rcfw->res->cctx;
95acd884deSSumit Saxena 	attr = rcfw->res->dattr;
96acd884deSSumit Saxena 
97acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_QUERY_FUNC,
98acd884deSSumit Saxena 				 sizeof(req));
99acd884deSSumit Saxena 
100acd884deSSumit Saxena 	sbuf.size = sizeof(*sb);
101acd884deSSumit Saxena 	sbuf.sb = dma_zalloc_coherent(&rcfw->pdev->dev, sbuf.size,
102acd884deSSumit Saxena 				       &sbuf.dma_addr, GFP_KERNEL);
103acd884deSSumit Saxena 	if (!sbuf.sb)
104acd884deSSumit Saxena 		return -ENOMEM;
105acd884deSSumit Saxena 
106acd884deSSumit Saxena 	sb = sbuf.sb;
107acd884deSSumit Saxena 	req.resp_size = sbuf.size / BNXT_QPLIB_CMDQE_UNITS;
108acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req),
109acd884deSSumit Saxena 				sizeof(resp), 0);
110acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
111acd884deSSumit Saxena 	if (rc)
112acd884deSSumit Saxena 		goto bail;
113acd884deSSumit Saxena 	/* Extract the context from the side buffer */
114acd884deSSumit Saxena 	chip_gen = _get_chip_gen_p5_type(cctx);
115acd884deSSumit Saxena 	attr->max_qp = le32_to_cpu(sb->max_qp);
116acd884deSSumit Saxena 	attr->max_qp = min_t(u32, attr->max_qp, BNXT_RE_MAX_QP_SUPPORTED(chip_gen));
117acd884deSSumit Saxena 	/* max_qp value reported by FW does not include the QP1 */
118acd884deSSumit Saxena 	attr->max_qp += 1;
119acd884deSSumit Saxena 	attr->max_qp_rd_atom =
120acd884deSSumit Saxena 		sb->max_qp_rd_atom > BNXT_QPLIB_MAX_OUT_RD_ATOM ?
121acd884deSSumit Saxena 		BNXT_QPLIB_MAX_OUT_RD_ATOM : sb->max_qp_rd_atom;
122acd884deSSumit Saxena 	attr->max_qp_init_rd_atom =
123acd884deSSumit Saxena 		sb->max_qp_init_rd_atom > BNXT_QPLIB_MAX_OUT_RD_ATOM ?
124acd884deSSumit Saxena 		BNXT_QPLIB_MAX_OUT_RD_ATOM : sb->max_qp_init_rd_atom;
125acd884deSSumit Saxena 	/* Report 1 less than the max_qp_wqes reported by FW as driver adds
126acd884deSSumit Saxena 	 * one extra entry while creating the qp
127acd884deSSumit Saxena 	 */
128acd884deSSumit Saxena 	attr->max_qp_wqes = le16_to_cpu(sb->max_qp_wr) - 1;
129acd884deSSumit Saxena 	/* Adjust for max_qp_wqes for variable wqe */
130acd884deSSumit Saxena 	if (cctx->modes.wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE) {
131acd884deSSumit Saxena 		attr->max_qp_wqes = (BNXT_MAX_SQ_SIZE) /
132acd884deSSumit Saxena 			(BNXT_MAX_VAR_WQE_SIZE / BNXT_SGE_SIZE) - 1;
133acd884deSSumit Saxena 	}
134acd884deSSumit Saxena 	if (!_is_chip_gen_p5_p7(cctx)) {
135acd884deSSumit Saxena 		/*
136acd884deSSumit Saxena 		 * 128 WQEs needs to be reserved for the HW (8916). Prevent
137acd884deSSumit Saxena 		 * reporting the max number for gen-p4 only.
138acd884deSSumit Saxena 		 */
139acd884deSSumit Saxena 		attr->max_qp_wqes -= BNXT_QPLIB_RESERVED_QP_WRS;
140acd884deSSumit Saxena 	}
141acd884deSSumit Saxena 	attr->max_qp_sges = sb->max_sge;
142acd884deSSumit Saxena 	if (_is_chip_gen_p5_p7(cctx) &&
143acd884deSSumit Saxena 	    cctx->modes.wqe_mode == BNXT_QPLIB_WQE_MODE_VARIABLE)
144acd884deSSumit Saxena 		attr->max_qp_sges = sb->max_sge_var_wqe;
145acd884deSSumit Saxena 	attr->max_cq = le32_to_cpu(sb->max_cq);
146acd884deSSumit Saxena 	attr->max_cq = min_t(u32, attr->max_cq, BNXT_RE_MAX_CQ_SUPPORTED(chip_gen));
147acd884deSSumit Saxena 
148acd884deSSumit Saxena 	attr->max_cq_wqes = le32_to_cpu(sb->max_cqe);
149acd884deSSumit Saxena 	attr->max_cq_wqes = min_t(u32, BNXT_QPLIB_MAX_CQ_WQES, attr->max_cq_wqes);
150acd884deSSumit Saxena 
151acd884deSSumit Saxena 	attr->max_cq_sges = attr->max_qp_sges;
152acd884deSSumit Saxena 	attr->max_mr = le32_to_cpu(sb->max_mr);
153acd884deSSumit Saxena 	attr->max_mr = min_t(u32, attr->max_mr, BNXT_RE_MAX_MRW_SUPPORTED(chip_gen));
154acd884deSSumit Saxena 	attr->max_mw = le32_to_cpu(sb->max_mw);
155acd884deSSumit Saxena 	attr->max_mw = min_t(u32, attr->max_mw, BNXT_RE_MAX_MRW_SUPPORTED(chip_gen));
156acd884deSSumit Saxena 
157acd884deSSumit Saxena 	attr->max_mr_size = le64_to_cpu(sb->max_mr_size);
158acd884deSSumit Saxena 	attr->max_pd = BNXT_QPLIB_MAX_PD;
159acd884deSSumit Saxena 	attr->max_raw_ethy_qp = le32_to_cpu(sb->max_raw_eth_qp);
160acd884deSSumit Saxena 	attr->max_ah = le32_to_cpu(sb->max_ah);
161acd884deSSumit Saxena 	attr->max_ah = min_t(u32, attr->max_ah, BNXT_RE_MAX_AH_SUPPORTED(chip_gen));
162acd884deSSumit Saxena 
163acd884deSSumit Saxena 	attr->max_fmr = le32_to_cpu(sb->max_fmr);
164acd884deSSumit Saxena 	attr->max_map_per_fmr = sb->max_map_per_fmr;
165acd884deSSumit Saxena 
166acd884deSSumit Saxena 	attr->max_srq = le16_to_cpu(sb->max_srq);
167acd884deSSumit Saxena 	attr->max_srq = min_t(u32, attr->max_srq, BNXT_RE_MAX_SRQ_SUPPORTED(chip_gen));
168acd884deSSumit Saxena 	attr->max_srq_wqes = le32_to_cpu(sb->max_srq_wr) - 1;
169acd884deSSumit Saxena 	attr->max_srq_sges = sb->max_srq_sge;
170acd884deSSumit Saxena 	attr->max_pkey = 1;
171acd884deSSumit Saxena 
172acd884deSSumit Saxena 	attr->max_inline_data = !cctx->modes.wqe_mode ?
173acd884deSSumit Saxena 				le32_to_cpu(sb->max_inline_data) :
174acd884deSSumit Saxena 				le16_to_cpu(sb->max_inline_data_var_wqe);
175acd884deSSumit Saxena 	if (!_is_chip_p7(cctx)) {
176acd884deSSumit Saxena 		attr->l2_db_size = (sb->l2_db_space_size + 1) *
177acd884deSSumit Saxena 				    (0x01 << RCFW_DBR_BASE_PAGE_SHIFT);
178acd884deSSumit Saxena 	}
179acd884deSSumit Saxena 	attr->max_sgid = le32_to_cpu(sb->max_gid);
180acd884deSSumit Saxena 
181acd884deSSumit Saxena 	/* TODO: remove this hack for statically allocated gid_map */
182acd884deSSumit Saxena 	bnxt_re_set_max_gid(&attr->max_sgid);
183acd884deSSumit Saxena 
184acd884deSSumit Saxena 	attr->dev_cap_flags = le16_to_cpu(sb->dev_cap_flags);
185acd884deSSumit Saxena 	attr->page_size_cap = BIT_ULL(28) | BIT_ULL(21) | BIT_ULL(12);
186acd884deSSumit Saxena 
187acd884deSSumit Saxena 	bnxt_qplib_query_version(rcfw, attr->fw_ver);
188acd884deSSumit Saxena 
189acd884deSSumit Saxena 	for (i = 0; i < MAX_TQM_ALLOC_REQ / 4; i++) {
190acd884deSSumit Saxena 		temp = le32_to_cpu(sb->tqm_alloc_reqs[i]);
191acd884deSSumit Saxena 		tqm_alloc = (u8 *)&temp;
192acd884deSSumit Saxena 		attr->tqm_alloc_reqs[i * 4] = *tqm_alloc;
193acd884deSSumit Saxena 		attr->tqm_alloc_reqs[i * 4 + 1] = *(++tqm_alloc);
194acd884deSSumit Saxena 		attr->tqm_alloc_reqs[i * 4 + 2] = *(++tqm_alloc);
195acd884deSSumit Saxena 		attr->tqm_alloc_reqs[i * 4 + 3] = *(++tqm_alloc);
196acd884deSSumit Saxena 	}
197acd884deSSumit Saxena 
198acd884deSSumit Saxena 	if (rcfw->res->cctx->hwrm_intf_ver >= HWRM_VERSION_DEV_ATTR_MAX_DPI)
199acd884deSSumit Saxena 		attr->max_dpi = le32_to_cpu(sb->max_dpi);
200acd884deSSumit Saxena 
201acd884deSSumit Saxena 	attr->is_atomic = bnxt_qplib_is_atomic_cap(rcfw);
202acd884deSSumit Saxena bail:
203acd884deSSumit Saxena 	dma_free_coherent(&rcfw->pdev->dev, sbuf.size,
204acd884deSSumit Saxena 				  sbuf.sb, sbuf.dma_addr);
205acd884deSSumit Saxena 	return rc;
206acd884deSSumit Saxena }
207acd884deSSumit Saxena 
bnxt_qplib_set_func_resources(struct bnxt_qplib_res * res)208acd884deSSumit Saxena int bnxt_qplib_set_func_resources(struct bnxt_qplib_res *res)
209acd884deSSumit Saxena {
210acd884deSSumit Saxena 	struct creq_set_func_resources_resp resp = {};
211acd884deSSumit Saxena 	struct cmdq_set_func_resources req = {};
212acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
213acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw;
214acd884deSSumit Saxena 	struct bnxt_qplib_ctx *hctx;
215acd884deSSumit Saxena 	int rc = 0;
216acd884deSSumit Saxena 
217acd884deSSumit Saxena 	rcfw = res->rcfw;
218acd884deSSumit Saxena 	hctx = res->hctx;
219acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_SET_FUNC_RESOURCES,
220acd884deSSumit Saxena 				 sizeof(req));
221acd884deSSumit Saxena 
222acd884deSSumit Saxena 	req.number_of_qp = cpu_to_le32(hctx->qp_ctx.max);
223acd884deSSumit Saxena 	req.number_of_mrw = cpu_to_le32(hctx->mrw_ctx.max);
224acd884deSSumit Saxena 	req.number_of_srq =  cpu_to_le32(hctx->srq_ctx.max);
225acd884deSSumit Saxena 	req.number_of_cq = cpu_to_le32(hctx->cq_ctx.max);
226acd884deSSumit Saxena 
227acd884deSSumit Saxena 	req.max_qp_per_vf = cpu_to_le32(hctx->vf_res.max_qp);
228acd884deSSumit Saxena 	req.max_mrw_per_vf = cpu_to_le32(hctx->vf_res.max_mrw);
229acd884deSSumit Saxena 	req.max_srq_per_vf = cpu_to_le32(hctx->vf_res.max_srq);
230acd884deSSumit Saxena 	req.max_cq_per_vf = cpu_to_le32(hctx->vf_res.max_cq);
231acd884deSSumit Saxena 	req.max_gid_per_vf = cpu_to_le32(hctx->vf_res.max_gid);
232acd884deSSumit Saxena 
233acd884deSSumit Saxena 	/* Keep the old stats context id of PF */
234acd884deSSumit Saxena 	req.stat_ctx_id = cpu_to_le32(hctx->stats.fw_id);
235acd884deSSumit Saxena 
236acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
237acd884deSSumit Saxena 				sizeof(resp), 0);
238acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
239acd884deSSumit Saxena 	if (rc)
240acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
241acd884deSSumit Saxena 			"QPLIB: Failed to set function resources\n");
242acd884deSSumit Saxena 
243acd884deSSumit Saxena 	return rc;
244acd884deSSumit Saxena }
245acd884deSSumit Saxena 
bnxt_qplib_update_sgid(struct bnxt_qplib_sgid_tbl * sgid_tbl,struct bnxt_qplib_gid * gid,u16 gid_idx,const u8 * smac)246acd884deSSumit Saxena int bnxt_qplib_update_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
247acd884deSSumit Saxena 			   struct bnxt_qplib_gid *gid, u16 gid_idx, const u8 *smac)
248acd884deSSumit Saxena {
249acd884deSSumit Saxena 	struct bnxt_qplib_res *res = to_bnxt_qplib(sgid_tbl,
250acd884deSSumit Saxena 						   struct bnxt_qplib_res,
251acd884deSSumit Saxena 						   sgid_tbl);
252acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
253acd884deSSumit Saxena 	struct creq_modify_gid_resp resp = {};
254acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
255acd884deSSumit Saxena 	struct cmdq_modify_gid req = {};
256acd884deSSumit Saxena 	int rc;
257acd884deSSumit Saxena 
258acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_MODIFY_GID,
259acd884deSSumit Saxena 				 sizeof(req));
260acd884deSSumit Saxena 
261acd884deSSumit Saxena 	req.gid[0] = cpu_to_be32(((u32 *)gid->data)[3]);
262acd884deSSumit Saxena 	req.gid[1] = cpu_to_be32(((u32 *)gid->data)[2]);
263acd884deSSumit Saxena 	req.gid[2] = cpu_to_be32(((u32 *)gid->data)[1]);
264acd884deSSumit Saxena 	req.gid[3] = cpu_to_be32(((u32 *)gid->data)[0]);
265acd884deSSumit Saxena 	if (res->prio) {
266acd884deSSumit Saxena 		req.vlan |= cpu_to_le16(CMDQ_ADD_GID_VLAN_TPID_TPID_8100 |
267acd884deSSumit Saxena 			CMDQ_ADD_GID_VLAN_VLAN_EN);
268acd884deSSumit Saxena 	}
269acd884deSSumit Saxena 
270acd884deSSumit Saxena 	/* MAC in network format */
271acd884deSSumit Saxena 	req.src_mac[0] = cpu_to_be16(((u16 *)smac)[0]);
272acd884deSSumit Saxena 	req.src_mac[1] = cpu_to_be16(((u16 *)smac)[1]);
273acd884deSSumit Saxena 	req.src_mac[2] = cpu_to_be16(((u16 *)smac)[2]);
274acd884deSSumit Saxena 	req.gid_index = cpu_to_le16(gid_idx);
275acd884deSSumit Saxena 
276acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
277acd884deSSumit Saxena 				sizeof(resp), 0);
278acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
279acd884deSSumit Saxena 	if (rc) {
280acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
281acd884deSSumit Saxena 			"QPLIB: update SGID table failed\n");
282acd884deSSumit Saxena 		return rc;
283acd884deSSumit Saxena 	}
284acd884deSSumit Saxena 	return 0;
285acd884deSSumit Saxena }
286acd884deSSumit Saxena 
287acd884deSSumit Saxena /* SGID */
bnxt_qplib_get_sgid(struct bnxt_qplib_res * res,struct bnxt_qplib_sgid_tbl * sgid_tbl,int index,struct bnxt_qplib_gid * gid)288acd884deSSumit Saxena int bnxt_qplib_get_sgid(struct bnxt_qplib_res *res,
289acd884deSSumit Saxena 			struct bnxt_qplib_sgid_tbl *sgid_tbl, int index,
290acd884deSSumit Saxena 			struct bnxt_qplib_gid *gid)
291acd884deSSumit Saxena {
292acd884deSSumit Saxena 	if (index > sgid_tbl->max) {
293acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
294acd884deSSumit Saxena 			"QPLIB: Index %d exceeded SGID table max (%d)\n",
295acd884deSSumit Saxena 			index, sgid_tbl->max);
296acd884deSSumit Saxena 		return -EINVAL;
297acd884deSSumit Saxena 	}
298acd884deSSumit Saxena 	memcpy(gid, &sgid_tbl->tbl[index].gid, sizeof(*gid));
299acd884deSSumit Saxena 	return 0;
300acd884deSSumit Saxena }
301acd884deSSumit Saxena 
bnxt_qplib_del_sgid(struct bnxt_qplib_sgid_tbl * sgid_tbl,struct bnxt_qplib_gid * gid,u16 vlan_id,bool update)302acd884deSSumit Saxena int bnxt_qplib_del_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
303acd884deSSumit Saxena 			struct bnxt_qplib_gid *gid,
304acd884deSSumit Saxena 			u16 vlan_id, bool update)
305acd884deSSumit Saxena {
306acd884deSSumit Saxena 	struct bnxt_qplib_res *res = to_bnxt_qplib(sgid_tbl,
307acd884deSSumit Saxena 						   struct bnxt_qplib_res,
308acd884deSSumit Saxena 						   sgid_tbl);
309acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
310acd884deSSumit Saxena 	int index;
311acd884deSSumit Saxena 
312acd884deSSumit Saxena 	if (sgid_tbl == NULL) {
313acd884deSSumit Saxena 		dev_err(&res->pdev->dev, "QPLIB: SGID table not allocated\n");
314acd884deSSumit Saxena 		return -EINVAL;
315acd884deSSumit Saxena 	}
316acd884deSSumit Saxena 	/* Do we need a sgid_lock here? */
317acd884deSSumit Saxena 	if (!sgid_tbl->active) {
318acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
319acd884deSSumit Saxena 			"QPLIB: SGID table has no active entries\n");
320acd884deSSumit Saxena 		return -ENOMEM;
321acd884deSSumit Saxena 	}
322acd884deSSumit Saxena 	for (index = 0; index < sgid_tbl->max; index++) {
323acd884deSSumit Saxena 		if (!memcmp(&sgid_tbl->tbl[index].gid, gid, sizeof(*gid)) &&
324acd884deSSumit Saxena 		    vlan_id == sgid_tbl->tbl[index].vlan_id)
325acd884deSSumit Saxena 			break;
326acd884deSSumit Saxena 	}
327acd884deSSumit Saxena 	if (index == sgid_tbl->max) {
328acd884deSSumit Saxena 		dev_warn(&res->pdev->dev, "GID not found in the SGID table\n");
329acd884deSSumit Saxena 		return 0;
330acd884deSSumit Saxena 	}
331acd884deSSumit Saxena 
332acd884deSSumit Saxena 	if (update) {
333acd884deSSumit Saxena 		struct creq_delete_gid_resp resp = {};
334acd884deSSumit Saxena 		struct bnxt_qplib_cmdqmsg msg = {};
335acd884deSSumit Saxena 		struct cmdq_delete_gid req = {};
336acd884deSSumit Saxena 		int rc;
337acd884deSSumit Saxena 
338acd884deSSumit Saxena 		bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_DELETE_GID,
339acd884deSSumit Saxena 					 sizeof(req));
340acd884deSSumit Saxena 		if (sgid_tbl->hw_id[index] == 0xFFFF) {
341acd884deSSumit Saxena 			dev_err(&res->pdev->dev,
342acd884deSSumit Saxena 				"QPLIB: GID entry contains an invalid HW id");
343acd884deSSumit Saxena 			return -EINVAL;
344acd884deSSumit Saxena 		}
345acd884deSSumit Saxena 		req.gid_index = cpu_to_le16(sgid_tbl->hw_id[index]);
346acd884deSSumit Saxena 		bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
347acd884deSSumit Saxena 					sizeof(resp), 0);
348acd884deSSumit Saxena 		rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
349acd884deSSumit Saxena 		if (rc)
350acd884deSSumit Saxena 			return rc;
351acd884deSSumit Saxena 	}
352acd884deSSumit Saxena 	memcpy(&sgid_tbl->tbl[index].gid, &bnxt_qplib_gid_zero,
353acd884deSSumit Saxena 	       sizeof(bnxt_qplib_gid_zero));
354acd884deSSumit Saxena 	sgid_tbl->tbl[index].vlan_id = 0xFFFF;
355acd884deSSumit Saxena 	sgid_tbl->vlan[index] = false;
356acd884deSSumit Saxena 	sgid_tbl->active--;
357acd884deSSumit Saxena 	dev_dbg(&res->pdev->dev,
358acd884deSSumit Saxena 		 "QPLIB: SGID deleted hw_id[0x%x] = 0x%x active = 0x%x\n",
359acd884deSSumit Saxena 		 index, sgid_tbl->hw_id[index], sgid_tbl->active);
360acd884deSSumit Saxena 	sgid_tbl->hw_id[index] = (u16)-1;
361acd884deSSumit Saxena 
362acd884deSSumit Saxena 	return 0;
363acd884deSSumit Saxena }
364acd884deSSumit Saxena 
bnxt_qplib_add_sgid(struct bnxt_qplib_sgid_tbl * sgid_tbl,const union ib_gid * gid,const u8 * smac,u16 vlan_id,bool update,u32 * index)365acd884deSSumit Saxena int bnxt_qplib_add_sgid(struct bnxt_qplib_sgid_tbl *sgid_tbl,
366acd884deSSumit Saxena 			const union ib_gid *gid, const u8 *smac, u16 vlan_id,
367acd884deSSumit Saxena 			bool update, u32 *index)
368acd884deSSumit Saxena {
369acd884deSSumit Saxena 	struct bnxt_qplib_res *res = to_bnxt_qplib(sgid_tbl,
370acd884deSSumit Saxena 						   struct bnxt_qplib_res,
371acd884deSSumit Saxena 						   sgid_tbl);
372acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
373acd884deSSumit Saxena 	int i, free_idx;
374acd884deSSumit Saxena 
375acd884deSSumit Saxena 	if (sgid_tbl == NULL) {
376acd884deSSumit Saxena 		dev_err(&res->pdev->dev, "QPLIB: SGID table not allocated\n");
377acd884deSSumit Saxena 		return -EINVAL;
378acd884deSSumit Saxena 	}
379acd884deSSumit Saxena 	/* Do we need a sgid_lock here? */
380acd884deSSumit Saxena 	if (sgid_tbl->active == sgid_tbl->max) {
381acd884deSSumit Saxena 		dev_err(&res->pdev->dev, "QPLIB: SGID table is full\n");
382acd884deSSumit Saxena 		return -ENOMEM;
383acd884deSSumit Saxena 	}
384acd884deSSumit Saxena 	free_idx = sgid_tbl->max;
385acd884deSSumit Saxena 	for (i = 0; i < sgid_tbl->max; i++) {
386acd884deSSumit Saxena 		if (!memcmp(&sgid_tbl->tbl[i], gid, sizeof(*gid)) &&
387acd884deSSumit Saxena 		    sgid_tbl->tbl[i].vlan_id == vlan_id) {
388acd884deSSumit Saxena 			dev_dbg(&res->pdev->dev,
389acd884deSSumit Saxena 				"QPLIB: SGID entry already exist in entry %d!\n",
390acd884deSSumit Saxena 				i);
391acd884deSSumit Saxena 			*index = i;
392acd884deSSumit Saxena 			return -EALREADY;
393acd884deSSumit Saxena 		} else if (!memcmp(&sgid_tbl->tbl[i], &bnxt_qplib_gid_zero,
394acd884deSSumit Saxena 				   sizeof(bnxt_qplib_gid_zero)) &&
395acd884deSSumit Saxena 			   free_idx == sgid_tbl->max) {
396acd884deSSumit Saxena 			free_idx = i;
397acd884deSSumit Saxena 		}
398acd884deSSumit Saxena 	}
399acd884deSSumit Saxena 	if (free_idx == sgid_tbl->max) {
400acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
401acd884deSSumit Saxena 			"QPLIB: SGID table is FULL but count is not MAX??\n");
402acd884deSSumit Saxena 		return -ENOMEM;
403acd884deSSumit Saxena 	}
404acd884deSSumit Saxena 	if (update) {
405acd884deSSumit Saxena 		struct creq_add_gid_resp resp = {};
406acd884deSSumit Saxena 		struct bnxt_qplib_cmdqmsg msg = {};
407acd884deSSumit Saxena 		struct cmdq_add_gid req = {};
408acd884deSSumit Saxena 		int rc;
409acd884deSSumit Saxena 
410acd884deSSumit Saxena 		bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_ADD_GID,
411acd884deSSumit Saxena 					 sizeof(req));
412acd884deSSumit Saxena 
413acd884deSSumit Saxena 		req.gid[0] = cpu_to_be32(((u32 *)gid->raw)[3]);
414acd884deSSumit Saxena 		req.gid[1] = cpu_to_be32(((u32 *)gid->raw)[2]);
415acd884deSSumit Saxena 		req.gid[2] = cpu_to_be32(((u32 *)gid->raw)[1]);
416acd884deSSumit Saxena 		req.gid[3] = cpu_to_be32(((u32 *)gid->raw)[0]);
417acd884deSSumit Saxena 		/* driver should ensure that all RoCE traffic is always VLAN tagged
418acd884deSSumit Saxena 		 * if RoCE traffic is running on non-zero VLAN ID or
419acd884deSSumit Saxena 		 * RoCE traffic is running on non-zero Priority.
420acd884deSSumit Saxena 		 */
421acd884deSSumit Saxena 		if ((vlan_id != 0xFFFF) || res->prio) {
422acd884deSSumit Saxena 			if (vlan_id != 0xFFFF)
423acd884deSSumit Saxena 				req.vlan = cpu_to_le16(vlan_id &
424acd884deSSumit Saxena 						CMDQ_ADD_GID_VLAN_VLAN_ID_MASK);
425acd884deSSumit Saxena 			req.vlan |=
426acd884deSSumit Saxena 				cpu_to_le16(CMDQ_ADD_GID_VLAN_TPID_TPID_8100 |
427acd884deSSumit Saxena 					    CMDQ_ADD_GID_VLAN_VLAN_EN);
428acd884deSSumit Saxena 		}
429acd884deSSumit Saxena 
430acd884deSSumit Saxena 		/* MAC in network format */
431acd884deSSumit Saxena 		req.src_mac[0] = cpu_to_be16(((u16 *)smac)[0]);
432acd884deSSumit Saxena 		req.src_mac[1] = cpu_to_be16(((u16 *)smac)[1]);
433acd884deSSumit Saxena 		req.src_mac[2] = cpu_to_be16(((u16 *)smac)[2]);
434acd884deSSumit Saxena 
435acd884deSSumit Saxena 		bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
436acd884deSSumit Saxena 					sizeof(resp), 0);
437acd884deSSumit Saxena 		rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
438acd884deSSumit Saxena 		if (rc)
439acd884deSSumit Saxena 			return rc;
440acd884deSSumit Saxena 		sgid_tbl->hw_id[free_idx] = le32_to_cpu(resp.xid);
441acd884deSSumit Saxena 	}
442acd884deSSumit Saxena 
443acd884deSSumit Saxena 	if (vlan_id != 0xFFFF)
444acd884deSSumit Saxena 		sgid_tbl->vlan[free_idx] = true;
445acd884deSSumit Saxena 
446acd884deSSumit Saxena 	memcpy(&sgid_tbl->tbl[free_idx], gid, sizeof(*gid));
447acd884deSSumit Saxena 	sgid_tbl->tbl[free_idx].vlan_id = vlan_id;
448acd884deSSumit Saxena 	sgid_tbl->active++;
449acd884deSSumit Saxena 	dev_dbg(&res->pdev->dev,
450acd884deSSumit Saxena 		 "QPLIB: SGID added hw_id[0x%x] = 0x%x active = 0x%x\n",
451acd884deSSumit Saxena 		 free_idx, sgid_tbl->hw_id[free_idx], sgid_tbl->active);
452acd884deSSumit Saxena 
453acd884deSSumit Saxena 	*index = free_idx;
454acd884deSSumit Saxena 	/* unlock */
455acd884deSSumit Saxena 	return 0;
456acd884deSSumit Saxena }
457acd884deSSumit Saxena 
458acd884deSSumit Saxena /* AH */
bnxt_qplib_create_ah(struct bnxt_qplib_res * res,struct bnxt_qplib_ah * ah,bool block)459acd884deSSumit Saxena int bnxt_qplib_create_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah,
460acd884deSSumit Saxena 			 bool block)
461acd884deSSumit Saxena {
462acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
463acd884deSSumit Saxena 	struct creq_create_ah_resp resp = {};
464acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
465acd884deSSumit Saxena 	struct cmdq_create_ah req = {};
466acd884deSSumit Saxena 	u32 temp32[4];
467acd884deSSumit Saxena 	u16 temp16[3];
468acd884deSSumit Saxena 	int rc;
469acd884deSSumit Saxena 
470acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_CREATE_AH,
471acd884deSSumit Saxena 				 sizeof(req));
472acd884deSSumit Saxena 
473acd884deSSumit Saxena 	memcpy(temp32, ah->dgid.data, sizeof(struct bnxt_qplib_gid));
474acd884deSSumit Saxena 	req.dgid[0] = cpu_to_le32(temp32[0]);
475acd884deSSumit Saxena 	req.dgid[1] = cpu_to_le32(temp32[1]);
476acd884deSSumit Saxena 	req.dgid[2] = cpu_to_le32(temp32[2]);
477acd884deSSumit Saxena 	req.dgid[3] = cpu_to_le32(temp32[3]);
478acd884deSSumit Saxena 
479acd884deSSumit Saxena 	req.type = ah->nw_type;
480acd884deSSumit Saxena 	req.hop_limit = ah->hop_limit;
481acd884deSSumit Saxena 	req.sgid_index = cpu_to_le16(res->sgid_tbl.hw_id[ah->sgid_index]);
482acd884deSSumit Saxena 	req.dest_vlan_id_flow_label = cpu_to_le32((ah->flow_label &
483acd884deSSumit Saxena 					CMDQ_CREATE_AH_FLOW_LABEL_MASK) |
484acd884deSSumit Saxena 					CMDQ_CREATE_AH_DEST_VLAN_ID_MASK);
485acd884deSSumit Saxena 	req.pd_id = cpu_to_le32(ah->pd->id);
486acd884deSSumit Saxena 	req.traffic_class = ah->traffic_class;
487acd884deSSumit Saxena 
488acd884deSSumit Saxena 	/* MAC in network format */
489acd884deSSumit Saxena 	memcpy(temp16, ah->dmac, ETH_ALEN);
490acd884deSSumit Saxena 	req.dest_mac[0] = cpu_to_le16(temp16[0]);
491acd884deSSumit Saxena 	req.dest_mac[1] = cpu_to_le16(temp16[1]);
492acd884deSSumit Saxena 	req.dest_mac[2] = cpu_to_le16(temp16[2]);
493acd884deSSumit Saxena 
494acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
495acd884deSSumit Saxena 				sizeof(resp), block);
496acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
497acd884deSSumit Saxena 	if (rc)
498acd884deSSumit Saxena 		return rc;
499acd884deSSumit Saxena 
500acd884deSSumit Saxena 	ah->id = le32_to_cpu(resp.xid);
501acd884deSSumit Saxena 	/* for Cu/Wh AHID 0 is not valid */
502acd884deSSumit Saxena 	if (!_is_chip_gen_p5_p7(res->cctx) && !ah->id)
503acd884deSSumit Saxena 		rc = -EINVAL;
504acd884deSSumit Saxena 
505acd884deSSumit Saxena 	return rc;
506acd884deSSumit Saxena }
507acd884deSSumit Saxena 
bnxt_qplib_destroy_ah(struct bnxt_qplib_res * res,struct bnxt_qplib_ah * ah,bool block)508acd884deSSumit Saxena int bnxt_qplib_destroy_ah(struct bnxt_qplib_res *res, struct bnxt_qplib_ah *ah,
509acd884deSSumit Saxena 			  bool block)
510acd884deSSumit Saxena {
511acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
512acd884deSSumit Saxena 	struct creq_destroy_ah_resp resp = {};
513acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
514acd884deSSumit Saxena 	struct cmdq_destroy_ah req = {};
515acd884deSSumit Saxena 	int rc;
516acd884deSSumit Saxena 
517acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_DESTROY_AH,
518acd884deSSumit Saxena 				 sizeof(req));
519acd884deSSumit Saxena 
520acd884deSSumit Saxena 	req.ah_cid = cpu_to_le32(ah->id);
521acd884deSSumit Saxena 
522acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
523acd884deSSumit Saxena 				sizeof(resp), block);
524acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
525acd884deSSumit Saxena 	return rc;
526acd884deSSumit Saxena }
527acd884deSSumit Saxena 
528acd884deSSumit Saxena /* MRW */
bnxt_qplib_free_mrw(struct bnxt_qplib_res * res,struct bnxt_qplib_mrw * mrw)529acd884deSSumit Saxena int bnxt_qplib_free_mrw(struct bnxt_qplib_res *res, struct bnxt_qplib_mrw *mrw)
530acd884deSSumit Saxena {
531acd884deSSumit Saxena 	struct creq_deallocate_key_resp resp = {};
532acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
533acd884deSSumit Saxena 	struct cmdq_deallocate_key req = {};
534acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
535acd884deSSumit Saxena 	int rc;
536acd884deSSumit Saxena 
537acd884deSSumit Saxena 	if (mrw->lkey == 0xFFFFFFFF) {
538acd884deSSumit Saxena 		dev_info(&res->pdev->dev,
539acd884deSSumit Saxena 			 "QPLIB: SP: Free a reserved lkey MRW\n");
540acd884deSSumit Saxena 		return 0;
541acd884deSSumit Saxena 	}
542acd884deSSumit Saxena 
543acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_DEALLOCATE_KEY,
544acd884deSSumit Saxena 				 sizeof(req));
545acd884deSSumit Saxena 
546acd884deSSumit Saxena 	req.mrw_flags = mrw->type;
547acd884deSSumit Saxena 
548acd884deSSumit Saxena 	if ((mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE1)  ||
549acd884deSSumit Saxena 	    (mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2A) ||
550acd884deSSumit Saxena 	    (mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2B))
551acd884deSSumit Saxena 		req.key = cpu_to_le32(mrw->rkey);
552acd884deSSumit Saxena 	else
553acd884deSSumit Saxena 		req.key = cpu_to_le32(mrw->lkey);
554acd884deSSumit Saxena 
555acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
556acd884deSSumit Saxena 				sizeof(resp), 0);
557acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
558acd884deSSumit Saxena 	if (rc)
559acd884deSSumit Saxena 		return rc;
560acd884deSSumit Saxena 
561acd884deSSumit Saxena 	if (mrw->hwq.max_elements)
562acd884deSSumit Saxena 		bnxt_qplib_free_hwq(res, &mrw->hwq);
563acd884deSSumit Saxena 
564acd884deSSumit Saxena 	return 0;
565acd884deSSumit Saxena }
566acd884deSSumit Saxena 
bnxt_qplib_alloc_mrw(struct bnxt_qplib_res * res,struct bnxt_qplib_mrw * mrw)567acd884deSSumit Saxena int bnxt_qplib_alloc_mrw(struct bnxt_qplib_res *res, struct bnxt_qplib_mrw *mrw)
568acd884deSSumit Saxena {
569acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
570acd884deSSumit Saxena 	struct creq_allocate_mrw_resp resp = {};
571acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
572acd884deSSumit Saxena 	struct cmdq_allocate_mrw req = {};
573acd884deSSumit Saxena 	int rc;
574acd884deSSumit Saxena 
575acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_ALLOCATE_MRW,
576acd884deSSumit Saxena 				 sizeof(req));
577acd884deSSumit Saxena 
578acd884deSSumit Saxena 	req.pd_id = cpu_to_le32(mrw->pd->id);
579acd884deSSumit Saxena 	req.mrw_flags = mrw->type;
580acd884deSSumit Saxena 	if ((mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_PMR &&
581acd884deSSumit Saxena 	     mrw->flags & BNXT_QPLIB_FR_PMR) ||
582acd884deSSumit Saxena 	    mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2A ||
583acd884deSSumit Saxena 	    mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2B)
584acd884deSSumit Saxena 		req.access = CMDQ_ALLOCATE_MRW_ACCESS_CONSUMER_OWNED_KEY;
585*bbe42332SMark Johnston 	req.mrw_handle = cpu_to_le64((uintptr_t)mrw);
586acd884deSSumit Saxena 
587acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
588acd884deSSumit Saxena 				sizeof(resp), 0);
589acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
590acd884deSSumit Saxena 	if (rc)
591acd884deSSumit Saxena 		return rc;
592acd884deSSumit Saxena 	if ((mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE1)  ||
593acd884deSSumit Saxena 	    (mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2A) ||
594acd884deSSumit Saxena 	    (mrw->type == CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2B))
595acd884deSSumit Saxena 		mrw->rkey = le32_to_cpu(resp.xid);
596acd884deSSumit Saxena 	else
597acd884deSSumit Saxena 		mrw->lkey = le32_to_cpu(resp.xid);
598acd884deSSumit Saxena 
599acd884deSSumit Saxena 	return 0;
600acd884deSSumit Saxena }
601acd884deSSumit Saxena 
bnxt_qplib_dereg_mrw(struct bnxt_qplib_res * res,struct bnxt_qplib_mrw * mrw,bool block)602acd884deSSumit Saxena int bnxt_qplib_dereg_mrw(struct bnxt_qplib_res *res, struct bnxt_qplib_mrw *mrw,
603acd884deSSumit Saxena 			 bool block)
604acd884deSSumit Saxena {
605acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
606acd884deSSumit Saxena 	struct creq_deregister_mr_resp resp = {};
607acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
608acd884deSSumit Saxena 	struct cmdq_deregister_mr req = {};
609acd884deSSumit Saxena 	int rc;
610acd884deSSumit Saxena 
611acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_DEREGISTER_MR,
612acd884deSSumit Saxena 				 sizeof(req));
613acd884deSSumit Saxena 
614acd884deSSumit Saxena 	req.lkey = cpu_to_le32(mrw->lkey);
615acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
616acd884deSSumit Saxena 				sizeof(resp), block);
617acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
618acd884deSSumit Saxena 	if (rc)
619acd884deSSumit Saxena 		return rc;
620acd884deSSumit Saxena 
621acd884deSSumit Saxena 	if (mrw->hwq.max_elements) {
622acd884deSSumit Saxena 		mrw->va = 0;
623acd884deSSumit Saxena 		mrw->total_size = 0;
624acd884deSSumit Saxena 		bnxt_qplib_free_hwq(res, &mrw->hwq);
625acd884deSSumit Saxena 	}
626acd884deSSumit Saxena 
627acd884deSSumit Saxena 	return 0;
628acd884deSSumit Saxena }
629acd884deSSumit Saxena 
bnxt_qplib_reg_mr(struct bnxt_qplib_res * res,struct bnxt_qplib_mrinfo * mrinfo,bool block)630acd884deSSumit Saxena int bnxt_qplib_reg_mr(struct bnxt_qplib_res *res,
631acd884deSSumit Saxena 		      struct bnxt_qplib_mrinfo *mrinfo,
632acd884deSSumit Saxena 		      bool block)
633acd884deSSumit Saxena {
634acd884deSSumit Saxena 	struct bnxt_qplib_hwq_attr hwq_attr = {};
635acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
636acd884deSSumit Saxena 	struct creq_register_mr_resp resp = {};
637acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
638acd884deSSumit Saxena 	struct cmdq_register_mr req = {};
639acd884deSSumit Saxena 	struct bnxt_qplib_mrw *mr;
640acd884deSSumit Saxena 	u32 buf_pg_size;
641acd884deSSumit Saxena 	u32 pg_size;
642acd884deSSumit Saxena 	u16 level;
643acd884deSSumit Saxena 	u16 flags;
644acd884deSSumit Saxena 	int rc;
645acd884deSSumit Saxena 
646acd884deSSumit Saxena 	mr = mrinfo->mrw;
647acd884deSSumit Saxena 	buf_pg_size = 0x01ULL << mrinfo->sg.pgshft;
648acd884deSSumit Saxena 	if (mrinfo->sg.npages) {
649acd884deSSumit Saxena 		/* Free the hwq if it already exist, must be a rereg */
650acd884deSSumit Saxena 		if (mr->hwq.max_elements)
651acd884deSSumit Saxena 			bnxt_qplib_free_hwq(res, &mr->hwq);
652acd884deSSumit Saxena 		/* Use system PAGE_SIZE */
653acd884deSSumit Saxena 		hwq_attr.res = res;
654acd884deSSumit Saxena 		hwq_attr.depth = mrinfo->sg.npages;
655acd884deSSumit Saxena 		hwq_attr.stride = PAGE_SIZE;
656acd884deSSumit Saxena 		hwq_attr.type = HWQ_TYPE_MR;
657acd884deSSumit Saxena 		hwq_attr.sginfo = &mrinfo->sg;
658acd884deSSumit Saxena 		rc = bnxt_qplib_alloc_init_hwq(&mr->hwq, &hwq_attr);
659acd884deSSumit Saxena 		if (rc) {
660acd884deSSumit Saxena 			dev_err(&res->pdev->dev,
661acd884deSSumit Saxena 				"SP: Reg MR memory allocation failed\n");
662acd884deSSumit Saxena 			return -ENOMEM;
663acd884deSSumit Saxena 		}
664acd884deSSumit Saxena 	}
665acd884deSSumit Saxena 
666acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_REGISTER_MR,
667acd884deSSumit Saxena 				 sizeof(req));
668acd884deSSumit Saxena 	/* Configure the request */
669acd884deSSumit Saxena 	if (mrinfo->is_dma) {
670acd884deSSumit Saxena 		/* No PBL provided, just use system PAGE_SIZE */
671acd884deSSumit Saxena 		level = 0;
672acd884deSSumit Saxena 		req.pbl = 0;
673acd884deSSumit Saxena 		pg_size = PAGE_SIZE;
674acd884deSSumit Saxena 	} else {
675acd884deSSumit Saxena 		level = mr->hwq.level;
676acd884deSSumit Saxena 		req.pbl = cpu_to_le64(mr->hwq.pbl[PBL_LVL_0].pg_map_arr[0]);
677acd884deSSumit Saxena 	}
678acd884deSSumit Saxena 
679acd884deSSumit Saxena 	pg_size = buf_pg_size ? buf_pg_size : PAGE_SIZE;
680acd884deSSumit Saxena 	req.log2_pg_size_lvl = (level << CMDQ_REGISTER_MR_LVL_SFT) |
681acd884deSSumit Saxena 			       ((ilog2(pg_size) <<
682acd884deSSumit Saxena 				 CMDQ_REGISTER_MR_LOG2_PG_SIZE_SFT) &
683acd884deSSumit Saxena 				CMDQ_REGISTER_MR_LOG2_PG_SIZE_MASK);
684acd884deSSumit Saxena 	req.log2_pbl_pg_size = cpu_to_le16(((ilog2(PAGE_SIZE) <<
685acd884deSSumit Saxena 				 CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_SFT) &
686acd884deSSumit Saxena 				CMDQ_REGISTER_MR_LOG2_PBL_PG_SIZE_MASK));
687acd884deSSumit Saxena 	req.access = (mr->flags & 0xFFFF);
688acd884deSSumit Saxena 	req.va = cpu_to_le64(mr->va);
689acd884deSSumit Saxena 	req.key = cpu_to_le32(mr->lkey);
690acd884deSSumit Saxena 	if (_is_alloc_mr_unified(res->dattr)) {
691acd884deSSumit Saxena 		flags = 0;
692acd884deSSumit Saxena 		req.key = cpu_to_le32(mr->pd->id);
693acd884deSSumit Saxena 		flags |= CMDQ_REGISTER_MR_FLAGS_ALLOC_MR;
694acd884deSSumit Saxena 		req.flags = cpu_to_le16(flags);
695acd884deSSumit Saxena 	}
696acd884deSSumit Saxena 	req.mr_size = cpu_to_le64(mr->total_size);
697acd884deSSumit Saxena 
698acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
699acd884deSSumit Saxena 				sizeof(resp), block);
700acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
701acd884deSSumit Saxena 	if (rc)
702acd884deSSumit Saxena 		goto fail;
703acd884deSSumit Saxena 
704acd884deSSumit Saxena 	if (_is_alloc_mr_unified(res->dattr)) {
705acd884deSSumit Saxena 		mr->lkey = le32_to_cpu(resp.xid);
706acd884deSSumit Saxena 		mr->rkey = mr->lkey;
707acd884deSSumit Saxena 	}
708acd884deSSumit Saxena 
709acd884deSSumit Saxena 	return 0;
710acd884deSSumit Saxena fail:
711acd884deSSumit Saxena 	if (mr->hwq.max_elements)
712acd884deSSumit Saxena 		bnxt_qplib_free_hwq(res, &mr->hwq);
713acd884deSSumit Saxena 	return rc;
714acd884deSSumit Saxena }
715acd884deSSumit Saxena 
bnxt_qplib_alloc_fast_reg_page_list(struct bnxt_qplib_res * res,struct bnxt_qplib_frpl * frpl,int max_pg_ptrs)716acd884deSSumit Saxena int bnxt_qplib_alloc_fast_reg_page_list(struct bnxt_qplib_res *res,
717acd884deSSumit Saxena 					struct bnxt_qplib_frpl *frpl,
718acd884deSSumit Saxena 					int max_pg_ptrs)
719acd884deSSumit Saxena {
720acd884deSSumit Saxena 	struct bnxt_qplib_hwq_attr hwq_attr = {};
721acd884deSSumit Saxena 	struct bnxt_qplib_sg_info sginfo = {};
722acd884deSSumit Saxena 	int pg_ptrs, rc;
723acd884deSSumit Saxena 
724acd884deSSumit Saxena 	/* Re-calculate the max to fit the HWQ allocation model */
725acd884deSSumit Saxena 	pg_ptrs = roundup_pow_of_two(max_pg_ptrs);
726acd884deSSumit Saxena 
727acd884deSSumit Saxena 	sginfo.pgsize = PAGE_SIZE;
728acd884deSSumit Saxena 	sginfo.nopte = true;
729acd884deSSumit Saxena 
730acd884deSSumit Saxena 	hwq_attr.res = res;
731acd884deSSumit Saxena 	hwq_attr.depth = pg_ptrs;
732acd884deSSumit Saxena 	hwq_attr.stride = PAGE_SIZE;
733acd884deSSumit Saxena 	hwq_attr.sginfo = &sginfo;
734acd884deSSumit Saxena 	hwq_attr.type = HWQ_TYPE_CTX;
735acd884deSSumit Saxena 	rc = bnxt_qplib_alloc_init_hwq(&frpl->hwq, &hwq_attr);
736acd884deSSumit Saxena 	if (!rc)
737acd884deSSumit Saxena 		frpl->max_pg_ptrs = pg_ptrs;
738acd884deSSumit Saxena 
739acd884deSSumit Saxena 	return rc;
740acd884deSSumit Saxena }
741acd884deSSumit Saxena 
bnxt_qplib_free_fast_reg_page_list(struct bnxt_qplib_res * res,struct bnxt_qplib_frpl * frpl)742acd884deSSumit Saxena void bnxt_qplib_free_fast_reg_page_list(struct bnxt_qplib_res *res,
743acd884deSSumit Saxena 					struct bnxt_qplib_frpl *frpl)
744acd884deSSumit Saxena {
745acd884deSSumit Saxena 	bnxt_qplib_free_hwq(res, &frpl->hwq);
746acd884deSSumit Saxena }
747acd884deSSumit Saxena 
bnxt_qplib_map_tc2cos(struct bnxt_qplib_res * res,u16 * cids)748acd884deSSumit Saxena int bnxt_qplib_map_tc2cos(struct bnxt_qplib_res *res, u16 *cids)
749acd884deSSumit Saxena {
750acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
751acd884deSSumit Saxena 	struct creq_map_tc_to_cos_resp resp = {};
752acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
753acd884deSSumit Saxena 	struct cmdq_map_tc_to_cos req = {};
754acd884deSSumit Saxena 	int rc;
755acd884deSSumit Saxena 
756acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_MAP_TC_TO_COS,
757acd884deSSumit Saxena 				 sizeof(req));
758acd884deSSumit Saxena 	req.cos0 = cpu_to_le16(cids[0]);
759acd884deSSumit Saxena 	req.cos1 = cpu_to_le16(cids[1]);
760acd884deSSumit Saxena 
761acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
762acd884deSSumit Saxena 				sizeof(resp), 0);
763acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
764acd884deSSumit Saxena 	return rc;
765acd884deSSumit Saxena }
766acd884deSSumit Saxena 
bnxt_qplib_fill_cc_gen1(struct cmdq_modify_roce_cc_gen1_tlv * ext_req,struct bnxt_qplib_cc_param_ext * cc_ext)767acd884deSSumit Saxena static void bnxt_qplib_fill_cc_gen1(struct cmdq_modify_roce_cc_gen1_tlv *ext_req,
768acd884deSSumit Saxena 			     struct bnxt_qplib_cc_param_ext *cc_ext)
769acd884deSSumit Saxena {
770acd884deSSumit Saxena 	ext_req->modify_mask = cpu_to_le64(cc_ext->ext_mask);
771acd884deSSumit Saxena 	cc_ext->ext_mask = 0;
772acd884deSSumit Saxena 	ext_req->inactivity_th_hi = cpu_to_le16(cc_ext->inact_th_hi);
773acd884deSSumit Saxena 	ext_req->min_time_between_cnps = cpu_to_le16(cc_ext->min_delta_cnp);
774acd884deSSumit Saxena 	ext_req->init_cp = cpu_to_le16(cc_ext->init_cp);
775acd884deSSumit Saxena 	ext_req->tr_update_mode = cc_ext->tr_update_mode;
776acd884deSSumit Saxena 	ext_req->tr_update_cycles = cc_ext->tr_update_cyls;
777acd884deSSumit Saxena 	ext_req->fr_num_rtts = cc_ext->fr_rtt;
778acd884deSSumit Saxena 	ext_req->ai_rate_increase = cc_ext->ai_rate_incr;
779acd884deSSumit Saxena 	ext_req->reduction_relax_rtts_th = cpu_to_le16(cc_ext->rr_rtt_th);
780acd884deSSumit Saxena 	ext_req->additional_relax_cr_th = cpu_to_le16(cc_ext->ar_cr_th);
781acd884deSSumit Saxena 	ext_req->cr_min_th = cpu_to_le16(cc_ext->cr_min_th);
782acd884deSSumit Saxena 	ext_req->bw_avg_weight = cc_ext->bw_avg_weight;
783acd884deSSumit Saxena 	ext_req->actual_cr_factor = cc_ext->cr_factor;
784acd884deSSumit Saxena 	ext_req->max_cp_cr_th = cpu_to_le16(cc_ext->cr_th_max_cp);
785acd884deSSumit Saxena 	ext_req->cp_bias_en = cc_ext->cp_bias_en;
786acd884deSSumit Saxena 	ext_req->cp_bias = cc_ext->cp_bias;
787acd884deSSumit Saxena 	ext_req->cnp_ecn = cc_ext->cnp_ecn;
788acd884deSSumit Saxena 	ext_req->rtt_jitter_en = cc_ext->rtt_jitter_en;
789acd884deSSumit Saxena 	ext_req->link_bytes_per_usec = cpu_to_le16(cc_ext->bytes_per_usec);
790acd884deSSumit Saxena 	ext_req->reset_cc_cr_th = cpu_to_le16(cc_ext->cc_cr_reset_th);
791acd884deSSumit Saxena 	ext_req->cr_width = cc_ext->cr_width;
792acd884deSSumit Saxena 	ext_req->quota_period_min = cc_ext->min_quota;
793acd884deSSumit Saxena 	ext_req->quota_period_max = cc_ext->max_quota;
794acd884deSSumit Saxena 	ext_req->quota_period_abs_max = cc_ext->abs_max_quota;
795acd884deSSumit Saxena 	ext_req->tr_lower_bound = cpu_to_le16(cc_ext->tr_lb);
796acd884deSSumit Saxena 	ext_req->cr_prob_factor = cc_ext->cr_prob_fac;
797acd884deSSumit Saxena 	ext_req->tr_prob_factor = cc_ext->tr_prob_fac;
798acd884deSSumit Saxena 	ext_req->fairness_cr_th = cpu_to_le16(cc_ext->fair_cr_th);
799acd884deSSumit Saxena 	ext_req->red_div = cc_ext->red_div;
800acd884deSSumit Saxena 	ext_req->cnp_ratio_th = cc_ext->cnp_ratio_th;
801acd884deSSumit Saxena 	ext_req->exp_ai_rtts = cpu_to_le16(cc_ext->ai_ext_rtt);
802acd884deSSumit Saxena 	ext_req->exp_ai_cr_cp_ratio = cc_ext->exp_crcp_ratio;
803acd884deSSumit Saxena 	ext_req->use_rate_table = cc_ext->low_rate_en;
804acd884deSSumit Saxena 	ext_req->cp_exp_update_th = cpu_to_le16(cc_ext->cpcr_update_th);
805acd884deSSumit Saxena 	ext_req->high_exp_ai_rtts_th1 = cpu_to_le16(cc_ext->ai_rtt_th1);
806acd884deSSumit Saxena 	ext_req->high_exp_ai_rtts_th2 = cpu_to_le16(cc_ext->ai_rtt_th2);
807acd884deSSumit Saxena 	ext_req->actual_cr_cong_free_rtts_th = cpu_to_le16(cc_ext->cf_rtt_th);
808acd884deSSumit Saxena 	ext_req->severe_cong_cr_th1 = cpu_to_le16(cc_ext->sc_cr_th1);
809acd884deSSumit Saxena 	ext_req->severe_cong_cr_th2 = cpu_to_le16(cc_ext->sc_cr_th2);
810acd884deSSumit Saxena 	ext_req->link64B_per_rtt = cpu_to_le32(cc_ext->l64B_per_rtt);
811acd884deSSumit Saxena 	ext_req->cc_ack_bytes = cc_ext->cc_ack_bytes;
812acd884deSSumit Saxena 	ext_req->reduce_init_cong_free_rtts_th = cpu_to_le16(cc_ext->reduce_cf_rtt_th);
813acd884deSSumit Saxena }
814acd884deSSumit Saxena 
bnxt_qplib_modify_cc(struct bnxt_qplib_res * res,struct bnxt_qplib_cc_param * cc_param)815acd884deSSumit Saxena int bnxt_qplib_modify_cc(struct bnxt_qplib_res *res,
816acd884deSSumit Saxena 			 struct bnxt_qplib_cc_param *cc_param)
817acd884deSSumit Saxena {
818acd884deSSumit Saxena 	struct bnxt_qplib_tlv_modify_cc_req tlv_req = {};
819acd884deSSumit Saxena 	struct creq_modify_roce_cc_resp resp = {};
820acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
821acd884deSSumit Saxena 	struct cmdq_modify_roce_cc *req;
822acd884deSSumit Saxena 	int req_size;
823acd884deSSumit Saxena 	void *cmd;
824acd884deSSumit Saxena 	int rc;
825acd884deSSumit Saxena 
826acd884deSSumit Saxena 	/* Prepare the older base command */
827acd884deSSumit Saxena 	req = &tlv_req.base_req;
828acd884deSSumit Saxena 	cmd = req;
829acd884deSSumit Saxena 	req_size = sizeof(*req);
830acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(req, CMDQ_BASE_OPCODE_MODIFY_ROCE_CC,
831acd884deSSumit Saxena 				 sizeof(*req));
832acd884deSSumit Saxena 	req->modify_mask = cpu_to_le32(cc_param->mask);
833acd884deSSumit Saxena 	req->enable_cc = cc_param->enable;
834acd884deSSumit Saxena 	req->g = cc_param->g;
835acd884deSSumit Saxena 	req->num_phases_per_state = cc_param->nph_per_state;
836acd884deSSumit Saxena 	req->time_per_phase = cc_param->time_pph;
837acd884deSSumit Saxena 	req->pkts_per_phase = cc_param->pkts_pph;
838acd884deSSumit Saxena 	req->init_cr = cpu_to_le16(cc_param->init_cr);
839acd884deSSumit Saxena 	req->init_tr = cpu_to_le16(cc_param->init_tr);
840acd884deSSumit Saxena 	req->tos_dscp_tos_ecn = (cc_param->tos_dscp <<
841acd884deSSumit Saxena 				 CMDQ_MODIFY_ROCE_CC_TOS_DSCP_SFT) |
842acd884deSSumit Saxena 				 (cc_param->tos_ecn &
843acd884deSSumit Saxena 				 CMDQ_MODIFY_ROCE_CC_TOS_ECN_MASK);
844acd884deSSumit Saxena 	req->alt_vlan_pcp = cc_param->alt_vlan_pcp;
845acd884deSSumit Saxena 	req->alt_tos_dscp = cpu_to_le16(cc_param->alt_tos_dscp);
846acd884deSSumit Saxena 	req->rtt = cpu_to_le16(cc_param->rtt);
847acd884deSSumit Saxena 	req->tcp_cp = cpu_to_le16(cc_param->tcp_cp);
848acd884deSSumit Saxena 	req->cc_mode = cc_param->cc_mode;
849acd884deSSumit Saxena 	req->inactivity_th = cpu_to_le16(cc_param->inact_th);
850acd884deSSumit Saxena 
851acd884deSSumit Saxena 	/* For chip gen P5 onwards fill extended cmd and header */
852acd884deSSumit Saxena 	if (_is_chip_gen_p5_p7(res->cctx)) {
853acd884deSSumit Saxena 		struct roce_tlv *hdr;
854acd884deSSumit Saxena 		u32 payload;
855acd884deSSumit Saxena 		u32 chunks;
856acd884deSSumit Saxena 
857acd884deSSumit Saxena 		cmd = &tlv_req;
858acd884deSSumit Saxena 		req_size = sizeof(tlv_req);
859acd884deSSumit Saxena 		/* Prepare primary tlv header */
860acd884deSSumit Saxena 		hdr = &tlv_req.tlv_hdr;
861acd884deSSumit Saxena 		chunks = CHUNKS(sizeof(struct bnxt_qplib_tlv_modify_cc_req));
862acd884deSSumit Saxena 		payload = sizeof(struct cmdq_modify_roce_cc);
863acd884deSSumit Saxena 		ROCE_1ST_TLV_PREP(hdr, chunks, payload, true);
864acd884deSSumit Saxena 		/* Prepare secondary tlv header */
865acd884deSSumit Saxena 		hdr = (struct roce_tlv *)&tlv_req.ext_req;
866acd884deSSumit Saxena 		payload = sizeof(struct cmdq_modify_roce_cc_gen1_tlv) -
867acd884deSSumit Saxena 			  sizeof(struct roce_tlv);
868acd884deSSumit Saxena 		ROCE_EXT_TLV_PREP(hdr, TLV_TYPE_MODIFY_ROCE_CC_GEN1, payload,
869acd884deSSumit Saxena 				  false, true);
870acd884deSSumit Saxena 		bnxt_qplib_fill_cc_gen1(&tlv_req.ext_req, &cc_param->cc_ext);
871acd884deSSumit Saxena 	}
872acd884deSSumit Saxena 
873acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, cmd, &resp, NULL, req_size,
874acd884deSSumit Saxena 				sizeof(resp), 0);
875acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(res->rcfw, &msg);
876acd884deSSumit Saxena 	return rc;
877acd884deSSumit Saxena }
878acd884deSSumit Saxena 
bnxt_qplib_read_cc_gen1(struct bnxt_qplib_cc_param_ext * cc_ext,struct creq_query_roce_cc_gen1_resp_sb_tlv * sb)879acd884deSSumit Saxena static void bnxt_qplib_read_cc_gen1(struct bnxt_qplib_cc_param_ext *cc_ext,
880acd884deSSumit Saxena 			     struct creq_query_roce_cc_gen1_resp_sb_tlv *sb)
881acd884deSSumit Saxena {
882acd884deSSumit Saxena 	cc_ext->inact_th_hi = le16_to_cpu(sb->inactivity_th_hi);
883acd884deSSumit Saxena 	cc_ext->min_delta_cnp = le16_to_cpu(sb->min_time_between_cnps);
884acd884deSSumit Saxena 	cc_ext->init_cp = le16_to_cpu(sb->init_cp);
885acd884deSSumit Saxena 	cc_ext->tr_update_mode = sb->tr_update_mode;
886acd884deSSumit Saxena 	cc_ext->tr_update_cyls = sb->tr_update_cycles;
887acd884deSSumit Saxena 	cc_ext->fr_rtt = sb->fr_num_rtts;
888acd884deSSumit Saxena 	cc_ext->ai_rate_incr = sb->ai_rate_increase;
889acd884deSSumit Saxena 	cc_ext->rr_rtt_th = le16_to_cpu(sb->reduction_relax_rtts_th);
890acd884deSSumit Saxena 	cc_ext->ar_cr_th = le16_to_cpu(sb->additional_relax_cr_th);
891acd884deSSumit Saxena 	cc_ext->cr_min_th = le16_to_cpu(sb->cr_min_th);
892acd884deSSumit Saxena 	cc_ext->bw_avg_weight = sb->bw_avg_weight;
893acd884deSSumit Saxena 	cc_ext->cr_factor = sb->actual_cr_factor;
894acd884deSSumit Saxena 	cc_ext->cr_th_max_cp = le16_to_cpu(sb->max_cp_cr_th);
895acd884deSSumit Saxena 	cc_ext->cp_bias_en = sb->cp_bias_en;
896acd884deSSumit Saxena 	cc_ext->cp_bias = sb->cp_bias;
897acd884deSSumit Saxena 	cc_ext->cnp_ecn = sb->cnp_ecn;
898acd884deSSumit Saxena 	cc_ext->rtt_jitter_en = sb->rtt_jitter_en;
899acd884deSSumit Saxena 	cc_ext->bytes_per_usec = le16_to_cpu(sb->link_bytes_per_usec);
900acd884deSSumit Saxena 	cc_ext->cc_cr_reset_th = le16_to_cpu(sb->reset_cc_cr_th);
901acd884deSSumit Saxena 	cc_ext->cr_width = sb->cr_width;
902acd884deSSumit Saxena 	cc_ext->min_quota = sb->quota_period_min;
903acd884deSSumit Saxena 	cc_ext->max_quota = sb->quota_period_max;
904acd884deSSumit Saxena 	cc_ext->abs_max_quota = sb->quota_period_abs_max;
905acd884deSSumit Saxena 	cc_ext->tr_lb = le16_to_cpu(sb->tr_lower_bound);
906acd884deSSumit Saxena 	cc_ext->cr_prob_fac = sb->cr_prob_factor;
907acd884deSSumit Saxena 	cc_ext->tr_prob_fac = sb->tr_prob_factor;
908acd884deSSumit Saxena 	cc_ext->fair_cr_th = le16_to_cpu(sb->fairness_cr_th);
909acd884deSSumit Saxena 	cc_ext->red_div = sb->red_div;
910acd884deSSumit Saxena 	cc_ext->cnp_ratio_th = sb->cnp_ratio_th;
911acd884deSSumit Saxena 	cc_ext->ai_ext_rtt = le16_to_cpu(sb->exp_ai_rtts);
912acd884deSSumit Saxena 	cc_ext->exp_crcp_ratio = sb->exp_ai_cr_cp_ratio;
913acd884deSSumit Saxena 	cc_ext->low_rate_en = sb->use_rate_table;
914acd884deSSumit Saxena 	cc_ext->cpcr_update_th = le16_to_cpu(sb->cp_exp_update_th);
915acd884deSSumit Saxena 	cc_ext->ai_rtt_th1 = le16_to_cpu(sb->high_exp_ai_rtts_th1);
916acd884deSSumit Saxena 	cc_ext->ai_rtt_th2 = le16_to_cpu(sb->high_exp_ai_rtts_th2);
917acd884deSSumit Saxena 	cc_ext->cf_rtt_th = le16_to_cpu(sb->actual_cr_cong_free_rtts_th);
918acd884deSSumit Saxena 	cc_ext->sc_cr_th1 = le16_to_cpu(sb->severe_cong_cr_th1);
919acd884deSSumit Saxena 	cc_ext->sc_cr_th2 = le16_to_cpu(sb->severe_cong_cr_th2);
920acd884deSSumit Saxena 	cc_ext->l64B_per_rtt = le32_to_cpu(sb->link64B_per_rtt);
921acd884deSSumit Saxena 	cc_ext->cc_ack_bytes = sb->cc_ack_bytes;
922acd884deSSumit Saxena 	cc_ext->reduce_cf_rtt_th = le16_to_cpu(sb->reduce_init_cong_free_rtts_th);
923acd884deSSumit Saxena }
924acd884deSSumit Saxena 
bnxt_qplib_query_cc_param(struct bnxt_qplib_res * res,struct bnxt_qplib_cc_param * cc_param)925acd884deSSumit Saxena int bnxt_qplib_query_cc_param(struct bnxt_qplib_res *res,
926acd884deSSumit Saxena 			      struct bnxt_qplib_cc_param *cc_param)
927acd884deSSumit Saxena {
928acd884deSSumit Saxena 	struct creq_query_roce_cc_gen1_resp_sb_tlv *gen1_sb;
929acd884deSSumit Saxena 	struct bnxt_qplib_tlv_query_rcc_sb *ext_sb;
930acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
931acd884deSSumit Saxena 	struct creq_query_roce_cc_resp resp = {};
932acd884deSSumit Saxena 	struct creq_query_roce_cc_resp_sb *sb;
933acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
934acd884deSSumit Saxena 	struct cmdq_query_roce_cc req = {};
935acd884deSSumit Saxena 	struct bnxt_qplib_rcfw_sbuf sbuf;
936acd884deSSumit Saxena 	size_t resp_size;
937acd884deSSumit Saxena 	int rc;
938acd884deSSumit Saxena 
939acd884deSSumit Saxena 	/* Query the parameters from chip */
940acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_QUERY_ROCE_CC,
941acd884deSSumit Saxena 				 sizeof(req));
942acd884deSSumit Saxena 	if (_is_chip_gen_p5_p7(res->cctx))
943acd884deSSumit Saxena 		resp_size = sizeof(*ext_sb);
944acd884deSSumit Saxena 	else
945acd884deSSumit Saxena 		resp_size = sizeof(*sb);
946acd884deSSumit Saxena 	sbuf.size = ALIGN(resp_size, BNXT_QPLIB_CMDQE_UNITS);
947acd884deSSumit Saxena 	sbuf.sb = dma_zalloc_coherent(&rcfw->pdev->dev, sbuf.size,
948acd884deSSumit Saxena 				       &sbuf.dma_addr, GFP_KERNEL);
949acd884deSSumit Saxena 	if (!sbuf.sb)
950acd884deSSumit Saxena 		return -ENOMEM;
951acd884deSSumit Saxena 
952acd884deSSumit Saxena 	req.resp_size = sbuf.size / BNXT_QPLIB_CMDQE_UNITS;
953acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req),
954acd884deSSumit Saxena 				sizeof(resp), 0);
955acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(res->rcfw, &msg);
956acd884deSSumit Saxena 	if (rc) {
957acd884deSSumit Saxena 		dev_dbg(&res->pdev->dev, "%s:Query CC param failed:0x%x\n",
958acd884deSSumit Saxena 			__func__, rc);
959acd884deSSumit Saxena 		goto out;
960acd884deSSumit Saxena 	}
961acd884deSSumit Saxena 
962acd884deSSumit Saxena 	ext_sb = sbuf.sb;
963acd884deSSumit Saxena 	gen1_sb = &ext_sb->gen1_sb;
964acd884deSSumit Saxena 	sb = _is_chip_gen_p5_p7(res->cctx) ? &ext_sb->base_sb :
965acd884deSSumit Saxena 		(struct creq_query_roce_cc_resp_sb *)ext_sb;
966acd884deSSumit Saxena 
967acd884deSSumit Saxena 	cc_param->enable = sb->enable_cc & CREQ_QUERY_ROCE_CC_RESP_SB_ENABLE_CC;
968acd884deSSumit Saxena 	cc_param->tos_ecn = (sb->tos_dscp_tos_ecn &
969acd884deSSumit Saxena 			     CREQ_QUERY_ROCE_CC_RESP_SB_TOS_ECN_MASK) >>
970acd884deSSumit Saxena 			     CREQ_QUERY_ROCE_CC_RESP_SB_TOS_ECN_SFT;
971acd884deSSumit Saxena 	cc_param->tos_dscp = (sb->tos_dscp_tos_ecn &
972acd884deSSumit Saxena 			      CREQ_QUERY_ROCE_CC_RESP_SB_TOS_DSCP_MASK) >>
973acd884deSSumit Saxena 			      CREQ_QUERY_ROCE_CC_RESP_SB_TOS_DSCP_SFT;
974acd884deSSumit Saxena 	cc_param->alt_tos_dscp = sb->alt_tos_dscp;
975acd884deSSumit Saxena 	cc_param->alt_vlan_pcp = sb->alt_vlan_pcp;
976acd884deSSumit Saxena 
977acd884deSSumit Saxena 	cc_param->g = sb->g;
978acd884deSSumit Saxena 	cc_param->nph_per_state = sb->num_phases_per_state;
979acd884deSSumit Saxena 	cc_param->init_cr = le16_to_cpu(sb->init_cr);
980acd884deSSumit Saxena 	cc_param->init_tr = le16_to_cpu(sb->init_tr);
981acd884deSSumit Saxena 	cc_param->cc_mode = sb->cc_mode;
982acd884deSSumit Saxena 	cc_param->inact_th = le16_to_cpu(sb->inactivity_th);
983acd884deSSumit Saxena 	cc_param->rtt = le16_to_cpu(sb->rtt);
984acd884deSSumit Saxena 	cc_param->tcp_cp = le16_to_cpu(sb->tcp_cp);
985acd884deSSumit Saxena 	cc_param->time_pph = sb->time_per_phase;
986acd884deSSumit Saxena 	cc_param->pkts_pph = sb->pkts_per_phase;
987acd884deSSumit Saxena 	if (_is_chip_gen_p5_p7(res->cctx))
988acd884deSSumit Saxena 		bnxt_qplib_read_cc_gen1(&cc_param->cc_ext, gen1_sb);
989acd884deSSumit Saxena out:
990acd884deSSumit Saxena 	dma_free_coherent(&rcfw->pdev->dev, sbuf.size,
991acd884deSSumit Saxena 				  sbuf.sb, sbuf.dma_addr);
992acd884deSSumit Saxena 	return rc;
993acd884deSSumit Saxena }
994acd884deSSumit Saxena 
995acd884deSSumit Saxena 
bnxt_qplib_get_roce_error_stats(struct bnxt_qplib_rcfw * rcfw,struct bnxt_qplib_roce_stats * stats,struct bnxt_qplib_query_stats_info * sinfo)996acd884deSSumit Saxena int bnxt_qplib_get_roce_error_stats(struct bnxt_qplib_rcfw *rcfw,
997acd884deSSumit Saxena 				    struct bnxt_qplib_roce_stats *stats,
998acd884deSSumit Saxena 				    struct bnxt_qplib_query_stats_info *sinfo)
999acd884deSSumit Saxena {
1000acd884deSSumit Saxena 	struct creq_query_roce_stats_resp resp = {};
1001acd884deSSumit Saxena 	struct creq_query_roce_stats_resp_sb *sb;
1002acd884deSSumit Saxena 	struct cmdq_query_roce_stats req = {};
1003acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
1004acd884deSSumit Saxena 	struct bnxt_qplib_rcfw_sbuf sbuf;
1005acd884deSSumit Saxena 	u16 cmd_flags = 0;
1006acd884deSSumit Saxena 	u32 fn_id = 0;
1007acd884deSSumit Saxena 	int rc = 0;
1008acd884deSSumit Saxena 
1009acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_QUERY_ROCE_STATS,
1010acd884deSSumit Saxena 				 sizeof(req));
1011acd884deSSumit Saxena 
1012acd884deSSumit Saxena 	sbuf.size = sizeof(*sb);
1013acd884deSSumit Saxena 	sbuf.sb = dma_zalloc_coherent(&rcfw->pdev->dev, sbuf.size,
1014acd884deSSumit Saxena 				       &sbuf.dma_addr, GFP_KERNEL);
1015acd884deSSumit Saxena 	if (!sbuf.sb)
1016acd884deSSumit Saxena 		return -ENOMEM;
1017acd884deSSumit Saxena 	sb = sbuf.sb;
1018acd884deSSumit Saxena 
1019acd884deSSumit Saxena 	if (rcfw->res->cctx->hwrm_intf_ver >= HWRM_VERSION_ROCE_STATS_FN_ID) {
1020acd884deSSumit Saxena 		if (sinfo->function_id != 0xFFFFFFFF) {
1021acd884deSSumit Saxena 			cmd_flags = CMDQ_QUERY_ROCE_STATS_FLAGS_FUNCTION_ID;
1022acd884deSSumit Saxena 			if (sinfo->vf_valid) {
1023acd884deSSumit Saxena 				fn_id = CMDQ_QUERY_ROCE_STATS_VF_VALID;
1024acd884deSSumit Saxena 				fn_id |= (sinfo->function_id <<
1025acd884deSSumit Saxena 					  CMDQ_QUERY_ROCE_STATS_VF_NUM_SFT) &
1026acd884deSSumit Saxena 					  CMDQ_QUERY_ROCE_STATS_VF_NUM_MASK;
1027acd884deSSumit Saxena 			} else {
1028acd884deSSumit Saxena 				fn_id = sinfo->function_id &
1029acd884deSSumit Saxena 					CMDQ_QUERY_ROCE_STATS_PF_NUM_MASK;
1030acd884deSSumit Saxena 			}
1031acd884deSSumit Saxena 		}
1032acd884deSSumit Saxena 
1033acd884deSSumit Saxena 		req.flags = cpu_to_le16(cmd_flags);
1034acd884deSSumit Saxena 		req.function_id = cpu_to_le32(fn_id);
1035acd884deSSumit Saxena 
1036acd884deSSumit Saxena 		if (sinfo->collection_id != 0xFF) {
1037acd884deSSumit Saxena 			cmd_flags |= CMDQ_QUERY_ROCE_STATS_FLAGS_COLLECTION_ID;
1038acd884deSSumit Saxena 			req.collection_id = sinfo->collection_id;
1039acd884deSSumit Saxena 		}
1040acd884deSSumit Saxena 	} else {
1041acd884deSSumit Saxena 		/* For older HWRM version, the command length has to be
1042acd884deSSumit Saxena 		 * adjusted. 8 bytes are more in the newer command.
1043acd884deSSumit Saxena 		 * So subtract these 8 bytes for older HWRM version.
1044acd884deSSumit Saxena 		 * command units are adjusted inside
1045acd884deSSumit Saxena 		 * bnxt_qplib_rcfw_send_message.
1046acd884deSSumit Saxena 		 */
1047acd884deSSumit Saxena 		req.cmd_size -= 8;
1048acd884deSSumit Saxena 	}
1049acd884deSSumit Saxena 
1050acd884deSSumit Saxena 	req.resp_size = sbuf.size / BNXT_QPLIB_CMDQE_UNITS;
1051acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req),
1052acd884deSSumit Saxena 				sizeof(resp), 0);
1053acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
1054acd884deSSumit Saxena 	if (rc)
1055acd884deSSumit Saxena 		goto bail;
1056acd884deSSumit Saxena 	/* Extract the context from the side buffer */
1057acd884deSSumit Saxena 	stats->to_retransmits = le64_to_cpu(sb->to_retransmits);
1058acd884deSSumit Saxena 	stats->seq_err_naks_rcvd = le64_to_cpu(sb->seq_err_naks_rcvd);
1059acd884deSSumit Saxena 	stats->max_retry_exceeded = le64_to_cpu(sb->max_retry_exceeded);
1060acd884deSSumit Saxena 	stats->rnr_naks_rcvd = le64_to_cpu(sb->rnr_naks_rcvd);
1061acd884deSSumit Saxena 	stats->missing_resp = le64_to_cpu(sb->missing_resp);
1062acd884deSSumit Saxena 	stats->unrecoverable_err = le64_to_cpu(sb->unrecoverable_err);
1063acd884deSSumit Saxena 	stats->bad_resp_err = le64_to_cpu(sb->bad_resp_err);
1064acd884deSSumit Saxena 	stats->local_qp_op_err = le64_to_cpu(sb->local_qp_op_err);
1065acd884deSSumit Saxena 	stats->local_protection_err = le64_to_cpu(sb->local_protection_err);
1066acd884deSSumit Saxena 	stats->mem_mgmt_op_err = le64_to_cpu(sb->mem_mgmt_op_err);
1067acd884deSSumit Saxena 	stats->remote_invalid_req_err = le64_to_cpu(sb->remote_invalid_req_err);
1068acd884deSSumit Saxena 	stats->remote_access_err = le64_to_cpu(sb->remote_access_err);
1069acd884deSSumit Saxena 	stats->remote_op_err = le64_to_cpu(sb->remote_op_err);
1070acd884deSSumit Saxena 	stats->dup_req = le64_to_cpu(sb->dup_req);
1071acd884deSSumit Saxena 	stats->res_exceed_max = le64_to_cpu(sb->res_exceed_max);
1072acd884deSSumit Saxena 	stats->res_length_mismatch = le64_to_cpu(sb->res_length_mismatch);
1073acd884deSSumit Saxena 	stats->res_exceeds_wqe = le64_to_cpu(sb->res_exceeds_wqe);
1074acd884deSSumit Saxena 	stats->res_opcode_err = le64_to_cpu(sb->res_opcode_err);
1075acd884deSSumit Saxena 	stats->res_rx_invalid_rkey = le64_to_cpu(sb->res_rx_invalid_rkey);
1076acd884deSSumit Saxena 	stats->res_rx_domain_err = le64_to_cpu(sb->res_rx_domain_err);
1077acd884deSSumit Saxena 	stats->res_rx_no_perm = le64_to_cpu(sb->res_rx_no_perm);
1078acd884deSSumit Saxena 	stats->res_rx_range_err = le64_to_cpu(sb->res_rx_range_err);
1079acd884deSSumit Saxena 	stats->res_tx_invalid_rkey = le64_to_cpu(sb->res_tx_invalid_rkey);
1080acd884deSSumit Saxena 	stats->res_tx_domain_err = le64_to_cpu(sb->res_tx_domain_err);
1081acd884deSSumit Saxena 	stats->res_tx_no_perm = le64_to_cpu(sb->res_tx_no_perm);
1082acd884deSSumit Saxena 	stats->res_tx_range_err = le64_to_cpu(sb->res_tx_range_err);
1083acd884deSSumit Saxena 	stats->res_irrq_oflow = le64_to_cpu(sb->res_irrq_oflow);
1084acd884deSSumit Saxena 	stats->res_unsup_opcode = le64_to_cpu(sb->res_unsup_opcode);
1085acd884deSSumit Saxena 	stats->res_unaligned_atomic = le64_to_cpu(sb->res_unaligned_atomic);
1086acd884deSSumit Saxena 	stats->res_rem_inv_err = le64_to_cpu(sb->res_rem_inv_err);
1087acd884deSSumit Saxena 	stats->res_mem_error = le64_to_cpu(sb->res_mem_error);
1088acd884deSSumit Saxena 	stats->res_srq_err = le64_to_cpu(sb->res_srq_err);
1089acd884deSSumit Saxena 	stats->res_cmp_err = le64_to_cpu(sb->res_cmp_err);
1090acd884deSSumit Saxena 	stats->res_invalid_dup_rkey = le64_to_cpu(sb->res_invalid_dup_rkey);
1091acd884deSSumit Saxena 	stats->res_wqe_format_err = le64_to_cpu(sb->res_wqe_format_err);
1092acd884deSSumit Saxena 	stats->res_cq_load_err = le64_to_cpu(sb->res_cq_load_err);
1093acd884deSSumit Saxena 	stats->res_srq_load_err = le64_to_cpu(sb->res_srq_load_err);
1094acd884deSSumit Saxena 	stats->res_tx_pci_err = le64_to_cpu(sb->res_tx_pci_err);
1095acd884deSSumit Saxena 	stats->res_rx_pci_err = le64_to_cpu(sb->res_rx_pci_err);
1096acd884deSSumit Saxena 
1097acd884deSSumit Saxena 	if (!rcfw->init_oos_stats) {
1098acd884deSSumit Saxena 		rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
1099acd884deSSumit Saxena 		rcfw->init_oos_stats = true;
1100acd884deSSumit Saxena 	} else {
1101acd884deSSumit Saxena 		stats->res_oos_drop_count += (le64_to_cpu(sb->res_oos_drop_count) -
1102acd884deSSumit Saxena 					      rcfw->oos_prev) &
1103acd884deSSumit Saxena 					     BNXT_QPLIB_OOS_COUNT_MASK;
1104acd884deSSumit Saxena 		rcfw->oos_prev = le64_to_cpu(sb->res_oos_drop_count);
1105acd884deSSumit Saxena 	}
1106acd884deSSumit Saxena 
1107acd884deSSumit Saxena 	stats->active_qp_count_p0 = le64_to_cpu(sb->active_qp_count_p0);
1108acd884deSSumit Saxena 	stats->active_qp_count_p1 = le64_to_cpu(sb->active_qp_count_p1);
1109acd884deSSumit Saxena 	stats->active_qp_count_p2 = le64_to_cpu(sb->active_qp_count_p2);
1110acd884deSSumit Saxena 	stats->active_qp_count_p3 = le64_to_cpu(sb->active_qp_count_p3);
1111acd884deSSumit Saxena bail:
1112acd884deSSumit Saxena 	dma_free_coherent(&rcfw->pdev->dev, sbuf.size,
1113acd884deSSumit Saxena 				  sbuf.sb, sbuf.dma_addr);
1114acd884deSSumit Saxena 	return rc;
1115acd884deSSumit Saxena }
1116acd884deSSumit Saxena 
bnxt_qplib_set_link_aggr_mode(struct bnxt_qplib_res * res,u8 aggr_mode,u8 member_port_map,u8 active_port_map,bool aggr_en,u32 stats_fw_id)1117acd884deSSumit Saxena int bnxt_qplib_set_link_aggr_mode(struct bnxt_qplib_res *res,
1118acd884deSSumit Saxena 				  u8 aggr_mode, u8 member_port_map,
1119acd884deSSumit Saxena 				  u8 active_port_map, bool aggr_en,
1120acd884deSSumit Saxena 				  u32 stats_fw_id)
1121acd884deSSumit Saxena {
1122acd884deSSumit Saxena 	struct creq_set_link_aggr_mode_resources_resp resp = {};
1123acd884deSSumit Saxena 	struct cmdq_set_link_aggr_mode_cc req = {};
1124acd884deSSumit Saxena 	struct bnxt_qplib_rcfw *rcfw = res->rcfw;
1125acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
1126acd884deSSumit Saxena 	int rc = 0;
1127acd884deSSumit Saxena 
1128acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req, CMDQ_BASE_OPCODE_SET_LINK_AGGR_MODE,
1129acd884deSSumit Saxena 				 sizeof(req));
1130acd884deSSumit Saxena 
1131acd884deSSumit Saxena 	req.aggr_enable = aggr_en;
1132acd884deSSumit Saxena 	req.active_port_map = active_port_map;
1133acd884deSSumit Saxena 	req.member_port_map = member_port_map;
1134acd884deSSumit Saxena 	req.link_aggr_mode = aggr_mode;
1135acd884deSSumit Saxena 
1136acd884deSSumit Saxena 	/* need to specify only second port stats ctx id for now */
1137acd884deSSumit Saxena 	req.stat_ctx_id[1] = cpu_to_le16((u16)(stats_fw_id));
1138acd884deSSumit Saxena 
1139acd884deSSumit Saxena 	req.modify_mask =
1140acd884deSSumit Saxena 		cpu_to_le32(CMDQ_SET_LINK_AGGR_MODE_MODIFY_MASK_AGGR_EN |
1141acd884deSSumit Saxena 			    CMDQ_SET_LINK_AGGR_MODE_MODIFY_MASK_ACTIVE_PORT_MAP |
1142acd884deSSumit Saxena 			    CMDQ_SET_LINK_AGGR_MODE_MODIFY_MASK_MEMBER_PORT_MAP |
1143acd884deSSumit Saxena 			    CMDQ_SET_LINK_AGGR_MODE_MODIFY_MASK_AGGR_MODE |
1144acd884deSSumit Saxena 			    CMDQ_SET_LINK_AGGR_MODE_MODIFY_MASK_STAT_CTX_ID);
1145acd884deSSumit Saxena 
1146acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
1147acd884deSSumit Saxena 				sizeof(resp), 0);
1148acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
1149acd884deSSumit Saxena 	if (rc)
1150acd884deSSumit Saxena 		dev_err(&res->pdev->dev,
1151acd884deSSumit Saxena 			"QPLIB: Failed to set link aggr mode, %#x\n", rc);
1152acd884deSSumit Saxena 
1153acd884deSSumit Saxena 	return rc;
1154acd884deSSumit Saxena }
1155acd884deSSumit Saxena 
bnxt_qplib_qext_stat(struct bnxt_qplib_rcfw * rcfw,u32 fid,struct bnxt_qplib_ext_stat * estat,struct bnxt_qplib_query_stats_info * sinfo)1156acd884deSSumit Saxena int bnxt_qplib_qext_stat(struct bnxt_qplib_rcfw *rcfw, u32 fid,
1157acd884deSSumit Saxena 			 struct bnxt_qplib_ext_stat *estat,
1158acd884deSSumit Saxena 			 struct bnxt_qplib_query_stats_info *sinfo)
1159acd884deSSumit Saxena {
1160acd884deSSumit Saxena 	struct creq_query_roce_stats_ext_resp resp = {};
1161acd884deSSumit Saxena 	struct creq_query_roce_stats_ext_resp_sb *sb;
1162acd884deSSumit Saxena 	struct cmdq_query_roce_stats_ext req = {};
1163acd884deSSumit Saxena 	struct bnxt_qplib_cmdqmsg msg = {};
1164acd884deSSumit Saxena 	struct bnxt_qplib_rcfw_sbuf sbuf;
1165acd884deSSumit Saxena 	int rc;
1166acd884deSSumit Saxena 
1167acd884deSSumit Saxena 	sbuf.size = sizeof(*sb);
1168acd884deSSumit Saxena 	sbuf.sb = dma_zalloc_coherent(&rcfw->pdev->dev, sbuf.size,
1169acd884deSSumit Saxena 				       &sbuf.dma_addr, GFP_KERNEL);
1170acd884deSSumit Saxena 	if (!sbuf.sb) {
1171acd884deSSumit Saxena 		dev_err(&rcfw->pdev->dev,
1172acd884deSSumit Saxena 			"QPLIB: SP: QUERY_ROCE_STATS_EXT alloc sb failed\n");
1173acd884deSSumit Saxena 		return -ENOMEM;
1174acd884deSSumit Saxena 	}
1175acd884deSSumit Saxena 	sb = sbuf.sb;
1176acd884deSSumit Saxena 
1177acd884deSSumit Saxena 	bnxt_qplib_rcfw_cmd_prep(&req,
1178acd884deSSumit Saxena 			CMDQ_QUERY_ROCE_STATS_EXT_OPCODE_QUERY_ROCE_STATS,
1179acd884deSSumit Saxena 			sizeof(req));
1180acd884deSSumit Saxena 	req.resp_size = sbuf.size;
1181acd884deSSumit Saxena 	req.resp_addr = cpu_to_le64(sbuf.dma_addr);
1182acd884deSSumit Saxena 	req.flags = cpu_to_le16(CMDQ_QUERY_ROCE_STATS_EXT_FLAGS_FUNCTION_ID);
1183acd884deSSumit Saxena 	if (_is_chip_p7(rcfw->res->cctx) && rcfw->res->is_vf) {
1184acd884deSSumit Saxena 		if (sinfo->vf_valid)
1185acd884deSSumit Saxena 			req.function_id =
1186acd884deSSumit Saxena 				cpu_to_le32(CMDQ_QUERY_ROCE_STATS_EXT_VF_VALID |
1187acd884deSSumit Saxena 					    (fid << CMDQ_QUERY_ROCE_STATS_EXT_VF_NUM_SFT));
1188acd884deSSumit Saxena 		else
1189acd884deSSumit Saxena 			req.flags = cpu_to_le16(0);
1190acd884deSSumit Saxena 	} else {
1191acd884deSSumit Saxena 		req.function_id = cpu_to_le32(fid);
1192acd884deSSumit Saxena 	}
1193acd884deSSumit Saxena 
1194acd884deSSumit Saxena 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, &sbuf, sizeof(req),
1195acd884deSSumit Saxena 				sizeof(resp), 0);
1196acd884deSSumit Saxena 	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
1197acd884deSSumit Saxena 	if (rc)
1198acd884deSSumit Saxena 		goto bail;
1199acd884deSSumit Saxena 
1200acd884deSSumit Saxena 	/* dump when dyndbg is enabled */
1201acd884deSSumit Saxena 	print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, sb, sizeof(*sb));
1202acd884deSSumit Saxena 	estat->tx_atomic_req = le64_to_cpu(sb->tx_atomic_req_pkts);
1203acd884deSSumit Saxena 	estat->tx_read_req = le64_to_cpu(sb->tx_read_req_pkts);
1204acd884deSSumit Saxena 	estat->tx_read_res = le64_to_cpu(sb->tx_read_res_pkts);
1205acd884deSSumit Saxena 	estat->tx_write_req = le64_to_cpu(sb->tx_write_req_pkts);
1206acd884deSSumit Saxena 	estat->tx_send_req = le64_to_cpu(sb->tx_send_req_pkts);
1207acd884deSSumit Saxena 	estat->tx_roce_pkts = le64_to_cpu(sb->tx_roce_pkts);
1208acd884deSSumit Saxena 	estat->tx_roce_bytes = le64_to_cpu(sb->tx_roce_bytes);
1209acd884deSSumit Saxena 	estat->rx_atomic_req = le64_to_cpu(sb->rx_atomic_req_pkts);
1210acd884deSSumit Saxena 	estat->rx_read_req = le64_to_cpu(sb->rx_read_req_pkts);
1211acd884deSSumit Saxena 	estat->rx_read_res = le64_to_cpu(sb->rx_read_res_pkts);
1212acd884deSSumit Saxena 	estat->rx_write_req = le64_to_cpu(sb->rx_write_req_pkts);
1213acd884deSSumit Saxena 	estat->rx_send_req = le64_to_cpu(sb->rx_send_req_pkts);
1214acd884deSSumit Saxena 	estat->rx_roce_pkts = le64_to_cpu(sb->rx_roce_pkts);
1215acd884deSSumit Saxena 	estat->rx_roce_bytes = le64_to_cpu(sb->rx_roce_bytes);
1216acd884deSSumit Saxena 	estat->rx_roce_good_pkts = le64_to_cpu(sb->rx_roce_good_pkts);
1217acd884deSSumit Saxena 	estat->rx_roce_good_bytes = le64_to_cpu(sb->rx_roce_good_bytes);
1218acd884deSSumit Saxena 	estat->rx_out_of_buffer = le64_to_cpu(sb->rx_out_of_buffer_pkts);
1219acd884deSSumit Saxena 	estat->rx_out_of_sequence = le64_to_cpu(sb->rx_out_of_sequence_pkts);
1220acd884deSSumit Saxena 	estat->tx_cnp = le64_to_cpu(sb->tx_cnp_pkts);
1221acd884deSSumit Saxena 	estat->rx_cnp = le64_to_cpu(sb->rx_cnp_pkts);
1222acd884deSSumit Saxena 	estat->rx_ecn_marked = le64_to_cpu(sb->rx_ecn_marked_pkts);
1223acd884deSSumit Saxena 	estat->seq_err_naks_rcvd = le64_to_cpu(sb->seq_err_naks_rcvd);
1224acd884deSSumit Saxena 	estat->rnr_naks_rcvd = le64_to_cpu(sb->rnr_naks_rcvd);
1225acd884deSSumit Saxena 	estat->missing_resp = le64_to_cpu(sb->missing_resp);
1226acd884deSSumit Saxena 	estat->to_retransmits = le64_to_cpu(sb->to_retransmit);
1227acd884deSSumit Saxena 	estat->dup_req = le64_to_cpu(sb->dup_req);
1228acd884deSSumit Saxena 	estat->rx_dcn_payload_cut = le64_to_cpu(sb->rx_dcn_payload_cut);
1229acd884deSSumit Saxena 	estat->te_bypassed = le64_to_cpu(sb->te_bypassed);
1230acd884deSSumit Saxena bail:
1231acd884deSSumit Saxena 	dma_free_coherent(&rcfw->pdev->dev, sbuf.size,
1232acd884deSSumit Saxena 				  sbuf.sb, sbuf.dma_addr);
1233acd884deSSumit Saxena 	return rc;
1234acd884deSSumit Saxena }
1235