xref: /freebsd/sys/dev/mana/mana_sysctl.c (revision 516b5059)
1ce110ea1SWei Hu /*-
2ce110ea1SWei Hu  * SPDX-License-Identifier: BSD-2-Clause
3ce110ea1SWei Hu  *
4ce110ea1SWei Hu  * Copyright (c) 2021 Microsoft Corp.
5ce110ea1SWei Hu  * All rights reserved.
6ce110ea1SWei Hu  *
7ce110ea1SWei Hu  * Redistribution and use in source and binary forms, with or without
8ce110ea1SWei Hu  * modification, are permitted provided that the following conditions
9ce110ea1SWei Hu  * are met:
10ce110ea1SWei Hu  *
11ce110ea1SWei Hu  * 1. Redistributions of source code must retain the above copyright
12ce110ea1SWei Hu  *    notice, this list of conditions and the following disclaimer.
13ce110ea1SWei Hu  *
14ce110ea1SWei Hu  * 2. Redistributions in binary form must reproduce the above copyright
15ce110ea1SWei Hu  *    notice, this list of conditions and the following disclaimer in the
16ce110ea1SWei Hu  *    documentation and/or other materials provided with the distribution.
17ce110ea1SWei Hu  *
18ce110ea1SWei Hu  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19ce110ea1SWei Hu  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20ce110ea1SWei Hu  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21ce110ea1SWei Hu  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22ce110ea1SWei Hu  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23ce110ea1SWei Hu  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24ce110ea1SWei Hu  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25ce110ea1SWei Hu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26ce110ea1SWei Hu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27ce110ea1SWei Hu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28ce110ea1SWei Hu  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29ce110ea1SWei Hu  */
30ce110ea1SWei Hu #include <sys/cdefs.h>
31ce110ea1SWei Hu #include "mana_sysctl.h"
32ce110ea1SWei Hu 
33ce110ea1SWei Hu static int mana_sysctl_cleanup_thread_cpu(SYSCTL_HANDLER_ARGS);
34ce110ea1SWei Hu 
35ce110ea1SWei Hu int mana_log_level = MANA_ALERT | MANA_WARNING | MANA_INFO;
36ce110ea1SWei Hu 
37ce110ea1SWei Hu SYSCTL_NODE(_hw, OID_AUTO, mana, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
38ce110ea1SWei Hu     "MANA driver parameters");
39ce110ea1SWei Hu 
40ce110ea1SWei Hu /*
41ce110ea1SWei Hu  * Logging level for changing verbosity of the output
42ce110ea1SWei Hu  */
43ce110ea1SWei Hu SYSCTL_INT(_hw_mana, OID_AUTO, log_level, CTLFLAG_RWTUN,
44ce110ea1SWei Hu     &mana_log_level, 0, "Logging level indicating verbosity of the logs");
45ce110ea1SWei Hu 
46ce110ea1SWei Hu SYSCTL_CONST_STRING(_hw_mana, OID_AUTO, driver_version, CTLFLAG_RD,
47ce110ea1SWei Hu     DRV_MODULE_VERSION, "MANA driver version");
48ce110ea1SWei Hu 
49b167e449SWei Hu static int
mana_sysctl_rx_stat_agg_u64(SYSCTL_HANDLER_ARGS)50b167e449SWei Hu mana_sysctl_rx_stat_agg_u64(SYSCTL_HANDLER_ARGS)
51b167e449SWei Hu {
52b167e449SWei Hu 	struct mana_port_context *apc = arg1;
53b167e449SWei Hu 	int offset = arg2, i, err;
54b167e449SWei Hu 	struct mana_rxq *rxq;
55b167e449SWei Hu 	uint64_t stat;
56b167e449SWei Hu 
57b167e449SWei Hu 	stat = 0;
58b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
59b167e449SWei Hu 		rxq = apc->rxqs[i];
60b167e449SWei Hu 		stat += *((uint64_t *)((uint8_t *)rxq + offset));
61b167e449SWei Hu 	}
62b167e449SWei Hu 
63b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
64b167e449SWei Hu 	if (err || req->newptr == NULL)
65b167e449SWei Hu 		return err;
66b167e449SWei Hu 
67b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
68b167e449SWei Hu 		rxq = apc->rxqs[i];
69b167e449SWei Hu 		*((uint64_t *)((uint8_t *)rxq + offset)) = 0;
70b167e449SWei Hu 	}
71b167e449SWei Hu 	return 0;
72b167e449SWei Hu }
73b167e449SWei Hu 
74b167e449SWei Hu static int
mana_sysctl_rx_stat_u16(SYSCTL_HANDLER_ARGS)75b167e449SWei Hu mana_sysctl_rx_stat_u16(SYSCTL_HANDLER_ARGS)
76b167e449SWei Hu {
77b167e449SWei Hu 	struct mana_port_context *apc = arg1;
78b167e449SWei Hu 	int offset = arg2, err;
79b167e449SWei Hu 	struct mana_rxq *rxq;
80b167e449SWei Hu 	uint64_t stat;
81b167e449SWei Hu 	uint16_t val;
82b167e449SWei Hu 
83b167e449SWei Hu 	rxq = apc->rxqs[0];
84b167e449SWei Hu 	val = *((uint16_t *)((uint8_t *)rxq + offset));
85b167e449SWei Hu 	stat = val;
86b167e449SWei Hu 
87b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
88b167e449SWei Hu 	if (err || req->newptr == NULL)
89b167e449SWei Hu 		return err;
90b167e449SWei Hu 	else
91b167e449SWei Hu 		return 0;
92b167e449SWei Hu }
93b167e449SWei Hu 
94b167e449SWei Hu static int
mana_sysctl_rx_stat_u32(SYSCTL_HANDLER_ARGS)95b167e449SWei Hu mana_sysctl_rx_stat_u32(SYSCTL_HANDLER_ARGS)
96b167e449SWei Hu {
97b167e449SWei Hu 	struct mana_port_context *apc = arg1;
98b167e449SWei Hu 	int offset = arg2, err;
99b167e449SWei Hu 	struct mana_rxq *rxq;
100b167e449SWei Hu 	uint64_t stat;
101b167e449SWei Hu 	uint32_t val;
102b167e449SWei Hu 
103b167e449SWei Hu 	rxq = apc->rxqs[0];
104b167e449SWei Hu 	val = *((uint32_t *)((uint8_t *)rxq + offset));
105b167e449SWei Hu 	stat = val;
106b167e449SWei Hu 
107b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
108b167e449SWei Hu 	if (err || req->newptr == NULL)
109b167e449SWei Hu 		return err;
110b167e449SWei Hu 	else
111b167e449SWei Hu 		return 0;
112b167e449SWei Hu }
113b167e449SWei Hu 
114b167e449SWei Hu static int
mana_sysctl_tx_stat_agg_u64(SYSCTL_HANDLER_ARGS)115b167e449SWei Hu mana_sysctl_tx_stat_agg_u64(SYSCTL_HANDLER_ARGS)
116b167e449SWei Hu {
117b167e449SWei Hu 	struct mana_port_context *apc = arg1;
118b167e449SWei Hu 	int offset = arg2, i, err;
119b167e449SWei Hu 	struct mana_txq *txq;
120b167e449SWei Hu 	uint64_t stat;
121b167e449SWei Hu 
122b167e449SWei Hu 	stat = 0;
123b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
124b167e449SWei Hu 		txq = &apc->tx_qp[i].txq;
125b167e449SWei Hu 		stat += *((uint64_t *)((uint8_t *)txq + offset));
126b167e449SWei Hu 	}
127b167e449SWei Hu 
128b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
129b167e449SWei Hu 	if (err || req->newptr == NULL)
130b167e449SWei Hu 		return err;
131b167e449SWei Hu 
132b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
133b167e449SWei Hu 		txq = &apc->tx_qp[i].txq;
134b167e449SWei Hu 		*((uint64_t *)((uint8_t *)txq + offset)) = 0;
135b167e449SWei Hu 	}
136b167e449SWei Hu 	return 0;
137b167e449SWei Hu }
138b167e449SWei Hu 
139ce110ea1SWei Hu void
mana_sysctl_add_port(struct mana_port_context * apc)140ce110ea1SWei Hu mana_sysctl_add_port(struct mana_port_context *apc)
141ce110ea1SWei Hu {
142ce110ea1SWei Hu 	struct gdma_context *gc = apc->ac->gdma_dev->gdma_context;
143ce110ea1SWei Hu 	device_t dev = gc->dev;
144ce110ea1SWei Hu 	struct sysctl_ctx_list *ctx;
145ce110ea1SWei Hu 	struct sysctl_oid *tree;
146ce110ea1SWei Hu 	struct sysctl_oid_list *child;
147ce110ea1SWei Hu 	struct mana_port_stats *port_stats;
148ce110ea1SWei Hu 	char node_name[32];
149ce110ea1SWei Hu 
150ce110ea1SWei Hu 	struct sysctl_oid *port_node, *stats_node;
151ce110ea1SWei Hu 	struct sysctl_oid_list *stats_list;
152ce110ea1SWei Hu 
153ce110ea1SWei Hu 	ctx = device_get_sysctl_ctx(dev);
154ce110ea1SWei Hu 	tree = device_get_sysctl_tree(dev);
155ce110ea1SWei Hu 	child = SYSCTL_CHILDREN(tree);
156ce110ea1SWei Hu 
157ce110ea1SWei Hu 	port_stats = &apc->port_stats;
158ce110ea1SWei Hu 
159ce110ea1SWei Hu 	snprintf(node_name, 32, "port%d", apc->port_idx);
160ce110ea1SWei Hu 
161ce110ea1SWei Hu 	port_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO,
162ce110ea1SWei Hu 	    node_name, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Port Name");
163ce110ea1SWei Hu 	apc->port_list = SYSCTL_CHILDREN(port_node);
164ce110ea1SWei Hu 
165ce110ea1SWei Hu 	SYSCTL_ADD_BOOL(ctx, apc->port_list, OID_AUTO,
166ce110ea1SWei Hu 	    "enable_altq", CTLFLAG_RW, &apc->enable_tx_altq, 0,
167ce110ea1SWei Hu 	    "Choose alternative txq under heavy load");
168ce110ea1SWei Hu 
169ce110ea1SWei Hu 	SYSCTL_ADD_PROC(ctx, apc->port_list, OID_AUTO,
170ce110ea1SWei Hu 	    "bind_cleanup_thread_cpu",
171ce110ea1SWei Hu 	    CTLTYPE_U8 | CTLFLAG_RW | CTLFLAG_MPSAFE,
172ce110ea1SWei Hu 	    apc, 0, mana_sysctl_cleanup_thread_cpu, "I",
173ce110ea1SWei Hu 	    "Bind cleanup thread to a cpu. 0 disables it.");
174ce110ea1SWei Hu 
175ce110ea1SWei Hu 	stats_node = SYSCTL_ADD_NODE(ctx, apc->port_list, OID_AUTO,
176ce110ea1SWei Hu 	    "port_stats", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
177ce110ea1SWei Hu 	    "Statistics of port");
178ce110ea1SWei Hu 	stats_list = SYSCTL_CHILDREN(stats_node);
179ce110ea1SWei Hu 
180ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_packets",
181ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_packets, "Packets received");
182ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_packets",
183ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_packets, "Packets transmitted");
184ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_bytes",
185ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_bytes, "Bytes received");
186ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_bytes",
187ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_bytes, "Bytes transmitted");
188ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_drops",
189ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_drops, "Receive packet drops");
190ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_drops",
191ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_drops, "Transmit packet drops");
192b167e449SWei Hu 
193b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_queued",
194b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
195b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_queued),
196b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO queued");
197b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_flushed",
198b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
199b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_flushed),
200b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO flushed");
201b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_bad_csum",
202b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
203b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_bad_csum),
204b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO bad checksum");
205b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_tried",
206b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
207b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro_tried),
208b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO tried");
209b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_failed",
210b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
211b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro_failed),
212b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO failed");
213b167e449SWei Hu 
214b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_ackcnt_lim",
215b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
216b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_ackcnt_lim),
217b167e449SWei Hu 	    mana_sysctl_rx_stat_u16,
218b167e449SWei Hu 	    "LU", "Max # of ACKs to be aggregated by LRO");
219b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_length_lim",
220b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
221b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_length_lim),
222b167e449SWei Hu 	    mana_sysctl_rx_stat_u32,
223b167e449SWei Hu 	    "LU", "Max len of aggregated data in byte by LRO");
224b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_cnt",
225b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
226b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_cnt),
227b167e449SWei Hu 	    mana_sysctl_rx_stat_u32,
228b167e449SWei Hu 	    "LU", "Max # or LRO packet count");
229b167e449SWei Hu 
230b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "tx_tso_packets",
231b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
232b167e449SWei Hu 	    __offsetof(struct mana_txq, tso_pkts),
233b167e449SWei Hu 	    mana_sysctl_tx_stat_agg_u64, "LU", "TSO packets");
234b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "tx_tso_bytes",
235b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
236b167e449SWei Hu 	    __offsetof(struct mana_txq, tso_bytes),
237b167e449SWei Hu 	    mana_sysctl_tx_stat_agg_u64, "LU", "TSO bytes");
238ce110ea1SWei Hu }
239ce110ea1SWei Hu 
240ce110ea1SWei Hu void
mana_sysctl_add_queues(struct mana_port_context * apc)241ce110ea1SWei Hu mana_sysctl_add_queues(struct mana_port_context *apc)
242ce110ea1SWei Hu {
243ce110ea1SWei Hu 	struct sysctl_ctx_list *ctx = &apc->que_sysctl_ctx;
244ce110ea1SWei Hu 	struct sysctl_oid_list *child = apc->port_list;
245ce110ea1SWei Hu 
246ce110ea1SWei Hu 	struct sysctl_oid *queue_node, *tx_node, *rx_node;
247ce110ea1SWei Hu 	struct sysctl_oid_list *queue_list, *tx_list, *rx_list;
248ce110ea1SWei Hu 	struct mana_txq *txq;
249ce110ea1SWei Hu 	struct mana_rxq *rxq;
250ce110ea1SWei Hu 	struct mana_stats *tx_stats, *rx_stats;
251ce110ea1SWei Hu 	char que_name[32];
252ce110ea1SWei Hu 	int i;
253ce110ea1SWei Hu 
254ce110ea1SWei Hu 	sysctl_ctx_init(ctx);
255ce110ea1SWei Hu 
256ce110ea1SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
257ce110ea1SWei Hu 		rxq = apc->rxqs[i];
258ce110ea1SWei Hu 		txq = &apc->tx_qp[i].txq;
259ce110ea1SWei Hu 
260ce110ea1SWei Hu 		snprintf(que_name, 32, "queue%d", i);
261ce110ea1SWei Hu 
262ce110ea1SWei Hu 		queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO,
263ce110ea1SWei Hu 		    que_name, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Queue Name");
264ce110ea1SWei Hu 		queue_list = SYSCTL_CHILDREN(queue_node);
265ce110ea1SWei Hu 
266ce110ea1SWei Hu 		/* TX stats */
267ce110ea1SWei Hu 		tx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
268ce110ea1SWei Hu 		    "txq", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TX queue");
269ce110ea1SWei Hu 		tx_list = SYSCTL_CHILDREN(tx_node);
270ce110ea1SWei Hu 
271ce110ea1SWei Hu 		tx_stats = &txq->stats;
272ce110ea1SWei Hu 
273ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "count",
274ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->packets, "Packets sent");
275ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "bytes",
276ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->bytes, "Bytes sent");
277ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "queue_wakeups",
278ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->wakeup, "Queue wakeups");
279ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "queue_stops",
280ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->stop, "Queue stops");
281ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "mbuf_collapse",
282ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->collapse, "Mbuf collapse count");
283ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
284ce110ea1SWei Hu 		    "mbuf_collapse_err", CTLFLAG_RD,
285ce110ea1SWei Hu 		    &tx_stats->collapse_err, "Mbuf collapse failures");
286ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
287ce110ea1SWei Hu 		    "dma_mapping_err", CTLFLAG_RD,
288ce110ea1SWei Hu 		    &tx_stats->dma_mapping_err, "DMA mapping failures");
289ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
290ce110ea1SWei Hu 		    "alt_chg", CTLFLAG_RD,
291ce110ea1SWei Hu 		    &tx_stats->alt_chg, "Switch to alternative txq");
292ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
293ce110ea1SWei Hu 		    "alt_reset", CTLFLAG_RD,
294ce110ea1SWei Hu 		    &tx_stats->alt_reset, "Reset to self txq");
295516b5059SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
296516b5059SWei Hu 		    "cqe_err", CTLFLAG_RD,
297516b5059SWei Hu 		    &tx_stats->cqe_err, "Error CQE count");
298516b5059SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
299516b5059SWei Hu 		    "cqe_unknown_type", CTLFLAG_RD,
300516b5059SWei Hu 		    &tx_stats->cqe_unknown_type, "Unknown CQE count");
301ce110ea1SWei Hu 
302ce110ea1SWei Hu 		/* RX stats */
303ce110ea1SWei Hu 		rx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
304ce110ea1SWei Hu 		    "rxq", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "RX queue");
305ce110ea1SWei Hu 		rx_list = SYSCTL_CHILDREN(rx_node);
306ce110ea1SWei Hu 
307ce110ea1SWei Hu 		rx_stats = &rxq->stats;
308ce110ea1SWei Hu 
309ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, "count",
310ce110ea1SWei Hu 		    CTLFLAG_RD, &rx_stats->packets, "Packets received");
311ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, "bytes",
312ce110ea1SWei Hu 		    CTLFLAG_RD, &rx_stats->bytes, "Bytes received");
313ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
314ce110ea1SWei Hu 		    "mbuf_alloc_fail", CTLFLAG_RD,
315ce110ea1SWei Hu 		    &rx_stats->mbuf_alloc_fail, "Failed mbuf allocs");
316ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
317ce110ea1SWei Hu 		    "dma_mapping_err", CTLFLAG_RD,
318ce110ea1SWei Hu 		    &rx_stats->dma_mapping_err, "DMA mapping errors");
319ce110ea1SWei Hu 	}
320ce110ea1SWei Hu }
321ce110ea1SWei Hu 
322ce110ea1SWei Hu /*
323ce110ea1SWei Hu  * Free all queues' sysctl trees attached to the port's tree.
324ce110ea1SWei Hu  */
325ce110ea1SWei Hu void
mana_sysctl_free_queues(struct mana_port_context * apc)326ce110ea1SWei Hu mana_sysctl_free_queues(struct mana_port_context *apc)
327ce110ea1SWei Hu {
328ce110ea1SWei Hu 	sysctl_ctx_free(&apc->que_sysctl_ctx);
329ce110ea1SWei Hu }
330ce110ea1SWei Hu 
331ce110ea1SWei Hu static int
mana_sysctl_cleanup_thread_cpu(SYSCTL_HANDLER_ARGS)332ce110ea1SWei Hu mana_sysctl_cleanup_thread_cpu(SYSCTL_HANDLER_ARGS)
333ce110ea1SWei Hu {
334ce110ea1SWei Hu 	struct mana_port_context *apc = arg1;
335ce110ea1SWei Hu 	bool bind_cpu = false;
336ce110ea1SWei Hu 	uint8_t val;
337ce110ea1SWei Hu 	int err;
338ce110ea1SWei Hu 
339ce110ea1SWei Hu 	val = 0;
340ce110ea1SWei Hu 	err = sysctl_wire_old_buffer(req, sizeof(val));
341ce110ea1SWei Hu 	if (err == 0) {
342ce110ea1SWei Hu 		val = apc->bind_cleanup_thread_cpu;
343ce110ea1SWei Hu 		err = sysctl_handle_8(oidp, &val, 0, req);
344ce110ea1SWei Hu 	}
345ce110ea1SWei Hu 
346ce110ea1SWei Hu 	if (err != 0 || req->newptr == NULL)
347ce110ea1SWei Hu 		return (err);
348ce110ea1SWei Hu 
349ce110ea1SWei Hu 	if (val != 0)
350ce110ea1SWei Hu 		bind_cpu = true;
351ce110ea1SWei Hu 
352ce110ea1SWei Hu 	if (bind_cpu != apc->bind_cleanup_thread_cpu) {
353ce110ea1SWei Hu 		apc->bind_cleanup_thread_cpu = bind_cpu;
354ce110ea1SWei Hu 		err = mana_restart(apc);
355ce110ea1SWei Hu 	}
356ce110ea1SWei Hu 
357ce110ea1SWei Hu 	return (err);
358ce110ea1SWei Hu }
359