Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, 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 | |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 23 | #include "nss_tx_rx_common.h" |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 24 | #include "nss_core.h" |
| 25 | #include "nss_stats.h" |
Thomas Wu | c3e382c | 2014-10-29 15:35:13 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 28 | * nss_stats_str_drv |
| 29 | * Host driver stats strings |
| 30 | */ |
| 31 | static int8_t *nss_stats_str_drv[NSS_STATS_DRV_MAX] = { |
| 32 | "nbuf_alloc_errors", |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 33 | "paged_buf_alloc_errors", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 34 | "tx_queue_full[0]", |
| 35 | "tx_queue_full[1]", |
| 36 | "tx_buffers_empty", |
Sachin Shashidhar | 475012b | 2017-03-13 16:56:07 -0700 | [diff] [blame] | 37 | "tx_paged_buffers_empty", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 38 | "tx_buffers_pkt", |
| 39 | "tx_buffers_cmd", |
| 40 | "tx_buffers_crypto", |
Murat Sezgin | b6e1a01 | 2015-09-29 14:06:37 -0700 | [diff] [blame] | 41 | "tx_buffers_reuse", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 42 | "rx_buffers_empty", |
| 43 | "rx_buffers_pkt", |
| 44 | "rx_buffers_cmd_resp", |
| 45 | "rx_buffers_status_sync", |
| 46 | "rx_buffers_crypto", |
Thomas Wu | 0acd816 | 2014-12-07 15:43:39 -0800 | [diff] [blame] | 47 | "rx_buffers_virtual", |
| 48 | "tx_skb_simple", |
| 49 | "tx_skb_nr_frags", |
| 50 | "tx_skb_fraglist", |
| 51 | "rx_skb_simple", |
| 52 | "rx_skb_nr_frags", |
| 53 | "rx_skb_fraglist", |
Sundarajan Srinivasan | 6e0366b | 2015-01-20 12:10:42 -0800 | [diff] [blame] | 54 | "rx_bad_desciptor", |
Thomas Wu | 1fbf521 | 2015-06-04 14:38:40 -0700 | [diff] [blame] | 55 | "nss_skb_count", |
| 56 | "rx_chain_seg_processed", |
| 57 | "rx_frag_seg_processed" |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 61 | * nss_stats_str_gmac |
| 62 | * GMAC stats strings |
| 63 | */ |
| 64 | static int8_t *nss_stats_str_gmac[NSS_STATS_GMAC_MAX] = { |
| 65 | "ticks", |
| 66 | "worst_ticks", |
| 67 | "iterations" |
| 68 | }; |
| 69 | |
| 70 | /* |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 71 | * nss_stats_str_node |
| 72 | * Interface stats strings per node |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 73 | */ |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 74 | static int8_t *nss_stats_str_node[NSS_STATS_NODE_MAX] = { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 75 | "rx_packets", |
| 76 | "rx_bytes", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 77 | "tx_packets", |
ratheesh kannoth | 93ba95c | 2017-07-13 15:52:52 +0530 | [diff] [blame] | 78 | "tx_bytes", |
| 79 | "rx_queue_0_dropped", |
| 80 | "rx_queue_1_dropped", |
| 81 | "rx_queue_2_dropped", |
| 82 | "rx_queue_3_dropped", |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 86 | * nss_stats_create_dentry() |
| 87 | * Create statistics debug entry for subsystem. |
Murat Sezgin | 99dab64 | 2014-08-28 14:40:34 -0700 | [diff] [blame] | 88 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 89 | void nss_stats_create_dentry(char *name, const struct file_operations *ops) |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 90 | { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 91 | if (!debugfs_create_file(name, 0400, nss_top_main.stats_dentry, &nss_top_main, ops)) { |
| 92 | nss_warning("Faied to create debug entry for subsystem %s\n", name); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 93 | } |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 94 | } |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 95 | |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 96 | /* |
| 97 | * nss_stats_fill_common_stats() |
| 98 | * Fill common node statistics. |
| 99 | */ |
| 100 | size_t nss_stats_fill_common_stats(uint32_t if_num, char *lbuf, size_t size_wr, size_t size_al) |
| 101 | { |
| 102 | uint64_t stats_shadow[NSS_STATS_NODE_MAX]; |
| 103 | int i; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 104 | |
Abhishek Rastogi | a1a0797 | 2014-04-01 19:43:33 +0530 | [diff] [blame] | 105 | 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] | 106 | spin_lock_bh(&nss_top_main.stats_lock); |
| 107 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 108 | stats_shadow[i] = nss_top_main.stats_node[if_num][i]; |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 109 | } |
Abhishek Rastogi | 84d95d0 | 2014-03-26 19:31:31 +0530 | [diff] [blame] | 110 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 111 | |
| 112 | for (i = 0; (i < NSS_STATS_NODE_MAX); i++) { |
| 113 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 114 | "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]); |
| 115 | } |
| 116 | |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 117 | return size_wr; |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 121 | * nss_drv_stats_read() |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 122 | * Read HLOS driver stats |
| 123 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 124 | static ssize_t nss_drv_stats_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] | 125 | { |
| 126 | int32_t i; |
| 127 | |
| 128 | /* |
| 129 | * max output lines = #stats + start tag line + end tag line + three blank lines |
| 130 | */ |
| 131 | uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5; |
| 132 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 133 | size_t size_wr = 0; |
| 134 | ssize_t bytes_read = 0; |
| 135 | uint64_t *stats_shadow; |
| 136 | |
| 137 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 138 | if (unlikely(lbuf == NULL)) { |
| 139 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL); |
| 144 | if (unlikely(stats_shadow == NULL)) { |
| 145 | nss_warning("Could not allocate memory for local shadow buffer"); |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 146 | kfree(lbuf); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 151 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
Sundarajan Srinivasan | 62fee7e | 2015-01-22 11:13:10 -0800 | [diff] [blame] | 152 | stats_shadow[i] = NSS_PKT_STATS_READ(&nss_top_main.stats_drv[i]); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 153 | } |
| 154 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 155 | for (i = 0; (i < NSS_STATS_DRV_MAX); i++) { |
| 156 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 157 | "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]); |
| 158 | } |
| 159 | |
| 160 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n"); |
| 161 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 162 | kfree(lbuf); |
| 163 | kfree(stats_shadow); |
| 164 | |
| 165 | return bytes_read; |
| 166 | } |
| 167 | |
| 168 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 169 | * nss_gmac_stats_read() |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 170 | * Read GMAC stats |
| 171 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 172 | static ssize_t nss_gmac_stats_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] | 173 | { |
| 174 | uint32_t i, id; |
| 175 | |
| 176 | /* |
| 177 | * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank |
| 178 | */ |
| 179 | uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5; |
| 180 | size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines; |
| 181 | size_t size_wr = 0; |
| 182 | ssize_t bytes_read = 0; |
| 183 | uint64_t *stats_shadow; |
| 184 | |
| 185 | char *lbuf = kzalloc(size_al, GFP_KERNEL); |
| 186 | if (unlikely(lbuf == NULL)) { |
| 187 | nss_warning("Could not allocate memory for local statistics buffer"); |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL); |
| 192 | if (unlikely(stats_shadow == NULL)) { |
| 193 | nss_warning("Could not allocate memory for local shadow buffer"); |
Ankit Dhanuka | 1499999 | 2014-11-12 15:35:11 +0530 | [diff] [blame] | 194 | kfree(lbuf); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n"); |
| 199 | |
| 200 | for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) { |
| 201 | spin_lock_bh(&nss_top_main.stats_lock); |
| 202 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 203 | stats_shadow[i] = nss_top_main.stats_gmac[id][i]; |
| 204 | } |
| 205 | |
| 206 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 207 | |
| 208 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id); |
| 209 | for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) { |
| 210 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 211 | "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]); |
| 212 | } |
Aniruddha Paul | 1b170c2 | 2017-05-29 12:30:39 +0530 | [diff] [blame] | 213 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n"); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n"); |
| 217 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 218 | kfree(lbuf); |
| 219 | kfree(stats_shadow); |
| 220 | |
| 221 | return bytes_read; |
| 222 | } |
| 223 | |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 224 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 225 | * nss_wt_stats_read() |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 226 | * Reads and formats worker thread statistics and outputs them to ubuf |
| 227 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 228 | static ssize_t nss_wt_stats_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos) |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 229 | { |
| 230 | struct nss_stats_data *data = fp->private_data; |
| 231 | struct nss_ctx_instance *nss_ctx = data->nss_ctx; |
| 232 | struct nss_project_irq_stats *shadow; |
| 233 | uint32_t thread_count = nss_ctx->worker_thread_count; |
| 234 | uint32_t irq_count = nss_ctx->irq_count; |
| 235 | |
| 236 | /* |
| 237 | * Three lines for each IRQ |
| 238 | */ |
| 239 | uint32_t max_output_lines = thread_count * 3 * irq_count; |
| 240 | size_t size_al = max_output_lines * NSS_STATS_MAX_STR_LENGTH; |
| 241 | size_t size_wr = 0; |
| 242 | ssize_t bytes_read = 0; |
| 243 | char *lbuf; |
| 244 | int i; |
| 245 | int j; |
| 246 | |
| 247 | lbuf = kzalloc(size_al, GFP_KERNEL); |
| 248 | if (unlikely(!lbuf)) { |
| 249 | nss_warning("Could not allocate memory for local statistics buffer\n"); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | shadow = kzalloc(thread_count * irq_count * sizeof(struct nss_project_irq_stats), GFP_KERNEL); |
| 254 | if (unlikely(!shadow)) { |
| 255 | nss_warning("Could not allocate memory for stats shadow\n"); |
| 256 | kfree(lbuf); |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | spin_lock_bh(&nss_top_main.stats_lock); |
| 261 | if (unlikely(!nss_ctx->wt_stats)) { |
| 262 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 263 | nss_warning("Worker thread statistics not allocated\n"); |
| 264 | kfree(lbuf); |
| 265 | kfree(shadow); |
| 266 | return 0; |
| 267 | } |
| 268 | for (i = 0; i < thread_count; ++i) { |
| 269 | |
| 270 | /* |
| 271 | * The statistics shadow is an array with thread_count * irq_count |
| 272 | * items in it. Each item is located at the index: |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 273 | * (thread number) * (irq_count) + (irq number) |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 274 | * thus simulating a two-dimensional array. |
| 275 | */ |
| 276 | for (j = 0; j < irq_count; ++j) { |
| 277 | shadow[i * irq_count + j] = nss_ctx->wt_stats[i].irq_stats[j]; |
| 278 | } |
| 279 | } |
| 280 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 281 | |
| 282 | for (i = 0; i < thread_count; ++i) { |
| 283 | for (j = 0; j < irq_count; ++j) { |
| 284 | struct nss_project_irq_stats *is = &(shadow[i * irq_count + j]); |
| 285 | if (!(is->count)) { |
| 286 | continue; |
| 287 | } |
| 288 | |
| 289 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 290 | "t-%d:irq-%d callback: 0x%x, count: %llu\n", |
| 291 | i, j, is->callback, is->count); |
| 292 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 293 | "t-%d:irq-%d tick min: %10u avg: %10u max:%10u\n", |
| 294 | i, j, is->ticks_min, is->ticks_avg, is->ticks_max); |
| 295 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, |
| 296 | "t-%d:irq-%d insn min: %10u avg: %10u max:%10u\n\n", |
| 297 | i, j, is->insn_min, is->insn_avg, is->insn_max); |
| 298 | } |
| 299 | } |
| 300 | bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf)); |
| 301 | kfree(lbuf); |
| 302 | kfree(shadow); |
| 303 | |
| 304 | return bytes_read; |
| 305 | } |
| 306 | |
| 307 | /* |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 308 | * nss_stats_open() |
| 309 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 310 | int nss_stats_open(struct inode *inode, struct file *filp) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 311 | { |
| 312 | struct nss_stats_data *data = NULL; |
| 313 | |
| 314 | data = kzalloc(sizeof(struct nss_stats_data), GFP_KERNEL); |
| 315 | if (!data) { |
| 316 | return -ENOMEM; |
| 317 | } |
| 318 | memset(data, 0, sizeof (struct nss_stats_data)); |
| 319 | data->if_num = NSS_DYNAMIC_IF_START; |
Ankit Dhanuka | 6228ebd | 2014-11-05 17:26:01 +0530 | [diff] [blame] | 320 | data->index = 0; |
Stephen Wang | aed4633 | 2016-12-12 17:29:03 -0800 | [diff] [blame] | 321 | data->edma_id = (nss_ptr_t)inode->i_private; |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 322 | data->nss_ctx = (struct nss_ctx_instance *)(inode->i_private); |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 323 | filp->private_data = data; |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * nss_stats_release() |
| 330 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 331 | int nss_stats_release(struct inode *inode, struct file *filp) |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 332 | { |
| 333 | struct nss_stats_data *data = filp->private_data; |
| 334 | |
| 335 | if (data) { |
| 336 | kfree(data); |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 342 | /* |
| 343 | * drv_stats_ops |
| 344 | */ |
| 345 | NSS_STATS_DECLARE_FILE_OPERATIONS(drv) |
| 346 | |
| 347 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 348 | * gmac_stats_ops |
| 349 | */ |
| 350 | NSS_STATS_DECLARE_FILE_OPERATIONS(gmac) |
| 351 | |
| 352 | /* |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 353 | * wt_stats_ops |
| 354 | */ |
| 355 | NSS_STATS_DECLARE_FILE_OPERATIONS(wt) |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * nss_stats_clean() |
| 359 | * Cleanup NSS statistics files |
| 360 | */ |
| 361 | void nss_stats_clean(void) |
| 362 | { |
| 363 | /* |
| 364 | * Remove debugfs tree |
| 365 | */ |
| 366 | if (likely(nss_top_main.top_dentry != NULL)) { |
| 367 | debugfs_remove_recursive(nss_top_main.top_dentry); |
| 368 | nss_top_main.top_dentry = NULL; |
| 369 | } |
| 370 | } |
| 371 | |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 372 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 373 | * nss_stats_init() |
| 374 | * Enable NSS statistics |
| 375 | */ |
| 376 | void nss_stats_init(void) |
| 377 | { |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 378 | struct dentry *core_dentry = NULL; |
| 379 | struct dentry *wt_dentry = NULL; |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 380 | char file_name[10]; |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 381 | int i; |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 382 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 383 | /* |
| 384 | * NSS driver entry |
| 385 | */ |
| 386 | nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL); |
| 387 | if (unlikely(nss_top_main.top_dentry == NULL)) { |
| 388 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 389 | |
| 390 | /* |
| 391 | * Non availability of debugfs directory is not a catastrophy |
| 392 | * We can still go ahead with other initialization |
| 393 | */ |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | 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] | 398 | if (unlikely(nss_top_main.stats_dentry == NULL)) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 399 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 400 | |
| 401 | /* |
| 402 | * Non availability of debugfs directory is not a catastrophy |
| 403 | * We can still go ahead with rest of initialization |
| 404 | */ |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Create files to obtain statistics |
| 410 | */ |
| 411 | |
| 412 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 413 | * drv_stats |
| 414 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 415 | nss_stats_create_dentry("drv", &nss_drv_stats_ops); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 416 | |
| 417 | /* |
| 418 | * gmac_stats |
| 419 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 420 | nss_stats_create_dentry("gmac", &nss_gmac_stats_ops); |
Aniruddha Paul | 1b170c2 | 2017-05-29 12:30:39 +0530 | [diff] [blame] | 421 | |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 422 | /* |
| 423 | * Per-project stats |
| 424 | */ |
| 425 | nss_top_main.project_dentry = debugfs_create_dir("project", |
| 426 | nss_top_main.stats_dentry); |
| 427 | if (unlikely(nss_top_main.project_dentry == NULL)) { |
| 428 | nss_warning("Failed to create qca-nss-drv/stats/project directory in debugfs"); |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | for (i = 0; i < NSS_MAX_CORES; ++i) { |
| 433 | memset(file_name, 0, sizeof(file_name)); |
| 434 | scnprintf(file_name, sizeof(file_name), "core%d", i); |
| 435 | core_dentry = debugfs_create_dir(file_name, |
| 436 | nss_top_main.project_dentry); |
| 437 | if (unlikely(core_dentry == NULL)) { |
| 438 | nss_warning("Failed to create qca-nss-drv/stats/project/core%d directory in debugfs", i); |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | wt_dentry = debugfs_create_file("worker_threads", |
| 443 | 0400, |
| 444 | core_dentry, |
| 445 | &(nss_top_main.nss[i]), |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 446 | &nss_wt_stats_ops); |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 447 | if (unlikely(wt_dentry == NULL)) { |
| 448 | nss_warning("Failed to create qca-nss-drv/stats/project/core%d/worker_threads file in debugfs", i); |
| 449 | return; |
| 450 | } |
| 451 | } |
| 452 | |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 453 | nss_log_init(); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 454 | } |