xref: /freebsd/sys/dev/bnxt/bnxt_sysctl.c (revision 783d3ff6)
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 
33 #include "bnxt.h"
34 #include "bnxt_hwrm.h"
35 #include "bnxt_sysctl.h"
36 
37 /*
38  * We want to create:
39  * dev.bnxt.0.hwstats.txq0
40  * dev.bnxt.0.hwstats.txq0.txmbufs
41  * dev.bnxt.0.hwstats.rxq0
42  * dev.bnxt.0.hwstats.txq0.rxmbufs
43  * so the hwstats ctx list needs to be created in attach_post and populated
44  * during init.
45  *
46  * Then, it needs to be cleaned up in stop.
47  */
48 
49 int
50 bnxt_init_sysctl_ctx(struct bnxt_softc *softc)
51 {
52 	struct sysctl_ctx_list *ctx;
53 
54 	sysctl_ctx_init(&softc->hw_stats);
55 	ctx = device_get_sysctl_ctx(softc->dev);
56 	softc->hw_stats_oid = SYSCTL_ADD_NODE(ctx,
57 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
58 	    "hwstats", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware statistics");
59 	if (!softc->hw_stats_oid) {
60 		sysctl_ctx_free(&softc->hw_stats);
61 		return ENOMEM;
62 	}
63 
64 	sysctl_ctx_init(&softc->ver_info->ver_ctx);
65 	ctx = device_get_sysctl_ctx(softc->dev);
66 	softc->ver_info->ver_oid = SYSCTL_ADD_NODE(ctx,
67 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
68 	    "ver", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
69 	    "hardware/firmware version information");
70 	if (!softc->ver_info->ver_oid) {
71 		sysctl_ctx_free(&softc->ver_info->ver_ctx);
72 		return ENOMEM;
73 	}
74 
75 	if (BNXT_PF(softc)) {
76 		sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
77 		ctx = device_get_sysctl_ctx(softc->dev);
78 		softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
79 		    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
80 		    "nvram", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
81 		    "nvram information");
82 		if (!softc->nvm_info->nvm_oid) {
83 			sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
84 			return ENOMEM;
85 		}
86 	}
87 
88 	sysctl_ctx_init(&softc->hw_lro_ctx);
89 	ctx = device_get_sysctl_ctx(softc->dev);
90 	softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
91 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
92 	    "hw_lro", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware lro");
93 	if (!softc->hw_lro_oid) {
94 		sysctl_ctx_free(&softc->hw_lro_ctx);
95 		return ENOMEM;
96 	}
97 
98 	sysctl_ctx_init(&softc->flow_ctrl_ctx);
99 	ctx = device_get_sysctl_ctx(softc->dev);
100 	softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
101 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
102 	    "fc", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "flow ctrl");
103 	if (!softc->flow_ctrl_oid) {
104 		sysctl_ctx_free(&softc->flow_ctrl_ctx);
105 		return ENOMEM;
106 	}
107 
108 	return 0;
109 }
110 
111 int
112 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
113 {
114 	int orc;
115 	int rc = 0;
116 
117 	if (softc->hw_stats_oid != NULL) {
118 		orc = sysctl_ctx_free(&softc->hw_stats);
119 		if (orc)
120 			rc = orc;
121 		else
122 			softc->hw_stats_oid = NULL;
123 	}
124 	if (softc->ver_info->ver_oid != NULL) {
125 		orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
126 		if (orc)
127 			rc = orc;
128 		else
129 			softc->ver_info->ver_oid = NULL;
130 	}
131 	if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
132 		orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
133 		if (orc)
134 			rc = orc;
135 		else
136 			softc->nvm_info->nvm_oid = NULL;
137 	}
138 	if (softc->hw_lro_oid != NULL) {
139 		orc = sysctl_ctx_free(&softc->hw_lro_ctx);
140 		if (orc)
141 			rc = orc;
142 		else
143 			softc->hw_lro_oid = NULL;
144 	}
145 
146 	if (softc->flow_ctrl_oid != NULL) {
147 		orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
148 		if (orc)
149 			rc = orc;
150 		else
151 			softc->flow_ctrl_oid = NULL;
152 	}
153 
154 	return rc;
155 }
156 
157 int
158 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
159 {
160 	struct sysctl_oid *oid;
161 	struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats[txr].idi_vaddr;
162 	char	name[32];
163 	char	desc[64];
164 
165 	sprintf(name, "txq%d", txr);
166 	sprintf(desc, "transmit queue %d", txr);
167 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
168 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
169 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
170 	if (!oid)
171 		return ENOMEM;
172 
173 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
174 	    "ucast_pkts", CTLFLAG_RD, &tx_stats->tx_ucast_pkts,
175 	    "unicast packets sent");
176 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
177 	    "mcast_pkts", CTLFLAG_RD, &tx_stats->tx_mcast_pkts,
178 	    "multicast packets sent");
179 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
180 	    "bcast_pkts", CTLFLAG_RD, &tx_stats->tx_bcast_pkts,
181 	    "broadcast packets sent");
182 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
183 	    "discard_pkts", CTLFLAG_RD,
184 	    &tx_stats->tx_discard_pkts, "discarded transmit packets");
185 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
186 	    "error_pkts", CTLFLAG_RD, &tx_stats->tx_error_pkts,
187 	    "Error transmit packets");
188 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
189 	    "ucast_bytes", CTLFLAG_RD, &tx_stats->tx_ucast_bytes,
190 	    "unicast bytes sent");
191 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
192 	    "mcast_bytes", CTLFLAG_RD, &tx_stats->tx_mcast_bytes,
193 	    "multicast bytes sent");
194 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
195 	    "bcast_bytes", CTLFLAG_RD, &tx_stats->tx_bcast_bytes,
196 	    "broadcast bytes sent");
197 
198 	return 0;
199 }
200 
201 int
202 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
203 {
204 	struct sysctl_oid *oid;
205 	char	name[32];
206 	char	desc[64];
207 
208 	sprintf(name, "port_stats");
209 	sprintf(desc, "Port Stats");
210 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
211 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
212 	        CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
213 	if (!oid)
214 		return ENOMEM;
215 
216 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
217 	    "tx_64b_frames", CTLFLAG_RD,
218 	    &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
219 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
220 	    "tx_65b_127b_frames", CTLFLAG_RD,
221 	    &softc->tx_port_stats->tx_65b_127b_frames,
222 	    "Transmitted 65b 127b frames");
223 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
224 	    "tx_128b_255b_frames", CTLFLAG_RD,
225 	    &softc->tx_port_stats->tx_128b_255b_frames,
226 	    "Transmitted 128b 255b frames");
227 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
228 	    "tx_256b_511b_frames", CTLFLAG_RD,
229 	    &softc->tx_port_stats->tx_256b_511b_frames,
230 	    "Transmitted 256b 511b frames");
231 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
232 	    "tx_512b_1023b_frames", CTLFLAG_RD,
233 	    &softc->tx_port_stats->tx_512b_1023b_frames,
234 	    "Transmitted 512b 1023b frames");
235 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
236 	    "tx_1024b_1518b_frames", CTLFLAG_RD,
237 	    &softc->tx_port_stats->tx_1024b_1518b_frames,
238 	    "Transmitted 1024b 1518b frames");
239 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
240 	    "tx_good_vlan_frames", CTLFLAG_RD,
241 	    &softc->tx_port_stats->tx_good_vlan_frames,
242 	    "Transmitted good vlan frames");
243 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
244 	    "tx_1519b_2047b_frames", CTLFLAG_RD,
245 	    &softc->tx_port_stats->tx_1519b_2047b_frames,
246 	    "Transmitted 1519b 2047b frames");
247 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
248 	    "tx_2048b_4095b_frames", CTLFLAG_RD,
249 	    &softc->tx_port_stats->tx_2048b_4095b_frames,
250 	    "Transmitted 2048b 4095b frames");
251 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
252 	    "tx_4096b_9216b_frames", CTLFLAG_RD,
253 	    &softc->tx_port_stats->tx_4096b_9216b_frames,
254 	    "Transmitted 4096b 9216b frames");
255 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
256 	    "tx_9217b_16383b_frames", CTLFLAG_RD,
257 	    &softc->tx_port_stats->tx_9217b_16383b_frames,
258 	    "Transmitted 9217b 16383b frames");
259 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
260 	    "tx_good_frames", CTLFLAG_RD,
261 	    &softc->tx_port_stats->tx_good_frames, "Transmitted good frames");
262 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
263 	    "tx_total_frames", CTLFLAG_RD,
264 	    &softc->tx_port_stats->tx_total_frames, "Transmitted total frames");
265 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
266 	    "tx_ucast_frames", CTLFLAG_RD,
267 	    &softc->tx_port_stats->tx_ucast_frames, "Transmitted ucast frames");
268 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
269 	    "tx_mcast_frames", CTLFLAG_RD,
270 	    &softc->tx_port_stats->tx_mcast_frames, "Transmitted mcast frames");
271 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
272 	    "tx_bcast_frames", CTLFLAG_RD,
273 	    &softc->tx_port_stats->tx_bcast_frames, "Transmitted bcast frames");
274 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
275 	    "tx_pause_frames", CTLFLAG_RD,
276 	    &softc->tx_port_stats->tx_pause_frames, "Transmitted pause frames");
277 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
278 	    "tx_pfc_frames", CTLFLAG_RD,
279 	    &softc->tx_port_stats->tx_pfc_frames, "Transmitted pfc frames");
280 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
281 	    "tx_jabber_frames", CTLFLAG_RD,
282 	    &softc->tx_port_stats->tx_jabber_frames, "Transmitted jabber frames");
283 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
284 	    "tx_fcs_err_frames", CTLFLAG_RD,
285 	    &softc->tx_port_stats->tx_fcs_err_frames,
286 	    "Transmitted fcs err frames");
287 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
288 	    "tx_err", CTLFLAG_RD,
289 	    &softc->tx_port_stats->tx_err, "Transmitted err");
290 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
291 	    "tx_fifo_underruns", CTLFLAG_RD,
292 	    &softc->tx_port_stats->tx_fifo_underruns,
293 	    "Transmitted fifo underruns");
294 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
295 	    "tx_pfc_ena_frames_pri0", CTLFLAG_RD,
296 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri0,
297 	    "Transmitted pfc ena frames pri0");
298 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
299 	    "tx_pfc_ena_frames_pri1", CTLFLAG_RD,
300 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri1,
301 	    "Transmitted pfc ena frames pri1");
302 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
303 	    "tx_pfc_ena_frames_pri2", CTLFLAG_RD,
304 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri2,
305 	    "Transmitted pfc ena frames pri2");
306 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
307 	    "tx_pfc_ena_frames_pri3", CTLFLAG_RD,
308 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri3,
309 	    "Transmitted pfc ena frames pri3");
310 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
311 	    "tx_pfc_ena_frames_pri4", CTLFLAG_RD,
312 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri4,
313 	    "Transmitted pfc ena frames pri4");
314 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
315 	    "tx_pfc_ena_frames_pri5", CTLFLAG_RD,
316 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri5,
317 	    "Transmitted pfc ena frames pri5");
318 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
319 	    "tx_pfc_ena_frames_pri6", CTLFLAG_RD,
320 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri6,
321 	    "Transmitted pfc ena frames pri6");
322 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
323 	    "tx_pfc_ena_frames_pri7", CTLFLAG_RD,
324 	    &softc->tx_port_stats->tx_pfc_ena_frames_pri7,
325 	    "Transmitted pfc ena frames pri7");
326 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
327 	    "tx_eee_lpi_events", CTLFLAG_RD,
328 	    &softc->tx_port_stats->tx_eee_lpi_events,
329 	    "Transmitted eee lpi events");
330 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
331 	    "tx_eee_lpi_duration", CTLFLAG_RD,
332 	    &softc->tx_port_stats->tx_eee_lpi_duration,
333 	    "Transmitted eee lpi duration");
334 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
335 	    "tx_llfc_logical_msgs", CTLFLAG_RD,
336 	    &softc->tx_port_stats->tx_llfc_logical_msgs,
337 	    "Transmitted llfc logical msgs");
338 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
339 	    "tx_hcfc_msgs", CTLFLAG_RD,
340 	    &softc->tx_port_stats->tx_hcfc_msgs, "Transmitted hcfc msgs");
341 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
342 	    "tx_total_collisions", CTLFLAG_RD,
343 	    &softc->tx_port_stats->tx_total_collisions,
344 	    "Transmitted total collisions");
345 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
346 	    "tx_bytes", CTLFLAG_RD,
347 	    &softc->tx_port_stats->tx_bytes, "Transmitted bytes");
348 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
349 	    "tx_xthol_frames", CTLFLAG_RD,
350 	    &softc->tx_port_stats->tx_xthol_frames, "Transmitted xthol frames");
351 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
352 	    "tx_stat_discard", CTLFLAG_RD,
353 	    &softc->tx_port_stats->tx_stat_discard, "Transmitted stat discard");
354 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
355 	    "tx_stat_error", CTLFLAG_RD,
356 	    &softc->tx_port_stats->tx_stat_error, "Transmitted stat error");
357 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
358 	    "rx_64b_frames", CTLFLAG_RD,
359 	    &softc->rx_port_stats->rx_64b_frames, "Received 64b frames");
360 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
361 	    "rx_65b_127b_frames", CTLFLAG_RD,
362 	    &softc->rx_port_stats->rx_65b_127b_frames, "Received 65b 127b frames");
363 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
364 	    "rx_128b_255b_frames", CTLFLAG_RD,
365 	    &softc->rx_port_stats->rx_128b_255b_frames,
366 	    "Received 128b 255b frames");
367 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
368 	    "rx_256b_511b_frames", CTLFLAG_RD,
369 	    &softc->rx_port_stats->rx_256b_511b_frames,
370 	    "Received 256b 511b frames");
371 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
372 	    "rx_512b_1023b_frames", CTLFLAG_RD,
373 	    &softc->rx_port_stats->rx_512b_1023b_frames,
374 	    "Received 512b 1023b frames");
375 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
376 	    "rx_1024b_1518b_frames", CTLFLAG_RD,
377 	    &softc->rx_port_stats->rx_1024b_1518b_frames,
378 	    "Received 1024b 1518 frames");
379 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
380 	    "rx_good_vlan_frames", CTLFLAG_RD,
381 	    &softc->rx_port_stats->rx_good_vlan_frames,
382 	    "Received good vlan frames");
383 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
384 	    "rx_1519b_2047b_frames", CTLFLAG_RD,
385 	    &softc->rx_port_stats->rx_1519b_2047b_frames,
386 	    "Received 1519b 2047b frames");
387 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
388 	    "rx_2048b_4095b_frames", CTLFLAG_RD,
389 	    &softc->rx_port_stats->rx_2048b_4095b_frames,
390 	    "Received 2048b 4095b frames");
391 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
392 	    "rx_4096b_9216b_frames", CTLFLAG_RD,
393 	    &softc->rx_port_stats->rx_4096b_9216b_frames,
394 	    "Received 4096b 9216b frames");
395 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
396 	    "rx_9217b_16383b_frames", CTLFLAG_RD,
397 	    &softc->rx_port_stats->rx_9217b_16383b_frames,
398 	    "Received 9217b 16383b frames");
399 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
400 	    "rx_total_frames", CTLFLAG_RD,
401 	    &softc->rx_port_stats->rx_total_frames, "Received total frames");
402 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
403 	    "rx_ucast_frames", CTLFLAG_RD,
404 	    &softc->rx_port_stats->rx_ucast_frames, "Received ucast frames");
405 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
406 	    "rx_mcast_frames", CTLFLAG_RD,
407 	    &softc->rx_port_stats->rx_mcast_frames, "Received mcast frames");
408 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
409 	    "rx_bcast_frames", CTLFLAG_RD,
410 	    &softc->rx_port_stats->rx_bcast_frames, "Received bcast frames");
411 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
412 	    "rx_fcs_err_frames", CTLFLAG_RD,
413 	    &softc->rx_port_stats->rx_fcs_err_frames, "Received fcs err frames");
414 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
415 	    "rx_ctrl_frames", CTLFLAG_RD,
416 	    &softc->rx_port_stats->rx_ctrl_frames, "Received ctrl frames");
417 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
418 	    "rx_pause_frames", CTLFLAG_RD,
419 	    &softc->rx_port_stats->rx_pause_frames, "Received pause frames");
420 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
421 	    "rx_pfc_frames", CTLFLAG_RD,
422 	    &softc->rx_port_stats->rx_pfc_frames, "Received pfc frames");
423 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
424 	    "rx_align_err_frames", CTLFLAG_RD,
425 	    &softc->rx_port_stats->rx_align_err_frames,
426 	    "Received align err frames");
427 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
428 	    "rx_ovrsz_frames", CTLFLAG_RD,
429 	    &softc->rx_port_stats->rx_ovrsz_frames,
430 	    "Received ovrsz frames");
431 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
432 	    "rx_jbr_frames", CTLFLAG_RD,
433 	    &softc->rx_port_stats->rx_jbr_frames,
434 	    "Received jbr frames");
435 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
436 	    "rx_mtu_err_frames", CTLFLAG_RD,
437 	    &softc->rx_port_stats->rx_mtu_err_frames,
438 	    "Received mtu err frames");
439 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
440 	    "rx_tagged_frames", CTLFLAG_RD,
441 	    &softc->rx_port_stats->rx_tagged_frames,
442 	    "Received tagged frames");
443 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
444 	    "rx_double_tagged_frames", CTLFLAG_RD,
445 	    &softc->rx_port_stats->rx_double_tagged_frames,
446 	    "Received double tagged frames");
447 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
448 	    "rx_good_frames", CTLFLAG_RD,
449 	    &softc->rx_port_stats->rx_good_frames,
450 	    "Received good frames");
451 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
452 	    "rx_pfc_ena_frames_pri0", CTLFLAG_RD,
453 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri0,
454 	    "Received pfc ena frames pri0");
455 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
456 	    "rx_pfc_ena_frames_pri1", CTLFLAG_RD,
457 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri1,
458 	    "Received pfc ena frames pri1");
459 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
460 	    "rx_pfc_ena_frames_pri2", CTLFLAG_RD,
461 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri2,
462 	    "Received pfc ena frames pri2");
463 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
464 	    "rx_pfc_ena_frames_pri3", CTLFLAG_RD,
465 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri3,
466 	    "Received pfc ena frames pri3");
467 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
468 	    "rx_pfc_ena_frames_pri4", CTLFLAG_RD,
469 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri4,
470 	    "Received pfc ena frames pri4");
471 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
472 	    "rx_pfc_ena_frames_pri5", CTLFLAG_RD,
473 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri5,
474 	    "Received pfc ena frames pri5");
475 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
476 	    "rx_pfc_ena_frames_pri6", CTLFLAG_RD,
477 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri6,
478 	    "Received pfc ena frames pri6");
479 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
480 	    "rx_pfc_ena_frames_pri7", CTLFLAG_RD,
481 	    &softc->rx_port_stats->rx_pfc_ena_frames_pri7,
482 	    "Received pfc ena frames pri7");
483 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
484 	    "rx_sch_crc_err_frames", CTLFLAG_RD,
485 	    &softc->rx_port_stats->rx_sch_crc_err_frames,
486 	    "Received sch crc err frames");
487 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
488 	    "rx_undrsz_frames", CTLFLAG_RD,
489 	    &softc->rx_port_stats->rx_undrsz_frames, "Received undrsz frames");
490 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
491 	    "rx_eee_lpi_events", CTLFLAG_RD,
492 	    &softc->rx_port_stats->rx_eee_lpi_events, "Received eee lpi events");
493 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
494 	    "rx_eee_lpi_duration", CTLFLAG_RD,
495 	    &softc->rx_port_stats->rx_eee_lpi_duration,
496 	    "Received eee lpi duration");
497 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
498 	    "rx_llfc_physical_msgs", CTLFLAG_RD,
499 	    &softc->rx_port_stats->rx_llfc_physical_msgs,
500 	    "Received llfc physical msgs");
501 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
502 	    "rx_llfc_logical_msgs", CTLFLAG_RD,
503 	    &softc->rx_port_stats->rx_llfc_logical_msgs,
504 	    "Received llfc logical msgs");
505 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
506 	    "rx_llfc_msgs_with_crc_err", CTLFLAG_RD,
507 	    &softc->rx_port_stats->rx_llfc_msgs_with_crc_err,
508 	    "Received llfc msgs with crc err");
509 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
510 	    "rx_hcfc_msgs", CTLFLAG_RD,
511 	    &softc->rx_port_stats->rx_hcfc_msgs, "Received hcfc msgs");
512 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
513 	    "rx_hcfc_msgs_with_crc_err", CTLFLAG_RD,
514 	    &softc->rx_port_stats->rx_hcfc_msgs_with_crc_err,
515 	    "Received hcfc msgs with crc err");
516 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
517 	    "rx_bytes", CTLFLAG_RD,
518 	    &softc->rx_port_stats->rx_bytes, "Received bytes");
519 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
520 	    "rx_runt_bytes", CTLFLAG_RD,
521 	    &softc->rx_port_stats->rx_runt_bytes, "Received runt bytes");
522 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
523 	    "rx_runt_frames", CTLFLAG_RD,
524 	    &softc->rx_port_stats->rx_runt_frames, "Received runt frames");
525 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
526 	    "rx_stat_discard", CTLFLAG_RD,
527 	    &softc->rx_port_stats->rx_stat_discard, "Received stat discard");
528 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
529 	    "rx_stat_err", CTLFLAG_RD,
530 	    &softc->rx_port_stats->rx_stat_err, "Received stat err");
531 
532 	if (BNXT_CHIP_P5(softc) &&
533 	    (softc->flags & BNXT_FLAG_FW_CAP_EXT_STATS)) {
534 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
535 		    "tx_bytes_cos0", CTLFLAG_RD,
536 		    &softc->tx_port_stats_ext->tx_bytes_cos0, "Transmitted bytes count cos0");
537 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
538 		    "tx_packets_cos0", CTLFLAG_RD,
539 		    &softc->tx_port_stats_ext->tx_packets_cos0, "Transmitted packets count cos0");
540 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
541 		    "tx_bytes_cos1", CTLFLAG_RD,
542 		    &softc->tx_port_stats_ext->tx_bytes_cos1, "Transmitted bytes count cos1");
543 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
544 		    "tx_packets_cos1", CTLFLAG_RD,
545 		    &softc->tx_port_stats_ext->tx_packets_cos1, "Transmitted packets count cos1");
546 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
547 		    "tx_bytes_cos2", CTLFLAG_RD,
548 		    &softc->tx_port_stats_ext->tx_bytes_cos2, "Transmitted bytes count cos2");
549 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
550 		    "tx_packets_cos2", CTLFLAG_RD,
551 		    &softc->tx_port_stats_ext->tx_packets_cos2, "Transmitted packets count cos2");
552 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
553 		    "tx_bytes_cos3", CTLFLAG_RD,
554 		    &softc->tx_port_stats_ext->tx_bytes_cos3, "Transmitted bytes count cos3");
555 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
556 		    "tx_packets_cos3", CTLFLAG_RD,
557 		    &softc->tx_port_stats_ext->tx_packets_cos3, "Transmitted packets count cos3");
558 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
559 		    "tx_bytes_cos4", CTLFLAG_RD,
560 		    &softc->tx_port_stats_ext->tx_bytes_cos4, "Transmitted bytes count cos4");
561 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
562 		    "tx_packets_cos4", CTLFLAG_RD,
563 		    &softc->tx_port_stats_ext->tx_packets_cos4, "Transmitted packets count cos4");
564 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
565 		    "tx_bytes_cos5", CTLFLAG_RD,
566 		    &softc->tx_port_stats_ext->tx_bytes_cos5, "Transmitted bytes count cos5");
567 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
568 		    "tx_packets_cos5", CTLFLAG_RD,
569 		    &softc->tx_port_stats_ext->tx_packets_cos5, "Transmitted packets count cos5");
570 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
571 		    "tx_bytes_cos6", CTLFLAG_RD,
572 		    &softc->tx_port_stats_ext->tx_bytes_cos6, "Transmitted bytes count cos6");
573 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
574 		    "tx_packets_cos6", CTLFLAG_RD,
575 		    &softc->tx_port_stats_ext->tx_packets_cos6, "Transmitted packets count cos6");
576 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
577 		    "tx_bytes_cos7", CTLFLAG_RD,
578 		    &softc->tx_port_stats_ext->tx_bytes_cos7, "Transmitted bytes count cos7");
579 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
580 		    "tx_packets_cos7", CTLFLAG_RD,
581 		    &softc->tx_port_stats_ext->tx_packets_cos7, "Transmitted packets count cos7");
582 
583 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
584 		    "pfc_pri0_tx_duration_us", CTLFLAG_RD,
585 		    &softc->tx_port_stats_ext->pfc_pri0_tx_duration_us, "Time duration between"
586 		    "XON to XOFF and XOFF to XON for pri0");
587 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
588 		    "pfc_pri0_tx_transitions", CTLFLAG_RD,
589 		    &softc->tx_port_stats_ext->pfc_pri0_tx_transitions, "Num times transition"
590 		    "between XON to XOFF and XOFF to XON for pri0");
591 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
592 		    "pfc_pri1_tx_duration_us", CTLFLAG_RD,
593 		    &softc->tx_port_stats_ext->pfc_pri1_tx_duration_us, "Time duration between"
594 		    "XON to XOFF and XOFF to XON for pri1");
595 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
596 		    "pfc_pri1_tx_transitions", CTLFLAG_RD,
597 		    &softc->tx_port_stats_ext->pfc_pri1_tx_transitions, "Num times transition"
598 		    "between XON to XOFF and XOFF to XON for pri1");
599 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
600 		    "pfc_pri2_tx_duration_us", CTLFLAG_RD,
601 		    &softc->tx_port_stats_ext->pfc_pri2_tx_duration_us, "Time duration between"
602 		    "XON to XOFF and XOFF to XON for pri2");
603 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
604 		    "pfc_pri2_tx_transitions", CTLFLAG_RD,
605 		    &softc->tx_port_stats_ext->pfc_pri2_tx_transitions, "Num times transition"
606 		    "between XON to XOFF and XOFF to XON for pri2");
607 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
608 		    "pfc_pri3_tx_duration_us", CTLFLAG_RD,
609 		    &softc->tx_port_stats_ext->pfc_pri3_tx_duration_us, "Time duration between"
610 		    "XON to XOFF and XOFF to XON for pri3");
611 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
612 		    "pfc_pri3_tx_transitions", CTLFLAG_RD,
613 		    &softc->tx_port_stats_ext->pfc_pri3_tx_transitions, "Num times transition"
614 		    "between XON to XOFF and XOFF to XON for pri3");
615 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
616 		    "pfc_pri4_tx_duration_us", CTLFLAG_RD,
617 		    &softc->tx_port_stats_ext->pfc_pri4_tx_duration_us, "Time duration between"
618 		    "XON to XOFF and XOFF to XON for pri4");
619 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
620 		    "pfc_pri4_tx_transitions", CTLFLAG_RD,
621 		    &softc->tx_port_stats_ext->pfc_pri4_tx_transitions, "Num times transition"
622 		    "between XON to XOFF and XOFF to XON for pri4");
623 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
624 		    "pfc_pri5_tx_duration_us", CTLFLAG_RD,
625 		    &softc->tx_port_stats_ext->pfc_pri5_tx_duration_us, "Time duration between"
626 		    "XON to XOFF and XOFF to XON for pri5");
627 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
628 		    "pfc_pri5_tx_transitions", CTLFLAG_RD,
629 		    &softc->tx_port_stats_ext->pfc_pri5_tx_transitions, "Num times transition"
630 		    "between XON to XOFF and XOFF to XON for pri5");
631 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
632 		    "pfc_pri6_tx_duration_us", CTLFLAG_RD,
633 		    &softc->tx_port_stats_ext->pfc_pri6_tx_duration_us, "Time duration between"
634 		    "XON to XOFF and XOFF to XON for pri6");
635 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
636 		    "pfc_pri6_tx_transitions", CTLFLAG_RD,
637 		    &softc->tx_port_stats_ext->pfc_pri6_tx_transitions, "Num times transition"
638 		    "between XON to XOFF and XOFF to XON for pri6");
639 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
640 		    "pfc_pri7_tx_duration_us", CTLFLAG_RD,
641 		    &softc->tx_port_stats_ext->pfc_pri7_tx_duration_us, "Time duration between"
642 		    "XON to XOFF and XOFF to XON for pri7");
643 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
644 		    "pfc_pri7_tx_transitions", CTLFLAG_RD,
645 		    &softc->tx_port_stats_ext->pfc_pri7_tx_transitions, "Num times transition"
646 		    "between XON to XOFF and XOFF to XON for pri7");
647 
648 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
649 		    "link_down_events", CTLFLAG_RD,
650 		    &softc->rx_port_stats_ext->link_down_events, "Num times link states down");
651 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
652 		    "continuous_pause_events", CTLFLAG_RD,
653 		    &softc->rx_port_stats_ext->continuous_pause_events, "Num times pause events");
654 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
655 		    "resume_pause_events", CTLFLAG_RD,
656 		    &softc->rx_port_stats_ext->resume_pause_events, "Num times pause events"
657 		    "resumes");
658 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
659 		    "continuous_roce_pause_events", CTLFLAG_RD,
660 		    &softc->rx_port_stats_ext->continuous_roce_pause_events, "Num times roce"
661 		    "pause events");
662 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
663 		    "resume_roce_pause_events", CTLFLAG_RD,
664 		    &softc->rx_port_stats_ext->resume_roce_pause_events, "Num times roce pause"
665 		    "events resumes");
666 
667 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
668 		    "rx_bytes_cos0", CTLFLAG_RD,
669 		    &softc->rx_port_stats_ext->rx_bytes_cos0, "Received bytes count cos0");
670 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
671 		    "rx_packets_cos0", CTLFLAG_RD,
672 		    &softc->rx_port_stats_ext->rx_packets_cos0, "Received packets count cos0");
673 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
674 		    "rx_bytes_cos1", CTLFLAG_RD,
675 		    &softc->rx_port_stats_ext->rx_bytes_cos1, "Received bytes count cos1");
676 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
677 		    "rx_packets_cos1", CTLFLAG_RD,
678 		    &softc->rx_port_stats_ext->rx_packets_cos1, "Received packets count cos1");
679 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
680 		    "rx_bytes_cos2", CTLFLAG_RD,
681 		    &softc->rx_port_stats_ext->rx_bytes_cos2, "Received bytes count cos2");
682 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
683 		    "rx_packets_cos2", CTLFLAG_RD,
684 		    &softc->rx_port_stats_ext->rx_packets_cos2, "Received packets count cos2");
685 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
686 		    "rx_bytes_cos3", CTLFLAG_RD,
687 		    &softc->rx_port_stats_ext->rx_bytes_cos3, "Received bytes count cos3");
688 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
689 		    "rx_packets_cos3", CTLFLAG_RD,
690 		    &softc->rx_port_stats_ext->rx_packets_cos3, "Received packets count cos3");
691 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
692 		    "rx_bytes_cos4", CTLFLAG_RD,
693 		    &softc->rx_port_stats_ext->rx_bytes_cos4, "Received bytes count cos4");
694 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
695 		    "rx_packets_cos4", CTLFLAG_RD,
696 		    &softc->rx_port_stats_ext->rx_packets_cos4, "Received packets count cos4");
697 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
698 		    "rx_bytes_cos5", CTLFLAG_RD,
699 		    &softc->rx_port_stats_ext->rx_bytes_cos5, "Received bytes count cos5");
700 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
701 		    "rx_packets_cos5", CTLFLAG_RD,
702 		    &softc->rx_port_stats_ext->rx_packets_cos5, "Received packets count cos5");
703 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
704 		    "rx_bytes_cos6", CTLFLAG_RD,
705 		    &softc->rx_port_stats_ext->rx_bytes_cos6, "Received bytes count cos6");
706 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
707 		    "rx_packets_cos6", CTLFLAG_RD,
708 		    &softc->rx_port_stats_ext->rx_packets_cos6, "Received packets count cos6");
709 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
710 		    "rx_bytes_cos7", CTLFLAG_RD,
711 		    &softc->rx_port_stats_ext->rx_bytes_cos7, "Received bytes count cos7");
712 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
713 		    "rx_packets_cos7", CTLFLAG_RD,
714 		    &softc->rx_port_stats_ext->rx_packets_cos7, "Received packets count cos7");
715 
716 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
717 		    "pfc_pri0_rx_duration_us", CTLFLAG_RD,
718 		    &softc->rx_port_stats_ext->pfc_pri0_rx_duration_us, "Time duration in receiving"
719 		    "between XON to XOFF and XOFF to XON for pri0");
720 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
721 		    "pfc_pri0_rx_transitions", CTLFLAG_RD,
722 		    &softc->rx_port_stats_ext->pfc_pri0_rx_transitions, "Num times rx transition"
723 		    "between XON to XOFF and XOFF to XON for pri0");
724 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
725 		    "pfc_pri1_rx_duration_us", CTLFLAG_RD,
726 		    &softc->rx_port_stats_ext->pfc_pri1_rx_duration_us, "Time duration in receiving"
727 		    "between XON to XOFF and XOFF to XON for pri1");
728 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
729 		    "pfc_pri1_rx_transitions", CTLFLAG_RD,
730 		    &softc->rx_port_stats_ext->pfc_pri1_rx_transitions, "Num times rx transition"
731 		    "between XON to XOFF and XOFF to XON for pri1");
732 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
733 		    "pfc_pri2_rx_duration_us", CTLFLAG_RD,
734 		    &softc->rx_port_stats_ext->pfc_pri2_rx_duration_us, "Time duration in receiving"
735 		    "between XON to XOFF and XOFF to XON for pri2");
736 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
737 		    "pfc_pri2_rx_transitions", CTLFLAG_RD,
738 		    &softc->rx_port_stats_ext->pfc_pri2_rx_transitions, "Num times rx transition"
739 		    "between XON to XOFF and XOFF to XON for pri2");
740 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
741 		    "pfc_pri3_rx_duration_us", CTLFLAG_RD,
742 		    &softc->rx_port_stats_ext->pfc_pri3_rx_duration_us, "Time duration in receiving"
743 		    "between XON to XOFF and XOFF to XON for pri3");
744 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
745 		    "pfc_pri3_rx_transitions", CTLFLAG_RD,
746 		    &softc->rx_port_stats_ext->pfc_pri3_rx_transitions, "Num times rx transition"
747 		    "between XON to XOFF and XOFF to XON for pri3");
748 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
749 		    "pfc_pri4_rx_duration_us", CTLFLAG_RD,
750 		    &softc->rx_port_stats_ext->pfc_pri4_rx_duration_us, "Time duration in receiving"
751 		    "between XON to XOFF and XOFF to XON for pri4");
752 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
753 		    "pfc_pri4_rx_transitions", CTLFLAG_RD,
754 		    &softc->rx_port_stats_ext->pfc_pri4_rx_transitions, "Num times rx transition"
755 		    "between XON to XOFF and XOFF to XON for pri4");
756 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
757 		    "pfc_pri5_rx_duration_us", CTLFLAG_RD,
758 		    &softc->rx_port_stats_ext->pfc_pri5_rx_duration_us, "Time duration in receiving"
759 		    "between XON to XOFF and XOFF to XON for pri5");
760 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
761 		    "pfc_pri5_rx_transitions", CTLFLAG_RD,
762 		    &softc->rx_port_stats_ext->pfc_pri5_rx_transitions, "Num times rx transition"
763 		    "between XON to XOFF and XOFF to XON for pri5");
764 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
765 		    "pfc_pri6_rx_duration_us", CTLFLAG_RD,
766 		    &softc->rx_port_stats_ext->pfc_pri6_rx_duration_us, "Time duration in receiving"
767 		    "between XON to XOFF and XOFF to XON for pri6");
768 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
769 		    "pfc_pri6_rx_transitions", CTLFLAG_RD,
770 		    &softc->rx_port_stats_ext->pfc_pri6_rx_transitions, "Num times rx transition"
771 		    "between XON to XOFF and XOFF to XON for pri6");
772 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
773 		    "pfc_pri7_rx_duration_us", CTLFLAG_RD,
774 		    &softc->rx_port_stats_ext->pfc_pri7_rx_duration_us, "Time duration in receiving"
775 		    "between XON to XOFF and XOFF to XON for pri7");
776 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
777 		    "pfc_pri7_rx_transitions", CTLFLAG_RD,
778 		    &softc->rx_port_stats_ext->pfc_pri7_rx_transitions, "Num times rx transition"
779 		    "between XON to XOFF and XOFF to XON for pri7");
780 
781 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
782 		    "rx_bits", CTLFLAG_RD,
783 		    &softc->rx_port_stats_ext->rx_bits, "total number of received bits");
784 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
785 		    "rx_buffer_passed_threshold", CTLFLAG_RD,
786 		    &softc->rx_port_stats_ext->rx_buffer_passed_threshold, "num of events port"
787 		    "buffer"
788 		    "was over 85%");
789 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
790 		    "rx_pcs_symbol_err", CTLFLAG_RD,
791 		    &softc->rx_port_stats_ext->rx_pcs_symbol_err, "num of symbol errors wasn't"
792 		    "corrected by FEC");
793 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
794 		    "rx_corrected_bits", CTLFLAG_RD,
795 		    &softc->rx_port_stats_ext->rx_corrected_bits, "num of bits corrected by FEC");
796 
797 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
798 		    "rx_discard_bytes_cos0", CTLFLAG_RD,
799 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos0, "num of rx discard bytes"
800 		    "count on cos0");
801 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
802 		    "rx_discard_packets_cos0", CTLFLAG_RD,
803 		    &softc->rx_port_stats_ext->rx_discard_packets_cos0, "num of rx discard packets"
804 		    "count on cos0");
805 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
806 		    "rx_discard_bytes_cos1", CTLFLAG_RD,
807 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos1, "num of rx discard bytes"
808 		    "count on cos1");
809 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
810 		    "rx_discard_packets_cos1", CTLFLAG_RD,
811 		    &softc->rx_port_stats_ext->rx_discard_packets_cos1, "num of rx discard packets"
812 		    "count on cos1");
813 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
814 		    "rx_discard_bytes_cos2", CTLFLAG_RD,
815 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos2, "num of rx discard bytes"
816 		    "count on cos2");
817 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
818 		    "rx_discard_packets_cos2", CTLFLAG_RD,
819 		    &softc->rx_port_stats_ext->rx_discard_packets_cos2, "num of rx discard packets"
820 		    "count on cos2");
821 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
822 		    "rx_discard_bytes_cos3", CTLFLAG_RD,
823 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos3, "num of rx discard bytes"
824 		    "count on cos3");
825 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
826 		    "rx_discard_packets_cos3", CTLFLAG_RD,
827 		    &softc->rx_port_stats_ext->rx_discard_packets_cos3, "num of rx discard packets"
828 		    "count on cos3");
829 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
830 		    "rx_discard_bytes_cos4", CTLFLAG_RD,
831 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos4, "num of rx discard bytes"
832 		    "count on cos4");
833 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
834 		    "rx_discard_packets_cos4", CTLFLAG_RD,
835 		    &softc->rx_port_stats_ext->rx_discard_packets_cos4, "num of rx discard packets"
836 		    "count on cos4");
837 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
838 		    "rx_discard_bytes_cos5", CTLFLAG_RD,
839 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos5, "num of rx discard bytes"
840 		    "count on cos5");
841 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
842 		    "rx_discard_packets_cos5", CTLFLAG_RD,
843 		    &softc->rx_port_stats_ext->rx_discard_packets_cos5, "num of rx discard packets"
844 		    "count on cos5");
845 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
846 		    "rx_discard_bytes_cos6", CTLFLAG_RD,
847 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos6, "num of rx discard bytes"
848 		    "count on cos6");
849 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
850 		    "rx_discard_packets_cos6", CTLFLAG_RD,
851 		    &softc->rx_port_stats_ext->rx_discard_packets_cos6, "num of rx discard packets"
852 		    "count on cos6");
853 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
854 		    "rx_discard_bytes_cos7", CTLFLAG_RD,
855 		    &softc->rx_port_stats_ext->rx_discard_bytes_cos7, "num of rx discard bytes"
856 		    "count on cos7");
857 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
858 		    "rx_discard_packets_cos7", CTLFLAG_RD,
859 		    &softc->rx_port_stats_ext->rx_discard_packets_cos7, "num of rx discard packets"
860 		    "count on cos7");
861 	}
862 
863 
864 	return 0;
865 }
866 
867 int
868 bnxt_create_rx_sysctls(struct bnxt_softc *softc, int rxr)
869 {
870 	struct sysctl_oid *oid;
871 	struct ctx_hw_stats *rx_stats = (void *)softc->rx_stats[rxr].idi_vaddr;
872 	char	name[32];
873 	char	desc[64];
874 
875 	sprintf(name, "rxq%d", rxr);
876 	sprintf(desc, "receive queue %d", rxr);
877 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
878 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
879 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
880 	if (!oid)
881 		return ENOMEM;
882 
883 	if (BNXT_CHIP_P5(softc))
884 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
885 		    "nq_num_ints", CTLFLAG_RD, &softc->nq_rings[rxr].int_count,
886 		    "Num Interrupts");
887 	else
888 		SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
889 		    "rq_num_ints", CTLFLAG_RD, &softc->rx_cp_rings[rxr].int_count,
890 		    "Num Interrupts");
891 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
892 	    "ucast_pkts", CTLFLAG_RD, &rx_stats->rx_ucast_pkts,
893 	    "unicast packets received");
894 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
895 	    "mcast_pkts", CTLFLAG_RD, &rx_stats->rx_mcast_pkts,
896 	    "multicast packets received");
897 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
898 	    "bcast_pkts", CTLFLAG_RD, &rx_stats->rx_bcast_pkts,
899 	    "broadcast packets received");
900 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
901 	    "discard_pkts", CTLFLAG_RD,
902 	    &rx_stats->rx_discard_pkts, "discarded receive packets");
903 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
904 	    "error_pkts", CTLFLAG_RD, &rx_stats->rx_error_pkts,
905 	    "Error receive packets");
906 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
907 	    "ucast_bytes", CTLFLAG_RD, &rx_stats->rx_ucast_bytes,
908 	    "unicast bytes received");
909 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
910 	    "mcast_bytes", CTLFLAG_RD, &rx_stats->rx_mcast_bytes,
911 	    "multicast bytes received");
912 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
913 	    "bcast_bytes", CTLFLAG_RD, &rx_stats->rx_bcast_bytes,
914 	    "broadcast bytes received");
915 
916 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
917 	    "tpa_pkts", CTLFLAG_RD, &rx_stats->tpa_pkts,
918 	    "TPA packets");
919 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
920 	    "tpa_bytes", CTLFLAG_RD, &rx_stats->tpa_bytes,
921 	    "TPA bytes");
922 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
923 	    "tpa_events", CTLFLAG_RD, &rx_stats->tpa_events,
924 	    "TPA events");
925 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
926 	    "tpa_aborts", CTLFLAG_RD, &rx_stats->tpa_aborts,
927 	    "TPA aborts");
928 
929 	return 0;
930 }
931 
932 static char *bnxt_chip_type[] = {
933 	"ASIC",
934 	"FPGA",
935 	"Palladium",
936 	"Unknown"
937 };
938 #define MAX_CHIP_TYPE 3
939 
940 static char *bnxt_parse_pkglog(int desired_field, uint8_t *data, size_t datalen)
941 {
942 	char    *retval = NULL;
943 	char    *p;
944 	char    *value;
945 	int     field = 0;
946 
947 	if (datalen < 1)
948 		return NULL;
949 	/* null-terminate the log data (removing last '\n'): */
950 	data[datalen - 1] = 0;
951 	for (p = data; *p != 0; p++) {
952 		field = 0;
953 		retval = NULL;
954 		while (*p != 0 && *p != '\n') {
955 			value = p;
956 			while (*p != 0 && *p != '\t' && *p != '\n')
957 				p++;
958 			if (field == desired_field)
959 				retval = value;
960 			if (*p != '\t')
961 				break;
962 			*p = 0;
963 			field++;
964 			p++;
965 		}
966 		if (*p == 0)
967 			break;
968 		*p = 0;
969 	}
970 	return retval;
971 }
972 
973 static int
974 bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)
975 {
976 	struct bnxt_softc *softc = arg1;
977 	struct iflib_dma_info dma_data;
978 	char *pkglog = NULL;
979 	char *p;
980 	char unk[] = "<unknown>";
981 	char *buf = unk;
982 	int rc;
983 	uint16_t ordinal = BNX_DIR_ORDINAL_FIRST;
984 	uint16_t index;
985 	uint32_t data_len;
986 
987 	rc = bnxt_hwrm_nvm_find_dir_entry(softc, BNX_DIR_TYPE_PKG_LOG,
988 	    &ordinal, BNX_DIR_EXT_NONE, &index, false,
989 	    HWRM_NVM_FIND_DIR_ENTRY_INPUT_OPT_ORDINAL_EQ,
990 	    &data_len, NULL, NULL);
991 	dma_data.idi_vaddr = NULL;
992 	if (rc == 0 && data_len) {
993 		rc = iflib_dma_alloc(softc->ctx, data_len, &dma_data,
994 		    BUS_DMA_NOWAIT);
995 		if (rc == 0) {
996 			rc = bnxt_hwrm_nvm_read(softc, index, 0, data_len,
997 			    &dma_data);
998 			if (rc == 0) {
999 				pkglog = dma_data.idi_vaddr;
1000 				p = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkglog, data_len);
1001 				if (p && *p != 0 && isdigit(*p))
1002 					buf = p;
1003 			}
1004 		} else
1005 			dma_data.idi_vaddr = NULL;
1006 	}
1007 
1008 	rc = sysctl_handle_string(oidp, buf, 0, req);
1009 	if (dma_data.idi_vaddr)
1010 		iflib_dma_free(&dma_data);
1011 	return rc;
1012 }
1013 
1014 static int
1015 bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)
1016 {
1017 	struct bnxt_softc *softc = arg1;
1018 	char buf[16];
1019 	uint8_t	newver[3];
1020 	int rc;
1021 
1022 	sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
1023 	    softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
1024 
1025 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1026 	if (rc || req->newptr == NULL)
1027 		return rc;
1028 	if (sscanf(buf, "%hhu.%hhu.%hhu%*c", &newver[0], &newver[1],
1029 	    &newver[2]) != 3)
1030 		return EINVAL;
1031 	softc->ver_info->hwrm_min_major = newver[0];
1032 	softc->ver_info->hwrm_min_minor = newver[1];
1033 	softc->ver_info->hwrm_min_update = newver[2];
1034 	bnxt_check_hwrm_version(softc);
1035 
1036 	return rc;
1037 }
1038 
1039 int
1040 bnxt_create_ver_sysctls(struct bnxt_softc *softc)
1041 {
1042 	struct bnxt_ver_info *vi = softc->ver_info;
1043 	struct sysctl_oid *oid = vi->ver_oid;
1044 
1045 	if (!oid)
1046 		return ENOMEM;
1047 
1048 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1049 	    "hwrm_if", CTLFLAG_RD, vi->hwrm_if_ver, 0,
1050 	    "HWRM interface version");
1051 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1052 	    "driver_hwrm_if", CTLFLAG_RD, vi->driver_hwrm_if_ver, 0,
1053 	    "HWRM firmware version");
1054 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1055 	    "hwrm_fw", CTLFLAG_RD, vi->hwrm_fw_ver, 0,
1056 	    "HWRM firmware version");
1057 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1058 	    "mgmt_fw", CTLFLAG_RD, vi->mgmt_fw_ver, 0,
1059 	    "management firmware version");
1060 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1061 	    "netctrl_fw", CTLFLAG_RD, vi->netctrl_fw_ver, 0,
1062 	    "network control firmware version");
1063 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1064 	    "roce_fw", CTLFLAG_RD, vi->roce_fw_ver, 0,
1065 	    "RoCE firmware version");
1066 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1067 	    "fw_ver", CTLFLAG_RD, vi->fw_ver_str, 0,
1068 	    "Firmware version");
1069 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1070 	    "phy", CTLFLAG_RD, vi->phy_ver, 0,
1071 	    "PHY version");
1072 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1073 	    "hwrm_fw_name", CTLFLAG_RD, vi->hwrm_fw_name, 0,
1074 	    "HWRM firmware name");
1075 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1076 	    "mgmt_fw_name", CTLFLAG_RD, vi->mgmt_fw_name, 0,
1077 	    "management firmware name");
1078 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1079 	    "netctrl_fw_name", CTLFLAG_RD, vi->netctrl_fw_name, 0,
1080 	    "network control firmware name");
1081 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1082 	    "roce_fw_name", CTLFLAG_RD, vi->roce_fw_name, 0,
1083 	    "RoCE firmware name");
1084 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1085 	    "phy_vendor", CTLFLAG_RD, vi->phy_vendor, 0,
1086 	    "PHY vendor name");
1087 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1088 	    "phy_partnumber", CTLFLAG_RD, vi->phy_partnumber, 0,
1089 	    "PHY vendor part number");
1090 	SYSCTL_ADD_U16(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1091 	    "chip_num", CTLFLAG_RD, &vi->chip_num, 0, "chip number");
1092 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1093 	    "chip_rev", CTLFLAG_RD, &vi->chip_rev, 0, "chip revision");
1094 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1095 	    "chip_metal", CTLFLAG_RD, &vi->chip_metal, 0, "chip metal number");
1096 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1097 	    "chip_bond_id", CTLFLAG_RD, &vi->chip_bond_id, 0,
1098 	    "chip bond id");
1099 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1100 	    "chip_type", CTLFLAG_RD, vi->chip_type > MAX_CHIP_TYPE ?
1101 	    bnxt_chip_type[MAX_CHIP_TYPE] : bnxt_chip_type[vi->chip_type], 0,
1102 	    "RoCE firmware name");
1103 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1104 	    "package_ver", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1105 	    softc, 0, bnxt_package_ver_sysctl, "A",
1106 	    "currently installed package version");
1107 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1108 	    "hwrm_min_ver", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1109 	    softc, 0, bnxt_hwrm_min_ver_sysctl, "A",
1110 	    "minimum hwrm API vesion to support");
1111 
1112 	return 0;
1113 }
1114 
1115 int
1116 bnxt_create_nvram_sysctls(struct bnxt_nvram_info *ni)
1117 {
1118 	struct sysctl_oid *oid = ni->nvm_oid;
1119 
1120 	if (!oid)
1121 		return ENOMEM;
1122 
1123 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1124 	    "mfg_id", CTLFLAG_RD, &ni->mfg_id, 0, "manufacturer id");
1125 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1126 	    "device_id", CTLFLAG_RD, &ni->device_id, 0, "device id");
1127 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1128 	    "sector_size", CTLFLAG_RD, &ni->sector_size, 0, "sector size");
1129 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1130 	    "size", CTLFLAG_RD, &ni->size, 0, "nvram total size");
1131 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1132 	    "reserved_size", CTLFLAG_RD, &ni->reserved_size, 0,
1133 	    "total reserved space");
1134 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1135 	    "available_size", CTLFLAG_RD, &ni->available_size, 0,
1136 	    "total available space");
1137 
1138 	return 0;
1139 }
1140 
1141 static int
1142 bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)
1143 {
1144 	struct bnxt_softc *softc = arg1;
1145 	char buf[HW_HASH_KEY_SIZE*2+1] = {0};
1146 	char *p;
1147 	int i;
1148 	int rc;
1149 
1150 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++)
1151 		p += sprintf(p, "%02x", softc->vnic_info.rss_hash_key[i]);
1152 
1153 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1154 	if (rc || req->newptr == NULL)
1155 		return rc;
1156 
1157 	if (strspn(buf, "0123456789abcdefABCDEF") != (HW_HASH_KEY_SIZE * 2))
1158 		return EINVAL;
1159 
1160 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++) {
1161 		if (sscanf(p, "%02hhx", &softc->vnic_info.rss_hash_key[i]) != 1)
1162 			return EINVAL;
1163 		p += 2;
1164 	}
1165 
1166 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1167 		bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1168 		    softc->vnic_info.rss_hash_type);
1169 
1170 	return rc;
1171 }
1172 
1173 static const char *bnxt_hash_types[] = {"ipv4", "tcp_ipv4", "udp_ipv4", "ipv6",
1174     "tcp_ipv6", "udp_ipv6", NULL};
1175 
1176 static int bnxt_get_rss_type_str_bit(char *str)
1177 {
1178 	int i;
1179 
1180 	for (i=0; bnxt_hash_types[i]; i++)
1181 		if (strcmp(bnxt_hash_types[i], str) == 0)
1182 			return i;
1183 
1184 	return -1;
1185 }
1186 
1187 static int
1188 bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)
1189 {
1190 	struct bnxt_softc *softc = arg1;
1191 	char buf[256] = {0};
1192 	char *p;
1193 	char *next;
1194 	int rc;
1195 	int type;
1196 	int bit;
1197 
1198 	for (type = softc->vnic_info.rss_hash_type; type;
1199 	    type &= ~(1<<bit)) {
1200 		bit = ffs(type) - 1;
1201 		if (bit >= sizeof(bnxt_hash_types) / sizeof(const char *))
1202 			continue;
1203 		if (type != softc->vnic_info.rss_hash_type)
1204 			strcat(buf, ",");
1205 		strcat(buf, bnxt_hash_types[bit]);
1206 	}
1207 
1208 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1209 	if (rc || req->newptr == NULL)
1210 		return rc;
1211 
1212 	for (type = 0, next = buf, p = strsep(&next, " ,"); p;
1213 	    p = strsep(&next, " ,")) {
1214 		bit = bnxt_get_rss_type_str_bit(p);
1215 		if (bit == -1)
1216 			return EINVAL;
1217 		type |= 1<<bit;
1218 	}
1219 	if (type != softc->vnic_info.rss_hash_type) {
1220 		softc->vnic_info.rss_hash_type = type;
1221 		if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1222 			bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
1223 			    softc->vnic_info.rss_hash_type);
1224 	}
1225 
1226 	return rc;
1227 }
1228 
1229 static int
1230 bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS) {
1231 	struct bnxt_softc *softc = arg1;
1232 	int rc;
1233 	int val;
1234 
1235 	if (softc == NULL)
1236 		return EBUSY;
1237 
1238 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_BD_STALL);
1239 	rc = sysctl_handle_int(oidp, &val, 0, req);
1240 	if (rc || !req->newptr)
1241 		return rc;
1242 
1243 	if (val)
1244 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_BD_STALL;
1245 	else
1246 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_BD_STALL;
1247 
1248 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1249 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1250 
1251 	return rc;
1252 }
1253 
1254 static int
1255 bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS) {
1256 	struct bnxt_softc *softc = arg1;
1257 	int rc;
1258 	int val;
1259 
1260 	if (softc == NULL)
1261 		return EBUSY;
1262 
1263 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_VLAN_STRIP);
1264 	rc = sysctl_handle_int(oidp, &val, 0, req);
1265 	if (rc || !req->newptr)
1266 		return rc;
1267 
1268 	if (val)
1269 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_VLAN_STRIP;
1270 	else
1271 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_VLAN_STRIP;
1272 
1273 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1274 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1275 
1276 	return rc;
1277 }
1278 
1279 static int
1280 bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS) {
1281 	struct bnxt_softc *softc = arg1;
1282 	int rc;
1283 	int val;
1284 
1285 	if (softc == NULL)
1286 		return EBUSY;
1287 
1288 	val = softc->rx_coal_usecs;
1289 	rc = sysctl_handle_int(oidp, &val, 0, req);
1290 	if (rc || !req->newptr)
1291 		return rc;
1292 
1293 	softc->rx_coal_usecs = val;
1294 	rc = bnxt_hwrm_set_coal(softc);
1295 
1296 	return rc;
1297 }
1298 
1299 static int
1300 bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS) {
1301 	struct bnxt_softc *softc = arg1;
1302 	int rc;
1303 	int val;
1304 
1305 	if (softc == NULL)
1306 		return EBUSY;
1307 
1308 	val = softc->rx_coal_frames;
1309 	rc = sysctl_handle_int(oidp, &val, 0, req);
1310 	if (rc || !req->newptr)
1311 		return rc;
1312 
1313 	softc->rx_coal_frames = val;
1314 	rc = bnxt_hwrm_set_coal(softc);
1315 
1316 	return rc;
1317 }
1318 
1319 static int
1320 bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1321 	struct bnxt_softc *softc = arg1;
1322 	int rc;
1323 	int val;
1324 
1325 	if (softc == NULL)
1326 		return EBUSY;
1327 
1328 	val = softc->rx_coal_usecs_irq;
1329 	rc = sysctl_handle_int(oidp, &val, 0, req);
1330 	if (rc || !req->newptr)
1331 		return rc;
1332 
1333 	softc->rx_coal_usecs_irq = val;
1334 	rc = bnxt_hwrm_set_coal(softc);
1335 
1336 	return rc;
1337 }
1338 
1339 static int
1340 bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS) {
1341 	struct bnxt_softc *softc = arg1;
1342 	int rc;
1343 	int val;
1344 
1345 	if (softc == NULL)
1346 		return EBUSY;
1347 
1348 	val = softc->rx_coal_frames_irq;
1349 	rc = sysctl_handle_int(oidp, &val, 0, req);
1350 	if (rc || !req->newptr)
1351 		return rc;
1352 
1353 	softc->rx_coal_frames_irq = val;
1354 	rc = bnxt_hwrm_set_coal(softc);
1355 
1356 	return rc;
1357 }
1358 
1359 static int
1360 bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS) {
1361 	struct bnxt_softc *softc = arg1;
1362 	int rc;
1363 	int val;
1364 
1365 	if (softc == NULL)
1366 		return EBUSY;
1367 
1368 	val = softc->tx_coal_usecs;
1369 	rc = sysctl_handle_int(oidp, &val, 0, req);
1370 	if (rc || !req->newptr)
1371 		return rc;
1372 
1373 	softc->tx_coal_usecs = val;
1374 	rc = bnxt_hwrm_set_coal(softc);
1375 
1376 	return rc;
1377 }
1378 
1379 static int
1380 bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS) {
1381 	struct bnxt_softc *softc = arg1;
1382 	int rc;
1383 	int val;
1384 
1385 	if (softc == NULL)
1386 		return EBUSY;
1387 
1388 	val = softc->tx_coal_frames;
1389 	rc = sysctl_handle_int(oidp, &val, 0, req);
1390 	if (rc || !req->newptr)
1391 		return rc;
1392 
1393 	softc->tx_coal_frames = val;
1394 	rc = bnxt_hwrm_set_coal(softc);
1395 
1396 	return rc;
1397 }
1398 
1399 static int
1400 bnxt_set_coal_tx_usecs_irq(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->tx_coal_usecs_irq;
1409 	rc = sysctl_handle_int(oidp, &val, 0, req);
1410 	if (rc || !req->newptr)
1411 		return rc;
1412 
1413 	softc->tx_coal_usecs_irq = val;
1414 	rc = bnxt_hwrm_set_coal(softc);
1415 
1416 	return rc;
1417 }
1418 
1419 static int
1420 bnxt_set_coal_tx_frames_irq(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->tx_coal_frames_irq;
1429 	rc = sysctl_handle_int(oidp, &val, 0, req);
1430 	if (rc || !req->newptr)
1431 		return rc;
1432 
1433 	softc->tx_coal_frames_irq = val;
1434 	rc = bnxt_hwrm_set_coal(softc);
1435 
1436 	return rc;
1437 }
1438 
1439 int
1440 bnxt_create_config_sysctls_pre(struct bnxt_softc *softc)
1441 {
1442 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1443 	struct sysctl_oid_list *children;
1444 
1445 	children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));
1446 
1447 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_key",
1448 	    CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1449 	    bnxt_rss_key_sysctl, "A", "RSS key");
1450 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_type",
1451 	    CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1452 	    bnxt_rss_type_sysctl, "A", "RSS type bits");
1453 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_stall",
1454 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1455 	    bnxt_rx_stall_sysctl, "I",
1456 	    "buffer rx packets in hardware until the host posts new buffers");
1457 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_strip",
1458 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1459 	    bnxt_vlan_strip_sysctl, "I", "strip VLAN tag in the RX path");
1460 	SYSCTL_ADD_CONST_STRING(ctx, children, OID_AUTO, "if_name", CTLFLAG_RD,
1461 		if_name(iflib_get_ifp(softc->ctx)), "interface name");
1462 
1463         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs",
1464             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1465 	    bnxt_set_coal_rx_usecs, "I", "interrupt coalescing Rx Usecs");
1466         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames",
1467             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1468 	    bnxt_set_coal_rx_frames, "I", "interrupt coalescing Rx Frames");
1469         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs_irq",
1470             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1471 	    bnxt_set_coal_rx_usecs_irq, "I",
1472 	    "interrupt coalescing Rx Usecs IRQ");
1473         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames_irq",
1474             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1475 	    bnxt_set_coal_rx_frames_irq, "I",
1476 	    "interrupt coalescing Rx Frames IRQ");
1477         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs",
1478             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1479 	    bnxt_set_coal_tx_usecs, "I", "interrupt coalescing Tx Usces");
1480         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames",
1481             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1482 	    bnxt_set_coal_tx_frames, "I", "interrupt coalescing Tx Frames");
1483         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs_irq",
1484             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1485 	    bnxt_set_coal_tx_usecs_irq, "I",
1486 	    "interrupt coalescing Tx Usecs IRQ");
1487         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames_irq",
1488             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1489 	    bnxt_set_coal_tx_frames_irq, "I",
1490 	    "interrupt coalescing Tx Frames IRQ");
1491 
1492 	return 0;
1493 }
1494 
1495 #define BNXT_HW_LRO_FN(fn_name, arg)			                   \
1496 static int						                   \
1497 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1498 	struct bnxt_softc *softc = arg1;		                   \
1499 	int rc;						                   \
1500 	int val;					                   \
1501 							                   \
1502 	if (softc == NULL)				                   \
1503 		return EBUSY;				                   \
1504 							                   \
1505 	val = softc->hw_lro.arg;			                   \
1506 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1507 	if (rc || !req->newptr)				                   \
1508 		return rc;				                   \
1509 							                   \
1510 	if ((if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)) \
1511 		return EBUSY;				                   \
1512 							                   \
1513 	if (!(softc->flags & BNXT_FLAG_TPA))				   \
1514 		return EINVAL;						   \
1515 							                   \
1516 	softc->hw_lro.arg = val;			                   \
1517 	bnxt_validate_hw_lro_settings(softc);		                   \
1518 	rc = bnxt_hwrm_vnic_tpa_cfg(softc);		                   \
1519 							                   \
1520 	return rc;					                   \
1521 }
1522 
1523 BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable, enable)
1524 BNXT_HW_LRO_FN(bnxt_hw_lro_set_mode, is_mode_gro)
1525 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_agg_segs, max_agg_segs)
1526 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_aggs, max_aggs)
1527 BNXT_HW_LRO_FN(bnxt_hw_lro_set_min_agg_len, min_agg_len)
1528 
1529 #define BNXT_FLOW_CTRL_FN(fn_name, arg)			                   \
1530 static int						                   \
1531 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1532 	struct bnxt_softc *softc = arg1;		                   \
1533 	int rc;						                   \
1534 	int val;					                   \
1535 							                   \
1536 	if (softc == NULL)				                   \
1537 		return EBUSY;				                   \
1538 							                   \
1539 	val = softc->link_info.flow_ctrl.arg;			           \
1540 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1541 	if (rc || !req->newptr)				                   \
1542 		return rc;				                   \
1543 							                   \
1544 	if (val)					                   \
1545 	   	val = 1; 				                   \
1546 	        					                   \
1547 	if (softc->link_info.flow_ctrl.arg != val) {		           \
1548 		softc->link_info.flow_ctrl.arg = val;		           \
1549 		rc = bnxt_hwrm_set_link_setting(softc, true, false, false);\
1550 		rc = bnxt_hwrm_port_phy_qcfg(softc);			   \
1551 	}						                   \
1552 							                   \
1553 	return rc;					                   \
1554 }
1555 
1556 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_tx, tx)
1557 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_rx, rx)
1558 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_autoneg, autoneg)
1559 int
1560 bnxt_create_pause_fc_sysctls(struct bnxt_softc *softc)
1561 {
1562 	struct sysctl_oid *oid = softc->flow_ctrl_oid;
1563 
1564 	if (!oid)
1565 		return ENOMEM;
1566 
1567 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1568 	    "tx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1569 	    bnxt_flow_ctrl_tx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1570 
1571 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1572 	    "rx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1573 	    bnxt_flow_ctrl_rx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1574 
1575 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1576 	    "autoneg", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1577 	    0, bnxt_flow_ctrl_autoneg, "A",
1578 	    "Enable or Disable Autoneg Flow Ctrl: 0 / 1");
1579 
1580 	return 0;
1581 }
1582 
1583 int
1584 bnxt_create_hw_lro_sysctls(struct bnxt_softc *softc)
1585 {
1586 	struct sysctl_oid *oid = softc->hw_lro_oid;
1587 
1588 	if (!oid)
1589 		return ENOMEM;
1590 
1591 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1592 	    "enable", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1593 	    0, bnxt_hw_lro_enable_disable, "A",
1594 	    "Enable or Disable HW LRO: 0 / 1");
1595 
1596 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1597 	    "gro_mode", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1598 	    0, bnxt_hw_lro_set_mode, "A",
1599 	    "Set mode: 1 = GRO mode, 0 = RSC mode");
1600 
1601 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1602 	    "max_agg_segs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1603 	    softc, 0, bnxt_hw_lro_set_max_agg_segs, "A",
1604 	    "Set Max Agg Seg Value (unit is Log2): "
1605 	    "0 (= 1 seg) / 1 (= 2 segs) /  ... / 31 (= 2^31 segs)");
1606 
1607         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1608 	    "max_aggs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1609 	    softc, 0, bnxt_hw_lro_set_max_aggs, "A",
1610 	    "Set Max Aggs Value (unit is Log2): "
1611 	    "0 (= 1 agg) / 1 (= 2 aggs) /  ... / 7 (= 2^7 segs)");
1612 
1613 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1614 	    "min_agg_len", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1615 	    softc, 0, bnxt_hw_lro_set_min_agg_len, "A",
1616 	    "Min Agg Len: 1 to 9000");
1617 
1618 	return 0;
1619 }
1620 
1621 int
1622 bnxt_create_config_sysctls_post(struct bnxt_softc *softc)
1623 {
1624 	/* Nothing for now, meant for future expansion */
1625 	return 0;
1626 }
1627