xref: /freebsd/sys/dev/ena/ena_sysctl.c (revision 4f52dfbb8d6c4d446500c5b097e3806ec219fbd4)
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright (c) 2015-2017 Amazon.com, Inc. or its affiliates.
5  * All rights reserved.
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  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 #include "ena_sysctl.h"
34 
35 static void	ena_sysctl_add_wd(struct ena_adapter *);
36 static void	ena_sysctl_add_stats(struct ena_adapter *);
37 
38 void
39 ena_sysctl_add_nodes(struct ena_adapter *adapter)
40 {
41 	ena_sysctl_add_wd(adapter);
42 	ena_sysctl_add_stats(adapter);
43 }
44 
45 static void
46 ena_sysctl_add_wd(struct ena_adapter *adapter)
47 {
48 	device_t dev;
49 
50 	struct sysctl_ctx_list *ctx;
51 	struct sysctl_oid *tree;
52 	struct sysctl_oid_list *child;
53 
54 	dev = adapter->pdev;
55 
56 	ctx = device_get_sysctl_ctx(dev);
57 	tree = device_get_sysctl_tree(dev);
58 	child = SYSCTL_CHILDREN(tree);
59 
60 	/* Sysctl calls for Watchdog service */
61 	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "wd_active",
62 	    CTLFLAG_RWTUN, &adapter->wd_active, 0,
63 	    "Watchdog is active");
64 
65 	SYSCTL_ADD_QUAD(ctx, child, OID_AUTO, "keep_alive_timeout",
66 	    CTLFLAG_RWTUN, &adapter->keep_alive_timeout,
67 	    "Timeout for Keep Alive messages");
68 
69 	SYSCTL_ADD_QUAD(ctx, child, OID_AUTO, "missing_tx_timeout",
70 	    CTLFLAG_RWTUN, &adapter->missing_tx_timeout,
71 	    "Timeout for TX completion");
72 
73 	SYSCTL_ADD_U32(ctx, child, OID_AUTO, "missing_tx_max_queues",
74 	    CTLFLAG_RWTUN, &adapter->missing_tx_max_queues, 0,
75 	    "Number of TX queues to check per run");
76 
77 	SYSCTL_ADD_U32(ctx, child, OID_AUTO, "missing_tx_threshold",
78 	    CTLFLAG_RWTUN, &adapter->missing_tx_threshold, 0,
79 	    "Max number of timeouted packets");
80 }
81 
82 static void
83 ena_sysctl_add_stats(struct ena_adapter *adapter)
84 {
85 	device_t dev;
86 
87 	struct ena_ring *tx_ring;
88 	struct ena_ring *rx_ring;
89 
90 	struct ena_hw_stats *hw_stats;
91 	struct ena_stats_dev *dev_stats;
92 	struct ena_stats_tx *tx_stats;
93 	struct ena_stats_rx *rx_stats;
94 	struct ena_com_stats_admin *admin_stats;
95 
96 	struct sysctl_ctx_list *ctx;
97 	struct sysctl_oid *tree;
98 	struct sysctl_oid_list *child;
99 
100 	struct sysctl_oid *queue_node, *tx_node, *rx_node, *hw_node;
101 	struct sysctl_oid *admin_node;
102 	struct sysctl_oid_list *queue_list, *tx_list, *rx_list, *hw_list;
103 	struct sysctl_oid_list *admin_list;
104 
105 #define QUEUE_NAME_LEN 32
106 	char namebuf[QUEUE_NAME_LEN];
107 	int i;
108 
109 	dev = adapter->pdev;
110 
111 	ctx = device_get_sysctl_ctx(dev);
112 	tree = device_get_sysctl_tree(dev);
113 	child = SYSCTL_CHILDREN(tree);
114 
115 	tx_ring = adapter->tx_ring;
116 	rx_ring = adapter->rx_ring;
117 
118 	hw_stats = &adapter->hw_stats;
119 	dev_stats = &adapter->dev_stats;
120 	admin_stats = &adapter->ena_dev->admin_queue.stats;
121 
122 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "wd_expired",
123 	    CTLFLAG_RD, &dev_stats->wd_expired,
124 	    "Watchdog expiry count");
125 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_up",
126 	    CTLFLAG_RD, &dev_stats->interface_up,
127 	    "Network interface up count");
128 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_down",
129 	    CTLFLAG_RD, &dev_stats->interface_down,
130 	    "Network interface down count");
131 	SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "admin_q_pause",
132 	    CTLFLAG_RD, &dev_stats->admin_q_pause,
133 	    "Admin queue pauses");
134 
135 	for (i = 0; i < adapter->num_queues; ++i, ++tx_ring, ++rx_ring) {
136 		snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i);
137 
138 		queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO,
139 		    namebuf, CTLFLAG_RD, NULL, "Queue Name");
140 		queue_list = SYSCTL_CHILDREN(queue_node);
141 
142 		/* TX specific stats */
143 		tx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
144 		    "tx_ring", CTLFLAG_RD, NULL, "TX ring");
145 		tx_list = SYSCTL_CHILDREN(tx_node);
146 
147 		tx_stats = &tx_ring->tx_stats;
148 
149 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
150 		    "count", CTLFLAG_RD,
151 		    &tx_stats->cnt, "Packets sent");
152 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
153 		    "bytes", CTLFLAG_RD,
154 		    &tx_stats->bytes, "Bytes sent");
155 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
156 		    "prepare_ctx_err", CTLFLAG_RD,
157 		    &tx_stats->prepare_ctx_err,
158 		    "TX buffer preparation failures");
159 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
160 		    "dma_mapping_err", CTLFLAG_RD,
161 		    &tx_stats->dma_mapping_err, "DMA mapping failures");
162 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
163 		    "doorbells", CTLFLAG_RD,
164 		    &tx_stats->doorbells, "Queue doorbells");
165 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
166 		    "missing_tx_comp", CTLFLAG_RD,
167 		    &tx_stats->missing_tx_comp, "TX completions missed");
168 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
169 		    "bad_req_id", CTLFLAG_RD,
170 		    &tx_stats->bad_req_id, "Bad request id count");
171 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
172 		        "mbuf_collapses", CTLFLAG_RD,
173 		        &tx_stats->collapse,
174 		        "Mbuf collapse count");
175 		SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO,
176 		        "mbuf_collapse_err", CTLFLAG_RD,
177 		        &tx_stats->collapse_err,
178 		        "Mbuf collapse failures");
179 
180 		/* RX specific stats */
181 		rx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO,
182 		    "rx_ring", CTLFLAG_RD, NULL, "RX ring");
183 		rx_list = SYSCTL_CHILDREN(rx_node);
184 
185 		rx_stats = &rx_ring->rx_stats;
186 
187 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
188 		    "count", CTLFLAG_RD,
189 		    &rx_stats->cnt, "Packets received");
190 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
191 		    "bytes", CTLFLAG_RD,
192 		    &rx_stats->bytes, "Bytes received");
193 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
194 		    "refil_partial", CTLFLAG_RD,
195 		    &rx_stats->refil_partial, "Partial refilled mbufs");
196 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
197 		    "bad_csum", CTLFLAG_RD,
198 		    &rx_stats->bad_csum, "Bad RX checksum");
199 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
200 		    "mbuf_alloc_fail", CTLFLAG_RD,
201 		    &rx_stats->mbuf_alloc_fail, "Failed mbuf allocs");
202 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
203 		    "mjum_alloc_fail", CTLFLAG_RD,
204 		    &rx_stats->mjum_alloc_fail, "Failed jumbo mbuf allocs");
205 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
206 		    "dma_mapping_err", CTLFLAG_RD,
207 		    &rx_stats->dma_mapping_err, "DMA mapping errors");
208 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
209 		    "bad_desc_num", CTLFLAG_RD,
210 		    &rx_stats->bad_desc_num, "Bad descriptor count");
211 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
212 		    "bad_req_id", CTLFLAG_RD,
213 		    &rx_stats->bad_req_id, "Bad request id count");
214 		SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO,
215 		    "empty_rx_ring", CTLFLAG_RD,
216 		    &rx_stats->empty_rx_ring, "RX descriptors depletion count");
217 	}
218 
219 	/* Stats read from device */
220 	hw_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hw_stats",
221 	    CTLFLAG_RD, NULL, "Statistics from hardware");
222 	hw_list = SYSCTL_CHILDREN(hw_node);
223 
224 	SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_packets", CTLFLAG_RD,
225 	    &hw_stats->rx_packets, "Packets received");
226 	SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "tx_packets", CTLFLAG_RD,
227 	    &hw_stats->tx_packets, "Packets transmitted");
228 	SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_bytes", CTLFLAG_RD,
229 	    &hw_stats->rx_bytes, "Bytes received");
230 	SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "tx_bytes", CTLFLAG_RD,
231 	    &hw_stats->tx_bytes, "Bytes transmitted");
232 	SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_drops", CTLFLAG_RD,
233 	    &hw_stats->rx_drops, "Receive packet drops");
234 
235 	/* ENA Admin queue stats */
236 	admin_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "admin_stats",
237 	    CTLFLAG_RD, NULL, "ENA Admin Queue statistics");
238 	admin_list = SYSCTL_CHILDREN(admin_node);
239 
240 	SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "aborted_cmd", CTLFLAG_RD,
241 	    &admin_stats->aborted_cmd, 0, "Aborted commands");
242 	SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "sumbitted_cmd", CTLFLAG_RD,
243 	    &admin_stats->submitted_cmd, 0, "Submitted commands");
244 	SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "completed_cmd", CTLFLAG_RD,
245 	    &admin_stats->completed_cmd, 0, "Completed commands");
246 	SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "out_of_space", CTLFLAG_RD,
247 	    &admin_stats->out_of_space, 0, "Queue out of space");
248 	SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "no_completion", CTLFLAG_RD,
249 	    &admin_stats->no_completion, 0, "Commands not completed");
250 }
251 
252