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