1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) 2015-2019 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 static void ena_sysctl_add_tuneables(struct ena_adapter *); 38 static int ena_sysctl_buf_ring_size(SYSCTL_HANDLER_ARGS); 39 static int ena_sysctl_rx_queue_size(SYSCTL_HANDLER_ARGS); 40 41 static SYSCTL_NODE(_hw, OID_AUTO, ena, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 42 "ENA driver parameters"); 43 44 /* 45 * Logging level for changing verbosity of the output 46 */ 47 int ena_log_level = ENA_ALERT | ENA_WARNING; 48 SYSCTL_INT(_hw_ena, OID_AUTO, log_level, CTLFLAG_RWTUN, 49 &ena_log_level, 0, "Logging level indicating verbosity of the logs"); 50 51 52 void 53 ena_sysctl_add_nodes(struct ena_adapter *adapter) 54 { 55 ena_sysctl_add_wd(adapter); 56 ena_sysctl_add_stats(adapter); 57 ena_sysctl_add_tuneables(adapter); 58 } 59 60 static void 61 ena_sysctl_add_wd(struct ena_adapter *adapter) 62 { 63 device_t dev; 64 65 struct sysctl_ctx_list *ctx; 66 struct sysctl_oid *tree; 67 struct sysctl_oid_list *child; 68 69 dev = adapter->pdev; 70 71 ctx = device_get_sysctl_ctx(dev); 72 tree = device_get_sysctl_tree(dev); 73 child = SYSCTL_CHILDREN(tree); 74 75 /* Sysctl calls for Watchdog service */ 76 SYSCTL_ADD_INT(ctx, child, OID_AUTO, "wd_active", 77 CTLFLAG_RWTUN, &adapter->wd_active, 0, 78 "Watchdog is active"); 79 80 SYSCTL_ADD_QUAD(ctx, child, OID_AUTO, "keep_alive_timeout", 81 CTLFLAG_RWTUN, &adapter->keep_alive_timeout, 82 "Timeout for Keep Alive messages"); 83 84 SYSCTL_ADD_QUAD(ctx, child, OID_AUTO, "missing_tx_timeout", 85 CTLFLAG_RWTUN, &adapter->missing_tx_timeout, 86 "Timeout for TX completion"); 87 88 SYSCTL_ADD_U32(ctx, child, OID_AUTO, "missing_tx_max_queues", 89 CTLFLAG_RWTUN, &adapter->missing_tx_max_queues, 0, 90 "Number of TX queues to check per run"); 91 92 SYSCTL_ADD_U32(ctx, child, OID_AUTO, "missing_tx_threshold", 93 CTLFLAG_RWTUN, &adapter->missing_tx_threshold, 0, 94 "Max number of timeouted packets"); 95 } 96 97 static void 98 ena_sysctl_add_stats(struct ena_adapter *adapter) 99 { 100 device_t dev; 101 102 struct ena_ring *tx_ring; 103 struct ena_ring *rx_ring; 104 105 struct ena_hw_stats *hw_stats; 106 struct ena_stats_dev *dev_stats; 107 struct ena_stats_tx *tx_stats; 108 struct ena_stats_rx *rx_stats; 109 struct ena_com_stats_admin *admin_stats; 110 111 struct sysctl_ctx_list *ctx; 112 struct sysctl_oid *tree; 113 struct sysctl_oid_list *child; 114 115 struct sysctl_oid *queue_node, *tx_node, *rx_node, *hw_node; 116 struct sysctl_oid *admin_node; 117 struct sysctl_oid_list *queue_list, *tx_list, *rx_list, *hw_list; 118 struct sysctl_oid_list *admin_list; 119 120 #define QUEUE_NAME_LEN 32 121 char namebuf[QUEUE_NAME_LEN]; 122 int i; 123 124 dev = adapter->pdev; 125 126 ctx = device_get_sysctl_ctx(dev); 127 tree = device_get_sysctl_tree(dev); 128 child = SYSCTL_CHILDREN(tree); 129 130 tx_ring = adapter->tx_ring; 131 rx_ring = adapter->rx_ring; 132 133 hw_stats = &adapter->hw_stats; 134 dev_stats = &adapter->dev_stats; 135 admin_stats = &adapter->ena_dev->admin_queue.stats; 136 137 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "wd_expired", 138 CTLFLAG_RD, &dev_stats->wd_expired, 139 "Watchdog expiry count"); 140 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_up", 141 CTLFLAG_RD, &dev_stats->interface_up, 142 "Network interface up count"); 143 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_down", 144 CTLFLAG_RD, &dev_stats->interface_down, 145 "Network interface down count"); 146 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "admin_q_pause", 147 CTLFLAG_RD, &dev_stats->admin_q_pause, 148 "Admin queue pauses"); 149 150 for (i = 0; i < adapter->num_queues; ++i, ++tx_ring, ++rx_ring) { 151 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i); 152 153 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, 154 namebuf, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Queue Name"); 155 queue_list = SYSCTL_CHILDREN(queue_node); 156 157 /* TX specific stats */ 158 tx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO, 159 "tx_ring", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "TX ring"); 160 tx_list = SYSCTL_CHILDREN(tx_node); 161 162 tx_stats = &tx_ring->tx_stats; 163 164 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 165 "count", CTLFLAG_RD, 166 &tx_stats->cnt, "Packets sent"); 167 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 168 "bytes", CTLFLAG_RD, 169 &tx_stats->bytes, "Bytes sent"); 170 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 171 "prepare_ctx_err", CTLFLAG_RD, 172 &tx_stats->prepare_ctx_err, 173 "TX buffer preparation failures"); 174 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 175 "dma_mapping_err", CTLFLAG_RD, 176 &tx_stats->dma_mapping_err, "DMA mapping failures"); 177 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 178 "doorbells", CTLFLAG_RD, 179 &tx_stats->doorbells, "Queue doorbells"); 180 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 181 "missing_tx_comp", CTLFLAG_RD, 182 &tx_stats->missing_tx_comp, "TX completions missed"); 183 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 184 "bad_req_id", CTLFLAG_RD, 185 &tx_stats->bad_req_id, "Bad request id count"); 186 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 187 "mbuf_collapses", CTLFLAG_RD, 188 &tx_stats->collapse, 189 "Mbuf collapse count"); 190 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 191 "mbuf_collapse_err", CTLFLAG_RD, 192 &tx_stats->collapse_err, 193 "Mbuf collapse failures"); 194 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 195 "queue_wakeups", CTLFLAG_RD, 196 &tx_stats->queue_wakeup, "Queue wakeups"); 197 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 198 "queue_stops", CTLFLAG_RD, 199 &tx_stats->queue_stop, "Queue stops"); 200 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 201 "llq_buffer_copy", CTLFLAG_RD, 202 &tx_stats->llq_buffer_copy, 203 "Header copies for llq transaction"); 204 205 /* RX specific stats */ 206 rx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO, 207 "rx_ring", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "RX ring"); 208 rx_list = SYSCTL_CHILDREN(rx_node); 209 210 rx_stats = &rx_ring->rx_stats; 211 212 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 213 "count", CTLFLAG_RD, 214 &rx_stats->cnt, "Packets received"); 215 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 216 "bytes", CTLFLAG_RD, 217 &rx_stats->bytes, "Bytes received"); 218 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 219 "refil_partial", CTLFLAG_RD, 220 &rx_stats->refil_partial, "Partial refilled mbufs"); 221 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 222 "bad_csum", CTLFLAG_RD, 223 &rx_stats->bad_csum, "Bad RX checksum"); 224 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 225 "mbuf_alloc_fail", CTLFLAG_RD, 226 &rx_stats->mbuf_alloc_fail, "Failed mbuf allocs"); 227 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 228 "mjum_alloc_fail", CTLFLAG_RD, 229 &rx_stats->mjum_alloc_fail, "Failed jumbo mbuf allocs"); 230 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 231 "dma_mapping_err", CTLFLAG_RD, 232 &rx_stats->dma_mapping_err, "DMA mapping errors"); 233 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 234 "bad_desc_num", CTLFLAG_RD, 235 &rx_stats->bad_desc_num, "Bad descriptor count"); 236 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 237 "bad_req_id", CTLFLAG_RD, 238 &rx_stats->bad_req_id, "Bad request id count"); 239 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 240 "empty_rx_ring", CTLFLAG_RD, 241 &rx_stats->empty_rx_ring, "RX descriptors depletion count"); 242 } 243 244 /* Stats read from device */ 245 hw_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hw_stats", 246 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Statistics from hardware"); 247 hw_list = SYSCTL_CHILDREN(hw_node); 248 249 SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_packets", CTLFLAG_RD, 250 &hw_stats->rx_packets, "Packets received"); 251 SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "tx_packets", CTLFLAG_RD, 252 &hw_stats->tx_packets, "Packets transmitted"); 253 SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_bytes", CTLFLAG_RD, 254 &hw_stats->rx_bytes, "Bytes received"); 255 SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "tx_bytes", CTLFLAG_RD, 256 &hw_stats->tx_bytes, "Bytes transmitted"); 257 SYSCTL_ADD_COUNTER_U64(ctx, hw_list, OID_AUTO, "rx_drops", CTLFLAG_RD, 258 &hw_stats->rx_drops, "Receive packet drops"); 259 260 /* ENA Admin queue stats */ 261 admin_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "admin_stats", 262 CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "ENA Admin Queue statistics"); 263 admin_list = SYSCTL_CHILDREN(admin_node); 264 265 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "aborted_cmd", CTLFLAG_RD, 266 &admin_stats->aborted_cmd, 0, "Aborted commands"); 267 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "sumbitted_cmd", CTLFLAG_RD, 268 &admin_stats->submitted_cmd, 0, "Submitted commands"); 269 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "completed_cmd", CTLFLAG_RD, 270 &admin_stats->completed_cmd, 0, "Completed commands"); 271 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "out_of_space", CTLFLAG_RD, 272 &admin_stats->out_of_space, 0, "Queue out of space"); 273 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "no_completion", CTLFLAG_RD, 274 &admin_stats->no_completion, 0, "Commands not completed"); 275 } 276 277 static void 278 ena_sysctl_add_tuneables(struct ena_adapter *adapter) 279 { 280 device_t dev; 281 282 struct sysctl_ctx_list *ctx; 283 struct sysctl_oid *tree; 284 struct sysctl_oid_list *child; 285 286 dev = adapter->pdev; 287 288 ctx = device_get_sysctl_ctx(dev); 289 tree = device_get_sysctl_tree(dev); 290 child = SYSCTL_CHILDREN(tree); 291 292 /* Tuneable number of buffers in the buf-ring (drbr) */ 293 SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "buf_ring_size", 294 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, 295 ena_sysctl_buf_ring_size, "I", "Size of the bufring"); 296 297 /* Tuneable number of Rx ring size */ 298 SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rx_queue_size", 299 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, adapter, 0, 300 ena_sysctl_rx_queue_size, "I", "Size of the Rx ring. " 301 "The size should be a power of 2. Max value is 8K"); 302 } 303 304 305 static int 306 ena_sysctl_buf_ring_size(SYSCTL_HANDLER_ARGS) 307 { 308 struct ena_adapter *adapter = arg1; 309 int val; 310 int error; 311 312 val = 0; 313 error = sysctl_wire_old_buffer(req, sizeof(int)); 314 if (error == 0) { 315 val = adapter->buf_ring_size; 316 error = sysctl_handle_int(oidp, &val, 0, req); 317 } 318 if (error != 0 || req->newptr == NULL) 319 return (error); 320 if (val < 0) 321 return (EINVAL); 322 323 device_printf(adapter->pdev, 324 "Requested new buf ring size: %d. Old size: %d\n", 325 val, adapter->buf_ring_size); 326 327 if (val != adapter->buf_ring_size) { 328 adapter->buf_ring_size = val; 329 adapter->reset_reason = ENA_REGS_RESET_OS_TRIGGER; 330 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); 331 } 332 333 return (0); 334 } 335 336 static int 337 ena_sysctl_rx_queue_size(SYSCTL_HANDLER_ARGS) 338 { 339 struct ena_adapter *adapter = arg1; 340 int val; 341 int error; 342 343 val = 0; 344 error = sysctl_wire_old_buffer(req, sizeof(int)); 345 if (error == 0) { 346 val = adapter->rx_ring_size; 347 error = sysctl_handle_int(oidp, &val, 0, req); 348 } 349 if (error != 0 || req->newptr == NULL) 350 return (error); 351 if (val < 16) 352 return (EINVAL); 353 354 device_printf(adapter->pdev, 355 "Requested new rx queue size: %d. Old size: %d\n", 356 val, adapter->rx_ring_size); 357 358 if (val != adapter->rx_ring_size) { 359 adapter->rx_ring_size = val; 360 adapter->reset_reason = ENA_REGS_RESET_OS_TRIGGER; 361 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter); 362 } 363 364 return (0); 365 } 366