blob: ac1409d1558e9feb331b38f5fe2d333ced0539f3 [file] [log] [blame]
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05301/*
2 **************************************************************************
Zac Livingston866b0e22013-10-23 18:14:17 -06003 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05304 * 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 Rastogi38cffff2013-06-02 11:25:47 +053016
17/*
18 * nss_stats.c
19 * NSS stats APIs
20 *
21 */
22
23#include "nss_core.h"
24
25/*
26 * Maximum string length:
27 * This should be equal to maximum string size of any stats
28 * inclusive of stats value
29 */
30#define NSS_STATS_MAX_STR_LENGTH 96
31
32/*
33 * Global variables/extern declarations
34 */
35extern struct nss_top_instance nss_top_main;
36
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053037uint64_t stats_shadow_pppoe_except[NSS_PPPOE_NUM_SESSION_PER_INTERFACE][NSS_PPPOE_EXCEPTION_EVENT_MAX];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053038
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053039/*
40 * Statistics structures
41 */
42
43/*
44 * nss_stats_str_ipv4
45 * IPv4 stats strings
46 */
47static int8_t *nss_stats_str_ipv4[NSS_STATS_IPV4_MAX] = {
48 "rx_pkts",
49 "rx_bytes",
50 "tx_pkts",
51 "tx_bytes",
52 "create_requests",
53 "create_collisions",
54 "create_invalid_interface",
55 "destroy_requests",
56 "destroy_misses",
57 "hash_hits",
58 "hash_reorders",
59 "flushes",
60 "evictions"
61};
62
63/*
64 * nss_stats_str_ipv6
65 * IPv6 stats strings
66 */
67static int8_t *nss_stats_str_ipv6[NSS_STATS_IPV6_MAX] = {
68 "rx_pkts",
69 "rx_bytes",
70 "tx_pkts",
71 "tx_bytes",
72 "create_requests",
73 "create_collisions",
74 "create_invalid_interface",
75 "destroy_requests",
76 "destroy_misses",
77 "hash_hits",
78 "hash_reorders",
79 "flushes",
80 "evictions",
81};
82
83/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053084 * nss_stats_str_n2h
85 * N2H stats strings
86 */
87static int8_t *nss_stats_str_n2h[NSS_STATS_N2H_MAX] = {
88 "queue_dropped",
89 "ticks",
90 "worst_ticks",
Murat Sezgin0c0561d2014-04-09 18:55:58 -070091 "iterations",
Thomas Wu3fd8dd72014-06-11 15:57:05 -070092 "pbuf_ocm_alloc_fails",
93 "pbuf_ocm_free_count",
94 "pbuf_ocm_total_count",
95 "pbuf_default_alloc_fails",
96 "pbuf_default_free_count",
97 "pbuf_default_total_count",
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053098 "payload_fails"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053099};
100
101/*
102 * nss_stats_str_drv
103 * Host driver stats strings
104 */
105static int8_t *nss_stats_str_drv[NSS_STATS_DRV_MAX] = {
106 "nbuf_alloc_errors",
107 "tx_queue_full[0]",
108 "tx_queue_full[1]",
109 "tx_buffers_empty",
110 "tx_buffers_pkt",
111 "tx_buffers_cmd",
112 "tx_buffers_crypto",
113 "rx_buffers_empty",
114 "rx_buffers_pkt",
115 "rx_buffers_cmd_resp",
116 "rx_buffers_status_sync",
117 "rx_buffers_crypto",
118 "rx_buffers_virtual"
119};
120
121/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530122 * nss_stats_str_pppoe
123 * PPPoE stats strings
124 */
125static int8_t *nss_stats_str_pppoe[NSS_STATS_PPPOE_MAX] = {
126 "create_requests",
127 "create_failures",
128 "destroy_requests",
129 "destroy_misses"
130};
131
132/*
133 * nss_stats_str_gmac
134 * GMAC stats strings
135 */
136static int8_t *nss_stats_str_gmac[NSS_STATS_GMAC_MAX] = {
137 "ticks",
138 "worst_ticks",
139 "iterations"
140};
141
142/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530143 * nss_stats_str_node
144 * Interface stats strings per node
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530145 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530146static int8_t *nss_stats_str_node[NSS_STATS_NODE_MAX] = {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530147 "rx_packets",
148 "rx_bytes",
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530149 "rx_dropped",
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530150 "tx_packets",
151 "tx_bytes"
152};
153
154/*
Murat Sezgin99dab642014-08-28 14:40:34 -0700155 * nss_stats_str_eth_rx
156 * eth_rx stats strings
157 */
158static int8_t *nss_stats_str_eth_rx[NSS_STATS_ETH_RX_MAX] = {
159 "ticks",
160 "worst_ticks",
161 "iterations"
162};
163
164/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530165 * nss_stats_str_if_exception_unknown
166 * Interface stats strings for unknown exceptions
167 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530168static int8_t *nss_stats_str_if_exception_eth_rx[NSS_EXCEPTION_EVENT_ETH_RX_MAX] = {
169 "UNKNOWN_L3_PROTOCOL"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530170};
171
172/*
173 * nss_stats_str_if_exception_ipv4
174 * Interface stats strings for ipv4 exceptions
175 */
176static int8_t *nss_stats_str_if_exception_ipv4[NSS_EXCEPTION_EVENT_IPV4_MAX] = {
177 "IPV4_ICMP_HEADER_INCOMPLETE",
178 "IPV4_ICMP_UNHANDLED_TYPE",
179 "IPV4_ICMP_IPV4_HEADER_INCOMPLETE",
180 "IPV4_ICMP_IPV4_UDP_HEADER_INCOMPLETE",
181 "IPV4_ICMP_IPV4_TCP_HEADER_INCOMPLETE",
182 "IPV4_ICMP_IPV4_UNKNOWN_PROTOCOL",
183 "IPV4_ICMP_NO_ICME",
184 "IPV4_ICMP_FLUSH_TO_HOST",
185 "IPV4_TCP_HEADER_INCOMPLETE",
186 "IPV4_TCP_NO_ICME",
187 "IPV4_TCP_IP_OPTION",
188 "IPV4_TCP_IP_FRAGMENT",
189 "IPV4_TCP_SMALL_TTL",
190 "IPV4_TCP_NEEDS_FRAGMENTATION",
191 "IPV4_TCP_FLAGS",
192 "IPV4_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
193 "IPV4_TCP_SMALL_DATA_OFFS",
194 "IPV4_TCP_BAD_SACK",
195 "IPV4_TCP_BIG_DATA_OFFS",
196 "IPV4_TCP_SEQ_BEFORE_LEFT_EDGE",
197 "IPV4_TCP_ACK_EXCEEDS_RIGHT_EDGE",
198 "IPV4_TCP_ACK_BEFORE_LEFT_EDGE",
199 "IPV4_UDP_HEADER_INCOMPLETE",
200 "IPV4_UDP_NO_ICME",
201 "IPV4_UDP_IP_OPTION",
202 "IPV4_UDP_IP_FRAGMENT",
203 "IPV4_UDP_SMALL_TTL",
204 "IPV4_UDP_NEEDS_FRAGMENTATION",
205 "IPV4_WRONG_TARGET_MAC",
206 "IPV4_HEADER_INCOMPLETE",
207 "IPV4_BAD_TOTAL_LENGTH",
208 "IPV4_BAD_CHECKSUM",
209 "IPV4_NON_INITIAL_FRAGMENT",
210 "IPV4_DATAGRAM_INCOMPLETE",
211 "IPV4_OPTIONS_INCOMPLETE",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530212 "IPV4_UNKNOWN_PROTOCOL",
213 "IPV4_ESP_HEADER_INCOMPLETE",
214 "IPV4_ESP_NO_ICME",
215 "IPV4_ESP_IP_OPTION",
216 "IPV4_ESP_IP_FRAGMENT",
217 "IPV4_ESP_SMALL_TTL",
218 "IPV4_ESP_NEEDS_FRAGMENTATION",
219 "IPV4_INGRESS_VID_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700220 "IPV4_INGRESS_VID_MISSING",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530221 "IPV4_6RD_NO_ICME",
222 "IPV4_6RD_IP_OPTION",
223 "IPV4_6RD_IP_FRAGMENT",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700224 "IPV4_6RD_NEEDS_FRAGMENTATION",
225 "IPV4_DSCP_MARKING_MISMATCH",
Murat Sezgin7c5956a2014-05-12 09:59:51 -0700226 "IPV4_VLAN_MARKING_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700227 "IPV4_INTERFACE_MISMATCH",
228 "IPV4_DESTROY"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530229};
230
231/*
232 * nss_stats_str_if_exception_ipv6
233 * Interface stats strings for ipv6 exceptions
234 */
235static int8_t *nss_stats_str_if_exception_ipv6[NSS_EXCEPTION_EVENT_IPV6_MAX] = {
236 "IPV6_ICMP_HEADER_INCOMPLETE",
237 "IPV6_ICMP_UNHANDLED_TYPE",
238 "IPV6_ICMP_IPV6_HEADER_INCOMPLETE",
239 "IPV6_ICMP_IPV6_UDP_HEADER_INCOMPLETE",
240 "IPV6_ICMP_IPV6_TCP_HEADER_INCOMPLETE",
241 "IPV6_ICMP_IPV6_UNKNOWN_PROTOCOL",
242 "IPV6_ICMP_NO_ICME",
243 "IPV6_ICMP_FLUSH_TO_HOST",
244 "IPV6_TCP_HEADER_INCOMPLETE",
245 "IPV6_TCP_NO_ICME",
246 "IPV6_TCP_SMALL_HOP_LIMIT",
247 "IPV6_TCP_NEEDS_FRAGMENTATION",
248 "IPV6_TCP_FLAGS",
249 "IPV6_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
250 "IPV6_TCP_SMALL_DATA_OFFS",
251 "IPV6_TCP_BAD_SACK",
252 "IPV6_TCP_BIG_DATA_OFFS",
253 "IPV6_TCP_SEQ_BEFORE_LEFT_EDGE",
254 "IPV6_TCP_ACK_EXCEEDS_RIGHT_EDGE",
255 "IPV6_TCP_ACK_BEFORE_LEFT_EDGE",
256 "IPV6_UDP_HEADER_INCOMPLETE",
257 "IPV6_UDP_NO_ICME",
258 "IPV6_UDP_SMALL_HOP_LIMIT",
259 "IPV6_UDP_NEEDS_FRAGMENTATION",
260 "IPV6_WRONG_TARGET_MAC",
261 "IPV6_HEADER_INCOMPLETE",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530262 "IPV6_UNKNOWN_PROTOCOL",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700263 "IPV6_INGRESS_VID_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700264 "IPV6_INGRESS_VID_MISSING",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700265 "IPV6_DSCP_MARKING_MISMATCH",
266 "IPV6_VLAN_MARKING_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700267 "IPV6_INTERFACE_MISMATCH",
268 "IPV6_DESTROY"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530269};
270
271/*
272 * nss_stats_str_if_exception_pppoe
273 * Interface stats strings for PPPoE exceptions
274 */
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530275static int8_t *nss_stats_str_if_exception_pppoe[NSS_PPPOE_EXCEPTION_EVENT_MAX] = {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530276 "PPPOE_WRONG_VERSION_OR_TYPE",
277 "PPPOE_WRONG_CODE",
278 "PPPOE_HEADER_INCOMPLETE",
Murat Sezgin7c5956a2014-05-12 09:59:51 -0700279 "PPPOE_UNSUPPORTED_PPP_PROTOCOL",
280 "PPPOE_INTERFACE_MISMATCH"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530281};
282
283/*
284 * nss_stats_ipv4_read()
285 * Read IPV4 stats
286 */
287static ssize_t nss_stats_ipv4_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
288{
289 int32_t i;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530290 /*
291 * max output lines = #stats + start tag line + end tag line + three blank lines
292 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530293 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV4_MAX + 3) + (NSS_EXCEPTION_EVENT_IPV4_MAX + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530294 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
295 size_t size_wr = 0;
296 ssize_t bytes_read = 0;
297 uint64_t *stats_shadow;
298
299 char *lbuf = kzalloc(size_al, GFP_KERNEL);
300 if (unlikely(lbuf == NULL)) {
301 nss_warning("Could not allocate memory for local statistics buffer");
302 return 0;
303 }
304
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530305 /*
306 * Note: The assumption here is that exception event count is larger than other statistics count for IPv4
307 */
308 stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV4_MAX * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530309 if (unlikely(stats_shadow == NULL)) {
310 nss_warning("Could not allocate memory for local shadow buffer");
311 return 0;
312 }
313
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530314 size_wr = scnprintf(lbuf, size_al, "ipv4 stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530315
316 /*
317 * Common node stats
318 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530319 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530320 spin_lock_bh(&nss_top_main.stats_lock);
321 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
322 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV4_RX_INTERFACE][i];
323 }
324
325 spin_unlock_bh(&nss_top_main.stats_lock);
326
327 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
328 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
329 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
330 }
331
332 /*
333 * IPv4 node stats
334 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530335 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530336
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530337 spin_lock_bh(&nss_top_main.stats_lock);
338 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
339 stats_shadow[i] = nss_top_main.stats_ipv4[i];
340 }
341
342 spin_unlock_bh(&nss_top_main.stats_lock);
343
344 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
345 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
346 "%s = %llu\n", nss_stats_str_ipv4[i], stats_shadow[i]);
347 }
348
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530349 /*
350 * Exception stats
351 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530352 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530353
354 spin_lock_bh(&nss_top_main.stats_lock);
355 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
356 stats_shadow[i] = nss_top_main.stats_if_exception_ipv4[i];
357 }
358
359 spin_unlock_bh(&nss_top_main.stats_lock);
360
361 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
362 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
363 "%s = %llu\n", nss_stats_str_if_exception_ipv4[i], stats_shadow[i]);
364 }
365
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530366 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530367 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
368 kfree(lbuf);
369 kfree(stats_shadow);
370
371 return bytes_read;
372}
373
374/*
375 * nss_stats_ipv6_read()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530376 * Read IPV6 stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530377 */
378static ssize_t nss_stats_ipv6_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
379{
380 int32_t i;
381
382 /*
383 * max output lines = #stats + start tag line + end tag line + three blank lines
384 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530385 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV6_MAX + 3) + (NSS_EXCEPTION_EVENT_IPV6_MAX + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530386 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
387 size_t size_wr = 0;
388 ssize_t bytes_read = 0;
389 uint64_t *stats_shadow;
390
391 char *lbuf = kzalloc(size_al, GFP_KERNEL);
392 if (unlikely(lbuf == NULL)) {
393 nss_warning("Could not allocate memory for local statistics buffer");
394 return 0;
395 }
396
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530397 /*
398 * Note: The assumption here is that exception event count is larger than other statistics count for IPv4
399 */
400 stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV6_MAX * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530401 if (unlikely(stats_shadow == NULL)) {
402 nss_warning("Could not allocate memory for local shadow buffer");
403 return 0;
404 }
405
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530406 size_wr = scnprintf(lbuf, size_al, "ipv6 stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530407
408 /*
409 * Common node stats
410 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530411 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530412 spin_lock_bh(&nss_top_main.stats_lock);
413 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
414 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV6_RX_INTERFACE][i];
415 }
416
417 spin_unlock_bh(&nss_top_main.stats_lock);
418
419 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
420 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
421 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
422 }
423
424 /*
425 * IPv6 node stats
426 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530427 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530428
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530429 spin_lock_bh(&nss_top_main.stats_lock);
430 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
431 stats_shadow[i] = nss_top_main.stats_ipv6[i];
432 }
433
434 spin_unlock_bh(&nss_top_main.stats_lock);
435
436 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
437 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
438 "%s = %llu\n", nss_stats_str_ipv6[i], stats_shadow[i]);
439 }
440
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530441 /*
442 * Exception stats
443 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530444 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530445
446 spin_lock_bh(&nss_top_main.stats_lock);
447 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
448 stats_shadow[i] = nss_top_main.stats_if_exception_ipv6[i];
449 }
450
451 spin_unlock_bh(&nss_top_main.stats_lock);
452
453 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
454 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
455 "%s = %llu\n", nss_stats_str_if_exception_ipv6[i], stats_shadow[i]);
456 }
457
458 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\nipv6 stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530459 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
460 kfree(lbuf);
461 kfree(stats_shadow);
462
463 return bytes_read;
464}
465
466/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530467 * nss_stats_eth_rx_read()
468 * Read ETH_RX stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530469 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530470static ssize_t nss_stats_eth_rx_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530471{
472 int32_t i;
473
474 /*
475 * max output lines = #stats + start tag line + end tag line + three blank lines
476 */
Murat Sezgin99dab642014-08-28 14:40:34 -0700477 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_ETH_RX_MAX + 3) + (NSS_EXCEPTION_EVENT_ETH_RX_MAX + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530478 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
479 size_t size_wr = 0;
480 ssize_t bytes_read = 0;
481 uint64_t *stats_shadow;
482
483 char *lbuf = kzalloc(size_al, GFP_KERNEL);
484 if (unlikely(lbuf == NULL)) {
485 nss_warning("Could not allocate memory for local statistics buffer");
486 return 0;
487 }
488
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530489 /*
490 * Note: The assumption here is that we do not have more than 64 stats
491 */
492 stats_shadow = kzalloc(64 * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530493 if (unlikely(stats_shadow == NULL)) {
494 nss_warning("Could not allocate memory for local shadow buffer");
495 return 0;
496 }
497
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530498 size_wr = scnprintf(lbuf, size_al,"eth_rx stats start:\n\n");
499
500 /*
501 * Common node stats
502 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530503 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530504 spin_lock_bh(&nss_top_main.stats_lock);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530505 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
506 stats_shadow[i] = nss_top_main.stats_node[NSS_ETH_RX_INTERFACE][i];
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530507 }
508
509 spin_unlock_bh(&nss_top_main.stats_lock);
510
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530511 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530512 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530513 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530514 }
515
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530516 /*
Murat Sezgin99dab642014-08-28 14:40:34 -0700517 * eth_rx node stats
518 */
519 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx node stats:\n\n");
520 spin_lock_bh(&nss_top_main.stats_lock);
521 for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) {
522 stats_shadow[i] = nss_top_main.stats_eth_rx[i];
523 }
524
525 spin_unlock_bh(&nss_top_main.stats_lock);
526
527 for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) {
528 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
529 "%s = %llu\n", nss_stats_str_eth_rx[i], stats_shadow[i]);
530 }
531
532 /*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530533 * Exception stats
534 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530535 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530536
537 spin_lock_bh(&nss_top_main.stats_lock);
538 for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) {
539 stats_shadow[i] = nss_top_main.stats_if_exception_eth_rx[i];
540 }
541
542 spin_unlock_bh(&nss_top_main.stats_lock);
543
544 for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) {
545 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
546 "%s = %llu\n", nss_stats_str_if_exception_eth_rx[i], stats_shadow[i]);
547 }
548
549 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\neth_rx stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530550 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
551 kfree(lbuf);
552 kfree(stats_shadow);
553
554 return bytes_read;
555}
556
557/*
558 * nss_stats_n2h_read()
559 * Read N2H stats
560 */
561static ssize_t nss_stats_n2h_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
562{
563 int32_t i;
564
565 /*
566 * max output lines = #stats + start tag line + end tag line + three blank lines
567 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530568 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_N2H_MAX + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530569 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
570 size_t size_wr = 0;
571 ssize_t bytes_read = 0;
572 uint64_t *stats_shadow;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700573 int max = NSS_STATS_N2H_MAX - NSS_STATS_NODE_MAX;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530574
575 char *lbuf = kzalloc(size_al, GFP_KERNEL);
576 if (unlikely(lbuf == NULL)) {
577 nss_warning("Could not allocate memory for local statistics buffer");
578 return 0;
579 }
580
581 stats_shadow = kzalloc(NSS_STATS_N2H_MAX * 8, GFP_KERNEL);
582 if (unlikely(stats_shadow == NULL)) {
583 nss_warning("Could not allocate memory for local shadow buffer");
584 return 0;
585 }
586
587 size_wr = scnprintf(lbuf, size_al, "n2h stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530588
589 /*
590 * Common node stats
591 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530592 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530593 spin_lock_bh(&nss_top_main.stats_lock);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530594 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
595 stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i];
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530596 }
597
598 spin_unlock_bh(&nss_top_main.stats_lock);
599
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530600 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
601 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
602 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
603 }
604
605 /*
606 * N2H node stats
607 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530608 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530609 spin_lock_bh(&nss_top_main.stats_lock);
610 for (i = NSS_STATS_NODE_MAX; (i < NSS_STATS_N2H_MAX); i++) {
611 stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i];
612 }
613
614 spin_unlock_bh(&nss_top_main.stats_lock);
615
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700616 for (i = 0; i < max; i++) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530617 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700618 "%s = %llu\n", nss_stats_str_n2h[i], stats_shadow[i + NSS_STATS_NODE_MAX]);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530619 }
620
621 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h stats end\n\n");
622 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
623 kfree(lbuf);
624 kfree(stats_shadow);
625
626 return bytes_read;
627}
628
629/*
630 * nss_stats_drv_read()
631 * Read HLOS driver stats
632 */
633static ssize_t nss_stats_drv_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
634{
635 int32_t i;
636
637 /*
638 * max output lines = #stats + start tag line + end tag line + three blank lines
639 */
640 uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5;
641 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
642 size_t size_wr = 0;
643 ssize_t bytes_read = 0;
644 uint64_t *stats_shadow;
645
646 char *lbuf = kzalloc(size_al, GFP_KERNEL);
647 if (unlikely(lbuf == NULL)) {
648 nss_warning("Could not allocate memory for local statistics buffer");
649 return 0;
650 }
651
652 stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL);
653 if (unlikely(stats_shadow == NULL)) {
654 nss_warning("Could not allocate memory for local shadow buffer");
655 return 0;
656 }
657
658 size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n");
659 spin_lock_bh(&nss_top_main.stats_lock);
660 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
661 stats_shadow[i] = nss_top_main.stats_drv[i];
662 }
663
664 spin_unlock_bh(&nss_top_main.stats_lock);
665
666 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
667 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
668 "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]);
669 }
670
671 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n");
672 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
673 kfree(lbuf);
674 kfree(stats_shadow);
675
676 return bytes_read;
677}
678
679/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530680 * nss_stats_pppoe_read()
681 * Read PPPoE stats
682 */
683static ssize_t nss_stats_pppoe_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
684{
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530685 int32_t i, j, k;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530686
687 /*
688 * max output lines = #stats + start tag line + end tag line + three blank lines
689 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530690 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_PPPOE_MAX + 3) +
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530691 ((NSS_MAX_PHYSICAL_INTERFACES * NSS_PPPOE_NUM_SESSION_PER_INTERFACE * (NSS_PPPOE_EXCEPTION_EVENT_MAX + 5)) + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530692 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
693 size_t size_wr = 0;
694 ssize_t bytes_read = 0;
695 uint64_t *stats_shadow;
696
697 char *lbuf = kzalloc(size_al, GFP_KERNEL);
698 if (unlikely(lbuf == NULL)) {
699 nss_warning("Could not allocate memory for local statistics buffer");
700 return 0;
701 }
702
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530703 stats_shadow = kzalloc(64 * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530704 if (unlikely(stats_shadow == NULL)) {
705 nss_warning("Could not allocate memory for local shadow buffer");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530706 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530707 return 0;
708 }
709
710 size_wr = scnprintf(lbuf, size_al, "pppoe stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530711
712 /*
713 * Common node stats
714 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530715 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530716 spin_lock_bh(&nss_top_main.stats_lock);
717 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
718 stats_shadow[i] = nss_top_main.stats_node[NSS_PPPOE_RX_INTERFACE][i];
719 }
720
721 spin_unlock_bh(&nss_top_main.stats_lock);
722
723 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
724 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
725 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
726 }
727
728 /*
729 * PPPoE node stats
730 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530731 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "pppoe node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530732 spin_lock_bh(&nss_top_main.stats_lock);
733 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
734 stats_shadow[i] = nss_top_main.stats_pppoe[i];
735 }
736
737 spin_unlock_bh(&nss_top_main.stats_lock);
738
739 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
740 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
741 "%s = %llu\n", nss_stats_str_pppoe[i], stats_shadow[i]);
742 }
743
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530744 /*
745 * Exception stats
746 */
747 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nException PPPoE:\n\n");
748
749 for (j = 0; j < NSS_MAX_PHYSICAL_INTERFACES; j++) {
750 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nInterface %d:\n\n", j);
751
752 spin_lock_bh(&nss_top_main.stats_lock);
753 for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530754 for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) {
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530755 stats_shadow_pppoe_except[k][i] = nss_top_main.stats_if_exception_pppoe[j][k][i];
756 }
757 }
758
759 spin_unlock_bh(&nss_top_main.stats_lock);
760
761 for (k = 0; k < NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) {
762 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "%d. Session\n", k);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530763 for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) {
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530764 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
765 "%s = %llu\n",
766 nss_stats_str_if_exception_pppoe[i],
767 stats_shadow_pppoe_except[k][i]);
768 }
769 }
770
771 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe stats end\n\n");
772 }
773
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530774 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
775 kfree(lbuf);
776 kfree(stats_shadow);
777
778 return bytes_read;
779}
780
781/*
782 * nss_stats_gmac_read()
783 * Read GMAC stats
784 */
785static ssize_t nss_stats_gmac_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
786{
787 uint32_t i, id;
788
789 /*
790 * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank
791 */
792 uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5;
793 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
794 size_t size_wr = 0;
795 ssize_t bytes_read = 0;
796 uint64_t *stats_shadow;
797
798 char *lbuf = kzalloc(size_al, GFP_KERNEL);
799 if (unlikely(lbuf == NULL)) {
800 nss_warning("Could not allocate memory for local statistics buffer");
801 return 0;
802 }
803
804 stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL);
805 if (unlikely(stats_shadow == NULL)) {
806 nss_warning("Could not allocate memory for local shadow buffer");
807 return 0;
808 }
809
810 size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n");
811
812 for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) {
813 spin_lock_bh(&nss_top_main.stats_lock);
814 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
815 stats_shadow[i] = nss_top_main.stats_gmac[id][i];
816 }
817
818 spin_unlock_bh(&nss_top_main.stats_lock);
819
820 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id);
821 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
822 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
823 "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]);
824 }
825 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n");
826 }
827
828 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n");
829 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
830 kfree(lbuf);
831 kfree(stats_shadow);
832
833 return bytes_read;
834}
835
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530836#define NSS_STATS_DECLARE_FILE_OPERATIONS(name) \
837static const struct file_operations nss_stats_##name##_ops = { \
838 .open = simple_open, \
839 .read = nss_stats_##name##_read, \
840 .llseek = generic_file_llseek, \
841};
842
843/*
844 * nss_ipv4_stats_ops
845 */
846NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4)
847
848/*
849 * ipv6_stats_ops
850 */
851NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6)
852
853/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530854 * n2h_stats_ops
855 */
856NSS_STATS_DECLARE_FILE_OPERATIONS(n2h)
857/*
858 * drv_stats_ops
859 */
860NSS_STATS_DECLARE_FILE_OPERATIONS(drv)
861
862/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530863 * pppoe_stats_ops
864 */
865NSS_STATS_DECLARE_FILE_OPERATIONS(pppoe)
866
867/*
868 * gmac_stats_ops
869 */
870NSS_STATS_DECLARE_FILE_OPERATIONS(gmac)
871
872/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530873 * eth_rx_stats_ops
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530874 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530875NSS_STATS_DECLARE_FILE_OPERATIONS(eth_rx)
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530876
877/*
878 * nss_stats_init()
879 * Enable NSS statistics
880 */
881void nss_stats_init(void)
882{
883 /*
884 * NSS driver entry
885 */
886 nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL);
887 if (unlikely(nss_top_main.top_dentry == NULL)) {
888 nss_warning("Failed to create qca-nss-drv directory in debugfs");
889
890 /*
891 * Non availability of debugfs directory is not a catastrophy
892 * We can still go ahead with other initialization
893 */
894 return;
895 }
896
897 nss_top_main.stats_dentry = debugfs_create_dir("stats", nss_top_main.top_dentry);
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +0530898 if (unlikely(nss_top_main.stats_dentry == NULL)) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530899 nss_warning("Failed to create qca-nss-drv directory in debugfs");
900
901 /*
902 * Non availability of debugfs directory is not a catastrophy
903 * We can still go ahead with rest of initialization
904 */
905 return;
906 }
907
908 /*
909 * Create files to obtain statistics
910 */
911
912 /*
913 * ipv4_stats
914 */
915 nss_top_main.ipv4_dentry = debugfs_create_file("ipv4", 0400,
916 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_ops);
917 if (unlikely(nss_top_main.ipv4_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +0530918 nss_warning("Failed to create qca-nss-drv/stats/ipv4 file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530919 return;
920 }
921
922 /*
923 * ipv6_stats
924 */
925 nss_top_main.ipv6_dentry = debugfs_create_file("ipv6", 0400,
926 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_ops);
927 if (unlikely(nss_top_main.ipv6_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +0530928 nss_warning("Failed to create qca-nss-drv/stats/ipv6 file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530929 return;
930 }
931
932 /*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530933 * ipv6_stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530934 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530935 nss_top_main.eth_rx_dentry = debugfs_create_file("eth_rx", 0400,
936 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_eth_rx_ops);
937 if (unlikely(nss_top_main.eth_rx_dentry == NULL)) {
938 nss_warning("Failed to create qca-nss-drv/stats/eth_rx file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530939 return;
940 }
941
942 /*
943 * n2h_stats
944 */
945 nss_top_main.n2h_dentry = debugfs_create_file("n2h", 0400,
946 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_n2h_ops);
947 if (unlikely(nss_top_main.n2h_dentry == NULL)) {
948 nss_warning("Failed to create qca-nss-drv/stats/n2h directory in debugfs");
949 return;
950 }
951
952 /*
953 * drv_stats
954 */
955 nss_top_main.drv_dentry = debugfs_create_file("drv", 0400,
956 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_drv_ops);
957 if (unlikely(nss_top_main.drv_dentry == NULL)) {
958 nss_warning("Failed to create qca-nss-drv/stats/drv directory in debugfs");
959 return;
960 }
961
962 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530963 * pppoe_stats
964 */
965 nss_top_main.pppoe_dentry = debugfs_create_file("pppoe", 0400,
966 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pppoe_ops);
967 if (unlikely(nss_top_main.pppoe_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +0530968 nss_warning("Failed to create qca-nss-drv/stats/pppoe file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530969 return;
970 }
971
972 /*
973 * gmac_stats
974 */
975 nss_top_main.gmac_dentry = debugfs_create_file("gmac", 0400,
976 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gmac_ops);
977 if (unlikely(nss_top_main.gmac_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +0530978 nss_warning("Failed to create qca-nss-drv/stats/gmac file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530979 return;
980 }
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530981}
982
983
984/*
985 * nss_stats_clean()
986 * Cleanup NSS statistics files
987 */
988void nss_stats_clean(void)
989{
990 /*
991 * Remove debugfs tree
992 */
993 if (likely(nss_top_main.top_dentry != NULL)) {
994 debugfs_remove_recursive(nss_top_main.top_dentry);
995 }
996}