blob: e22c45e724b97a6018e443359d8bf1aa18b8ab4e [file] [log] [blame]
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301/* * Copyright (c) 2013 Qualcomm Atheros, Inc. * */
2
3/*
4 * nss_stats.c
5 * NSS stats APIs
6 *
7 */
8
9#include "nss_core.h"
10
11/*
12 * Maximum string length:
13 * This should be equal to maximum string size of any stats
14 * inclusive of stats value
15 */
16#define NSS_STATS_MAX_STR_LENGTH 96
17
18/*
19 * Global variables/extern declarations
20 */
21extern struct nss_top_instance nss_top_main;
22
23/*
24 * Statistics structures
25 */
26
27/*
28 * nss_stats_str_ipv4
29 * IPv4 stats strings
30 */
31static int8_t *nss_stats_str_ipv4[NSS_STATS_IPV4_MAX] = {
32 "rx_pkts",
33 "rx_bytes",
34 "tx_pkts",
35 "tx_bytes",
36 "create_requests",
37 "create_collisions",
38 "create_invalid_interface",
39 "destroy_requests",
40 "destroy_misses",
41 "hash_hits",
42 "hash_reorders",
43 "flushes",
44 "evictions"
45};
46
47/*
48 * nss_stats_str_ipv6
49 * IPv6 stats strings
50 */
51static int8_t *nss_stats_str_ipv6[NSS_STATS_IPV6_MAX] = {
52 "rx_pkts",
53 "rx_bytes",
54 "tx_pkts",
55 "tx_bytes",
56 "create_requests",
57 "create_collisions",
58 "create_invalid_interface",
59 "destroy_requests",
60 "destroy_misses",
61 "hash_hits",
62 "hash_reorders",
63 "flushes",
64 "evictions",
65};
66
67/*
68 * nss_stats_str_pbuf
69 * Pbuf stats strings
70 */
71static int8_t *nss_stats_str_pbuf[NSS_STATS_PBUF_MAX] = {
72 "pbuf_fails",
73 "payload_fails"
74};
75
76/*
77 * nss_stats_str_n2h
78 * N2H stats strings
79 */
80static int8_t *nss_stats_str_n2h[NSS_STATS_N2H_MAX] = {
81 "queue_dropped",
82 "ticks",
83 "worst_ticks",
84 "iterations"
85};
86
87/*
88 * nss_stats_str_drv
89 * Host driver stats strings
90 */
91static int8_t *nss_stats_str_drv[NSS_STATS_DRV_MAX] = {
92 "nbuf_alloc_errors",
93 "tx_queue_full[0]",
94 "tx_queue_full[1]",
95 "tx_buffers_empty",
96 "tx_buffers_pkt",
97 "tx_buffers_cmd",
98 "tx_buffers_crypto",
99 "rx_buffers_empty",
100 "rx_buffers_pkt",
101 "rx_buffers_cmd_resp",
102 "rx_buffers_status_sync",
103 "rx_buffers_crypto",
104 "rx_buffers_virtual"
105};
106
107/*
108 * nss_stats_str_ethbr
109 * Eth bridge stats strings
110 */
111static int8_t *nss_stats_str_ethbr[NSS_STATS_ETHBR_MAX] = {
112 "rx_pkts",
113 "rx_bytes",
114 "virtual_rx_pkts",
115 "virtual_rx_bytes",
116 "physical_rx_pkts",
117 "physical_rx_bytes",
118 "create_requests",
119 "create_collisions",
120 "create_invalid_interface",
121 "destroy_requests",
122 "destroy_misses",
123 "hash_hits",
124 "hash_reorders",
125 "flushes",
126 "evictions",
127 "queue_dropped",
128 "ticks",
129 "worst_ticks",
130 "iterations"
131};
132
133/*
134 * nss_stats_str_pppoe
135 * PPPoE stats strings
136 */
137static int8_t *nss_stats_str_pppoe[NSS_STATS_PPPOE_MAX] = {
138 "create_requests",
139 "create_failures",
140 "destroy_requests",
141 "destroy_misses"
142};
143
144/*
145 * nss_stats_str_gmac
146 * GMAC stats strings
147 */
148static int8_t *nss_stats_str_gmac[NSS_STATS_GMAC_MAX] = {
149 "ticks",
150 "worst_ticks",
151 "iterations"
152};
153
154/*
155 * nss_stats_str_if_host
156 * Interface stats strings for host
157 */
158static int8_t *nss_stats_str_if_host[NSS_STATS_IF_HOST_MAX] = {
159 "rx_packets",
160 "rx_bytes",
161 "tx_packets",
162 "tx_bytes",
163
164};
165
166/*
167 * nss_stats_str_if_ipv4
168 * Interface stats strings for ipv4
169 */
170static int8_t *nss_stats_str_if_ipv4[NSS_STATS_IF_IPV4_MAX] = {
171 "rx_packets",
172 "rx_bytes",
173 "tx_packets",
174 "tx_bytes"
175};
176
177/*
178 * nss_stats_str_if_ipv6
179 * Interface stats strings for ipv6
180 */
181static int8_t *nss_stats_str_if_ipv6[NSS_STATS_IF_IPV6_MAX] = {
182 "rx_packets",
183 "rx_bytes",
184 "tx_packets",
185 "tx_bytes"
186};
187
188/*
189 * nss_stats_str_if_exception_unknown
190 * Interface stats strings for unknown exceptions
191 */
192static int8_t *nss_stats_str_if_exception_unknown[NSS_EXCEPTION_EVENT_UNKNOWN_MAX] = {
193 "UNKNOWN_L2_PROTOCOL"
194};
195
196/*
197 * nss_stats_str_if_exception_ipv4
198 * Interface stats strings for ipv4 exceptions
199 */
200static int8_t *nss_stats_str_if_exception_ipv4[NSS_EXCEPTION_EVENT_IPV4_MAX] = {
201 "IPV4_ICMP_HEADER_INCOMPLETE",
202 "IPV4_ICMP_UNHANDLED_TYPE",
203 "IPV4_ICMP_IPV4_HEADER_INCOMPLETE",
204 "IPV4_ICMP_IPV4_UDP_HEADER_INCOMPLETE",
205 "IPV4_ICMP_IPV4_TCP_HEADER_INCOMPLETE",
206 "IPV4_ICMP_IPV4_UNKNOWN_PROTOCOL",
207 "IPV4_ICMP_NO_ICME",
208 "IPV4_ICMP_FLUSH_TO_HOST",
209 "IPV4_TCP_HEADER_INCOMPLETE",
210 "IPV4_TCP_NO_ICME",
211 "IPV4_TCP_IP_OPTION",
212 "IPV4_TCP_IP_FRAGMENT",
213 "IPV4_TCP_SMALL_TTL",
214 "IPV4_TCP_NEEDS_FRAGMENTATION",
215 "IPV4_TCP_FLAGS",
216 "IPV4_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
217 "IPV4_TCP_SMALL_DATA_OFFS",
218 "IPV4_TCP_BAD_SACK",
219 "IPV4_TCP_BIG_DATA_OFFS",
220 "IPV4_TCP_SEQ_BEFORE_LEFT_EDGE",
221 "IPV4_TCP_ACK_EXCEEDS_RIGHT_EDGE",
222 "IPV4_TCP_ACK_BEFORE_LEFT_EDGE",
223 "IPV4_UDP_HEADER_INCOMPLETE",
224 "IPV4_UDP_NO_ICME",
225 "IPV4_UDP_IP_OPTION",
226 "IPV4_UDP_IP_FRAGMENT",
227 "IPV4_UDP_SMALL_TTL",
228 "IPV4_UDP_NEEDS_FRAGMENTATION",
229 "IPV4_WRONG_TARGET_MAC",
230 "IPV4_HEADER_INCOMPLETE",
231 "IPV4_BAD_TOTAL_LENGTH",
232 "IPV4_BAD_CHECKSUM",
233 "IPV4_NON_INITIAL_FRAGMENT",
234 "IPV4_DATAGRAM_INCOMPLETE",
235 "IPV4_OPTIONS_INCOMPLETE",
236 "IPV4_UNKNOWN_PROTOCOL"
237};
238
239/*
240 * nss_stats_str_if_exception_ipv6
241 * Interface stats strings for ipv6 exceptions
242 */
243static int8_t *nss_stats_str_if_exception_ipv6[NSS_EXCEPTION_EVENT_IPV6_MAX] = {
244 "IPV6_ICMP_HEADER_INCOMPLETE",
245 "IPV6_ICMP_UNHANDLED_TYPE",
246 "IPV6_ICMP_IPV6_HEADER_INCOMPLETE",
247 "IPV6_ICMP_IPV6_UDP_HEADER_INCOMPLETE",
248 "IPV6_ICMP_IPV6_TCP_HEADER_INCOMPLETE",
249 "IPV6_ICMP_IPV6_UNKNOWN_PROTOCOL",
250 "IPV6_ICMP_NO_ICME",
251 "IPV6_ICMP_FLUSH_TO_HOST",
252 "IPV6_TCP_HEADER_INCOMPLETE",
253 "IPV6_TCP_NO_ICME",
254 "IPV6_TCP_SMALL_HOP_LIMIT",
255 "IPV6_TCP_NEEDS_FRAGMENTATION",
256 "IPV6_TCP_FLAGS",
257 "IPV6_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
258 "IPV6_TCP_SMALL_DATA_OFFS",
259 "IPV6_TCP_BAD_SACK",
260 "IPV6_TCP_BIG_DATA_OFFS",
261 "IPV6_TCP_SEQ_BEFORE_LEFT_EDGE",
262 "IPV6_TCP_ACK_EXCEEDS_RIGHT_EDGE",
263 "IPV6_TCP_ACK_BEFORE_LEFT_EDGE",
264 "IPV6_UDP_HEADER_INCOMPLETE",
265 "IPV6_UDP_NO_ICME",
266 "IPV6_UDP_SMALL_HOP_LIMIT",
267 "IPV6_UDP_NEEDS_FRAGMENTATION",
268 "IPV6_WRONG_TARGET_MAC",
269 "IPV6_HEADER_INCOMPLETE",
270 "IPV6_UNKNOWN_PROTOCOL"
271};
272
273/*
274 * nss_stats_str_if_exception_pppoe
275 * Interface stats strings for PPPoE exceptions
276 */
277static int8_t *nss_stats_str_if_exception_pppoe[NSS_EXCEPTION_EVENT_PPPOE_MAX] = {
278 "PPPOE_WRONG_VERSION_OR_TYPE",
279 "PPPOE_WRONG_CODE",
280 "PPPOE_HEADER_INCOMPLETE",
281 "PPPOE_UNSUPPORTED_PPP_PROTOCOL"
282};
283
284/*
285 * nss_stats_ipv4_read()
286 * Read IPV4 stats
287 */
288static ssize_t nss_stats_ipv4_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
289{
290 int32_t i;
291
292 /*
293 * max output lines = #stats + start tag line + end tag line + three blank lines
294 */
295 uint32_t max_output_lines = NSS_STATS_IPV4_MAX + 5;
296 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
297 size_t size_wr = 0;
298 ssize_t bytes_read = 0;
299 uint64_t *stats_shadow;
300
301 char *lbuf = kzalloc(size_al, GFP_KERNEL);
302 if (unlikely(lbuf == NULL)) {
303 nss_warning("Could not allocate memory for local statistics buffer");
304 return 0;
305 }
306
307 stats_shadow = kzalloc(NSS_STATS_IPV4_MAX * 8, GFP_KERNEL);
308 if (unlikely(stats_shadow == NULL)) {
309 nss_warning("Could not allocate memory for local shadow buffer");
310 return 0;
311 }
312
313 size_wr = scnprintf(lbuf, size_al,"ipv4 stats start:\n\n");
314 spin_lock_bh(&nss_top_main.stats_lock);
315 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
316 stats_shadow[i] = nss_top_main.stats_ipv4[i];
317 }
318
319 spin_unlock_bh(&nss_top_main.stats_lock);
320
321 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
322 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
323 "%s = %llu\n", nss_stats_str_ipv4[i], stats_shadow[i]);
324 }
325
326 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\nipv4 stats end\n\n");
327 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
328 kfree(lbuf);
329 kfree(stats_shadow);
330
331 return bytes_read;
332}
333
334/*
335 * nss_stats_ipv6_read()
336 * Read IPv6 stats
337 */
338static ssize_t nss_stats_ipv6_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
339{
340 int32_t i;
341
342 /*
343 * max output lines = #stats + start tag line + end tag line + three blank lines
344 */
345 uint32_t max_output_lines = NSS_STATS_IPV6_MAX + 5;
346 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
347 size_t size_wr = 0;
348 ssize_t bytes_read = 0;
349 uint64_t *stats_shadow;
350
351 char *lbuf = kzalloc(size_al, GFP_KERNEL);
352 if (unlikely(lbuf == NULL)) {
353 nss_warning("Could not allocate memory for local statistics buffer");
354 return 0;
355 }
356
357 stats_shadow = kzalloc(NSS_STATS_IPV6_MAX * 8, GFP_KERNEL);
358 if (unlikely(stats_shadow == NULL)) {
359 nss_warning("Could not allocate memory for local shadow buffer");
360 return 0;
361 }
362
363 size_wr = scnprintf(lbuf, size_al,"ipv6 stats start:\n\n");
364 spin_lock_bh(&nss_top_main.stats_lock);
365 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
366 stats_shadow[i] = nss_top_main.stats_ipv6[i];
367 }
368
369 spin_unlock_bh(&nss_top_main.stats_lock);
370
371 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
372 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
373 "%s = %llu\n", nss_stats_str_ipv6[i], stats_shadow[i]);
374 }
375
376 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 stats end\n\n");
377 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
378 kfree(lbuf);
379 kfree(stats_shadow);
380
381 return bytes_read;
382}
383
384/*
385 * nss_stats_pbuf_read()
386 * Read pbuf manager stats
387 */
388static ssize_t nss_stats_pbuf_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
389{
390 int32_t i;
391
392 /*
393 * max output lines = #stats + start tag line + end tag line + three blank lines
394 */
395 uint32_t max_output_lines = NSS_STATS_PBUF_MAX + 5;
396 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
397 size_t size_wr = 0;
398 ssize_t bytes_read = 0;
399 uint64_t *stats_shadow;
400
401 char *lbuf = kzalloc(size_al, GFP_KERNEL);
402 if (unlikely(lbuf == NULL)) {
403 nss_warning("Could not allocate memory for local statistics buffer");
404 return 0;
405 }
406
407 stats_shadow = kzalloc(NSS_STATS_PBUF_MAX * 8, GFP_KERNEL);
408 if (unlikely(stats_shadow == NULL)) {
409 nss_warning("Could not allocate memory for local shadow buffer");
410 return 0;
411 }
412
413 size_wr = scnprintf(lbuf, size_al, "pbuf_mgr stats start:\n\n");
414 spin_lock_bh(&nss_top_main.stats_lock);
415 for (i = 0; (i < NSS_STATS_PBUF_MAX); i++) {
416 stats_shadow[i] = nss_top_main.stats_pbuf[i];
417 }
418
419 spin_unlock_bh(&nss_top_main.stats_lock);
420
421 for (i = 0; (i < NSS_STATS_PBUF_MAX); i++) {
422 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
423 "%s = %llu\n", nss_stats_str_pbuf[i], stats_shadow[i]);
424 }
425
426 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npbuf_mgr stats end\n\n");
427 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
428 kfree(lbuf);
429 kfree(stats_shadow);
430
431 return bytes_read;
432}
433
434/*
435 * nss_stats_n2h_read()
436 * Read N2H stats
437 */
438static ssize_t nss_stats_n2h_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
439{
440 int32_t i;
441
442 /*
443 * max output lines = #stats + start tag line + end tag line + three blank lines
444 */
445 uint32_t max_output_lines = NSS_STATS_N2H_MAX + 5;
446 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
447 size_t size_wr = 0;
448 ssize_t bytes_read = 0;
449 uint64_t *stats_shadow;
450
451 char *lbuf = kzalloc(size_al, GFP_KERNEL);
452 if (unlikely(lbuf == NULL)) {
453 nss_warning("Could not allocate memory for local statistics buffer");
454 return 0;
455 }
456
457 stats_shadow = kzalloc(NSS_STATS_N2H_MAX * 8, GFP_KERNEL);
458 if (unlikely(stats_shadow == NULL)) {
459 nss_warning("Could not allocate memory for local shadow buffer");
460 return 0;
461 }
462
463 size_wr = scnprintf(lbuf, size_al, "n2h stats start:\n\n");
464 spin_lock_bh(&nss_top_main.stats_lock);
465 for (i = 0; (i < NSS_STATS_N2H_MAX); i++) {
466 stats_shadow[i] = nss_top_main.stats_n2h[i];
467 }
468
469 spin_unlock_bh(&nss_top_main.stats_lock);
470
471 for (i = 0; (i < NSS_STATS_N2H_MAX); i++) {
472 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
473 "%s = %llu\n", nss_stats_str_n2h[i], stats_shadow[i]);
474 }
475
476 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h stats end\n\n");
477 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
478 kfree(lbuf);
479 kfree(stats_shadow);
480
481 return bytes_read;
482}
483
484/*
485 * nss_stats_drv_read()
486 * Read HLOS driver stats
487 */
488static ssize_t nss_stats_drv_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
489{
490 int32_t i;
491
492 /*
493 * max output lines = #stats + start tag line + end tag line + three blank lines
494 */
495 uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5;
496 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
497 size_t size_wr = 0;
498 ssize_t bytes_read = 0;
499 uint64_t *stats_shadow;
500
501 char *lbuf = kzalloc(size_al, GFP_KERNEL);
502 if (unlikely(lbuf == NULL)) {
503 nss_warning("Could not allocate memory for local statistics buffer");
504 return 0;
505 }
506
507 stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL);
508 if (unlikely(stats_shadow == NULL)) {
509 nss_warning("Could not allocate memory for local shadow buffer");
510 return 0;
511 }
512
513 size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n");
514 spin_lock_bh(&nss_top_main.stats_lock);
515 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
516 stats_shadow[i] = nss_top_main.stats_drv[i];
517 }
518
519 spin_unlock_bh(&nss_top_main.stats_lock);
520
521 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
522 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
523 "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]);
524 }
525
526 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n");
527 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
528 kfree(lbuf);
529 kfree(stats_shadow);
530
531 return bytes_read;
532}
533
534/*
535 * nss_stats_ethbr_read()
536 * Read ETH_BR stats
537 */
538static ssize_t nss_stats_ethbr_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
539{
540 int32_t i;
541
542 /*
543 * max output lines = #stats + start tag line + end tag line + three blank lines
544 */
545 uint32_t max_output_lines = NSS_STATS_ETHBR_MAX + 5;
546 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
547 size_t size_wr = 0;
548 ssize_t bytes_read = 0;
549 uint64_t *stats_shadow;
550
551 char *lbuf = kzalloc(size_al, GFP_KERNEL);
552 if (unlikely(lbuf == NULL)) {
553 nss_warning("Could not allocate memory for local statistics buffer");
554 return 0;
555 }
556
557 stats_shadow = kzalloc(NSS_STATS_ETHBR_MAX * 8, GFP_KERNEL);
558 if (unlikely(stats_shadow == NULL)) {
559 nss_warning("Could not allocate memory for local shadow buffer");
560 return 0;
561 }
562
563 size_wr = scnprintf(lbuf, size_al, "eth_br stats start:\n\n");
564 spin_lock_bh(&nss_top_main.stats_lock);
565 for (i = 0; (i < NSS_STATS_ETHBR_MAX); i++) {
566 stats_shadow[i] = nss_top_main.stats_ethbr[i];
567 }
568
569 spin_unlock_bh(&nss_top_main.stats_lock);
570
571 for (i = 0; (i < NSS_STATS_ETHBR_MAX); i++) {
572 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
573 "%s = %llu\n", nss_stats_str_ethbr[i], stats_shadow[i]);
574 }
575
576 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_br stats end\n\n");
577 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
578 kfree(lbuf);
579 kfree(stats_shadow);
580
581 return bytes_read;
582}
583
584/*
585 * nss_stats_pppoe_read()
586 * Read PPPoE stats
587 */
588static ssize_t nss_stats_pppoe_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
589{
590 int32_t i;
591
592 /*
593 * max output lines = #stats + start tag line + end tag line + three blank lines
594 */
595 uint32_t max_output_lines = NSS_STATS_PPPOE_MAX + 5;
596 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
597 size_t size_wr = 0;
598 ssize_t bytes_read = 0;
599 uint64_t *stats_shadow;
600
601 char *lbuf = kzalloc(size_al, GFP_KERNEL);
602 if (unlikely(lbuf == NULL)) {
603 nss_warning("Could not allocate memory for local statistics buffer");
604 return 0;
605 }
606
607 stats_shadow = kzalloc(NSS_STATS_PPPOE_MAX * 8, GFP_KERNEL);
608 if (unlikely(stats_shadow == NULL)) {
609 nss_warning("Could not allocate memory for local shadow buffer");
610 return 0;
611 }
612
613 size_wr = scnprintf(lbuf, size_al, "pppoe stats start:\n\n");
614 spin_lock_bh(&nss_top_main.stats_lock);
615 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
616 stats_shadow[i] = nss_top_main.stats_pppoe[i];
617 }
618
619 spin_unlock_bh(&nss_top_main.stats_lock);
620
621 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
622 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
623 "%s = %llu\n", nss_stats_str_pppoe[i], stats_shadow[i]);
624 }
625
626 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe stats end\n\n");
627 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
628 kfree(lbuf);
629 kfree(stats_shadow);
630
631 return bytes_read;
632}
633
634/*
635 * nss_stats_gmac_read()
636 * Read GMAC stats
637 */
638static ssize_t nss_stats_gmac_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
639{
640 uint32_t i, id;
641
642 /*
643 * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank
644 */
645 uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5;
646 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
647 size_t size_wr = 0;
648 ssize_t bytes_read = 0;
649 uint64_t *stats_shadow;
650
651 char *lbuf = kzalloc(size_al, GFP_KERNEL);
652 if (unlikely(lbuf == NULL)) {
653 nss_warning("Could not allocate memory for local statistics buffer");
654 return 0;
655 }
656
657 stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL);
658 if (unlikely(stats_shadow == NULL)) {
659 nss_warning("Could not allocate memory for local shadow buffer");
660 return 0;
661 }
662
663 size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n");
664
665 for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) {
666 spin_lock_bh(&nss_top_main.stats_lock);
667 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
668 stats_shadow[i] = nss_top_main.stats_gmac[id][i];
669 }
670
671 spin_unlock_bh(&nss_top_main.stats_lock);
672
673 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id);
674 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
675 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
676 "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]);
677 }
678 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n");
679 }
680
681 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n");
682 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
683 kfree(lbuf);
684 kfree(stats_shadow);
685
686 return bytes_read;
687}
688
689/*
690 * nss_stats_if_read()
691 * Read interface stats
692 */
693static ssize_t nss_stats_if_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
694{
695 uint32_t i, id;
696
697 /*
698 * max output lines per interface =
699 * (#ipv4 stats + start tag + blank line) +
700 * (#ipv6 stats + start tag + blank line) +
701 * (#host stats + start tag + blank line) +
702 * (#unknown exception stats + start tag + blank line) +
703 * (#ipv4 exception + start tag + blank line) +
704 * (#ipv6 exception + start tag + blank line) +
705 * (#pppoe exception + start tag + blank line) + interface start tag
706 *
707 * max output lines =
708 * (max output lines per interface * #interfaces) +
709 * (start tag + end tag + 3 blank lines)
710 */
711 uint32_t max_output_lines_interface = ((NSS_STATS_IF_IPV4_MAX + 2) + (NSS_STATS_IF_IPV6_MAX + 2) +
712 (NSS_STATS_IF_HOST_MAX + 2) + (NSS_EXCEPTION_EVENT_UNKNOWN_MAX + 2) +
713 (NSS_EXCEPTION_EVENT_IPV4_MAX + 2) + (NSS_EXCEPTION_EVENT_IPV6_MAX + 2) +
714 (NSS_EXCEPTION_EVENT_PPPOE_MAX + 2)) + 1;
715 size_t size_al = NSS_STATS_MAX_STR_LENGTH * ((max_output_lines_interface * NSS_MAX_NET_INTERFACES) + 5);
716 size_t size_wr = 0;
717 ssize_t bytes_read = 0;
718 uint64_t *stats_shadow;
719
720 char *lbuf = kzalloc(size_al, GFP_KERNEL);
721 if (unlikely(lbuf == NULL)) {
722 nss_warning("Could not allocate memory for local statistics buffer");
723 return 0;
724 }
725
726 /*
727 * WARNING: We are only allocating memory for 64 stats counters per stats type
728 * Developers must ensure that number of counters are not more than 64
729 */
730
731 if ( (NSS_STATS_IF_IPV4_MAX > 64) ||
732 (NSS_STATS_IF_IPV6_MAX > 64) ||
733 (NSS_STATS_IF_HOST_MAX > 64) ||
734 (NSS_EXCEPTION_EVENT_UNKNOWN_MAX > 64) ||
735 (NSS_EXCEPTION_EVENT_IPV4_MAX > 64) ||
736 (NSS_EXCEPTION_EVENT_IPV6_MAX > 64) ||
737 (NSS_EXCEPTION_EVENT_PPPOE_MAX > 64)) {
738 nss_warning("Size of shadow stats structure is not enough to copy all stats");
739 }
740
741 stats_shadow = kzalloc(64 * 8, GFP_KERNEL);
742 if (unlikely(stats_shadow == NULL)) {
743 nss_warning("Could not allocate memory for local shadow buffer");
744 return 0;
745 }
746
747 size_wr = scnprintf(lbuf, size_al, "if stats start:\n\n");
748
749 for (id = 0; id < NSS_MAX_NET_INTERFACES; id++) {
750 /*
751 * Host Stats
752 */
753 spin_lock_bh(&nss_top_main.stats_lock);
754 for (i = 0; (i < NSS_STATS_IF_HOST_MAX); i++) {
755 stats_shadow[i] = nss_top_main.stats_if_host[id][i];
756 }
757
758 spin_unlock_bh(&nss_top_main.stats_lock);
759
760 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Interface ID: %d\n", id);
761 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Host:\n");
762 for (i = 0; (i < NSS_STATS_IF_HOST_MAX); i++) {
763 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
764 "%s = %llu\n", nss_stats_str_if_host[i], stats_shadow[i]);
765 }
766
767 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
768
769 /*
770 * IPv4 stats
771 */
772 spin_lock_bh(&nss_top_main.stats_lock);
773 for (i = 0; (i < NSS_STATS_IF_IPV4_MAX); i++) {
774 stats_shadow[i] = nss_top_main.stats_if_ipv4[id][i];
775 }
776
777 spin_unlock_bh(&nss_top_main.stats_lock);
778
779 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "IPv4:\n");
780 for (i = 0; (i < NSS_STATS_IF_IPV4_MAX); i++) {
781 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
782 "%s = %llu\n", nss_stats_str_if_ipv4[i], stats_shadow[i]);
783 }
784
785 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
786
787 /*
788 * IPv6 stats
789 */
790 spin_lock_bh(&nss_top_main.stats_lock);
791 for (i = 0; (i < NSS_STATS_IF_IPV6_MAX); i++) {
792 stats_shadow[i] = nss_top_main.stats_if_ipv6[id][i];
793 }
794
795 spin_unlock_bh(&nss_top_main.stats_lock);
796
797 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "IPv6:\n");
798 for (i = 0; (i < NSS_STATS_IF_IPV6_MAX); i++) {
799 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
800 "%s = %llu\n", nss_stats_str_if_ipv6[i], stats_shadow[i]);
801 }
802
803 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
804
805 /*
806 * Unknown exception stats
807 */
808 spin_lock_bh(&nss_top_main.stats_lock);
809 for (i = 0; (i < NSS_EXCEPTION_EVENT_UNKNOWN_MAX); i++) {
810 stats_shadow[i] = nss_top_main.stats_if_exception_unknown[id][i];
811 }
812
813 spin_unlock_bh(&nss_top_main.stats_lock);
814
815 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Exception Unknown:\n");
816 for (i = 0; (i < NSS_EXCEPTION_EVENT_UNKNOWN_MAX); i++) {
817 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
818 "%s = %llu\n",
819 nss_stats_str_if_exception_unknown[i],
820 stats_shadow[i]);
821 }
822
823 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
824
825 /*
826 * IPv4 exception stats
827 */
828 spin_lock_bh(&nss_top_main.stats_lock);
829 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
830 stats_shadow[i] = nss_top_main.stats_if_exception_ipv4[id][i];
831 }
832
833 spin_unlock_bh(&nss_top_main.stats_lock);
834
835 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Exception IPv4:\n");
836 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
837 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
838 "%s = %llu\n",
839 nss_stats_str_if_exception_ipv4[i],
840 stats_shadow[i]);
841 }
842
843 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
844
845 /*
846 * IPv6 exception stats
847 */
848 spin_lock_bh(&nss_top_main.stats_lock);
849 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
850 stats_shadow[i] = nss_top_main.stats_if_exception_ipv6[id][i];
851 }
852
853 spin_unlock_bh(&nss_top_main.stats_lock);
854
855 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Exception IPv6:\n");
856 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
857 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
858 "%s = %llu\n",
859 nss_stats_str_if_exception_ipv6[i],
860 stats_shadow[i]);
861 }
862 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
863
864
865 /*
866 * Exception PPPoE
867 */
868 spin_lock_bh(&nss_top_main.stats_lock);
869 for (i = 0; (i < NSS_EXCEPTION_EVENT_PPPOE_MAX); i++) {
870 stats_shadow[i] = nss_top_main.stats_if_exception_pppoe[id][i];
871 }
872
873 spin_unlock_bh(&nss_top_main.stats_lock);
874
875 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "Exception PPPoE:\n");
876 for (i = 0; (i < NSS_EXCEPTION_EVENT_PPPOE_MAX); i++) {
877 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
878 "%s = %llu\n",
879 nss_stats_str_if_exception_pppoe[i],
880 stats_shadow[i]);
881 }
882 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
883 }
884
885 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nif stats end\n\n");
886 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
887 kfree(lbuf);
888 kfree(stats_shadow);
889
890 return bytes_read;
891}
892
893
894#define NSS_STATS_DECLARE_FILE_OPERATIONS(name) \
895static const struct file_operations nss_stats_##name##_ops = { \
896 .open = simple_open, \
897 .read = nss_stats_##name##_read, \
898 .llseek = generic_file_llseek, \
899};
900
901/*
902 * nss_ipv4_stats_ops
903 */
904NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4)
905
906/*
907 * ipv6_stats_ops
908 */
909NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6)
910
911/*
912 * pbuf_stats_ops
913 */
914NSS_STATS_DECLARE_FILE_OPERATIONS(pbuf)
915
916/*
917 * n2h_stats_ops
918 */
919NSS_STATS_DECLARE_FILE_OPERATIONS(n2h)
920/*
921 * drv_stats_ops
922 */
923NSS_STATS_DECLARE_FILE_OPERATIONS(drv)
924
925/*
926 * ethbr_stats_ops
927 */
928NSS_STATS_DECLARE_FILE_OPERATIONS(ethbr)
929
930/*
931 * pppoe_stats_ops
932 */
933NSS_STATS_DECLARE_FILE_OPERATIONS(pppoe)
934
935/*
936 * gmac_stats_ops
937 */
938NSS_STATS_DECLARE_FILE_OPERATIONS(gmac)
939
940/*
941 * if_stats_ops
942 */
943NSS_STATS_DECLARE_FILE_OPERATIONS(if)
944
945/*
946 * nss_stats_init()
947 * Enable NSS statistics
948 */
949void nss_stats_init(void)
950{
951 /*
952 * NSS driver entry
953 */
954 nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL);
955 if (unlikely(nss_top_main.top_dentry == NULL)) {
956 nss_warning("Failed to create qca-nss-drv directory in debugfs");
957
958 /*
959 * Non availability of debugfs directory is not a catastrophy
960 * We can still go ahead with other initialization
961 */
962 return;
963 }
964
965 nss_top_main.stats_dentry = debugfs_create_dir("stats", nss_top_main.top_dentry);
966 if (unlikely(nss_top_main.top_dentry == NULL)) {
967 nss_warning("Failed to create qca-nss-drv directory in debugfs");
968
969 /*
970 * Non availability of debugfs directory is not a catastrophy
971 * We can still go ahead with rest of initialization
972 */
973 return;
974 }
975
976 /*
977 * Create files to obtain statistics
978 */
979
980 /*
981 * ipv4_stats
982 */
983 nss_top_main.ipv4_dentry = debugfs_create_file("ipv4", 0400,
984 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_ops);
985 if (unlikely(nss_top_main.ipv4_dentry == NULL)) {
986 nss_warning("Failed to create qca-nss-drv/stats/ipv4 directory in debugfs");
987 return;
988 }
989
990 /*
991 * ipv6_stats
992 */
993 nss_top_main.ipv6_dentry = debugfs_create_file("ipv6", 0400,
994 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_ops);
995 if (unlikely(nss_top_main.ipv6_dentry == NULL)) {
996 nss_warning("Failed to create qca-nss-drv/stats/ipv6 directory in debugfs");
997 return;
998 }
999
1000 /*
1001 * pbuf_stats
1002 */
1003 nss_top_main.pbuf_dentry = debugfs_create_file("pbuf_mgr", 0400,
1004 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pbuf_ops);
1005 if (unlikely(nss_top_main.pbuf_dentry == NULL)) {
1006 nss_warning("Failed to create qca-nss-drv/stats/pbuf directory in debugfs");
1007 return;
1008 }
1009
1010 /*
1011 * n2h_stats
1012 */
1013 nss_top_main.n2h_dentry = debugfs_create_file("n2h", 0400,
1014 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_n2h_ops);
1015 if (unlikely(nss_top_main.n2h_dentry == NULL)) {
1016 nss_warning("Failed to create qca-nss-drv/stats/n2h directory in debugfs");
1017 return;
1018 }
1019
1020 /*
1021 * drv_stats
1022 */
1023 nss_top_main.drv_dentry = debugfs_create_file("drv", 0400,
1024 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_drv_ops);
1025 if (unlikely(nss_top_main.drv_dentry == NULL)) {
1026 nss_warning("Failed to create qca-nss-drv/stats/drv directory in debugfs");
1027 return;
1028 }
1029
1030 /*
1031 * ethbr_stats
1032 */
1033 nss_top_main.ethbr_dentry = debugfs_create_file("eth_br", 0400,
1034 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ethbr_ops);
1035 if (unlikely(nss_top_main.ethbr_dentry == NULL)) {
1036 nss_warning("Failed to create qca-nss-drv/stats/ethbr directory in debugfs");
1037 return;
1038 }
1039
1040 /*
1041 * pppoe_stats
1042 */
1043 nss_top_main.pppoe_dentry = debugfs_create_file("pppoe", 0400,
1044 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pppoe_ops);
1045 if (unlikely(nss_top_main.pppoe_dentry == NULL)) {
1046 nss_warning("Failed to create qca-nss-drv/stats/pppoe directory in debugfs");
1047 return;
1048 }
1049
1050 /*
1051 * gmac_stats
1052 */
1053 nss_top_main.gmac_dentry = debugfs_create_file("gmac", 0400,
1054 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gmac_ops);
1055 if (unlikely(nss_top_main.gmac_dentry == NULL)) {
1056 nss_warning("Failed to create qca-nss-drv/stats/gmac directory in debugfs");
1057 return;
1058 }
1059
1060 /*
1061 * interface_stats
1062 */
1063 nss_top_main.if_dentry = debugfs_create_file("interface", 0400,
1064 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_if_ops);
1065 if (unlikely(nss_top_main.if_dentry == NULL)) {
1066 nss_warning("Failed to create qca-nss-drv/stats/interface directory in debugfs");
1067 return;
1068 }
1069}
1070
1071
1072/*
1073 * nss_stats_clean()
1074 * Cleanup NSS statistics files
1075 */
1076void nss_stats_clean(void)
1077{
1078 /*
1079 * Remove debugfs tree
1080 */
1081 if (likely(nss_top_main.top_dentry != NULL)) {
1082 debugfs_remove_recursive(nss_top_main.top_dentry);
1083 }
1084}