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