]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bnxt/bnxt_sysctl.c
zfs: merge openzfs/zfs@95f71c019
[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 #include <sys/types.h>
31 #include <sys/sysctl.h>
32
33 #include "bnxt.h"
34 #include "bnxt_hwrm.h"
35 #include "bnxt_sysctl.h"
36
37 /*
38  * We want to create:
39  * dev.bnxt.0.hwstats.txq0
40  * dev.bnxt.0.hwstats.txq0.txmbufs
41  * dev.bnxt.0.hwstats.rxq0
42  * dev.bnxt.0.hwstats.txq0.rxmbufs
43  * so the hwstats ctx list needs to be created in attach_post and populated
44  * during init.
45  *
46  * Then, it needs to be cleaned up in stop.
47  */
48
49 int
50 bnxt_init_sysctl_ctx(struct bnxt_softc *softc)
51 {
52         struct sysctl_ctx_list *ctx;
53
54         sysctl_ctx_init(&softc->hw_stats);
55         ctx = device_get_sysctl_ctx(softc->dev);
56         softc->hw_stats_oid = SYSCTL_ADD_NODE(ctx,
57             SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
58             "hwstats", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware statistics");
59         if (!softc->hw_stats_oid) {
60                 sysctl_ctx_free(&softc->hw_stats);
61                 return ENOMEM;
62         }
63
64         sysctl_ctx_init(&softc->ver_info->ver_ctx);
65         ctx = device_get_sysctl_ctx(softc->dev);
66         softc->ver_info->ver_oid = SYSCTL_ADD_NODE(ctx,
67             SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
68             "ver", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
69             "hardware/firmware version information");
70         if (!softc->ver_info->ver_oid) {
71                 sysctl_ctx_free(&softc->ver_info->ver_ctx);
72                 return ENOMEM;
73         }
74
75         if (BNXT_PF(softc)) {
76                 sysctl_ctx_init(&softc->nvm_info->nvm_ctx);
77                 ctx = device_get_sysctl_ctx(softc->dev);
78                 softc->nvm_info->nvm_oid = SYSCTL_ADD_NODE(ctx,
79                     SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
80                     "nvram", CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
81                     "nvram information");
82                 if (!softc->nvm_info->nvm_oid) {
83                         sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
84                         return ENOMEM;
85                 }
86         }
87
88         sysctl_ctx_init(&softc->hw_lro_ctx);
89         ctx = device_get_sysctl_ctx(softc->dev);
90         softc->hw_lro_oid = SYSCTL_ADD_NODE(ctx,
91             SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
92             "hw_lro", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "hardware lro");
93         if (!softc->hw_lro_oid) {
94                 sysctl_ctx_free(&softc->hw_lro_ctx);
95                 return ENOMEM;
96         }
97
98         sysctl_ctx_init(&softc->flow_ctrl_ctx);
99         ctx = device_get_sysctl_ctx(softc->dev);
100         softc->flow_ctrl_oid = SYSCTL_ADD_NODE(ctx,
101             SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev)), OID_AUTO,
102             "fc", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "flow ctrl");
103         if (!softc->flow_ctrl_oid) {
104                 sysctl_ctx_free(&softc->flow_ctrl_ctx);
105                 return ENOMEM;
106         }
107
108         return 0;
109 }
110
111 int
112 bnxt_free_sysctl_ctx(struct bnxt_softc *softc)
113 {
114         int orc;
115         int rc = 0;
116
117         if (softc->hw_stats_oid != NULL) {
118                 orc = sysctl_ctx_free(&softc->hw_stats);
119                 if (orc)
120                         rc = orc;
121                 else
122                         softc->hw_stats_oid = NULL;
123         }
124         if (softc->ver_info->ver_oid != NULL) {
125                 orc = sysctl_ctx_free(&softc->ver_info->ver_ctx);
126                 if (orc)
127                         rc = orc;
128                 else
129                         softc->ver_info->ver_oid = NULL;
130         }
131         if (BNXT_PF(softc) && softc->nvm_info->nvm_oid != NULL) {
132                 orc = sysctl_ctx_free(&softc->nvm_info->nvm_ctx);
133                 if (orc)
134                         rc = orc;
135                 else
136                         softc->nvm_info->nvm_oid = NULL;
137         }
138         if (softc->hw_lro_oid != NULL) {
139                 orc = sysctl_ctx_free(&softc->hw_lro_ctx);
140                 if (orc)
141                         rc = orc;
142                 else
143                         softc->hw_lro_oid = NULL;
144         }
145
146         if (softc->flow_ctrl_oid != NULL) {
147                 orc = sysctl_ctx_free(&softc->flow_ctrl_ctx);
148                 if (orc)
149                         rc = orc;
150                 else
151                         softc->flow_ctrl_oid = NULL;
152         }
153
154         return rc;
155 }
156
157 int
158 bnxt_create_tx_sysctls(struct bnxt_softc *softc, int txr)
159 {
160         struct sysctl_oid *oid;
161         struct ctx_hw_stats *tx_stats = (void *)softc->tx_stats[txr].idi_vaddr;
162         char    name[32];
163         char    desc[64];
164
165         sprintf(name, "txq%d", txr);
166         sprintf(desc, "transmit queue %d", txr);
167         oid = SYSCTL_ADD_NODE(&softc->hw_stats,
168             SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
169             CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
170         if (!oid)
171                 return ENOMEM;
172
173         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
174             "ucast_pkts", CTLFLAG_RD, &tx_stats->tx_ucast_pkts,
175             "unicast packets sent");
176         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
177             "mcast_pkts", CTLFLAG_RD, &tx_stats->tx_mcast_pkts,
178             "multicast packets sent");
179         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
180             "bcast_pkts", CTLFLAG_RD, &tx_stats->tx_bcast_pkts,
181             "broadcast packets sent");
182         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
183             "discard_pkts", CTLFLAG_RD,
184             &tx_stats->tx_discard_pkts, "discarded transmit packets");
185         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
186             "error_pkts", CTLFLAG_RD, &tx_stats->tx_error_pkts,
187             "Error transmit packets");
188         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
189             "ucast_bytes", CTLFLAG_RD, &tx_stats->tx_ucast_bytes,
190             "unicast bytes sent");
191         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
192             "mcast_bytes", CTLFLAG_RD, &tx_stats->tx_mcast_bytes,
193             "multicast bytes sent");
194         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
195             "bcast_bytes", CTLFLAG_RD, &tx_stats->tx_bcast_bytes,
196             "broadcast bytes sent");
197
198         return 0;
199 }
200
201 int
202 bnxt_create_port_stats_sysctls(struct bnxt_softc *softc)
203 {
204         struct sysctl_oid *oid;
205         char    name[32];
206         char    desc[64];
207
208         sprintf(name, "port_stats");
209         sprintf(desc, "Port Stats");
210         oid = SYSCTL_ADD_NODE(&softc->hw_stats,
211             SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
212                 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
213         if (!oid)
214                 return ENOMEM;
215
216         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
217             "tx_64b_frames", CTLFLAG_RD,
218             &softc->tx_port_stats->tx_64b_frames, "Transmitted 64b frames");
219         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
220             "tx_65b_127b_frames", CTLFLAG_RD,
221             &softc->tx_port_stats->tx_65b_127b_frames,
222             "Transmitted 65b 127b frames");
223         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
224             "tx_128b_255b_frames", CTLFLAG_RD,
225             &softc->tx_port_stats->tx_128b_255b_frames,
226             "Transmitted 128b 255b frames");
227         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
228             "tx_256b_511b_frames", CTLFLAG_RD,
229             &softc->tx_port_stats->tx_256b_511b_frames,
230             "Transmitted 256b 511b frames");
231         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
232             "tx_512b_1023b_frames", CTLFLAG_RD,
233             &softc->tx_port_stats->tx_512b_1023b_frames,
234             "Transmitted 512b 1023b frames");
235         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
236             "tx_1024b_1518_frames", CTLFLAG_RD,
237             &softc->tx_port_stats->tx_1024b_1518b_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_2047b_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_1518b_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 int
651 bnxt_create_rx_sysctls(struct bnxt_softc *softc, int rxr)
652 {
653         struct sysctl_oid *oid;
654         struct ctx_hw_stats *rx_stats = (void *)softc->rx_stats[rxr].idi_vaddr;
655         char    name[32];
656         char    desc[64];
657
658         sprintf(name, "rxq%d", rxr);
659         sprintf(desc, "receive queue %d", rxr);
660         oid = SYSCTL_ADD_NODE(&softc->hw_stats,
661             SYSCTL_CHILDREN(softc->hw_stats_oid), OID_AUTO, name,
662             CTLFLAG_RD | CTLFLAG_MPSAFE, 0, desc);
663         if (!oid)
664                 return ENOMEM;
665
666         if (BNXT_CHIP_P5(softc))
667                 SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
668                     "nq_num_ints", CTLFLAG_RD, &softc->nq_rings[rxr].int_count,
669                     "Num Interrupts");
670         else
671                 SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
672                     "rq_num_ints", CTLFLAG_RD, &softc->rx_cp_rings[rxr].int_count,
673                     "Num Interrupts");
674         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
675             "ucast_pkts", CTLFLAG_RD, &rx_stats->rx_ucast_pkts,
676             "unicast packets received");
677         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
678             "mcast_pkts", CTLFLAG_RD, &rx_stats->rx_mcast_pkts,
679             "multicast packets received");
680         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
681             "bcast_pkts", CTLFLAG_RD, &rx_stats->rx_bcast_pkts,
682             "broadcast packets received");
683         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
684             "discard_pkts", CTLFLAG_RD,
685             &rx_stats->rx_discard_pkts, "discarded receive packets");
686         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
687             "error_pkts", CTLFLAG_RD, &rx_stats->rx_error_pkts,
688             "Error receive packets");
689         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
690             "ucast_bytes", CTLFLAG_RD, &rx_stats->rx_ucast_bytes,
691             "unicast bytes received");
692         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
693             "mcast_bytes", CTLFLAG_RD, &rx_stats->rx_mcast_bytes,
694             "multicast bytes received");
695         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
696             "bcast_bytes", CTLFLAG_RD, &rx_stats->rx_bcast_bytes,
697             "broadcast bytes received");
698
699         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
700             "tpa_pkts", CTLFLAG_RD, &rx_stats->tpa_pkts,
701             "TPA packets");
702         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
703             "tpa_bytes", CTLFLAG_RD, &rx_stats->tpa_bytes,
704             "TPA bytes");
705         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
706             "tpa_events", CTLFLAG_RD, &rx_stats->tpa_events,
707             "TPA events");
708         SYSCTL_ADD_QUAD(&softc->hw_stats, SYSCTL_CHILDREN(oid), OID_AUTO,
709             "tpa_aborts", CTLFLAG_RD, &rx_stats->tpa_aborts,
710             "TPA aborts");
711
712         return 0;
713 }
714
715 static char *bnxt_chip_type[] = {
716         "ASIC",
717         "FPGA",
718         "Palladium",
719         "Unknown"
720 };
721 #define MAX_CHIP_TYPE 3
722
723 static int
724 bnxt_package_ver_sysctl(SYSCTL_HANDLER_ARGS)
725 {
726         struct bnxt_softc *softc = arg1;
727         struct iflib_dma_info dma_data;
728         char *pkglog = NULL;
729         char *p;
730         char *next;
731         char unk[] = "<unknown>";
732         char *buf = unk;
733         int rc;
734         int field;
735         uint16_t ordinal = BNX_DIR_ORDINAL_FIRST;
736         uint16_t index;
737         uint32_t data_len;
738
739         rc = bnxt_hwrm_nvm_find_dir_entry(softc, BNX_DIR_TYPE_PKG_LOG,
740             &ordinal, BNX_DIR_EXT_NONE, &index, false,
741             HWRM_NVM_FIND_DIR_ENTRY_INPUT_OPT_ORDINAL_EQ,
742             &data_len, NULL, NULL);
743         dma_data.idi_vaddr = NULL;
744         if (rc == 0 && data_len) {
745                 rc = iflib_dma_alloc(softc->ctx, data_len, &dma_data,
746                     BUS_DMA_NOWAIT);
747                 if (rc == 0) {
748                         rc = bnxt_hwrm_nvm_read(softc, index, 0, data_len,
749                             &dma_data);
750                         if (rc == 0) {
751                                 pkglog = dma_data.idi_vaddr;
752                                 /* NULL terminate (removes last \n) */
753                                 pkglog[data_len-1] = 0;
754
755                                 /* Set p = start of last line */
756                                 p = strrchr(pkglog, '\n');
757                                 if (p == NULL)
758                                         p = pkglog;
759
760                                 /* Now find the correct tab delimited field */
761                                 for (field = 0, next = p,
762                                     p = strsep(&next, "\t");
763                                     field <
764                                     BNX_PKG_LOG_FIELD_IDX_PKG_VERSION && p;
765                                     p = strsep(&next, "\t")) {
766                                         field++;
767                                 }
768                                 if (field == BNX_PKG_LOG_FIELD_IDX_PKG_VERSION)
769                                         buf = p;
770                         }
771                 }
772                 else
773                         dma_data.idi_vaddr = NULL;
774         }
775
776         rc = sysctl_handle_string(oidp, buf, 0, req);
777         if (dma_data.idi_vaddr)
778                 iflib_dma_free(&dma_data);
779         return rc;
780 }
781
782 static int
783 bnxt_hwrm_min_ver_sysctl(SYSCTL_HANDLER_ARGS)
784 {
785         struct bnxt_softc *softc = arg1;
786         char buf[16];
787         uint8_t newver[3];
788         int rc;
789
790         sprintf(buf, "%hhu.%hhu.%hhu", softc->ver_info->hwrm_min_major,
791             softc->ver_info->hwrm_min_minor, softc->ver_info->hwrm_min_update);
792
793         rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
794         if (rc || req->newptr == NULL)
795                 return rc;
796         if (sscanf(buf, "%hhu.%hhu.%hhu%*c", &newver[0], &newver[1],
797             &newver[2]) != 3)
798                 return EINVAL;
799         softc->ver_info->hwrm_min_major = newver[0];
800         softc->ver_info->hwrm_min_minor = newver[1];
801         softc->ver_info->hwrm_min_update = newver[2];
802         bnxt_check_hwrm_version(softc);
803
804         return rc;
805 }
806
807 int
808 bnxt_create_ver_sysctls(struct bnxt_softc *softc)
809 {
810         struct bnxt_ver_info *vi = softc->ver_info;
811         struct sysctl_oid *oid = vi->ver_oid;
812
813         if (!oid)
814                 return ENOMEM;
815
816         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
817             "hwrm_if", CTLFLAG_RD, vi->hwrm_if_ver, 0,
818             "HWRM interface version");
819         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
820             "driver_hwrm_if", CTLFLAG_RD, vi->driver_hwrm_if_ver, 0,
821             "HWRM firmware version");
822         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
823             "hwrm_fw", CTLFLAG_RD, vi->hwrm_fw_ver, 0,
824             "HWRM firmware version");
825         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
826             "mgmt_fw", CTLFLAG_RD, vi->mgmt_fw_ver, 0,
827             "management firmware version");
828         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
829             "netctrl_fw", CTLFLAG_RD, vi->netctrl_fw_ver, 0,
830             "network control firmware version");
831         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
832             "roce_fw", CTLFLAG_RD, vi->roce_fw_ver, 0,
833             "RoCE firmware version");
834         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
835             "fw_ver", CTLFLAG_RD, vi->fw_ver_str, 0,
836             "Firmware version");
837         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
838             "phy", CTLFLAG_RD, vi->phy_ver, 0,
839             "PHY version");
840         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
841             "hwrm_fw_name", CTLFLAG_RD, vi->hwrm_fw_name, 0,
842             "HWRM firmware name");
843         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
844             "mgmt_fw_name", CTLFLAG_RD, vi->mgmt_fw_name, 0,
845             "management firmware name");
846         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
847             "netctrl_fw_name", CTLFLAG_RD, vi->netctrl_fw_name, 0,
848             "network control firmware name");
849         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
850             "roce_fw_name", CTLFLAG_RD, vi->roce_fw_name, 0,
851             "RoCE firmware name");
852         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
853             "phy_vendor", CTLFLAG_RD, vi->phy_vendor, 0,
854             "PHY vendor name");
855         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
856             "phy_partnumber", CTLFLAG_RD, vi->phy_partnumber, 0,
857             "PHY vendor part number");
858         SYSCTL_ADD_U16(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
859             "chip_num", CTLFLAG_RD, &vi->chip_num, 0, "chip number");
860         SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
861             "chip_rev", CTLFLAG_RD, &vi->chip_rev, 0, "chip revision");
862         SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
863             "chip_metal", CTLFLAG_RD, &vi->chip_metal, 0, "chip metal number");
864         SYSCTL_ADD_U8(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
865             "chip_bond_id", CTLFLAG_RD, &vi->chip_bond_id, 0,
866             "chip bond id");
867         SYSCTL_ADD_STRING(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
868             "chip_type", CTLFLAG_RD, vi->chip_type > MAX_CHIP_TYPE ?
869             bnxt_chip_type[MAX_CHIP_TYPE] : bnxt_chip_type[vi->chip_type], 0,
870             "RoCE firmware name");
871         SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
872             "package_ver", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
873             softc, 0, bnxt_package_ver_sysctl, "A",
874             "currently installed package version");
875         SYSCTL_ADD_PROC(&vi->ver_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
876             "hwrm_min_ver", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
877             softc, 0, bnxt_hwrm_min_ver_sysctl, "A",
878             "minimum hwrm API vesion to support");
879
880         return 0;
881 }
882
883 int
884 bnxt_create_nvram_sysctls(struct bnxt_nvram_info *ni)
885 {
886         struct sysctl_oid *oid = ni->nvm_oid;
887
888         if (!oid)
889                 return ENOMEM;
890
891         SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
892             "mfg_id", CTLFLAG_RD, &ni->mfg_id, 0, "manufacturer id");
893         SYSCTL_ADD_U16(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
894             "device_id", CTLFLAG_RD, &ni->device_id, 0, "device id");
895         SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
896             "sector_size", CTLFLAG_RD, &ni->sector_size, 0, "sector size");
897         SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
898             "size", CTLFLAG_RD, &ni->size, 0, "nvram total size");
899         SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
900             "reserved_size", CTLFLAG_RD, &ni->reserved_size, 0,
901             "total reserved space");
902         SYSCTL_ADD_U32(&ni->nvm_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
903             "available_size", CTLFLAG_RD, &ni->available_size, 0,
904             "total available space");
905
906         return 0;
907 }
908
909 static int
910 bnxt_rss_key_sysctl(SYSCTL_HANDLER_ARGS)
911 {
912         struct bnxt_softc *softc = arg1;
913         char buf[HW_HASH_KEY_SIZE*2+1] = {0};
914         char *p;
915         int i;
916         int rc;
917
918         for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++)
919                 p += sprintf(p, "%02x", softc->vnic_info.rss_hash_key[i]);
920
921         rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
922         if (rc || req->newptr == NULL)
923                 return rc;
924
925         if (strspn(buf, "0123456789abcdefABCDEF") != (HW_HASH_KEY_SIZE * 2))
926                 return EINVAL;
927
928         for (p = buf, i=0; i<HW_HASH_KEY_SIZE; i++) {
929                 if (sscanf(p, "%02hhx", &softc->vnic_info.rss_hash_key[i]) != 1)
930                         return EINVAL;
931                 p += 2;
932         }
933
934         if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
935                 bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
936                     softc->vnic_info.rss_hash_type);
937
938         return rc;
939 }
940
941 static const char *bnxt_hash_types[] = {"ipv4", "tcp_ipv4", "udp_ipv4", "ipv6",
942     "tcp_ipv6", "udp_ipv6", NULL};
943
944 static int bnxt_get_rss_type_str_bit(char *str)
945 {
946         int i;
947
948         for (i=0; bnxt_hash_types[i]; i++)
949                 if (strcmp(bnxt_hash_types[i], str) == 0)
950                         return i;
951
952         return -1;
953 }
954
955 static int
956 bnxt_rss_type_sysctl(SYSCTL_HANDLER_ARGS)
957 {
958         struct bnxt_softc *softc = arg1;
959         char buf[256] = {0};
960         char *p;
961         char *next;
962         int rc;
963         int type;
964         int bit;
965
966         for (type = softc->vnic_info.rss_hash_type; type;
967             type &= ~(1<<bit)) {
968                 bit = ffs(type) - 1;
969                 if (bit >= sizeof(bnxt_hash_types) / sizeof(const char *))
970                         continue;
971                 if (type != softc->vnic_info.rss_hash_type)
972                         strcat(buf, ",");
973                 strcat(buf, bnxt_hash_types[bit]);
974         }
975
976         rc = sysctl_handle_string(oidp, buf, sizeof(buf), req);
977         if (rc || req->newptr == NULL)
978                 return rc;
979
980         for (type = 0, next = buf, p = strsep(&next, " ,"); p;
981             p = strsep(&next, " ,")) {
982                 bit = bnxt_get_rss_type_str_bit(p);
983                 if (bit == -1)
984                         return EINVAL;
985                 type |= 1<<bit;
986         }
987         if (type != softc->vnic_info.rss_hash_type) {
988                 softc->vnic_info.rss_hash_type = type;
989                 if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
990                         bnxt_hwrm_rss_cfg(softc, &softc->vnic_info,
991                             softc->vnic_info.rss_hash_type);
992         }
993
994         return rc;
995 }
996
997 static int
998 bnxt_rx_stall_sysctl(SYSCTL_HANDLER_ARGS) {
999         struct bnxt_softc *softc = arg1;
1000         int rc;
1001         int val;
1002
1003         if (softc == NULL)
1004                 return EBUSY;
1005
1006         val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_BD_STALL);
1007         rc = sysctl_handle_int(oidp, &val, 0, req);
1008         if (rc || !req->newptr)
1009                 return rc;
1010
1011         if (val)
1012                 softc->vnic_info.flags |= BNXT_VNIC_FLAG_BD_STALL;
1013         else
1014                 softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_BD_STALL;
1015
1016         if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1017                 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1018
1019         return rc;
1020 }
1021
1022 static int
1023 bnxt_vlan_strip_sysctl(SYSCTL_HANDLER_ARGS) {
1024         struct bnxt_softc *softc = arg1;
1025         int rc;
1026         int val;
1027
1028         if (softc == NULL)
1029                 return EBUSY;
1030
1031         val = (bool)(softc->vnic_info.flags & BNXT_VNIC_FLAG_VLAN_STRIP);
1032         rc = sysctl_handle_int(oidp, &val, 0, req);
1033         if (rc || !req->newptr)
1034                 return rc;
1035
1036         if (val)
1037                 softc->vnic_info.flags |= BNXT_VNIC_FLAG_VLAN_STRIP;
1038         else
1039                 softc->vnic_info.flags &= ~BNXT_VNIC_FLAG_VLAN_STRIP;
1040
1041         if (if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)
1042                 rc = bnxt_hwrm_vnic_cfg(softc, &softc->vnic_info);
1043
1044         return rc;
1045 }
1046
1047 static int
1048 bnxt_set_coal_rx_usecs(SYSCTL_HANDLER_ARGS) {
1049         struct bnxt_softc *softc = arg1;
1050         int rc;
1051         int val;
1052
1053         if (softc == NULL)
1054                 return EBUSY;
1055
1056         val = softc->rx_coal_usecs;
1057         rc = sysctl_handle_int(oidp, &val, 0, req);
1058         if (rc || !req->newptr)
1059                 return rc;
1060
1061         softc->rx_coal_usecs = val;
1062         rc = bnxt_hwrm_set_coal(softc);
1063
1064         return rc;
1065 }
1066
1067 static int
1068 bnxt_set_coal_rx_frames(SYSCTL_HANDLER_ARGS) {
1069         struct bnxt_softc *softc = arg1;
1070         int rc;
1071         int val;
1072
1073         if (softc == NULL)
1074                 return EBUSY;
1075
1076         val = softc->rx_coal_frames;
1077         rc = sysctl_handle_int(oidp, &val, 0, req);
1078         if (rc || !req->newptr)
1079                 return rc;
1080
1081         softc->rx_coal_frames = val;
1082         rc = bnxt_hwrm_set_coal(softc);
1083
1084         return rc;
1085 }
1086
1087 static int
1088 bnxt_set_coal_rx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1089         struct bnxt_softc *softc = arg1;
1090         int rc;
1091         int val;
1092
1093         if (softc == NULL)
1094                 return EBUSY;
1095
1096         val = softc->rx_coal_usecs_irq;
1097         rc = sysctl_handle_int(oidp, &val, 0, req);
1098         if (rc || !req->newptr)
1099                 return rc;
1100
1101         softc->rx_coal_usecs_irq = val;
1102         rc = bnxt_hwrm_set_coal(softc);
1103
1104         return rc;
1105 }
1106
1107 static int
1108 bnxt_set_coal_rx_frames_irq(SYSCTL_HANDLER_ARGS) {
1109         struct bnxt_softc *softc = arg1;
1110         int rc;
1111         int val;
1112
1113         if (softc == NULL)
1114                 return EBUSY;
1115
1116         val = softc->rx_coal_frames_irq;
1117         rc = sysctl_handle_int(oidp, &val, 0, req);
1118         if (rc || !req->newptr)
1119                 return rc;
1120
1121         softc->rx_coal_frames_irq = val;
1122         rc = bnxt_hwrm_set_coal(softc);
1123
1124         return rc;
1125 }
1126
1127 static int
1128 bnxt_set_coal_tx_usecs(SYSCTL_HANDLER_ARGS) {
1129         struct bnxt_softc *softc = arg1;
1130         int rc;
1131         int val;
1132
1133         if (softc == NULL)
1134                 return EBUSY;
1135
1136         val = softc->tx_coal_usecs;
1137         rc = sysctl_handle_int(oidp, &val, 0, req);
1138         if (rc || !req->newptr)
1139                 return rc;
1140
1141         softc->tx_coal_usecs = val;
1142         rc = bnxt_hwrm_set_coal(softc);
1143
1144         return rc;
1145 }
1146
1147 static int
1148 bnxt_set_coal_tx_frames(SYSCTL_HANDLER_ARGS) {
1149         struct bnxt_softc *softc = arg1;
1150         int rc;
1151         int val;
1152
1153         if (softc == NULL)
1154                 return EBUSY;
1155
1156         val = softc->tx_coal_frames;
1157         rc = sysctl_handle_int(oidp, &val, 0, req);
1158         if (rc || !req->newptr)
1159                 return rc;
1160
1161         softc->tx_coal_frames = val;
1162         rc = bnxt_hwrm_set_coal(softc);
1163
1164         return rc;
1165 }
1166
1167 static int
1168 bnxt_set_coal_tx_usecs_irq(SYSCTL_HANDLER_ARGS) {
1169         struct bnxt_softc *softc = arg1;
1170         int rc;
1171         int val;
1172
1173         if (softc == NULL)
1174                 return EBUSY;
1175
1176         val = softc->tx_coal_usecs_irq;
1177         rc = sysctl_handle_int(oidp, &val, 0, req);
1178         if (rc || !req->newptr)
1179                 return rc;
1180
1181         softc->tx_coal_usecs_irq = val;
1182         rc = bnxt_hwrm_set_coal(softc);
1183
1184         return rc;
1185 }
1186
1187 static int
1188 bnxt_set_coal_tx_frames_irq(SYSCTL_HANDLER_ARGS) {
1189         struct bnxt_softc *softc = arg1;
1190         int rc;
1191         int val;
1192
1193         if (softc == NULL)
1194                 return EBUSY;
1195
1196         val = softc->tx_coal_frames_irq;
1197         rc = sysctl_handle_int(oidp, &val, 0, req);
1198         if (rc || !req->newptr)
1199                 return rc;
1200
1201         softc->tx_coal_frames_irq = val;
1202         rc = bnxt_hwrm_set_coal(softc);
1203
1204         return rc;
1205 }
1206
1207 int
1208 bnxt_create_config_sysctls_pre(struct bnxt_softc *softc)
1209 {
1210         struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(softc->dev);
1211         struct sysctl_oid_list *children;
1212
1213         children = SYSCTL_CHILDREN(device_get_sysctl_tree(softc->dev));
1214
1215         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_key",
1216             CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1217             bnxt_rss_key_sysctl, "A", "RSS key");
1218         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rss_type",
1219             CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1220             bnxt_rss_type_sysctl, "A", "RSS type bits");
1221         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "rx_stall",
1222             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1223             bnxt_rx_stall_sysctl, "I",
1224             "buffer rx packets in hardware until the host posts new buffers");
1225         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "vlan_strip",
1226             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1227             bnxt_vlan_strip_sysctl, "I", "strip VLAN tag in the RX path");
1228         SYSCTL_ADD_CONST_STRING(ctx, children, OID_AUTO, "if_name", CTLFLAG_RD,
1229                 if_name(iflib_get_ifp(softc->ctx)), "interface name");
1230
1231         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs",
1232             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1233             bnxt_set_coal_rx_usecs, "I", "interrupt coalescing Rx Usecs");
1234         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames",
1235             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1236             bnxt_set_coal_rx_frames, "I", "interrupt coalescing Rx Frames");
1237         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_usecs_irq",
1238             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1239             bnxt_set_coal_rx_usecs_irq, "I",
1240             "interrupt coalescing Rx Usecs IRQ");
1241         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_rx_frames_irq",
1242             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1243             bnxt_set_coal_rx_frames_irq, "I",
1244             "interrupt coalescing Rx Frames IRQ");
1245         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs",
1246             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1247             bnxt_set_coal_tx_usecs, "I", "interrupt coalescing Tx Usces");
1248         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames",
1249             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1250             bnxt_set_coal_tx_frames, "I", "interrupt coalescing Tx Frames"); 
1251         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_usecs_irq",
1252             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1253             bnxt_set_coal_tx_usecs_irq, "I",
1254             "interrupt coalescing Tx Usecs IRQ"); 
1255         SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "intr_coal_tx_frames_irq",
1256             CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1257             bnxt_set_coal_tx_frames_irq, "I",
1258             "interrupt coalescing Tx Frames IRQ");
1259
1260         return 0;
1261 }
1262
1263 #define BNXT_HW_LRO_FN(fn_name, arg)                                       \
1264 static int                                                                 \
1265 fn_name(SYSCTL_HANDLER_ARGS) {                                             \
1266         struct bnxt_softc *softc = arg1;                                   \
1267         int rc;                                                            \
1268         int val;                                                           \
1269                                                                            \
1270         if (softc == NULL)                                                 \
1271                 return EBUSY;                                              \
1272                                                                            \
1273         val = softc->hw_lro.arg;                                           \
1274         rc = sysctl_handle_int(oidp, &val, 0, req);                        \
1275         if (rc || !req->newptr)                                            \
1276                 return rc;                                                 \
1277                                                                            \
1278         if ((if_getdrvflags(iflib_get_ifp(softc->ctx)) & IFF_DRV_RUNNING)) \
1279                 return EBUSY;                                              \
1280                                                                            \
1281         if (!(softc->flags & BNXT_FLAG_TPA))                               \
1282                 return EINVAL;                                             \
1283                                                                            \
1284         softc->hw_lro.arg = val;                                           \
1285         bnxt_validate_hw_lro_settings(softc);                              \
1286         rc = bnxt_hwrm_vnic_tpa_cfg(softc);                                \
1287                                                                            \
1288         return rc;                                                         \
1289 }
1290
1291 BNXT_HW_LRO_FN(bnxt_hw_lro_enable_disable, enable)
1292 BNXT_HW_LRO_FN(bnxt_hw_lro_set_mode, is_mode_gro)
1293 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_agg_segs, max_agg_segs)
1294 BNXT_HW_LRO_FN(bnxt_hw_lro_set_max_aggs, max_aggs)
1295 BNXT_HW_LRO_FN(bnxt_hw_lro_set_min_agg_len, min_agg_len)
1296
1297 #define BNXT_FLOW_CTRL_FN(fn_name, arg)                                    \
1298 static int                                                                 \
1299 fn_name(SYSCTL_HANDLER_ARGS) {                                             \
1300         struct bnxt_softc *softc = arg1;                                   \
1301         int rc;                                                            \
1302         int val;                                                           \
1303                                                                            \
1304         if (softc == NULL)                                                 \
1305                 return EBUSY;                                              \
1306                                                                            \
1307         val = softc->link_info.flow_ctrl.arg;                              \
1308         rc = sysctl_handle_int(oidp, &val, 0, req);                        \
1309         if (rc || !req->newptr)                                            \
1310                 return rc;                                                 \
1311                                                                            \
1312         if (val)                                                           \
1313                 val = 1;                                                   \
1314                                                                            \
1315         if (softc->link_info.flow_ctrl.arg != val) {                       \
1316                 softc->link_info.flow_ctrl.arg = val;                      \
1317                 rc = bnxt_hwrm_set_link_setting(softc, true, false, false);\
1318                 rc = bnxt_hwrm_port_phy_qcfg(softc);                       \
1319         }                                                                  \
1320                                                                            \
1321         return rc;                                                         \
1322 }
1323
1324 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_tx, tx)
1325 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_rx, rx)
1326 BNXT_FLOW_CTRL_FN(bnxt_flow_ctrl_autoneg, autoneg)
1327 int
1328 bnxt_create_pause_fc_sysctls(struct bnxt_softc *softc)
1329 {
1330         struct sysctl_oid *oid = softc->flow_ctrl_oid;
1331
1332         if (!oid)
1333                 return ENOMEM;
1334
1335         SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1336             "tx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1337             bnxt_flow_ctrl_tx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1338
1339         SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1340             "rx", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc, 0,
1341             bnxt_flow_ctrl_rx, "A", "Enable or Disable Tx Flow Ctrl: 0 / 1");
1342
1343         SYSCTL_ADD_PROC(&softc->flow_ctrl_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1344             "autoneg", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1345             0, bnxt_flow_ctrl_autoneg, "A",
1346             "Enable or Disable Autoneg Flow Ctrl: 0 / 1");
1347
1348         return 0;
1349 }
1350
1351 int
1352 bnxt_create_hw_lro_sysctls(struct bnxt_softc *softc)
1353 {
1354         struct sysctl_oid *oid = softc->hw_lro_oid;
1355
1356         if (!oid)
1357                 return ENOMEM;
1358
1359         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1360             "enable", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1361             0, bnxt_hw_lro_enable_disable, "A",
1362             "Enable or Disable HW LRO: 0 / 1");
1363
1364         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1365             "gro_mode", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, softc,
1366             0, bnxt_hw_lro_set_mode, "A",
1367             "Set mode: 1 = GRO mode, 0 = RSC mode");
1368
1369         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1370             "max_agg_segs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1371             softc, 0, bnxt_hw_lro_set_max_agg_segs, "A",
1372             "Set Max Agg Seg Value (unit is Log2): "
1373             "0 (= 1 seg) / 1 (= 2 segs) /  ... / 31 (= 2^31 segs)");
1374
1375         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1376             "max_aggs", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1377             softc, 0, bnxt_hw_lro_set_max_aggs, "A",
1378             "Set Max Aggs Value (unit is Log2): "
1379             "0 (= 1 agg) / 1 (= 2 aggs) /  ... / 7 (= 2^7 segs)");
1380
1381         SYSCTL_ADD_PROC(&softc->hw_lro_ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
1382             "min_agg_len", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1383             softc, 0, bnxt_hw_lro_set_min_agg_len, "A",
1384             "Min Agg Len: 1 to 9000");
1385
1386         return 0;
1387 }
1388
1389 int
1390 bnxt_create_config_sysctls_post(struct bnxt_softc *softc)
1391 {
1392         /* Nothing for now, meant for future expansion */
1393         return 0;
1394 }