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