xref: /freebsd/sys/dev/bnxt/bnxt_sysctl.c (revision b00ab754)
1 /*-
2  * Broadcom NetXtreme-C/E network driver.
3  *
4  * Copyright (c) 2016 Broadcom, All Rights Reserved.
5  * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include <sys/types.h>
33 #include <sys/sysctl.h>
34 
35 #include "bnxt.h"
36 #include "bnxt_hwrm.h"
37 #include "bnxt_sysctl.h"
38 
39 static int bnxt_vlan_only_sysctl(SYSCTL_HANDLER_ARGS);
40 /*
41  * We want to create:
42  * dev.bnxt.0.hwstats.txq0
43  * dev.bnxt.0.hwstats.txq0.txmbufs
44  * dev.bnxt.0.hwstats.rxq0
45  * dev.bnxt.0.hwstats.txq0.rxmbufs
46  * so the hwstats ctx list needs to be created in attach_post and populated
47  * during init.
48  *
49  * Then, it needs to be cleaned up in stop.
50  */
51 
52 int
53 bnxt_init_sysctl_ctx(struct bnxt_softc *softc)
54 {
55 	struct sysctl_ctx_list *ctx;
56 
57 	sysctl_ctx_init(&softc->hw_stats);
58 	ctx = device_get_sysctl_ctx(softc->dev);
59 	softc->hw_stats_oid = SYSCTL_ADD_NODE(ctx,
60 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
61 	    "hwstats", CTLFLAG_RD, 0, "hardware statistics");
62 	if (!softc->hw_stats_oid) {
63 		sysctl_ctx_free(&softc->hw_stats);
64 		return ENOMEM;
65 	}
66 
67 	sysctl_ctx_init(&softc->ver_info->ver_ctx);
68 	ctx = device_get_sysctl_ctx(softc->dev);
69 	softc->ver_info->ver_oid = SYSCTL_ADD_NODE(ctx,
70 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
71 	    "ver", CTLFLAG_RD, 0, "hardware/firmware version information");
72 	if (!softc->ver_info->ver_oid) {
73 		sysctl_ctx_free(&softc->ver_info->ver_ctx);
74 		return ENOMEM;
75 	}
76 
77 	if (BNXT_PF(softc)) {
78 		sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
79 		ctx = device_get_sysctl_ctx(softc->dev);
80 		softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
81 		    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
82 		    "nvram", CTLFLAG_RD, 0, "nvram information");
83 		if (!softc->nvm_info->nvm_oid) {
84 			sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
85 			return ENOMEM;
86 		}
87 	}
88 
89 	sysctl_ctx_init(&softc->hw_lro_ctx);
90 	ctx = device_get_sysctl_ctx(softc->dev);
91 	softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
92 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
93 	    "hw_lro", CTLFLAG_RD, 0, "hardware lro");
94 	if (!softc->hw_lro_oid) {
95 		sysctl_ctx_free(&softc->hw_lro_ctx);
96 		return ENOMEM;
97 	}
98 
99 	sysctl_ctx_init(&softc->flow_ctrl_ctx);
100 	ctx = device_get_sysctl_ctx(softc->dev);
101 	softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
102 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
103 	    "fc", CTLFLAG_RD, 0, "flow ctrl");
104 	if (!softc->flow_ctrl_oid) {
105 		sysctl_ctx_free(&softc->flow_ctrl_ctx);
106 		return ENOMEM;
107 	}
108 
109 	return 0;
110 }
111 
112 int
113 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
114 {
115 	int orc;
116 	int rc = 0;
117 
118 	if (softc->hw_stats_oid != NULL) {
119 		orc = sysctl_ctx_free(&softc->hw_stats);
120 		if (orc)
121 			rc = orc;
122 		else
123 			softc->hw_stats_oid = NULL;
124 	}
125 	if (softc->ver_info->ver_oid != NULL) {
126 		orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
127 		if (orc)
128 			rc = orc;
129 		else
130 			softc->ver_info->ver_oid = NULL;
131 	}
132 	if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
133 		orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
134 		if (orc)
135 			rc = orc;
136 		else
137 			softc->nvm_info->nvm_oid = NULL;
138 	}
139 	if (softc->hw_lro_oid != NULL) {
140 		orc = sysctl_ctx_free(&softc->hw_lro_ctx);
141 		if (orc)
142 			rc = orc;
143 		else
144 			softc->hw_lro_oid = NULL;
145 	}
146 
147 	if (softc->flow_ctrl_oid != NULL) {
148 		orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
149 		if (orc)
150 			rc = orc;
151 		else
152 			softc->flow_ctrl_oid = NULL;
153 	}
154 
155 	return rc;
156 }
157 
158 int
159 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
160 {
161 	struct sysctl_oid *oid;
162 	struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats.idi_vaddr;
163 	char	name[32];
164 	char	desc[64];
165 
166 	sprintf(name, "txq%d", txr);
167 	sprintf(desc, "transmit queue %d", txr);
168 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
169 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name, CTLFLAG_RD, 0,
170 	    desc);
171 	if (!oid)
172 		return ENOMEM;
173 
174 
175 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
176 	    "ucast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_ucast_pkts,
177 	    "unicast packets sent");
178 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
179 	    "mcast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_mcast_pkts,
180 	    "multicast packets sent");
181 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
182 	    "bcast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_bcast_pkts,
183 	    "broadcast packets sent");
184 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
185 	    "discard_pkts", CTLFLAG_RD,
186 	    &tx_stats[txr].tx_discard_pkts, "discarded transmit packets");
187 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
188 	    "drop_pkts", CTLFLAG_RD, &tx_stats[txr].tx_drop_pkts,
189 	    "dropped transmit packets");
190 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
191 	    "ucast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_ucast_bytes,
192 	    "unicast bytes sent");
193 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
194 	    "mcast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_mcast_bytes,
195 	    "multicast bytes sent");
196 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
197 	    "bcast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_bcast_bytes,
198 	    "broadcast bytes sent");
199 
200 	return 0;
201 }
202 
203 int
204 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
205 {
206 	struct sysctl_oid *oid;
207 	char	name[32];
208 	char	desc[64];
209 
210 	sprintf(name, "port_stats");
211 	sprintf(desc, "Port Stats");
212 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
213 			SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name, CTLFLAG_RD, 0,
214 			desc);
215 	if (!oid)
216 		return ENOMEM;
217 
218 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
219 	    "tx_64b_frames", CTLFLAG_RD,
220  	    &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
221 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
222 	    "tx_65b_127b_frames", CTLFLAG_RD,
223  	    &softc->tx_port_stats->tx_65b_127b_frames,
224 	    "Transmitted 65b 127b frames");
225 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
226 	    "tx_128b_255b_frames", CTLFLAG_RD,
227  	    &softc->tx_port_stats->tx_128b_255b_frames,
228 	    "Transmitted 128b 255b frames");
229 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
230 	    "tx_256b_511b_frames", CTLFLAG_RD,
231  	    &softc->tx_port_stats->tx_256b_511b_frames,
232 	    "Transmitted 256b 511b frames");
233 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
234 	    "tx_512b_1023b_frames", CTLFLAG_RD,
235  	    &softc->tx_port_stats->tx_512b_1023b_frames,
236 	    "Transmitted 512b 1023b frames");
237 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
238 	    "tx_1024b_1518_frames", CTLFLAG_RD,
239  	    &softc->tx_port_stats->tx_1024b_1518_frames,
240 	    "Transmitted 1024b 1518 frames");
241 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
242 	    "tx_good_vlan_frames", CTLFLAG_RD,
243  	    &softc->tx_port_stats->tx_good_vlan_frames,
244 	    "Transmitted good vlan frames");
245 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
246 	    "tx_1519b_2047_frames", CTLFLAG_RD,
247  	    &softc->tx_port_stats->tx_1519b_2047_frames,
248 	    "Transmitted 1519b 2047 frames");
249 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
250 	    "tx_2048b_4095b_frames", CTLFLAG_RD,
251  	    &softc->tx_port_stats->tx_2048b_4095b_frames,
252 	    "Transmitted 2048b 4095b frames");
253 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
254 	    "tx_4096b_9216b_frames", CTLFLAG_RD,
255  	    &softc->tx_port_stats->tx_4096b_9216b_frames,
256 	    "Transmitted 4096b 9216b frames");
257 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
258 	    "tx_9217b_16383b_frames", CTLFLAG_RD,
259 	    &softc->tx_port_stats->tx_9217b_16383b_frames,
260 	    "Transmitted 9217b 16383b frames");
261 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
262 	    "tx_good_frames", CTLFLAG_RD,
263  	    &softc->tx_port_stats->tx_good_frames, "Transmitted good frames");
264 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
265 	    "tx_total_frames", CTLFLAG_RD,
266  	    &softc->tx_port_stats->tx_total_frames, "Transmitted total frames");
267 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
268 	    "tx_ucast_frames", CTLFLAG_RD,
269  	    &softc->tx_port_stats->tx_ucast_frames, "Transmitted ucast frames");
270 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
271 	    "tx_mcast_frames", CTLFLAG_RD,
272  	    &softc->tx_port_stats->tx_mcast_frames, "Transmitted mcast frames");
273 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
274 	    "tx_bcast_frames", CTLFLAG_RD,
275  	    &softc->tx_port_stats->tx_bcast_frames, "Transmitted bcast frames");
276 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
277 	    "tx_pause_frames", CTLFLAG_RD,
278  	    &softc->tx_port_stats->tx_pause_frames, "Transmitted pause frames");
279 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
280 	    "tx_pfc_frames", CTLFLAG_RD,
281  	    &softc->tx_port_stats->tx_pfc_frames, "Transmitted pfc frames");
282 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
283 	    "tx_jabber_frames", CTLFLAG_RD,
284  	    &softc->tx_port_stats->tx_jabber_frames, "Transmitted jabber frames");
285 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
286 	    "tx_fcs_err_frames", CTLFLAG_RD,
287  	    &softc->tx_port_stats->tx_fcs_err_frames,
288 	    "Transmitted fcs err frames");
289 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
290 	    "tx_control_frames", CTLFLAG_RD,
291  	    &softc->tx_port_stats->tx_control_frames,
292 	    "Transmitted control frames");
293 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
294 	    "tx_oversz_frames", CTLFLAG_RD,
295  	    &softc->tx_port_stats->tx_oversz_frames, "Transmitted oversz frames");
296 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
297 	    "tx_single_dfrl_frames", CTLFLAG_RD,
298  	    &softc->tx_port_stats->tx_single_dfrl_frames,
299 	    "Transmitted single dfrl frames");
300 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
301 	    "tx_multi_dfrl_frames", CTLFLAG_RD,
302  	    &softc->tx_port_stats->tx_multi_dfrl_frames,
303 	    "Transmitted multi dfrl frames");
304 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
305 	    "tx_single_coll_frames", CTLFLAG_RD,
306  	    &softc->tx_port_stats->tx_single_coll_frames,
307 	    "Transmitted single coll frames");
308 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
309 	    "tx_multi_coll_frames", CTLFLAG_RD,
310  	    &softc->tx_port_stats->tx_multi_coll_frames,
311 	    "Transmitted multi coll frames");
312 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
313 	    "tx_late_coll_frames", CTLFLAG_RD,
314  	    &softc->tx_port_stats->tx_late_coll_frames,
315 	    "Transmitted late coll frames");
316 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
317 	    "tx_excessive_coll_frames", CTLFLAG_RD,
318  	    &softc->tx_port_stats->tx_excessive_coll_frames,
319 	    "Transmitted excessive coll frames");
320 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
321 	    "tx_frag_frames", CTLFLAG_RD,
322  	    &softc->tx_port_stats->tx_frag_frames, "Transmitted frag frames");
323 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
324 	    "tx_err", CTLFLAG_RD,
325  	    &softc->tx_port_stats->tx_err, "Transmitted err");
326 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
327 	    "tx_tagged_frames", CTLFLAG_RD,
328  	    &softc->tx_port_stats->tx_tagged_frames, "Transmitted tagged frames");
329 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
330 	    "tx_dbl_tagged_frames", CTLFLAG_RD,
331  	    &softc->tx_port_stats->tx_dbl_tagged_frames,
332 	    "Transmitted dbl tagged frames");
333 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
334 	    "tx_runt_frames", CTLFLAG_RD,
335  	    &softc->tx_port_stats->tx_runt_frames, "Transmitted runt frames");
336 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
337 	    "tx_fifo_underruns", CTLFLAG_RD,
338  	    &softc->tx_port_stats->tx_fifo_underruns,
339 	    "Transmitted fifo underruns");
340 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
341 	    "tx_pfc_ena_frames_pri0", CTLFLAG_RD,
342  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri0,
343 	    "Transmitted pfc ena frames pri0");
344 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
345 	    "tx_pfc_ena_frames_pri1", CTLFLAG_RD,
346  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri1,
347 	    "Transmitted pfc ena frames pri1");
348 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
349 	    "tx_pfc_ena_frames_pri2", CTLFLAG_RD,
350  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri2,
351 	    "Transmitted pfc ena frames pri2");
352 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
353 	    "tx_pfc_ena_frames_pri3", CTLFLAG_RD,
354  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri3,
355 	    "Transmitted pfc ena frames pri3");
356 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
357 	    "tx_pfc_ena_frames_pri4", CTLFLAG_RD,
358  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri4,
359 	    "Transmitted pfc ena frames pri4");
360 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
361 	    "tx_pfc_ena_frames_pri5", CTLFLAG_RD,
362  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri5,
363 	    "Transmitted pfc ena frames pri5");
364 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
365 	    "tx_pfc_ena_frames_pri6", CTLFLAG_RD,
366  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri6,
367 	    "Transmitted pfc ena frames pri6");
368 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
369 	    "tx_pfc_ena_frames_pri7", CTLFLAG_RD,
370  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri7,
371 	    "Transmitted pfc ena frames pri7");
372 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
373 	    "tx_eee_lpi_events", CTLFLAG_RD,
374  	    &softc->tx_port_stats->tx_eee_lpi_events,
375 	    "Transmitted eee lpi events");
376 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
377 	    "tx_eee_lpi_duration", CTLFLAG_RD,
378  	    &softc->tx_port_stats->tx_eee_lpi_duration,
379 	    "Transmitted eee lpi duration");
380 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
381 	    "tx_llfc_logical_msgs", CTLFLAG_RD,
382  	    &softc->tx_port_stats->tx_llfc_logical_msgs,
383 	    "Transmitted llfc logical msgs");
384 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
385 	    "tx_hcfc_msgs", CTLFLAG_RD,
386  	    &softc->tx_port_stats->tx_hcfc_msgs, "Transmitted hcfc msgs");
387 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
388 	    "tx_total_collisions", CTLFLAG_RD,
389  	    &softc->tx_port_stats->tx_total_collisions,
390 	    "Transmitted total collisions");
391 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
392 	    "tx_bytes", CTLFLAG_RD,
393  	    &softc->tx_port_stats->tx_bytes, "Transmitted bytes");
394 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
395 	    "tx_xthol_frames", CTLFLAG_RD,
396  	    &softc->tx_port_stats->tx_xthol_frames, "Transmitted xthol frames");
397 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
398 	    "tx_stat_discard", CTLFLAG_RD,
399  	    &softc->tx_port_stats->tx_stat_discard, "Transmitted stat discard");
400 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
401 	    "tx_stat_error", CTLFLAG_RD,
402  	    &softc->tx_port_stats->tx_stat_error, "Transmitted stat error");
403 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
404 	    "rx_64b_frames", CTLFLAG_RD,
405  	    &softc->rx_port_stats->rx_64b_frames, "Received 64b frames");
406 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
407 	    "rx_65b_127b_frames", CTLFLAG_RD,
408  	    &softc->rx_port_stats->rx_65b_127b_frames, "Received 65b 127b frames");
409 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
410 	    "rx_128b_255b_frames", CTLFLAG_RD,
411  	    &softc->rx_port_stats->rx_128b_255b_frames,
412 	    "Received 128b 255b frames");
413 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
414 	    "rx_256b_511b_frames", CTLFLAG_RD,
415  	    &softc->rx_port_stats->rx_256b_511b_frames,
416 	    "Received 256b 511b frames");
417 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
418 	    "rx_512b_1023b_frames", CTLFLAG_RD,
419  	    &softc->rx_port_stats->rx_512b_1023b_frames,
420 	    "Received 512b 1023b frames");
421 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
422 	    "rx_1024b_1518_frames", CTLFLAG_RD,
423  	    &softc->rx_port_stats->rx_1024b_1518_frames,
424 	    "Received 1024b 1518 frames");
425 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
426 	    "rx_good_vlan_frames", CTLFLAG_RD,
427  	    &softc->rx_port_stats->rx_good_vlan_frames,
428 	    "Received good vlan frames");
429 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
430 	    "rx_1519b_2047b_frames", CTLFLAG_RD,
431  	    &softc->rx_port_stats->rx_1519b_2047b_frames,
432 	    "Received 1519b 2047b frames");
433 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
434 	    "rx_2048b_4095b_frames", CTLFLAG_RD,
435  	    &softc->rx_port_stats->rx_2048b_4095b_frames,
436 	    "Received 2048b 4095b frames");
437 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
438 	    "rx_4096b_9216b_frames", CTLFLAG_RD,
439  	    &softc->rx_port_stats->rx_4096b_9216b_frames,
440 	    "Received 4096b 9216b frames");
441 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
442 	    "rx_9217b_16383b_frames", CTLFLAG_RD,
443  	    &softc->rx_port_stats->rx_9217b_16383b_frames,
444 	    "Received 9217b 16383b frames");
445 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
446 	    "rx_total_frames", CTLFLAG_RD,
447  	    &softc->rx_port_stats->rx_total_frames, "Received total frames");
448 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
449 	    "rx_ucast_frames", CTLFLAG_RD,
450  	    &softc->rx_port_stats->rx_ucast_frames, "Received ucast frames");
451 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
452 	    "rx_mcast_frames", CTLFLAG_RD,
453  	    &softc->rx_port_stats->rx_mcast_frames, "Received mcast frames");
454 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
455 	    "rx_bcast_frames", CTLFLAG_RD,
456  	    &softc->rx_port_stats->rx_bcast_frames, "Received bcast frames");
457 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
458 	    "rx_fcs_err_frames", CTLFLAG_RD,
459  	    &softc->rx_port_stats->rx_fcs_err_frames, "Received fcs err frames");
460 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
461 	    "rx_ctrl_frames", CTLFLAG_RD,
462  	    &softc->rx_port_stats->rx_ctrl_frames, "Received ctrl frames");
463 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
464 	    "rx_pause_frames", CTLFLAG_RD,
465  	    &softc->rx_port_stats->rx_pause_frames, "Received pause frames");
466 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
467 	    "rx_pfc_frames", CTLFLAG_RD,
468  	    &softc->rx_port_stats->rx_pfc_frames, "Received pfc frames");
469 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
470 	    "rx_unsupported_opcode_frames", CTLFLAG_RD,
471  	    &softc->rx_port_stats->rx_unsupported_opcode_frames,
472 	    "Received unsupported opcode frames");
473 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
474 	    "rx_unsupported_da_pausepfc_frames", CTLFLAG_RD,
475  	    &softc->rx_port_stats->rx_unsupported_da_pausepfc_frames,
476 	    "Received unsupported da pausepfc frames");
477 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
478 	    "rx_wrong_sa_frames", CTLFLAG_RD,
479  	    &softc->rx_port_stats->rx_wrong_sa_frames,
480 	    "Received wrong sa frames");
481 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
482 	    "rx_align_err_frames", CTLFLAG_RD,
483  	    &softc->rx_port_stats->rx_align_err_frames,
484 	    "Received align err frames");
485 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
486 	    "rx_oor_len_frames", CTLFLAG_RD,
487  	    &softc->rx_port_stats->rx_oor_len_frames,
488 	    "Received oor len frames");
489 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
490 	    "rx_code_err_frames", CTLFLAG_RD,
491  	    &softc->rx_port_stats->rx_code_err_frames,
492 	    "Received code err frames");
493 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
494 	    "rx_false_carrier_frames", CTLFLAG_RD,
495  	    &softc->rx_port_stats->rx_false_carrier_frames,
496 	    "Received false carrier frames");
497 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
498 	    "rx_ovrsz_frames", CTLFLAG_RD,
499  	    &softc->rx_port_stats->rx_ovrsz_frames,
500 	    "Received ovrsz frames");
501 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
502 	    "rx_jbr_frames", CTLFLAG_RD,
503  	    &softc->rx_port_stats->rx_jbr_frames,
504 	    "Received jbr frames");
505 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
506 	    "rx_mtu_err_frames", CTLFLAG_RD,
507  	    &softc->rx_port_stats->rx_mtu_err_frames,
508 	    "Received mtu err frames");
509 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
510 	    "rx_match_crc_frames", CTLFLAG_RD,
511  	    &softc->rx_port_stats->rx_match_crc_frames,
512 	    "Received match crc frames");
513 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
514 	    "rx_promiscuous_frames", CTLFLAG_RD,
515  	    &softc->rx_port_stats->rx_promiscuous_frames,
516 	    "Received promiscuous frames");
517 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
518 	    "rx_tagged_frames", CTLFLAG_RD,
519  	    &softc->rx_port_stats->rx_tagged_frames,
520 	    "Received tagged frames");
521 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
522 	    "rx_double_tagged_frames", CTLFLAG_RD,
523  	    &softc->rx_port_stats->rx_double_tagged_frames,
524 	    "Received double tagged frames");
525 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
526 	    "rx_trunc_frames", CTLFLAG_RD,
527  	    &softc->rx_port_stats->rx_trunc_frames,
528 	    "Received trunc frames");
529 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
530 	    "rx_good_frames", CTLFLAG_RD,
531  	    &softc->rx_port_stats->rx_good_frames,
532 	    "Received good frames");
533 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
534 	    "rx_pfc_xon2xoff_frames_pri0", CTLFLAG_RD,
535  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri0,
536 	    "Received pfc xon2xoff frames pri0");
537 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
538 	    "rx_pfc_xon2xoff_frames_pri1", CTLFLAG_RD,
539  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri1,
540 	    "Received pfc xon2xoff frames pri1");
541 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
542 	    "rx_pfc_xon2xoff_frames_pri2", CTLFLAG_RD,
543  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri2,
544 	    "Received pfc xon2xoff frames pri2");
545 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
546 	    "rx_pfc_xon2xoff_frames_pri3", CTLFLAG_RD,
547  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri3,
548 	    "Received pfc xon2xoff frames pri3");
549 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
550 	    "rx_pfc_xon2xoff_frames_pri4", CTLFLAG_RD,
551  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri4,
552 	    "Received pfc xon2xoff frames pri4");
553 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
554 	    "rx_pfc_xon2xoff_frames_pri5", CTLFLAG_RD,
555  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri5,
556 	    "Received pfc xon2xoff frames pri5");
557 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
558 	    "rx_pfc_xon2xoff_frames_pri6", CTLFLAG_RD,
559  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri6,
560 	    "Received pfc xon2xoff frames pri6");
561 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
562 	    "rx_pfc_xon2xoff_frames_pri7", CTLFLAG_RD,
563  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri7,
564 	    "Received pfc xon2xoff frames pri7");
565 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
566 	    "rx_pfc_ena_frames_pri0", CTLFLAG_RD,
567  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri0,
568 	    "Received pfc ena frames pri0");
569 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
570 	    "rx_pfc_ena_frames_pri1", CTLFLAG_RD,
571  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri1,
572 	    "Received pfc ena frames pri1");
573 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
574 	    "rx_pfc_ena_frames_pri2", CTLFLAG_RD,
575  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri2,
576 	    "Received pfc ena frames pri2");
577 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
578 	    "rx_pfc_ena_frames_pri3", CTLFLAG_RD,
579  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri3,
580 	    "Received pfc ena frames pri3");
581 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
582 	    "rx_pfc_ena_frames_pri4", CTLFLAG_RD,
583  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri4,
584 	    "Received pfc ena frames pri4");
585 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
586 	    "rx_pfc_ena_frames_pri5", CTLFLAG_RD,
587  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri5,
588 	    "Received pfc ena frames pri5");
589 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
590 	    "rx_pfc_ena_frames_pri6", CTLFLAG_RD,
591  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri6,
592 	    "Received pfc ena frames pri6");
593 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
594 	    "rx_pfc_ena_frames_pri7", CTLFLAG_RD,
595  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri7,
596 	    "Received pfc ena frames pri7");
597 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
598 	    "rx_sch_crc_err_frames", CTLFLAG_RD,
599  	    &softc->rx_port_stats->rx_sch_crc_err_frames,
600 	    "Received sch crc err frames");
601 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
602 	    "rx_undrsz_frames", CTLFLAG_RD,
603  	    &softc->rx_port_stats->rx_undrsz_frames, "Received undrsz frames");
604 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
605 	    "rx_frag_frames", CTLFLAG_RD,
606  	    &softc->rx_port_stats->rx_frag_frames, "Received frag frames");
607 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
608 	    "rx_eee_lpi_events", CTLFLAG_RD,
609  	    &softc->rx_port_stats->rx_eee_lpi_events, "Received eee lpi events");
610 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
611 	    "rx_eee_lpi_duration", CTLFLAG_RD,
612  	    &softc->rx_port_stats->rx_eee_lpi_duration,
613 	    "Received eee lpi duration");
614 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
615 	    "rx_llfc_physical_msgs", CTLFLAG_RD,
616  	    &softc->rx_port_stats->rx_llfc_physical_msgs,
617 	    "Received llfc physical msgs");
618 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
619 	    "rx_llfc_logical_msgs", CTLFLAG_RD,
620  	    &softc->rx_port_stats->rx_llfc_logical_msgs,
621 	    "Received llfc logical msgs");
622 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
623 	    "rx_llfc_msgs_with_crc_err", CTLFLAG_RD,
624  	    &softc->rx_port_stats->rx_llfc_msgs_with_crc_err,
625 	    "Received llfc msgs with crc err");
626 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
627 	    "rx_hcfc_msgs", CTLFLAG_RD,
628  	    &softc->rx_port_stats->rx_hcfc_msgs, "Received hcfc msgs");
629 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
630 	    "rx_hcfc_msgs_with_crc_err", CTLFLAG_RD,
631  	    &softc->rx_port_stats->rx_hcfc_msgs_with_crc_err,
632 	    "Received hcfc msgs with crc err");
633 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
634 	    "rx_bytes", CTLFLAG_RD,
635  	    &softc->rx_port_stats->rx_bytes, "Received bytes");
636 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
637 	    "rx_runt_bytes", CTLFLAG_RD,
638  	    &softc->rx_port_stats->rx_runt_bytes, "Received runt bytes");
639 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
640 	    "rx_runt_frames", CTLFLAG_RD,
641  	    &softc->rx_port_stats->rx_runt_frames, "Received runt frames");
642 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
643 	    "rx_stat_discard", CTLFLAG_RD,
644  	    &softc->rx_port_stats->rx_stat_discard, "Received stat discard");
645 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
646 	    "rx_stat_err", CTLFLAG_RD,
647  	    &softc->rx_port_stats->rx_stat_err, "Received stat err");
648 
649 	return 0;
650 }
651 
652 
653 int
654 bnxt_create_rx_sysctls(struct bnxt_softc *softc, int rxr)
655 {
656 	struct sysctl_oid *oid;
657 	struct ctx_hw_stats *rx_stats = (void *)softc->rx_stats.idi_vaddr;
658 	char	name[32];
659 	char	desc[64];
660 
661 	sprintf(name, "rxq%d", rxr);
662 	sprintf(desc, "receive queue %d", rxr);
663 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
664 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name, CTLFLAG_RD, 0,
665 	    desc);
666 	if (!oid)
667 		return ENOMEM;
668 
669 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
670 	    "ucast_pkts", CTLFLAG_RD, &rx_stats[rxr].rx_ucast_pkts,
671 	    "unicast packets received");
672 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
673 	    "mcast_pkts", CTLFLAG_RD, &rx_stats[rxr].rx_mcast_pkts,
674 	    "multicast packets received");
675 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
676 	    "bcast_pkts", CTLFLAG_RD, &rx_stats[rxr].rx_bcast_pkts,
677 	    "broadcast packets received");
678 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
679 	    "discard_pkts", CTLFLAG_RD,
680 	    &rx_stats[rxr].rx_discard_pkts, "discarded receive packets");
681 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
682 	    "drop_pkts", CTLFLAG_RD, &rx_stats[rxr].rx_drop_pkts,
683 	    "dropped receive packets");
684 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
685 	    "ucast_bytes", CTLFLAG_RD, &rx_stats[rxr].rx_ucast_bytes,
686 	    "unicast bytes received");
687 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
688 	    "mcast_bytes", CTLFLAG_RD, &rx_stats[rxr].rx_mcast_bytes,
689 	    "multicast bytes received");
690 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
691 	    "bcast_bytes", CTLFLAG_RD, &rx_stats[rxr].rx_bcast_bytes,
692 	    "broadcast bytes received");
693 
694 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
695 	    "tpa_pkts", CTLFLAG_RD, &rx_stats[rxr].tpa_pkts,
696 	    "TPA packets");
697 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
698 	    "tpa_bytes", CTLFLAG_RD, &rx_stats[rxr].tpa_bytes,
699 	    "TPA bytes");
700 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
701 	    "tpa_events", CTLFLAG_RD, &rx_stats[rxr].tpa_events,
702 	    "TPA events");
703 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
704 	    "tpa_aborts", CTLFLAG_RD, &rx_stats[rxr].tpa_aborts,
705 	    "TPA aborts");
706 
707 	return 0;
708 }
709 
710 static char *bnxt_chip_type[] = {
711 	"ASIC",
712 	"FPGA",
713 	"Palladium",
714 	"Unknown"
715 };
716 #define MAX_CHIP_TYPE 3
717 
718 static int
719 bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)
720 {
721 	struct bnxt_softc *softc = arg1;
722 	struct iflib_dma_info dma_data;
723 	char *pkglog = NULL;
724 	char *p;
725 	char *next;
726 	char unk[] = "<unknown>";
727 	char *buf = unk;
728 	int rc;
729 	int field;
730 	uint16_t ordinal = BNX_DIR_ORDINAL_FIRST;
731 	uint16_t index;
732 	uint32_t data_len;
733 
734 	rc = bnxt_hwrm_nvm_find_dir_entry(softc, BNX_DIR_TYPE_PKG_LOG,
735 	    &ordinal, BNX_DIR_EXT_NONE, &index, false,
736 	    HWRM_NVM_FIND_DIR_ENTRY_INPUT_OPT_ORDINAL_EQ,
737 	    &data_len, NULL, NULL);
738 	dma_data.idi_vaddr = NULL;
739 	if (rc == 0 && data_len) {
740 		rc = iflib_dma_alloc(softc->ctx, data_len, &dma_data,
741 		    BUS_DMA_NOWAIT);
742 		if (rc == 0) {
743 			rc = bnxt_hwrm_nvm_read(softc, index, 0, data_len,
744 			    &dma_data);
745 			if (rc == 0) {
746 				pkglog = dma_data.idi_vaddr;
747 				/* NULL terminate (removes last \n) */
748 				pkglog[data_len-1] = 0;
749 
750 				/* Set p = start of last line */
751 				p = strrchr(pkglog, '\n');
752 				if (p == NULL)
753 					p = pkglog;
754 
755 				/* Now find the correct tab delimited field */
756 				for (field = 0, next = p,
757 				    p = strsep(&next, "\t");
758 				    field <
759 				    BNX_PKG_LOG_FIELD_IDX_PKG_VERSION && p;
760 				    p = strsep(&next, "\t")) {
761 					field++;
762 				}
763 				if (field == BNX_PKG_LOG_FIELD_IDX_PKG_VERSION)
764 					buf = p;
765 			}
766 		}
767 		else
768 			dma_data.idi_vaddr = NULL;
769 	}
770 
771 	rc = sysctl_handle_string(oidp, buf, 0, req);
772 	if (dma_data.idi_vaddr)
773 		iflib_dma_free(&dma_data);
774 	return rc;
775 }
776 
777 static int
778 bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)
779 {
780 	struct bnxt_softc *softc = arg1;
781 	char buf[16];
782 	uint8_t	newver[3];
783 	int rc;
784 
785 	sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
786 	    softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
787 
788 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
789 	if (rc || req->newptr == NULL)
790 		return rc;
791 	if (sscanf(buf, "%hhu.%hhu.%hhu%*c", &newver[0], &newver[1],
792 	    &newver[2]) != 3)
793 		return EINVAL;
794 	softc->ver_info->hwrm_min_major = newver[0];
795 	softc->ver_info->hwrm_min_minor = newver[1];
796 	softc->ver_info->hwrm_min_update = newver[2];
797 	bnxt_check_hwrm_version(softc);
798 
799 	return rc;
800 }
801 
802 int
803 bnxt_create_ver_sysctls(struct bnxt_softc *softc)
804 {
805 	struct bnxt_ver_info *vi = softc->ver_info;
806 	struct sysctl_oid *oid = vi->ver_oid;
807 
808 	if (!oid)
809 		return ENOMEM;
810 
811 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
812 	    "hwrm_if", CTLFLAG_RD, vi->hwrm_if_ver, 0,
813 	    "HWRM interface version");
814 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
815 	    "driver_hwrm_if", CTLFLAG_RD, vi->driver_hwrm_if_ver, 0,
816 	    "HWRM firmware version");
817 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
818 	    "hwrm_fw", CTLFLAG_RD, vi->hwrm_fw_ver, 0,
819 	    "HWRM firmware version");
820 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
821 	    "mgmt_fw", CTLFLAG_RD, vi->mgmt_fw_ver, 0,
822 	    "management firmware version");
823 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
824 	    "netctrl_fw", CTLFLAG_RD, vi->netctrl_fw_ver, 0,
825 	    "network control firmware version");
826 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
827 	    "roce_fw", CTLFLAG_RD, vi->roce_fw_ver, 0,
828 	    "RoCE firmware version");
829 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
830 	    "phy", CTLFLAG_RD, vi->phy_ver, 0,
831 	    "PHY version");
832 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
833 	    "hwrm_fw_name", CTLFLAG_RD, vi->hwrm_fw_name, 0,
834 	    "HWRM firmware name");
835 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
836 	    "mgmt_fw_name", CTLFLAG_RD, vi->mgmt_fw_name, 0,
837 	    "management firmware name");
838 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
839 	    "netctrl_fw_name", CTLFLAG_RD, vi->netctrl_fw_name, 0,
840 	    "network control firmware name");
841 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
842 	    "roce_fw_name", CTLFLAG_RD, vi->roce_fw_name, 0,
843 	    "RoCE firmware name");
844 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
845 	    "phy_vendor", CTLFLAG_RD, vi->phy_vendor, 0,
846 	    "PHY vendor name");
847 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
848 	    "phy_partnumber", CTLFLAG_RD, vi->phy_partnumber, 0,
849 	    "PHY vendor part number");
850 	SYSCTL_ADD_U16(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
851 	    "chip_num", CTLFLAG_RD, &vi->chip_num, 0, "chip number");
852 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
853 	    "chip_rev", CTLFLAG_RD, &vi->chip_rev, 0, "chip revision");
854 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
855 	    "chip_metal", CTLFLAG_RD, &vi->chip_metal, 0, "chip metal number");
856 	SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
857 	    "chip_bond_id", CTLFLAG_RD, &vi->chip_bond_id, 0,
858 	    "chip bond id");
859 	SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
860 	    "chip_type", CTLFLAG_RD, vi->chip_type > MAX_CHIP_TYPE ?
861 	    bnxt_chip_type[MAX_CHIP_TYPE] : bnxt_chip_type[vi->chip_type], 0,
862 	    "RoCE firmware name");
863 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
864 	    "package_ver", CTLTYPE_STRING|CTLFLAG_RD, softc, 0,
865 	    bnxt_package_ver_sysctl, "A",
866 	    "currently installed package version");
867 	SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
868 	    "hwrm_min_ver", CTLTYPE_STRING|CTLFLAG_RWTUN, softc, 0,
869 	    bnxt_hwrm_min_ver_sysctl, "A",
870 	    "minimum hwrm API vesion to support");
871 
872 	return 0;
873 }
874 
875 int
876 bnxt_create_nvram_sysctls(struct bnxt_nvram_info *ni)
877 {
878 	struct sysctl_oid *oid = ni->nvm_oid;
879 
880 	if (!oid)
881 		return ENOMEM;
882 
883 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
884 	    "mfg_id", CTLFLAG_RD, &ni->mfg_id, 0, "manufacturer id");
885 	SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
886 	    "device_id", CTLFLAG_RD, &ni->device_id, 0, "device id");
887 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
888 	    "sector_size", CTLFLAG_RD, &ni->sector_size, 0, "sector size");
889 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
890 	    "size", CTLFLAG_RD, &ni->size, 0, "nvram total size");
891 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
892 	    "reserved_size", CTLFLAG_RD, &ni->reserved_size, 0,
893 	    "total reserved space");
894 	SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
895 	    "available_size", CTLFLAG_RD, &ni->available_size, 0,
896 	    "total available space");
897 
898 	return 0;
899 }
900 
901 static int
902 bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)
903 {
904 	struct bnxt_softc *softc = arg1;
905 	char buf[HW_HASH_KEY_SIZE*2+1] = {0};
906 	char *p;
907 	int i;
908 	int rc;
909 
910 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++)
911 		p += sprintf(p, "%02x", softc->vnic_info.rss_hash_key[i]);
912 
913 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
914 	if (rc || req->newptr == NULL)
915 		return rc;
916 
917 	if (strspn(buf, "0123456789abcdefABCDEF") != (HW_HASH_KEY_SIZE * 2))
918 		return EINVAL;
919 
920 	for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++) {
921 		if (sscanf(p, "%02hhx", &softc->vnic_info.rss_hash_key[i]) != 1)
922 			return EINVAL;
923 		p += 2;
924 	}
925 
926 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
927 		bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
928 		    softc->vnic_info.rss_hash_type);
929 
930 	return rc;
931 }
932 
933 static const char *bnxt_hash_types[] = {"ipv4", "tcp_ipv4", "udp_ipv4", "ipv6",
934     "tcp_ipv6", "udp_ipv6", NULL};
935 
936 static int bnxt_get_rss_type_str_bit(char *str)
937 {
938 	int i;
939 
940 	for (i=0; bnxt_hash_types[i]; i++)
941 		if (strcmp(bnxt_hash_types[i], str) == 0)
942 			return i;
943 
944 	return -1;
945 }
946 
947 static int
948 bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)
949 {
950 	struct bnxt_softc *softc = arg1;
951 	char buf[256] = {0};
952 	char *p;
953 	char *next;
954 	int rc;
955 	int type;
956 	int bit;
957 
958 	for (type = softc->vnic_info.rss_hash_type; type;
959 	    type &= ~(1<<bit)) {
960 		bit = ffs(type) - 1;
961 		if (bit >= sizeof(bnxt_hash_types) / sizeof(const char *))
962 			continue;
963 		if (type != softc->vnic_info.rss_hash_type)
964 			strcat(buf, ",");
965 		strcat(buf, bnxt_hash_types[bit]);
966 	}
967 
968 	rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
969 	if (rc || req->newptr == NULL)
970 		return rc;
971 
972 	for (type = 0, next = buf, p = strsep(&next, " ,"); p;
973 	    p = strsep(&next, " ,")) {
974 		bit = bnxt_get_rss_type_str_bit(p);
975 		if (bit == -1)
976 			return EINVAL;
977 		type |= 1<<bit;
978 	}
979 	if (type != softc->vnic_info.rss_hash_type) {
980 		softc->vnic_info.rss_hash_type = type;
981 		if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
982 			bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
983 			    softc->vnic_info.rss_hash_type);
984 	}
985 
986 	return rc;
987 }
988 
989 static int
990 bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS) {
991 	struct bnxt_softc *softc = arg1;
992 	int rc;
993 	int val;
994 
995 	if (softc == NULL)
996 		return EBUSY;
997 
998 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_BD_STALL);
999 	rc = sysctl_handle_int(oidp, &val, 0, req);
1000 	if (rc || !req->newptr)
1001 		return rc;
1002 
1003 	if (val)
1004 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_BD_STALL;
1005 	else
1006 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_BD_STALL;
1007 
1008 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1009 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1010 
1011 	return rc;
1012 }
1013 
1014 static int
1015 bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS) {
1016 	struct bnxt_softc *softc = arg1;
1017 	int rc;
1018 	int val;
1019 
1020 	if (softc == NULL)
1021 		return EBUSY;
1022 
1023 	val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_VLAN_STRIP);
1024 	rc = sysctl_handle_int(oidp, &val, 0, req);
1025 	if (rc || !req->newptr)
1026 		return rc;
1027 
1028 	if (val)
1029 		softc->vnic_info.flags |= BNXT_VNIC_FLAG_VLAN_STRIP;
1030 	else
1031 		softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_VLAN_STRIP;
1032 
1033 	if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1034 		rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1035 
1036 	return rc;
1037 }
1038 
1039 static int
1040 bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS) {
1041 	struct bnxt_softc *softc = arg1;
1042 	int rc;
1043 	int val;
1044 
1045 	if (softc == NULL)
1046 		return EBUSY;
1047 
1048 	val = softc->rx_coal_usecs;
1049 	rc = sysctl_handle_int(oidp, &val, 0, req);
1050 	if (rc || !req->newptr)
1051 		return rc;
1052 
1053 	softc->rx_coal_usecs = val;
1054 	rc = bnxt_hwrm_set_coal(softc);
1055 
1056 	return rc;
1057 }
1058 
1059 static int
1060 bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS) {
1061 	struct bnxt_softc *softc = arg1;
1062 	int rc;
1063 	int val;
1064 
1065 	if (softc == NULL)
1066 		return EBUSY;
1067 
1068 	val = softc->rx_coal_frames;
1069 	rc = sysctl_handle_int(oidp, &val, 0, req);
1070 	if (rc || !req->newptr)
1071 		return rc;
1072 
1073 	softc->rx_coal_frames = val;
1074 	rc = bnxt_hwrm_set_coal(softc);
1075 
1076 	return rc;
1077 }
1078 
1079 static int
1080 bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1081 	struct bnxt_softc *softc = arg1;
1082 	int rc;
1083 	int val;
1084 
1085 	if (softc == NULL)
1086 		return EBUSY;
1087 
1088 	val = softc->rx_coal_usecs_irq;
1089 	rc = sysctl_handle_int(oidp, &val, 0, req);
1090 	if (rc || !req->newptr)
1091 		return rc;
1092 
1093 	softc->rx_coal_usecs_irq = val;
1094 	rc = bnxt_hwrm_set_coal(softc);
1095 
1096 	return rc;
1097 }
1098 
1099 static int
1100 bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS) {
1101 	struct bnxt_softc *softc = arg1;
1102 	int rc;
1103 	int val;
1104 
1105 	if (softc == NULL)
1106 		return EBUSY;
1107 
1108 	val = softc->rx_coal_frames_irq;
1109 	rc = sysctl_handle_int(oidp, &val, 0, req);
1110 	if (rc || !req->newptr)
1111 		return rc;
1112 
1113 	softc->rx_coal_frames_irq = val;
1114 	rc = bnxt_hwrm_set_coal(softc);
1115 
1116 	return rc;
1117 }
1118 
1119 static int
1120 bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS) {
1121 	struct bnxt_softc *softc = arg1;
1122 	int rc;
1123 	int val;
1124 
1125 	if (softc == NULL)
1126 		return EBUSY;
1127 
1128 	val = softc->tx_coal_usecs;
1129 	rc = sysctl_handle_int(oidp, &val, 0, req);
1130 	if (rc || !req->newptr)
1131 		return rc;
1132 
1133 	softc->tx_coal_usecs = val;
1134 	rc = bnxt_hwrm_set_coal(softc);
1135 
1136 	return rc;
1137 }
1138 
1139 static int
1140 bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS) {
1141 	struct bnxt_softc *softc = arg1;
1142 	int rc;
1143 	int val;
1144 
1145 	if (softc == NULL)
1146 		return EBUSY;
1147 
1148 	val = softc->tx_coal_frames;
1149 	rc = sysctl_handle_int(oidp, &val, 0, req);
1150 	if (rc || !req->newptr)
1151 		return rc;
1152 
1153 	softc->tx_coal_frames = val;
1154 	rc = bnxt_hwrm_set_coal(softc);
1155 
1156 	return rc;
1157 }
1158 
1159 static int
1160 bnxt_set_coal_tx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1161 	struct bnxt_softc *softc = arg1;
1162 	int rc;
1163 	int val;
1164 
1165 	if (softc == NULL)
1166 		return EBUSY;
1167 
1168 	val = softc->tx_coal_usecs_irq;
1169 	rc = sysctl_handle_int(oidp, &val, 0, req);
1170 	if (rc || !req->newptr)
1171 		return rc;
1172 
1173 	softc->tx_coal_usecs_irq = val;
1174 	rc = bnxt_hwrm_set_coal(softc);
1175 
1176 	return rc;
1177 }
1178 
1179 static int
1180 bnxt_set_coal_tx_frames_irq(SYSCTL_HANDLER_ARGS) {
1181 	struct bnxt_softc *softc = arg1;
1182 	int rc;
1183 	int val;
1184 
1185 	if (softc == NULL)
1186 		return EBUSY;
1187 
1188 	val = softc->tx_coal_frames_irq;
1189 	rc = sysctl_handle_int(oidp, &val, 0, req);
1190 	if (rc || !req->newptr)
1191 		return rc;
1192 
1193 	softc->tx_coal_frames_irq = val;
1194 	rc = bnxt_hwrm_set_coal(softc);
1195 
1196 	return rc;
1197 }
1198 
1199 int
1200 bnxt_create_config_sysctls_pre(struct bnxt_softc *softc)
1201 {
1202 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1203 	struct sysctl_oid_list *children;
1204 
1205 	children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));;
1206 
1207 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_key",
1208 	    CTLTYPE_STRING|CTLFLAG_RWTUN, softc, 0, bnxt_rss_key_sysctl, "A",
1209 	    "RSS key");
1210 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_type",
1211 	    CTLTYPE_STRING|CTLFLAG_RWTUN, softc, 0, bnxt_rss_type_sysctl, "A",
1212 	    "RSS type bits");
1213 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_stall",
1214 	    CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_rx_stall_sysctl, "I",
1215 	    "buffer rx packets in hardware until the host posts new buffers");
1216 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_strip",
1217 	    CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_vlan_strip_sysctl, "I",
1218 	    "strip VLAN tag in the RX path");
1219 	SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "if_name", CTLFLAG_RD,
1220 		iflib_get_ifp(softc->ctx)->if_xname, 0, "interface name");
1221 
1222         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs",
1223                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_rx_usecs,
1224 			"I", "interrupt coalescing Rx Usecs");
1225         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames",
1226                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_rx_frames,
1227 			"I", "interrupt coalescing Rx Frames");
1228         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs_irq",
1229                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_rx_usecs_irq,
1230 			"I", "interrupt coalescing Rx Usecs IRQ");
1231         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames_irq",
1232                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_rx_frames_irq,
1233 			"I", "interrupt coalescing Rx Frames IRQ");
1234         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs",
1235                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_tx_usecs,
1236 			"I", "interrupt coalescing Tx Usces");
1237         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames",
1238                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_tx_frames,
1239 			"I", "interrupt coalescing Tx Frames");
1240         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs_irq",
1241                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_tx_usecs_irq,
1242 			"I", "interrupt coalescing Tx Usecs IRQ");
1243         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames_irq",
1244                         CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_set_coal_tx_frames_irq,
1245 			"I", "interrupt coalescing Tx Frames IRQ");
1246 
1247 	return 0;
1248 }
1249 
1250 #define BNXT_HW_LRO_FN(fn_name, arg)			                   \
1251 static int						                   \
1252 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1253 	struct bnxt_softc *softc = arg1;		                   \
1254 	int rc;						                   \
1255 	int val;					                   \
1256 							                   \
1257 	if (softc == NULL)				                   \
1258 		return EBUSY;				                   \
1259 							                   \
1260 	val = softc->hw_lro.arg;			                   \
1261 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1262 	if (rc || !req->newptr)				                   \
1263 		return rc;				                   \
1264 							                   \
1265 	if ((if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)) \
1266 		return EBUSY;				                   \
1267 							                   \
1268 	softc->hw_lro.arg = val;			                   \
1269 	bnxt_validate_hw_lro_settings(softc);		                   \
1270 	rc = bnxt_hwrm_vnic_tpa_cfg(softc);		                   \
1271 							                   \
1272 	return rc;					                   \
1273 }
1274 
1275 BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable, enable)
1276 BNXT_HW_LRO_FN(bnxt_hw_lro_set_mode, is_mode_gro)
1277 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_agg_segs, max_agg_segs)
1278 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_aggs, max_aggs)
1279 BNXT_HW_LRO_FN(bnxt_hw_lro_set_min_agg_len, min_agg_len)
1280 
1281 #define BNXT_FLOW_CTRL_FN(fn_name, arg)			                   \
1282 static int						                   \
1283 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1284 	struct bnxt_softc *softc = arg1;		                   \
1285 	int rc;						                   \
1286 	int val;					                   \
1287 							                   \
1288 	if (softc == NULL)				                   \
1289 		return EBUSY;				                   \
1290 							                   \
1291 	val = softc->link_info.flow_ctrl.arg;			           \
1292 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1293 	if (rc || !req->newptr)				                   \
1294 		return rc;				                   \
1295 							                   \
1296 	if (val)					                   \
1297 	   	val = 1; 				                   \
1298 	        					                   \
1299 	if (softc->link_info.flow_ctrl.arg != val) {		           \
1300 		softc->link_info.flow_ctrl.arg = val;		           \
1301 		rc = bnxt_hwrm_set_link_setting(softc, true, false, false);\
1302 		rc = bnxt_hwrm_port_phy_qcfg(softc);			   \
1303 	}						                   \
1304 							                   \
1305 	return rc;					                   \
1306 }
1307 
1308 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_tx, tx)
1309 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_rx, rx)
1310 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_autoneg, autoneg)
1311 int
1312 bnxt_create_pause_fc_sysctls(struct bnxt_softc *softc)
1313 {
1314 	struct sysctl_oid *oid = softc->flow_ctrl_oid;
1315 
1316 	if (!oid)
1317 		return ENOMEM;
1318 
1319 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1320 			"tx", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1321 			bnxt_flow_ctrl_tx, "A",
1322 			"Enable or Disable Tx Flow Ctrl: 0 / 1");
1323 
1324 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1325 			"rx", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1326 			bnxt_flow_ctrl_rx, "A",
1327 			"Enable or Disable Tx Flow Ctrl: 0 / 1");
1328 
1329 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1330 			"autoneg", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1331 			bnxt_flow_ctrl_autoneg, "A",
1332 			"Enable or Disable Autoneg Flow Ctrl: 0 / 1");
1333 
1334 	return 0;
1335 }
1336 
1337 int
1338 bnxt_create_hw_lro_sysctls(struct bnxt_softc *softc)
1339 {
1340 	struct sysctl_oid *oid = softc->hw_lro_oid;
1341 
1342 	if (!oid)
1343 		return ENOMEM;
1344 
1345 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1346 			"enable", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1347 			bnxt_hw_lro_enable_disable, "A",
1348 			"Enable or Disable HW LRO: 0 / 1");
1349 
1350 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1351 			"gro_mode", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1352 			bnxt_hw_lro_set_mode, "A",
1353 			"Set mode: 1 = GRO mode, 0 = RSC mode");
1354 
1355 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1356 			"max_agg_segs", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1357 			bnxt_hw_lro_set_max_agg_segs, "A",
1358 			"Set Max Agg Seg Value (unit is Log2): "
1359 			"0 (= 1 seg) / 1 (= 2 segs) /  ... / 31 (= 2^31 segs)");
1360 
1361         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1362 			"max_aggs", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1363 			bnxt_hw_lro_set_max_aggs, "A",
1364 			"Set Max Aggs Value (unit is Log2): "
1365 			"0 (= 1 agg) / 1 (= 2 aggs) /  ... / 7 (= 2^7 segs)");
1366 
1367 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1368 			"min_agg_len", CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0,
1369 			bnxt_hw_lro_set_min_agg_len, "A",
1370 			"Min Agg Len: 1 to 9000");
1371 
1372 	return 0;
1373 }
1374 static int
1375 bnxt_vlan_only_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 = softc->vnic_info.vlan_only;
1384 	rc = sysctl_handle_int(oidp, &val, 0, req);
1385 	if (rc || !req->newptr)
1386 		return rc;
1387 
1388 	if (val)
1389 		val = 1;
1390 
1391 	if (val != softc->vnic_info.vlan_only) {
1392 		softc->vnic_info.vlan_only = val;
1393 		if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1394 			rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc,
1395 			    &softc->vnic_info);
1396 	}
1397 
1398 	return rc;
1399 }
1400 
1401 int
1402 bnxt_create_config_sysctls_post(struct bnxt_softc *softc)
1403 {
1404 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1405 	struct sysctl_oid_list *children;
1406 
1407 	children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));;
1408 
1409 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_only",
1410 	    CTLTYPE_INT|CTLFLAG_RWTUN, softc, 0, bnxt_vlan_only_sysctl, "I",
1411 	    "require vlan tag on received packets when vlan is enabled");
1412 
1413 	return 0;
1414 }
1415