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 | /* |
| 155 | * nss_stats_str_if_exception_unknown |
| 156 | * Interface stats strings for unknown exceptions |
| 157 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 158 | static int8_t *nss_stats_str_if_exception_eth_rx[NSS_EXCEPTION_EVENT_ETH_RX_MAX] = { |
| 159 | "UNKNOWN_L3_PROTOCOL" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | /* |
| 163 | * nss_stats_str_if_exception_ipv4 |
| 164 | * Interface stats strings for ipv4 exceptions |
| 165 | */ |
| 166 | static int8_t *nss_stats_str_if_exception_ipv4[NSS_EXCEPTION_EVENT_IPV4_MAX] = { |
| 167 | "IPV4_ICMP_HEADER_INCOMPLETE", |
| 168 | "IPV4_ICMP_UNHANDLED_TYPE", |
| 169 | "IPV4_ICMP_IPV4_HEADER_INCOMPLETE", |
| 170 | "IPV4_ICMP_IPV4_UDP_HEADER_INCOMPLETE", |
| 171 | "IPV4_ICMP_IPV4_TCP_HEADER_INCOMPLETE", |
| 172 | "IPV4_ICMP_IPV4_UNKNOWN_PROTOCOL", |
| 173 | "IPV4_ICMP_NO_ICME", |
| 174 | "IPV4_ICMP_FLUSH_TO_HOST", |
| 175 | "IPV4_TCP_HEADER_INCOMPLETE", |
| 176 | "IPV4_TCP_NO_ICME", |
| 177 | "IPV4_TCP_IP_OPTION", |
| 178 | "IPV4_TCP_IP_FRAGMENT", |
| 179 | "IPV4_TCP_SMALL_TTL", |
| 180 | "IPV4_TCP_NEEDS_FRAGMENTATION", |
| 181 | "IPV4_TCP_FLAGS", |
| 182 | "IPV4_TCP_SEQ_EXCEEDS_RIGHT_EDGE", |
| 183 | "IPV4_TCP_SMALL_DATA_OFFS", |
| 184 | "IPV4_TCP_BAD_SACK", |
| 185 | "IPV4_TCP_BIG_DATA_OFFS", |
| 186 | "IPV4_TCP_SEQ_BEFORE_LEFT_EDGE", |
| 187 | "IPV4_TCP_ACK_EXCEEDS_RIGHT_EDGE", |
| 188 | "IPV4_TCP_ACK_BEFORE_LEFT_EDGE", |
| 189 | "IPV4_UDP_HEADER_INCOMPLETE", |
| 190 | "IPV4_UDP_NO_ICME", |
| 191 | "IPV4_UDP_IP_OPTION", |
| 192 | "IPV4_UDP_IP_FRAGMENT", |
| 193 | "IPV4_UDP_SMALL_TTL", |
| 194 | "IPV4_UDP_NEEDS_FRAGMENTATION", |
| 195 | "IPV4_WRONG_TARGET_MAC", |
| 196 | "IPV4_HEADER_INCOMPLETE", |
| 197 | "IPV4_BAD_TOTAL_LENGTH", |
| 198 | "IPV4_BAD_CHECKSUM", |
| 199 | "IPV4_NON_INITIAL_FRAGMENT", |
| 200 | "IPV4_DATAGRAM_INCOMPLETE", |
| 201 | "IPV4_OPTIONS_INCOMPLETE", |
Radha krishna Simha Jiguru | 59a1a1c | 2014-01-27 18:29:40 +0530 | [diff] [blame] | 202 | "IPV4_UNKNOWN_PROTOCOL", |
| 203 | "IPV4_ESP_HEADER_INCOMPLETE", |
| 204 | "IPV4_ESP_NO_ICME", |
| 205 | "IPV4_ESP_IP_OPTION", |
| 206 | "IPV4_ESP_IP_FRAGMENT", |
| 207 | "IPV4_ESP_SMALL_TTL", |
| 208 | "IPV4_ESP_NEEDS_FRAGMENTATION", |
| 209 | "IPV4_INGRESS_VID_MISMATCH", |
| 210 | "IPV4_6RD_NO_ICME", |
| 211 | "IPV4_6RD_IP_OPTION", |
| 212 | "IPV4_6RD_IP_FRAGMENT", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 213 | "IPV4_6RD_NEEDS_FRAGMENTATION", |
| 214 | "IPV4_DSCP_MARKING_MISMATCH", |
Murat Sezgin | 7c5956a | 2014-05-12 09:59:51 -0700 | [diff] [blame] | 215 | "IPV4_VLAN_MARKING_MISMATCH", |
| 216 | "IPV4_INTERFACE_MISMATCH" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * nss_stats_str_if_exception_ipv6 |
| 221 | * Interface stats strings for ipv6 exceptions |
| 222 | */ |
| 223 | static int8_t *nss_stats_str_if_exception_ipv6[NSS_EXCEPTION_EVENT_IPV6_MAX] = { |
| 224 | "IPV6_ICMP_HEADER_INCOMPLETE", |
| 225 | "IPV6_ICMP_UNHANDLED_TYPE", |
| 226 | "IPV6_ICMP_IPV6_HEADER_INCOMPLETE", |
| 227 | "IPV6_ICMP_IPV6_UDP_HEADER_INCOMPLETE", |
| 228 | "IPV6_ICMP_IPV6_TCP_HEADER_INCOMPLETE", |
| 229 | "IPV6_ICMP_IPV6_UNKNOWN_PROTOCOL", |
| 230 | "IPV6_ICMP_NO_ICME", |
| 231 | "IPV6_ICMP_FLUSH_TO_HOST", |
| 232 | "IPV6_TCP_HEADER_INCOMPLETE", |
| 233 | "IPV6_TCP_NO_ICME", |
| 234 | "IPV6_TCP_SMALL_HOP_LIMIT", |
| 235 | "IPV6_TCP_NEEDS_FRAGMENTATION", |
| 236 | "IPV6_TCP_FLAGS", |
| 237 | "IPV6_TCP_SEQ_EXCEEDS_RIGHT_EDGE", |
| 238 | "IPV6_TCP_SMALL_DATA_OFFS", |
| 239 | "IPV6_TCP_BAD_SACK", |
| 240 | "IPV6_TCP_BIG_DATA_OFFS", |
| 241 | "IPV6_TCP_SEQ_BEFORE_LEFT_EDGE", |
| 242 | "IPV6_TCP_ACK_EXCEEDS_RIGHT_EDGE", |
| 243 | "IPV6_TCP_ACK_BEFORE_LEFT_EDGE", |
| 244 | "IPV6_UDP_HEADER_INCOMPLETE", |
| 245 | "IPV6_UDP_NO_ICME", |
| 246 | "IPV6_UDP_SMALL_HOP_LIMIT", |
| 247 | "IPV6_UDP_NEEDS_FRAGMENTATION", |
| 248 | "IPV6_WRONG_TARGET_MAC", |
| 249 | "IPV6_HEADER_INCOMPLETE", |
Radha krishna Simha Jiguru | 59a1a1c | 2014-01-27 18:29:40 +0530 | [diff] [blame] | 250 | "IPV6_UNKNOWN_PROTOCOL", |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 251 | "IPV6_INGRESS_VID_MISMATCH", |
| 252 | "IPV6_DSCP_MARKING_MISMATCH", |
| 253 | "IPV6_VLAN_MARKING_MISMATCH", |
Murat Sezgin | 7c5956a | 2014-05-12 09:59:51 -0700 | [diff] [blame] | 254 | "IPV6_INTERFACE_MISMATCH" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | /* |
| 258 | * nss_stats_str_if_exception_pppoe |
| 259 | * Interface stats strings for PPPoE exceptions |
| 260 | */ |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 261 | 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] | 262 | "PPPOE_WRONG_VERSION_OR_TYPE", |
| 263 | "PPPOE_WRONG_CODE", |
| 264 | "PPPOE_HEADER_INCOMPLETE", |
Murat Sezgin | 7c5956a | 2014-05-12 09:59:51 -0700 | [diff] [blame] | 265 | "PPPOE_UNSUPPORTED_PPP_PROTOCOL", |
| 266 | "PPPOE_INTERFACE_MISMATCH" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | /* |
| 270 | * nss_stats_ipv4_read() |
| 271 | * Read IPV4 stats |
| 272 | */ |
| 273 | static ssize_t nss_stats_ipv4_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 274 | { |
| 275 | int32_t i; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 276 | /* |
| 277 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 278 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 279 | 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] | 280 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 281 | size_t size_wr = 0; |
| 282 | ssize_t bytes_read = 0; |
| 283 | uint64_t *stats_shadow; |
| 284 | |
| 285 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 286 | if (unlikely(lbuf == NULL)) { |
| 287 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 288 | return 0; |
| 289 | } |
| 290 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 291 | /* |
| 292 | * Note: The assumption here is that exception event count is larger than other statistics count for IPv4 |
| 293 | */ |
| 294 | stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV4_MAX * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 295 | if (unlikely(stats_shadow == NULL)) { |
| 296 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 297 | return 0; |
| 298 | } |
| 299 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 300 | size_wr = scnprintf(lbuf, size_al, "ipv4 stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * Common node stats |
| 304 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 305 | 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] | 306 | spin_lock_bh(&nss_top_main.stats_lock); |
| 307 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 308 | stats_shadow[i] = nss_top_main.stats_node[NSS_IPV4_RX_INTERFACE][i]; |
| 309 | } |
| 310 | |
| 311 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 312 | |
| 313 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 314 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 315 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * IPv4 node stats |
| 320 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 321 | 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] | 322 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 323 | spin_lock_bh(&nss_top_main.stats_lock); |
| 324 | for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) { |
| 325 | stats_shadow[i] = nss_top_main.stats_ipv4[i]; |
| 326 | } |
| 327 | |
| 328 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 329 | |
| 330 | for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) { |
| 331 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 332 | "%s = %llu\n", nss_stats_str_ipv4[i], stats_shadow[i]); |
| 333 | } |
| 334 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 335 | /* |
| 336 | * Exception stats |
| 337 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 338 | 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] | 339 | |
| 340 | spin_lock_bh(&nss_top_main.stats_lock); |
| 341 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) { |
| 342 | stats_shadow[i] = nss_top_main.stats_if_exception_ipv4[i]; |
| 343 | } |
| 344 | |
| 345 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 346 | |
| 347 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) { |
| 348 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 349 | "%s = %llu\n", nss_stats_str_if_exception_ipv4[i], stats_shadow[i]); |
| 350 | } |
| 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 stats end\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 353 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 354 | kfree(lbuf); |
| 355 | kfree(stats_shadow); |
| 356 | |
| 357 | return bytes_read; |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * nss_stats_ipv6_read() |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 362 | * Read IPV6 stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 363 | */ |
| 364 | static ssize_t nss_stats_ipv6_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 365 | { |
| 366 | int32_t i; |
| 367 | |
| 368 | /* |
| 369 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 370 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 371 | 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] | 372 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 373 | size_t size_wr = 0; |
| 374 | ssize_t bytes_read = 0; |
| 375 | uint64_t *stats_shadow; |
| 376 | |
| 377 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 378 | if (unlikely(lbuf == NULL)) { |
| 379 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 380 | return 0; |
| 381 | } |
| 382 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 383 | /* |
| 384 | * Note: The assumption here is that exception event count is larger than other statistics count for IPv4 |
| 385 | */ |
| 386 | stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV6_MAX * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 387 | if (unlikely(stats_shadow == NULL)) { |
| 388 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 389 | return 0; |
| 390 | } |
| 391 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 392 | size_wr = scnprintf(lbuf, size_al, "ipv6 stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 393 | |
| 394 | /* |
| 395 | * Common node stats |
| 396 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 397 | 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] | 398 | spin_lock_bh(&nss_top_main.stats_lock); |
| 399 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 400 | stats_shadow[i] = nss_top_main.stats_node[NSS_IPV6_RX_INTERFACE][i]; |
| 401 | } |
| 402 | |
| 403 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 404 | |
| 405 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 406 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 407 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | * IPv6 node stats |
| 412 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 413 | 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] | 414 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 415 | spin_lock_bh(&nss_top_main.stats_lock); |
| 416 | for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) { |
| 417 | stats_shadow[i] = nss_top_main.stats_ipv6[i]; |
| 418 | } |
| 419 | |
| 420 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 421 | |
| 422 | for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) { |
| 423 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 424 | "%s = %llu\n", nss_stats_str_ipv6[i], stats_shadow[i]); |
| 425 | } |
| 426 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 427 | /* |
| 428 | * Exception stats |
| 429 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 430 | 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] | 431 | |
| 432 | spin_lock_bh(&nss_top_main.stats_lock); |
| 433 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) { |
| 434 | stats_shadow[i] = nss_top_main.stats_if_exception_ipv6[i]; |
| 435 | } |
| 436 | |
| 437 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 438 | |
| 439 | for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) { |
| 440 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 441 | "%s = %llu\n", nss_stats_str_if_exception_ipv6[i], stats_shadow[i]); |
| 442 | } |
| 443 | |
| 444 | 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] | 445 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 446 | kfree(lbuf); |
| 447 | kfree(stats_shadow); |
| 448 | |
| 449 | return bytes_read; |
| 450 | } |
| 451 | |
| 452 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 453 | * nss_stats_eth_rx_read() |
| 454 | * Read ETH_RX stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 455 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 456 | 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] | 457 | { |
| 458 | int32_t i; |
| 459 | |
| 460 | /* |
| 461 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 462 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 463 | uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_EXCEPTION_EVENT_ETH_RX_MAX + 3) + 5; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 464 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 465 | size_t size_wr = 0; |
| 466 | ssize_t bytes_read = 0; |
| 467 | uint64_t *stats_shadow; |
| 468 | |
| 469 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 470 | if (unlikely(lbuf == NULL)) { |
| 471 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 472 | return 0; |
| 473 | } |
| 474 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 475 | /* |
| 476 | * Note: The assumption here is that we do not have more than 64 stats |
| 477 | */ |
| 478 | stats_shadow = kzalloc(64 * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 479 | if (unlikely(stats_shadow == NULL)) { |
| 480 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 481 | return 0; |
| 482 | } |
| 483 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 484 | size_wr = scnprintf(lbuf, size_al,"eth_rx stats start:\n\n"); |
| 485 | |
| 486 | /* |
| 487 | * Common node stats |
| 488 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 489 | 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] | 490 | spin_lock_bh(&nss_top_main.stats_lock); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 491 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 492 | 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] | 493 | } |
| 494 | |
| 495 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 496 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 497 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 498 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 499 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 500 | } |
| 501 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 502 | /* |
| 503 | * Exception stats |
| 504 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 505 | 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] | 506 | |
| 507 | spin_lock_bh(&nss_top_main.stats_lock); |
| 508 | for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) { |
| 509 | stats_shadow[i] = nss_top_main.stats_if_exception_eth_rx[i]; |
| 510 | } |
| 511 | |
| 512 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 513 | |
| 514 | for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) { |
| 515 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 516 | "%s = %llu\n", nss_stats_str_if_exception_eth_rx[i], stats_shadow[i]); |
| 517 | } |
| 518 | |
| 519 | 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] | 520 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 521 | kfree(lbuf); |
| 522 | kfree(stats_shadow); |
| 523 | |
| 524 | return bytes_read; |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | * nss_stats_n2h_read() |
| 529 | * Read N2H stats |
| 530 | */ |
| 531 | static ssize_t nss_stats_n2h_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 532 | { |
| 533 | int32_t i; |
| 534 | |
| 535 | /* |
| 536 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 537 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 538 | 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] | 539 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 540 | size_t size_wr = 0; |
| 541 | ssize_t bytes_read = 0; |
| 542 | uint64_t *stats_shadow; |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 543 | int max = NSS_STATS_N2H_MAX - NSS_STATS_NODE_MAX; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 544 | |
| 545 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 546 | if (unlikely(lbuf == NULL)) { |
| 547 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | stats_shadow = kzalloc(NSS_STATS_N2H_MAX * 8, GFP_KERNEL); |
| 552 | if (unlikely(stats_shadow == NULL)) { |
| 553 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | size_wr = scnprintf(lbuf, size_al, "n2h stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 558 | |
| 559 | /* |
| 560 | * Common node stats |
| 561 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 562 | 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] | 563 | spin_lock_bh(&nss_top_main.stats_lock); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 564 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 565 | stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i]; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 569 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 570 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 571 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 572 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | * N2H node stats |
| 577 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 578 | 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] | 579 | spin_lock_bh(&nss_top_main.stats_lock); |
| 580 | for (i = NSS_STATS_NODE_MAX; (i < NSS_STATS_N2H_MAX); i++) { |
| 581 | stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i]; |
| 582 | } |
| 583 | |
| 584 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 585 | |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 586 | for (i = 0; i < max; i++) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 587 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
Murat Sezgin | 0c0561d | 2014-04-09 18:55:58 -0700 | [diff] [blame] | 588 | "%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] | 589 | } |
| 590 | |
| 591 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h stats end\n\n"); |
| 592 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 593 | kfree(lbuf); |
| 594 | kfree(stats_shadow); |
| 595 | |
| 596 | return bytes_read; |
| 597 | } |
| 598 | |
| 599 | /* |
| 600 | * nss_stats_drv_read() |
| 601 | * Read HLOS driver stats |
| 602 | */ |
| 603 | static ssize_t nss_stats_drv_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 604 | { |
| 605 | int32_t i; |
| 606 | |
| 607 | /* |
| 608 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 609 | */ |
| 610 | uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5; |
| 611 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 612 | size_t size_wr = 0; |
| 613 | ssize_t bytes_read = 0; |
| 614 | uint64_t *stats_shadow; |
| 615 | |
| 616 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 617 | if (unlikely(lbuf == NULL)) { |
| 618 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL); |
| 623 | if (unlikely(stats_shadow == NULL)) { |
| 624 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n"); |
| 629 | spin_lock_bh(&nss_top_main.stats_lock); |
| 630 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
| 631 | stats_shadow[i] = nss_top_main.stats_drv[i]; |
| 632 | } |
| 633 | |
| 634 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 635 | |
| 636 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
| 637 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 638 | "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]); |
| 639 | } |
| 640 | |
| 641 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n"); |
| 642 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 643 | kfree(lbuf); |
| 644 | kfree(stats_shadow); |
| 645 | |
| 646 | return bytes_read; |
| 647 | } |
| 648 | |
| 649 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 650 | * nss_stats_pppoe_read() |
| 651 | * Read PPPoE stats |
| 652 | */ |
| 653 | static ssize_t nss_stats_pppoe_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 654 | { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 655 | int32_t i, j, k; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 656 | |
| 657 | /* |
| 658 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 659 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 660 | 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] | 661 | ((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] | 662 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 663 | size_t size_wr = 0; |
| 664 | ssize_t bytes_read = 0; |
| 665 | uint64_t *stats_shadow; |
| 666 | |
| 667 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 668 | if (unlikely(lbuf == NULL)) { |
| 669 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 670 | return 0; |
| 671 | } |
| 672 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 673 | stats_shadow = kzalloc(64 * 8, GFP_KERNEL); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 674 | if (unlikely(stats_shadow == NULL)) { |
| 675 | nss_warning("Could not allocate memory for local shadow buffer"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 676 | kfree(lbuf); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | size_wr = scnprintf(lbuf, size_al, "pppoe stats start:\n\n"); |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 681 | |
| 682 | /* |
| 683 | * Common node stats |
| 684 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 685 | 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] | 686 | spin_lock_bh(&nss_top_main.stats_lock); |
| 687 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 688 | stats_shadow[i] = nss_top_main.stats_node[NSS_PPPOE_RX_INTERFACE][i]; |
| 689 | } |
| 690 | |
| 691 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 692 | |
| 693 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 694 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 695 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * PPPoE node stats |
| 700 | */ |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 701 | 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] | 702 | spin_lock_bh(&nss_top_main.stats_lock); |
| 703 | for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) { |
| 704 | stats_shadow[i] = nss_top_main.stats_pppoe[i]; |
| 705 | } |
| 706 | |
| 707 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 708 | |
| 709 | for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) { |
| 710 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 711 | "%s = %llu\n", nss_stats_str_pppoe[i], stats_shadow[i]); |
| 712 | } |
| 713 | |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 714 | /* |
| 715 | * Exception stats |
| 716 | */ |
| 717 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nException PPPoE:\n\n"); |
| 718 | |
| 719 | for (j = 0; j < NSS_MAX_PHYSICAL_INTERFACES; j++) { |
| 720 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nInterface %d:\n\n", j); |
| 721 | |
| 722 | spin_lock_bh(&nss_top_main.stats_lock); |
| 723 | for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) { |
Ankit Dhanuka | a1569ce | 2014-05-13 19:58:06 +0530 | [diff] [blame] | 724 | for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 725 | stats_shadow_pppoe_except[k][i] = nss_top_main.stats_if_exception_pppoe[j][k][i]; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 730 | |
| 731 | for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) { |
| 732 | 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] | 733 | for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) { |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 734 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 735 | "%s = %llu\n", |
| 736 | nss_stats_str_if_exception_pppoe[i], |
| 737 | stats_shadow_pppoe_except[k][i]); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe stats end\n\n"); |
| 742 | } |
| 743 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 744 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 745 | kfree(lbuf); |
| 746 | kfree(stats_shadow); |
| 747 | |
| 748 | return bytes_read; |
| 749 | } |
| 750 | |
| 751 | /* |
| 752 | * nss_stats_gmac_read() |
| 753 | * Read GMAC stats |
| 754 | */ |
| 755 | static ssize_t nss_stats_gmac_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
| 756 | { |
| 757 | uint32_t i, id; |
| 758 | |
| 759 | /* |
| 760 | * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank |
| 761 | */ |
| 762 | uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5; |
| 763 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 764 | size_t size_wr = 0; |
| 765 | ssize_t bytes_read = 0; |
| 766 | uint64_t *stats_shadow; |
| 767 | |
| 768 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 769 | if (unlikely(lbuf == NULL)) { |
| 770 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL); |
| 775 | if (unlikely(stats_shadow == NULL)) { |
| 776 | nss_warning("Could not allocate memory for local shadow buffer"); |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n"); |
| 781 | |
| 782 | for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) { |
| 783 | spin_lock_bh(&nss_top_main.stats_lock); |
| 784 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 785 | stats_shadow[i] = nss_top_main.stats_gmac[id][i]; |
| 786 | } |
| 787 | |
| 788 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 789 | |
| 790 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id); |
| 791 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 792 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 793 | "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]); |
| 794 | } |
| 795 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n"); |
| 796 | } |
| 797 | |
| 798 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n"); |
| 799 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 800 | kfree(lbuf); |
| 801 | kfree(stats_shadow); |
| 802 | |
| 803 | return bytes_read; |
| 804 | } |
| 805 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 806 | #define NSS_STATS_DECLARE_FILE_OPERATIONS(name) \ |
| 807 | static const struct file_operations nss_stats_##name##_ops = { \ |
| 808 | .open = simple_open, \ |
| 809 | .read = nss_stats_##name##_read, \ |
| 810 | .llseek = generic_file_llseek, \ |
| 811 | }; |
| 812 | |
| 813 | /* |
| 814 | * nss_ipv4_stats_ops |
| 815 | */ |
| 816 | NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4) |
| 817 | |
| 818 | /* |
| 819 | * ipv6_stats_ops |
| 820 | */ |
| 821 | NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6) |
| 822 | |
| 823 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 824 | * n2h_stats_ops |
| 825 | */ |
| 826 | NSS_STATS_DECLARE_FILE_OPERATIONS(n2h) |
| 827 | /* |
| 828 | * drv_stats_ops |
| 829 | */ |
| 830 | NSS_STATS_DECLARE_FILE_OPERATIONS(drv) |
| 831 | |
| 832 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 833 | * pppoe_stats_ops |
| 834 | */ |
| 835 | NSS_STATS_DECLARE_FILE_OPERATIONS(pppoe) |
| 836 | |
| 837 | /* |
| 838 | * gmac_stats_ops |
| 839 | */ |
| 840 | NSS_STATS_DECLARE_FILE_OPERATIONS(gmac) |
| 841 | |
| 842 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 843 | * eth_rx_stats_ops |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 844 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 845 | NSS_STATS_DECLARE_FILE_OPERATIONS(eth_rx) |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 846 | |
| 847 | /* |
| 848 | * nss_stats_init() |
| 849 | * Enable NSS statistics |
| 850 | */ |
| 851 | void nss_stats_init(void) |
| 852 | { |
| 853 | /* |
| 854 | * NSS driver entry |
| 855 | */ |
| 856 | nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL); |
| 857 | if (unlikely(nss_top_main.top_dentry == NULL)) { |
| 858 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 859 | |
| 860 | /* |
| 861 | * Non availability of debugfs directory is not a catastrophy |
| 862 | * We can still go ahead with other initialization |
| 863 | */ |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | 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] | 868 | if (unlikely(nss_top_main.stats_dentry == NULL)) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 869 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 870 | |
| 871 | /* |
| 872 | * Non availability of debugfs directory is not a catastrophy |
| 873 | * We can still go ahead with rest of initialization |
| 874 | */ |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | /* |
| 879 | * Create files to obtain statistics |
| 880 | */ |
| 881 | |
| 882 | /* |
| 883 | * ipv4_stats |
| 884 | */ |
| 885 | nss_top_main.ipv4_dentry = debugfs_create_file("ipv4", 0400, |
| 886 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_ops); |
| 887 | if (unlikely(nss_top_main.ipv4_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 888 | 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] | 889 | return; |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * ipv6_stats |
| 894 | */ |
| 895 | nss_top_main.ipv6_dentry = debugfs_create_file("ipv6", 0400, |
| 896 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_ops); |
| 897 | if (unlikely(nss_top_main.ipv6_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 898 | 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] | 899 | return; |
| 900 | } |
| 901 | |
| 902 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 903 | * ipv6_stats |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 904 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 905 | nss_top_main.eth_rx_dentry = debugfs_create_file("eth_rx", 0400, |
| 906 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_eth_rx_ops); |
| 907 | if (unlikely(nss_top_main.eth_rx_dentry == NULL)) { |
| 908 | 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] | 909 | return; |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * n2h_stats |
| 914 | */ |
| 915 | nss_top_main.n2h_dentry = debugfs_create_file("n2h", 0400, |
| 916 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_n2h_ops); |
| 917 | if (unlikely(nss_top_main.n2h_dentry == NULL)) { |
| 918 | nss_warning("Failed to create qca-nss-drv/stats/n2h directory in debugfs"); |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * drv_stats |
| 924 | */ |
| 925 | nss_top_main.drv_dentry = debugfs_create_file("drv", 0400, |
| 926 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_drv_ops); |
| 927 | if (unlikely(nss_top_main.drv_dentry == NULL)) { |
| 928 | nss_warning("Failed to create qca-nss-drv/stats/drv directory in debugfs"); |
| 929 | return; |
| 930 | } |
| 931 | |
| 932 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 933 | * pppoe_stats |
| 934 | */ |
| 935 | nss_top_main.pppoe_dentry = debugfs_create_file("pppoe", 0400, |
| 936 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pppoe_ops); |
| 937 | if (unlikely(nss_top_main.pppoe_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 938 | 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] | 939 | return; |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * gmac_stats |
| 944 | */ |
| 945 | nss_top_main.gmac_dentry = debugfs_create_file("gmac", 0400, |
| 946 | nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gmac_ops); |
| 947 | if (unlikely(nss_top_main.gmac_dentry == NULL)) { |
Abhishek Rastogi | 80f4eb1 | 2013-09-24 14:31:21 +0530 | [diff] [blame] | 948 | 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] | 949 | return; |
| 950 | } |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | |
| 954 | /* |
| 955 | * nss_stats_clean() |
| 956 | * Cleanup NSS statistics files |
| 957 | */ |
| 958 | void nss_stats_clean(void) |
| 959 | { |
| 960 | /* |
| 961 | * Remove debugfs tree |
| 962 | */ |
| 963 | if (likely(nss_top_main.top_dentry != NULL)) { |
| 964 | debugfs_remove_recursive(nss_top_main.top_dentry); |
| 965 | } |
| 966 | } |