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