xref: /freebsd/sys/dev/bnxt/bnxt_en/bnxt_sysctl.c (revision c972c5acbac472a5dc797856f39f478862b6c6ea)
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/types.h>
30 #include <sys/sysctl.h>
31 #include <sys/ctype.h>
32 #include <linux/delay.h>
33 
34 #include "bnxt.h"
35 #include "bnxt_hwrm.h"
36 #include "bnxt_sysctl.h"
37 
38 DEFINE_MUTEX(tmp_mutex); /* mutex lock for driver */
39 extern void bnxt_fw_reset(struct bnxt_softc *bp);
40 extern void bnxt_queue_sp_work(struct bnxt_softc *bp);
41 extern void
42 process_nq(struct bnxt_softc *softc, uint16_t nqid);
43 /*
44  * We want to create:
45  * dev.bnxt.0.hwstats.txq0
46  * dev.bnxt.0.hwstats.txq0.txmbufs
47  * dev.bnxt.0.hwstats.rxq0
48  * dev.bnxt.0.hwstats.txq0.rxmbufs
49  * so the hwstats ctx list needs to be created in attach_post and populated
50  * during init.
51  *
52  * Then, it needs to be cleaned up in stop.
53  */
54 
55 int
bnxt_init_sysctl_ctx(struct bnxt_softc * softc)56 bnxt_init_sysctl_ctx(struct bnxt_softc *softc)
57 {
58 	struct sysctl_ctx_list *ctx;
59 
60 	sysctl_ctx_init(&softc->hw_stats);
61 	ctx = device_get_sysctl_ctx(softc->dev);
62 	softc->hw_stats_oid = SYSCTL_ADD_NODE(ctx,
63 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
64 	    "hwstats", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware statistics");
65 	if (!softc->hw_stats_oid) {
66 		sysctl_ctx_free(&softc->hw_stats);
67 		return ENOMEM;
68 	}
69 
70 	sysctl_ctx_init(&softc->ver_info->ver_ctx);
71 	ctx = device_get_sysctl_ctx(softc->dev);
72 	softc->ver_info->ver_oid = SYSCTL_ADD_NODE(ctx,
73 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
74 	    "ver", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
75 	    "hardware/firmware version information");
76 	if (!softc->ver_info->ver_oid) {
77 		sysctl_ctx_free(&softc->ver_info->ver_ctx);
78 		return ENOMEM;
79 	}
80 
81 	if (BNXT_PF(softc)) {
82 		sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
83 		ctx = device_get_sysctl_ctx(softc->dev);
84 		softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
85 		    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
86 		    "nvram", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
87 		    "nvram information");
88 		if (!softc->nvm_info->nvm_oid) {
89 			sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
90 			return ENOMEM;
91 		}
92 	}
93 
94 	sysctl_ctx_init(&softc->hw_lro_ctx);
95 	ctx = device_get_sysctl_ctx(softc->dev);
96 	softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
97 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
98 	    "hw_lro", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware lro");
99 	if (!softc->hw_lro_oid) {
100 		sysctl_ctx_free(&softc->hw_lro_ctx);
101 		return ENOMEM;
102 	}
103 
104 	sysctl_ctx_init(&softc->flow_ctrl_ctx);
105 	ctx = device_get_sysctl_ctx(softc->dev);
106 	softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
107 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
108 	    "fc", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "flow ctrl");
109 	if (!softc->flow_ctrl_oid) {
110 		sysctl_ctx_free(&softc->flow_ctrl_ctx);
111 		return ENOMEM;
112 	}
113 
114 	sysctl_ctx_init(&softc->dcb_ctx);
115 	ctx = device_get_sysctl_ctx(softc->dev);
116 	softc->dcb_oid = SYSCTL_ADD_NODE(ctx,
117 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
118 	    "dcb", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Data Center Bridging");
119 	if (!softc->dcb_oid) {
120 		sysctl_ctx_free(&softc->dcb_ctx);
121 		return ENOMEM;
122 	}
123 
124 	return 0;
125 }
126 
127 int
bnxt_free_sysctl_ctx(struct bnxt_softc * softc)128 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
129 {
130 	int orc;
131 	int rc = 0;
132 
133 	if (softc->hw_stats_oid != NULL) {
134 		orc = sysctl_ctx_free(&softc->hw_stats);
135 		if (orc)
136 			rc = orc;
137 		else
138 			softc->hw_stats_oid = NULL;
139 	}
140 	if (softc->ver_info->ver_oid != NULL) {
141 		orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
142 		if (orc)
143 			rc = orc;
144 		else
145 			softc->ver_info->ver_oid = NULL;
146 	}
147 	if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
148 		orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
149 		if (orc)
150 			rc = orc;
151 		else
152 			softc->nvm_info->nvm_oid = NULL;
153 	}
154 	if (softc->hw_lro_oid != NULL) {
155 		orc = sysctl_ctx_free(&softc->hw_lro_ctx);
156 		if (orc)
157 			rc = orc;
158 		else
159 			softc->hw_lro_oid = NULL;
160 	}
161 
162 	if (softc->flow_ctrl_oid != NULL) {
163 		orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
164 		if (orc)
165 			rc = orc;
166 		else
167 			softc->flow_ctrl_oid = NULL;
168 	}
169 
170 	if (softc->dcb_oid != NULL) {
171 		orc = sysctl_ctx_free(&softc->dcb_ctx);
172 		if (orc)
173 			rc = orc;
174 		else
175 			softc->dcb_oid = NULL;
176 	}
177 
178 	return rc;
179 }
180 
181 int
bnxt_create_tx_sysctls(struct bnxt_softc * softc,int txr)182 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
183 {
184 	struct sysctl_oid *oid;
185 	struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats[txr].idi_vaddr;
186 	char	name[32];
187 	char	desc[64];
188 
189 	sprintf(name, "txq%d", txr);
190 	sprintf(desc, "transmit queue %d", txr);
191 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
192 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
193 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
194 	if (!oid)
195 		return ENOMEM;
196 
197 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
198 	    "ucast_pkts", CTLFLAG_RD, &tx_stats->tx_ucast_pkts,
199 	    "unicast packets sent");
200 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
201 	    "mcast_pkts", CTLFLAG_RD, &tx_stats->tx_mcast_pkts,
202 	    "multicast packets sent");
203 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
204 	    "bcast_pkts", CTLFLAG_RD, &tx_stats->tx_bcast_pkts,
205 	    "broadcast packets sent");
206 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
207 	    "discard_pkts", CTLFLAG_RD,
208 	    &tx_stats->tx_discard_pkts, "discarded transmit packets");
209 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
210 	    "error_pkts", CTLFLAG_RD, &tx_stats->tx_error_pkts,
211 	    "Error transmit packets");
212 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
213 	    "ucast_bytes", CTLFLAG_RD, &tx_stats->tx_ucast_bytes,
214 	    "unicast bytes sent");
215 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
216 	    "mcast_bytes", CTLFLAG_RD, &tx_stats->tx_mcast_bytes,
217 	    "multicast bytes sent");
218 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
219 	    "bcast_bytes", CTLFLAG_RD, &tx_stats->tx_bcast_bytes,
220 	    "broadcast bytes sent");
221 
222 	return 0;
223 }
224 
225 int
bnxt_create_port_stats_sysctls(struct bnxt_softc * softc)226 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
227 {
228 	struct sysctl_oid *oid;
229 	char	name[32];
230 	char	desc[64];
231 
232 	sprintf(name, "port_stats");
233 	sprintf(desc, "Port Stats");
234 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
235 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
236 	        CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
237 	if (!oid)
238 		return ENOMEM;
239 
240 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
241 	    "tx_64b_frames", CTLFLAG_RD,
242 	    &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
243 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
244 	    "tx_65b_127b_frames", CTLFLAG_RD,
245 	    &softc->tx_port_stats->tx_65b_127b_frames,
246 	    "Transmitted 65b 127b frames");
247 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
248 	    "tx_128b_255b_frames", CTLFLAG_RD,
249 	    &softc->tx_port_stats->tx_128b_255b_frames,
250 	    "Transmitted 128b 255b frames");
251 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
252 	    "tx_256b_511b_frames", CTLFLAG_RD,
253 	    &softc->tx_port_stats->tx_256b_511b_frames,
254 	    "Transmitted 256b 511b frames");
255 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
256 	    "tx_512b_1023b_frames", CTLFLAG_RD,
257 	    &softc->tx_port_stats->tx_512b_1023b_frames,
258 	    "Transmitted 512b 1023b frames");
259 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
260 	    "tx_1024b_1518b_frames", CTLFLAG_RD,
261 	    &softc->tx_port_stats->tx_1024b_1518b_frames,
262 	    "Transmitted 1024b 1518b frames");
263 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
264 	    "tx_good_vlan_frames", CTLFLAG_RD,
265 	    &softc->tx_port_stats->tx_good_vlan_frames,
266 	    "Transmitted good vlan frames");
267 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
268 	    "tx_1519b_2047b_frames", CTLFLAG_RD,
269 	    &softc->tx_port_stats->tx_1519b_2047b_frames,
270 	    "Transmitted 1519b 2047b frames");
271 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
272 	    "tx_2048b_4095b_frames", CTLFLAG_RD,
273 	    &softc->tx_port_stats->tx_2048b_4095b_frames,
274 	    "Transmitted 2048b 4095b frames");
275 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
276 	    "tx_4096b_9216b_frames", CTLFLAG_RD,
277 	    &softc->tx_port_stats->tx_4096b_9216b_frames,
278 	    "Transmitted 4096b 9216b frames");
279 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
280 	    "tx_9217b_16383b_frames", CTLFLAG_RD,
281 	    &softc->tx_port_stats->tx_9217b_16383b_frames,
282 	    "Transmitted 9217b 16383b frames");
283 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
284 	    "tx_good_frames", CTLFLAG_RD,
285 	    &softc->tx_port_stats->tx_good_frames, "Transmitted good frames");
286 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
287 	    "tx_total_frames", CTLFLAG_RD,
288 	    &softc->tx_port_stats->tx_total_frames, "Transmitted total frames");
289 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
290 	    "tx_ucast_frames", CTLFLAG_RD,
291 	    &softc->tx_port_stats->tx_ucast_frames, "Transmitted ucast frames");
292 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
293 	    "tx_mcast_frames", CTLFLAG_RD,
294 	    &softc->tx_port_stats->tx_mcast_frames, "Transmitted mcast frames");
295 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
296 	    "tx_bcast_frames", CTLFLAG_RD,
297 	    &softc->tx_port_stats->tx_bcast_frames, "Transmitted bcast frames");
298 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
299 	    "tx_pause_frames", CTLFLAG_RD,
300 	    &softc->tx_port_stats->tx_pause_frames, "Transmitted pause frames");
301 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
302 	    "tx_pfc_frames", CTLFLAG_RD,
303 	    &softc->tx_port_stats->tx_pfc_frames, "Transmitted pfc frames");
304 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
305 	    "tx_jabber_frames", CTLFLAG_RD,
306 	    &softc->tx_port_stats->tx_jabber_frames, "Transmitted jabber frames");
307 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
308 	    "tx_fcs_err_frames", CTLFLAG_RD,
309 	    &softc->tx_port_stats->tx_fcs_err_frames,
310 	    "Transmitted fcs err frames");
311 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
312 	    "tx_err", CTLFLAG_RD,
313 	    &softc->tx_port_stats->tx_err, "Transmitted err");
314 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
315 	    "tx_fifo_underruns", CTLFLAG_RD,
316 	    &softc->tx_port_stats->tx_fifo_underruns,
317 	    "Transmitted fifo underruns");
318 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
319 	    "tx_pfc_ena_frames_pri0", CTLFLAG_RD,
320 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri0,
321 	    "Transmitted pfc ena frames pri0");
322 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
323 	    "tx_pfc_ena_frames_pri1", CTLFLAG_RD,
324 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri1,
325 	    "Transmitted pfc ena frames pri1");
326 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
327 	    "tx_pfc_ena_frames_pri2", CTLFLAG_RD,
328 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri2,
329 	    "Transmitted pfc ena frames pri2");
330 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
331 	    "tx_pfc_ena_frames_pri3", CTLFLAG_RD,
332 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri3,
333 	    "Transmitted pfc ena frames pri3");
334 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
335 	    "tx_pfc_ena_frames_pri4", CTLFLAG_RD,
336 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri4,
337 	    "Transmitted pfc ena frames pri4");
338 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
339 	    "tx_pfc_ena_frames_pri5", CTLFLAG_RD,
340 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri5,
341 	    "Transmitted pfc ena frames pri5");
342 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
343 	    "tx_pfc_ena_frames_pri6", CTLFLAG_RD,
344 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri6,
345 	    "Transmitted pfc ena frames pri6");
346 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
347 	    "tx_pfc_ena_frames_pri7", CTLFLAG_RD,
348 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri7,
349 	    "Transmitted pfc ena frames pri7");
350 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
351 	    "tx_eee_lpi_events", CTLFLAG_RD,
352 	    &softc->tx_port_stats->tx_eee_lpi_events,
353 	    "Transmitted eee lpi events");
354 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
355 	    "tx_eee_lpi_duration", CTLFLAG_RD,
356 	    &softc->tx_port_stats->tx_eee_lpi_duration,
357 	    "Transmitted eee lpi duration");
358 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
359 	    "tx_llfc_logical_msgs", CTLFLAG_RD,
360 	    &softc->tx_port_stats->tx_llfc_logical_msgs,
361 	    "Transmitted llfc logical msgs");
362 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
363 	    "tx_hcfc_msgs", CTLFLAG_RD,
364 	    &softc->tx_port_stats->tx_hcfc_msgs, "Transmitted hcfc msgs");
365 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
366 	    "tx_total_collisions", CTLFLAG_RD,
367 	    &softc->tx_port_stats->tx_total_collisions,
368 	    "Transmitted total collisions");
369 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
370 	    "tx_bytes", CTLFLAG_RD,
371 	    &softc->tx_port_stats->tx_bytes, "Transmitted bytes");
372 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
373 	    "tx_xthol_frames", CTLFLAG_RD,
374 	    &softc->tx_port_stats->tx_xthol_frames, "Transmitted xthol frames");
375 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
376 	    "tx_stat_discard", CTLFLAG_RD,
377 	    &softc->tx_port_stats->tx_stat_discard, "Transmitted stat discard");
378 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
379 	    "tx_stat_error", CTLFLAG_RD,
380 	    &softc->tx_port_stats->tx_stat_error, "Transmitted stat error");
381 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
382 	    "rx_64b_frames", CTLFLAG_RD,
383 	    &softc->rx_port_stats->rx_64b_frames, "Received 64b frames");
384 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
385 	    "rx_65b_127b_frames", CTLFLAG_RD,
386 	    &softc->rx_port_stats->rx_65b_127b_frames, "Received 65b 127b frames");
387 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
388 	    "rx_128b_255b_frames", CTLFLAG_RD,
389 	    &softc->rx_port_stats->rx_128b_255b_frames,
390 	    "Received 128b 255b frames");
391 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
392 	    "rx_256b_511b_frames", CTLFLAG_RD,
393 	    &softc->rx_port_stats->rx_256b_511b_frames,
394 	    "Received 256b 511b frames");
395 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
396 	    "rx_512b_1023b_frames", CTLFLAG_RD,
397 	    &softc->rx_port_stats->rx_512b_1023b_frames,
398 	    "Received 512b 1023b frames");
399 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
400 	    "rx_1024b_1518b_frames", CTLFLAG_RD,
401 	    &softc->rx_port_stats->rx_1024b_1518b_frames,
402 	    "Received 1024b 1518 frames");
403 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
404 	    "rx_good_vlan_frames", CTLFLAG_RD,
405 	    &softc->rx_port_stats->rx_good_vlan_frames,
406 	    "Received good vlan frames");
407 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
408 	    "rx_1519b_2047b_frames", CTLFLAG_RD,
409 	    &softc->rx_port_stats->rx_1519b_2047b_frames,
410 	    "Received 1519b 2047b frames");
411 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
412 	    "rx_2048b_4095b_frames", CTLFLAG_RD,
413 	    &softc->rx_port_stats->rx_2048b_4095b_frames,
414 	    "Received 2048b 4095b frames");
415 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
416 	    "rx_4096b_9216b_frames", CTLFLAG_RD,
417 	    &softc->rx_port_stats->rx_4096b_9216b_frames,
418 	    "Received 4096b 9216b frames");
419 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
420 	    "rx_9217b_16383b_frames", CTLFLAG_RD,
421 	    &softc->rx_port_stats->rx_9217b_16383b_frames,
422 	    "Received 9217b 16383b frames");
423 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
424 	    "rx_total_frames", CTLFLAG_RD,
425 	    &softc->rx_port_stats->rx_total_frames, "Received total frames");
426 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
427 	    "rx_ucast_frames", CTLFLAG_RD,
428 	    &softc->rx_port_stats->rx_ucast_frames, "Received ucast frames");
429 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
430 	    "rx_mcast_frames", CTLFLAG_RD,
431 	    &softc->rx_port_stats->rx_mcast_frames, "Received mcast frames");
432 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
433 	    "rx_bcast_frames", CTLFLAG_RD,
434 	    &softc->rx_port_stats->rx_bcast_frames, "Received bcast frames");
435 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
436 	    "rx_fcs_err_frames", CTLFLAG_RD,
437 	    &softc->rx_port_stats->rx_fcs_err_frames, "Received fcs err frames");
438 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
439 	    "rx_ctrl_frames", CTLFLAG_RD,
440 	    &softc->rx_port_stats->rx_ctrl_frames, "Received ctrl frames");
441 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
442 	    "rx_pause_frames", CTLFLAG_RD,
443 	    &softc->rx_port_stats->rx_pause_frames, "Received pause frames");
444 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
445 	    "rx_pfc_frames", CTLFLAG_RD,
446 	    &softc->rx_port_stats->rx_pfc_frames, "Received pfc frames");
447 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
448 	    "rx_align_err_frames", CTLFLAG_RD,
449 	    &softc->rx_port_stats->rx_align_err_frames,
450 	    "Received align err frames");
451 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
452 	    "rx_ovrsz_frames", CTLFLAG_RD,
453 	    &softc->rx_port_stats->rx_ovrsz_frames,
454 	    "Received ovrsz frames");
455 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
456 	    "rx_jbr_frames", CTLFLAG_RD,
457 	    &softc->rx_port_stats->rx_jbr_frames,
458 	    "Received jbr frames");
459 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
460 	    "rx_mtu_err_frames", CTLFLAG_RD,
461 	    &softc->rx_port_stats->rx_mtu_err_frames,
462 	    "Received mtu err frames");
463 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
464 	    "rx_tagged_frames", CTLFLAG_RD,
465 	    &softc->rx_port_stats->rx_tagged_frames,
466 	    "Received tagged frames");
467 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
468 	    "rx_double_tagged_frames", CTLFLAG_RD,
469 	    &softc->rx_port_stats->rx_double_tagged_frames,
470 	    "Received double tagged frames");
471 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
472 	    "rx_good_frames", CTLFLAG_RD,
473 	    &softc->rx_port_stats->rx_good_frames,
474 	    "Received good frames");
475 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
476 	    "rx_pfc_ena_frames_pri0", CTLFLAG_RD,
477 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri0,
478 	    "Received pfc ena frames pri0");
479 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
480 	    "rx_pfc_ena_frames_pri1", CTLFLAG_RD,
481 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri1,
482 	    "Received pfc ena frames pri1");
483 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
484 	    "rx_pfc_ena_frames_pri2", CTLFLAG_RD,
485 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri2,
486 	    "Received pfc ena frames pri2");
487 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
488 	    "rx_pfc_ena_frames_pri3", CTLFLAG_RD,
489 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri3,
490 	    "Received pfc ena frames pri3");
491 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
492 	    "rx_pfc_ena_frames_pri4", CTLFLAG_RD,
493 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri4,
494 	    "Received pfc ena frames pri4");
495 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
496 	    "rx_pfc_ena_frames_pri5", CTLFLAG_RD,
497 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri5,
498 	    "Received pfc ena frames pri5");
499 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
500 	    "rx_pfc_ena_frames_pri6", CTLFLAG_RD,
501 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri6,
502 	    "Received pfc ena frames pri6");
503 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
504 	    "rx_pfc_ena_frames_pri7", CTLFLAG_RD,
505 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri7,
506 	    "Received pfc ena frames pri7");
507 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
508 	    "rx_sch_crc_err_frames", CTLFLAG_RD,
509 	    &softc->rx_port_stats->rx_sch_crc_err_frames,
510 	    "Received sch crc err frames");
511 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
512 	    "rx_undrsz_frames", CTLFLAG_RD,
513 	    &softc->rx_port_stats->rx_undrsz_frames, "Received undrsz frames");
514 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
515 	    "rx_eee_lpi_events", CTLFLAG_RD,
516 	    &softc->rx_port_stats->rx_eee_lpi_events, "Received eee lpi events");
517 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
518 	    "rx_eee_lpi_duration", CTLFLAG_RD,
519 	    &softc->rx_port_stats->rx_eee_lpi_duration,
520 	    "Received eee lpi duration");
521 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
522 	    "rx_llfc_physical_msgs", CTLFLAG_RD,
523 	    &softc->rx_port_stats->rx_llfc_physical_msgs,
524 	    "Received llfc physical msgs");
525 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
526 	    "rx_llfc_logical_msgs", CTLFLAG_RD,
527 	    &softc->rx_port_stats->rx_llfc_logical_msgs,
528 	    "Received llfc logical msgs");
529 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
530 	    "rx_llfc_msgs_with_crc_err", CTLFLAG_RD,
531 	    &softc->rx_port_stats->rx_llfc_msgs_with_crc_err,
532 	    "Received llfc msgs with crc err");
533 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
534 	    "rx_hcfc_msgs", CTLFLAG_RD,
535 	    &softc->rx_port_stats->rx_hcfc_msgs, "Received hcfc msgs");
536 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
537 	    "rx_hcfc_msgs_with_crc_err", CTLFLAG_RD,
538 	    &softc->rx_port_stats->rx_hcfc_msgs_with_crc_err,
539 	    "Received hcfc msgs with crc err");
540 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
541 	    "rx_bytes", CTLFLAG_RD,
542 	    &softc->rx_port_stats->rx_bytes, "Received bytes");
543 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
544 	    "rx_runt_bytes", CTLFLAG_RD,
545 	    &softc->rx_port_stats->rx_runt_bytes, "Received runt bytes");
546 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
547 	    "rx_runt_frames", CTLFLAG_RD,
548 	    &softc->rx_port_stats->rx_runt_frames, "Received runt frames");
549 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
550 	    "rx_stat_discard", CTLFLAG_RD,
551 	    &softc->rx_port_stats->rx_stat_discard, "Received stat discard");
552 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
553 	    "rx_stat_err", CTLFLAG_RD,
554 	    &softc->rx_port_stats->rx_stat_err, "Received stat err");
555 
556 	if (BNXT_CHIP_P5_PLUS(softc) &&
557 	    (softc->flags & BNXT_FLAG_FW_CAP_EXT_STATS)) {
558 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
559 		    "tx_bytes_cos0", CTLFLAG_RD,
560 		    &softc->tx_port_stats_ext->tx_bytes_cos0, "Transmitted bytes count cos0");
561 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
562 		    "tx_packets_cos0", CTLFLAG_RD,
563 		    &softc->tx_port_stats_ext->tx_packets_cos0, "Transmitted packets count cos0");
564 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
565 		    "tx_bytes_cos1", CTLFLAG_RD,
566 		    &softc->tx_port_stats_ext->tx_bytes_cos1, "Transmitted bytes count cos1");
567 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
568 		    "tx_packets_cos1", CTLFLAG_RD,
569 		    &softc->tx_port_stats_ext->tx_packets_cos1, "Transmitted packets count cos1");
570 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
571 		    "tx_bytes_cos2", CTLFLAG_RD,
572 		    &softc->tx_port_stats_ext->tx_bytes_cos2, "Transmitted bytes count cos2");
573 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
574 		    "tx_packets_cos2", CTLFLAG_RD,
575 		    &softc->tx_port_stats_ext->tx_packets_cos2, "Transmitted packets count cos2");
576 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
577 		    "tx_bytes_cos3", CTLFLAG_RD,
578 		    &softc->tx_port_stats_ext->tx_bytes_cos3, "Transmitted bytes count cos3");
579 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
580 		    "tx_packets_cos3", CTLFLAG_RD,
581 		    &softc->tx_port_stats_ext->tx_packets_cos3, "Transmitted packets count cos3");
582 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
583 		    "tx_bytes_cos4", CTLFLAG_RD,
584 		    &softc->tx_port_stats_ext->tx_bytes_cos4, "Transmitted bytes count cos4");
585 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
586 		    "tx_packets_cos4", CTLFLAG_RD,
587 		    &softc->tx_port_stats_ext->tx_packets_cos4, "Transmitted packets count cos4");
588 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
589 		    "tx_bytes_cos5", CTLFLAG_RD,
590 		    &softc->tx_port_stats_ext->tx_bytes_cos5, "Transmitted bytes count cos5");
591 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
592 		    "tx_packets_cos5", CTLFLAG_RD,
593 		    &softc->tx_port_stats_ext->tx_packets_cos5, "Transmitted packets count cos5");
594 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
595 		    "tx_bytes_cos6", CTLFLAG_RD,
596 		    &softc->tx_port_stats_ext->tx_bytes_cos6, "Transmitted bytes count cos6");
597 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
598 		    "tx_packets_cos6", CTLFLAG_RD,
599 		    &softc->tx_port_stats_ext->tx_packets_cos6, "Transmitted packets count cos6");
600 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
601 		    "tx_bytes_cos7", CTLFLAG_RD,
602 		    &softc->tx_port_stats_ext->tx_bytes_cos7, "Transmitted bytes count cos7");
603 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
604 		    "tx_packets_cos7", CTLFLAG_RD,
605 		    &softc->tx_port_stats_ext->tx_packets_cos7, "Transmitted packets count cos7");
606 
607 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
608 		    "tx_bytes_pri0", CTLFLAG_RD,
609 		    &softc->tx_bytes_pri[0], "Transmitted bytes count pri0");
610 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
611 		    "tx_packets_pri0", CTLFLAG_RD,
612 		    &softc->tx_packets_pri[0], "Transmitted packets count pri0");
613 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
614 		    "tx_bytes_pri1", CTLFLAG_RD,
615 		    &softc->tx_bytes_pri[1], "Transmitted bytes count pri1");
616 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
617 		    "tx_packets_pri1", CTLFLAG_RD,
618 		    &softc->tx_packets_pri[1], "Transmitted packets count pri1");
619 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
620 		    "tx_bytes_pri2", CTLFLAG_RD,
621 		    &softc->tx_bytes_pri[2], "Transmitted bytes count pri2");
622 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
623 		    "tx_packets_pri2", CTLFLAG_RD,
624 		    &softc->tx_packets_pri[2], "Transmitted packets count pri2");
625 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
626 		    "tx_bytes_pri3", CTLFLAG_RD,
627 		    &softc->tx_bytes_pri[3], "Transmitted bytes count pri3");
628 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
629 		    "tx_packets_pri3", CTLFLAG_RD,
630 		    &softc->tx_packets_pri[3], "Transmitted packets count pri3");
631 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
632 		    "tx_bytes_pri4", CTLFLAG_RD,
633 		    &softc->tx_bytes_pri[4], "Transmitted bytes count pri4");
634 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
635 		    "tx_packets_pri4", CTLFLAG_RD,
636 		    &softc->tx_packets_pri[4], "Transmitted packets count pri4");
637 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
638 		    "tx_bytes_pri5", CTLFLAG_RD,
639 		    &softc->tx_bytes_pri[5], "Transmitted bytes count pri5");
640 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
641 		    "tx_packets_pri5", CTLFLAG_RD,
642 		    &softc->tx_packets_pri[5], "Transmitted packets count pri5");
643 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
644 		    "tx_bytes_pri6", CTLFLAG_RD,
645 		    &softc->tx_bytes_pri[6], "Transmitted bytes count pri6");
646 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
647 		    "tx_packets_pri6", CTLFLAG_RD,
648 		    &softc->tx_packets_pri[6], "Transmitted packets count pri6");
649 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
650 		    "tx_bytes_pri7", CTLFLAG_RD,
651 		    &softc->tx_bytes_pri[7], "Transmitted bytes count pri7");
652 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
653 		    "tx_packets_pri7", CTLFLAG_RD,
654 		    &softc->tx_packets_pri[7], "Transmitted packets count pri7");
655 
656 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
657 		    "pfc_pri0_tx_duration_us", CTLFLAG_RD,
658 		    &softc->tx_port_stats_ext->pfc_pri0_tx_duration_us, "Time duration between"
659 		    "XON to XOFF and XOFF to XON for pri0");
660 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
661 		    "pfc_pri0_tx_transitions", CTLFLAG_RD,
662 		    &softc->tx_port_stats_ext->pfc_pri0_tx_transitions, "Num times transition"
663 		    "between XON to XOFF and XOFF to XON for pri0");
664 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
665 		    "pfc_pri1_tx_duration_us", CTLFLAG_RD,
666 		    &softc->tx_port_stats_ext->pfc_pri1_tx_duration_us, "Time duration between"
667 		    "XON to XOFF and XOFF to XON for pri1");
668 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
669 		    "pfc_pri1_tx_transitions", CTLFLAG_RD,
670 		    &softc->tx_port_stats_ext->pfc_pri1_tx_transitions, "Num times transition"
671 		    "between XON to XOFF and XOFF to XON for pri1");
672 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
673 		    "pfc_pri2_tx_duration_us", CTLFLAG_RD,
674 		    &softc->tx_port_stats_ext->pfc_pri2_tx_duration_us, "Time duration between"
675 		    "XON to XOFF and XOFF to XON for pri2");
676 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
677 		    "pfc_pri2_tx_transitions", CTLFLAG_RD,
678 		    &softc->tx_port_stats_ext->pfc_pri2_tx_transitions, "Num times transition"
679 		    "between XON to XOFF and XOFF to XON for pri2");
680 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
681 		    "pfc_pri3_tx_duration_us", CTLFLAG_RD,
682 		    &softc->tx_port_stats_ext->pfc_pri3_tx_duration_us, "Time duration between"
683 		    "XON to XOFF and XOFF to XON for pri3");
684 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
685 		    "pfc_pri3_tx_transitions", CTLFLAG_RD,
686 		    &softc->tx_port_stats_ext->pfc_pri3_tx_transitions, "Num times transition"
687 		    "between XON to XOFF and XOFF to XON for pri3");
688 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
689 		    "pfc_pri4_tx_duration_us", CTLFLAG_RD,
690 		    &softc->tx_port_stats_ext->pfc_pri4_tx_duration_us, "Time duration between"
691 		    "XON to XOFF and XOFF to XON for pri4");
692 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
693 		    "pfc_pri4_tx_transitions", CTLFLAG_RD,
694 		    &softc->tx_port_stats_ext->pfc_pri4_tx_transitions, "Num times transition"
695 		    "between XON to XOFF and XOFF to XON for pri4");
696 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
697 		    "pfc_pri5_tx_duration_us", CTLFLAG_RD,
698 		    &softc->tx_port_stats_ext->pfc_pri5_tx_duration_us, "Time duration between"
699 		    "XON to XOFF and XOFF to XON for pri5");
700 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
701 		    "pfc_pri5_tx_transitions", CTLFLAG_RD,
702 		    &softc->tx_port_stats_ext->pfc_pri5_tx_transitions, "Num times transition"
703 		    "between XON to XOFF and XOFF to XON for pri5");
704 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
705 		    "pfc_pri6_tx_duration_us", CTLFLAG_RD,
706 		    &softc->tx_port_stats_ext->pfc_pri6_tx_duration_us, "Time duration between"
707 		    "XON to XOFF and XOFF to XON for pri6");
708 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
709 		    "pfc_pri6_tx_transitions", CTLFLAG_RD,
710 		    &softc->tx_port_stats_ext->pfc_pri6_tx_transitions, "Num times transition"
711 		    "between XON to XOFF and XOFF to XON for pri6");
712 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
713 		    "pfc_pri7_tx_duration_us", CTLFLAG_RD,
714 		    &softc->tx_port_stats_ext->pfc_pri7_tx_duration_us, "Time duration between"
715 		    "XON to XOFF and XOFF to XON for pri7");
716 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
717 		    "pfc_pri7_tx_transitions", CTLFLAG_RD,
718 		    &softc->tx_port_stats_ext->pfc_pri7_tx_transitions, "Num times transition"
719 		    "between XON to XOFF and XOFF to XON for pri7");
720 
721 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
722 		    "link_down_events", CTLFLAG_RD,
723 		    &softc->rx_port_stats_ext->link_down_events, "Num times link states down");
724 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
725 		    "continuous_pause_events", CTLFLAG_RD,
726 		    &softc->rx_port_stats_ext->continuous_pause_events, "Num times pause events");
727 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
728 		    "resume_pause_events", CTLFLAG_RD,
729 		    &softc->rx_port_stats_ext->resume_pause_events, "Num times pause events"
730 		    "resumes");
731 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
732 		    "continuous_roce_pause_events", CTLFLAG_RD,
733 		    &softc->rx_port_stats_ext->continuous_roce_pause_events, "Num times roce"
734 		    "pause events");
735 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
736 		    "resume_roce_pause_events", CTLFLAG_RD,
737 		    &softc->rx_port_stats_ext->resume_roce_pause_events, "Num times roce pause"
738 		    "events resumes");
739 
740 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
741 		    "rx_bytes_cos0", CTLFLAG_RD,
742 		    &softc->rx_port_stats_ext->rx_bytes_cos0, "Received bytes count cos0");
743 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
744 		    "rx_packets_cos0", CTLFLAG_RD,
745 		    &softc->rx_port_stats_ext->rx_packets_cos0, "Received packets count cos0");
746 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
747 		    "rx_bytes_cos1", CTLFLAG_RD,
748 		    &softc->rx_port_stats_ext->rx_bytes_cos1, "Received bytes count cos1");
749 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
750 		    "rx_packets_cos1", CTLFLAG_RD,
751 		    &softc->rx_port_stats_ext->rx_packets_cos1, "Received packets count cos1");
752 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
753 		    "rx_bytes_cos2", CTLFLAG_RD,
754 		    &softc->rx_port_stats_ext->rx_bytes_cos2, "Received bytes count cos2");
755 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
756 		    "rx_packets_cos2", CTLFLAG_RD,
757 		    &softc->rx_port_stats_ext->rx_packets_cos2, "Received packets count cos2");
758 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
759 		    "rx_bytes_cos3", CTLFLAG_RD,
760 		    &softc->rx_port_stats_ext->rx_bytes_cos3, "Received bytes count cos3");
761 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
762 		    "rx_packets_cos3", CTLFLAG_RD,
763 		    &softc->rx_port_stats_ext->rx_packets_cos3, "Received packets count cos3");
764 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
765 		    "rx_bytes_cos4", CTLFLAG_RD,
766 		    &softc->rx_port_stats_ext->rx_bytes_cos4, "Received bytes count cos4");
767 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
768 		    "rx_packets_cos4", CTLFLAG_RD,
769 		    &softc->rx_port_stats_ext->rx_packets_cos4, "Received packets count cos4");
770 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
771 		    "rx_bytes_cos5", CTLFLAG_RD,
772 		    &softc->rx_port_stats_ext->rx_bytes_cos5, "Received bytes count cos5");
773 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
774 		    "rx_packets_cos5", CTLFLAG_RD,
775 		    &softc->rx_port_stats_ext->rx_packets_cos5, "Received packets count cos5");
776 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
777 		    "rx_bytes_cos6", CTLFLAG_RD,
778 		    &softc->rx_port_stats_ext->rx_bytes_cos6, "Received bytes count cos6");
779 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
780 		    "rx_packets_cos6", CTLFLAG_RD,
781 		    &softc->rx_port_stats_ext->rx_packets_cos6, "Received packets count cos6");
782 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
783 		    "rx_bytes_cos7", CTLFLAG_RD,
784 		    &softc->rx_port_stats_ext->rx_bytes_cos7, "Received bytes count cos7");
785 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
786 		    "rx_packets_cos7", CTLFLAG_RD,
787 		    &softc->rx_port_stats_ext->rx_packets_cos7, "Received packets count cos7");
788 
789 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
790 		    "rx_bytes_pri0", CTLFLAG_RD,
791 		    &softc->rx_bytes_pri[0], "Received bytes count pri0");
792 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
793 		    "rx_packets_pri0", CTLFLAG_RD,
794 		    &softc->rx_packets_pri[0], "Received packets count pri0");
795 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
796 		    "rx_bytes_pri1", CTLFLAG_RD,
797 		    &softc->rx_bytes_pri[1], "Received bytes count pri1");
798 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
799 		    "rx_packets_pri1", CTLFLAG_RD,
800 		    &softc->rx_packets_pri[1], "Received packets count pri1");
801 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
802 		    "rx_bytes_pri2", CTLFLAG_RD,
803 		    &softc->rx_bytes_pri[2], "Received bytes count pri2");
804 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
805 		    "rx_packets_pri2", CTLFLAG_RD,
806 		    &softc->rx_packets_pri[2], "Received packets count pri2");
807 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
808 		    "rx_bytes_pri3", CTLFLAG_RD,
809 		    &softc->rx_bytes_pri[3], "Received bytes count pri3");
810 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
811 		    "rx_packets_pri3", CTLFLAG_RD,
812 		    &softc->rx_packets_pri[3], "Received packets count pri3");
813 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
814 		    "rx_bytes_pri4", CTLFLAG_RD,
815 		    &softc->rx_bytes_pri[4], "Received bytes count pri4");
816 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
817 		    "rx_packets_pri4", CTLFLAG_RD,
818 		    &softc->rx_packets_pri[4], "Received packets count pri4");
819 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
820 		    "rx_bytes_pri5", CTLFLAG_RD,
821 		    &softc->rx_bytes_pri[5], "Received bytes count pri5");
822 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
823 		    "rx_packets_pri5", CTLFLAG_RD,
824 		    &softc->rx_packets_pri[5], "Received packets count pri5");
825 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
826 		    "rx_bytes_pri6", CTLFLAG_RD,
827 		    &softc->rx_bytes_pri[6], "Received bytes count pri6");
828 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
829 		    "rx_packets_pri6", CTLFLAG_RD,
830 		    &softc->rx_packets_pri[6], "Received packets count pri6");
831 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
832 		    "rx_bytes_pri7", CTLFLAG_RD,
833 		    &softc->rx_bytes_pri[7], "Received bytes count pri7");
834 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
835 		    "rx_packets_pri7", CTLFLAG_RD,
836 		    &softc->rx_packets_pri[7], "Received packets count pri7");
837 
838 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
839 		    "pfc_pri0_rx_duration_us", CTLFLAG_RD,
840 		    &softc->rx_port_stats_ext->pfc_pri0_rx_duration_us, "Time duration in receiving"
841 		    "between XON to XOFF and XOFF to XON for pri0");
842 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
843 		    "pfc_pri0_rx_transitions", CTLFLAG_RD,
844 		    &softc->rx_port_stats_ext->pfc_pri0_rx_transitions, "Num times rx transition"
845 		    "between XON to XOFF and XOFF to XON for pri0");
846 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
847 		    "pfc_pri1_rx_duration_us", CTLFLAG_RD,
848 		    &softc->rx_port_stats_ext->pfc_pri1_rx_duration_us, "Time duration in receiving"
849 		    "between XON to XOFF and XOFF to XON for pri1");
850 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
851 		    "pfc_pri1_rx_transitions", CTLFLAG_RD,
852 		    &softc->rx_port_stats_ext->pfc_pri1_rx_transitions, "Num times rx transition"
853 		    "between XON to XOFF and XOFF to XON for pri1");
854 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
855 		    "pfc_pri2_rx_duration_us", CTLFLAG_RD,
856 		    &softc->rx_port_stats_ext->pfc_pri2_rx_duration_us, "Time duration in receiving"
857 		    "between XON to XOFF and XOFF to XON for pri2");
858 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
859 		    "pfc_pri2_rx_transitions", CTLFLAG_RD,
860 		    &softc->rx_port_stats_ext->pfc_pri2_rx_transitions, "Num times rx transition"
861 		    "between XON to XOFF and XOFF to XON for pri2");
862 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
863 		    "pfc_pri3_rx_duration_us", CTLFLAG_RD,
864 		    &softc->rx_port_stats_ext->pfc_pri3_rx_duration_us, "Time duration in receiving"
865 		    "between XON to XOFF and XOFF to XON for pri3");
866 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
867 		    "pfc_pri3_rx_transitions", CTLFLAG_RD,
868 		    &softc->rx_port_stats_ext->pfc_pri3_rx_transitions, "Num times rx transition"
869 		    "between XON to XOFF and XOFF to XON for pri3");
870 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
871 		    "pfc_pri4_rx_duration_us", CTLFLAG_RD,
872 		    &softc->rx_port_stats_ext->pfc_pri4_rx_duration_us, "Time duration in receiving"
873 		    "between XON to XOFF and XOFF to XON for pri4");
874 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
875 		    "pfc_pri4_rx_transitions", CTLFLAG_RD,
876 		    &softc->rx_port_stats_ext->pfc_pri4_rx_transitions, "Num times rx transition"
877 		    "between XON to XOFF and XOFF to XON for pri4");
878 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
879 		    "pfc_pri5_rx_duration_us", CTLFLAG_RD,
880 		    &softc->rx_port_stats_ext->pfc_pri5_rx_duration_us, "Time duration in receiving"
881 		    "between XON to XOFF and XOFF to XON for pri5");
882 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
883 		    "pfc_pri5_rx_transitions", CTLFLAG_RD,
884 		    &softc->rx_port_stats_ext->pfc_pri5_rx_transitions, "Num times rx transition"
885 		    "between XON to XOFF and XOFF to XON for pri5");
886 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
887 		    "pfc_pri6_rx_duration_us", CTLFLAG_RD,
888 		    &softc->rx_port_stats_ext->pfc_pri6_rx_duration_us, "Time duration in receiving"
889 		    "between XON to XOFF and XOFF to XON for pri6");
890 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
891 		    "pfc_pri6_rx_transitions", CTLFLAG_RD,
892 		    &softc->rx_port_stats_ext->pfc_pri6_rx_transitions, "Num times rx transition"
893 		    "between XON to XOFF and XOFF to XON for pri6");
894 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
895 		    "pfc_pri7_rx_duration_us", CTLFLAG_RD,
896 		    &softc->rx_port_stats_ext->pfc_pri7_rx_duration_us, "Time duration in receiving"
897 		    "between XON to XOFF and XOFF to XON for pri7");
898 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
899 		    "pfc_pri7_rx_transitions", CTLFLAG_RD,
900 		    &softc->rx_port_stats_ext->pfc_pri7_rx_transitions, "Num times rx transition"
901 		    "between XON to XOFF and XOFF to XON for pri7");
902 
903 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
904 		    "rx_bits", CTLFLAG_RD,
905 		    &softc->rx_port_stats_ext->rx_bits, "total number of received bits");
906 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
907 		    "rx_buffer_passed_threshold", CTLFLAG_RD,
908 		    &softc->rx_port_stats_ext->rx_buffer_passed_threshold, "num of events port"
909 		    "buffer"
910 		    "was over 85%");
911 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
912 		    "rx_pcs_symbol_err", CTLFLAG_RD,
913 		    &softc->rx_port_stats_ext->rx_pcs_symbol_err, "num of symbol errors wasn't"
914 		    "corrected by FEC");
915 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
916 		    "rx_corrected_bits", CTLFLAG_RD,
917 		    &softc->rx_port_stats_ext->rx_corrected_bits, "num of bits corrected by FEC");
918 
919 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
920 		    "rx_discard_bytes_cos0", CTLFLAG_RD,
921 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos0, "num of rx discard bytes"
922 		    "count on cos0");
923 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
924 		    "rx_discard_packets_cos0", CTLFLAG_RD,
925 		    &softc->rx_port_stats_ext->rx_discard_packets_cos0, "num of rx discard packets"
926 		    "count on cos0");
927 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
928 		    "rx_discard_bytes_cos1", CTLFLAG_RD,
929 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos1, "num of rx discard bytes"
930 		    "count on cos1");
931 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
932 		    "rx_discard_packets_cos1", CTLFLAG_RD,
933 		    &softc->rx_port_stats_ext->rx_discard_packets_cos1, "num of rx discard packets"
934 		    "count on cos1");
935 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
936 		    "rx_discard_bytes_cos2", CTLFLAG_RD,
937 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos2, "num of rx discard bytes"
938 		    "count on cos2");
939 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
940 		    "rx_discard_packets_cos2", CTLFLAG_RD,
941 		    &softc->rx_port_stats_ext->rx_discard_packets_cos2, "num of rx discard packets"
942 		    "count on cos2");
943 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
944 		    "rx_discard_bytes_cos3", CTLFLAG_RD,
945 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos3, "num of rx discard bytes"
946 		    "count on cos3");
947 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
948 		    "rx_discard_packets_cos3", CTLFLAG_RD,
949 		    &softc->rx_port_stats_ext->rx_discard_packets_cos3, "num of rx discard packets"
950 		    "count on cos3");
951 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
952 		    "rx_discard_bytes_cos4", CTLFLAG_RD,
953 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos4, "num of rx discard bytes"
954 		    "count on cos4");
955 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
956 		    "rx_discard_packets_cos4", CTLFLAG_RD,
957 		    &softc->rx_port_stats_ext->rx_discard_packets_cos4, "num of rx discard packets"
958 		    "count on cos4");
959 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
960 		    "rx_discard_bytes_cos5", CTLFLAG_RD,
961 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos5, "num of rx discard bytes"
962 		    "count on cos5");
963 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
964 		    "rx_discard_packets_cos5", CTLFLAG_RD,
965 		    &softc->rx_port_stats_ext->rx_discard_packets_cos5, "num of rx discard packets"
966 		    "count on cos5");
967 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
968 		    "rx_discard_bytes_cos6", CTLFLAG_RD,
969 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos6, "num of rx discard bytes"
970 		    "count on cos6");
971 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
972 		    "rx_discard_packets_cos6", CTLFLAG_RD,
973 		    &softc->rx_port_stats_ext->rx_discard_packets_cos6, "num of rx discard packets"
974 		    "count on cos6");
975 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
976 		    "rx_discard_bytes_cos7", CTLFLAG_RD,
977 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos7, "num of rx discard bytes"
978 		    "count on cos7");
979 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
980 		    "rx_discard_packets_cos7", CTLFLAG_RD,
981 		    &softc->rx_port_stats_ext->rx_discard_packets_cos7, "num of rx discard packets"
982 		    "count on cos7");
983 	}
984 
985 
986 	return 0;
987 }
988 
989 int
bnxt_create_rx_sysctls(struct bnxt_softc * softc,int rxr)990 bnxt_create_rx_sysctls(struct bnxt_softc *softc, int rxr)
991 {
992 	struct sysctl_oid *oid;
993 	struct ctx_hw_stats *rx_stats = (void *)softc->rx_stats[rxr].idi_vaddr;
994 	char	name[32];
995 	char	desc[64];
996 
997 	sprintf(name, "rxq%d", rxr);
998 	sprintf(desc, "receive queue %d", rxr);
999 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
1000 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
1001 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
1002 	if (!oid)
1003 		return ENOMEM;
1004 
1005 	if (BNXT_CHIP_P5_PLUS(softc))
1006 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1007 		    "nq_num_ints", CTLFLAG_RD, &softc->nq_rings[rxr].int_count,
1008 		    "Num Interrupts");
1009 	else
1010 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1011 		    "rq_num_ints", CTLFLAG_RD, &softc->rx_cp_rings[rxr].int_count,
1012 		    "Num Interrupts");
1013 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1014 	    "ucast_pkts", CTLFLAG_RD, &rx_stats->rx_ucast_pkts,
1015 	    "unicast packets received");
1016 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1017 	    "mcast_pkts", CTLFLAG_RD, &rx_stats->rx_mcast_pkts,
1018 	    "multicast packets received");
1019 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1020 	    "bcast_pkts", CTLFLAG_RD, &rx_stats->rx_bcast_pkts,
1021 	    "broadcast packets received");
1022 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1023 	    "discard_pkts", CTLFLAG_RD,
1024 	    &rx_stats->rx_discard_pkts, "discarded receive packets");
1025 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1026 	    "error_pkts", CTLFLAG_RD, &rx_stats->rx_error_pkts,
1027 	    "Error receive packets");
1028 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1029 	    "ucast_bytes", CTLFLAG_RD, &rx_stats->rx_ucast_bytes,
1030 	    "unicast bytes received");
1031 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1032 	    "mcast_bytes", CTLFLAG_RD, &rx_stats->rx_mcast_bytes,
1033 	    "multicast bytes received");
1034 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1035 	    "bcast_bytes", CTLFLAG_RD, &rx_stats->rx_bcast_bytes,
1036 	    "broadcast bytes received");
1037 
1038 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1039 	    "tpa_pkts", CTLFLAG_RD, &rx_stats->tpa_pkts,
1040 	    "TPA packets");
1041 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1042 	    "tpa_bytes", CTLFLAG_RD, &rx_stats->tpa_bytes,
1043 	    "TPA bytes");
1044 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1045 	    "tpa_events", CTLFLAG_RD, &rx_stats->tpa_events,
1046 	    "TPA events");
1047 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
1048 	    "tpa_aborts", CTLFLAG_RD, &rx_stats->tpa_aborts,
1049 	    "TPA aborts");
1050 
1051 	return 0;
1052 }
1053 
1054 static char *bnxt_chip_type[] = {
1055 	"ASIC",
1056 	"FPGA",
1057 	"Palladium",
1058 	"Unknown"
1059 };
1060 #define MAX_CHIP_TYPE 3
1061 
bnxt_parse_pkglog(int desired_field,uint8_t * data,size_t datalen)1062 static char *bnxt_parse_pkglog(int desired_field, uint8_t *data, size_t datalen)
1063 {
1064 	char    *retval = NULL;
1065 	char    *p;
1066 	char    *value;
1067 	int     field = 0;
1068 
1069 	if (datalen < 1)
1070 		return NULL;
1071 	/* null-terminate the log data (removing last '\n'): */
1072 	data[datalen - 1] = 0;
1073 	for (p = data; *p != 0; p++) {
1074 		field = 0;
1075 		retval = NULL;
1076 		while (*p != 0 && *p != '\n') {
1077 			value = p;
1078 			while (*p != 0 && *p != '\t' && *p != '\n')
1079 				p++;
1080 			if (field == desired_field)
1081 				retval = value;
1082 			if (*p != '\t')
1083 				break;
1084 			*p = 0;
1085 			field++;
1086 			p++;
1087 		}
1088 		if (*p == 0)
1089 			break;
1090 		*p = 0;
1091 	}
1092 	return retval;
1093 }
1094 
1095 static int
bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)1096 bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)
1097 {
1098 	struct bnxt_softc *softc = arg1;
1099 	struct iflib_dma_info dma_data;
1100 	char *pkglog = NULL;
1101 	char *p;
1102 	char unk[] = "<unknown>";
1103 	char *buf = unk;
1104 	int rc;
1105 	uint16_t ordinal = BNX_DIR_ORDINAL_FIRST;
1106 	uint16_t index;
1107 	uint32_t data_len;
1108 
1109 	rc = bnxt_hwrm_nvm_find_dir_entry(softc, BNX_DIR_TYPE_PKG_LOG,
1110 	    &ordinal, BNX_DIR_EXT_NONE, &index, false,
1111 	    HWRM_NVM_FIND_DIR_ENTRY_INPUT_OPT_ORDINAL_EQ,
1112 	    &data_len, NULL, NULL);
1113 	dma_data.idi_vaddr = NULL;
1114 	if (rc == 0 && data_len) {
1115 		rc = iflib_dma_alloc(softc->ctx, data_len, &dma_data,
1116 		    BUS_DMA_NOWAIT);
1117 		if (rc == 0) {
1118 			rc = bnxt_hwrm_nvm_read(softc, index, 0, data_len,
1119 			    &dma_data);
1120 			if (rc == 0) {
1121 				pkglog = dma_data.idi_vaddr;
1122 				p = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkglog, data_len);
1123 				if (p && *p != 0 && isdigit(*p))
1124 					buf = p;
1125 			}
1126 		} else
1127 			dma_data.idi_vaddr = NULL;
1128 	}
1129 
1130 	rc = sysctl_handle_string(oidp, buf, 0, req);
1131 	if (dma_data.idi_vaddr)
1132 		iflib_dma_free(&dma_data);
1133 	return rc;
1134 }
1135 
1136 static int
bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)1137 bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)
1138 {
1139 	struct bnxt_softc *softc = arg1;
1140 	char buf[16];
1141 	uint8_t	newver[3];
1142 	int rc;
1143 
1144 	sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
1145 	    softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
1146 
1147 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1148 	if (rc || req->newptr == NULL)
1149 		return rc;
1150 	if (sscanf(buf, "%hhu.%hhu.%hhu%*c", &newver[0], &newver[1],
1151 	    &newver[2]) != 3)
1152 		return EINVAL;
1153 	softc->ver_info->hwrm_min_major = newver[0];
1154 	softc->ver_info->hwrm_min_minor = newver[1];
1155 	softc->ver_info->hwrm_min_update = newver[2];
1156 	bnxt_check_hwrm_version(softc);
1157 
1158 	return rc;
1159 }
1160 
1161 int
bnxt_create_ver_sysctls(struct bnxt_softc * softc)1162 bnxt_create_ver_sysctls(struct bnxt_softc *softc)
1163 {
1164 	struct bnxt_ver_info *vi = softc->ver_info;
1165 	struct sysctl_oid *oid = vi->ver_oid;
1166 
1167 	if (!oid)
1168 		return ENOMEM;
1169 
1170 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1171 	    "hwrm_if", CTLFLAG_RD, vi->hwrm_if_ver, 0,
1172 	    "HWRM interface version");
1173 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1174 	    "driver_hwrm_if", CTLFLAG_RD, vi->driver_hwrm_if_ver, 0,
1175 	    "HWRM firmware version");
1176 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1177 	    "mgmt_fw", CTLFLAG_RD, vi->mgmt_fw_ver, 0,
1178 	    "management firmware version");
1179 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1180 	    "netctrl_fw", CTLFLAG_RD, vi->netctrl_fw_ver, 0,
1181 	    "network control firmware version");
1182 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1183 	    "roce_fw", CTLFLAG_RD, vi->roce_fw_ver, 0,
1184 	    "RoCE firmware version");
1185 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1186 	    "fw_ver", CTLFLAG_RD, vi->fw_ver_str, 0,
1187 	    "Firmware version");
1188 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1189 	    "phy", CTLFLAG_RD, vi->phy_ver, 0,
1190 	    "PHY version");
1191 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1192 	    "hwrm_fw_name", CTLFLAG_RD, vi->hwrm_fw_name, 0,
1193 	    "HWRM firmware name");
1194 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1195 	    "mgmt_fw_name", CTLFLAG_RD, vi->mgmt_fw_name, 0,
1196 	    "management firmware name");
1197 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1198 	    "netctrl_fw_name", CTLFLAG_RD, vi->netctrl_fw_name, 0,
1199 	    "network control firmware name");
1200 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1201 	    "roce_fw_name", CTLFLAG_RD, vi->roce_fw_name, 0,
1202 	    "RoCE firmware name");
1203 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1204 	    "phy_vendor", CTLFLAG_RD, vi->phy_vendor, 0,
1205 	    "PHY vendor name");
1206 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1207 	    "phy_partnumber", CTLFLAG_RD, vi->phy_partnumber, 0,
1208 	    "PHY vendor part number");
1209 	SYSCTL_ADD_U16(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1210 	    "chip_num", CTLFLAG_RD, &vi->chip_num, 0, "chip number");
1211 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1212 	    "chip_rev", CTLFLAG_RD, &vi->chip_rev, 0, "chip revision");
1213 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1214 	    "chip_metal", CTLFLAG_RD, &vi->chip_metal, 0, "chip metal number");
1215 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1216 	    "chip_bond_id", CTLFLAG_RD, &vi->chip_bond_id, 0,
1217 	    "chip bond id");
1218 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1219 	    "chip_type", CTLFLAG_RD, vi->chip_type > MAX_CHIP_TYPE ?
1220 	    bnxt_chip_type[MAX_CHIP_TYPE] : bnxt_chip_type[vi->chip_type], 0,
1221 	    "RoCE firmware name");
1222 	if (!BNXT_VF(softc))
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