xref: /linux/drivers/net/ethernet/broadcom/bnge/bnge_hwrm_lib.c (revision fab183d632628381b466a41479489541ac0e29a0)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2025 Broadcom.
3 
4 #include <linux/errno.h>
5 #include <linux/kernel.h>
6 #include <linux/mm.h>
7 #include <linux/pci.h>
8 #include <linux/bnge/hsi.h>
9 #include <linux/if_vlan.h>
10 #include <net/netdev_queues.h>
11 
12 #include "bnge.h"
13 #include "bnge_hwrm.h"
14 #include "bnge_hwrm_lib.h"
15 #include "bnge_rmem.h"
16 #include "bnge_resc.h"
17 #include "bnge_netdev.h"
18 
19 static const u16 bnge_async_events_arr[] = {
20 	ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE,
21 	ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CHANGE,
22 	ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE,
23 	ASYNC_EVENT_CMPL_EVENT_ID_PORT_PHY_CFG_CHANGE,
24 };
25 
bnge_hwrm_ver_get(struct bnge_dev * bd)26 int bnge_hwrm_ver_get(struct bnge_dev *bd)
27 {
28 	u32 dev_caps_cfg, hwrm_ver, hwrm_spec_code;
29 	u16 fw_maj, fw_min, fw_bld, fw_rsv;
30 	struct hwrm_ver_get_output *resp;
31 	struct hwrm_ver_get_input *req;
32 	int rc;
33 
34 	rc = bnge_hwrm_req_init(bd, req, HWRM_VER_GET);
35 	if (rc)
36 		return rc;
37 
38 	bnge_hwrm_req_flags(bd, req, BNGE_HWRM_FULL_WAIT);
39 	bd->hwrm_max_req_len = HWRM_MAX_REQ_LEN;
40 	req->hwrm_intf_maj = HWRM_VERSION_MAJOR;
41 	req->hwrm_intf_min = HWRM_VERSION_MINOR;
42 	req->hwrm_intf_upd = HWRM_VERSION_UPDATE;
43 
44 	resp = bnge_hwrm_req_hold(bd, req);
45 	rc = bnge_hwrm_req_send(bd, req);
46 	if (rc)
47 		goto hwrm_ver_get_exit;
48 
49 	memcpy(&bd->ver_resp, resp, sizeof(struct hwrm_ver_get_output));
50 
51 	hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 |
52 			 resp->hwrm_intf_min_8b << 8 |
53 			 resp->hwrm_intf_upd_8b;
54 	hwrm_ver = HWRM_VERSION_MAJOR << 16 | HWRM_VERSION_MINOR << 8 |
55 			HWRM_VERSION_UPDATE;
56 
57 	if (hwrm_spec_code > hwrm_ver)
58 		snprintf(bd->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
59 			 HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR,
60 			 HWRM_VERSION_UPDATE);
61 	else
62 		snprintf(bd->hwrm_ver_supp, FW_VER_STR_LEN, "%d.%d.%d",
63 			 resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
64 			 resp->hwrm_intf_upd_8b);
65 
66 	fw_maj = le16_to_cpu(resp->hwrm_fw_major);
67 	fw_min = le16_to_cpu(resp->hwrm_fw_minor);
68 	fw_bld = le16_to_cpu(resp->hwrm_fw_build);
69 	fw_rsv = le16_to_cpu(resp->hwrm_fw_patch);
70 
71 	bd->fw_ver_code = BNGE_FW_VER_CODE(fw_maj, fw_min, fw_bld, fw_rsv);
72 	snprintf(bd->fw_ver_str, FW_VER_STR_LEN, "%d.%d.%d.%d",
73 		 fw_maj, fw_min, fw_bld, fw_rsv);
74 
75 	if (strlen(resp->active_pkg_name)) {
76 		int fw_ver_len = strlen(bd->fw_ver_str);
77 
78 		snprintf(bd->fw_ver_str + fw_ver_len,
79 			 FW_VER_STR_LEN - fw_ver_len - 1, "/pkg %s",
80 			 resp->active_pkg_name);
81 		bd->fw_cap |= BNGE_FW_CAP_PKG_VER;
82 	}
83 
84 	bd->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout);
85 	if (!bd->hwrm_cmd_timeout)
86 		bd->hwrm_cmd_timeout = BNGE_DFLT_HWRM_CMD_TIMEOUT;
87 	bd->hwrm_cmd_max_timeout = le16_to_cpu(resp->max_req_timeout) * 1000;
88 	if (!bd->hwrm_cmd_max_timeout)
89 		bd->hwrm_cmd_max_timeout = BNGE_HWRM_CMD_MAX_TIMEOUT;
90 	else if (bd->hwrm_cmd_max_timeout > BNGE_HWRM_CMD_MAX_TIMEOUT)
91 		dev_warn(bd->dev, "Default HWRM commands max timeout increased to %d seconds\n",
92 			 bd->hwrm_cmd_max_timeout / 1000);
93 
94 	bd->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len);
95 	bd->hwrm_max_ext_req_len = le16_to_cpu(resp->max_ext_req_len);
96 
97 	if (bd->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
98 		bd->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
99 
100 	bd->chip_num = le16_to_cpu(resp->chip_num);
101 	bd->chip_rev = resp->chip_rev;
102 
103 	dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg);
104 	if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
105 	    (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED))
106 		bd->fw_cap |= BNGE_FW_CAP_SHORT_CMD;
107 
108 	if (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED)
109 		bd->fw_cap |= BNGE_FW_CAP_KONG_MB_CHNL;
110 
111 	if (dev_caps_cfg &
112 	    VER_GET_RESP_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED)
113 		bd->fw_cap |= BNGE_FW_CAP_CFA_ADV_FLOW;
114 
115 hwrm_ver_get_exit:
116 	bnge_hwrm_req_drop(bd, req);
117 	return rc;
118 }
119 
120 int
bnge_hwrm_nvm_dev_info(struct bnge_dev * bd,struct hwrm_nvm_get_dev_info_output * nvm_info)121 bnge_hwrm_nvm_dev_info(struct bnge_dev *bd,
122 		       struct hwrm_nvm_get_dev_info_output *nvm_info)
123 {
124 	struct hwrm_nvm_get_dev_info_output *resp;
125 	struct hwrm_nvm_get_dev_info_input *req;
126 	int rc;
127 
128 	rc = bnge_hwrm_req_init(bd, req, HWRM_NVM_GET_DEV_INFO);
129 	if (rc)
130 		return rc;
131 
132 	resp = bnge_hwrm_req_hold(bd, req);
133 	rc = bnge_hwrm_req_send(bd, req);
134 	if (!rc)
135 		memcpy(nvm_info, resp, sizeof(*resp));
136 	bnge_hwrm_req_drop(bd, req);
137 	return rc;
138 }
139 
bnge_hwrm_func_reset(struct bnge_dev * bd)140 int bnge_hwrm_func_reset(struct bnge_dev *bd)
141 {
142 	struct hwrm_func_reset_input *req;
143 	int rc;
144 
145 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_RESET);
146 	if (rc)
147 		return rc;
148 
149 	req->enables = 0;
150 	bnge_hwrm_req_timeout(bd, req, BNGE_HWRM_RESET_TIMEOUT);
151 	return bnge_hwrm_req_send(bd, req);
152 }
153 
bnge_hwrm_fw_set_time(struct bnge_dev * bd)154 int bnge_hwrm_fw_set_time(struct bnge_dev *bd)
155 {
156 	struct hwrm_fw_set_time_input *req;
157 	struct tm tm;
158 	int rc;
159 
160 	time64_to_tm(ktime_get_real_seconds(), 0, &tm);
161 
162 	rc = bnge_hwrm_req_init(bd, req, HWRM_FW_SET_TIME);
163 	if (rc)
164 		return rc;
165 
166 	req->year = cpu_to_le16(1900 + tm.tm_year);
167 	req->month = 1 + tm.tm_mon;
168 	req->day = tm.tm_mday;
169 	req->hour = tm.tm_hour;
170 	req->minute = tm.tm_min;
171 	req->second = tm.tm_sec;
172 	return bnge_hwrm_req_send(bd, req);
173 }
174 
bnge_hwrm_func_drv_rgtr(struct bnge_dev * bd)175 int bnge_hwrm_func_drv_rgtr(struct bnge_dev *bd)
176 {
177 	DECLARE_BITMAP(async_events_bmap, 256);
178 	struct hwrm_func_drv_rgtr_output *resp;
179 	struct hwrm_func_drv_rgtr_input *req;
180 	u32 events[8];
181 	u32 flags;
182 	int rc, i;
183 
184 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_DRV_RGTR);
185 	if (rc)
186 		return rc;
187 
188 	req->enables = cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE |
189 				   FUNC_DRV_RGTR_REQ_ENABLES_VER |
190 				   FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD);
191 
192 	req->os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX);
193 	flags = FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE;
194 
195 	req->flags = cpu_to_le32(flags);
196 	req->ver_maj_8b = DRV_VER_MAJ;
197 	req->ver_min_8b = DRV_VER_MIN;
198 	req->ver_upd_8b = DRV_VER_UPD;
199 	req->ver_maj = cpu_to_le16(DRV_VER_MAJ);
200 	req->ver_min = cpu_to_le16(DRV_VER_MIN);
201 	req->ver_upd = cpu_to_le16(DRV_VER_UPD);
202 
203 	memset(async_events_bmap, 0, sizeof(async_events_bmap));
204 	for (i = 0; i < ARRAY_SIZE(bnge_async_events_arr); i++)
205 		__set_bit(bnge_async_events_arr[i], async_events_bmap);
206 
207 	bitmap_to_arr32(events, async_events_bmap, 256);
208 	for (i = 0; i < ARRAY_SIZE(req->async_event_fwd); i++)
209 		req->async_event_fwd[i] |= cpu_to_le32(events[i]);
210 
211 	resp = bnge_hwrm_req_hold(bd, req);
212 	rc = bnge_hwrm_req_send(bd, req);
213 	if (!rc) {
214 		set_bit(BNGE_STATE_DRV_REGISTERED, &bd->state);
215 		if (resp->flags &
216 		    cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED))
217 			bd->fw_cap |= BNGE_FW_CAP_IF_CHANGE;
218 	}
219 	bnge_hwrm_req_drop(bd, req);
220 	return rc;
221 }
222 
bnge_hwrm_func_drv_unrgtr(struct bnge_dev * bd)223 int bnge_hwrm_func_drv_unrgtr(struct bnge_dev *bd)
224 {
225 	struct hwrm_func_drv_unrgtr_input *req;
226 	int rc;
227 
228 	if (!test_and_clear_bit(BNGE_STATE_DRV_REGISTERED, &bd->state))
229 		return 0;
230 
231 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_DRV_UNRGTR);
232 	if (rc)
233 		return rc;
234 	return bnge_hwrm_req_send(bd, req);
235 }
236 
bnge_init_ctx_initializer(struct bnge_ctx_mem_type * ctxm,u8 init_val,u8 init_offset,bool init_mask_set)237 static void bnge_init_ctx_initializer(struct bnge_ctx_mem_type *ctxm,
238 				      u8 init_val, u8 init_offset,
239 				      bool init_mask_set)
240 {
241 	ctxm->init_value = init_val;
242 	ctxm->init_offset = BNGE_CTX_INIT_INVALID_OFFSET;
243 	if (init_mask_set)
244 		ctxm->init_offset = init_offset * 4;
245 	else
246 		ctxm->init_value = 0;
247 }
248 
bnge_alloc_all_ctx_pg_info(struct bnge_dev * bd,int ctx_max)249 static int bnge_alloc_all_ctx_pg_info(struct bnge_dev *bd, int ctx_max)
250 {
251 	struct bnge_ctx_mem_info *ctx = bd->ctx;
252 	u16 type;
253 
254 	for (type = 0; type < ctx_max; type++) {
255 		struct bnge_ctx_mem_type *ctxm = &ctx->ctx_arr[type];
256 		int n = 1;
257 
258 		if (!ctxm->max_entries)
259 			continue;
260 
261 		if (ctxm->instance_bmap)
262 			n = hweight32(ctxm->instance_bmap);
263 		ctxm->pg_info = kzalloc_objs(*ctxm->pg_info, n);
264 		if (!ctxm->pg_info)
265 			return -ENOMEM;
266 	}
267 
268 	return 0;
269 }
270 
271 #define BNGE_CTX_INIT_VALID(flags)	\
272 	(!!((flags) &			\
273 	    FUNC_BACKING_STORE_QCAPS_V2_RESP_FLAGS_ENABLE_CTX_KIND_INIT))
274 
bnge_hwrm_func_backing_store_qcaps(struct bnge_dev * bd)275 int bnge_hwrm_func_backing_store_qcaps(struct bnge_dev *bd)
276 {
277 	struct hwrm_func_backing_store_qcaps_v2_output *resp;
278 	struct hwrm_func_backing_store_qcaps_v2_input *req;
279 	struct bnge_ctx_mem_info *ctx;
280 	u16 type, next_type;
281 	int rc;
282 
283 	if (bd->ctx)
284 		return 0;
285 
286 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_BACKING_STORE_QCAPS_V2);
287 	if (rc)
288 		return rc;
289 
290 	ctx = kzalloc_obj(*ctx);
291 	if (!ctx)
292 		return -ENOMEM;
293 	bd->ctx = ctx;
294 
295 	resp = bnge_hwrm_req_hold(bd, req);
296 
297 	for (type = 0; type < BNGE_CTX_INV; type = next_type) {
298 		struct bnge_ctx_mem_type *ctxm;
299 		u8 init_val, init_off, i;
300 		__le32 *p;
301 		u32 flags;
302 
303 		req->type = cpu_to_le16(type);
304 		rc = bnge_hwrm_req_send(bd, req);
305 		if (rc)
306 			goto ctx_done;
307 
308 		next_type = le16_to_cpu(resp->next_valid_type);
309 		if (type >= BNGE_CTX_V2_MAX)
310 			continue;
311 
312 		ctxm = &ctx->ctx_arr[type];
313 		flags = le32_to_cpu(resp->flags);
314 
315 		if (!(flags &
316 		      FUNC_BACKING_STORE_QCAPS_V2_RESP_FLAGS_TYPE_VALID))
317 			continue;
318 
319 		ctxm->type = le16_to_cpu(resp->type);
320 		ctxm->entry_size = le16_to_cpu(resp->entry_size);
321 		ctxm->flags = flags;
322 		ctxm->instance_bmap = le32_to_cpu(resp->instance_bit_map);
323 		ctxm->entry_multiple = resp->entry_multiple;
324 		ctxm->max_entries = le32_to_cpu(resp->max_num_entries);
325 		ctxm->min_entries = le32_to_cpu(resp->min_num_entries);
326 		init_val = resp->ctx_init_value;
327 		init_off = resp->ctx_init_offset;
328 		bnge_init_ctx_initializer(ctxm, init_val, init_off,
329 					  BNGE_CTX_INIT_VALID(flags));
330 		ctxm->split_entry_cnt = min_t(u8, resp->subtype_valid_cnt,
331 					      BNGE_MAX_SPLIT_ENTRY);
332 		for (i = 0, p = &resp->split_entry_0; i < ctxm->split_entry_cnt;
333 		     i++, p++)
334 			ctxm->split[i] = le32_to_cpu(*p);
335 	}
336 	rc = bnge_alloc_all_ctx_pg_info(bd, BNGE_CTX_V2_MAX);
337 
338 ctx_done:
339 	bnge_hwrm_req_drop(bd, req);
340 	return rc;
341 }
342 
bnge_hwrm_set_pg_attr(struct bnge_ring_mem_info * rmem,u8 * pg_attr,__le64 * pg_dir)343 static void bnge_hwrm_set_pg_attr(struct bnge_ring_mem_info *rmem, u8 *pg_attr,
344 				  __le64 *pg_dir)
345 {
346 	if (!rmem->nr_pages)
347 		return;
348 
349 	BNGE_SET_CTX_PAGE_ATTR(*pg_attr);
350 	if (rmem->depth >= 1) {
351 		if (rmem->depth == 2)
352 			*pg_attr |= 2;
353 		else
354 			*pg_attr |= 1;
355 		*pg_dir = cpu_to_le64(rmem->dma_pg_tbl);
356 	} else {
357 		*pg_dir = cpu_to_le64(rmem->dma_arr[0]);
358 	}
359 }
360 
bnge_hwrm_func_backing_store(struct bnge_dev * bd,struct bnge_ctx_mem_type * ctxm,bool last)361 int bnge_hwrm_func_backing_store(struct bnge_dev *bd,
362 				 struct bnge_ctx_mem_type *ctxm,
363 				 bool last)
364 {
365 	struct hwrm_func_backing_store_cfg_v2_input *req;
366 	u32 instance_bmap = ctxm->instance_bmap;
367 	int i, j, rc = 0, n = 1;
368 	__le32 *p;
369 
370 	if (!(ctxm->flags & BNGE_CTX_MEM_TYPE_VALID) || !ctxm->pg_info)
371 		return 0;
372 
373 	if (instance_bmap)
374 		n = hweight32(ctxm->instance_bmap);
375 	else
376 		instance_bmap = 1;
377 
378 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_BACKING_STORE_CFG_V2);
379 	if (rc)
380 		return rc;
381 	bnge_hwrm_req_hold(bd, req);
382 	req->type = cpu_to_le16(ctxm->type);
383 	req->entry_size = cpu_to_le16(ctxm->entry_size);
384 	req->subtype_valid_cnt = ctxm->split_entry_cnt;
385 	for (i = 0, p = &req->split_entry_0; i < ctxm->split_entry_cnt; i++)
386 		p[i] = cpu_to_le32(ctxm->split[i]);
387 	for (i = 0, j = 0; j < n && !rc; i++) {
388 		struct bnge_ctx_pg_info *ctx_pg;
389 
390 		if (!(instance_bmap & (1 << i)))
391 			continue;
392 		req->instance = cpu_to_le16(i);
393 		ctx_pg = &ctxm->pg_info[j++];
394 		if (!ctx_pg->entries)
395 			continue;
396 		req->num_entries = cpu_to_le32(ctx_pg->entries);
397 		bnge_hwrm_set_pg_attr(&ctx_pg->ring_mem,
398 				      &req->page_size_pbl_level,
399 				      &req->page_dir);
400 		if (last && j == n)
401 			req->flags =
402 				cpu_to_le32(BNGE_BS_CFG_ALL_DONE);
403 		rc = bnge_hwrm_req_send(bd, req);
404 	}
405 	bnge_hwrm_req_drop(bd, req);
406 
407 	return rc;
408 }
409 
bnge_hwrm_get_rings(struct bnge_dev * bd)410 static int bnge_hwrm_get_rings(struct bnge_dev *bd)
411 {
412 	struct bnge_hw_resc *hw_resc = &bd->hw_resc;
413 	struct hwrm_func_qcfg_output *resp;
414 	struct hwrm_func_qcfg_input *req;
415 	u16 cp, stats;
416 	u16 rx, tx;
417 	int rc;
418 
419 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_QCFG);
420 	if (rc)
421 		return rc;
422 
423 	req->fid = cpu_to_le16(0xffff);
424 	resp = bnge_hwrm_req_hold(bd, req);
425 	rc = bnge_hwrm_req_send(bd, req);
426 	if (rc) {
427 		bnge_hwrm_req_drop(bd, req);
428 		return rc;
429 	}
430 
431 	hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings);
432 	hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings);
433 	hw_resc->resv_hw_ring_grps =
434 		le32_to_cpu(resp->alloc_hw_ring_grps);
435 	hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics);
436 	hw_resc->resv_rsscos_ctxs = le16_to_cpu(resp->alloc_rsscos_ctx);
437 	cp = le16_to_cpu(resp->alloc_cmpl_rings);
438 	stats = le16_to_cpu(resp->alloc_stat_ctx);
439 	hw_resc->resv_irqs = cp;
440 	rx = hw_resc->resv_rx_rings;
441 	tx = hw_resc->resv_tx_rings;
442 	if (bnge_is_agg_reqd(bd))
443 		rx >>= 1;
444 	if (cp < (rx + tx)) {
445 		rc = bnge_fix_rings_count(&rx, &tx, cp, false);
446 		if (rc)
447 			goto get_rings_exit;
448 		if (bnge_is_agg_reqd(bd))
449 			rx <<= 1;
450 		hw_resc->resv_rx_rings = rx;
451 		hw_resc->resv_tx_rings = tx;
452 	}
453 	hw_resc->resv_irqs = le16_to_cpu(resp->alloc_msix);
454 	hw_resc->resv_hw_ring_grps = rx;
455 	hw_resc->resv_cp_rings = cp;
456 	hw_resc->resv_stat_ctxs = stats;
457 
458 get_rings_exit:
459 	bnge_hwrm_req_drop(bd, req);
460 	return rc;
461 }
462 
463 static struct hwrm_func_cfg_input *
__bnge_hwrm_reserve_pf_rings(struct bnge_dev * bd,struct bnge_hw_rings * hwr)464 __bnge_hwrm_reserve_pf_rings(struct bnge_dev *bd, struct bnge_hw_rings *hwr)
465 {
466 	struct hwrm_func_cfg_input *req;
467 	u32 enables = 0;
468 
469 	if (bnge_hwrm_req_init(bd, req, HWRM_FUNC_CFG))
470 		return NULL;
471 
472 	req->fid = cpu_to_le16(0xffff);
473 	enables |= hwr->tx ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0;
474 	req->num_tx_rings = cpu_to_le16(hwr->tx);
475 
476 	enables |= hwr->rx ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0;
477 	enables |= hwr->stat ? FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0;
478 	enables |= hwr->nq ? FUNC_CFG_REQ_ENABLES_NUM_MSIX : 0;
479 	enables |= hwr->cmpl ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS : 0;
480 	enables |= hwr->vnic ? FUNC_CFG_REQ_ENABLES_NUM_VNICS : 0;
481 	enables |= hwr->rss_ctx ? FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0;
482 
483 	req->num_rx_rings = cpu_to_le16(hwr->rx);
484 	req->num_rsscos_ctxs = cpu_to_le16(hwr->rss_ctx);
485 	req->num_cmpl_rings = cpu_to_le16(hwr->cmpl);
486 	req->num_msix = cpu_to_le16(hwr->nq);
487 	req->num_stat_ctxs = cpu_to_le16(hwr->stat);
488 	req->num_vnics = cpu_to_le16(hwr->vnic);
489 	req->enables = cpu_to_le32(enables);
490 
491 	return req;
492 }
493 
494 static int
bnge_hwrm_reserve_pf_rings(struct bnge_dev * bd,struct bnge_hw_rings * hwr)495 bnge_hwrm_reserve_pf_rings(struct bnge_dev *bd, struct bnge_hw_rings *hwr)
496 {
497 	struct hwrm_func_cfg_input *req;
498 	int rc;
499 
500 	req = __bnge_hwrm_reserve_pf_rings(bd, hwr);
501 	if (!req)
502 		return -ENOMEM;
503 
504 	if (!req->enables) {
505 		bnge_hwrm_req_drop(bd, req);
506 		return 0;
507 	}
508 
509 	rc = bnge_hwrm_req_send(bd, req);
510 	if (rc)
511 		return rc;
512 
513 	return bnge_hwrm_get_rings(bd);
514 }
515 
bnge_hwrm_reserve_rings(struct bnge_dev * bd,struct bnge_hw_rings * hwr)516 int bnge_hwrm_reserve_rings(struct bnge_dev *bd, struct bnge_hw_rings *hwr)
517 {
518 	return bnge_hwrm_reserve_pf_rings(bd, hwr);
519 }
520 
bnge_hwrm_func_qcfg(struct bnge_dev * bd)521 int bnge_hwrm_func_qcfg(struct bnge_dev *bd)
522 {
523 	struct hwrm_func_qcfg_output *resp;
524 	struct hwrm_func_qcfg_input *req;
525 	int rc;
526 
527 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_QCFG);
528 	if (rc)
529 		return rc;
530 
531 	req->fid = cpu_to_le16(0xffff);
532 	resp = bnge_hwrm_req_hold(bd, req);
533 	rc = bnge_hwrm_req_send(bd, req);
534 	if (rc)
535 		goto func_qcfg_exit;
536 
537 	bd->max_mtu = le16_to_cpu(resp->max_mtu_configured);
538 	if (!bd->max_mtu)
539 		bd->max_mtu = BNGE_MAX_MTU;
540 
541 	if (bd->db_size)
542 		goto func_qcfg_exit;
543 
544 	bd->db_offset = le16_to_cpu(resp->legacy_l2_db_size_kb) * 1024;
545 	bd->db_size = PAGE_ALIGN(le16_to_cpu(resp->l2_doorbell_bar_size_kb) *
546 			1024);
547 	if (!bd->db_size || bd->db_size > pci_resource_len(bd->pdev, 2) ||
548 	    bd->db_size <= bd->db_offset)
549 		bd->db_size = pci_resource_len(bd->pdev, 2);
550 
551 func_qcfg_exit:
552 	bnge_hwrm_req_drop(bd, req);
553 	return rc;
554 }
555 
bnge_hwrm_func_resc_qcaps(struct bnge_dev * bd)556 int bnge_hwrm_func_resc_qcaps(struct bnge_dev *bd)
557 {
558 	struct hwrm_func_resource_qcaps_output *resp;
559 	struct bnge_hw_resc *hw_resc = &bd->hw_resc;
560 	struct hwrm_func_resource_qcaps_input *req;
561 	int rc;
562 
563 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_RESOURCE_QCAPS);
564 	if (rc)
565 		return rc;
566 
567 	req->fid = cpu_to_le16(0xffff);
568 	resp = bnge_hwrm_req_hold(bd, req);
569 	rc = bnge_hwrm_req_send_silent(bd, req);
570 	if (rc)
571 		goto hwrm_func_resc_qcaps_exit;
572 
573 	hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs);
574 	hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx);
575 	hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
576 	hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings);
577 	hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
578 	hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings);
579 	hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
580 	hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings);
581 	hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings);
582 	hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps);
583 	hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps);
584 	hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs);
585 	hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs);
586 	hw_resc->min_vnics = le16_to_cpu(resp->min_vnics);
587 	hw_resc->max_vnics = le16_to_cpu(resp->max_vnics);
588 	hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx);
589 	hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx);
590 
591 	hw_resc->max_nqs = le16_to_cpu(resp->max_msix);
592 	hw_resc->max_hw_ring_grps = hw_resc->max_rx_rings;
593 
594 hwrm_func_resc_qcaps_exit:
595 	bnge_hwrm_req_drop(bd, req);
596 	return rc;
597 }
598 
bnge_hwrm_func_qcaps(struct bnge_dev * bd)599 int bnge_hwrm_func_qcaps(struct bnge_dev *bd)
600 {
601 	struct hwrm_func_qcaps_output *resp;
602 	struct hwrm_func_qcaps_input *req;
603 	struct bnge_pf_info *pf = &bd->pf;
604 	u32 flags, flags_ext;
605 	int rc;
606 
607 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_QCAPS);
608 	if (rc)
609 		return rc;
610 
611 	req->fid = cpu_to_le16(0xffff);
612 	resp = bnge_hwrm_req_hold(bd, req);
613 	rc = bnge_hwrm_req_send(bd, req);
614 	if (rc)
615 		goto hwrm_func_qcaps_exit;
616 
617 	flags = le32_to_cpu(resp->flags);
618 	if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED)
619 		bd->flags |= BNGE_EN_ROCE_V1;
620 	if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED)
621 		bd->flags |= BNGE_EN_ROCE_V2;
622 	if (flags & FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED)
623 		bd->fw_cap |= BNGE_FW_CAP_EXT_STATS_SUPPORTED;
624 
625 	flags_ext = le32_to_cpu(resp->flags_ext);
626 	if (flags_ext & FUNC_QCAPS_RESP_FLAGS_EXT_EXT_HW_STATS_SUPPORTED)
627 		bd->fw_cap |= BNGE_FW_CAP_EXT_HW_STATS_SUPPORTED;
628 
629 	pf->fw_fid = le16_to_cpu(resp->fid);
630 	pf->port_id = le16_to_cpu(resp->port_id);
631 	memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN);
632 
633 	bd->tso_max_segs = le16_to_cpu(resp->max_tso_segs);
634 
635 hwrm_func_qcaps_exit:
636 	bnge_hwrm_req_drop(bd, req);
637 	return rc;
638 }
639 
bnge_hwrm_vnic_qcaps(struct bnge_dev * bd)640 int bnge_hwrm_vnic_qcaps(struct bnge_dev *bd)
641 {
642 	struct hwrm_vnic_qcaps_output *resp;
643 	struct hwrm_vnic_qcaps_input *req;
644 	int rc;
645 
646 	bd->hw_ring_stats_size = sizeof(struct ctx_hw_stats);
647 	bd->rss_cap &= ~BNGE_RSS_CAP_NEW_RSS_CAP;
648 
649 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_QCAPS);
650 	if (rc)
651 		return rc;
652 
653 	resp = bnge_hwrm_req_hold(bd, req);
654 	rc = bnge_hwrm_req_send(bd, req);
655 	if (!rc) {
656 		u32 flags = le32_to_cpu(resp->flags);
657 
658 		if (flags & VNIC_QCAPS_RESP_FLAGS_VLAN_STRIP_CAP)
659 			bd->fw_cap |= BNGE_FW_CAP_VLAN_RX_STRIP;
660 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_HASH_TYPE_DELTA_CAP)
661 			bd->rss_cap |= BNGE_RSS_CAP_RSS_HASH_TYPE_DELTA;
662 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_PROF_TCAM_MODE_ENABLED)
663 			bd->rss_cap |= BNGE_RSS_CAP_RSS_TCAM;
664 		bd->max_tpa_v2 = le16_to_cpu(resp->max_aggs_supported);
665 		if (bd->max_tpa_v2)
666 			bd->hw_ring_stats_size = BNGE_RING_STATS_SIZE;
667 		if (flags & VNIC_QCAPS_RESP_FLAGS_HW_TUNNEL_TPA_CAP)
668 			bd->fw_cap |= BNGE_FW_CAP_VNIC_TUNNEL_TPA;
669 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_AH_SPI_IPV4_CAP)
670 			bd->rss_cap |= BNGE_RSS_CAP_AH_V4_RSS_CAP;
671 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_AH_SPI_IPV6_CAP)
672 			bd->rss_cap |= BNGE_RSS_CAP_AH_V6_RSS_CAP;
673 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_ESP_SPI_IPV4_CAP)
674 			bd->rss_cap |= BNGE_RSS_CAP_ESP_V4_RSS_CAP;
675 		if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_IPSEC_ESP_SPI_IPV6_CAP)
676 			bd->rss_cap |= BNGE_RSS_CAP_ESP_V6_RSS_CAP;
677 	}
678 	bnge_hwrm_req_drop(bd, req);
679 
680 	return rc;
681 }
682 
683 #define BNGE_CNPQ(q_profile)	\
684 		((q_profile) ==	\
685 		 QUEUE_QPORTCFG_RESP_QUEUE_ID0_SERVICE_PROFILE_LOSSY_ROCE_CNP)
686 
bnge_hwrm_queue_qportcfg(struct bnge_dev * bd)687 int bnge_hwrm_queue_qportcfg(struct bnge_dev *bd)
688 {
689 	struct hwrm_queue_qportcfg_output *resp;
690 	struct hwrm_queue_qportcfg_input *req;
691 	u8 i, j, *qptr;
692 	bool no_rdma;
693 	int rc;
694 
695 	rc = bnge_hwrm_req_init(bd, req, HWRM_QUEUE_QPORTCFG);
696 	if (rc)
697 		return rc;
698 
699 	resp = bnge_hwrm_req_hold(bd, req);
700 	rc = bnge_hwrm_req_send(bd, req);
701 	if (rc)
702 		goto qportcfg_exit;
703 
704 	if (!resp->max_configurable_queues) {
705 		rc = -EINVAL;
706 		goto qportcfg_exit;
707 	}
708 	bd->max_tc = resp->max_configurable_queues;
709 	bd->max_lltc = resp->max_configurable_lossless_queues;
710 	if (bd->max_tc > BNGE_MAX_QUEUE)
711 		bd->max_tc = BNGE_MAX_QUEUE;
712 
713 	no_rdma = !bnge_is_roce_en(bd);
714 	qptr = &resp->queue_id0;
715 	for (i = 0, j = 0; i < bd->max_tc; i++) {
716 		bd->q_info[j].queue_id = *qptr;
717 		bd->q_ids[i] = *qptr++;
718 		bd->q_info[j].queue_profile = *qptr++;
719 		bd->tc_to_qidx[j] = j;
720 		if (!BNGE_CNPQ(bd->q_info[j].queue_profile) || no_rdma)
721 			j++;
722 	}
723 	bd->max_q = bd->max_tc;
724 	bd->max_tc = max_t(u8, j, 1);
725 
726 	if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG)
727 		bd->max_tc = 1;
728 
729 	if (bd->max_lltc > bd->max_tc)
730 		bd->max_lltc = bd->max_tc;
731 
732 qportcfg_exit:
733 	bnge_hwrm_req_drop(bd, req);
734 	return rc;
735 }
736 
bnge_hwrm_vnic_set_hds(struct bnge_net * bn,struct bnge_vnic_info * vnic)737 int bnge_hwrm_vnic_set_hds(struct bnge_net *bn, struct bnge_vnic_info *vnic)
738 {
739 	u16 hds_thresh = (u16)bn->netdev->cfg_pending->hds_thresh;
740 	struct hwrm_vnic_plcmodes_cfg_input *req;
741 	struct bnge_dev *bd = bn->bd;
742 	int rc;
743 
744 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_PLCMODES_CFG);
745 	if (rc)
746 		return rc;
747 
748 	req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
749 	req->enables = cpu_to_le32(BNGE_PLC_EN_JUMBO_THRES_VALID);
750 	req->jumbo_thresh = cpu_to_le16(bn->rx_buf_use_size);
751 
752 	if (bnge_is_agg_reqd(bd)) {
753 		req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
754 					  VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
755 		req->enables |=
756 			cpu_to_le32(BNGE_PLC_EN_HDS_THRES_VALID);
757 		req->hds_threshold = cpu_to_le16(hds_thresh);
758 	}
759 	req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
760 	return bnge_hwrm_req_send(bd, req);
761 }
762 
bnge_hwrm_vnic_ctx_alloc(struct bnge_dev * bd,struct bnge_vnic_info * vnic,u16 ctx_idx)763 int bnge_hwrm_vnic_ctx_alloc(struct bnge_dev *bd,
764 			     struct bnge_vnic_info *vnic, u16 ctx_idx)
765 {
766 	struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp;
767 	struct hwrm_vnic_rss_cos_lb_ctx_alloc_input *req;
768 	int rc;
769 
770 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC);
771 	if (rc)
772 		return rc;
773 
774 	resp = bnge_hwrm_req_hold(bd, req);
775 	rc = bnge_hwrm_req_send(bd, req);
776 	if (!rc)
777 		vnic->fw_rss_cos_lb_ctx[ctx_idx] =
778 			le16_to_cpu(resp->rss_cos_lb_ctx_id);
779 	bnge_hwrm_req_drop(bd, req);
780 
781 	return rc;
782 }
783 
784 static void
__bnge_hwrm_vnic_set_rss(struct bnge_net * bn,struct hwrm_vnic_rss_cfg_input * req,struct bnge_vnic_info * vnic)785 __bnge_hwrm_vnic_set_rss(struct bnge_net *bn,
786 			 struct hwrm_vnic_rss_cfg_input *req,
787 			 struct bnge_vnic_info *vnic)
788 {
789 	struct bnge_dev *bd = bn->bd;
790 
791 	bnge_fill_hw_rss_tbl(bn, vnic);
792 	req->flags |= VNIC_RSS_CFG_REQ_FLAGS_IPSEC_HASH_TYPE_CFG_SUPPORT;
793 
794 	req->hash_type = cpu_to_le32(bd->rss_hash_cfg);
795 	req->hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT;
796 	req->ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr);
797 	req->hash_key_tbl_addr = cpu_to_le64(vnic->rss_hash_key_dma_addr);
798 }
799 
bnge_hwrm_vnic_set_rss(struct bnge_net * bn,struct bnge_vnic_info * vnic,bool set_rss)800 int bnge_hwrm_vnic_set_rss(struct bnge_net *bn,
801 			   struct bnge_vnic_info *vnic, bool set_rss)
802 {
803 	struct hwrm_vnic_rss_cfg_input *req;
804 	struct bnge_dev *bd = bn->bd;
805 	dma_addr_t ring_tbl_map;
806 	u32 i, nr_ctxs;
807 	int rc;
808 
809 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_RSS_CFG);
810 	if (rc)
811 		return rc;
812 
813 	req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
814 	if (!set_rss)
815 		return bnge_hwrm_req_send(bd, req);
816 
817 	__bnge_hwrm_vnic_set_rss(bn, req, vnic);
818 	ring_tbl_map = vnic->rss_table_dma_addr;
819 	nr_ctxs = bnge_cal_nr_rss_ctxs(bd->rx_nr_rings);
820 
821 	bnge_hwrm_req_hold(bd, req);
822 	for (i = 0; i < nr_ctxs; ring_tbl_map += BNGE_RSS_TABLE_SIZE, i++) {
823 		req->ring_grp_tbl_addr = cpu_to_le64(ring_tbl_map);
824 		req->ring_table_pair_index = i;
825 		req->rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[i]);
826 		rc = bnge_hwrm_req_send(bd, req);
827 		if (rc)
828 			goto exit;
829 	}
830 
831 exit:
832 	bnge_hwrm_req_drop(bd, req);
833 	return rc;
834 }
835 
bnge_hwrm_vnic_cfg(struct bnge_net * bn,struct bnge_vnic_info * vnic)836 int bnge_hwrm_vnic_cfg(struct bnge_net *bn, struct bnge_vnic_info *vnic)
837 {
838 	struct bnge_rx_ring_info *rxr = &bn->rx_ring[0];
839 	struct hwrm_vnic_cfg_input *req;
840 	struct bnge_dev *bd = bn->bd;
841 	int rc;
842 
843 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_CFG);
844 	if (rc)
845 		return rc;
846 
847 	req->default_rx_ring_id =
848 		cpu_to_le16(rxr->rx_ring_struct.fw_ring_id);
849 	req->default_cmpl_ring_id =
850 		cpu_to_le16(bnge_cp_ring_for_rx(rxr));
851 	req->enables =
852 		cpu_to_le32(VNIC_CFG_REQ_ENABLES_DEFAULT_RX_RING_ID |
853 			    VNIC_CFG_REQ_ENABLES_DEFAULT_CMPL_RING_ID);
854 	vnic->mru = bd->netdev->mtu + ETH_HLEN + VLAN_HLEN;
855 	req->mru = cpu_to_le16(vnic->mru);
856 
857 	req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
858 
859 	if (bd->flags & BNGE_EN_STRIP_VLAN)
860 		req->flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE);
861 	if (vnic->vnic_id == BNGE_VNIC_DEFAULT && bnge_aux_registered(bd))
862 		req->flags |= cpu_to_le32(BNGE_VNIC_CFG_ROCE_DUAL_MODE);
863 
864 	return bnge_hwrm_req_send(bd, req);
865 }
866 
bnge_hwrm_update_rss_hash_cfg(struct bnge_net * bn)867 void bnge_hwrm_update_rss_hash_cfg(struct bnge_net *bn)
868 {
869 	struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT];
870 	struct hwrm_vnic_rss_qcfg_output *resp;
871 	struct hwrm_vnic_rss_qcfg_input *req;
872 	struct bnge_dev *bd = bn->bd;
873 
874 	if (bnge_hwrm_req_init(bd, req, HWRM_VNIC_RSS_QCFG))
875 		return;
876 
877 	req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
878 	/* all contexts configured to same hash_type, zero always exists */
879 	req->rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]);
880 	resp = bnge_hwrm_req_hold(bd, req);
881 	if (!bnge_hwrm_req_send(bd, req))
882 		bd->rss_hash_cfg =
883 			le32_to_cpu(resp->hash_type) ?: bd->rss_hash_cfg;
884 	bnge_hwrm_req_drop(bd, req);
885 }
886 
bnge_hwrm_l2_filter_free(struct bnge_dev * bd,struct bnge_l2_filter * fltr)887 int bnge_hwrm_l2_filter_free(struct bnge_dev *bd, struct bnge_l2_filter *fltr)
888 {
889 	struct hwrm_cfa_l2_filter_free_input *req;
890 	int rc;
891 
892 	rc = bnge_hwrm_req_init(bd, req, HWRM_CFA_L2_FILTER_FREE);
893 	if (rc)
894 		return rc;
895 
896 	req->l2_filter_id = fltr->base.filter_id;
897 	return bnge_hwrm_req_send(bd, req);
898 }
899 
bnge_hwrm_l2_filter_alloc(struct bnge_dev * bd,struct bnge_l2_filter * fltr)900 int bnge_hwrm_l2_filter_alloc(struct bnge_dev *bd, struct bnge_l2_filter *fltr)
901 {
902 	struct hwrm_cfa_l2_filter_alloc_output *resp;
903 	struct hwrm_cfa_l2_filter_alloc_input *req;
904 	int rc;
905 
906 	rc = bnge_hwrm_req_init(bd, req, HWRM_CFA_L2_FILTER_ALLOC);
907 	if (rc)
908 		return rc;
909 
910 	req->flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX);
911 
912 	req->flags |= cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST);
913 	req->dst_id = cpu_to_le16(fltr->base.fw_vnic_id);
914 	req->enables =
915 		cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR |
916 			    CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID |
917 			    CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK);
918 	ether_addr_copy(req->l2_addr, fltr->l2_key.dst_mac_addr);
919 	eth_broadcast_addr(req->l2_addr_mask);
920 
921 	if (fltr->l2_key.vlan) {
922 		req->enables |=
923 			cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_IVLAN |
924 				CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_IVLAN_MASK |
925 				CFA_L2_FILTER_ALLOC_REQ_ENABLES_NUM_VLANS);
926 		req->num_vlans = 1;
927 		req->l2_ivlan = cpu_to_le16(fltr->l2_key.vlan);
928 		req->l2_ivlan_mask = cpu_to_le16(0xfff);
929 	}
930 
931 	resp = bnge_hwrm_req_hold(bd, req);
932 	rc = bnge_hwrm_req_send(bd, req);
933 	if (!rc)
934 		fltr->base.filter_id = resp->l2_filter_id;
935 
936 	bnge_hwrm_req_drop(bd, req);
937 	return rc;
938 }
939 
bnge_hwrm_cfa_l2_set_rx_mask(struct bnge_dev * bd,struct bnge_vnic_info * vnic)940 int bnge_hwrm_cfa_l2_set_rx_mask(struct bnge_dev *bd,
941 				 struct bnge_vnic_info *vnic)
942 {
943 	struct hwrm_cfa_l2_set_rx_mask_input *req;
944 	int rc;
945 
946 	rc = bnge_hwrm_req_init(bd, req, HWRM_CFA_L2_SET_RX_MASK);
947 	if (rc)
948 		return rc;
949 
950 	req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
951 	if (vnic->rx_mask & CFA_L2_SET_RX_MASK_REQ_MASK_MCAST) {
952 		req->num_mc_entries = cpu_to_le32(vnic->mc_list_count);
953 		req->mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping);
954 	}
955 	req->mask = cpu_to_le32(vnic->rx_mask);
956 	return bnge_hwrm_req_send_silent(bd, req);
957 }
958 
bnge_hwrm_vnic_alloc(struct bnge_dev * bd,struct bnge_vnic_info * vnic,unsigned int nr_rings)959 int bnge_hwrm_vnic_alloc(struct bnge_dev *bd, struct bnge_vnic_info *vnic,
960 			 unsigned int nr_rings)
961 {
962 	struct hwrm_vnic_alloc_output *resp;
963 	struct hwrm_vnic_alloc_input *req;
964 	unsigned int i;
965 	int rc;
966 
967 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_ALLOC);
968 	if (rc)
969 		return rc;
970 
971 	for (i = 0; i < BNGE_MAX_CTX_PER_VNIC; i++)
972 		vnic->fw_rss_cos_lb_ctx[i] = INVALID_HW_RING_ID;
973 	if (vnic->vnic_id == BNGE_VNIC_DEFAULT)
974 		req->flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT);
975 
976 	resp = bnge_hwrm_req_hold(bd, req);
977 	rc = bnge_hwrm_req_send(bd, req);
978 	if (!rc)
979 		vnic->fw_vnic_id = le32_to_cpu(resp->vnic_id);
980 	bnge_hwrm_req_drop(bd, req);
981 	return rc;
982 }
983 
bnge_hwrm_vnic_free_one(struct bnge_dev * bd,struct bnge_vnic_info * vnic)984 void bnge_hwrm_vnic_free_one(struct bnge_dev *bd, struct bnge_vnic_info *vnic)
985 {
986 	if (vnic->fw_vnic_id != INVALID_HW_RING_ID) {
987 		struct hwrm_vnic_free_input *req;
988 
989 		if (bnge_hwrm_req_init(bd, req, HWRM_VNIC_FREE))
990 			return;
991 
992 		req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
993 
994 		bnge_hwrm_req_send(bd, req);
995 		vnic->fw_vnic_id = INVALID_HW_RING_ID;
996 	}
997 }
998 
bnge_hwrm_vnic_ctx_free_one(struct bnge_dev * bd,struct bnge_vnic_info * vnic,u16 ctx_idx)999 void bnge_hwrm_vnic_ctx_free_one(struct bnge_dev *bd,
1000 				 struct bnge_vnic_info *vnic, u16 ctx_idx)
1001 {
1002 	struct hwrm_vnic_rss_cos_lb_ctx_free_input *req;
1003 
1004 	if (bnge_hwrm_req_init(bd, req, HWRM_VNIC_RSS_COS_LB_CTX_FREE))
1005 		return;
1006 
1007 	req->rss_cos_lb_ctx_id =
1008 		cpu_to_le16(vnic->fw_rss_cos_lb_ctx[ctx_idx]);
1009 
1010 	bnge_hwrm_req_send(bd, req);
1011 	vnic->fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID;
1012 }
1013 
bnge_phy_qcaps_no_speed(struct hwrm_port_phy_qcaps_output * resp)1014 static bool bnge_phy_qcaps_no_speed(struct hwrm_port_phy_qcaps_output *resp)
1015 {
1016 	return !resp->supported_speeds2_auto_mode &&
1017 	       !resp->supported_speeds2_force_mode;
1018 }
1019 
bnge_hwrm_phy_qcaps(struct bnge_dev * bd)1020 int bnge_hwrm_phy_qcaps(struct bnge_dev *bd)
1021 {
1022 	struct bnge_link_info *link_info = &bd->link_info;
1023 	struct hwrm_port_phy_qcaps_output *resp;
1024 	struct hwrm_port_phy_qcaps_input *req;
1025 	int rc;
1026 
1027 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_PHY_QCAPS);
1028 	if (rc)
1029 		return rc;
1030 
1031 	resp = bnge_hwrm_req_hold(bd, req);
1032 	rc = bnge_hwrm_req_send(bd, req);
1033 	if (rc)
1034 		goto hwrm_phy_qcaps_exit;
1035 
1036 	bd->phy_flags = resp->flags |
1037 		       (le16_to_cpu(resp->flags2) << BNGE_PHY_FLAGS2_SHIFT);
1038 
1039 	if (bnge_phy_qcaps_no_speed(resp)) {
1040 		link_info->phy_enabled = false;
1041 		netdev_warn(bd->netdev, "Ethernet link disabled\n");
1042 	} else if (!link_info->phy_enabled) {
1043 		link_info->phy_enabled = true;
1044 		netdev_info(bd->netdev, "Ethernet link enabled\n");
1045 		/* Phy re-enabled, reprobe the speeds */
1046 		link_info->support_auto_speeds2 = 0;
1047 	}
1048 
1049 	/* Firmware may report 0 for autoneg supported speeds when no
1050 	 * SFP module is present. Skip the update to preserve the
1051 	 * current supported speeds -- storing 0 would cause autoneg
1052 	 * default fallback to advertise nothing.
1053 	 */
1054 	if (resp->supported_speeds2_auto_mode)
1055 		link_info->support_auto_speeds2 =
1056 			le16_to_cpu(resp->supported_speeds2_auto_mode);
1057 
1058 	bd->port_count = resp->port_cnt;
1059 
1060 hwrm_phy_qcaps_exit:
1061 	bnge_hwrm_req_drop(bd, req);
1062 	return rc;
1063 }
1064 
bnge_hwrm_set_link_setting(struct bnge_net * bn,bool set_pause)1065 int bnge_hwrm_set_link_setting(struct bnge_net *bn, bool set_pause)
1066 {
1067 	struct hwrm_port_phy_cfg_input *req;
1068 	struct bnge_dev *bd = bn->bd;
1069 	int rc;
1070 
1071 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_PHY_CFG);
1072 	if (rc)
1073 		return rc;
1074 
1075 	if (set_pause)
1076 		bnge_hwrm_set_pause_common(bn, req);
1077 
1078 	bnge_hwrm_set_link_common(bn, req);
1079 
1080 	rc = bnge_hwrm_req_send(bd, req);
1081 	if (!rc)
1082 		bn->eth_link_info.force_link_chng = false;
1083 
1084 	return rc;
1085 }
1086 
bnge_update_link(struct bnge_net * bn,bool chng_link_state)1087 int bnge_update_link(struct bnge_net *bn, bool chng_link_state)
1088 {
1089 	struct hwrm_port_phy_qcfg_output *resp;
1090 	struct hwrm_port_phy_qcfg_input *req;
1091 	struct bnge_link_info *link_info;
1092 	struct bnge_dev *bd = bn->bd;
1093 	bool support_changed;
1094 	u8 link_state;
1095 	int rc;
1096 
1097 	link_info = &bd->link_info;
1098 	link_state = link_info->link_state;
1099 
1100 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_PHY_QCFG);
1101 	if (rc)
1102 		return rc;
1103 
1104 	resp = bnge_hwrm_req_hold(bd, req);
1105 	rc = bnge_hwrm_req_send(bd, req);
1106 	if (rc) {
1107 		bnge_hwrm_req_drop(bd, req);
1108 		return rc;
1109 	}
1110 
1111 	memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp));
1112 	link_info->phy_link_status = resp->link;
1113 	link_info->duplex = resp->duplex_state;
1114 	link_info->pause = resp->pause;
1115 	link_info->auto_mode = resp->auto_mode;
1116 	link_info->auto_pause_setting = resp->auto_pause;
1117 	link_info->lp_pause = resp->link_partner_adv_pause;
1118 	link_info->force_pause_setting = resp->force_pause;
1119 	link_info->duplex_setting = resp->duplex_cfg;
1120 	if (link_info->phy_link_status == BNGE_LINK_LINK) {
1121 		link_info->link_speed = le16_to_cpu(resp->link_speed);
1122 		link_info->active_lanes = resp->active_lanes;
1123 	} else {
1124 		link_info->link_speed = 0;
1125 		link_info->active_lanes = 0;
1126 	}
1127 	link_info->force_link_speed2 = le16_to_cpu(resp->force_link_speeds2);
1128 	link_info->support_speeds2 = le16_to_cpu(resp->support_speeds2);
1129 	link_info->auto_link_speeds2 = le16_to_cpu(resp->auto_link_speeds2);
1130 	link_info->lp_auto_link_speeds =
1131 		le16_to_cpu(resp->link_partner_adv_speeds);
1132 	link_info->media_type = resp->media_type;
1133 	link_info->phy_type = resp->phy_type;
1134 	link_info->phy_addr = resp->eee_config_phy_addr &
1135 			      PORT_PHY_QCFG_RESP_PHY_ADDR_MASK;
1136 	link_info->module_status = resp->module_status;
1137 
1138 	link_info->fec_cfg = le16_to_cpu(resp->fec_cfg);
1139 	link_info->active_fec_sig_mode = resp->active_fec_signal_mode;
1140 
1141 	if (chng_link_state) {
1142 		if (link_info->phy_link_status == BNGE_LINK_LINK)
1143 			link_info->link_state = BNGE_LINK_STATE_UP;
1144 		else
1145 			link_info->link_state = BNGE_LINK_STATE_DOWN;
1146 		if (link_state != link_info->link_state)
1147 			bnge_report_link(bd);
1148 	} else {
1149 		/* always link down if not required to update link state */
1150 		link_info->link_state = BNGE_LINK_STATE_DOWN;
1151 	}
1152 	bnge_hwrm_req_drop(bd, req);
1153 
1154 	if (!BNGE_PHY_CFG_ABLE(bd))
1155 		return 0;
1156 
1157 	support_changed = bnge_support_speed_dropped(bn);
1158 	if (support_changed && (bn->eth_link_info.autoneg & BNGE_AUTONEG_SPEED))
1159 		rc = bnge_hwrm_set_link_setting(bn, true);
1160 	return rc;
1161 }
1162 
bnge_hwrm_set_pause(struct bnge_net * bn)1163 int bnge_hwrm_set_pause(struct bnge_net *bn)
1164 {
1165 	struct bnge_ethtool_link_info *elink_info = &bn->eth_link_info;
1166 	struct hwrm_port_phy_cfg_input *req;
1167 	struct bnge_dev *bd = bn->bd;
1168 	bool pause_autoneg;
1169 	int rc;
1170 
1171 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_PHY_CFG);
1172 	if (rc)
1173 		return rc;
1174 
1175 	pause_autoneg = !!(elink_info->autoneg & BNGE_AUTONEG_FLOW_CTRL);
1176 
1177 	/* Prepare PHY pause-advertisement or forced-pause settings. */
1178 	bnge_hwrm_set_pause_common(bn, req);
1179 
1180 	/* Prepare speed/autoneg settings */
1181 	if (pause_autoneg || elink_info->force_link_chng)
1182 		bnge_hwrm_set_link_common(bn, req);
1183 
1184 	rc = bnge_hwrm_req_send(bd, req);
1185 	if (!rc && !pause_autoneg) {
1186 		/* Since changing of pause setting, with pause autoneg off,
1187 		 * doesn't trigger any link change event, the driver needs to
1188 		 * update the current MAC pause upon successful return of the
1189 		 * phy_cfg command.
1190 		 */
1191 		bd->link_info.force_pause_setting =
1192 		bd->link_info.pause = elink_info->req_flow_ctrl;
1193 		bd->link_info.auto_pause_setting = 0;
1194 		if (!elink_info->force_link_chng)
1195 			bnge_report_link(bd);
1196 	}
1197 	if (!rc)
1198 		elink_info->force_link_chng = false;
1199 
1200 	return rc;
1201 }
1202 
bnge_hwrm_shutdown_link(struct bnge_dev * bd)1203 int bnge_hwrm_shutdown_link(struct bnge_dev *bd)
1204 {
1205 	struct hwrm_port_phy_cfg_input *req;
1206 	int rc;
1207 
1208 	if (!BNGE_PHY_CFG_ABLE(bd))
1209 		return 0;
1210 
1211 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_PHY_CFG);
1212 	if (rc)
1213 		return rc;
1214 
1215 	req->flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN);
1216 	rc = bnge_hwrm_req_send(bd, req);
1217 	if (!rc) {
1218 		/* Device is not obliged to link down in certain scenarios,
1219 		 * even when forced. Setting the state unknown is consistent
1220 		 * with driver startup and will force link state to be
1221 		 * reported during subsequent open based on PORT_PHY_QCFG.
1222 		 */
1223 		bd->link_info.link_state = BNGE_LINK_STATE_UNKNOWN;
1224 	}
1225 	return rc;
1226 }
1227 
bnge_hwrm_stat_ctx_free(struct bnge_net * bn)1228 void bnge_hwrm_stat_ctx_free(struct bnge_net *bn)
1229 {
1230 	struct hwrm_stat_ctx_free_input *req;
1231 	struct bnge_dev *bd = bn->bd;
1232 	int i;
1233 
1234 	if (bnge_hwrm_req_init(bd, req, HWRM_STAT_CTX_FREE))
1235 		return;
1236 
1237 	bnge_hwrm_req_hold(bd, req);
1238 	for (i = 0; i < bd->nq_nr_rings; i++) {
1239 		struct bnge_napi *bnapi = bn->bnapi[i];
1240 		struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
1241 
1242 		if (nqr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) {
1243 			req->stat_ctx_id = cpu_to_le32(nqr->hw_stats_ctx_id);
1244 			bnge_hwrm_req_send(bd, req);
1245 
1246 			nqr->hw_stats_ctx_id = INVALID_STATS_CTX_ID;
1247 		}
1248 	}
1249 	bnge_hwrm_req_drop(bd, req);
1250 }
1251 
bnge_hwrm_stat_ctx_alloc(struct bnge_net * bn)1252 int bnge_hwrm_stat_ctx_alloc(struct bnge_net *bn)
1253 {
1254 	struct hwrm_stat_ctx_alloc_output *resp;
1255 	struct hwrm_stat_ctx_alloc_input *req;
1256 	struct bnge_dev *bd = bn->bd;
1257 	int rc, i;
1258 
1259 	rc = bnge_hwrm_req_init(bd, req, HWRM_STAT_CTX_ALLOC);
1260 	if (rc)
1261 		return rc;
1262 
1263 	req->stats_dma_length = cpu_to_le16(bd->hw_ring_stats_size);
1264 	req->update_period_ms = cpu_to_le32(bn->stats_coal_ticks / 1000);
1265 
1266 	resp = bnge_hwrm_req_hold(bd, req);
1267 	for (i = 0; i < bd->nq_nr_rings; i++) {
1268 		struct bnge_napi *bnapi = bn->bnapi[i];
1269 		struct bnge_nq_ring_info *nqr = &bnapi->nq_ring;
1270 
1271 		req->stats_dma_addr = cpu_to_le64(nqr->stats.hw_stats_map);
1272 
1273 		rc = bnge_hwrm_req_send(bd, req);
1274 		if (rc)
1275 			break;
1276 
1277 		nqr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id);
1278 		bn->grp_info[i].fw_stats_ctx = nqr->hw_stats_ctx_id;
1279 	}
1280 	bnge_hwrm_req_drop(bd, req);
1281 	return rc;
1282 }
1283 
hwrm_ring_free_send_msg(struct bnge_net * bn,struct bnge_ring_struct * ring,u32 ring_type,u32 cmpl_ring_id)1284 int hwrm_ring_free_send_msg(struct bnge_net *bn,
1285 			    struct bnge_ring_struct *ring,
1286 			    u32 ring_type, u32 cmpl_ring_id)
1287 {
1288 	struct hwrm_ring_free_input *req;
1289 	struct bnge_dev *bd = bn->bd;
1290 	int rc;
1291 
1292 	rc = bnge_hwrm_req_init(bd, req, HWRM_RING_FREE);
1293 	if (rc)
1294 		goto exit;
1295 
1296 	req->cmpl_ring = cpu_to_le16(cmpl_ring_id);
1297 	req->ring_type = ring_type;
1298 	req->ring_id = cpu_to_le32(ring->fw_ring_id);
1299 
1300 	bnge_hwrm_req_hold(bd, req);
1301 	rc = bnge_hwrm_req_send(bd, req);
1302 	bnge_hwrm_req_drop(bd, req);
1303 exit:
1304 	if (rc) {
1305 		netdev_err(bd->netdev, "hwrm_ring_free type %d failed. rc:%d\n", ring_type, rc);
1306 		return -EIO;
1307 	}
1308 	return 0;
1309 }
1310 
hwrm_ring_alloc_send_msg(struct bnge_net * bn,struct bnge_ring_struct * ring,u32 ring_type,u32 map_index)1311 int hwrm_ring_alloc_send_msg(struct bnge_net *bn,
1312 			     struct bnge_ring_struct *ring,
1313 			     u32 ring_type, u32 map_index)
1314 {
1315 	struct bnge_ring_mem_info *rmem = &ring->ring_mem;
1316 	struct bnge_ring_grp_info *grp_info;
1317 	struct hwrm_ring_alloc_output *resp;
1318 	struct hwrm_ring_alloc_input *req;
1319 	struct bnge_dev *bd = bn->bd;
1320 	u32 ring_id, flags = 0;
1321 	int rc;
1322 
1323 	rc = bnge_hwrm_req_init(bd, req, HWRM_RING_ALLOC);
1324 	if (rc)
1325 		goto exit;
1326 
1327 	req->enables = 0;
1328 	if (rmem->nr_pages > 1) {
1329 		req->page_tbl_addr = cpu_to_le64(rmem->dma_pg_tbl);
1330 		/* Page size is in log2 units */
1331 		req->page_size = BNGE_PAGE_SHIFT;
1332 		req->page_tbl_depth = 1;
1333 	} else {
1334 		req->page_tbl_addr =  cpu_to_le64(rmem->dma_arr[0]);
1335 	}
1336 	req->fbo = 0;
1337 	/* Association of ring index with doorbell index and MSIX number */
1338 	req->logical_id = cpu_to_le16(map_index);
1339 
1340 	switch (ring_type) {
1341 	case HWRM_RING_ALLOC_TX: {
1342 		struct bnge_tx_ring_info *txr;
1343 
1344 		txr = container_of(ring, struct bnge_tx_ring_info,
1345 				   tx_ring_struct);
1346 		req->ring_type = RING_ALLOC_REQ_RING_TYPE_TX;
1347 		/* Association of transmit ring with completion ring */
1348 		grp_info = &bn->grp_info[ring->grp_idx];
1349 		req->cmpl_ring_id = cpu_to_le16(bnge_cp_ring_for_tx(txr));
1350 		req->length = cpu_to_le32(bn->tx_ring_mask + 1);
1351 		req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
1352 		req->queue_id = cpu_to_le16(ring->queue_id);
1353 		req->flags = cpu_to_le16(flags);
1354 		break;
1355 	}
1356 	case HWRM_RING_ALLOC_RX:
1357 		req->ring_type = RING_ALLOC_REQ_RING_TYPE_RX;
1358 		req->length = cpu_to_le32(bn->rx_ring_mask + 1);
1359 
1360 		/* Association of rx ring with stats context */
1361 		grp_info = &bn->grp_info[ring->grp_idx];
1362 		req->rx_buf_size = cpu_to_le16(bn->rx_buf_use_size);
1363 		req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
1364 		req->enables |=
1365 			cpu_to_le32(RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
1366 		if (NET_IP_ALIGN == 2)
1367 			flags = RING_ALLOC_REQ_FLAGS_RX_SOP_PAD;
1368 		req->flags = cpu_to_le16(flags);
1369 		break;
1370 	case HWRM_RING_ALLOC_AGG:
1371 		req->ring_type = RING_ALLOC_REQ_RING_TYPE_RX_AGG;
1372 		/* Association of agg ring with rx ring */
1373 		grp_info = &bn->grp_info[ring->grp_idx];
1374 		req->rx_ring_id = cpu_to_le16(grp_info->rx_fw_ring_id);
1375 		req->rx_buf_size = cpu_to_le16(BNGE_RX_PAGE_SIZE);
1376 		req->stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx);
1377 		req->enables |=
1378 			cpu_to_le32(RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID |
1379 				    RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID);
1380 		req->length = cpu_to_le32(bn->rx_agg_ring_mask + 1);
1381 		break;
1382 	case HWRM_RING_ALLOC_CMPL:
1383 		req->ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL;
1384 		req->length = cpu_to_le32(bn->cp_ring_mask + 1);
1385 		/* Association of cp ring with nq */
1386 		grp_info = &bn->grp_info[map_index];
1387 		req->nq_ring_id = cpu_to_le16(grp_info->nq_fw_ring_id);
1388 		req->cq_handle = cpu_to_le64(ring->handle);
1389 		req->enables |=
1390 			cpu_to_le32(RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID);
1391 		break;
1392 	case HWRM_RING_ALLOC_NQ:
1393 		req->ring_type = RING_ALLOC_REQ_RING_TYPE_NQ;
1394 		req->length = cpu_to_le32(bn->cp_ring_mask + 1);
1395 		req->int_mode = RING_ALLOC_REQ_INT_MODE_MSIX;
1396 		break;
1397 	default:
1398 		netdev_err(bn->netdev, "hwrm alloc invalid ring type %d\n", ring_type);
1399 		return -EINVAL;
1400 	}
1401 
1402 	resp = bnge_hwrm_req_hold(bd, req);
1403 	rc = bnge_hwrm_req_send(bd, req);
1404 	ring_id = le32_to_cpu(resp->ring_id);
1405 	bnge_hwrm_req_drop(bd, req);
1406 
1407 exit:
1408 	if (rc) {
1409 		netdev_err(bd->netdev, "hwrm_ring_alloc type %d failed. rc:%d\n", ring_type, rc);
1410 		return -EIO;
1411 	}
1412 	ring->fw_ring_id = ring_id;
1413 	return rc;
1414 }
1415 
bnge_hwrm_set_async_event_cr(struct bnge_dev * bd,int idx)1416 int bnge_hwrm_set_async_event_cr(struct bnge_dev *bd, int idx)
1417 {
1418 	struct hwrm_func_cfg_input *req;
1419 	int rc;
1420 
1421 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_CFG);
1422 	if (rc)
1423 		return rc;
1424 
1425 	req->fid = cpu_to_le16(0xffff);
1426 	req->enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR);
1427 	req->async_event_cr = cpu_to_le16(idx);
1428 	return bnge_hwrm_req_send(bd, req);
1429 }
1430 
1431 #define BNGE_DFLT_TUNL_TPA_BMAP				\
1432 	(VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_GRE |	\
1433 	 VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_IPV4 |	\
1434 	 VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_IPV6)
1435 
bnge_hwrm_vnic_update_tunl_tpa(struct bnge_dev * bd,struct hwrm_vnic_tpa_cfg_input * req)1436 static void bnge_hwrm_vnic_update_tunl_tpa(struct bnge_dev *bd,
1437 					   struct hwrm_vnic_tpa_cfg_input *req)
1438 {
1439 	struct bnge_net *bn = netdev_priv(bd->netdev);
1440 	u32 tunl_tpa_bmap = BNGE_DFLT_TUNL_TPA_BMAP;
1441 
1442 	if (!(bd->fw_cap & BNGE_FW_CAP_VNIC_TUNNEL_TPA))
1443 		return;
1444 
1445 	if (bn->vxlan_port)
1446 		tunl_tpa_bmap |= VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_VXLAN;
1447 	if (bn->vxlan_gpe_port)
1448 		tunl_tpa_bmap |= VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_VXLAN_GPE;
1449 	if (bn->nge_port)
1450 		tunl_tpa_bmap |= VNIC_TPA_CFG_REQ_TNL_TPA_EN_BITMAP_GENEVE;
1451 
1452 	req->enables |= cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_TNL_TPA_EN);
1453 	req->tnl_tpa_en_bitmap = cpu_to_le32(tunl_tpa_bmap);
1454 }
1455 
bnge_hwrm_vnic_set_tpa(struct bnge_dev * bd,struct bnge_vnic_info * vnic,u32 tpa_flags)1456 int bnge_hwrm_vnic_set_tpa(struct bnge_dev *bd, struct bnge_vnic_info *vnic,
1457 			   u32 tpa_flags)
1458 {
1459 	struct bnge_net *bn = netdev_priv(bd->netdev);
1460 	struct hwrm_vnic_tpa_cfg_input *req;
1461 	int rc;
1462 
1463 	if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
1464 		return 0;
1465 
1466 	rc = bnge_hwrm_req_init(bd, req, HWRM_VNIC_TPA_CFG);
1467 	if (rc)
1468 		return rc;
1469 
1470 	if (tpa_flags) {
1471 		u32 flags;
1472 
1473 		flags = VNIC_TPA_CFG_REQ_FLAGS_TPA |
1474 			VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA |
1475 			VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE |
1476 			VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN |
1477 			VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ;
1478 		if (tpa_flags & BNGE_NET_EN_GRO)
1479 			flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO;
1480 
1481 		req->flags = cpu_to_le32(flags);
1482 		req->enables =
1483 			cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS |
1484 				    VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS |
1485 				    VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN);
1486 		req->max_agg_segs = cpu_to_le16(MAX_TPA_SEGS);
1487 		req->max_aggs = cpu_to_le16(bn->max_tpa);
1488 		req->min_agg_len = cpu_to_le32(512);
1489 		bnge_hwrm_vnic_update_tunl_tpa(bd, req);
1490 	}
1491 	req->vnic_id = cpu_to_le16(vnic->fw_vnic_id);
1492 
1493 	return bnge_hwrm_req_send(bd, req);
1494 }
1495 
bnge_hwrm_func_qstat_ext(struct bnge_dev * bd,struct bnge_stats_mem * stats)1496 int bnge_hwrm_func_qstat_ext(struct bnge_dev *bd, struct bnge_stats_mem *stats)
1497 {
1498 	struct hwrm_func_qstats_ext_output *resp;
1499 	struct hwrm_func_qstats_ext_input *req;
1500 	__le64 *hw_masks;
1501 	int rc;
1502 
1503 	if (!(bd->fw_cap & BNGE_FW_CAP_EXT_HW_STATS_SUPPORTED))
1504 		return -EOPNOTSUPP;
1505 
1506 	rc = bnge_hwrm_req_init(bd, req, HWRM_FUNC_QSTATS_EXT);
1507 	if (rc)
1508 		return rc;
1509 
1510 	req->fid = cpu_to_le16(0xffff);
1511 	req->flags = FUNC_QSTATS_EXT_REQ_FLAGS_COUNTER_MASK;
1512 
1513 	resp = bnge_hwrm_req_hold(bd, req);
1514 	rc = bnge_hwrm_req_send(bd, req);
1515 	if (!rc) {
1516 		hw_masks = &resp->rx_ucast_pkts;
1517 		bnge_copy_hw_masks(stats->hw_masks, hw_masks, stats->len / 8);
1518 	}
1519 	bnge_hwrm_req_drop(bd, req);
1520 	return rc;
1521 }
1522 
bnge_hwrm_port_qstats_ext(struct bnge_dev * bd,u8 flags)1523 int bnge_hwrm_port_qstats_ext(struct bnge_dev *bd, u8 flags)
1524 {
1525 	struct hwrm_queue_pri2cos_qcfg_output *resp_qc;
1526 	struct bnge_net *bn = netdev_priv(bd->netdev);
1527 	struct hwrm_queue_pri2cos_qcfg_input *req_qc;
1528 	struct hwrm_port_qstats_ext_output *resp_qs;
1529 	struct hwrm_port_qstats_ext_input *req_qs;
1530 	struct bnge_pf_info *pf = &bd->pf;
1531 	u32 tx_stat_size;
1532 	int rc;
1533 
1534 	if (!(bn->flags & BNGE_FLAG_PORT_STATS_EXT))
1535 		return 0;
1536 
1537 	if (flags && !(bd->fw_cap & BNGE_FW_CAP_EXT_HW_STATS_SUPPORTED))
1538 		return -EOPNOTSUPP;
1539 
1540 	rc = bnge_hwrm_req_init(bd, req_qs, HWRM_PORT_QSTATS_EXT);
1541 	if (rc)
1542 		return rc;
1543 
1544 	req_qs->flags = flags;
1545 	req_qs->port_id = cpu_to_le16(pf->port_id);
1546 	req_qs->rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext));
1547 	req_qs->rx_stat_host_addr =
1548 		cpu_to_le64(bn->rx_port_stats_ext.hw_stats_map);
1549 	tx_stat_size = bn->tx_port_stats_ext.hw_stats ?
1550 		       sizeof(struct tx_port_stats_ext) : 0;
1551 	req_qs->tx_stat_size = cpu_to_le16(tx_stat_size);
1552 	req_qs->tx_stat_host_addr =
1553 		cpu_to_le64(bn->tx_port_stats_ext.hw_stats_map);
1554 	resp_qs = bnge_hwrm_req_hold(bd, req_qs);
1555 	rc = bnge_hwrm_req_send(bd, req_qs);
1556 	if (!rc) {
1557 		bn->fw_rx_stats_ext_size =
1558 			le16_to_cpu(resp_qs->rx_stat_size) / 8;
1559 		bn->fw_tx_stats_ext_size = tx_stat_size ?
1560 			le16_to_cpu(resp_qs->tx_stat_size) / 8 : 0;
1561 	} else {
1562 		bn->fw_rx_stats_ext_size = 0;
1563 		bn->fw_tx_stats_ext_size = 0;
1564 	}
1565 	bnge_hwrm_req_drop(bd, req_qs);
1566 
1567 	if (flags)
1568 		return rc;
1569 
1570 	if (bn->fw_tx_stats_ext_size <=
1571 	    offsetof(struct tx_port_stats_ext, pfc_pri0_tx_duration_us) / 8) {
1572 		bn->pri2cos_valid = false;
1573 		return rc;
1574 	}
1575 
1576 	rc = bnge_hwrm_req_init(bd, req_qc, HWRM_QUEUE_PRI2COS_QCFG);
1577 	if (rc)
1578 		return rc;
1579 
1580 	req_qc->flags = cpu_to_le32(QUEUE_PRI2COS_QCFG_REQ_FLAGS_IVLAN);
1581 
1582 	resp_qc = bnge_hwrm_req_hold(bd, req_qc);
1583 	rc = bnge_hwrm_req_send(bd, req_qc);
1584 	if (!rc) {
1585 		u8 *pri2cos;
1586 		int i, j;
1587 
1588 		pri2cos = &resp_qc->pri0_cos_queue_id;
1589 		for (i = 0; i < 8; i++) {
1590 			u8 queue_id = pri2cos[i];
1591 			u8 queue_idx;
1592 
1593 			/* Per port queue IDs start from 0, 10, 20, etc */
1594 			queue_idx = queue_id % 10;
1595 			if (queue_idx >= BNGE_MAX_QUEUE) {
1596 				bn->pri2cos_valid = false;
1597 				rc = -EINVAL;
1598 				goto drop_req;
1599 			}
1600 			for (j = 0; j < bd->max_q; j++) {
1601 				if (bd->q_ids[j] == queue_id)
1602 					bn->pri2cos_idx[i] = queue_idx;
1603 			}
1604 		}
1605 		bn->pri2cos_valid = true;
1606 	}
1607 drop_req:
1608 	bnge_hwrm_req_drop(bd, req_qc);
1609 	return rc;
1610 }
1611 
bnge_hwrm_port_qstats(struct bnge_dev * bd,u8 flags)1612 int bnge_hwrm_port_qstats(struct bnge_dev *bd, u8 flags)
1613 {
1614 	struct bnge_net *bn = netdev_priv(bd->netdev);
1615 	struct hwrm_port_qstats_input *req;
1616 	struct bnge_pf_info *pf = &bd->pf;
1617 	int rc;
1618 
1619 	if (!(bn->flags & BNGE_FLAG_PORT_STATS))
1620 		return 0;
1621 
1622 	if (flags && !(bd->fw_cap & BNGE_FW_CAP_EXT_HW_STATS_SUPPORTED))
1623 		return -EOPNOTSUPP;
1624 
1625 	rc = bnge_hwrm_req_init(bd, req, HWRM_PORT_QSTATS);
1626 	if (rc)
1627 		return rc;
1628 
1629 	req->flags = flags;
1630 	req->port_id = cpu_to_le16(pf->port_id);
1631 	req->tx_stat_host_addr = cpu_to_le64(bn->port_stats.hw_stats_map +
1632 					     BNGE_TX_PORT_STATS_BYTE_OFFSET);
1633 	req->rx_stat_host_addr = cpu_to_le64(bn->port_stats.hw_stats_map);
1634 
1635 	return bnge_hwrm_req_send(bd, req);
1636 }
1637