Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Zac Livingston | 866b0e2 | 2013-10-23 18:14:17 -0600 | [diff] [blame] | 3 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * nss_stats.c |
| 19 | * NSS stats APIs |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "nss_core.h" |
| 24 | |
| 25 | /* |
| 26 | * Maximum string length: |
| 27 | * This should be equal to maximum string size of any stats |
| 28 | * inclusive of stats value |
| 29 | */ |
| 30 | #define NSS_STATS_MAX_STR_LENGTH 96 |
| 31 | |
| 32 | /* |
| 33 | * Global variables/extern declarations |
| 34 | */ |
| 35 | extern struct nss_top_instance nss_top_main; |
| 36 | |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 37 | uint64_t stats_shadow_pppoe_except[NSS_PPPOE_NUM_SESSION_PER_INTERFACE][NSS_PPPOE_EXCEPTION_EVENT_MAX]; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 38 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 39 | /* |
| 40 | * Statistics structures |
| 41 | */ |
| 42 | |
| 43 | /* |
| 44 | * nss_stats_str_ipv4 |
| 45 | * IPv4 stats strings |
| 46 | */ |
| 47 | static int8_t *nss_stats_str_ipv4[NSS_STATS_IPV4_MAX] = { |
| 48 | "rx_pkts", |
| 49 | "rx_bytes", |
| 50 | "tx_pkts", |
| 51 | "tx_bytes", |
| 52 | "create_requests", |
| 53 | "create_collisions", |
| 54 | "create_invalid_interface", |
| 55 | "destroy_requests", |
| 56 | "destroy_misses", |
| 57 | "hash_hits", |
| 58 | "hash_reorders", |
| 59 | "flushes", |
| 60 | "evictions" |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * nss_stats_str_ipv6 |
| 65 | * IPv6 stats strings |
| 66 | */ |
| 67 | static int8_t *nss_stats_str_ipv6[NSS_STATS_IPV6_MAX] = { |
| 68 | "rx_pkts", |
| 69 | "rx_bytes", |
| 70 | "tx_pkts", |
| 71 | "tx_bytes", |
| 72 | "create_requests", |
| 73 | "create_collisions", |
| 74 | "create_invalid_interface", |
| 75 | "destroy_requests", |
| 76 | "destroy_misses", |
| 77 | "hash_hits", |
| 78 | "hash_reorders", |
| 79 | "flushes", |
| 80 | "evictions", |
| 81 | }; |
| 82 | |
| 83 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 84 | * nss_stats_str_n2h |
| 85 | * N2H stats strings |
| 86 | */ |
| 87 | static int8_t *nss_stats_str_n2h[NSS_STATS_N2H_MAX] = { |
| 88 | "queue_dropped", |
| 89 | "ticks", |
| 90 | "worst_ticks", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 91 | "iterations", |
Thomas Wu | 3fd8dd7 | 2014-06-11 15:57:05 -0700 | [diff] [blame] | 92 | "pbuf_ocm_alloc_fails", |
| 93 | "pbuf_ocm_free_count", |
| 94 | "pbuf_ocm_total_count", |
| 95 | "pbuf_default_alloc_fails", |
| 96 | "pbuf_default_free_count", |
| 97 | "pbuf_default_total_count", |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 98 | "payload_fails" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | /* |
| 102 | * nss_stats_str_drv |
| 103 | * Host driver stats strings |
| 104 | */ |
| 105 | static int8_t *nss_stats_str_drv[NSS_STATS_DRV_MAX] = { |
| 106 | "nbuf_alloc_errors", |
| 107 | "tx_queue_full[0]", |
| 108 | "tx_queue_full[1]", |
| 109 | "tx_buffers_empty", |
| 110 | "tx_buffers_pkt", |
| 111 | "tx_buffers_cmd", |
| 112 | "tx_buffers_crypto", |
| 113 | "rx_buffers_empty", |
| 114 | "rx_buffers_pkt", |
| 115 | "rx_buffers_cmd_resp", |
| 116 | "rx_buffers_status_sync", |
| 117 | "rx_buffers_crypto", |
| 118 | "rx_buffers_virtual" |
| 119 | }; |
| 120 | |
| 121 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 122 | * nss_stats_str_pppoe |
| 123 | * PPPoE stats strings |
| 124 | */ |
| 125 | static int8_t *nss_stats_str_pppoe[NSS_STATS_PPPOE_MAX] = { |
| 126 | "create_requests", |
| 127 | "create_failures", |
| 128 | "destroy_requests", |
| 129 | "destroy_misses" |
| 130 | }; |
| 131 | |
| 132 | /* |
| 133 | * nss_stats_str_gmac |
| 134 | * GMAC stats strings |
| 135 | */ |
| 136 | static int8_t *nss_stats_str_gmac[NSS_STATS_GMAC_MAX] = { |
| 137 | "ticks", |
| 138 | "worst_ticks", |
| 139 | "iterations" |
| 140 | }; |
| 141 | |
| 142 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 143 | * nss_stats_str_node |
| 144 | * Interface stats strings per node |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 145 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 146 | static int8_t *nss_stats_str_node[NSS_STATS_NODE_MAX] = { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 147 | "rx_packets", |
| 148 | "rx_bytes", |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 149 | "rx_dropped", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 150 | "tx_packets", |
| 151 | "tx_bytes" |
| 152 | }; |
| 153 | |
| 154 | /* |
Murat Sezgin | 99dab64 | 2014-08-28 14:40:34 -0700 | [diff] [blame] | 155 | * nss_stats_str_eth_rx |
| 156 | * eth_rx stats strings |
| 157 | */ |
| 158 | static int8_t *nss_stats_str_eth_rx[NSS_STATS_ETH_RX_MAX] = { |
| 159 | "ticks", |
| 160 | "worst_ticks", |
| 161 | "iterations" |
| 162 | }; |
| 163 | |
| 164 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 165 | * nss_stats_str_if_exception_unknown |
| 166 | * Interface stats strings for unknown exceptions |
| 167 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 168 | static int8_t *nss_stats_str_if_exception_eth_rx[NSS_EXCEPTION_EVENT_ETH_RX_MAX] = { |
| 169 | "UNKNOWN_L3_PROTOCOL" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | /* |
| 173 | * nss_stats_str_if_exception_ipv4 |
| 174 | * Interface stats strings for ipv4 exceptions |
| 175 | */ |
| 176 | static int8_t *nss_stats_str_if_exception_ipv4[NSS_EXCEPTION_EVENT_IPV4_MAX] = { |
| 177 | "IPV4_ICMP_HEADER_INCOMPLETE", |
| 178 | "IPV4_ICMP_UNHANDLED_TYPE", |
| 179 | "IPV4_ICMP_IPV4_HEADER_INCOMPLETE", |
| 180 | "IPV4_ICMP_IPV4_UDP_HEADER_INCOMPLETE", |
| 181 | "IPV4_ICMP_IPV4_TCP_HEADER_INCOMPLETE", |
| 182 | "IPV4_ICMP_IPV4_UNKNOWN_PROTOCOL", |
| 183 | "IPV4_ICMP_NO_ICME", |
| 184 | "IPV4_ICMP_FLUSH_TO_HOST", |
| 185 | "IPV4_TCP_HEADER_INCOMPLETE", |
| 186 | "IPV4_TCP_NO_ICME", |
| 187 | "IPV4_TCP_IP_OPTION", |
| 188 | "IPV4_TCP_IP_FRAGMENT", |
| 189 | "IPV4_TCP_SMALL_TTL", |
| 190 | "IPV4_TCP_NEEDS_FRAGMENTATION", |
| 191 | "IPV4_TCP_FLAGS", |
| 192 | "IPV4_TCP_SEQ_EXCEEDS_RIGHT_EDGE", |
| 193 | "IPV4_TCP_SMALL_DATA_OFFS", |
| 194 | "IPV4_TCP_BAD_SACK", |
| 195 | "IPV4_TCP_BIG_DATA_OFFS", |
| 196 | "IPV4_TCP_SEQ_BEFORE_LEFT_EDGE", |
| 197 | "IPV4_TCP_ACK_EXCEEDS_RIGHT_EDGE", |
| 198 | "IPV4_TCP_ACK_BEFORE_LEFT_EDGE", |
| 199 | "IPV4_UDP_HEADER_INCOMPLETE", |
| 200 | "IPV4_UDP_NO_ICME", |
| 201 | "IPV4_UDP_IP_OPTION", |
| 202 | "IPV4_UDP_IP_FRAGMENT", |
| 203 | "IPV4_UDP_SMALL_TTL", |
| 204 | "IPV4_UDP_NEEDS_FRAGMENTATION", |
| 205 | "IPV4_WRONG_TARGET_MAC", |
| 206 | "IPV4_HEADER_INCOMPLETE", |
| 207 | "IPV4_BAD_TOTAL_LENGTH", |
| 208 | "IPV4_BAD_CHECKSUM", |
| 209 | "IPV4_NON_INITIAL_FRAGMENT", |
| 210 | "IPV4_DATAGRAM_INCOMPLETE", |
| 211 | "IPV4_OPTIONS_INCOMPLETE", |
Radha krishna Simha Jiguru | 59a1a1c | 2014-01-27 18:29:40 +0530 | [diff] [blame] | 212 | "IPV4_UNKNOWN_PROTOCOL", |
| 213 | "IPV4_ESP_HEADER_INCOMPLETE", |
| 214 | "IPV4_ESP_NO_ICME", |
| 215 | "IPV4_ESP_IP_OPTION", |
| 216 | "IPV4_ESP_IP_FRAGMENT", |
| 217 | "IPV4_ESP_SMALL_TTL", |
| 218 | "IPV4_ESP_NEEDS_FRAGMENTATION", |
| 219 | "IPV4_INGRESS_VID_MISMATCH", |
Thomas Wu | 8d6f4b2 | 2014-06-09 14:46:18 -0700 | [diff] [blame] | 220 | "IPV4_INGRESS_VID_MISSING", |
Radha krishna Simha Jiguru | 59a1a1c | 2014-01-27 18:29:40 +0530 | [diff] [blame] | 221 | "IPV4_6RD_NO_ICME", |
| 222 | "IPV4_6RD_IP_OPTION", |
| 223 | "IPV4_6RD_IP_FRAGMENT", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 224 | "IPV4_6RD_NEEDS_FRAGMENTATION", |
| 225 | "IPV4_DSCP_MARKING_MISMATCH", |
Murat Sezgin | 7c5956a | 2014-05-12 09:59:51 -0700 | [diff] [blame] | 226 | "IPV4_VLAN_MARKING_MISMATCH", |
Thomas Wu | 8d6f4b2 | 2014-06-09 14:46:18 -0700 | [diff] [blame] | 227 | "IPV4_INTERFACE_MISMATCH", |
| 228 | "IPV4_DESTROY" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | /* |
| 232 | * nss_stats_str_if_exception_ipv6 |
| 233 | * Interface stats strings for ipv6 exceptions |
| 234 | */ |
| 235 | static int8_t *nss_stats_str_if_exception_ipv6[NSS_EXCEPTION_EVENT_IPV6_MAX] = { |
| 236 | "IPV6_ICMP_HEADER_INCOMPLETE", |
| 237 | "IPV6_ICMP_UNHANDLED_TYPE", |
| 238 | "IPV6_ICMP_IPV6_HEADER_INCOMPLETE", |
| 239 | "IPV6_ICMP_IPV6_UDP_HEADER_INCOMPLETE", |
| 240 | "IPV6_ICMP_IPV6_TCP_HEADER_INCOMPLETE", |
| 241 | "IPV6_ICMP_IPV6_UNKNOWN_PROTOCOL", |
| 242 | "IPV6_ICMP_NO_ICME", |
| 243 | "IPV6_ICMP_FLUSH_TO_HOST", |
| 244 | "IPV6_TCP_HEADER_INCOMPLETE", |
| 245 | "IPV6_TCP_NO_ICME", |
| 246 | "IPV6_TCP_SMALL_HOP_LIMIT", |
| 247 | "IPV6_TCP_NEEDS_FRAGMENTATION", |
| 248 | "IPV6_TCP_FLAGS", |
| 249 | "IPV6_TCP_SEQ_EXCEEDS_RIGHT_EDGE", |
| 250 | "IPV6_TCP_SMALL_DATA_OFFS", |
| 251 | "IPV6_TCP_BAD_SACK", |
| 252 | "IPV6_TCP_BIG_DATA_OFFS", |
| 253 | "IPV6_TCP_SEQ_BEFORE_LEFT_EDGE", |
| 254 | "IPV6_TCP_ACK_EXCEEDS_RIGHT_EDGE", |
| 255 | "IPV6_TCP_ACK_BEFORE_LEFT_EDGE", |
| 256 | "IPV6_UDP_HEADER_INCOMPLETE", |
| 257 | "IPV6_UDP_NO_ICME", |
| 258 | "IPV6_UDP_SMALL_HOP_LIMIT", |
| 259 | "IPV6_UDP_NEEDS_FRAGMENTATION", |
| 260 | "IPV6_WRONG_TARGET_MAC", |
| 261 | "IPV6_HEADER_INCOMPLETE", |
Radha krishna Simha Jiguru | 59a1a1c | 2014-01-27 18:29:40 +0530 | [diff] [blame] | 262 | "IPV6_UNKNOWN_PROTOCOL", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 263 | "IPV6_INGRESS_VID_MISMATCH", |
Thomas Wu | 8d6f4b2 | 2014-06-09 14:46:18 -0700 | [diff] [blame] | 264 | "IPV6_INGRESS_VID_MISSING", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 265 | "IPV6_DSCP_MARKING_MISMATCH", |
| 266 | "IPV6_VLAN_MARKING_MISMATCH", |
Thomas Wu | 8d6f4b2 | 2014-06-09 14:46:18 -0700 | [diff] [blame] | 267 | "IPV6_INTERFACE_MISMATCH", |
| 268 | "IPV6_DESTROY" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | /* |
| 272 | * nss_stats_str_if_exception_pppoe |
| 273 | * Interface stats strings for PPPoE exceptions |
| 274 | */ |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 275 | static int8_t *nss_stats_str_if_exception_pppoe[NSS_PPPOE_EXCEPTION_EVENT_MAX] = { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 276 | "PPPOE_WRONG_VERSION_OR_TYPE", |
| 277 | "PPPOE_WRONG_CODE", |
| 278 | "PPPOE_HEADER_INCOMPLETE", |
Murat Sezgin | 7c5956a | 2014-05-12 09:59:51 -0700 | [diff] [blame] | 279 | "PPPOE_UNSUPPORTED_PPP_PROTOCOL", |
| 280 | "PPPOE_INTERFACE_MISMATCH" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | /* |
| 284 | * nss_stats_ipv4_read() |
| 285 | * Read IPV4 stats |
| 286 | */ |
| 287 | static ssize_t nss_stats_ipv4_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 288 | { |
| 289 | int32_t i; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 290 | /* |
| 291 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 292 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 293 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV4_MAX + 3) + (NSS_EXCEPTION_EVENT_IPV4_MAX + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 294 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 295 | size_t size_wr = 0; |
| 296 | ssize_t bytes_read = 0; |
| 297 | uint64_t *stats_shadow; |
| 298 | |
| 299 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 300 | if (unlikely(lbuf == NULL)) { |
| 301 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 302 | return 0; |
| 303 | } |
| 304 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 305 | /* |
| 306 | * Note: The assumption here is that exception event count is larger than other statistics count for IPv4 |
| 307 | */ |
| 308 | stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV4_MAX * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 309 | if (unlikely(stats_shadow == NULL)) { |
| 310 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 311 | return 0; |
| 312 | } |
| 313 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 314 | size_wr = scnprintf(lbuf, size_al, "ipv4 stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 315 | |
| 316 | /* |
| 317 | * Common node stats |
| 318 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 319 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 320 | spin_lock_bh(&nss_top_main.stats_lock); |
| 321 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 322 | stats_shadow[i] = nss_top_main.stats_node[NSS_IPV4_RX_INTERFACE][i]; |
| 323 | } |
| 324 | |
| 325 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 326 | |
| 327 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 328 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 329 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * IPv4 node stats |
| 334 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 335 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 336 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 337 | spin_lock_bh(&nss_top_main.stats_lock); |
| 338 | for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) { |
| 339 | stats_shadow[i] = nss_top_main.stats_ipv4[i]; |
| 340 | } |
| 341 | |
| 342 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 343 | |
| 344 | for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) { |
| 345 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 346 | "%s = %llu\n", nss_stats_str_ipv4[i], stats_shadow[i]); |
| 347 | } |
| 348 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 349 | /* |
| 350 | * Exception stats |
| 351 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 352 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 exception stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 353 | |
| 354 | spin_lock_bh(&nss_top_main.stats_lock); |
| 355 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) { |
| 356 | stats_shadow[i] = nss_top_main.stats_if_exception_ipv4[i]; |
| 357 | } |
| 358 | |
| 359 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 360 | |
| 361 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) { |
| 362 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 363 | "%s = %llu\n", nss_stats_str_if_exception_ipv4[i], stats_shadow[i]); |
| 364 | } |
| 365 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 366 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 stats end\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 367 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 368 | kfree(lbuf); |
| 369 | kfree(stats_shadow); |
| 370 | |
| 371 | return bytes_read; |
| 372 | } |
| 373 | |
| 374 | /* |
| 375 | * nss_stats_ipv6_read() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 376 | * Read IPV6 stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 377 | */ |
| 378 | static ssize_t nss_stats_ipv6_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 379 | { |
| 380 | int32_t i; |
| 381 | |
| 382 | /* |
| 383 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 384 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 385 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV6_MAX + 3) + (NSS_EXCEPTION_EVENT_IPV6_MAX + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 386 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 387 | size_t size_wr = 0; |
| 388 | ssize_t bytes_read = 0; |
| 389 | uint64_t *stats_shadow; |
| 390 | |
| 391 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 392 | if (unlikely(lbuf == NULL)) { |
| 393 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 394 | return 0; |
| 395 | } |
| 396 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 397 | /* |
| 398 | * Note: The assumption here is that exception event count is larger than other statistics count for IPv4 |
| 399 | */ |
| 400 | stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV6_MAX * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 401 | if (unlikely(stats_shadow == NULL)) { |
| 402 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 403 | return 0; |
| 404 | } |
| 405 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 406 | size_wr = scnprintf(lbuf, size_al, "ipv6 stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Common node stats |
| 410 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 411 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 412 | spin_lock_bh(&nss_top_main.stats_lock); |
| 413 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 414 | stats_shadow[i] = nss_top_main.stats_node[NSS_IPV6_RX_INTERFACE][i]; |
| 415 | } |
| 416 | |
| 417 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 418 | |
| 419 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 420 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 421 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * IPv6 node stats |
| 426 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 427 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 428 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 429 | spin_lock_bh(&nss_top_main.stats_lock); |
| 430 | for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) { |
| 431 | stats_shadow[i] = nss_top_main.stats_ipv6[i]; |
| 432 | } |
| 433 | |
| 434 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 435 | |
| 436 | for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) { |
| 437 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 438 | "%s = %llu\n", nss_stats_str_ipv6[i], stats_shadow[i]); |
| 439 | } |
| 440 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 441 | /* |
| 442 | * Exception stats |
| 443 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 444 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 exception stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 445 | |
| 446 | spin_lock_bh(&nss_top_main.stats_lock); |
| 447 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) { |
| 448 | stats_shadow[i] = nss_top_main.stats_if_exception_ipv6[i]; |
| 449 | } |
| 450 | |
| 451 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 452 | |
| 453 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) { |
| 454 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 455 | "%s = %llu\n", nss_stats_str_if_exception_ipv6[i], stats_shadow[i]); |
| 456 | } |
| 457 | |
| 458 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\nipv6 stats end\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 459 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 460 | kfree(lbuf); |
| 461 | kfree(stats_shadow); |
| 462 | |
| 463 | return bytes_read; |
| 464 | } |
| 465 | |
| 466 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 467 | * nss_stats_eth_rx_read() |
| 468 | * Read ETH_RX stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 469 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 470 | static ssize_t nss_stats_eth_rx_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 471 | { |
| 472 | int32_t i; |
| 473 | |
| 474 | /* |
| 475 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 476 | */ |
Murat Sezgin | 99dab64 | 2014-08-28 14:40:34 -0700 | [diff] [blame] | 477 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_ETH_RX_MAX + 3) + (NSS_EXCEPTION_EVENT_ETH_RX_MAX + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 478 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 479 | size_t size_wr = 0; |
| 480 | ssize_t bytes_read = 0; |
| 481 | uint64_t *stats_shadow; |
| 482 | |
| 483 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 484 | if (unlikely(lbuf == NULL)) { |
| 485 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 486 | return 0; |
| 487 | } |
| 488 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 489 | /* |
| 490 | * Note: The assumption here is that we do not have more than 64 stats |
| 491 | */ |
| 492 | stats_shadow = kzalloc(64 * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 493 | if (unlikely(stats_shadow == NULL)) { |
| 494 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 495 | return 0; |
| 496 | } |
| 497 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 498 | size_wr = scnprintf(lbuf, size_al,"eth_rx stats start:\n\n"); |
| 499 | |
| 500 | /* |
| 501 | * Common node stats |
| 502 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 503 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 504 | spin_lock_bh(&nss_top_main.stats_lock); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 505 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 506 | stats_shadow[i] = nss_top_main.stats_node[NSS_ETH_RX_INTERFACE][i]; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 510 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 511 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 512 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 513 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 514 | } |
| 515 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 516 | /* |
Murat Sezgin | 99dab64 | 2014-08-28 14:40:34 -0700 | [diff] [blame] | 517 | * eth_rx node stats |
| 518 | */ |
| 519 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx node stats:\n\n"); |
| 520 | spin_lock_bh(&nss_top_main.stats_lock); |
| 521 | for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) { |
| 522 | stats_shadow[i] = nss_top_main.stats_eth_rx[i]; |
| 523 | } |
| 524 | |
| 525 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 526 | |
| 527 | for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) { |
| 528 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 529 | "%s = %llu\n", nss_stats_str_eth_rx[i], stats_shadow[i]); |
| 530 | } |
| 531 | |
| 532 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 533 | * Exception stats |
| 534 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 535 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx exception stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 536 | |
| 537 | spin_lock_bh(&nss_top_main.stats_lock); |
| 538 | for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) { |
| 539 | stats_shadow[i] = nss_top_main.stats_if_exception_eth_rx[i]; |
| 540 | } |
| 541 | |
| 542 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 543 | |
| 544 | for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) { |
| 545 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 546 | "%s = %llu\n", nss_stats_str_if_exception_eth_rx[i], stats_shadow[i]); |
| 547 | } |
| 548 | |
| 549 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\neth_rx stats end\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 550 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 551 | kfree(lbuf); |
| 552 | kfree(stats_shadow); |
| 553 | |
| 554 | return bytes_read; |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | * nss_stats_n2h_read() |
| 559 | * Read N2H stats |
| 560 | */ |
| 561 | static ssize_t nss_stats_n2h_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 562 | { |
| 563 | int32_t i; |
| 564 | |
| 565 | /* |
| 566 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 567 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 568 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_N2H_MAX + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 569 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 570 | size_t size_wr = 0; |
| 571 | ssize_t bytes_read = 0; |
| 572 | uint64_t *stats_shadow; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 573 | int max = NSS_STATS_N2H_MAX - NSS_STATS_NODE_MAX; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 574 | |
| 575 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 576 | if (unlikely(lbuf == NULL)) { |
| 577 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | stats_shadow = kzalloc(NSS_STATS_N2H_MAX * 8, GFP_KERNEL); |
| 582 | if (unlikely(stats_shadow == NULL)) { |
| 583 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | size_wr = scnprintf(lbuf, size_al, "n2h stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 588 | |
| 589 | /* |
| 590 | * Common node stats |
| 591 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 592 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 593 | spin_lock_bh(&nss_top_main.stats_lock); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 594 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 595 | stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i]; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 599 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 600 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 601 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 602 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * N2H node stats |
| 607 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 608 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 609 | spin_lock_bh(&nss_top_main.stats_lock); |
| 610 | for (i = NSS_STATS_NODE_MAX; (i < NSS_STATS_N2H_MAX); i++) { |
| 611 | stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i]; |
| 612 | } |
| 613 | |
| 614 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 615 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 616 | for (i = 0; i < max; i++) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 617 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 618 | "%s = %llu\n", nss_stats_str_n2h[i], stats_shadow[i + NSS_STATS_NODE_MAX]); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h stats end\n\n"); |
| 622 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 623 | kfree(lbuf); |
| 624 | kfree(stats_shadow); |
| 625 | |
| 626 | return bytes_read; |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * nss_stats_drv_read() |
| 631 | * Read HLOS driver stats |
| 632 | */ |
| 633 | static ssize_t nss_stats_drv_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 634 | { |
| 635 | int32_t i; |
| 636 | |
| 637 | /* |
| 638 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 639 | */ |
| 640 | uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5; |
| 641 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 642 | size_t size_wr = 0; |
| 643 | ssize_t bytes_read = 0; |
| 644 | uint64_t *stats_shadow; |
| 645 | |
| 646 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 647 | if (unlikely(lbuf == NULL)) { |
| 648 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL); |
| 653 | if (unlikely(stats_shadow == NULL)) { |
| 654 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n"); |
| 659 | spin_lock_bh(&nss_top_main.stats_lock); |
| 660 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
| 661 | stats_shadow[i] = nss_top_main.stats_drv[i]; |
| 662 | } |
| 663 | |
| 664 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 665 | |
| 666 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
| 667 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 668 | "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]); |
| 669 | } |
| 670 | |
| 671 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n"); |
| 672 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 673 | kfree(lbuf); |
| 674 | kfree(stats_shadow); |
| 675 | |
| 676 | return bytes_read; |
| 677 | } |
| 678 | |
| 679 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 680 | * nss_stats_pppoe_read() |
| 681 | * Read PPPoE stats |
| 682 | */ |
| 683 | static ssize_t nss_stats_pppoe_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 684 | { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 685 | int32_t i, j, k; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 686 | |
| 687 | /* |
| 688 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 689 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 690 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_PPPOE_MAX + 3) + |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 691 | ((NSS_MAX_PHYSICAL_INTERFACES * NSS_PPPOE_NUM_SESSION_PER_INTERFACE * (NSS_PPPOE_EXCEPTION_EVENT_MAX + 5)) + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 692 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 693 | size_t size_wr = 0; |
| 694 | ssize_t bytes_read = 0; |
| 695 | uint64_t *stats_shadow; |
| 696 | |
| 697 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 698 | if (unlikely(lbuf == NULL)) { |
| 699 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 700 | return 0; |
| 701 | } |
| 702 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 703 | stats_shadow = kzalloc(64 * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 704 | if (unlikely(stats_shadow == NULL)) { |
| 705 | nss_warning("Could not allocate memory for local shadow buffer"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 706 | kfree(lbuf); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | size_wr = scnprintf(lbuf, size_al, "pppoe stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 711 | |
| 712 | /* |
| 713 | * Common node stats |
| 714 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 715 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 716 | spin_lock_bh(&nss_top_main.stats_lock); |
| 717 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 718 | stats_shadow[i] = nss_top_main.stats_node[NSS_PPPOE_RX_INTERFACE][i]; |
| 719 | } |
| 720 | |
| 721 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 722 | |
| 723 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 724 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 725 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 726 | } |
| 727 | |
| 728 | /* |
| 729 | * PPPoE node stats |
| 730 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 731 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "pppoe node stats:\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 732 | spin_lock_bh(&nss_top_main.stats_lock); |
| 733 | for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) { |
| 734 | stats_shadow[i] = nss_top_main.stats_pppoe[i]; |
| 735 | } |
| 736 | |
| 737 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 738 | |
| 739 | for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) { |
| 740 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 741 | "%s = %llu\n", nss_stats_str_pppoe[i], stats_shadow[i]); |
| 742 | } |
| 743 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 744 | /* |
| 745 | * Exception stats |
| 746 | */ |
| 747 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nException PPPoE:\n\n"); |
| 748 | |
| 749 | for (j = 0; j < NSS_MAX_PHYSICAL_INTERFACES; j++) { |
| 750 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nInterface %d:\n\n", j); |
| 751 | |
| 752 | spin_lock_bh(&nss_top_main.stats_lock); |
| 753 | for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) { |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 754 | for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 755 | stats_shadow_pppoe_except[k][i] = nss_top_main.stats_if_exception_pppoe[j][k][i]; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 760 | |
| 761 | for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) { |
| 762 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "%d. Session\n", k); |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 763 | for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 764 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 765 | "%s = %llu\n", |
| 766 | nss_stats_str_if_exception_pppoe[i], |
| 767 | stats_shadow_pppoe_except[k][i]); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe stats end\n\n"); |
| 772 | } |
| 773 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 774 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 775 | kfree(lbuf); |
| 776 | kfree(stats_shadow); |
| 777 | |
| 778 | return bytes_read; |
| 779 | } |
| 780 | |
| 781 | /* |
| 782 | * nss_stats_gmac_read() |
| 783 | * Read GMAC stats |
| 784 | */ |
| 785 | static ssize_t nss_stats_gmac_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 786 | { |
| 787 | uint32_t i, id; |
| 788 | |
| 789 | /* |
| 790 | * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank |
| 791 | */ |
| 792 | uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5; |
| 793 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 794 | size_t size_wr = 0; |
| 795 | ssize_t bytes_read = 0; |
| 796 | uint64_t *stats_shadow; |
| 797 | |
| 798 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 799 | if (unlikely(lbuf == NULL)) { |
| 800 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL); |
| 805 | if (unlikely(stats_shadow == NULL)) { |
| 806 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n"); |
| 811 | |
| 812 | for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) { |
| 813 | spin_lock_bh(&nss_top_main.stats_lock); |
| 814 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 815 | stats_shadow[i] = nss_top_main.stats_gmac[id][i]; |
| 816 | } |
| 817 | |
| 818 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 819 | |
| 820 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id); |
| 821 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 822 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 823 | "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]); |
| 824 | } |
| 825 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n"); |
| 826 | } |
| 827 | |
| 828 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n"); |
| 829 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 830 | kfree(lbuf); |
| 831 | kfree(stats_shadow); |
| 832 | |
| 833 | return bytes_read; |
| 834 | } |
| 835 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 836 | #define NSS_STATS_DECLARE_FILE_OPERATIONS(name) \ |
| 837 | static const struct file_operations nss_stats_##name##_ops = { \ |
| 838 | .open = simple_open, \ |
| 839 | .read = nss_stats_##name##_read, \ |
| 840 | .llseek = generic_file_llseek, \ |
| 841 | }; |
| 842 | |
| 843 | /* |
| 844 | * nss_ipv4_stats_ops |
| 845 | */ |
| 846 | NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4) |
| 847 | |
| 848 | /* |
| 849 | * ipv6_stats_ops |
| 850 | */ |
| 851 | NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6) |
| 852 | |
| 853 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 854 | * n2h_stats_ops |
| 855 | */ |
| 856 | NSS_STATS_DECLARE_FILE_OPERATIONS(n2h) |
| 857 | /* |
| 858 | * drv_stats_ops |
| 859 | */ |
| 860 | NSS_STATS_DECLARE_FILE_OPERATIONS(drv) |
| 861 | |
| 862 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 863 | * pppoe_stats_ops |
| 864 | */ |
| 865 | NSS_STATS_DECLARE_FILE_OPERATIONS(pppoe) |
| 866 | |
| 867 | /* |
| 868 | * gmac_stats_ops |
| 869 | */ |
| 870 | NSS_STATS_DECLARE_FILE_OPERATIONS(gmac) |
| 871 | |
| 872 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 873 | * eth_rx_stats_ops |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 874 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 875 | NSS_STATS_DECLARE_FILE_OPERATIONS(eth_rx) |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 876 | |
| 877 | /* |
| 878 | * nss_stats_init() |
| 879 | * Enable NSS statistics |
| 880 | */ |
| 881 | void nss_stats_init(void) |
| 882 | { |
| 883 | /* |
| 884 | * NSS driver entry |
| 885 | */ |
| 886 | nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL); |
| 887 | if (unlikely(nss_top_main.top_dentry == NULL)) { |
| 888 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 889 | |
| 890 | /* |
| 891 | * Non availability of debugfs directory is not a catastrophy |
| 892 | * We can still go ahead with other initialization |
| 893 | */ |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | nss_top_main.stats_dentry = debugfs_create_dir("stats", nss_top_main.top_dentry); |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 898 | if (unlikely(nss_top_main.stats_dentry == NULL)) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 899 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 900 | |
| 901 | /* |
| 902 | * Non availability of debugfs directory is not a catastrophy |
| 903 | * We can still go ahead with rest of initialization |
| 904 | */ |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | /* |
| 909 | * Create files to obtain statistics |
| 910 | */ |
| 911 | |
| 912 | /* |
| 913 | * ipv4_stats |
| 914 | */ |
| 915 | nss_top_main.ipv4_dentry = debugfs_create_file("ipv4", 0400, |
| 916 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_ops); |
| 917 | if (unlikely(nss_top_main.ipv4_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 918 | nss_warning("Failed to create qca-nss-drv/stats/ipv4 file in debugfs"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * ipv6_stats |
| 924 | */ |
| 925 | nss_top_main.ipv6_dentry = debugfs_create_file("ipv6", 0400, |
| 926 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_ops); |
| 927 | if (unlikely(nss_top_main.ipv6_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 928 | nss_warning("Failed to create qca-nss-drv/stats/ipv6 file in debugfs"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 929 | return; |
| 930 | } |
| 931 | |
| 932 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 933 | * ipv6_stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 934 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 935 | nss_top_main.eth_rx_dentry = debugfs_create_file("eth_rx", 0400, |
| 936 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_eth_rx_ops); |
| 937 | if (unlikely(nss_top_main.eth_rx_dentry == NULL)) { |
| 938 | nss_warning("Failed to create qca-nss-drv/stats/eth_rx file in debugfs"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 939 | return; |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * n2h_stats |
| 944 | */ |
| 945 | nss_top_main.n2h_dentry = debugfs_create_file("n2h", 0400, |
| 946 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_n2h_ops); |
| 947 | if (unlikely(nss_top_main.n2h_dentry == NULL)) { |
| 948 | nss_warning("Failed to create qca-nss-drv/stats/n2h directory in debugfs"); |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | * drv_stats |
| 954 | */ |
| 955 | nss_top_main.drv_dentry = debugfs_create_file("drv", 0400, |
| 956 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_drv_ops); |
| 957 | if (unlikely(nss_top_main.drv_dentry == NULL)) { |
| 958 | nss_warning("Failed to create qca-nss-drv/stats/drv directory in debugfs"); |
| 959 | return; |
| 960 | } |
| 961 | |
| 962 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 963 | * pppoe_stats |
| 964 | */ |
| 965 | nss_top_main.pppoe_dentry = debugfs_create_file("pppoe", 0400, |
| 966 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pppoe_ops); |
| 967 | if (unlikely(nss_top_main.pppoe_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 968 | nss_warning("Failed to create qca-nss-drv/stats/pppoe file in debugfs"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 969 | return; |
| 970 | } |
| 971 | |
| 972 | /* |
| 973 | * gmac_stats |
| 974 | */ |
| 975 | nss_top_main.gmac_dentry = debugfs_create_file("gmac", 0400, |
| 976 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gmac_ops); |
| 977 | if (unlikely(nss_top_main.gmac_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 978 | nss_warning("Failed to create qca-nss-drv/stats/gmac file in debugfs"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 979 | return; |
| 980 | } |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | |
| 984 | /* |
| 985 | * nss_stats_clean() |
| 986 | * Cleanup NSS statistics files |
| 987 | */ |
| 988 | void nss_stats_clean(void) |
| 989 | { |
| 990 | /* |
| 991 | * Remove debugfs tree |
| 992 | */ |
| 993 | if (likely(nss_top_main.top_dentry != NULL)) { |
| 994 | debugfs_remove_recursive(nss_top_main.top_dentry); |
| 995 | } |
| 996 | } |