xref: /freebsd-13.1/sys/dev/bnxt/bnxt_sysctl.c (revision 50570c64)
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
bnxt_init_sysctl_ctx(struct bnxt_softc * softc)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 | CTLFLAG_MPSAFE, 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 | CTLFLAG_MPSAFE, 0,
72 	    "hardware/firmware version information");
73 	if (!softc->ver_info->ver_oid) {
74 		sysctl_ctx_free(&softc->ver_info->ver_ctx);
75 		return ENOMEM;
76 	}
77 
78 	if (BNXT_PF(softc)) {
79 		sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
80 		ctx = device_get_sysctl_ctx(softc->dev);
81 		softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
82 		    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
83 		    "nvram", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
84 		    "nvram information");
85 		if (!softc->nvm_info->nvm_oid) {
86 			sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
87 			return ENOMEM;
88 		}
89 	}
90 
91 	sysctl_ctx_init(&softc->hw_lro_ctx);
92 	ctx = device_get_sysctl_ctx(softc->dev);
93 	softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
94 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
95 	    "hw_lro", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware lro");
96 	if (!softc->hw_lro_oid) {
97 		sysctl_ctx_free(&softc->hw_lro_ctx);
98 		return ENOMEM;
99 	}
100 
101 	sysctl_ctx_init(&softc->flow_ctrl_ctx);
102 	ctx = device_get_sysctl_ctx(softc->dev);
103 	softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
104 	    SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
105 	    "fc", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "flow ctrl");
106 	if (!softc->flow_ctrl_oid) {
107 		sysctl_ctx_free(&softc->flow_ctrl_ctx);
108 		return ENOMEM;
109 	}
110 
111 	return 0;
112 }
113 
114 int
bnxt_free_sysctl_ctx(struct bnxt_softc * softc)115 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
116 {
117 	int orc;
118 	int rc = 0;
119 
120 	if (softc->hw_stats_oid != NULL) {
121 		orc = sysctl_ctx_free(&softc->hw_stats);
122 		if (orc)
123 			rc = orc;
124 		else
125 			softc->hw_stats_oid = NULL;
126 	}
127 	if (softc->ver_info->ver_oid != NULL) {
128 		orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
129 		if (orc)
130 			rc = orc;
131 		else
132 			softc->ver_info->ver_oid = NULL;
133 	}
134 	if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
135 		orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
136 		if (orc)
137 			rc = orc;
138 		else
139 			softc->nvm_info->nvm_oid = NULL;
140 	}
141 	if (softc->hw_lro_oid != NULL) {
142 		orc = sysctl_ctx_free(&softc->hw_lro_ctx);
143 		if (orc)
144 			rc = orc;
145 		else
146 			softc->hw_lro_oid = NULL;
147 	}
148 
149 	if (softc->flow_ctrl_oid != NULL) {
150 		orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
151 		if (orc)
152 			rc = orc;
153 		else
154 			softc->flow_ctrl_oid = NULL;
155 	}
156 
157 	return rc;
158 }
159 
160 int
bnxt_create_tx_sysctls(struct bnxt_softc * softc,int txr)161 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
162 {
163 	struct sysctl_oid *oid;
164 	struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats.idi_vaddr;
165 	char	name[32];
166 	char	desc[64];
167 
168 	sprintf(name, "txq%d", txr);
169 	sprintf(desc, "transmit queue %d", txr);
170 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
171 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
172 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
173 	if (!oid)
174 		return ENOMEM;
175 
176 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
177 	    "ucast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_ucast_pkts,
178 	    "unicast packets sent");
179 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
180 	    "mcast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_mcast_pkts,
181 	    "multicast packets sent");
182 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
183 	    "bcast_pkts", CTLFLAG_RD, &tx_stats[txr].tx_bcast_pkts,
184 	    "broadcast packets sent");
185 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
186 	    "discard_pkts", CTLFLAG_RD,
187 	    &tx_stats[txr].tx_discard_pkts, "discarded transmit packets");
188 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
189 	    "drop_pkts", CTLFLAG_RD, &tx_stats[txr].tx_drop_pkts,
190 	    "dropped transmit packets");
191 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
192 	    "ucast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_ucast_bytes,
193 	    "unicast bytes sent");
194 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
195 	    "mcast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_mcast_bytes,
196 	    "multicast bytes sent");
197 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
198 	    "bcast_bytes", CTLFLAG_RD, &tx_stats[txr].tx_bcast_bytes,
199 	    "broadcast bytes sent");
200 
201 	return 0;
202 }
203 
204 int
bnxt_create_port_stats_sysctls(struct bnxt_softc * softc)205 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
206 {
207 	struct sysctl_oid *oid;
208 	char	name[32];
209 	char	desc[64];
210 
211 	sprintf(name, "port_stats");
212 	sprintf(desc, "Port Stats");
213 	oid = SYSCTL_ADD_NODE(&softc->hw_stats,
214 	    SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
215 	        CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
216 	if (!oid)
217 		return ENOMEM;
218 
219 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
220 	    "tx_64b_frames", CTLFLAG_RD,
221  	    &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
222 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
223 	    "tx_65b_127b_frames", CTLFLAG_RD,
224  	    &softc->tx_port_stats->tx_65b_127b_frames,
225 	    "Transmitted 65b 127b frames");
226 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
227 	    "tx_128b_255b_frames", CTLFLAG_RD,
228  	    &softc->tx_port_stats->tx_128b_255b_frames,
229 	    "Transmitted 128b 255b frames");
230 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
231 	    "tx_256b_511b_frames", CTLFLAG_RD,
232  	    &softc->tx_port_stats->tx_256b_511b_frames,
233 	    "Transmitted 256b 511b frames");
234 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
235 	    "tx_512b_1023b_frames", CTLFLAG_RD,
236  	    &softc->tx_port_stats->tx_512b_1023b_frames,
237 	    "Transmitted 512b 1023b frames");
238 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
239 	    "tx_1024b_1518_frames", CTLFLAG_RD,
240  	    &softc->tx_port_stats->tx_1024b_1518_frames,
241 	    "Transmitted 1024b 1518 frames");
242 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
243 	    "tx_good_vlan_frames", CTLFLAG_RD,
244  	    &softc->tx_port_stats->tx_good_vlan_frames,
245 	    "Transmitted good vlan frames");
246 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
247 	    "tx_1519b_2047_frames", CTLFLAG_RD,
248  	    &softc->tx_port_stats->tx_1519b_2047_frames,
249 	    "Transmitted 1519b 2047 frames");
250 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
251 	    "tx_2048b_4095b_frames", CTLFLAG_RD,
252  	    &softc->tx_port_stats->tx_2048b_4095b_frames,
253 	    "Transmitted 2048b 4095b frames");
254 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
255 	    "tx_4096b_9216b_frames", CTLFLAG_RD,
256  	    &softc->tx_port_stats->tx_4096b_9216b_frames,
257 	    "Transmitted 4096b 9216b frames");
258 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
259 	    "tx_9217b_16383b_frames", CTLFLAG_RD,
260 	    &softc->tx_port_stats->tx_9217b_16383b_frames,
261 	    "Transmitted 9217b 16383b frames");
262 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
263 	    "tx_good_frames", CTLFLAG_RD,
264  	    &softc->tx_port_stats->tx_good_frames, "Transmitted good frames");
265 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
266 	    "tx_total_frames", CTLFLAG_RD,
267  	    &softc->tx_port_stats->tx_total_frames, "Transmitted total frames");
268 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
269 	    "tx_ucast_frames", CTLFLAG_RD,
270  	    &softc->tx_port_stats->tx_ucast_frames, "Transmitted ucast frames");
271 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
272 	    "tx_mcast_frames", CTLFLAG_RD,
273  	    &softc->tx_port_stats->tx_mcast_frames, "Transmitted mcast frames");
274 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
275 	    "tx_bcast_frames", CTLFLAG_RD,
276  	    &softc->tx_port_stats->tx_bcast_frames, "Transmitted bcast frames");
277 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
278 	    "tx_pause_frames", CTLFLAG_RD,
279  	    &softc->tx_port_stats->tx_pause_frames, "Transmitted pause frames");
280 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
281 	    "tx_pfc_frames", CTLFLAG_RD,
282  	    &softc->tx_port_stats->tx_pfc_frames, "Transmitted pfc frames");
283 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
284 	    "tx_jabber_frames", CTLFLAG_RD,
285  	    &softc->tx_port_stats->tx_jabber_frames, "Transmitted jabber frames");
286 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
287 	    "tx_fcs_err_frames", CTLFLAG_RD,
288  	    &softc->tx_port_stats->tx_fcs_err_frames,
289 	    "Transmitted fcs err frames");
290 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
291 	    "tx_control_frames", CTLFLAG_RD,
292  	    &softc->tx_port_stats->tx_control_frames,
293 	    "Transmitted control frames");
294 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
295 	    "tx_oversz_frames", CTLFLAG_RD,
296  	    &softc->tx_port_stats->tx_oversz_frames, "Transmitted oversz frames");
297 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
298 	    "tx_single_dfrl_frames", CTLFLAG_RD,
299  	    &softc->tx_port_stats->tx_single_dfrl_frames,
300 	    "Transmitted single dfrl frames");
301 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
302 	    "tx_multi_dfrl_frames", CTLFLAG_RD,
303  	    &softc->tx_port_stats->tx_multi_dfrl_frames,
304 	    "Transmitted multi dfrl frames");
305 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
306 	    "tx_single_coll_frames", CTLFLAG_RD,
307  	    &softc->tx_port_stats->tx_single_coll_frames,
308 	    "Transmitted single coll frames");
309 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
310 	    "tx_multi_coll_frames", CTLFLAG_RD,
311  	    &softc->tx_port_stats->tx_multi_coll_frames,
312 	    "Transmitted multi coll frames");
313 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
314 	    "tx_late_coll_frames", CTLFLAG_RD,
315  	    &softc->tx_port_stats->tx_late_coll_frames,
316 	    "Transmitted late coll frames");
317 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
318 	    "tx_excessive_coll_frames", CTLFLAG_RD,
319  	    &softc->tx_port_stats->tx_excessive_coll_frames,
320 	    "Transmitted excessive coll frames");
321 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
322 	    "tx_frag_frames", CTLFLAG_RD,
323  	    &softc->tx_port_stats->tx_frag_frames, "Transmitted frag frames");
324 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
325 	    "tx_err", CTLFLAG_RD,
326  	    &softc->tx_port_stats->tx_err, "Transmitted err");
327 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
328 	    "tx_tagged_frames", CTLFLAG_RD,
329  	    &softc->tx_port_stats->tx_tagged_frames, "Transmitted tagged frames");
330 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
331 	    "tx_dbl_tagged_frames", CTLFLAG_RD,
332  	    &softc->tx_port_stats->tx_dbl_tagged_frames,
333 	    "Transmitted dbl tagged frames");
334 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
335 	    "tx_runt_frames", CTLFLAG_RD,
336  	    &softc->tx_port_stats->tx_runt_frames, "Transmitted runt frames");
337 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
338 	    "tx_fifo_underruns", CTLFLAG_RD,
339  	    &softc->tx_port_stats->tx_fifo_underruns,
340 	    "Transmitted fifo underruns");
341 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
342 	    "tx_pfc_ena_frames_pri0", CTLFLAG_RD,
343  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri0,
344 	    "Transmitted pfc ena frames pri0");
345 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
346 	    "tx_pfc_ena_frames_pri1", CTLFLAG_RD,
347  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri1,
348 	    "Transmitted pfc ena frames pri1");
349 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
350 	    "tx_pfc_ena_frames_pri2", CTLFLAG_RD,
351  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri2,
352 	    "Transmitted pfc ena frames pri2");
353 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
354 	    "tx_pfc_ena_frames_pri3", CTLFLAG_RD,
355  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri3,
356 	    "Transmitted pfc ena frames pri3");
357 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
358 	    "tx_pfc_ena_frames_pri4", CTLFLAG_RD,
359  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri4,
360 	    "Transmitted pfc ena frames pri4");
361 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
362 	    "tx_pfc_ena_frames_pri5", CTLFLAG_RD,
363  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri5,
364 	    "Transmitted pfc ena frames pri5");
365 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
366 	    "tx_pfc_ena_frames_pri6", CTLFLAG_RD,
367  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri6,
368 	    "Transmitted pfc ena frames pri6");
369 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
370 	    "tx_pfc_ena_frames_pri7", CTLFLAG_RD,
371  	    &softc->tx_port_stats->tx_pfc_ena_frames_pri7,
372 	    "Transmitted pfc ena frames pri7");
373 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
374 	    "tx_eee_lpi_events", CTLFLAG_RD,
375  	    &softc->tx_port_stats->tx_eee_lpi_events,
376 	    "Transmitted eee lpi events");
377 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
378 	    "tx_eee_lpi_duration", CTLFLAG_RD,
379  	    &softc->tx_port_stats->tx_eee_lpi_duration,
380 	    "Transmitted eee lpi duration");
381 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
382 	    "tx_llfc_logical_msgs", CTLFLAG_RD,
383  	    &softc->tx_port_stats->tx_llfc_logical_msgs,
384 	    "Transmitted llfc logical msgs");
385 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
386 	    "tx_hcfc_msgs", CTLFLAG_RD,
387  	    &softc->tx_port_stats->tx_hcfc_msgs, "Transmitted hcfc msgs");
388 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
389 	    "tx_total_collisions", CTLFLAG_RD,
390  	    &softc->tx_port_stats->tx_total_collisions,
391 	    "Transmitted total collisions");
392 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
393 	    "tx_bytes", CTLFLAG_RD,
394  	    &softc->tx_port_stats->tx_bytes, "Transmitted bytes");
395 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
396 	    "tx_xthol_frames", CTLFLAG_RD,
397  	    &softc->tx_port_stats->tx_xthol_frames, "Transmitted xthol frames");
398 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
399 	    "tx_stat_discard", CTLFLAG_RD,
400  	    &softc->tx_port_stats->tx_stat_discard, "Transmitted stat discard");
401 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
402 	    "tx_stat_error", CTLFLAG_RD,
403  	    &softc->tx_port_stats->tx_stat_error, "Transmitted stat error");
404 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
405 	    "rx_64b_frames", CTLFLAG_RD,
406  	    &softc->rx_port_stats->rx_64b_frames, "Received 64b frames");
407 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
408 	    "rx_65b_127b_frames", CTLFLAG_RD,
409  	    &softc->rx_port_stats->rx_65b_127b_frames, "Received 65b 127b frames");
410 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
411 	    "rx_128b_255b_frames", CTLFLAG_RD,
412  	    &softc->rx_port_stats->rx_128b_255b_frames,
413 	    "Received 128b 255b frames");
414 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
415 	    "rx_256b_511b_frames", CTLFLAG_RD,
416  	    &softc->rx_port_stats->rx_256b_511b_frames,
417 	    "Received 256b 511b frames");
418 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
419 	    "rx_512b_1023b_frames", CTLFLAG_RD,
420  	    &softc->rx_port_stats->rx_512b_1023b_frames,
421 	    "Received 512b 1023b frames");
422 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
423 	    "rx_1024b_1518_frames", CTLFLAG_RD,
424  	    &softc->rx_port_stats->rx_1024b_1518_frames,
425 	    "Received 1024b 1518 frames");
426 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
427 	    "rx_good_vlan_frames", CTLFLAG_RD,
428  	    &softc->rx_port_stats->rx_good_vlan_frames,
429 	    "Received good vlan frames");
430 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
431 	    "rx_1519b_2047b_frames", CTLFLAG_RD,
432  	    &softc->rx_port_stats->rx_1519b_2047b_frames,
433 	    "Received 1519b 2047b frames");
434 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
435 	    "rx_2048b_4095b_frames", CTLFLAG_RD,
436  	    &softc->rx_port_stats->rx_2048b_4095b_frames,
437 	    "Received 2048b 4095b frames");
438 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
439 	    "rx_4096b_9216b_frames", CTLFLAG_RD,
440  	    &softc->rx_port_stats->rx_4096b_9216b_frames,
441 	    "Received 4096b 9216b frames");
442 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
443 	    "rx_9217b_16383b_frames", CTLFLAG_RD,
444  	    &softc->rx_port_stats->rx_9217b_16383b_frames,
445 	    "Received 9217b 16383b frames");
446 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
447 	    "rx_total_frames", CTLFLAG_RD,
448  	    &softc->rx_port_stats->rx_total_frames, "Received total frames");
449 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
450 	    "rx_ucast_frames", CTLFLAG_RD,
451  	    &softc->rx_port_stats->rx_ucast_frames, "Received ucast frames");
452 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
453 	    "rx_mcast_frames", CTLFLAG_RD,
454  	    &softc->rx_port_stats->rx_mcast_frames, "Received mcast frames");
455 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
456 	    "rx_bcast_frames", CTLFLAG_RD,
457  	    &softc->rx_port_stats->rx_bcast_frames, "Received bcast frames");
458 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
459 	    "rx_fcs_err_frames", CTLFLAG_RD,
460  	    &softc->rx_port_stats->rx_fcs_err_frames, "Received fcs err frames");
461 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
462 	    "rx_ctrl_frames", CTLFLAG_RD,
463  	    &softc->rx_port_stats->rx_ctrl_frames, "Received ctrl frames");
464 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
465 	    "rx_pause_frames", CTLFLAG_RD,
466  	    &softc->rx_port_stats->rx_pause_frames, "Received pause frames");
467 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
468 	    "rx_pfc_frames", CTLFLAG_RD,
469  	    &softc->rx_port_stats->rx_pfc_frames, "Received pfc frames");
470 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
471 	    "rx_unsupported_opcode_frames", CTLFLAG_RD,
472  	    &softc->rx_port_stats->rx_unsupported_opcode_frames,
473 	    "Received unsupported opcode frames");
474 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
475 	    "rx_unsupported_da_pausepfc_frames", CTLFLAG_RD,
476  	    &softc->rx_port_stats->rx_unsupported_da_pausepfc_frames,
477 	    "Received unsupported da pausepfc frames");
478 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
479 	    "rx_wrong_sa_frames", CTLFLAG_RD,
480  	    &softc->rx_port_stats->rx_wrong_sa_frames,
481 	    "Received wrong sa frames");
482 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
483 	    "rx_align_err_frames", CTLFLAG_RD,
484  	    &softc->rx_port_stats->rx_align_err_frames,
485 	    "Received align err frames");
486 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
487 	    "rx_oor_len_frames", CTLFLAG_RD,
488  	    &softc->rx_port_stats->rx_oor_len_frames,
489 	    "Received oor len frames");
490 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
491 	    "rx_code_err_frames", CTLFLAG_RD,
492  	    &softc->rx_port_stats->rx_code_err_frames,
493 	    "Received code err frames");
494 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
495 	    "rx_false_carrier_frames", CTLFLAG_RD,
496  	    &softc->rx_port_stats->rx_false_carrier_frames,
497 	    "Received false carrier frames");
498 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
499 	    "rx_ovrsz_frames", CTLFLAG_RD,
500  	    &softc->rx_port_stats->rx_ovrsz_frames,
501 	    "Received ovrsz frames");
502 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
503 	    "rx_jbr_frames", CTLFLAG_RD,
504  	    &softc->rx_port_stats->rx_jbr_frames,
505 	    "Received jbr frames");
506 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
507 	    "rx_mtu_err_frames", CTLFLAG_RD,
508  	    &softc->rx_port_stats->rx_mtu_err_frames,
509 	    "Received mtu err frames");
510 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
511 	    "rx_match_crc_frames", CTLFLAG_RD,
512  	    &softc->rx_port_stats->rx_match_crc_frames,
513 	    "Received match crc frames");
514 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
515 	    "rx_promiscuous_frames", CTLFLAG_RD,
516  	    &softc->rx_port_stats->rx_promiscuous_frames,
517 	    "Received promiscuous frames");
518 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
519 	    "rx_tagged_frames", CTLFLAG_RD,
520  	    &softc->rx_port_stats->rx_tagged_frames,
521 	    "Received tagged frames");
522 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
523 	    "rx_double_tagged_frames", CTLFLAG_RD,
524  	    &softc->rx_port_stats->rx_double_tagged_frames,
525 	    "Received double tagged frames");
526 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
527 	    "rx_trunc_frames", CTLFLAG_RD,
528  	    &softc->rx_port_stats->rx_trunc_frames,
529 	    "Received trunc frames");
530 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
531 	    "rx_good_frames", CTLFLAG_RD,
532  	    &softc->rx_port_stats->rx_good_frames,
533 	    "Received good frames");
534 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
535 	    "rx_pfc_xon2xoff_frames_pri0", CTLFLAG_RD,
536  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri0,
537 	    "Received pfc xon2xoff frames pri0");
538 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
539 	    "rx_pfc_xon2xoff_frames_pri1", CTLFLAG_RD,
540  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri1,
541 	    "Received pfc xon2xoff frames pri1");
542 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
543 	    "rx_pfc_xon2xoff_frames_pri2", CTLFLAG_RD,
544  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri2,
545 	    "Received pfc xon2xoff frames pri2");
546 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
547 	    "rx_pfc_xon2xoff_frames_pri3", CTLFLAG_RD,
548  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri3,
549 	    "Received pfc xon2xoff frames pri3");
550 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
551 	    "rx_pfc_xon2xoff_frames_pri4", CTLFLAG_RD,
552  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri4,
553 	    "Received pfc xon2xoff frames pri4");
554 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
555 	    "rx_pfc_xon2xoff_frames_pri5", CTLFLAG_RD,
556  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri5,
557 	    "Received pfc xon2xoff frames pri5");
558 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
559 	    "rx_pfc_xon2xoff_frames_pri6", CTLFLAG_RD,
560  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri6,
561 	    "Received pfc xon2xoff frames pri6");
562 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
563 	    "rx_pfc_xon2xoff_frames_pri7", CTLFLAG_RD,
564  	    &softc->rx_port_stats->rx_pfc_xon2xoff_frames_pri7,
565 	    "Received pfc xon2xoff frames pri7");
566 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
567 	    "rx_pfc_ena_frames_pri0", CTLFLAG_RD,
568  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri0,
569 	    "Received pfc ena frames pri0");
570 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
571 	    "rx_pfc_ena_frames_pri1", CTLFLAG_RD,
572  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri1,
573 	    "Received pfc ena frames pri1");
574 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
575 	    "rx_pfc_ena_frames_pri2", CTLFLAG_RD,
576  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri2,
577 	    "Received pfc ena frames pri2");
578 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
579 	    "rx_pfc_ena_frames_pri3", CTLFLAG_RD,
580  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri3,
581 	    "Received pfc ena frames pri3");
582 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
583 	    "rx_pfc_ena_frames_pri4", CTLFLAG_RD,
584  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri4,
585 	    "Received pfc ena frames pri4");
586 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
587 	    "rx_pfc_ena_frames_pri5", CTLFLAG_RD,
588  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri5,
589 	    "Received pfc ena frames pri5");
590 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
591 	    "rx_pfc_ena_frames_pri6", CTLFLAG_RD,
592  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri6,
593 	    "Received pfc ena frames pri6");
594 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
595 	    "rx_pfc_ena_frames_pri7", CTLFLAG_RD,
596  	    &softc->rx_port_stats->rx_pfc_ena_frames_pri7,
597 	    "Received pfc ena frames pri7");
598 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
599 	    "rx_sch_crc_err_frames", CTLFLAG_RD,
600  	    &softc->rx_port_stats->rx_sch_crc_err_frames,
601 	    "Received sch crc err frames");
602 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
603 	    "rx_undrsz_frames", CTLFLAG_RD,
604  	    &softc->rx_port_stats->rx_undrsz_frames, "Received undrsz frames");
605 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
606 	    "rx_frag_frames", CTLFLAG_RD,
607  	    &softc->rx_port_stats->rx_frag_frames, "Received frag frames");
608 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
609 	    "rx_eee_lpi_events", CTLFLAG_RD,
610  	    &softc->rx_port_stats->rx_eee_lpi_events, "Received eee lpi events");
611 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
612 	    "rx_eee_lpi_duration", CTLFLAG_RD,
613  	    &softc->rx_port_stats->rx_eee_lpi_duration,
614 	    "Received eee lpi duration");
615 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
616 	    "rx_llfc_physical_msgs", CTLFLAG_RD,
617  	    &softc->rx_port_stats->rx_llfc_physical_msgs,
618 	    "Received llfc physical msgs");
619 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
620 	    "rx_llfc_logical_msgs", CTLFLAG_RD,
621  	    &softc->rx_port_stats->rx_llfc_logical_msgs,
622 	    "Received llfc logical msgs");
623 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
624 	    "rx_llfc_msgs_with_crc_err", CTLFLAG_RD,
625  	    &softc->rx_port_stats->rx_llfc_msgs_with_crc_err,
626 	    "Received llfc msgs with crc err");
627 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
628 	    "rx_hcfc_msgs", CTLFLAG_RD,
629  	    &softc->rx_port_stats->rx_hcfc_msgs, "Received hcfc msgs");
630 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
631 	    "rx_hcfc_msgs_with_crc_err", CTLFLAG_RD,
632  	    &softc->rx_port_stats->rx_hcfc_msgs_with_crc_err,
633 	    "Received hcfc msgs with crc err");
634 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
635 	    "rx_bytes", CTLFLAG_RD,
636  	    &softc->rx_port_stats->rx_bytes, "Received bytes");
637 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
638 	    "rx_runt_bytes", CTLFLAG_RD,
639  	    &softc->rx_port_stats->rx_runt_bytes, "Received runt bytes");
640 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
641 	    "rx_runt_frames", CTLFLAG_RD,
642  	    &softc->rx_port_stats->rx_runt_frames, "Received runt frames");
643 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
644 	    "rx_stat_discard", CTLFLAG_RD,
645  	    &softc->rx_port_stats->rx_stat_discard, "Received stat discard");
646 	SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
647 	    "rx_stat_err", CTLFLAG_RD,
648  	    &softc->rx_port_stats->rx_stat_err, "Received stat err");
649 
650 	return 0;
651 }
652 
653 int
bnxt_create_rx_sysctls(struct bnxt_softc * softc,int rxr)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,
665 	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 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
bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)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
bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)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
bnxt_create_ver_sysctls(struct bnxt_softc * softc)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 | CTLFLAG_MPSAFE,
865 	    softc, 0, 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 | CTLFLAG_MPSAFE,
869 	    softc, 0, bnxt_hwrm_min_ver_sysctl, "A",
870 	    "minimum hwrm API vesion to support");
871 
872 	return 0;
873 }
874 
875 int
bnxt_create_nvram_sysctls(struct bnxt_nvram_info * ni)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
bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)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 
bnxt_get_rss_type_str_bit(char * str)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
bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)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
bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS)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
bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_tx_usecs_irq(SYSCTL_HANDLER_ARGS)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
bnxt_set_coal_tx_frames_irq(SYSCTL_HANDLER_ARGS)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
bnxt_create_config_sysctls_pre(struct bnxt_softc * softc)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 | CTLFLAG_MPSAFE, softc, 0,
1209 	    bnxt_rss_key_sysctl, "A", "RSS key");
1210 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_type",
1211 	    CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1212 	    bnxt_rss_type_sysctl, "A", "RSS type bits");
1213 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_stall",
1214 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1215 	    bnxt_rx_stall_sysctl, "I",
1216 	    "buffer rx packets in hardware until the host posts new buffers");
1217 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_strip",
1218 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1219 	    bnxt_vlan_strip_sysctl, "I", "strip VLAN tag in the RX path");
1220 	SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "if_name", CTLFLAG_RD,
1221 		iflib_get_ifp(softc->ctx)->if_xname, 0, "interface name");
1222 
1223         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs",
1224             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1225 	    bnxt_set_coal_rx_usecs, "I", "interrupt coalescing Rx Usecs");
1226         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames",
1227             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1228 	    bnxt_set_coal_rx_frames, "I", "interrupt coalescing Rx Frames");
1229         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs_irq",
1230             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1231 	    bnxt_set_coal_rx_usecs_irq, "I",
1232 	    "interrupt coalescing Rx Usecs IRQ");
1233         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames_irq",
1234             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1235 	    bnxt_set_coal_rx_frames_irq, "I",
1236 	    "interrupt coalescing Rx Frames IRQ");
1237         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs",
1238             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1239 	    bnxt_set_coal_tx_usecs, "I", "interrupt coalescing Tx Usces");
1240         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames",
1241             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1242 	    bnxt_set_coal_tx_frames, "I", "interrupt coalescing Tx Frames");
1243         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs_irq",
1244             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1245 	    bnxt_set_coal_tx_usecs_irq, "I",
1246 	    "interrupt coalescing Tx Usecs IRQ");
1247         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames_irq",
1248             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1249 	    bnxt_set_coal_tx_frames_irq, "I",
1250 	    "interrupt coalescing Tx Frames IRQ");
1251 
1252 	return 0;
1253 }
1254 
1255 #define BNXT_HW_LRO_FN(fn_name, arg)			                   \
1256 static int						                   \
1257 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1258 	struct bnxt_softc *softc = arg1;		                   \
1259 	int rc;						                   \
1260 	int val;					                   \
1261 							                   \
1262 	if (softc == NULL)				                   \
1263 		return EBUSY;				                   \
1264 							                   \
1265 	val = softc->hw_lro.arg;			                   \
1266 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1267 	if (rc || !req->newptr)				                   \
1268 		return rc;				                   \
1269 							                   \
1270 	if ((if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)) \
1271 		return EBUSY;				                   \
1272 							                   \
1273 	softc->hw_lro.arg = val;			                   \
1274 	bnxt_validate_hw_lro_settings(softc);		                   \
1275 	rc = bnxt_hwrm_vnic_tpa_cfg(softc);		                   \
1276 							                   \
1277 	return rc;					                   \
1278 }
1279 
BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable,enable)1280 BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable, enable)
1281 BNXT_HW_LRO_FN(bnxt_hw_lro_set_mode, is_mode_gro)
1282 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_agg_segs, max_agg_segs)
1283 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_aggs, max_aggs)
1284 BNXT_HW_LRO_FN(bnxt_hw_lro_set_min_agg_len, min_agg_len)
1285 
1286 #define BNXT_FLOW_CTRL_FN(fn_name, arg)			                   \
1287 static int						                   \
1288 fn_name(SYSCTL_HANDLER_ARGS) {				                   \
1289 	struct bnxt_softc *softc = arg1;		                   \
1290 	int rc;						                   \
1291 	int val;					                   \
1292 							                   \
1293 	if (softc == NULL)				                   \
1294 		return EBUSY;				                   \
1295 							                   \
1296 	val = softc->link_info.flow_ctrl.arg;			           \
1297 	rc = sysctl_handle_int(oidp, &val, 0, req);	                   \
1298 	if (rc || !req->newptr)				                   \
1299 		return rc;				                   \
1300 							                   \
1301 	if (val)					                   \
1302 	   	val = 1; 				                   \
1303 	        					                   \
1304 	if (softc->link_info.flow_ctrl.arg != val) {		           \
1305 		softc->link_info.flow_ctrl.arg = val;		           \
1306 		rc = bnxt_hwrm_set_link_setting(softc, true, false, false);\
1307 		rc = bnxt_hwrm_port_phy_qcfg(softc);			   \
1308 	}						                   \
1309 							                   \
1310 	return rc;					                   \
1311 }
1312 
1313 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_tx, tx)
1314 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_rx, rx)
1315 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_autoneg, autoneg)
1316 int
1317 bnxt_create_pause_fc_sysctls(struct bnxt_softc *softc)
1318 {
1319 	struct sysctl_oid *oid = softc->flow_ctrl_oid;
1320 
1321 	if (!oid)
1322 		return ENOMEM;
1323 
1324 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1325 	    "tx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1326 	    bnxt_flow_ctrl_tx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1327 
1328 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1329 	    "rx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1330 	    bnxt_flow_ctrl_rx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1331 
1332 	SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1333 	    "autoneg", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1334 	    0, bnxt_flow_ctrl_autoneg, "A",
1335 	    "Enable or Disable Autoneg Flow Ctrl: 0 / 1");
1336 
1337 	return 0;
1338 }
1339 
1340 int
bnxt_create_hw_lro_sysctls(struct bnxt_softc * softc)1341 bnxt_create_hw_lro_sysctls(struct bnxt_softc *softc)
1342 {
1343 	struct sysctl_oid *oid = softc->hw_lro_oid;
1344 
1345 	if (!oid)
1346 		return ENOMEM;
1347 
1348 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1349 	    "enable", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1350 	    0, bnxt_hw_lro_enable_disable, "A",
1351 	    "Enable or Disable HW LRO: 0 / 1");
1352 
1353 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1354 	    "gro_mode", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1355 	    0, bnxt_hw_lro_set_mode, "A",
1356 	    "Set mode: 1 = GRO mode, 0 = RSC mode");
1357 
1358 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1359 	    "max_agg_segs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1360 	    softc, 0, bnxt_hw_lro_set_max_agg_segs, "A",
1361 	    "Set Max Agg Seg Value (unit is Log2): "
1362 	    "0 (= 1 seg) / 1 (= 2 segs) /  ... / 31 (= 2^31 segs)");
1363 
1364         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1365 	    "max_aggs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1366 	    softc, 0, bnxt_hw_lro_set_max_aggs, "A",
1367 	    "Set Max Aggs Value (unit is Log2): "
1368 	    "0 (= 1 agg) / 1 (= 2 aggs) /  ... / 7 (= 2^7 segs)");
1369 
1370 	SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1371 	    "min_agg_len", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1372 	    softc, 0, bnxt_hw_lro_set_min_agg_len, "A",
1373 	    "Min Agg Len: 1 to 9000");
1374 
1375 	return 0;
1376 }
1377 static int
bnxt_vlan_only_sysctl(SYSCTL_HANDLER_ARGS)1378 bnxt_vlan_only_sysctl(SYSCTL_HANDLER_ARGS) {
1379 	struct bnxt_softc *softc = arg1;
1380 	int rc;
1381 	int val;
1382 
1383 	if (softc == NULL)
1384 		return EBUSY;
1385 
1386 	val = softc->vnic_info.vlan_only;
1387 	rc = sysctl_handle_int(oidp, &val, 0, req);
1388 	if (rc || !req->newptr)
1389 		return rc;
1390 
1391 	if (val)
1392 		val = 1;
1393 
1394 	if (val != softc->vnic_info.vlan_only) {
1395 		softc->vnic_info.vlan_only = val;
1396 		if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1397 			rc = bnxt_hwrm_cfa_l2_set_rx_mask(softc,
1398 			    &softc->vnic_info);
1399 	}
1400 
1401 	return rc;
1402 }
1403 
1404 int
bnxt_create_config_sysctls_post(struct bnxt_softc * softc)1405 bnxt_create_config_sysctls_post(struct bnxt_softc *softc)
1406 {
1407 	struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1408 	struct sysctl_oid_list *children;
1409 
1410 	children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));
1411 
1412 	SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_only",
1413 	    CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1414 	    bnxt_vlan_only_sysctl, "I",
1415 	    "require vlan tag on received packets when vlan is enabled");
1416 
1417 	return 0;
1418 }
1419