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