Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Manish Verma | 51973ce | 2020-01-20 23:13:37 +0530 | [diff] [blame] | 3 | * Copyright (c) 2013-2020, 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 | |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 17 | #include "nss_core.h" |
Wayne Tan | b45933c | 2020-01-06 17:19:25 -0800 | [diff] [blame^] | 18 | #include "nss_strings.h" |
Thomas Wu | c3e382c | 2014-10-29 15:35:13 -0700 | [diff] [blame] | 19 | |
| 20 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 21 | * Maximum banner length: |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 22 | */ |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 23 | #define NSS_STATS_BANNER_MAX_LENGTH 80 |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 24 | |
| 25 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 26 | * Maximum number of digits a stats value can have: |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 27 | */ |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 28 | #define NSS_STATS_DIGITS_MAX 16 |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 29 | |
| 30 | /* |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 31 | * Spaces to print core details inside banner |
| 32 | */ |
| 33 | #define NSS_STATS_BANNER_SPACES 12 |
| 34 | |
| 35 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 36 | * Max characters for a node name. |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 37 | */ |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 38 | #define NSS_STATS_NODE_NAME_MAX 24 |
| 39 | |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 40 | int nonzero_stats_print = 0; |
| 41 | |
| 42 | /* |
| 43 | * nss_stats_spacing() |
| 44 | * Framework to maintain consistent spacing between stats value and stats type. |
| 45 | */ |
| 46 | static size_t nss_stats_spacing(uint64_t stats_val, char *lbuf, size_t size_wr, size_t size_al) |
| 47 | { |
| 48 | int i; |
| 49 | int digit_counter = (stats_val == 0 ? 1 : 0); |
| 50 | while (stats_val != 0) { |
| 51 | /* |
| 52 | * TODO: need to check for (nss_ptr_t) |
| 53 | */ |
| 54 | stats_val = (nss_ptr_t)stats_val / 10; |
| 55 | digit_counter++; |
| 56 | } |
| 57 | |
| 58 | for (i = 0; i < NSS_STATS_DIGITS_MAX - digit_counter; i++) { |
| 59 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, " "); |
| 60 | } |
| 61 | |
| 62 | return size_wr; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * nss_stats_nonzero_handler() |
| 67 | * Handler to take nonzero stats print configuration. |
| 68 | */ |
| 69 | static int nss_stats_nonzero_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 70 | { |
| 71 | int ret; |
| 72 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static struct ctl_table nss_stats_table[] = { |
| 77 | { |
| 78 | .procname = "non_zero_stats", |
| 79 | .data = &nonzero_stats_print, |
| 80 | .maxlen = sizeof(int), |
| 81 | .mode = 0644, |
| 82 | .proc_handler = &nss_stats_nonzero_handler, |
| 83 | }, |
| 84 | { } |
| 85 | }; |
| 86 | |
| 87 | static struct ctl_table nss_stats_dir[] = { |
| 88 | { |
| 89 | .procname = "stats", |
| 90 | .mode = 0555, |
| 91 | .child = nss_stats_table, |
| 92 | }, |
| 93 | { } |
| 94 | }; |
| 95 | |
| 96 | static struct ctl_table nss_stats_root_dir[] = { |
| 97 | { |
| 98 | .procname = "nss", |
| 99 | .mode = 0555, |
| 100 | .child = nss_stats_dir, |
| 101 | }, |
| 102 | { } |
| 103 | }; |
| 104 | |
| 105 | static struct ctl_table nss_stats_root[] = { |
| 106 | { |
| 107 | .procname = "dev", |
| 108 | .mode = 0555, |
| 109 | .child = nss_stats_root_dir, |
| 110 | }, |
| 111 | { } |
| 112 | }; |
| 113 | static struct ctl_table_header *nss_stats_header; |
| 114 | |
| 115 | /* |
| 116 | * nss_stats_register_sysctl() |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 117 | * Register a sysctl table for stats. |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 118 | */ |
| 119 | void nss_stats_register_sysctl(void) |
| 120 | { |
| 121 | /* |
| 122 | * Register sysctl table. |
| 123 | */ |
| 124 | nss_stats_header = register_sysctl_table(nss_stats_root); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * nss_stats_open() |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 129 | * Opens stats file. |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 130 | */ |
| 131 | int nss_stats_open(struct inode *inode, struct file *filp) |
| 132 | { |
| 133 | struct nss_stats_data *data = NULL; |
| 134 | |
| 135 | data = kzalloc(sizeof(struct nss_stats_data), GFP_KERNEL); |
| 136 | if (!data) { |
| 137 | return -ENOMEM; |
| 138 | } |
| 139 | |
| 140 | memset(data, 0, sizeof (struct nss_stats_data)); |
| 141 | data->if_num = NSS_DYNAMIC_IF_START; |
| 142 | data->index = 0; |
| 143 | data->edma_id = (nss_ptr_t)inode->i_private; |
| 144 | data->nss_ctx = (struct nss_ctx_instance *)(inode->i_private); |
| 145 | filp->private_data = data; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * nss_stats_release() |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 152 | * Releases stats file. |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 153 | */ |
| 154 | int nss_stats_release(struct inode *inode, struct file *filp) |
| 155 | { |
| 156 | struct nss_stats_data *data = filp->private_data; |
| 157 | |
| 158 | if (data) { |
| 159 | kfree(data); |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * nss_stats_clean() |
| 167 | * Cleanup NSS statistics files. |
| 168 | */ |
| 169 | void nss_stats_clean(void) |
| 170 | { |
| 171 | /* |
| 172 | * Remove debugfs tree |
| 173 | */ |
| 174 | if (likely(nss_top_main.top_dentry != NULL)) { |
| 175 | debugfs_remove_recursive(nss_top_main.top_dentry); |
| 176 | nss_top_main.top_dentry = NULL; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /* |
Manish Verma | 51973ce | 2020-01-20 23:13:37 +0530 | [diff] [blame] | 181 | * nss_stats_reset_common_stats() |
| 182 | * Reset common node statistics. |
| 183 | */ |
| 184 | void nss_stats_reset_common_stats(uint32_t if_num) |
| 185 | { |
| 186 | if (unlikely(if_num >= NSS_MAX_NET_INTERFACES)) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | spin_lock_bh(&nss_top_main.stats_lock); |
| 191 | memset(nss_top_main.stats_node[if_num], 0, NSS_STATS_NODE_MAX * sizeof(uint64_t)); |
| 192 | spin_unlock_bh(&nss_top_main.stats_lock); |
| 193 | } |
| 194 | |
| 195 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 196 | * nss_stats_fill_common_stats() |
| 197 | * Fill common node statistics. |
| 198 | */ |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 199 | size_t nss_stats_fill_common_stats(uint32_t if_num, int instance, char *lbuf, size_t size_wr, size_t size_al, char *node) |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 200 | { |
| 201 | uint64_t stats_val[NSS_STATS_NODE_MAX]; |
| 202 | int i; |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 203 | size_t orig_size_wr = size_wr; |
| 204 | |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 205 | spin_lock_bh(&nss_top_main.stats_lock); |
| 206 | for (i = 0; i < NSS_STATS_NODE_MAX; i++) { |
| 207 | stats_val[i] = nss_top_main.stats_node[if_num][i]; |
| 208 | } |
| 209 | |
| 210 | spin_unlock_bh(&nss_top_main.stats_lock); |
Wayne Tan | b45933c | 2020-01-06 17:19:25 -0800 | [diff] [blame^] | 211 | size_wr += nss_stats_print(node, NULL, instance, nss_strings_stats_node, stats_val, NSS_STATS_NODE_MAX, lbuf, size_wr, size_al); |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 212 | return size_wr - orig_size_wr; |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* |
| 216 | * nss_stats_banner() |
| 217 | * Printing banner for node. |
| 218 | */ |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 219 | size_t nss_stats_banner(char *lbuf, size_t size_wr, size_t size_al, char *node, int core) |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 220 | { |
| 221 | uint16_t banner_char_length, i; |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 222 | size_t orig_size_wr = size_wr; |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 223 | char node_upr[NSS_STATS_NODE_NAME_MAX + 1]; |
| 224 | |
| 225 | if (strlen(node) > NSS_STATS_NODE_NAME_MAX) { |
| 226 | nss_warning("Node name %s larger than %d characters\n", node, NSS_STATS_NODE_NAME_MAX); |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n"); |
| 231 | for (i = 0; i < NSS_STATS_BANNER_MAX_LENGTH ; i++) { |
| 232 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "_"); |
| 233 | } |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 234 | if (core > NSS_STATS_SINGLE_CORE) { |
| 235 | banner_char_length = (uint16_t)((NSS_STATS_BANNER_MAX_LENGTH - (strlen(node) + NSS_STATS_BANNER_SPACES)) / 2); |
| 236 | } else { |
| 237 | banner_char_length = (uint16_t)((NSS_STATS_BANNER_MAX_LENGTH - (strlen(node) + 2)) / 2); |
| 238 | } |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 239 | |
| 240 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n\n"); |
| 241 | for (i = 0; i < banner_char_length; i++) { |
| 242 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "<"); |
| 243 | } |
| 244 | |
| 245 | strlcpy(node_upr, node, NSS_STATS_NODE_NAME_MAX); |
| 246 | for (i = 0; node_upr[i] != '\0' && i < NSS_STATS_NODE_NAME_MAX; i++) { |
| 247 | node_upr[i] = toupper(node_upr[i]); |
| 248 | } |
| 249 | |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 250 | /* |
| 251 | * TODO: Enhance so that both core0 and core1 print the same way for a |
| 252 | * node that has presence in both cores. i.e. Core0 should have [CORE 0] |
| 253 | * and not just Core1. |
| 254 | */ |
| 255 | if (core > 1) { |
| 256 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, " %s [CORE %d] ", node_upr, core); |
| 257 | } else { |
| 258 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, " %s ", node_upr); |
| 259 | } |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 260 | for (i = 0; i < banner_char_length; i++) { |
| 261 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, ">"); |
| 262 | } |
| 263 | |
| 264 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n"); |
| 265 | for (i = 0; i < NSS_STATS_BANNER_MAX_LENGTH; i++) { |
| 266 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "_"); |
| 267 | } |
| 268 | |
| 269 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n\n"); |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 270 | return size_wr - orig_size_wr; |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* |
| 274 | * nss_stats_print() |
| 275 | * Helper API to print stats. |
| 276 | */ |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 277 | size_t nss_stats_print(char *node, char *stat_details, int instance, struct nss_stats_info *stats_info, |
| 278 | uint64_t *stats_val, uint16_t max, char *lbuf, size_t size_wr, size_t size_al) |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 279 | { |
| 280 | uint16_t i, j; |
| 281 | uint16_t maxlen = 0; |
| 282 | char stats_string[NSS_STATS_MAX_STR_LENGTH]; |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 283 | size_t orig_size_wr = size_wr; |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 284 | char node_lwr[NSS_STATS_NODE_NAME_MAX + 1]; |
| 285 | |
| 286 | if (strlen(node) > NSS_STATS_NODE_NAME_MAX) { |
| 287 | nss_warning("Node name %s (%u chars) is longer than max chars of %d\n", |
| 288 | node, (uint32_t)strlen(node), NSS_STATS_NODE_NAME_MAX); |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Calculating the maximum of the array for indentation purposes. |
| 294 | */ |
| 295 | for (i = 0; i < max; i++){ |
| 296 | if (strlen(stats_info[i].stats_name) > maxlen) { |
| 297 | maxlen = strlen(stats_info[i].stats_name); |
| 298 | } |
| 299 | } |
| 300 | |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 301 | if (stat_details != NULL) { |
| 302 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n#%s\n\n", stat_details); |
| 303 | } |
| 304 | |
| 305 | for (i = 0; i < max; i++){ |
| 306 | if (nonzero_stats_print == 1 && stats_val[i] == 0) { |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | strlcpy(stats_string, stats_info[i].stats_name, NSS_STATS_MAX_STR_LENGTH); |
| 311 | |
| 312 | /* |
| 313 | * Converting uppercase to lower case. |
| 314 | */ |
| 315 | for (j = 0; stats_string[j] != '\0' && j < NSS_STATS_MAX_STR_LENGTH; j++) { |
| 316 | stats_string[j] = tolower(stats_string[j]); |
| 317 | } |
| 318 | |
| 319 | strlcpy(node_lwr, node, NSS_STATS_NODE_NAME_MAX); |
| 320 | for (j = 0; node_lwr[j] != '\0' && j < NSS_STATS_NODE_NAME_MAX; j++) { |
| 321 | node_lwr[j] = tolower(node_lwr[j]); |
| 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Space before %s is needed to avoid printing stat name from start of the line. |
| 326 | */ |
| 327 | if (instance < 0) { |
| 328 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\t%s_%s", node_lwr, stats_string); |
| 329 | } else { |
| 330 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\t%s[%d]_%s", node_lwr, instance, stats_string); |
| 331 | } |
| 332 | |
| 333 | for (j = 0; j < (1 + maxlen - strlen(stats_string)); j++){ |
| 334 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, " "); |
| 335 | } |
| 336 | |
| 337 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "= %llu", stats_val[i]); |
| 338 | size_wr = nss_stats_spacing(stats_val[i], lbuf, size_wr, size_al); |
| 339 | |
| 340 | /* |
| 341 | * Switch case will take care of the indentation and spacing details. |
| 342 | */ |
| 343 | switch (stats_info[i].stats_type) { |
| 344 | case NSS_STATS_TYPE_COMMON: |
| 345 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common\n"); |
| 346 | break; |
| 347 | |
| 348 | case NSS_STATS_TYPE_SPECIAL: |
| 349 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "special\n"); |
| 350 | break; |
| 351 | |
| 352 | case NSS_STATS_TYPE_DROP: |
| 353 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "drop\n"); |
| 354 | break; |
| 355 | |
| 356 | case NSS_STATS_TYPE_ERROR: |
| 357 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "error\n"); |
| 358 | break; |
| 359 | |
| 360 | case NSS_STATS_TYPE_EXCEPTION: |
| 361 | size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "exception\n"); |
| 362 | break; |
| 363 | |
| 364 | default: |
| 365 | nss_warning("unknown statistics type"); |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 370 | return size_wr - orig_size_wr; |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 373 | /* |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 374 | * nss_stats_create_dentry() |
| 375 | * Create statistics debug entry for subsystem. |
Murat Sezgin | 99dab64 | 2014-08-28 14:40:34 -0700 | [diff] [blame] | 376 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 377 | void nss_stats_create_dentry(char *name, const struct file_operations *ops) |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 378 | { |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 379 | if (!debugfs_create_file(name, 0400, nss_top_main.stats_dentry, &nss_top_main, ops)) { |
Cemil Coskun | 26be616 | 2019-06-28 15:44:48 -0700 | [diff] [blame] | 380 | nss_warning("Failed to create debug entry for subsystem %s\n", name); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 381 | } |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 382 | } |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 383 | |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 384 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 385 | * TODO: Move the rest of the code to (nss_wt_stats.c, nss_gmac_stats.c, nss_drv_stats.c) accordingly. |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 386 | */ |
Saurabh Misra | 09dddeb | 2014-09-30 16:38:07 -0700 | [diff] [blame] | 387 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 388 | /* |
| 389 | * drv_stats_ops |
| 390 | */ |
Wayne Tan | b45933c | 2020-01-06 17:19:25 -0800 | [diff] [blame^] | 391 | NSS_STATS_DECLARE_FILE_OPERATIONS(drv); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 392 | |
| 393 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 394 | * gmac_stats_ops |
| 395 | */ |
Wayne Tan | b45933c | 2020-01-06 17:19:25 -0800 | [diff] [blame^] | 396 | NSS_STATS_DECLARE_FILE_OPERATIONS(gmac); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 397 | |
| 398 | /* |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 399 | * wt_stats_ops |
| 400 | */ |
Wayne Tan | b45933c | 2020-01-06 17:19:25 -0800 | [diff] [blame^] | 401 | NSS_STATS_DECLARE_FILE_OPERATIONS(wt); |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 402 | |
| 403 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 404 | * nss_stats_init() |
Sakthi Vignesh Radhakrishnan | 1ceafde | 2019-08-23 13:05:00 -0700 | [diff] [blame] | 405 | * Enable NSS statistics. |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 406 | */ |
| 407 | void nss_stats_init(void) |
| 408 | { |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 409 | struct dentry *core_dentry = NULL; |
| 410 | struct dentry *wt_dentry = NULL; |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 411 | char file_name[10]; |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 412 | int i; |
Shashank Balashankar | 512cb60 | 2016-08-01 17:57:42 -0700 | [diff] [blame] | 413 | |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 414 | /* |
| 415 | * NSS driver entry |
| 416 | */ |
| 417 | nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL); |
| 418 | if (unlikely(nss_top_main.top_dentry == NULL)) { |
| 419 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 420 | |
| 421 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 422 | * Non availability of debugfs directory is not a catastrophy. |
| 423 | * We can still go ahead with other initialization. |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 424 | */ |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | 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] | 429 | if (unlikely(nss_top_main.stats_dentry == NULL)) { |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 430 | nss_warning("Failed to create qca-nss-drv directory in debugfs"); |
| 431 | |
| 432 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 433 | * Non availability of debugfs directory is not a catastrophy. |
| 434 | * We can still go ahead with rest of initialization. |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 435 | */ |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | /* |
Sakthi Vignesh Radhakrishnan | 150c559 | 2019-07-02 10:17:44 -0700 | [diff] [blame] | 440 | * Create files to obtain statistics. |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 441 | */ |
| 442 | |
| 443 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 444 | * drv_stats |
| 445 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 446 | nss_stats_create_dentry("drv", &nss_drv_stats_ops); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * gmac_stats |
| 450 | */ |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 451 | nss_stats_create_dentry("gmac", &nss_gmac_stats_ops); |
Aniruddha Paul | 1b170c2 | 2017-05-29 12:30:39 +0530 | [diff] [blame] | 452 | |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 453 | /* |
| 454 | * Per-project stats |
| 455 | */ |
| 456 | nss_top_main.project_dentry = debugfs_create_dir("project", |
| 457 | nss_top_main.stats_dentry); |
| 458 | if (unlikely(nss_top_main.project_dentry == NULL)) { |
| 459 | nss_warning("Failed to create qca-nss-drv/stats/project directory in debugfs"); |
| 460 | return; |
| 461 | } |
| 462 | |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 463 | for (i = 0; i < nss_top_main.num_nss; ++i) { |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 464 | memset(file_name, 0, sizeof(file_name)); |
| 465 | scnprintf(file_name, sizeof(file_name), "core%d", i); |
| 466 | core_dentry = debugfs_create_dir(file_name, |
| 467 | nss_top_main.project_dentry); |
| 468 | if (unlikely(core_dentry == NULL)) { |
| 469 | nss_warning("Failed to create qca-nss-drv/stats/project/core%d directory in debugfs", i); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | wt_dentry = debugfs_create_file("worker_threads", |
| 474 | 0400, |
| 475 | core_dentry, |
| 476 | &(nss_top_main.nss[i]), |
Yu Huang | 8c10708 | 2017-07-24 14:58:26 -0700 | [diff] [blame] | 477 | &nss_wt_stats_ops); |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 478 | if (unlikely(wt_dentry == NULL)) { |
| 479 | nss_warning("Failed to create qca-nss-drv/stats/project/core%d/worker_threads file in debugfs", i); |
| 480 | return; |
| 481 | } |
| 482 | } |
| 483 | |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 484 | nss_log_init(); |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 485 | } |