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 int ena_sysctl_update_stats(SYSCTL_HANDLER_ARGS); 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_stats(adapter); 42 } 43 44 static void 45 ena_sysctl_add_stats(struct ena_adapter *adapter) 46 { 47 device_t dev; 48 49 struct ena_ring *tx_ring; 50 struct ena_ring *rx_ring; 51 52 struct ena_hw_stats *hw_stats; 53 struct ena_stats_dev *dev_stats; 54 struct ena_stats_tx *tx_stats; 55 struct ena_stats_rx *rx_stats; 56 struct ena_com_stats_admin *admin_stats; 57 58 struct sysctl_ctx_list *ctx; 59 struct sysctl_oid *tree; 60 struct sysctl_oid_list *child; 61 62 struct sysctl_oid *queue_node, *tx_node, *rx_node, *hw_node; 63 struct sysctl_oid *admin_node; 64 struct sysctl_oid_list *queue_list, *tx_list, *rx_list, *hw_list; 65 struct sysctl_oid_list *admin_list; 66 67 #define QUEUE_NAME_LEN 32 68 char namebuf[QUEUE_NAME_LEN]; 69 int i; 70 71 dev = adapter->pdev; 72 73 ctx = device_get_sysctl_ctx(dev); 74 tree = device_get_sysctl_tree(dev); 75 child = SYSCTL_CHILDREN(tree); 76 77 tx_ring = adapter->tx_ring; 78 rx_ring = adapter->rx_ring; 79 80 hw_stats = &adapter->hw_stats; 81 dev_stats = &adapter->dev_stats; 82 admin_stats = &adapter->ena_dev->admin_queue.stats; 83 84 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "tx_timeout", 85 CTLFLAG_RD, &dev_stats->tx_timeout, 86 "Driver TX timeouts"); 87 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "io_suspend", 88 CTLFLAG_RD, &dev_stats->io_suspend, 89 "IO queue suspends"); 90 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "io_resume", 91 CTLFLAG_RD, &dev_stats->io_resume, 92 "IO queue resumes"); 93 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "wd_expired", 94 CTLFLAG_RD, &dev_stats->wd_expired, 95 "Watchdog expiry count"); 96 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_up", 97 CTLFLAG_RD, &dev_stats->interface_up, 98 "Network interface up count"); 99 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "interface_down", 100 CTLFLAG_RD, &dev_stats->interface_down, 101 "Network interface down count"); 102 SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "admin_q_pause", 103 CTLFLAG_RD, &dev_stats->admin_q_pause, 104 "Admin queue pauses"); 105 106 for (i = 0; i < adapter->num_queues; ++i, ++tx_ring, ++rx_ring) { 107 snprintf(namebuf, QUEUE_NAME_LEN, "queue%d", i); 108 109 queue_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, 110 namebuf, CTLFLAG_RD, NULL, "Queue Name"); 111 queue_list = SYSCTL_CHILDREN(queue_node); 112 113 /* TX specific stats */ 114 tx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO, 115 "tx_ring", CTLFLAG_RD, NULL, "TX ring"); 116 tx_list = SYSCTL_CHILDREN(tx_node); 117 118 tx_stats = &tx_ring->tx_stats; 119 120 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 121 "count", CTLFLAG_RD, 122 &tx_stats->cnt, "Packets sent"); 123 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 124 "bytes", CTLFLAG_RD, 125 &tx_stats->bytes, "Bytes sent"); 126 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 127 "prepare_ctx_err", CTLFLAG_RD, 128 &tx_stats->prepare_ctx_err, 129 "TX buffer preparation failures"); 130 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 131 "queue_wakeup", CTLFLAG_RD, 132 &tx_stats->queue_wakeup, "Queue wakeups"); 133 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 134 "dma_mapping_err", CTLFLAG_RD, 135 &tx_stats->dma_mapping_err, "DMA mapping failures"); 136 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 137 "unsupported_desc_num", CTLFLAG_RD, 138 &tx_stats->unsupported_desc_num, 139 "Excessive descriptor packet discards"); 140 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 141 "napi_comp", CTLFLAG_RD, 142 &tx_stats->napi_comp, "Napi completions"); 143 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 144 "tx_poll", CTLFLAG_RD, 145 &tx_stats->tx_poll, "TX poll count"); 146 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 147 "doorbells", CTLFLAG_RD, 148 &tx_stats->doorbells, "Queue doorbells"); 149 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 150 "missing_tx_comp", CTLFLAG_RD, 151 &tx_stats->missing_tx_comp, "TX completions missed"); 152 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 153 "bad_req_id", CTLFLAG_RD, 154 &tx_stats->bad_req_id, "Bad request id count"); 155 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 156 "stops", CTLFLAG_RD, 157 &tx_stats->queue_stop, "Queue stops"); 158 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 159 "mbuf_collapses", CTLFLAG_RD, 160 &tx_stats->collapse, 161 "Mbuf collapse count"); 162 SYSCTL_ADD_COUNTER_U64(ctx, tx_list, OID_AUTO, 163 "mbuf_collapse_err", CTLFLAG_RD, 164 &tx_stats->collapse_err, 165 "Mbuf collapse failures"); 166 167 /* RX specific stats */ 168 rx_node = SYSCTL_ADD_NODE(ctx, queue_list, OID_AUTO, 169 "rx_ring", CTLFLAG_RD, NULL, "RX ring"); 170 rx_list = SYSCTL_CHILDREN(rx_node); 171 172 rx_stats = &rx_ring->rx_stats; 173 174 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 175 "count", CTLFLAG_RD, 176 &rx_stats->cnt, "Packets received"); 177 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 178 "bytes", CTLFLAG_RD, 179 &rx_stats->bytes, "Bytes received"); 180 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 181 "refil_partial", CTLFLAG_RD, 182 &rx_stats->refil_partial, "Partial refilled mbufs"); 183 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 184 "bad_csum", CTLFLAG_RD, 185 &rx_stats->bad_csum, "Bad RX checksum"); 186 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 187 "page_alloc_fail", CTLFLAG_RD, 188 &rx_stats->page_alloc_fail, "Failed page allocs"); 189 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 190 "mbuf_alloc_fail", CTLFLAG_RD, 191 &rx_stats->mbuf_alloc_fail, "Failed mbuf allocs"); 192 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 193 "dma_mapping_err", CTLFLAG_RD, 194 &rx_stats->dma_mapping_err, "DMA mapping errors"); 195 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 196 "bad_desc_num", CTLFLAG_RD, 197 &rx_stats->bad_desc_num, "Bad descriptor count"); 198 SYSCTL_ADD_COUNTER_U64(ctx, rx_list, OID_AUTO, 199 "small_copy_len_pkt", CTLFLAG_RD, 200 &rx_stats->small_copy_len_pkt, "Small copy packet count"); 201 } 202 203 /* Stats read from device */ 204 hw_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hw_stats", 205 CTLFLAG_RD, NULL, "Statistics from hardware"); 206 hw_list = SYSCTL_CHILDREN(hw_node); 207 208 SYSCTL_ADD_U64(ctx, hw_list, OID_AUTO, "rx_packets", CTLFLAG_RD, 209 &hw_stats->rx_packets, 0, "Packets received"); 210 SYSCTL_ADD_U64(ctx, hw_list, OID_AUTO, "tx_packets", CTLFLAG_RD, 211 &hw_stats->tx_packets, 0, "Packets transmitted"); 212 SYSCTL_ADD_U64(ctx, hw_list, OID_AUTO, "rx_bytes", CTLFLAG_RD, 213 &hw_stats->rx_bytes, 0, "Bytes received"); 214 SYSCTL_ADD_U64(ctx, hw_list, OID_AUTO, "tx_bytes", CTLFLAG_RD, 215 &hw_stats->tx_bytes, 0, "Bytes transmitted"); 216 SYSCTL_ADD_U64(ctx, hw_list, OID_AUTO, "rx_drops", CTLFLAG_RD, 217 &hw_stats->rx_drops, 0, "Receive packet drops"); 218 219 SYSCTL_ADD_PROC(ctx, hw_list, OID_AUTO, "update_stats", 220 CTLTYPE_INT|CTLFLAG_RD, adapter, 0, ena_sysctl_update_stats, 221 "A", "Update stats from hardware"); 222 /* ENA Admin queue stats */ 223 admin_node = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "admin_stats", 224 CTLFLAG_RD, NULL, "ENA Admin Queue statistics"); 225 admin_list = SYSCTL_CHILDREN(admin_node); 226 227 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "aborted_cmd", CTLFLAG_RD, 228 &admin_stats->aborted_cmd, 0, "Aborted commands"); 229 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "sumbitted_cmd", CTLFLAG_RD, 230 &admin_stats->submitted_cmd, 0, "Submitted commands"); 231 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "completed_cmd", CTLFLAG_RD, 232 &admin_stats->completed_cmd, 0, "Completed commands"); 233 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "out_of_space", CTLFLAG_RD, 234 &admin_stats->out_of_space, 0, "Queue out of space"); 235 SYSCTL_ADD_U32(ctx, admin_list, OID_AUTO, "no_completion", CTLFLAG_RD, 236 &admin_stats->no_completion, 0, "Commands not completed"); 237 } 238 239 static int 240 ena_sysctl_update_stats(SYSCTL_HANDLER_ARGS) 241 { 242 struct ena_adapter *adapter = (struct ena_adapter *)arg1; 243 int rc; 244 245 if (adapter->up) 246 ena_update_stats_counters(adapter); 247 248 rc = sysctl_handle_string(oidp, "", 1, req); 249 return (rc); 250 } 251 252