xref: /freebsd-14-stable/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c (revision 45e161020c2da04edeeeebc72598af839e41d609)
1 /*-
2  * Broadcom NetXtreme-C/E network driver.
3  *
4  * Copyright (c) 2016 Broadcom, All Rights Reserved.
5  * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
32 #include <sys/ctype.h>
33 #include <linux/delay.h>
34 
35 #include "bnxt.h"
36 #include "bnxt_hwrm.h"
37 #include "bnxt_sysctl.h"
38 
39 DEFINE_MUTEX(tmp_mutex); /* mutex lock for driver */
40 extern void bnxt_fw_reset(struct bnxt_softc *bp);
41 extern void bnxt_queue_sp_work(struct bnxt_softc *bp);
42 extern void
43 process_nq(struct bnxt_softc *softc, uint16_t nqid);
44 /*
45  * We want to create:
46  * dev.bnxt.0.hwstats.txq0
47  * dev.bnxt.0.hwstats.txq0.txmbufs
48  * dev.bnxt.0.hwstats.rxq0
49  * dev.bnxt.0.hwstats.txq0.rxmbufs
50  * so the hwstats ctx list needs to be created in attach_post and populated
51  * during init.
52  *
53  * Then, it needs to be cleaned up in stop.
54  */
55 
56 int
bnxt_init_sysctl_ctx(struct bnxt_softc * softc)57 bnxt_init_sysctl_ctx(struct bnxt_softc *softc)
58 {
59 	struct sysctl_ctx_list *ctx;
60 
61 	sysctl_ctx_init(&softc->hw_stats);
62 	ctx = device_get_sysctl_ctx(softc->dev);
63 	softc->hw_stats_oid = SYSCTL_ADD_NODE(ctx,
64 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
65 	    "hwstats", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware statistics");
66 	if (!softc->hw_stats_oid) {
67 		sysctl_ctx_free(&softc->hw_stats);
68 		return ENOMEM;
69 	}
70 
71 	sysctl_ctx_init(&softc->ver_info->ver_ctx);
72 	ctx = device_get_sysctl_ctx(softc->dev);
73 	softc->ver_info->ver_oid = SYSCTL_ADD_NODE(ctx,
74 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
75 	    "ver", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
76 	    "hardware/firmware version information");
77 	if (!softc->ver_info->ver_oid) {
78 		sysctl_ctx_free(&softc->ver_info->ver_ctx);
79 		return ENOMEM;
80 	}
81 
82 	if (BNXT_PF(softc)) {
83 		sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
84 		ctx = device_get_sysctl_ctx(softc->dev);
85 		softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
86 		    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
87 		    "nvram", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
88 		    "nvram information");
89 		if (!softc->nvm_info->nvm_oid) {
90 			sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
91 			return ENOMEM;
92 		}
93 	}
94 
95 	sysctl_ctx_init(&softc->hw_lro_ctx);
96 	ctx = device_get_sysctl_ctx(softc->dev);
97 	softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
98 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
99 	    "hw_lro", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware lro");
100 	if (!softc->hw_lro_oid) {
101 		sysctl_ctx_free(&softc->hw_lro_ctx);
102 		return ENOMEM;
103 	}
104 
105 	sysctl_ctx_init(&softc->flow_ctrl_ctx);
106 	ctx = device_get_sysctl_ctx(softc->dev);
107 	softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
108 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
109 	    "fc", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "flow ctrl");
110 	if (!softc->flow_ctrl_oid) {
111 		sysctl_ctx_free(&softc->flow_ctrl_ctx);
112 		return ENOMEM;
113 	}
114 
115 	sysctl_ctx_init(&softc->dcb_ctx);
116 	ctx = device_get_sysctl_ctx(softc->dev);
117 	softc->dcb_oid = SYSCTL_ADD_NODE(ctx,
118 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
119 	    "dcb", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Data Center Bridging");
120 	if (!softc->dcb_oid) {
121 		sysctl_ctx_free(&softc->dcb_ctx);
122 		return ENOMEM;
123 	}
124 
125 	return 0;
126 }
127 
128 int
bnxt_free_sysctl_ctx(struct bnxt_softc * softc)129 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
130 {
131 	int orc;
132 	int rc = 0;
133 
134 	if (softc->hw_stats_oid != NULL) {
135 		orc = sysctl_ctx_free(&softc->hw_stats);
136 		if (orc)
137 			rc = orc;
138 		else
139 			softc->hw_stats_oid = NULL;
140 	}
141 	if (softc->ver_info->ver_oid != NULL) {
142 		orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
143 		if (orc)
144 			rc = orc;
145 		else
146 			softc->ver_info->ver_oid = NULL;
147 	}
148 	if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
149 		orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
150 		if (orc)
151 			rc = orc;
152 		else
153 			softc->nvm_info->nvm_oid = NULL;
154 	}
155 	if (softc->hw_lro_oid != NULL) {
156 		orc = sysctl_ctx_free(&softc->hw_lro_ctx);
157 		if (orc)
158 			rc = orc;
159 		else
160 			softc->hw_lro_oid = NULL;
161 	}
162 
163 	if (softc->flow_ctrl_oid != NULL) {
164 		orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
165 		if (orc)
166 			rc = orc;
167 		else
168 			softc->flow_ctrl_oid = NULL;
169 	}
170 
171 	if (softc->dcb_oid != NULL) {
172 		orc = sysctl_ctx_free(&softc->dcb_ctx);
173 		if (orc)
174 			rc = orc;
175 		else
176 			softc->dcb_oid = NULL;
177 	}
178 
179 	return rc;
180 }
181 
182 int
bnxt_create_tx_sysctls(struct bnxt_softc * softc,int txr)183 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
184 {
185 	struct sysctl_oid *oid;
186 	struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats[txr].idi_vaddr;
187 	char	name[32];
188 	char	desc[64];
189 
190 	sprintf(name, "txq%d", txr);
191 	sprintf(desc, "transmit queue %d", txr);
192 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
193 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
194 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
195 	if (!oid)
196 		return ENOMEM;
197 
198 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
199 	    "ucast_pkts", CTLFLAG_RD, &tx_stats->tx_ucast_pkts,
200 	    "unicast packets sent");
201 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
202 	    "mcast_pkts", CTLFLAG_RD, &tx_stats->tx_mcast_pkts,
203 	    "multicast packets sent");
204 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
205 	    "bcast_pkts", CTLFLAG_RD, &tx_stats->tx_bcast_pkts,
206 	    "broadcast packets sent");
207 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
208 	    "discard_pkts", CTLFLAG_RD,
209 	    &tx_stats->tx_discard_pkts, "discarded transmit packets");
210 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
211 	    "error_pkts", CTLFLAG_RD, &tx_stats->tx_error_pkts,
212 	    "Error transmit packets");
213 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
214 	    "ucast_bytes", CTLFLAG_RD, &tx_stats->tx_ucast_bytes,
215 	    "unicast bytes sent");
216 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
217 	    "mcast_bytes", CTLFLAG_RD, &tx_stats->tx_mcast_bytes,
218 	    "multicast bytes sent");
219 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
220 	    "bcast_bytes", CTLFLAG_RD, &tx_stats->tx_bcast_bytes,
221 	    "broadcast bytes sent");
222 
223 	return 0;
224 }
225 
226 int
bnxt_create_port_stats_sysctls(struct bnxt_softc * softc)227 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
228 {
229 	struct sysctl_oid *oid;
230 	char	name[32];
231 	char	desc[64];
232 
233 	sprintf(name, "port_stats");
234 	sprintf(desc, "Port Stats");
235 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
236 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
237 	        CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
238 	if (!oid)
239 		return ENOMEM;
240 
241 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
242 	    "tx_64b_frames", CTLFLAG_RD,
243 	    &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
244 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
245 	    "tx_65b_127b_frames", CTLFLAG_RD,
246 	    &softc->tx_port_stats->tx_65b_127b_frames,
247 	    "Transmitted 65b 127b frames");
248 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
249 	    "tx_128b_255b_frames", CTLFLAG_RD,
250 	    &softc->tx_port_stats->tx_128b_255b_frames,
251 	    "Transmitted 128b 255b frames");
252 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
253 	    "tx_256b_511b_frames", CTLFLAG_RD,
254 	    &softc->tx_port_stats->tx_256b_511b_frames,
255 	    "Transmitted 256b 511b frames");
256 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
257 	    "tx_512b_1023b_frames", CTLFLAG_RD,
258 	    &softc->tx_port_stats->tx_512b_1023b_frames,
259 	    "Transmitted 512b 1023b frames");
260 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
261 	    "tx_1024b_1518b_frames", CTLFLAG_RD,
262 	    &softc->tx_port_stats->tx_1024b_1518b_frames,
263 	    "Transmitted 1024b 1518b frames");
264 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
265 	    "tx_good_vlan_frames", CTLFLAG_RD,
266 	    &softc->tx_port_stats->tx_good_vlan_frames,
267 	    "Transmitted good vlan frames");
268 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
269 	    "tx_1519b_2047b_frames", CTLFLAG_RD,
270 	    &softc->tx_port_stats->tx_1519b_2047b_frames,
271 	    "Transmitted 1519b 2047b frames");
272 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
273 	    "tx_2048b_4095b_frames", CTLFLAG_RD,
274 	    &softc->tx_port_stats->tx_2048b_4095b_frames,
275 	    "Transmitted 2048b 4095b frames");
276 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
277 	    "tx_4096b_9216b_frames", CTLFLAG_RD,
278 	    &softc->tx_port_stats->tx_4096b_9216b_frames,
279 	    "Transmitted 4096b 9216b frames");
280 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
281 	    "tx_9217b_16383b_frames", CTLFLAG_RD,
282 	    &softc->tx_port_stats->tx_9217b_16383b_frames,
283 	    "Transmitted 9217b 16383b frames");
284 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
285 	    "tx_good_frames", CTLFLAG_RD,
286 	    &softc->tx_port_stats->tx_good_frames, "Transmitted good frames");
287 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
288 	    "tx_total_frames", CTLFLAG_RD,
289 	    &softc->tx_port_stats->tx_total_frames, "Transmitted total frames");
290 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
291 	    "tx_ucast_frames", CTLFLAG_RD,
292 	    &softc->tx_port_stats->tx_ucast_frames, "Transmitted ucast frames");
293 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
294 	    "tx_mcast_frames", CTLFLAG_RD,
295 	    &softc->tx_port_stats->tx_mcast_frames, "Transmitted mcast frames");
296 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
297 	    "tx_bcast_frames", CTLFLAG_RD,
298 	    &softc->tx_port_stats->tx_bcast_frames, "Transmitted bcast frames");
299 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
300 	    "tx_pause_frames", CTLFLAG_RD,
301 	    &softc->tx_port_stats->tx_pause_frames, "Transmitted pause frames");
302 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
303 	    "tx_pfc_frames", CTLFLAG_RD,
304 	    &softc->tx_port_stats->tx_pfc_frames, "Transmitted pfc frames");
305 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
306 	    "tx_jabber_frames", CTLFLAG_RD,
307 	    &softc->tx_port_stats->tx_jabber_frames, "Transmitted jabber frames");
308 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
309 	    "tx_fcs_err_frames", CTLFLAG_RD,
310 	    &softc->tx_port_stats->tx_fcs_err_frames,
311 	    "Transmitted fcs err frames");
312 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
313 	    "tx_err", CTLFLAG_RD,
314 	    &softc->tx_port_stats->tx_err, "Transmitted err");
315 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
316 	    "tx_fifo_underruns", CTLFLAG_RD,
317 	    &softc->tx_port_stats->tx_fifo_underruns,
318 	    "Transmitted fifo underruns");
319 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
320 	    "tx_pfc_ena_frames_pri0", CTLFLAG_RD,
321 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri0,
322 	    "Transmitted pfc ena frames pri0");
323 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
324 	    "tx_pfc_ena_frames_pri1", CTLFLAG_RD,
325 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri1,
326 	    "Transmitted pfc ena frames pri1");
327 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
328 	    "tx_pfc_ena_frames_pri2", CTLFLAG_RD,
329 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri2,
330 	    "Transmitted pfc ena frames pri2");
331 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
332 	    "tx_pfc_ena_frames_pri3", CTLFLAG_RD,
333 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri3,
334 	    "Transmitted pfc ena frames pri3");
335 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
336 	    "tx_pfc_ena_frames_pri4", CTLFLAG_RD,
337 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri4,
338 	    "Transmitted pfc ena frames pri4");
339 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
340 	    "tx_pfc_ena_frames_pri5", CTLFLAG_RD,
341 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri5,
342 	    "Transmitted pfc ena frames pri5");
343 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
344 	    "tx_pfc_ena_frames_pri6", CTLFLAG_RD,
345 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri6,
346 	    "Transmitted pfc ena frames pri6");
347 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
348 	    "tx_pfc_ena_frames_pri7", CTLFLAG_RD,
349 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri7,
350 	    "Transmitted pfc ena frames pri7");
351 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
352 	    "tx_eee_lpi_events", CTLFLAG_RD,
353 	    &softc->tx_port_stats->tx_eee_lpi_events,
354 	    "Transmitted eee lpi events");
355 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
356 	    "tx_eee_lpi_duration", CTLFLAG_RD,
357 	    &softc->tx_port_stats->tx_eee_lpi_duration,
358 	    "Transmitted eee lpi duration");
359 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
360 	    "tx_llfc_logical_msgs", CTLFLAG_RD,
361 	    &softc->tx_port_stats->tx_llfc_logical_msgs,
362 	    "Transmitted llfc logical msgs");
363 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
364 	    "tx_hcfc_msgs", CTLFLAG_RD,
365 	    &softc->tx_port_stats->tx_hcfc_msgs, "Transmitted hcfc msgs");
366 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
367 	    "tx_total_collisions", CTLFLAG_RD,
368 	    &softc->tx_port_stats->tx_total_collisions,
369 	    "Transmitted total collisions");
370 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
371 	    "tx_bytes", CTLFLAG_RD,
372 	    &softc->tx_port_stats->tx_bytes, "Transmitted bytes");
373 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
374 	    "tx_xthol_frames", CTLFLAG_RD,
375 	    &softc->tx_port_stats->tx_xthol_frames, "Transmitted xthol frames");
376 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
377 	    "tx_stat_discard", CTLFLAG_RD,
378 	    &softc->tx_port_stats->tx_stat_discard, "Transmitted stat discard");
379 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
380 	    "tx_stat_error", CTLFLAG_RD,
381 	    &softc->tx_port_stats->tx_stat_error, "Transmitted stat error");
382 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
383 	    "rx_64b_frames", CTLFLAG_RD,
384 	    &softc->rx_port_stats->rx_64b_frames, "Received 64b frames");
385 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
386 	    "rx_65b_127b_frames", CTLFLAG_RD,
387 	    &softc->rx_port_stats->rx_65b_127b_frames, "Received 65b 127b frames");
388 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
389 	    "rx_128b_255b_frames", CTLFLAG_RD,
390 	    &softc->rx_port_stats->rx_128b_255b_frames,
391 	    "Received 128b 255b frames");
392 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
393 	    "rx_256b_511b_frames", CTLFLAG_RD,
394 	    &softc->rx_port_stats->rx_256b_511b_frames,
395 	    "Received 256b 511b frames");
396 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
397 	    "rx_512b_1023b_frames", CTLFLAG_RD,
398 	    &softc->rx_port_stats->rx_512b_1023b_frames,
399 	    "Received 512b 1023b frames");
400 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
401 	    "rx_1024b_1518b_frames", CTLFLAG_RD,
402 	    &softc->rx_port_stats->rx_1024b_1518b_frames,
403 	    "Received 1024b 1518 frames");
404 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
405 	    "rx_good_vlan_frames", CTLFLAG_RD,
406 	    &softc->rx_port_stats->rx_good_vlan_frames,
407 	    "Received good vlan frames");
408 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
409 	    "rx_1519b_2047b_frames", CTLFLAG_RD,
410 	    &softc->rx_port_stats->rx_1519b_2047b_frames,
411 	    "Received 1519b 2047b frames");
412 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
413 	    "rx_2048b_4095b_frames", CTLFLAG_RD,
414 	    &softc->rx_port_stats->rx_2048b_4095b_frames,
415 	    "Received 2048b 4095b frames");
416 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
417 	    "rx_4096b_9216b_frames", CTLFLAG_RD,
418 	    &softc->rx_port_stats->rx_4096b_9216b_frames,
419 	    "Received 4096b 9216b frames");
420 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
421 	    "rx_9217b_16383b_frames", CTLFLAG_RD,
422 	    &softc->rx_port_stats->rx_9217b_16383b_frames,
423 	    "Received 9217b 16383b frames");
424 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
425 	    "rx_total_frames", CTLFLAG_RD,
426 	    &softc->rx_port_stats->rx_total_frames, "Received total frames");
427 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
428 	    "rx_ucast_frames", CTLFLAG_RD,
429 	    &softc->rx_port_stats->rx_ucast_frames, "Received ucast frames");
430 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
431 	    "rx_mcast_frames", CTLFLAG_RD,
432 	    &softc->rx_port_stats->rx_mcast_frames, "Received mcast frames");
433 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
434 	    "rx_bcast_frames", CTLFLAG_RD,
435 	    &softc->rx_port_stats->rx_bcast_frames, "Received bcast frames");
436 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
437 	    "rx_fcs_err_frames", CTLFLAG_RD,
438 	    &softc->rx_port_stats->rx_fcs_err_frames, "Received fcs err frames");
439 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
440 	    "rx_ctrl_frames", CTLFLAG_RD,
441 	    &softc->rx_port_stats->rx_ctrl_frames, "Received ctrl frames");
442 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
443 	    "rx_pause_frames", CTLFLAG_RD,
444 	    &softc->rx_port_stats->rx_pause_frames, "Received pause frames");
445 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
446 	    "rx_pfc_frames", CTLFLAG_RD,
447 	    &softc->rx_port_stats->rx_pfc_frames, "Received pfc frames");
448 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
449 	    "rx_align_err_frames", CTLFLAG_RD,
450 	    &softc->rx_port_stats->rx_align_err_frames,
451 	    "Received align err frames");
452 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
453 	    "rx_ovrsz_frames", CTLFLAG_RD,
454 	    &softc->rx_port_stats->rx_ovrsz_frames,
455 	    "Received ovrsz frames");
456 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
457 	    "rx_jbr_frames", CTLFLAG_RD,
458 	    &softc->rx_port_stats->rx_jbr_frames,
459 	    "Received jbr frames");
460 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
461 	    "rx_mtu_err_frames", CTLFLAG_RD,
462 	    &softc->rx_port_stats->rx_mtu_err_frames,
463 	    "Received mtu err frames");
464 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
465 	    "rx_tagged_frames", CTLFLAG_RD,
466 	    &softc->rx_port_stats->rx_tagged_frames,
467 	    "Received tagged frames");
468 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
469 	    "rx_double_tagged_frames", CTLFLAG_RD,
470 	    &softc->rx_port_stats->rx_double_tagged_frames,
471 	    "Received double tagged frames");
472 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
473 	    "rx_good_frames", CTLFLAG_RD,
474 	    &softc->rx_port_stats->rx_good_frames,
475 	    "Received good frames");
476 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
477 	    "rx_pfc_ena_frames_pri0", CTLFLAG_RD,
478 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri0,
479 	    "Received pfc ena frames pri0");
480 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
481 	    "rx_pfc_ena_frames_pri1", CTLFLAG_RD,
482 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri1,
483 	    "Received pfc ena frames pri1");
484 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
485 	    "rx_pfc_ena_frames_pri2", CTLFLAG_RD,
486 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri2,
487 	    "Received pfc ena frames pri2");
488 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
489 	    "rx_pfc_ena_frames_pri3", CTLFLAG_RD,
490 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri3,
491 	    "Received pfc ena frames pri3");
492 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
493 	    "rx_pfc_ena_frames_pri4", CTLFLAG_RD,
494 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri4,
495 	    "Received pfc ena frames pri4");
496 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
497 	    "rx_pfc_ena_frames_pri5", CTLFLAG_RD,
498 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri5,
499 	    "Received pfc ena frames pri5");
500 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
501 	    "rx_pfc_ena_frames_pri6", CTLFLAG_RD,
502 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri6,
503 	    "Received pfc ena frames pri6");
504 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
505 	    "rx_pfc_ena_frames_pri7", CTLFLAG_RD,
506 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri7,
507 	    "Received pfc ena frames pri7");
508 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
509 	    "rx_sch_crc_err_frames", CTLFLAG_RD,
510 	    &softc->rx_port_stats->rx_sch_crc_err_frames,
511 	    "Received sch crc err frames");
512 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
513 	    "rx_undrsz_frames", CTLFLAG_RD,
514 	    &softc->rx_port_stats->rx_undrsz_frames, "Received undrsz frames");
515 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
516 	    "rx_eee_lpi_events", CTLFLAG_RD,
517 	    &softc->rx_port_stats->rx_eee_lpi_events, "Received eee lpi events");
518 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
519 	    "rx_eee_lpi_duration", CTLFLAG_RD,
520 	    &softc->rx_port_stats->rx_eee_lpi_duration,
521 	    "Received eee lpi duration");
522 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
523 	    "rx_llfc_physical_msgs", CTLFLAG_RD,
524 	    &softc->rx_port_stats->rx_llfc_physical_msgs,
525 	    "Received llfc physical msgs");
526 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
527 	    "rx_llfc_logical_msgs", CTLFLAG_RD,
528 	    &softc->rx_port_stats->rx_llfc_logical_msgs,
529 	    "Received llfc logical msgs");
530 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
531 	    "rx_llfc_msgs_with_crc_err", CTLFLAG_RD,
532 	    &softc->rx_port_stats->rx_llfc_msgs_with_crc_err,
533 	    "Received llfc msgs with crc err");
534 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
535 	    "rx_hcfc_msgs", CTLFLAG_RD,
536 	    &softc->rx_port_stats->rx_hcfc_msgs, "Received hcfc msgs");
537 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
538 	    "rx_hcfc_msgs_with_crc_err", CTLFLAG_RD,
539 	    &softc->rx_port_stats->rx_hcfc_msgs_with_crc_err,
540 	    "Received hcfc msgs with crc err");
541 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
542 	    "rx_bytes", CTLFLAG_RD,
543 	    &softc->rx_port_stats->rx_bytes, "Received bytes");
544 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
545 	    "rx_runt_bytes", CTLFLAG_RD,
546 	    &softc->rx_port_stats->rx_runt_bytes, "Received runt bytes");
547 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
548 	    "rx_runt_frames", CTLFLAG_RD,
549 	    &softc->rx_port_stats->rx_runt_frames, "Received runt frames");
550 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
551 	    "rx_stat_discard", CTLFLAG_RD,
552 	    &softc->rx_port_stats->rx_stat_discard, "Received stat discard");
553 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
554 	    "rx_stat_err", CTLFLAG_RD,
555 	    &softc->rx_port_stats->rx_stat_err, "Received stat err");
556 
557 	if (BNXT_CHIP_P5_PLUS(softc) &&
558 	    (softc->flags & BNXT_FLAG_FW_CAP_EXT_STATS)) {
559 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
560 		    "tx_bytes_cos0", CTLFLAG_RD,
561 		    &softc->tx_port_stats_ext->tx_bytes_cos0, "Transmitted bytes count cos0");
562 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
563 		    "tx_packets_cos0", CTLFLAG_RD,
564 		    &softc->tx_port_stats_ext->tx_packets_cos0, "Transmitted packets count cos0");
565 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
566 		    "tx_bytes_cos1", CTLFLAG_RD,
567 		    &softc->tx_port_stats_ext->tx_bytes_cos1, "Transmitted bytes count cos1");
568 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
569 		    "tx_packets_cos1", CTLFLAG_RD,
570 		    &softc->tx_port_stats_ext->tx_packets_cos1, "Transmitted packets count cos1");
571 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
572 		    "tx_bytes_cos2", CTLFLAG_RD,
573 		    &softc->tx_port_stats_ext->tx_bytes_cos2, "Transmitted bytes count cos2");
574 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
575 		    "tx_packets_cos2", CTLFLAG_RD,
576 		    &softc->tx_port_stats_ext->tx_packets_cos2, "Transmitted packets count cos2");
577 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
578 		    "tx_bytes_cos3", CTLFLAG_RD,
579 		    &softc->tx_port_stats_ext->tx_bytes_cos3, "Transmitted bytes count cos3");
580 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
581 		    "tx_packets_cos3", CTLFLAG_RD,
582 		    &softc->tx_port_stats_ext->tx_packets_cos3, "Transmitted packets count cos3");
583 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
584 		    "tx_bytes_cos4", CTLFLAG_RD,
585 		    &softc->tx_port_stats_ext->tx_bytes_cos4, "Transmitted bytes count cos4");
586 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
587 		    "tx_packets_cos4", CTLFLAG_RD,
588 		    &softc->tx_port_stats_ext->tx_packets_cos4, "Transmitted packets count cos4");
589 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
590 		    "tx_bytes_cos5", CTLFLAG_RD,
591 		    &softc->tx_port_stats_ext->tx_bytes_cos5, "Transmitted bytes count cos5");
592 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
593 		    "tx_packets_cos5", CTLFLAG_RD,
594 		    &softc->tx_port_stats_ext->tx_packets_cos5, "Transmitted packets count cos5");
595 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
596 		    "tx_bytes_cos6", CTLFLAG_RD,
597 		    &softc->tx_port_stats_ext->tx_bytes_cos6, "Transmitted bytes count cos6");
598 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
599 		    "tx_packets_cos6", CTLFLAG_RD,
600 		    &softc->tx_port_stats_ext->tx_packets_cos6, "Transmitted packets count cos6");
601 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
602 		    "tx_bytes_cos7", CTLFLAG_RD,
603 		    &softc->tx_port_stats_ext->tx_bytes_cos7, "Transmitted bytes count cos7");
604 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
605 		    "tx_packets_cos7", CTLFLAG_RD,
606 		    &softc->tx_port_stats_ext->tx_packets_cos7, "Transmitted packets count cos7");
607 
608 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
609 		    "tx_bytes_pri0", CTLFLAG_RD,
610 		    &softc->tx_bytes_pri[0], "Transmitted bytes count pri0");
611 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
612 		    "tx_packets_pri0", CTLFLAG_RD,
613 		    &softc->tx_packets_pri[0], "Transmitted packets count pri0");
614 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
615 		    "tx_bytes_pri1", CTLFLAG_RD,
616 		    &softc->tx_bytes_pri[1], "Transmitted bytes count pri1");
617 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
618 		    "tx_packets_pri1", CTLFLAG_RD,
619 		    &softc->tx_packets_pri[1], "Transmitted packets count pri1");
620 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
621 		    "tx_bytes_pri2", CTLFLAG_RD,
622 		    &softc->tx_bytes_pri[2], "Transmitted bytes count pri2");
623 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
624 		    "tx_packets_pri2", CTLFLAG_RD,
625 		    &softc->tx_packets_pri[2], "Transmitted packets count pri2");
626 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
627 		    "tx_bytes_pri3", CTLFLAG_RD,
628 		    &softc->tx_bytes_pri[3], "Transmitted bytes count pri3");
629 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
630 		    "tx_packets_pri3", CTLFLAG_RD,
631 		    &softc->tx_packets_pri[3], "Transmitted packets count pri3");
632 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
633 		    "tx_bytes_pri4", CTLFLAG_RD,
634 		    &softc->tx_bytes_pri[4], "Transmitted bytes count pri4");
635 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
636 		    "tx_packets_pri4", CTLFLAG_RD,
637 		    &softc->tx_packets_pri[4], "Transmitted packets count pri4");
638 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
639 		    "tx_bytes_pri5", CTLFLAG_RD,
640 		    &softc->tx_bytes_pri[5], "Transmitted bytes count pri5");
641 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
642 		    "tx_packets_pri5", CTLFLAG_RD,
643 		    &softc->tx_packets_pri[5], "Transmitted packets count pri5");
644 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
645 		    "tx_bytes_pri6", CTLFLAG_RD,
646 		    &softc->tx_bytes_pri[6], "Transmitted bytes count pri6");
647 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
648 		    "tx_packets_pri6", CTLFLAG_RD,
649 		    &softc->tx_packets_pri[6], "Transmitted packets count pri6");
650 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
651 		    "tx_bytes_pri7", CTLFLAG_RD,
652 		    &softc->tx_bytes_pri[7], "Transmitted bytes count pri7");
653 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
654 		    "tx_packets_pri7", CTLFLAG_RD,
655 		    &softc->tx_packets_pri[7], "Transmitted packets count pri7");
656 
657 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
658 		    "pfc_pri0_tx_duration_us", CTLFLAG_RD,
659 		    &softc->tx_port_stats_ext->pfc_pri0_tx_duration_us, "Time duration between"
660 		    "XON to XOFF and XOFF to XON for pri0");
661 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
662 		    "pfc_pri0_tx_transitions", CTLFLAG_RD,
663 		    &softc->tx_port_stats_ext->pfc_pri0_tx_transitions, "Num times transition"
664 		    "between XON to XOFF and XOFF to XON for pri0");
665 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
666 		    "pfc_pri1_tx_duration_us", CTLFLAG_RD,
667 		    &softc->tx_port_stats_ext->pfc_pri1_tx_duration_us, "Time duration between"
668 		    "XON to XOFF and XOFF to XON for pri1");
669 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
670 		    "pfc_pri1_tx_transitions", CTLFLAG_RD,
671 		    &softc->tx_port_stats_ext->pfc_pri1_tx_transitions, "Num times transition"
672 		    "between XON to XOFF and XOFF to XON for pri1");
673 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
674 		    "pfc_pri2_tx_duration_us", CTLFLAG_RD,
675 		    &softc->tx_port_stats_ext->pfc_pri2_tx_duration_us, "Time duration between"
676 		    "XON to XOFF and XOFF to XON for pri2");
677 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
678 		    "pfc_pri2_tx_transitions", CTLFLAG_RD,
679 		    &softc->tx_port_stats_ext->pfc_pri2_tx_transitions, "Num times transition"
680 		    "between XON to XOFF and XOFF to XON for pri2");
681 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
682 		    "pfc_pri3_tx_duration_us", CTLFLAG_RD,
683 		    &softc->tx_port_stats_ext->pfc_pri3_tx_duration_us, "Time duration between"
684 		    "XON to XOFF and XOFF to XON for pri3");
685 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
686 		    "pfc_pri3_tx_transitions", CTLFLAG_RD,
687 		    &softc->tx_port_stats_ext->pfc_pri3_tx_transitions, "Num times transition"
688 		    "between XON to XOFF and XOFF to XON for pri3");
689 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
690 		    "pfc_pri4_tx_duration_us", CTLFLAG_RD,
691 		    &softc->tx_port_stats_ext->pfc_pri4_tx_duration_us, "Time duration between"
692 		    "XON to XOFF and XOFF to XON for pri4");
693 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
694 		    "pfc_pri4_tx_transitions", CTLFLAG_RD,
695 		    &softc->tx_port_stats_ext->pfc_pri4_tx_transitions, "Num times transition"
696 		    "between XON to XOFF and XOFF to XON for pri4");
697 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
698 		    "pfc_pri5_tx_duration_us", CTLFLAG_RD,
699 		    &softc->tx_port_stats_ext->pfc_pri5_tx_duration_us, "Time duration between"
700 		    "XON to XOFF and XOFF to XON for pri5");
701 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
702 		    "pfc_pri5_tx_transitions", CTLFLAG_RD,
703 		    &softc->tx_port_stats_ext->pfc_pri5_tx_transitions, "Num times transition"
704 		    "between XON to XOFF and XOFF to XON for pri5");
705 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
706 		    "pfc_pri6_tx_duration_us", CTLFLAG_RD,
707 		    &softc->tx_port_stats_ext->pfc_pri6_tx_duration_us, "Time duration between"
708 		    "XON to XOFF and XOFF to XON for pri6");
709 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
710 		    "pfc_pri6_tx_transitions", CTLFLAG_RD,
711 		    &softc->tx_port_stats_ext->pfc_pri6_tx_transitions, "Num times transition"
712 		    "between XON to XOFF and XOFF to XON for pri6");
713 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
714 		    "pfc_pri7_tx_duration_us", CTLFLAG_RD,
715 		    &softc->tx_port_stats_ext->pfc_pri7_tx_duration_us, "Time duration between"
716 		    "XON to XOFF and XOFF to XON for pri7");
717 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
718 		    "pfc_pri7_tx_transitions", CTLFLAG_RD,
719 		    &softc->tx_port_stats_ext->pfc_pri7_tx_transitions, "Num times transition"
720 		    "between XON to XOFF and XOFF to XON for pri7");
721 
722 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
723 		    "link_down_events", CTLFLAG_RD,
724 		    &softc->rx_port_stats_ext->link_down_events, "Num times link states down");
725 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
726 		    "continuous_pause_events", CTLFLAG_RD,
727 		    &softc->rx_port_stats_ext->continuous_pause_events, "Num times pause events");
728 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
729 		    "resume_pause_events", CTLFLAG_RD,
730 		    &softc->rx_port_stats_ext->resume_pause_events, "Num times pause events"
731 		    "resumes");
732 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
733 		    "continuous_roce_pause_events", CTLFLAG_RD,
734 		    &softc->rx_port_stats_ext->continuous_roce_pause_events, "Num times roce"
735 		    "pause events");
736 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
737 		    "resume_roce_pause_events", CTLFLAG_RD,
738 		    &softc->rx_port_stats_ext->resume_roce_pause_events, "Num times roce pause"
739 		    "events resumes");
740 
741 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
742 		    "rx_bytes_cos0", CTLFLAG_RD,
743 		    &softc->rx_port_stats_ext->rx_bytes_cos0, "Received bytes count cos0");
744 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
745 		    "rx_packets_cos0", CTLFLAG_RD,
746 		    &softc->rx_port_stats_ext->rx_packets_cos0, "Received packets count cos0");
747 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
748 		    "rx_bytes_cos1", CTLFLAG_RD,
749 		    &softc->rx_port_stats_ext->rx_bytes_cos1, "Received bytes count cos1");
750 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
751 		    "rx_packets_cos1", CTLFLAG_RD,
752 		    &softc->rx_port_stats_ext->rx_packets_cos1, "Received packets count cos1");
753 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
754 		    "rx_bytes_cos2", CTLFLAG_RD,
755 		    &softc->rx_port_stats_ext->rx_bytes_cos2, "Received bytes count cos2");
756 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
757 		    "rx_packets_cos2", CTLFLAG_RD,
758 		    &softc->rx_port_stats_ext->rx_packets_cos2, "Received packets count cos2");
759 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
760 		    "rx_bytes_cos3", CTLFLAG_RD,
761 		    &softc->rx_port_stats_ext->rx_bytes_cos3, "Received bytes count cos3");
762 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
763 		    "rx_packets_cos3", CTLFLAG_RD,
764 		    &softc->rx_port_stats_ext->rx_packets_cos3, "Received packets count cos3");
765 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
766 		    "rx_bytes_cos4", CTLFLAG_RD,
767 		    &softc->rx_port_stats_ext->rx_bytes_cos4, "Received bytes count cos4");
768 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
769 		    "rx_packets_cos4", CTLFLAG_RD,
770 		    &softc->rx_port_stats_ext->rx_packets_cos4, "Received packets count cos4");
771 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
772 		    "rx_bytes_cos5", CTLFLAG_RD,
773 		    &softc->rx_port_stats_ext->rx_bytes_cos5, "Received bytes count cos5");
774 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
775 		    "rx_packets_cos5", CTLFLAG_RD,
776 		    &softc->rx_port_stats_ext->rx_packets_cos5, "Received packets count cos5");
777 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
778 		    "rx_bytes_cos6", CTLFLAG_RD,
779 		    &softc->rx_port_stats_ext->rx_bytes_cos6, "Received bytes count cos6");
780 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
781 		    "rx_packets_cos6", CTLFLAG_RD,
782 		    &softc->rx_port_stats_ext->rx_packets_cos6, "Received packets count cos6");
783 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
784 		    "rx_bytes_cos7", CTLFLAG_RD,
785 		    &softc->rx_port_stats_ext->rx_bytes_cos7, "Received bytes count cos7");
786 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
787 		    "rx_packets_cos7", CTLFLAG_RD,
788 		    &softc->rx_port_stats_ext->rx_packets_cos7, "Received packets count cos7");
789 
790 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
791 		    "rx_bytes_pri0", CTLFLAG_RD,
792 		    &softc->rx_bytes_pri[0], "Received bytes count pri0");
793 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
794 		    "rx_packets_pri0", CTLFLAG_RD,
795 		    &softc->rx_packets_pri[0], "Received packets count pri0");
796 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
797 		    "rx_bytes_pri1", CTLFLAG_RD,
798 		    &softc->rx_bytes_pri[1], "Received bytes count pri1");
799 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
800 		    "rx_packets_pri1", CTLFLAG_RD,
801 		    &softc->rx_packets_pri[1], "Received packets count pri1");
802 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
803 		    "rx_bytes_pri2", CTLFLAG_RD,
804 		    &softc->rx_bytes_pri[2], "Received bytes count pri2");
805 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
806 		    "rx_packets_pri2", CTLFLAG_RD,
807 		    &softc->rx_packets_pri[2], "Received packets count pri2");
808 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
809 		    "rx_bytes_pri3", CTLFLAG_RD,
810 		    &softc->rx_bytes_pri[3], "Received bytes count pri3");
811 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
812 		    "rx_packets_pri3", CTLFLAG_RD,
813 		    &softc->rx_packets_pri[3], "Received packets count pri3");
814 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
815 		    "rx_bytes_pri4", CTLFLAG_RD,
816 		    &softc->rx_bytes_pri[4], "Received bytes count pri4");
817 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
818 		    "rx_packets_pri4", CTLFLAG_RD,
819 		    &softc->rx_packets_pri[4], "Received packets count pri4");
820 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
821 		    "rx_bytes_pri5", CTLFLAG_RD,
822 		    &softc->rx_bytes_pri[5], "Received bytes count pri5");
823 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
824 		    "rx_packets_pri5", CTLFLAG_RD,
825 		    &softc->rx_packets_pri[5], "Received packets count pri5");
826 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
827 		    "rx_bytes_pri6", CTLFLAG_RD,
828 		    &softc->rx_bytes_pri[6], "Received bytes count pri6");
829 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
830 		    "rx_packets_pri6", CTLFLAG_RD,
831 		    &softc->rx_packets_pri[6], "Received packets count pri6");
832 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
833 		    "rx_bytes_pri7", CTLFLAG_RD,
834 		    &softc->rx_bytes_pri[7], "Received bytes count pri7");
835 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
836 		    "rx_packets_pri7", CTLFLAG_RD,
837 		    &softc->rx_packets_pri[7], "Received packets count pri7");
838 
839 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
840 		    "pfc_pri0_rx_duration_us", CTLFLAG_RD,
841 		    &softc->rx_port_stats_ext->pfc_pri0_rx_duration_us, "Time duration in receiving"
842 		    "between XON to XOFF and XOFF to XON for pri0");
843 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
844 		    "pfc_pri0_rx_transitions", CTLFLAG_RD,
845 		    &softc->rx_port_stats_ext->pfc_pri0_rx_transitions, "Num times rx transition"
846 		    "between XON to XOFF and XOFF to XON for pri0");
847 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
848 		    "pfc_pri1_rx_duration_us", CTLFLAG_RD,
849 		    &softc->rx_port_stats_ext->pfc_pri1_rx_duration_us, "Time duration in receiving"
850 		    "between XON to XOFF and XOFF to XON for pri1");
851 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
852 		    "pfc_pri1_rx_transitions", CTLFLAG_RD,
853 		    &softc->rx_port_stats_ext->pfc_pri1_rx_transitions, "Num times rx transition"
854 		    "between XON to XOFF and XOFF to XON for pri1");
855 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
856 		    "pfc_pri2_rx_duration_us", CTLFLAG_RD,
857 		    &softc->rx_port_stats_ext->pfc_pri2_rx_duration_us, "Time duration in receiving"
858 		    "between XON to XOFF and XOFF to XON for pri2");
859 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
860 		    "pfc_pri2_rx_transitions", CTLFLAG_RD,
861 		    &softc->rx_port_stats_ext->pfc_pri2_rx_transitions, "Num times rx transition"
862 		    "between XON to XOFF and XOFF to XON for pri2");
863 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
864 		    "pfc_pri3_rx_duration_us", CTLFLAG_RD,
865 		    &softc->rx_port_stats_ext->pfc_pri3_rx_duration_us, "Time duration in receiving"
866 		    "between XON to XOFF and XOFF to XON for pri3");
867 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
868 		    "pfc_pri3_rx_transitions", CTLFLAG_RD,
869 		    &softc->rx_port_stats_ext->pfc_pri3_rx_transitions, "Num times rx transition"
870 		    "between XON to XOFF and XOFF to XON for pri3");
871 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
872 		    "pfc_pri4_rx_duration_us", CTLFLAG_RD,
873 		    &softc->rx_port_stats_ext->pfc_pri4_rx_duration_us, "Time duration in receiving"
874 		    "between XON to XOFF and XOFF to XON for pri4");
875 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
876 		    "pfc_pri4_rx_transitions", CTLFLAG_RD,
877 		    &softc->rx_port_stats_ext->pfc_pri4_rx_transitions, "Num times rx transition"
878 		    "between XON to XOFF and XOFF to XON for pri4");
879 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
880 		    "pfc_pri5_rx_duration_us", CTLFLAG_RD,
881 		    &softc->rx_port_stats_ext->pfc_pri5_rx_duration_us, "Time duration in receiving"
882 		    "between XON to XOFF and XOFF to XON for pri5");
883 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
884 		    "pfc_pri5_rx_transitions", CTLFLAG_RD,
885 		    &softc->rx_port_stats_ext->pfc_pri5_rx_transitions, "Num times rx transition"
886 		    "between XON to XOFF and XOFF to XON for pri5");
887 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
888 		    "pfc_pri6_rx_duration_us", CTLFLAG_RD,
889 		    &softc->rx_port_stats_ext->pfc_pri6_rx_duration_us, "Time duration in receiving"
890 		    "between XON to XOFF and XOFF to XON for pri6");
891 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
892 		    "pfc_pri6_rx_transitions", CTLFLAG_RD,
893 		    &softc->rx_port_stats_ext->pfc_pri6_rx_transitions, "Num times rx transition"
894 		    "between XON to XOFF and XOFF to XON for pri6");
895 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
896 		    "pfc_pri7_rx_duration_us", CTLFLAG_RD,
897 		    &softc->rx_port_stats_ext->pfc_pri7_rx_duration_us, "Time duration in receiving"
898 		    "between XON to XOFF and XOFF to XON for pri7");
899 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
900 		    "pfc_pri7_rx_transitions", CTLFLAG_RD,
901 		    &softc->rx_port_stats_ext->pfc_pri7_rx_transitions, "Num times rx transition"
902 		    "between XON to XOFF and XOFF to XON for pri7");
903 
904 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
905 		    "rx_bits", CTLFLAG_RD,
906 		    &softc->rx_port_stats_ext->rx_bits, "total number of received bits");
907 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
908 		    "rx_buffer_passed_threshold", CTLFLAG_RD,
909 		    &softc->rx_port_stats_ext->rx_buffer_passed_threshold, "num of events port"
910 		    "buffer"
911 		    "was over 85%");
912 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
913 		    "rx_pcs_symbol_err", CTLFLAG_RD,
914 		    &softc->rx_port_stats_ext->rx_pcs_symbol_err, "num of symbol errors wasn't"
915 		    "corrected by FEC");
916 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
917 		    "rx_corrected_bits", CTLFLAG_RD,
918 		    &softc->rx_port_stats_ext->rx_corrected_bits, "num of bits corrected by FEC");
919 
920 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
921 		    "rx_discard_bytes_cos0", CTLFLAG_RD,
922 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos0, "num of rx discard bytes"
923 		    "count on cos0");
924 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
925 		    "rx_discard_packets_cos0", CTLFLAG_RD,
926 		    &softc->rx_port_stats_ext->rx_discard_packets_cos0, "num of rx discard packets"
927 		    "count on cos0");
928 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
929 		    "rx_discard_bytes_cos1", CTLFLAG_RD,
930 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos1, "num of rx discard bytes"
931 		    "count on cos1");
932 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
933 		    "rx_discard_packets_cos1", CTLFLAG_RD,
934 		    &softc->rx_port_stats_ext->rx_discard_packets_cos1, "num of rx discard packets"
935 		    "count on cos1");
936 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
937 		    "rx_discard_bytes_cos2", CTLFLAG_RD,
938 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos2, "num of rx discard bytes"
939 		    "count on cos2");
940 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
941 		    "rx_discard_packets_cos2", CTLFLAG_RD,
942 		    &softc->rx_port_stats_ext->rx_discard_packets_cos2, "num of rx discard packets"
943 		    "count on cos2");
944 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
945 		    "rx_discard_bytes_cos3", CTLFLAG_RD,
946 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos3, "num of rx discard bytes"
947 		    "count on cos3");
948 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
949 		    "rx_discard_packets_cos3", CTLFLAG_RD,
950 		    &softc->rx_port_stats_ext->rx_discard_packets_cos3, "num of rx discard packets"
951 		    "count on cos3");
952 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
953 		    "rx_discard_bytes_cos4", CTLFLAG_RD,
954 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos4, "num of rx discard bytes"
955 		    "count on cos4");
956 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
957 		    "rx_discard_packets_cos4", CTLFLAG_RD,
958 		    &softc->rx_port_stats_ext->rx_discard_packets_cos4, "num of rx discard packets"
959 		    "count on cos4");
960 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
961 		    "rx_discard_bytes_cos5", CTLFLAG_RD,
962 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos5, "num of rx discard bytes"
963 		    "count on cos5");
964 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
965 		    "rx_discard_packets_cos5", CTLFLAG_RD,
966 		    &softc->rx_port_stats_ext->rx_discard_packets_cos5, "num of rx discard packets"
967 		    "count on cos5");
968 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
969 		    "rx_discard_bytes_cos6", CTLFLAG_RD,
970 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos6, "num of rx discard bytes"
971 		    "count on cos6");
972 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
973 		    "rx_discard_packets_cos6", CTLFLAG_RD,
974 		    &softc->rx_port_stats_ext->rx_discard_packets_cos6, "num of rx discard packets"
975 		    "count on cos6");
976 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
977 		    "rx_discard_bytes_cos7", CTLFLAG_RD,
978 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos7, "num of rx discard bytes"
979 		    "count on cos7");
980 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
981 		    "rx_discard_packets_cos7", CTLFLAG_RD,
982 		    &softc->rx_port_stats_ext->rx_discard_packets_cos7, "num of rx discard packets"
983 		    "count on cos7");
984 	}
985 
986 
987 	return 0;
988 }
989 
990 int
bnxt_create_rx_sysctls(struct bnxt_softc * softc,int rxr)991 bnxt_create_rx_sysctls(struct bnxt_softc *softc, int rxr)
992 {
993 	struct sysctl_oid *oid;
994 	struct ctx_hw_stats *rx_stats = (void *)softc->rx_stats[rxr].idi_vaddr;
995 	char	name[32];
996 	char	desc[64];
997 
998 	sprintf(name, "rxq%d", rxr);
999 	sprintf(desc, "receive queue %d", rxr);
1000 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
1001 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
1002 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
1003 	if (!oid)
1004 		return ENOMEM;
1005 
1006 	if (BNXT_CHIP_P5_PLUS(softc))
1007 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1008 		    "nq_num_ints", CTLFLAG_RD, &softc->nq_rings[rxr].int_count,
1009 		    "Num Interrupts");
1010 	else
1011 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1012 		    "rq_num_ints", CTLFLAG_RD, &softc->rx_cp_rings[rxr].int_count,
1013 		    "Num Interrupts");
1014 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1015 	    "ucast_pkts", CTLFLAG_RD, &rx_stats->rx_ucast_pkts,
1016 	    "unicast packets received");
1017 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1018 	    "mcast_pkts", CTLFLAG_RD, &rx_stats->rx_mcast_pkts,
1019 	    "multicast packets received");
1020 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1021 	    "bcast_pkts", CTLFLAG_RD, &rx_stats->rx_bcast_pkts,
1022 	    "broadcast packets received");
1023 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1024 	    "discard_pkts", CTLFLAG_RD,
1025 	    &rx_stats->rx_discard_pkts, "discarded receive packets");
1026 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1027 	    "error_pkts", CTLFLAG_RD, &rx_stats->rx_error_pkts,
1028 	    "Error receive packets");
1029 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1030 	    "ucast_bytes", CTLFLAG_RD, &rx_stats->rx_ucast_bytes,
1031 	    "unicast bytes received");
1032 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1033 	    "mcast_bytes", CTLFLAG_RD, &rx_stats->rx_mcast_bytes,
1034 	    "multicast bytes received");
1035 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1036 	    "bcast_bytes", CTLFLAG_RD, &rx_stats->rx_bcast_bytes,
1037 	    "broadcast bytes received");
1038 
1039 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1040 	    "tpa_pkts", CTLFLAG_RD, &rx_stats->tpa_pkts,
1041 	    "TPA packets");
1042 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1043 	    "tpa_bytes", CTLFLAG_RD, &rx_stats->tpa_bytes,
1044 	    "TPA bytes");
1045 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1046 	    "tpa_events", CTLFLAG_RD, &rx_stats->tpa_events,
1047 	    "TPA events");
1048 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1049 	    "tpa_aborts", CTLFLAG_RD, &rx_stats->tpa_aborts,
1050 	    "TPA aborts");
1051 
1052 	return 0;
1053 }
1054 
1055 static char *bnxt_chip_type[] = {
1056 	"ASIC",
1057 	"FPGA",
1058 	"Palladium",
1059 	"Unknown"
1060 };
1061 #define MAX_CHIP_TYPE 3
1062 
bnxt_parse_pkglog(int desired_field,uint8_t * data,size_t datalen)1063 static char *bnxt_parse_pkglog(int desired_field, uint8_t *data, size_t datalen)
1064 {
1065 	char    *retval = NULL;
1066 	char    *p;
1067 	char    *value;
1068 	int     field = 0;
1069 
1070 	if (datalen < 1)
1071 		return NULL;
1072 	/* null-terminate the log data (removing last '\n'): */
1073 	data[datalen - 1] = 0;
1074 	for (p = data; *p != 0; p++) {
1075 		field = 0;
1076 		retval = NULL;
1077 		while (*p != 0 && *p != '\n') {
1078 			value = p;
1079 			while (*p != 0 && *p != '\t' && *p != '\n')
1080 				p++;
1081 			if (field == desired_field)
1082 				retval = value;
1083 			if (*p != '\t')
1084 				break;
1085 			*p = 0;
1086 			field++;
1087 			p++;
1088 		}
1089 		if (*p == 0)
1090 			break;
1091 		*p = 0;
1092 	}
1093 	return retval;
1094 }
1095 
1096 static int
bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)1097 bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)
1098 {
1099 	struct bnxt_softc *softc = arg1;
1100 	struct iflib_dma_info dma_data;
1101 	char *pkglog = NULL;
1102 	char *p;
1103 	char unk[] = "<unknown>";
1104 	char *buf = unk;
1105 	int rc;
1106 	uint16_t ordinal = BNX_DIR_ORDINAL_FIRST;
1107 	uint16_t index;
1108 	uint32_t data_len;
1109 
1110 	rc = bnxt_hwrm_nvm_find_dir_entry(softc, BNX_DIR_TYPE_PKG_LOG,
1111 	    &ordinal, BNX_DIR_EXT_NONE, &index, false,
1112 	    HWRM_NVM_FIND_DIR_ENTRY_INPUT_OPT_ORDINAL_EQ,
1113 	    &data_len, NULL, NULL);
1114 	dma_data.idi_vaddr = NULL;
1115 	if (rc == 0 && data_len) {
1116 		rc = iflib_dma_alloc(softc->ctx, data_len, &dma_data,
1117 		    BUS_DMA_NOWAIT);
1118 		if (rc == 0) {
1119 			rc = bnxt_hwrm_nvm_read(softc, index, 0, data_len,
1120 			    &dma_data);
1121 			if (rc == 0) {
1122 				pkglog = dma_data.idi_vaddr;
1123 				p = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkglog, data_len);
1124 				if (p && *p != 0 && isdigit(*p))
1125 					buf = p;
1126 			}
1127 		} else
1128 			dma_data.idi_vaddr = NULL;
1129 	}
1130 
1131 	rc = sysctl_handle_string(oidp, buf, 0, req);
1132 	if (dma_data.idi_vaddr)
1133 		iflib_dma_free(&dma_data);
1134 	return rc;
1135 }
1136 
1137 static int
bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)1138 bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)
1139 {
1140 	struct bnxt_softc *softc = arg1;
1141 	char buf[16];
1142 	uint8_t	newver[3];
1143 	int rc;
1144 
1145 	sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
1146 	    softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
1147 
1148 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1149 	if (rc || req->newptr == NULL)
1150 		return rc;
1151 	if (sscanf(buf, "%hhu.%hhu.%hhu%*c", &newver[0], &newver[1],
1152 	    &newver[2]) != 3)
1153 		return EINVAL;
1154 	softc->ver_info->hwrm_min_major = newver[0];
1155 	softc->ver_info->hwrm_min_minor = newver[1];
1156 	softc->ver_info->hwrm_min_update = newver[2];
1157 	bnxt_check_hwrm_version(softc);
1158 
1159 	return rc;
1160 }
1161 
1162 int
bnxt_create_ver_sysctls(struct bnxt_softc * softc)1163 bnxt_create_ver_sysctls(struct bnxt_softc *softc)
1164 {
1165 	struct bnxt_ver_info *vi = softc->ver_info;
1166 	struct sysctl_oid *oid = vi->ver_oid;
1167 
1168 	if (!oid)
1169 		return ENOMEM;
1170 
1171 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1172 	    "hwrm_if", CTLFLAG_RD, vi->hwrm_if_ver, 0,
1173 	    "HWRM interface version");
1174 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1175 	    "driver_hwrm_if", CTLFLAG_RD, vi->driver_hwrm_if_ver, 0,
1176 	    "HWRM firmware version");
1177 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1178 	    "mgmt_fw", CTLFLAG_RD, vi->mgmt_fw_ver, 0,
1179 	    "management firmware version");
1180 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1181 	    "netctrl_fw", CTLFLAG_RD, vi->netctrl_fw_ver, 0,
1182 	    "network control firmware version");
1183 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1184 	    "roce_fw", CTLFLAG_RD, vi->roce_fw_ver, 0,
1185 	    "RoCE firmware version");
1186 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1187 	    "fw_ver", CTLFLAG_RD, vi->fw_ver_str, 0,
1188 	    "Firmware version");
1189 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1190 	    "phy", CTLFLAG_RD, vi->phy_ver, 0,
1191 	    "PHY version");
1192 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1193 	    "hwrm_fw_name", CTLFLAG_RD, vi->hwrm_fw_name, 0,
1194 	    "HWRM firmware name");
1195 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1196 	    "mgmt_fw_name", CTLFLAG_RD, vi->mgmt_fw_name, 0,
1197 	    "management firmware name");
1198 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1199 	    "netctrl_fw_name", CTLFLAG_RD, vi->netctrl_fw_name, 0,
1200 	    "network control firmware name");
1201 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1202 	    "roce_fw_name", CTLFLAG_RD, vi->roce_fw_name, 0,
1203 	    "RoCE firmware name");
1204 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1205 	    "phy_vendor", CTLFLAG_RD, vi->phy_vendor, 0,
1206 	    "PHY vendor name");
1207 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1208 	    "phy_partnumber", CTLFLAG_RD, vi->phy_partnumber, 0,
1209 	    "PHY vendor part number");
1210 	SYSCTL_ADD_U16(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1211 	    "chip_num", CTLFLAG_RD, &vi->chip_num, 0, "chip number");
1212 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1213 	    "chip_rev", CTLFLAG_RD, &vi->chip_rev, 0, "chip revision");
1214 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1215 	    "chip_metal", CTLFLAG_RD, &vi->chip_metal, 0, "chip metal number");
1216 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1217 	    "chip_bond_id", CTLFLAG_RD, &vi->chip_bond_id, 0,
1218 	    "chip bond id");
1219 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1220 	    "chip_type", CTLFLAG_RD, vi->chip_type > MAX_CHIP_TYPE ?
1221 	    bnxt_chip_type[MAX_CHIP_TYPE] : bnxt_chip_type[vi->chip_type], 0,
1222 	    "RoCE firmware name");
1223 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1224 	    "package_ver", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1225 	    softc, 0, bnxt_package_ver_sysctl, "A",
1226 	    "currently installed package version");
1227 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1228 	    "hwrm_min_ver", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1229 	    softc, 0, bnxt_hwrm_min_ver_sysctl, "A",
1230 	    "minimum hwrm API vesion to support");
1231 
1232 	return 0;
1233 }
1234 
1235 int
bnxt_create_nvram_sysctls(struct bnxt_nvram_info * ni)1236 bnxt_create_nvram_sysctls(struct bnxt_nvram_info *ni)
1237 {
1238 	struct sysctl_oid *oid = ni->nvm_oid;
1239 
1240 	if (!oid)
1241 		return ENOMEM;
1242 
1243 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1244 	    "mfg_id", CTLFLAG_RD, &ni->mfg_id, 0, "manufacturer id");
1245 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1246 	    "device_id", CTLFLAG_RD, &ni->device_id, 0, "device id");
1247 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1248 	    "sector_size", CTLFLAG_RD, &ni->sector_size, 0, "sector size");
1249 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1250 	    "size", CTLFLAG_RD, &ni->size, 0, "nvram total size");
1251 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1252 	    "reserved_size", CTLFLAG_RD, &ni->reserved_size, 0,
1253 	    "total reserved space");
1254 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1255 	    "available_size", CTLFLAG_RD, &ni->available_size, 0,
1256 	    "total available space");
1257 
1258 	return 0;
1259 }
1260 
1261 static int
bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)1262 bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)
1263 {
1264 	struct bnxt_softc *softc = arg1;
1265 	char buf[HW_HASH_KEY_SIZE*2+1] = {0};
1266 	char *p;
1267 	int i;
1268 	int rc;
1269 
1270 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++)
1271 		p += sprintf(p, "%02x", softc->vnic_info.rss_hash_key[i]);
1272 
1273 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1274 	if (rc || req->newptr == NULL)
1275 		return rc;
1276 
1277 	if (strspn(buf, "0123456789abcdefABCDEF") != (HW_HASH_KEY_SIZE * 2))
1278 		return EINVAL;
1279 
1280 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++) {
1281 		if (sscanf(p, "%02hhx", &softc->vnic_info.rss_hash_key[i]) != 1)
1282 			return EINVAL;
1283 		p += 2;
1284 	}
1285 
1286 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1287 		bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1288 		    softc->vnic_info.rss_hash_type);
1289 
1290 	return rc;
1291 }
1292 
1293 static const char *bnxt_hash_types[] = {"ipv4", "tcp_ipv4", "udp_ipv4", "ipv6",
1294     "tcp_ipv6", "udp_ipv6", NULL};
1295 
bnxt_get_rss_type_str_bit(char * str)1296 static int bnxt_get_rss_type_str_bit(char *str)
1297 {
1298 	int i;
1299 
1300 	for (i=0; bnxt_hash_types[i]; i++)
1301 		if (strcmp(bnxt_hash_types[i], str) == 0)
1302 			return i;
1303 
1304 	return -1;
1305 }
1306 
1307 static int
bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)1308 bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)
1309 {
1310 	struct bnxt_softc *softc = arg1;
1311 	char buf[256] = {0};
1312 	char *p;
1313 	char *next;
1314 	int rc;
1315 	int type;
1316 	int bit;
1317 
1318 	for (type = softc->vnic_info.rss_hash_type; type;
1319 	    type &= ~(1<<bit)) {
1320 		bit = ffs(type) - 1;
1321 		if (bit >= sizeof(bnxt_hash_types) / sizeof(const char *))
1322 			continue;
1323 		if (type != softc->vnic_info.rss_hash_type)
1324 			strcat(buf, ",");
1325 		strcat(buf, bnxt_hash_types[bit]);
1326 	}
1327 
1328 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1329 	if (rc || req->newptr == NULL)
1330 		return rc;
1331 
1332 	for (type = 0, next = buf, p = strsep(&next, " ,"); p;
1333 	    p = strsep(&next, " ,")) {
1334 		bit = bnxt_get_rss_type_str_bit(p);
1335 		if (bit == -1)
1336 			return EINVAL;
1337 		type |= 1<<bit;
1338 	}
1339 	if (type != softc->vnic_info.rss_hash_type) {
1340 		softc->vnic_info.rss_hash_type = type;
1341 		if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1342 			bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1343 			    softc->vnic_info.rss_hash_type);
1344 	}
1345 
1346 	return rc;
1347 }
1348 
1349 static int
bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS)1350 bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS) {
1351 	struct bnxt_softc *softc = arg1;
1352 	int rc;
1353 	int val;
1354 
1355 	if (softc == NULL)
1356 		return EBUSY;
1357 
1358 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_BD_STALL);
1359 	rc = sysctl_handle_int(oidp, &val, 0, req);
1360 	if (rc || !req->newptr)
1361 		return rc;
1362 
1363 	if (val)
1364 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_BD_STALL;
1365 	else
1366 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_BD_STALL;
1367 
1368 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1369 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1370 
1371 	return rc;
1372 }
1373 
1374 static int
bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS)1375 bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS) {
1376 	struct bnxt_softc *softc = arg1;
1377 	int rc;
1378 	int val;
1379 
1380 	if (softc == NULL)
1381 		return EBUSY;
1382 
1383 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_VLAN_STRIP);
1384 	rc = sysctl_handle_int(oidp, &val, 0, req);
1385 	if (rc || !req->newptr)
1386 		return rc;
1387 
1388 	if (val)
1389 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_VLAN_STRIP;
1390 	else
1391 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_VLAN_STRIP;
1392 
1393 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1394 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1395 
1396 	return rc;
1397 }
1398 
1399 static int
bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS)1400 bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS) {
1401 	struct bnxt_softc *softc = arg1;
1402 	int rc;
1403 	int val;
1404 
1405 	if (softc == NULL)
1406 		return EBUSY;
1407 
1408 	val = softc->rx_coal_usecs;
1409 	rc = sysctl_handle_int(oidp, &val, 0, req);
1410 	if (rc || !req->newptr)
1411 		return rc;
1412 
1413 	softc->rx_coal_usecs = val;
1414 	rc = bnxt_hwrm_set_coal(softc);
1415 
1416 	return rc;
1417 }
1418 
1419 static int
bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS)1420 bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS) {
1421 	struct bnxt_softc *softc = arg1;
1422 	int rc;
1423 	int val;
1424 
1425 	if (softc == NULL)
1426 		return EBUSY;
1427 
1428 	val = softc->rx_coal_frames;
1429 	rc = sysctl_handle_int(oidp, &val, 0, req);
1430 	if (rc || !req->newptr)
1431 		return rc;
1432 
1433 	softc->rx_coal_frames = val;
1434 	rc = bnxt_hwrm_set_coal(softc);
1435 
1436 	return rc;
1437 }
1438 
1439 static int
bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS)1440 bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1441 	struct bnxt_softc *softc = arg1;
1442 	int rc;
1443 	int val;
1444 
1445 	if (softc == NULL)
1446 		return EBUSY;
1447 
1448 	val = softc->rx_coal_usecs_irq;
1449 	rc = sysctl_handle_int(oidp, &val, 0, req);
1450 	if (rc || !req->newptr)
1451 		return rc;
1452 
1453 	softc->rx_coal_usecs_irq = val;
1454 	rc = bnxt_hwrm_set_coal(softc);
1455 
1456 	return rc;
1457 }
1458 
1459 static int
bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS)1460 bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS) {
1461 	struct bnxt_softc *softc = arg1;
1462 	int rc;
1463 	int val;
1464 
1465 	if (softc == NULL)
1466 		return EBUSY;
1467 
1468 	val = softc->rx_coal_frames_irq;
1469 	rc = sysctl_handle_int(oidp, &val, 0, req);
1470 	if (rc || !req->newptr)
1471 		return rc;
1472 
1473 	softc->rx_coal_frames_irq = val;
1474 	rc = bnxt_hwrm_set_coal(softc);
1475 
1476 	return rc;
1477 }
1478 
1479 static int
bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS)1480 bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS) {
1481 	struct bnxt_softc *softc = arg1;
1482 	int rc;
1483 	int val;
1484 
1485 	if (softc == NULL)
1486 		return EBUSY;
1487 
1488 	val = softc->tx_coal_usecs;
1489 	rc = sysctl_handle_int(oidp, &val, 0, req);
1490 	if (rc || !req->newptr)
1491 		return rc;
1492 
1493 	softc->tx_coal_usecs = val;
1494 	rc = bnxt_hwrm_set_coal(softc);
1495 
1496 	return rc;
1497 }
1498 
1499 static int
bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS)1500 bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS) {
1501 	struct bnxt_softc *softc = arg1;
1502 	int rc;
1503 	int val;
1504 
1505 	if (softc == NULL)
1506 		return EBUSY;
1507 
1508 	val = softc->tx_coal_frames;
1509 	rc = sysctl_handle_int(oidp, &val, 0, req);
1510 	if (rc || !req->newptr)
1511 		return rc;
1512 
1513 	softc->tx_coal_frames = val;
1514 	rc = bnxt_hwrm_set_coal(softc);
1515 
1516 	return rc;
1517 }
1518 
1519 static int
bnxt_set_coal_tx_usecs_irq(SYSCTL_HANDLER_ARGS)1520 bnxt_set_coal_tx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1521 	struct bnxt_softc *softc = arg1;
1522 	int rc;
1523 	int val;
1524 
1525 	if (softc == NULL)
1526 		return EBUSY;
1527 
1528 	val = softc->tx_coal_usecs_irq;
1529 	rc = sysctl_handle_int(oidp, &val, 0, req);
1530 	if (rc || !req->newptr)
1531 		return rc;
1532 
1533 	softc->tx_coal_usecs_irq = val;
1534 	rc = bnxt_hwrm_set_coal(softc);
1535 
1536 	return rc;
1537 }
1538 
1539 static int
bnxt_set_coal_tx_frames_irq(SYSCTL_HANDLER_ARGS)1540 bnxt_set_coal_tx_frames_irq(SYSCTL_HANDLER_ARGS) {
1541 	struct bnxt_softc *softc = arg1;
1542 	int rc;
1543 	int val;
1544 
1545 	if (softc == NULL)
1546 		return EBUSY;
1547 
1548 	val = softc->tx_coal_frames_irq;
1549 	rc = sysctl_handle_int(oidp, &val, 0, req);
1550 	if (rc || !req->newptr)
1551 		return rc;
1552 
1553 	softc->tx_coal_frames_irq = val;
1554 	rc = bnxt_hwrm_set_coal(softc);
1555 
1556 	return rc;
1557 }
1558 
1559 static
simulate_reset(struct bnxt_softc * bp,char * fwcli_string)1560 void simulate_reset(struct bnxt_softc *bp, char *fwcli_string)
1561 {
1562 	struct hwrm_dbg_fw_cli_input req = {0};
1563 	int rc = 0;
1564 
1565 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_FW_CLI);
1566 	req.cmpl_ring = -1;
1567 	req.target_id = -1;
1568 	req.cli_cmd_len = strlen(fwcli_string);
1569 	req.host_buf_len = 64 * 1024;
1570 	strcpy((char *)req.cli_cmd, fwcli_string);
1571 
1572 	BNXT_HWRM_LOCK(bp);
1573 	rc = _hwrm_send_message(bp, &req, sizeof(req));
1574 	if (rc) {
1575 		device_printf(bp->dev, " Manual FW fault failed, rc:%x\n", rc);
1576 	}
1577 	BNXT_HWRM_UNLOCK(bp);
1578 }
1579 
1580 static int
bnxt_reset_ctrl(SYSCTL_HANDLER_ARGS)1581 bnxt_reset_ctrl(SYSCTL_HANDLER_ARGS) {
1582 	struct bnxt_softc *softc = arg1;
1583 	int rc = 0;
1584 	char buf[50] = {0};
1585 
1586 	if (softc == NULL)
1587 		return EBUSY;
1588 
1589 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1590 	if (rc || req->newptr == NULL)
1591 		return rc;
1592 
1593 	if (BNXT_CHIP_P5_PLUS(softc))
1594 		simulate_reset(softc, buf);
1595 
1596 	return rc;
1597 }
1598 
1599 int
bnxt_create_config_sysctls_pre(struct bnxt_softc * softc)1600 bnxt_create_config_sysctls_pre(struct bnxt_softc *softc)
1601 {
1602 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1603 	struct sysctl_oid_list *children;
1604 
1605 	children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));
1606 
1607 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_key",
1608 	    CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1609 	    bnxt_rss_key_sysctl, "A", "RSS key");
1610 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_type",
1611 	    CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1612 	    bnxt_rss_type_sysctl, "A", "RSS type bits");
1613 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_stall",
1614 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1615 	    bnxt_rx_stall_sysctl, "I",
1616 	    "buffer rx packets in hardware until the host posts new buffers");
1617 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_strip",
1618 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1619 	    bnxt_vlan_strip_sysctl, "I", "strip VLAN tag in the RX path");
1620 	SYSCTL_ADD_CONST_STRING(ctx, children, OID_AUTO, "if_name", CTLFLAG_RD,
1621 		if_name(iflib_get_ifp(softc->ctx)), "interface name");
1622 
1623 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs",
1624 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1625 	    bnxt_set_coal_rx_usecs, "I", "interrupt coalescing Rx Usecs");
1626 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames",
1627 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1628 	    bnxt_set_coal_rx_frames, "I", "interrupt coalescing Rx Frames");
1629 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs_irq",
1630 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1631 	    bnxt_set_coal_rx_usecs_irq, "I",
1632 	    "interrupt coalescing Rx Usecs IRQ");
1633 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames_irq",
1634 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1635 	    bnxt_set_coal_rx_frames_irq, "I",
1636 	    "interrupt coalescing Rx Frames IRQ");
1637 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs",
1638 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1639 	    bnxt_set_coal_tx_usecs, "I", "interrupt coalescing Tx Usces");
1640 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames",
1641 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1642 	    bnxt_set_coal_tx_frames, "I", "interrupt coalescing Tx Frames");
1643 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs_irq",
1644 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1645 	    bnxt_set_coal_tx_usecs_irq, "I",
1646 	    "interrupt coalescing Tx Usecs IRQ");
1647 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames_irq",
1648 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1649 	    bnxt_set_coal_tx_frames_irq, "I",
1650 	    "interrupt coalescing Tx Frames IRQ");
1651 	SYSCTL_ADD_U32(ctx, children, OID_AUTO, "flags", CTLFLAG_RD,
1652 		&softc->flags, 0, "flags");
1653 	SYSCTL_ADD_U64(ctx, children, OID_AUTO, "fw_cap", CTLFLAG_RD,
1654 		&softc->fw_cap, 0, "FW caps");
1655 
1656 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO,
1657 	    "reset_ctrl", CTLTYPE_STRING | CTLFLAG_RWTUN, softc,
1658 	    0, bnxt_reset_ctrl, "A",
1659 	    "Issue controller reset: 0 / 1");
1660 	return 0;
1661 }
1662 
1663 #define BNXT_HW_LRO_FN(fn_name, arg)			                   \
1664 static int						                   \
1665 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1666 	struct bnxt_softc *softc = arg1;		                   \
1667 	int rc;						                   \
1668 	int val;					                   \
1669 							                   \
1670 	if (softc == NULL)				                   \
1671 		return EBUSY;				                   \
1672 							                   \
1673 	val = softc->hw_lro.arg;			                   \
1674 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1675 	if (rc || !req->newptr)				                   \
1676 		return rc;				                   \
1677 							                   \
1678 	if ((if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)) \
1679 		return EBUSY;				                   \
1680 							                   \
1681 	if (!(softc->flags & BNXT_FLAG_TPA))				   \
1682 		return EINVAL;						   \
1683 							                   \
1684 	softc->hw_lro.arg = val;			                   \
1685 	bnxt_validate_hw_lro_settings(softc);		                   \
1686 	rc = bnxt_hwrm_vnic_tpa_cfg(softc);		                   \
1687 							                   \
1688 	return rc;					                   \
1689 }
1690 
BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable,enable)1691 BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable, enable)
1692 BNXT_HW_LRO_FN(bnxt_hw_lro_set_mode, is_mode_gro)
1693 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_agg_segs, max_agg_segs)
1694 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_aggs, max_aggs)
1695 BNXT_HW_LRO_FN(bnxt_hw_lro_set_min_agg_len, min_agg_len)
1696 
1697 #define BNXT_FLOW_CTRL_FN(fn_name, arg)			                   \
1698 static int						                   \
1699 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1700 	struct bnxt_softc *softc = arg1;		                   \
1701 	int rc;						                   \
1702 	int val;					                   \
1703 							                   \
1704 	if (softc == NULL)				                   \
1705 		return EBUSY;				                   \
1706 							                   \
1707 	val = softc->link_info.flow_ctrl.arg;			           \
1708 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1709 	if (rc || !req->newptr)				                   \
1710 		return rc;				                   \
1711 							                   \
1712 	if (val)					                   \
1713 	   	val = 1; 				                   \
1714 	        					                   \
1715 	if (softc->link_info.flow_ctrl.arg != val) {		           \
1716 		softc->link_info.flow_ctrl.arg = val;		           \
1717 		rc = bnxt_hwrm_set_link_setting(softc, true, false, false);\
1718 		rc = bnxt_hwrm_port_phy_qcfg(softc);			   \
1719 	}						                   \
1720 							                   \
1721 	return rc;					                   \
1722 }
1723 
1724 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_tx, tx)
1725 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_rx, rx)
1726 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_autoneg, autoneg)
1727 int
1728 bnxt_create_pause_fc_sysctls(struct bnxt_softc *softc)
1729 {
1730 	struct sysctl_oid *oid = softc->flow_ctrl_oid;
1731 
1732 	if (!oid)
1733 		return ENOMEM;
1734 
1735 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1736 	    "tx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1737 	    bnxt_flow_ctrl_tx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1738 
1739 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1740 	    "rx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1741 	    bnxt_flow_ctrl_rx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1742 
1743 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1744 	    "autoneg", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1745 	    0, bnxt_flow_ctrl_autoneg, "A",
1746 	    "Enable or Disable Autoneg Flow Ctrl: 0 / 1");
1747 
1748 	return 0;
1749 }
1750 
1751 int
bnxt_create_hw_lro_sysctls(struct bnxt_softc * softc)1752 bnxt_create_hw_lro_sysctls(struct bnxt_softc *softc)
1753 {
1754 	struct sysctl_oid *oid = softc->hw_lro_oid;
1755 
1756 	if (!oid)
1757 		return ENOMEM;
1758 
1759 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1760 	    "enable", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1761 	    0, bnxt_hw_lro_enable_disable, "A",
1762 	    "Enable or Disable HW LRO: 0 / 1");
1763 
1764 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1765 	    "gro_mode", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1766 	    0, bnxt_hw_lro_set_mode, "A",
1767 	    "Set mode: 1 = GRO mode, 0 = RSC mode");
1768 
1769 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1770 	    "max_agg_segs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1771 	    softc, 0, bnxt_hw_lro_set_max_agg_segs, "A",
1772 	    "Set Max Agg Seg Value (unit is Log2): "
1773 	    "0 (= 1 seg) / 1 (= 2 segs) /  ... / 31 (= 2^31 segs)");
1774 
1775         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1776 	    "max_aggs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1777 	    softc, 0, bnxt_hw_lro_set_max_aggs, "A",
1778 	    "Set Max Aggs Value (unit is Log2): "
1779 	    "0 (= 1 agg) / 1 (= 2 aggs) /  ... / 7 (= 2^7 segs)");
1780 
1781 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1782 	    "min_agg_len", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1783 	    softc, 0, bnxt_hw_lro_set_min_agg_len, "A",
1784 	    "Min Agg Len: 1 to 9000");
1785 
1786 	return 0;
1787 }
1788 
1789 static int
bnxt_dcb_dcbx_cap(SYSCTL_HANDLER_ARGS)1790 bnxt_dcb_dcbx_cap(SYSCTL_HANDLER_ARGS)
1791 {
1792 	struct bnxt_softc *softc = arg1;
1793 	int val;
1794 	int rc;
1795 
1796 	val = bnxt_dcb_getdcbx(softc);
1797 	rc = sysctl_handle_int(oidp, &val, 0, req);
1798 	if (rc || !req->newptr)
1799 		return rc;
1800 
1801 	bnxt_dcb_setdcbx(softc, val);
1802 
1803 	return rc;
1804 }
1805 
1806 static char
bnxt_ets_tsa_to_str(struct bnxt_softc * softc,uint32_t tc)1807 bnxt_ets_tsa_to_str(struct bnxt_softc *softc, uint32_t tc)
1808 {
1809 	switch (softc->ieee_ets->tc_tsa[tc]) {
1810 	case BNXT_IEEE_8021QAZ_TSA_STRICT:
1811 		return 's';
1812 	case BNXT_IEEE_8021QAZ_TSA_ETS:
1813 		return 'e';
1814 	default:
1815 		return 'X';
1816 
1817 	}
1818 }
1819 
1820 static uint32_t
bnxt_ets_str_to_tsa(char tsa_str)1821 bnxt_ets_str_to_tsa(char tsa_str)
1822 {
1823 	switch (tsa_str) {
1824 	case 's':
1825 		return BNXT_IEEE_8021QAZ_TSA_STRICT;
1826 	case 'e':
1827 		return BNXT_IEEE_8021QAZ_TSA_ETS;
1828 	default:
1829 		return -1;
1830 	}
1831 }
1832 
1833 static int
bnxt_ets_get_val(struct bnxt_softc * softc,uint32_t type,uint32_t tc)1834 bnxt_ets_get_val(struct bnxt_softc *softc, uint32_t type, uint32_t tc)
1835 {
1836 	switch (type) {
1837 	case BNXT_TYPE_ETS_TSA:
1838 		if (softc->ieee_ets)
1839 			return softc->ieee_ets->tc_tsa[tc];
1840 		break;
1841 	case BNXT_TYPE_ETS_PRI2TC:
1842 		if (softc->ieee_ets)
1843 			return softc->ieee_ets->prio_tc[tc];
1844 		break;
1845 	case BNXT_TYPE_ETS_TCBW:
1846 		if (softc->ieee_ets)
1847 			return softc->ieee_ets->tc_tx_bw[tc];
1848 		break;
1849 	default:
1850 		break;
1851 	}
1852 
1853 	return -1;
1854 }
1855 
1856 static void
bnxt_pfc_get_string(struct bnxt_softc * softc,char * buf,struct bnxt_ieee_pfc * pfc)1857 bnxt_pfc_get_string(struct bnxt_softc *softc, char *buf, struct bnxt_ieee_pfc *pfc)
1858 {
1859 	uint32_t i;
1860 	bool found = false;
1861 
1862 	for (i = 0; i < BNXT_IEEE_8021QAZ_MAX_TCS; i++) {
1863 		if (pfc->pfc_en & (1 << i)) {
1864 			if (found)
1865 				buf += sprintf(buf, ", ");
1866 			buf += sprintf(buf, "%d", i);
1867 			found = true;
1868 		}
1869 	}
1870 
1871 	if (!found)
1872 		buf += sprintf(buf, "none");
1873 }
1874 
bnxt_get_tlv_selector_str(uint8_t selector)1875 static const char *bnxt_get_tlv_selector_str(uint8_t selector)
1876 {
1877 	switch (selector) {
1878 	case BNXT_IEEE_8021QAZ_APP_SEL_ETHERTYPE:
1879 		return "Ethertype";
1880 	case BNXT_IEEE_8021QAZ_APP_SEL_DGRAM:
1881 		return "UDP or DCCP";
1882 	case BNXT_IEEE_8021QAZ_APP_SEL_DSCP:
1883 		return "DSCP";
1884 	default:
1885 		return "Unknown";
1886 	}
1887 }
1888 
1889 static void
bnxt_app_tlv_get_string(struct sbuf * sb,struct bnxt_dcb_app * app,int num)1890 bnxt_app_tlv_get_string(struct sbuf *sb, struct bnxt_dcb_app *app, int num)
1891 {
1892 	int i;
1893 
1894 	if (num == 0) {
1895 		sbuf_printf(sb, " None");
1896 		return;
1897 	}
1898 
1899 	sbuf_putc(sb, '\n');
1900 	for (i = 0; i < num; i++) {
1901 		sbuf_printf(sb, "\tAPP#%0d:\tpri: %d,\tSel: %d,\t%s: %d\n",
1902 		    i,
1903 		    app[i].priority,
1904 		    app[i].selector,
1905 		    bnxt_get_tlv_selector_str(app[i].selector),
1906 		    app[i].protocol);
1907 	}
1908 }
1909 
1910 static void
bnxt_ets_get_string(struct bnxt_softc * softc,char * buf)1911 bnxt_ets_get_string(struct bnxt_softc *softc, char *buf)
1912 {
1913 	uint32_t type, i;
1914 
1915 	type = BNXT_TYPE_ETS_TSA;
1916 	for (type = 0; type < BNXT_TYPE_ETS_MAX; type++) {
1917 		for (i = 0; i < BNXT_IEEE_8021QAZ_MAX_TCS; i++) {
1918 			if (i == 0)
1919 				buf += sprintf(buf, "%s:", BNXT_ETS_TYPE_STR[type]);
1920 
1921 			if (!softc->ieee_ets)
1922 				buf += sprintf(buf, "x");
1923 			else if (type == BNXT_TYPE_ETS_TSA)
1924 				buf += sprintf(buf, "%c", bnxt_ets_tsa_to_str(softc, i));
1925 			else
1926 				buf += sprintf(buf, "%d", bnxt_ets_get_val(softc, type, i));
1927 
1928 			if (i != BNXT_IEEE_8021QAZ_MAX_TCS - 1)
1929 				buf += sprintf(buf, ",");
1930 		}
1931 		if (type != BNXT_TYPE_ETS_MAX - 1)
1932 			buf += sprintf(buf, "#");
1933 	}
1934 }
1935 
1936 static int
bnxt_dcb_list_app(SYSCTL_HANDLER_ARGS)1937 bnxt_dcb_list_app(SYSCTL_HANDLER_ARGS)
1938 {
1939 	struct sbuf sb;
1940 	struct bnxt_dcb_app app[128] = {0};
1941 	struct bnxt_softc *softc = arg1;
1942 	int rc, num_inputs = 0;
1943 
1944 	sbuf_new_for_sysctl(&sb, NULL, 128, req);
1945 	bnxt_dcb_ieee_listapp(softc, app, nitems(app), &num_inputs);
1946 	bnxt_app_tlv_get_string(&sb, app, num_inputs);
1947 	rc = sbuf_finish(&sb);
1948 	sbuf_delete(&sb);
1949 	return rc;
1950 }
1951 
1952 static int
bnxt_dcb_del_app(SYSCTL_HANDLER_ARGS)1953 bnxt_dcb_del_app(SYSCTL_HANDLER_ARGS)
1954 {
1955 	struct bnxt_softc *softc = arg1;
1956 	struct bnxt_dcb_app app = {0};
1957 	char buf[256] = {0};
1958 	int rc, num_inputs;
1959 
1960 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1961 	if (rc || req->newptr == NULL)
1962 		return rc;
1963 
1964 	num_inputs = sscanf(buf, "%hhu,%hhu,%hd", &app.priority, &app.selector, &app.protocol);
1965 
1966 	if (num_inputs != 3) {
1967 		device_printf(softc->dev,
1968 			      "Invalid app tlv syntax, inputs = %d\n", num_inputs);
1969 		return EINVAL;
1970 	}
1971 
1972 	bnxt_dcb_ieee_delapp(softc, &app);
1973 
1974 	return rc;
1975 }
1976 static int
bnxt_dcb_set_app(SYSCTL_HANDLER_ARGS)1977 bnxt_dcb_set_app(SYSCTL_HANDLER_ARGS)
1978 {
1979 	struct bnxt_softc *softc = arg1;
1980 	struct bnxt_dcb_app app = {0};
1981 	char buf[256] = {0};
1982 	int rc, num_inputs;
1983 
1984 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1985 	if (rc || req->newptr == NULL)
1986 		return rc;
1987 
1988 	num_inputs = sscanf(buf, "%hhu,%hhu,%hd", &app.priority, &app.selector, &app.protocol);
1989 
1990 	if (num_inputs != 3) {
1991 		device_printf(softc->dev,
1992 			      "Invalid app tlv syntax, inputs = %d\n", num_inputs);
1993 		return EINVAL;
1994 	}
1995 
1996 	bnxt_dcb_ieee_setapp(softc, &app);
1997 
1998 	return rc;
1999 }
2000 
2001 static int
bnxt_dcb_pfc(SYSCTL_HANDLER_ARGS)2002 bnxt_dcb_pfc(SYSCTL_HANDLER_ARGS)
2003 {
2004 	struct bnxt_softc *softc = arg1;
2005 	struct bnxt_ieee_pfc pfc = {0};
2006 	int rc, i, num_inputs;
2007 	char buf[256] = {0};
2008 	int pri_mask = 0;
2009 	char pri[8];
2010 
2011 	rc = bnxt_dcb_ieee_getpfc(softc, &pfc);
2012 	if (!rc)
2013 		bnxt_pfc_get_string(softc, buf, &pfc);
2014 	else
2015 		sprintf(buf, "## getpfc failed with error %d ##", rc);
2016 
2017 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2018 	if (rc || req->newptr == NULL)
2019 		return rc;
2020 
2021 	/* Check for 'none' string first */
2022 	if (sscanf(buf,  "%s", buf) == 1) {
2023 		if (strncmp(buf, "none", 8) == 0) {
2024 			goto configure;
2025 		}
2026 	}
2027 	num_inputs = sscanf(buf, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
2028 			    &pri[0], &pri[1], &pri[2], &pri[3], &pri[4],
2029 			    &pri[5], &pri[6], &pri[7]);
2030 
2031 	if (num_inputs < 1 || num_inputs > 8) {
2032 		device_printf(softc->dev,
2033 			      "Invalid pfc syntax, inputs = %d\n", num_inputs);
2034 		return EINVAL;
2035 	}
2036 
2037 	for (i = 0; i < num_inputs; i++) {
2038 		if (pri[i] > 7 || pri[i] < 0) {
2039 			device_printf(softc->dev,
2040 				      "Invalid priority %d. Valid priorties are "
2041 				      "from 0 to 7 and string \"none\".\n", pri[i]);
2042 			return EINVAL;
2043 		}
2044 
2045 		pri_mask |= (1 << pri[i]) & 0xFF;
2046 	}
2047 
2048 configure:
2049 	pfc.pfc_en = pri_mask;
2050 	rc = bnxt_dcb_ieee_setpfc(softc, &pfc);
2051 	if (rc)
2052 		device_printf(softc->dev,
2053 			      "setpfc failed with status %d\n", rc);
2054 	return rc;
2055 }
2056 
2057 static int
bnxt_dcb_ets(SYSCTL_HANDLER_ARGS)2058 bnxt_dcb_ets(SYSCTL_HANDLER_ARGS)
2059 {
2060 	struct bnxt_softc *softc = arg1;
2061 	struct bnxt_ieee_ets ets = {0};
2062 	int rc = 0, i, num_inputs;
2063 	char buf[256] = {0};
2064 	char tsa[8];
2065 
2066 	rc = bnxt_dcb_ieee_getets(softc, &ets);
2067 	if (!rc)
2068 		bnxt_ets_get_string(softc, buf);
2069 	else
2070 		sprintf(buf, "## getets failed with error %d ##", rc);
2071 
2072 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2073 	if (rc || req->newptr == NULL)
2074 		return rc;
2075 
2076 	num_inputs = sscanf(buf,  "tsa:%c,%c,%c,%c,%c,%c,%c,%c#"
2077 			    "pri2tc:%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu#"
2078 			    "tcbw:%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
2079 			    &tsa[0], &tsa[1], &tsa[2], &tsa[3], &tsa[4], &tsa[5], &tsa[6], &tsa[7],
2080 			    &ets.prio_tc[0], &ets.prio_tc[1], &ets.prio_tc[2], &ets.prio_tc[3],
2081 			    &ets.prio_tc[4], &ets.prio_tc[5], &ets.prio_tc[6], &ets.prio_tc[7],
2082 			    &ets.tc_tx_bw[0], &ets.tc_tx_bw[1], &ets.tc_tx_bw[2], &ets.tc_tx_bw[3],
2083 			    &ets.tc_tx_bw[4], &ets.tc_tx_bw[5], &ets.tc_tx_bw[6], &ets.tc_tx_bw[7]);
2084 
2085 	if (num_inputs != 24)
2086 		return EINVAL;
2087 
2088 	for ( i= 0; i < 8; i++)
2089 		ets.tc_tsa[i] = bnxt_ets_str_to_tsa(tsa[i]);
2090 
2091 	rc = bnxt_dcb_ieee_setets(softc, &ets);
2092 
2093 	return rc;
2094 }
2095 
2096 int
bnxt_create_dcb_sysctls(struct bnxt_softc * softc)2097 bnxt_create_dcb_sysctls(struct bnxt_softc *softc)
2098 {
2099 	struct sysctl_oid *oid = softc->dcb_oid;
2100 
2101 	if (!oid)
2102 		return ENOMEM;
2103 
2104 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
2105 	    "dcbx_cap", CTLTYPE_INT | CTLFLAG_RWTUN, softc,
2106 	    0, bnxt_dcb_dcbx_cap, "A",
2107 	    "Enable DCB Capability Exchange Protocol (DCBX) capabilities");
2108 
2109 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "ets",
2110 	    CTLTYPE_STRING | CTLFLAG_RWTUN, softc, 0,
2111 	    bnxt_dcb_ets, "A", "Enhanced Transmission Selection (ETS)");
2112 
2113 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "pfc",
2114 	    CTLTYPE_STRING | CTLFLAG_RWTUN, softc, 0,
2115 	    bnxt_dcb_pfc, "A", "Enhanced Transmission Selection (ETS)");
2116 
2117 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "set_apptlv",
2118 	    CTLTYPE_STRING | CTLFLAG_WR, softc, 0,
2119 	    bnxt_dcb_set_app, "A", "Set App TLV");
2120 
2121 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "del_apptlv",
2122 	    CTLTYPE_STRING | CTLFLAG_WR, softc, 0,
2123 	    bnxt_dcb_del_app, "A", "Delete App TLV");
2124 
2125 	SYSCTL_ADD_PROC(&softc->dcb_ctx, SYSCTL_CHILDREN(oid), OID_AUTO, "list_apptlv",
2126 	    CTLTYPE_STRING | CTLFLAG_RD, softc, 0,
2127 	    bnxt_dcb_list_app, "A", "List all App TLVs");
2128 
2129 	return 0;
2130 }
2131 
2132 int
bnxt_create_config_sysctls_post(struct bnxt_softc * softc)2133 bnxt_create_config_sysctls_post(struct bnxt_softc *softc)
2134 {
2135 	/* Nothing for now, meant for future expansion */
2136 	return 0;
2137 }
2138