xref: /freebsd/sys/dev/mana/mana_sysctl.c (revision 9b8701b81f14f0fa0787425eb9761b765d5faab0)
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 
37a18e9994SWei Hu unsigned int mana_tx_req_size;
38a18e9994SWei Hu unsigned int mana_rx_req_size;
39*9b8701b8SWei Hu unsigned int mana_rx_refill_threshold;
40a18e9994SWei Hu 
41ce110ea1SWei Hu SYSCTL_NODE(_hw, OID_AUTO, mana, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
42ce110ea1SWei Hu     "MANA driver parameters");
43ce110ea1SWei Hu 
44a18e9994SWei Hu SYSCTL_UINT(_hw_mana, OID_AUTO, tx_req_size, CTLFLAG_RWTUN,
45a18e9994SWei Hu     &mana_tx_req_size, 0, "requested number of unit of tx queue");
46a18e9994SWei Hu SYSCTL_UINT(_hw_mana, OID_AUTO, rx_req_size, CTLFLAG_RWTUN,
47a18e9994SWei Hu     &mana_rx_req_size, 0, "requested number of unit of rx queue");
48*9b8701b8SWei Hu SYSCTL_UINT(_hw_mana, OID_AUTO, rx_refill_thresh, CTLFLAG_RWTUN,
49*9b8701b8SWei Hu     &mana_rx_refill_threshold, 0,
50*9b8701b8SWei Hu     "number of rx slots before starting the refill");
51a18e9994SWei Hu 
52ce110ea1SWei Hu /*
53ce110ea1SWei Hu  * Logging level for changing verbosity of the output
54ce110ea1SWei Hu  */
55ce110ea1SWei Hu SYSCTL_INT(_hw_mana, OID_AUTO, log_level, CTLFLAG_RWTUN,
56ce110ea1SWei Hu     &mana_log_level, 0, "Logging level indicating verbosity of the logs");
57ce110ea1SWei Hu 
58ce110ea1SWei Hu SYSCTL_CONST_STRING(_hw_mana, OID_AUTO, driver_version, CTLFLAG_RD,
59ce110ea1SWei Hu     DRV_MODULE_VERSION, "MANA driver version");
60ce110ea1SWei Hu 
61b167e449SWei Hu static int
mana_sysctl_rx_stat_agg_u64(SYSCTL_HANDLER_ARGS)62b167e449SWei Hu mana_sysctl_rx_stat_agg_u64(SYSCTL_HANDLER_ARGS)
63b167e449SWei Hu {
64b167e449SWei Hu 	struct mana_port_context *apc = arg1;
65b167e449SWei Hu 	int offset = arg2, i, err;
66b167e449SWei Hu 	struct mana_rxq *rxq;
67b167e449SWei Hu 	uint64_t stat;
68b167e449SWei Hu 
69b167e449SWei Hu 	stat = 0;
70b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
71b167e449SWei Hu 		rxq = apc->rxqs[i];
72b167e449SWei Hu 		stat += *((uint64_t *)((uint8_t *)rxq + offset));
73b167e449SWei Hu 	}
74b167e449SWei Hu 
75b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
76b167e449SWei Hu 	if (err || req->newptr == NULL)
77b167e449SWei Hu 		return err;
78b167e449SWei Hu 
79b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
80b167e449SWei Hu 		rxq = apc->rxqs[i];
81b167e449SWei Hu 		*((uint64_t *)((uint8_t *)rxq + offset)) = 0;
82b167e449SWei Hu 	}
83b167e449SWei Hu 	return 0;
84b167e449SWei Hu }
85b167e449SWei Hu 
86b167e449SWei Hu static int
mana_sysctl_rx_stat_u16(SYSCTL_HANDLER_ARGS)87b167e449SWei Hu mana_sysctl_rx_stat_u16(SYSCTL_HANDLER_ARGS)
88b167e449SWei Hu {
89b167e449SWei Hu 	struct mana_port_context *apc = arg1;
90b167e449SWei Hu 	int offset = arg2, err;
91b167e449SWei Hu 	struct mana_rxq *rxq;
92b167e449SWei Hu 	uint64_t stat;
93b167e449SWei Hu 	uint16_t val;
94b167e449SWei Hu 
95b167e449SWei Hu 	rxq = apc->rxqs[0];
96b167e449SWei Hu 	val = *((uint16_t *)((uint8_t *)rxq + offset));
97b167e449SWei Hu 	stat = val;
98b167e449SWei Hu 
99b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
100b167e449SWei Hu 	if (err || req->newptr == NULL)
101b167e449SWei Hu 		return err;
102b167e449SWei Hu 	else
103b167e449SWei Hu 		return 0;
104b167e449SWei Hu }
105b167e449SWei Hu 
106b167e449SWei Hu static int
mana_sysctl_rx_stat_u32(SYSCTL_HANDLER_ARGS)107b167e449SWei Hu mana_sysctl_rx_stat_u32(SYSCTL_HANDLER_ARGS)
108b167e449SWei Hu {
109b167e449SWei Hu 	struct mana_port_context *apc = arg1;
110b167e449SWei Hu 	int offset = arg2, err;
111b167e449SWei Hu 	struct mana_rxq *rxq;
112b167e449SWei Hu 	uint64_t stat;
113b167e449SWei Hu 	uint32_t val;
114b167e449SWei Hu 
115b167e449SWei Hu 	rxq = apc->rxqs[0];
116b167e449SWei Hu 	val = *((uint32_t *)((uint8_t *)rxq + offset));
117b167e449SWei Hu 	stat = val;
118b167e449SWei Hu 
119b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
120b167e449SWei Hu 	if (err || req->newptr == NULL)
121b167e449SWei Hu 		return err;
122b167e449SWei Hu 	else
123b167e449SWei Hu 		return 0;
124b167e449SWei Hu }
125b167e449SWei Hu 
126b167e449SWei Hu static int
mana_sysctl_tx_stat_agg_u64(SYSCTL_HANDLER_ARGS)127b167e449SWei Hu mana_sysctl_tx_stat_agg_u64(SYSCTL_HANDLER_ARGS)
128b167e449SWei Hu {
129b167e449SWei Hu 	struct mana_port_context *apc = arg1;
130b167e449SWei Hu 	int offset = arg2, i, err;
131b167e449SWei Hu 	struct mana_txq *txq;
132b167e449SWei Hu 	uint64_t stat;
133b167e449SWei Hu 
134b167e449SWei Hu 	stat = 0;
135b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
136b167e449SWei Hu 		txq = &apc->tx_qp[i].txq;
137b167e449SWei Hu 		stat += *((uint64_t *)((uint8_t *)txq + offset));
138b167e449SWei Hu 	}
139b167e449SWei Hu 
140b167e449SWei Hu 	err = sysctl_handle_64(oidp, &stat, 0, req);
141b167e449SWei Hu 	if (err || req->newptr == NULL)
142b167e449SWei Hu 		return err;
143b167e449SWei Hu 
144b167e449SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
145b167e449SWei Hu 		txq = &apc->tx_qp[i].txq;
146b167e449SWei Hu 		*((uint64_t *)((uint8_t *)txq + offset)) = 0;
147b167e449SWei Hu 	}
148b167e449SWei Hu 	return 0;
149b167e449SWei Hu }
150b167e449SWei Hu 
151ce110ea1SWei Hu void
mana_sysctl_add_port(struct mana_port_context * apc)152ce110ea1SWei Hu mana_sysctl_add_port(struct mana_port_context *apc)
153ce110ea1SWei Hu {
154ce110ea1SWei Hu 	struct gdma_context *gc = apc->ac->gdma_dev->gdma_context;
155ce110ea1SWei Hu 	device_t dev = gc->dev;
156ce110ea1SWei Hu 	struct sysctl_ctx_list *ctx;
157ce110ea1SWei Hu 	struct sysctl_oid *tree;
158ce110ea1SWei Hu 	struct sysctl_oid_list *child;
159ce110ea1SWei Hu 	struct mana_port_stats *port_stats;
160ce110ea1SWei Hu 	char node_name[32];
161ce110ea1SWei Hu 
162ce110ea1SWei Hu 	struct sysctl_oid *port_node, *stats_node;
163ce110ea1SWei Hu 	struct sysctl_oid_list *stats_list;
164ce110ea1SWei Hu 
165ce110ea1SWei Hu 	ctx = device_get_sysctl_ctx(dev);
166ce110ea1SWei Hu 	tree = device_get_sysctl_tree(dev);
167ce110ea1SWei Hu 	child = SYSCTL_CHILDREN(tree);
168ce110ea1SWei Hu 
169ce110ea1SWei Hu 	port_stats = &apc->port_stats;
170ce110ea1SWei Hu 
171ce110ea1SWei Hu 	snprintf(node_name, 32, "port%d", apc->port_idx);
172ce110ea1SWei Hu 
173ce110ea1SWei Hu 	port_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO,
174ce110ea1SWei Hu 	    node_name, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Port Name");
175ce110ea1SWei Hu 	apc->port_list = SYSCTL_CHILDREN(port_node);
176ce110ea1SWei Hu 
177ce110ea1SWei Hu 	SYSCTL_ADD_BOOL(ctx, apc->port_list, OID_AUTO,
178ce110ea1SWei Hu 	    "enable_altq", CTLFLAG_RW, &apc->enable_tx_altq, 0,
179ce110ea1SWei Hu 	    "Choose alternative txq under heavy load");
180ce110ea1SWei Hu 
181a18e9994SWei Hu 	SYSCTL_ADD_UINT(ctx, apc->port_list, OID_AUTO,
182a18e9994SWei Hu 	    "tx_queue_size", CTLFLAG_RD, &apc->tx_queue_size, 0,
183a18e9994SWei Hu 	    "number of unit of tx queue");
184a18e9994SWei Hu 
185a18e9994SWei Hu 	SYSCTL_ADD_UINT(ctx, apc->port_list, OID_AUTO,
186a18e9994SWei Hu 	    "rx_queue_size", CTLFLAG_RD, &apc->rx_queue_size, 0,
187a18e9994SWei Hu 	    "number of unit of rx queue");
188a18e9994SWei Hu 
189ce110ea1SWei Hu 	SYSCTL_ADD_PROC(ctx, apc->port_list, OID_AUTO,
190ce110ea1SWei Hu 	    "bind_cleanup_thread_cpu",
191ce110ea1SWei Hu 	    CTLTYPE_U8 | CTLFLAG_RW | CTLFLAG_MPSAFE,
192ce110ea1SWei Hu 	    apc, 0, mana_sysctl_cleanup_thread_cpu, "I",
193ce110ea1SWei Hu 	    "Bind cleanup thread to a cpu. 0 disables it.");
194ce110ea1SWei Hu 
195ce110ea1SWei Hu 	stats_node = SYSCTL_ADD_NODE(ctx, apc->port_list, OID_AUTO,
196ce110ea1SWei Hu 	    "port_stats", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
197ce110ea1SWei Hu 	    "Statistics of port");
198ce110ea1SWei Hu 	stats_list = SYSCTL_CHILDREN(stats_node);
199ce110ea1SWei Hu 
200ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_packets",
201ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_packets, "Packets received");
202ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_packets",
203ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_packets, "Packets transmitted");
204ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_bytes",
205ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_bytes, "Bytes received");
206ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_bytes",
207ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_bytes, "Bytes transmitted");
208ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "rx_drops",
209ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->rx_drops, "Receive packet drops");
210ce110ea1SWei Hu 	SYSCTL_ADD_COUNTER_U64(ctx, stats_list, OID_AUTO, "tx_drops",
211ce110ea1SWei Hu 	    CTLFLAG_RD, &port_stats->tx_drops, "Transmit packet drops");
212b167e449SWei Hu 
213b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_queued",
214b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
215b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_queued),
216b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO queued");
217b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_flushed",
218b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
219b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_flushed),
220b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO flushed");
221b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_bad_csum",
222b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_STATS, apc,
223b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_bad_csum),
224b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO bad checksum");
225b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_tried",
226b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
227b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro_tried),
228b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO tried");
229b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "rx_lro_failed",
230b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
231b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro_failed),
232b167e449SWei Hu 	    mana_sysctl_rx_stat_agg_u64, "LU", "LRO failed");
233b167e449SWei Hu 
234b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_ackcnt_lim",
235b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
236b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_ackcnt_lim),
237b167e449SWei Hu 	    mana_sysctl_rx_stat_u16,
238b167e449SWei Hu 	    "LU", "Max # of ACKs to be aggregated by LRO");
239b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_length_lim",
240b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
241b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_length_lim),
242b167e449SWei Hu 	    mana_sysctl_rx_stat_u32,
243b167e449SWei Hu 	    "LU", "Max len of aggregated data in byte by LRO");
244b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "lro_cnt",
245b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
246b167e449SWei Hu 	    __offsetof(struct mana_rxq, lro.lro_cnt),
247b167e449SWei Hu 	    mana_sysctl_rx_stat_u32,
248b167e449SWei Hu 	    "LU", "Max # or LRO packet count");
249b167e449SWei Hu 
250b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "tx_tso_packets",
251b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
252b167e449SWei Hu 	    __offsetof(struct mana_txq, tso_pkts),
253b167e449SWei Hu 	    mana_sysctl_tx_stat_agg_u64, "LU", "TSO packets");
254b167e449SWei Hu 	SYSCTL_ADD_PROC(ctx, stats_list, OID_AUTO, "tx_tso_bytes",
255b167e449SWei Hu 	    CTLTYPE_U64 | CTLFLAG_RD | CTLFLAG_STATS, apc,
256b167e449SWei Hu 	    __offsetof(struct mana_txq, tso_bytes),
257b167e449SWei Hu 	    mana_sysctl_tx_stat_agg_u64, "LU", "TSO bytes");
258ce110ea1SWei Hu }
259ce110ea1SWei Hu 
260ce110ea1SWei Hu void
mana_sysctl_add_queues(struct mana_port_context * apc)261ce110ea1SWei Hu mana_sysctl_add_queues(struct mana_port_context *apc)
262ce110ea1SWei Hu {
263ce110ea1SWei Hu 	struct sysctl_ctx_list *ctx = &apc->que_sysctl_ctx;
264ce110ea1SWei Hu 	struct sysctl_oid_list *child = apc->port_list;
265ce110ea1SWei Hu 
266ce110ea1SWei Hu 	struct sysctl_oid *queue_node, *tx_node, *rx_node;
267ce110ea1SWei Hu 	struct sysctl_oid_list *queue_list, *tx_list, *rx_list;
268ce110ea1SWei Hu 	struct mana_txq *txq;
269ce110ea1SWei Hu 	struct mana_rxq *rxq;
270ce110ea1SWei Hu 	struct mana_stats *tx_stats, *rx_stats;
271ce110ea1SWei Hu 	char que_name[32];
272ce110ea1SWei Hu 	int i;
273ce110ea1SWei Hu 
274ce110ea1SWei Hu 	sysctl_ctx_init(ctx);
275ce110ea1SWei Hu 
276ce110ea1SWei Hu 	for (i = 0; i < apc->num_queues; i++) {
277ce110ea1SWei Hu 		rxq = apc->rxqs[i];
278ce110ea1SWei Hu 		txq = &apc->tx_qp[i].txq;
279ce110ea1SWei Hu 
280ce110ea1SWei Hu 		snprintf(que_name, 32, "queue%d", i);
281ce110ea1SWei Hu 
282ce110ea1SWei Hu 		queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO,
283ce110ea1SWei Hu 		    que_name, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Queue Name");
284ce110ea1SWei Hu 		queue_list = SYSCTL_CHILDREN(queue_node);
285ce110ea1SWei Hu 
286ce110ea1SWei Hu 		/* TX stats */
287ce110ea1SWei Hu 		tx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
288ce110ea1SWei Hu 		    "txq", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TX queue");
289ce110ea1SWei Hu 		tx_list = SYSCTL_CHILDREN(tx_node);
290ce110ea1SWei Hu 
291ce110ea1SWei Hu 		tx_stats = &txq->stats;
292ce110ea1SWei Hu 
293ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "count",
294ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->packets, "Packets sent");
295ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "bytes",
296ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->bytes, "Bytes sent");
297ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "queue_wakeups",
298ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->wakeup, "Queue wakeups");
299ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "queue_stops",
300ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->stop, "Queue stops");
301ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, "mbuf_collapse",
302ce110ea1SWei Hu 		    CTLFLAG_RD, &tx_stats->collapse, "Mbuf collapse count");
303ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
304ce110ea1SWei Hu 		    "mbuf_collapse_err", CTLFLAG_RD,
305ce110ea1SWei Hu 		    &tx_stats->collapse_err, "Mbuf collapse failures");
306ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
307ce110ea1SWei Hu 		    "dma_mapping_err", CTLFLAG_RD,
308ce110ea1SWei Hu 		    &tx_stats->dma_mapping_err, "DMA mapping failures");
309ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
310ce110ea1SWei Hu 		    "alt_chg", CTLFLAG_RD,
311ce110ea1SWei Hu 		    &tx_stats->alt_chg, "Switch to alternative txq");
312ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
313ce110ea1SWei Hu 		    "alt_reset", CTLFLAG_RD,
314ce110ea1SWei Hu 		    &tx_stats->alt_reset, "Reset to self txq");
315516b5059SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
316516b5059SWei Hu 		    "cqe_err", CTLFLAG_RD,
317516b5059SWei Hu 		    &tx_stats->cqe_err, "Error CQE count");
318516b5059SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
319516b5059SWei Hu 		    "cqe_unknown_type", CTLFLAG_RD,
320516b5059SWei Hu 		    &tx_stats->cqe_unknown_type, "Unknown CQE count");
321ce110ea1SWei Hu 
322ce110ea1SWei Hu 		/* RX stats */
323ce110ea1SWei Hu 		rx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
324ce110ea1SWei Hu 		    "rxq", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "RX queue");
325ce110ea1SWei Hu 		rx_list = SYSCTL_CHILDREN(rx_node);
326ce110ea1SWei Hu 
327ce110ea1SWei Hu 		rx_stats = &rxq->stats;
328ce110ea1SWei Hu 
329ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, "count",
330ce110ea1SWei Hu 		    CTLFLAG_RD, &rx_stats->packets, "Packets received");
331ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, "bytes",
332ce110ea1SWei Hu 		    CTLFLAG_RD, &rx_stats->bytes, "Bytes received");
333ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
334ce110ea1SWei Hu 		    "mbuf_alloc_fail", CTLFLAG_RD,
335ce110ea1SWei Hu 		    &rx_stats->mbuf_alloc_fail, "Failed mbuf allocs");
336ce110ea1SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
337*9b8701b8SWei Hu 		    "partial_refill", CTLFLAG_RD,
338*9b8701b8SWei Hu 		    &rx_stats->partial_refill, "Partially refilled mbuf");
339*9b8701b8SWei Hu 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
340ce110ea1SWei Hu 		    "dma_mapping_err", CTLFLAG_RD,
341ce110ea1SWei Hu 		    &rx_stats->dma_mapping_err, "DMA mapping errors");
342ce110ea1SWei Hu 	}
343ce110ea1SWei Hu }
344ce110ea1SWei Hu 
345ce110ea1SWei Hu /*
346ce110ea1SWei Hu  * Free all queues' sysctl trees attached to the port's tree.
347ce110ea1SWei Hu  */
348ce110ea1SWei Hu void
mana_sysctl_free_queues(struct mana_port_context * apc)349ce110ea1SWei Hu mana_sysctl_free_queues(struct mana_port_context *apc)
350ce110ea1SWei Hu {
351ce110ea1SWei Hu 	sysctl_ctx_free(&apc->que_sysctl_ctx);
352ce110ea1SWei Hu }
353ce110ea1SWei Hu 
354ce110ea1SWei Hu static int
mana_sysctl_cleanup_thread_cpu(SYSCTL_HANDLER_ARGS)355ce110ea1SWei Hu mana_sysctl_cleanup_thread_cpu(SYSCTL_HANDLER_ARGS)
356ce110ea1SWei Hu {
357ce110ea1SWei Hu 	struct mana_port_context *apc = arg1;
358ce110ea1SWei Hu 	bool bind_cpu = false;
359ce110ea1SWei Hu 	uint8_t val;
360ce110ea1SWei Hu 	int err;
361ce110ea1SWei Hu 
362ce110ea1SWei Hu 	val = 0;
363ce110ea1SWei Hu 	err = sysctl_wire_old_buffer(req, sizeof(val));
364ce110ea1SWei Hu 	if (err == 0) {
365ce110ea1SWei Hu 		val = apc->bind_cleanup_thread_cpu;
366ce110ea1SWei Hu 		err = sysctl_handle_8(oidp, &val, 0, req);
367ce110ea1SWei Hu 	}
368ce110ea1SWei Hu 
369ce110ea1SWei Hu 	if (err != 0 || req->newptr == NULL)
370ce110ea1SWei Hu 		return (err);
371ce110ea1SWei Hu 
372ce110ea1SWei Hu 	if (val != 0)
373ce110ea1SWei Hu 		bind_cpu = true;
374ce110ea1SWei Hu 
375ce110ea1SWei Hu 	if (bind_cpu != apc->bind_cleanup_thread_cpu) {
376ce110ea1SWei Hu 		apc->bind_cleanup_thread_cpu = bind_cpu;
377ce110ea1SWei Hu 		err = mana_restart(apc);
378ce110ea1SWei Hu 	}
379ce110ea1SWei Hu 
380ce110ea1SWei Hu 	return (err);
381ce110ea1SWei Hu }
382