blob: d5ed3e570bed97f7540aeb6b82bcb2abc9ba93c2 [file] [log] [blame]
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05301/*
2 **************************************************************************
Sundarajan Srinivasan6e0366b2015-01-20 12:10:42 -08003 * Copyright (c) 2013-2015, 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
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -070037extern int32_t nss_tx_rx_virt_if_copy_stats(int32_t if_num, int i, char *line);
38
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +053039uint64_t stats_shadow_pppoe_except[NSS_PPPOE_NUM_SESSION_PER_INTERFACE][NSS_PPPOE_EXCEPTION_EVENT_MAX];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053040
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053041/*
Saurabh Misra09dddeb2014-09-30 16:38:07 -070042 * Private data for every file descriptor
43 */
44struct nss_stats_data {
Sundarajan Srinivasan273d9002015-03-03 15:43:16 -080045 uint32_t if_num; /**< Interface number for stats */
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +053046 uint32_t index; /**< Index for GRE_REDIR stats */
Saurabh Misra09dddeb2014-09-30 16:38:07 -070047};
48
49/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053050 * Statistics structures
51 */
52
53/*
54 * nss_stats_str_ipv4
55 * IPv4 stats strings
56 */
57static int8_t *nss_stats_str_ipv4[NSS_STATS_IPV4_MAX] = {
58 "rx_pkts",
59 "rx_bytes",
60 "tx_pkts",
61 "tx_bytes",
62 "create_requests",
63 "create_collisions",
64 "create_invalid_interface",
65 "destroy_requests",
66 "destroy_misses",
67 "hash_hits",
68 "hash_reorders",
69 "flushes",
Selin Dag60ea2b22014-11-05 09:36:22 -080070 "evictions",
Kiran Kumar C. S. K12998002014-09-04 17:09:03 +053071 "fragmentations",
72 "mc_create_requests",
73 "mc_update_requests",
74 "mc_create_invalid_interface",
75 "mc_destroy_requests",
76 "mc_destroy_misses",
77 "mc_flushes",
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053078};
79
80/*
Selin Dag6d9b0c12014-11-04 18:27:21 -080081 * nss_stats_str_ipv4_reasm
82 * IPv4 reassembly stats strings
83 */
84static int8_t *nss_stats_str_ipv4_reasm[NSS_STATS_IPV4_REASM_MAX] = {
85 "evictions",
86 "alloc_fails",
87 "timeouts",
88};
89
90/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +053091 * nss_stats_str_ipv6
92 * IPv6 stats strings
93 */
94static int8_t *nss_stats_str_ipv6[NSS_STATS_IPV6_MAX] = {
95 "rx_pkts",
96 "rx_bytes",
97 "tx_pkts",
98 "tx_bytes",
99 "create_requests",
100 "create_collisions",
101 "create_invalid_interface",
102 "destroy_requests",
103 "destroy_misses",
104 "hash_hits",
105 "hash_reorders",
106 "flushes",
107 "evictions",
Selin Dag5d68caa2015-05-12 13:23:33 -0700108 "fragmentations",
109 "frag_fails",
Kiran Kumar C. S. K12998002014-09-04 17:09:03 +0530110 "mc_create_requests",
111 "mc_update_requests",
112 "mc_create_invalid_interface",
113 "mc_destroy_requests",
114 "mc_destroy_misses",
115 "mc_flushes",
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530116};
117
118/*
Selin Dag60a2f5b2015-06-29 14:39:49 -0700119 * nss_stats_str_ipv6_reasm
120 * IPv6 reassembly stats strings
121 */
122static int8_t *nss_stats_str_ipv6_reasm[NSS_STATS_IPV6_REASM_MAX] = {
123 "alloc_fails",
124 "timeouts",
125 "discards",
126};
127
128/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530129 * nss_stats_str_n2h
130 * N2H stats strings
131 */
132static int8_t *nss_stats_str_n2h[NSS_STATS_N2H_MAX] = {
133 "queue_dropped",
134 "ticks",
135 "worst_ticks",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700136 "iterations",
Thomas Wu3fd8dd72014-06-11 15:57:05 -0700137 "pbuf_ocm_alloc_fails",
138 "pbuf_ocm_free_count",
139 "pbuf_ocm_total_count",
140 "pbuf_default_alloc_fails",
141 "pbuf_default_free_count",
142 "pbuf_default_total_count",
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -0800143 "payload_fails",
Thomas Wu53679842015-01-22 13:37:35 -0800144 "payload_free_count",
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -0800145 "h2n_control_packets",
146 "h2n_control_bytes",
147 "n2h_control_packets",
148 "n2h_control_bytes",
149 "h2n_data_packets",
150 "h2n_data_bytes",
151 "n2h_data_packets",
152 "n2h_data_bytes",
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530153};
154
155/*
Thomas Wuc3e382c2014-10-29 15:35:13 -0700156 * nss_stats_str_lso_rx
157 * LSO_RX stats strings
158 */
159static int8_t *nss_stats_str_lso_rx[NSS_STATS_LSO_RX_MAX] = {
160 "tx_dropped",
161 "dropped",
162 "pbuf_alloc_fail",
163 "pbuf_reference_fail"
164};
165
166/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530167 * nss_stats_str_drv
168 * Host driver stats strings
169 */
170static int8_t *nss_stats_str_drv[NSS_STATS_DRV_MAX] = {
171 "nbuf_alloc_errors",
172 "tx_queue_full[0]",
173 "tx_queue_full[1]",
174 "tx_buffers_empty",
175 "tx_buffers_pkt",
176 "tx_buffers_cmd",
177 "tx_buffers_crypto",
178 "rx_buffers_empty",
179 "rx_buffers_pkt",
180 "rx_buffers_cmd_resp",
181 "rx_buffers_status_sync",
182 "rx_buffers_crypto",
Thomas Wu0acd8162014-12-07 15:43:39 -0800183 "rx_buffers_virtual",
184 "tx_skb_simple",
185 "tx_skb_nr_frags",
186 "tx_skb_fraglist",
187 "rx_skb_simple",
188 "rx_skb_nr_frags",
189 "rx_skb_fraglist",
Sundarajan Srinivasan6e0366b2015-01-20 12:10:42 -0800190 "rx_bad_desciptor",
Thomas Wu1fbf5212015-06-04 14:38:40 -0700191 "nss_skb_count",
192 "rx_chain_seg_processed",
193 "rx_frag_seg_processed"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530194};
195
196/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530197 * nss_stats_str_pppoe
198 * PPPoE stats strings
199 */
200static int8_t *nss_stats_str_pppoe[NSS_STATS_PPPOE_MAX] = {
201 "create_requests",
202 "create_failures",
203 "destroy_requests",
204 "destroy_misses"
205};
206
207/*
208 * nss_stats_str_gmac
209 * GMAC stats strings
210 */
211static int8_t *nss_stats_str_gmac[NSS_STATS_GMAC_MAX] = {
212 "ticks",
213 "worst_ticks",
214 "iterations"
215};
216
217/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530218 * nss_stats_str_node
219 * Interface stats strings per node
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530220 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530221static int8_t *nss_stats_str_node[NSS_STATS_NODE_MAX] = {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530222 "rx_packets",
223 "rx_bytes",
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530224 "rx_dropped",
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530225 "tx_packets",
226 "tx_bytes"
227};
228
229/*
Murat Sezgin99dab642014-08-28 14:40:34 -0700230 * nss_stats_str_eth_rx
231 * eth_rx stats strings
232 */
233static int8_t *nss_stats_str_eth_rx[NSS_STATS_ETH_RX_MAX] = {
234 "ticks",
235 "worst_ticks",
236 "iterations"
237};
238
239/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530240 * nss_stats_str_if_exception_unknown
241 * Interface stats strings for unknown exceptions
242 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530243static int8_t *nss_stats_str_if_exception_eth_rx[NSS_EXCEPTION_EVENT_ETH_RX_MAX] = {
Selin Dag2e8e48c2015-02-20 15:51:55 -0800244 "UNKNOWN_L3_PROTOCOL",
245 "ETH_HDR_MISSING",
246 "VLAN_MISSING"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530247};
248
249/*
250 * nss_stats_str_if_exception_ipv4
251 * Interface stats strings for ipv4 exceptions
252 */
253static int8_t *nss_stats_str_if_exception_ipv4[NSS_EXCEPTION_EVENT_IPV4_MAX] = {
254 "IPV4_ICMP_HEADER_INCOMPLETE",
255 "IPV4_ICMP_UNHANDLED_TYPE",
256 "IPV4_ICMP_IPV4_HEADER_INCOMPLETE",
257 "IPV4_ICMP_IPV4_UDP_HEADER_INCOMPLETE",
258 "IPV4_ICMP_IPV4_TCP_HEADER_INCOMPLETE",
259 "IPV4_ICMP_IPV4_UNKNOWN_PROTOCOL",
260 "IPV4_ICMP_NO_ICME",
261 "IPV4_ICMP_FLUSH_TO_HOST",
262 "IPV4_TCP_HEADER_INCOMPLETE",
263 "IPV4_TCP_NO_ICME",
264 "IPV4_TCP_IP_OPTION",
265 "IPV4_TCP_IP_FRAGMENT",
266 "IPV4_TCP_SMALL_TTL",
267 "IPV4_TCP_NEEDS_FRAGMENTATION",
268 "IPV4_TCP_FLAGS",
269 "IPV4_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
270 "IPV4_TCP_SMALL_DATA_OFFS",
271 "IPV4_TCP_BAD_SACK",
272 "IPV4_TCP_BIG_DATA_OFFS",
273 "IPV4_TCP_SEQ_BEFORE_LEFT_EDGE",
274 "IPV4_TCP_ACK_EXCEEDS_RIGHT_EDGE",
275 "IPV4_TCP_ACK_BEFORE_LEFT_EDGE",
276 "IPV4_UDP_HEADER_INCOMPLETE",
277 "IPV4_UDP_NO_ICME",
278 "IPV4_UDP_IP_OPTION",
279 "IPV4_UDP_IP_FRAGMENT",
280 "IPV4_UDP_SMALL_TTL",
281 "IPV4_UDP_NEEDS_FRAGMENTATION",
282 "IPV4_WRONG_TARGET_MAC",
283 "IPV4_HEADER_INCOMPLETE",
284 "IPV4_BAD_TOTAL_LENGTH",
285 "IPV4_BAD_CHECKSUM",
286 "IPV4_NON_INITIAL_FRAGMENT",
287 "IPV4_DATAGRAM_INCOMPLETE",
288 "IPV4_OPTIONS_INCOMPLETE",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530289 "IPV4_UNKNOWN_PROTOCOL",
290 "IPV4_ESP_HEADER_INCOMPLETE",
291 "IPV4_ESP_NO_ICME",
292 "IPV4_ESP_IP_OPTION",
293 "IPV4_ESP_IP_FRAGMENT",
294 "IPV4_ESP_SMALL_TTL",
295 "IPV4_ESP_NEEDS_FRAGMENTATION",
296 "IPV4_INGRESS_VID_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700297 "IPV4_INGRESS_VID_MISSING",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530298 "IPV4_6RD_NO_ICME",
299 "IPV4_6RD_IP_OPTION",
300 "IPV4_6RD_IP_FRAGMENT",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700301 "IPV4_6RD_NEEDS_FRAGMENTATION",
302 "IPV4_DSCP_MARKING_MISMATCH",
Murat Sezgin7c5956a2014-05-12 09:59:51 -0700303 "IPV4_VLAN_MARKING_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700304 "IPV4_INTERFACE_MISMATCH",
Radha krishna Simha Jiguru00cfe562014-10-21 16:22:12 +0530305 "IPV4_GRE_HEADER_INCOMPLETE",
306 "IPV4_GRE_NO_ICME",
307 "IPV4_GRE_IP_OPTION",
308 "IPV4_GRE_IP_FRAGMENT",
309 "IPV4_GRE_SMALL_TTL",
310 "IPV4_GRE_NEEDS_FRAGMENTATION",
Selin Dag60ea2b22014-11-05 09:36:22 -0800311 "IPV4_FRAG_DF_SET",
312 "IPV4_FRAG_FAIL",
Saurabh Misra5b07cc02015-01-15 14:20:58 -0800313 "IPV4_DESTROY",
314 "IPV4_ICMP_IPV4_UDPLITE_HEADER_INCOMPLETE",
315 "IPV4_UDPLITE_HEADER_INCOMPLETE",
316 "IPV4_UDPLITE_NO_ICME",
317 "IPV4_UDPLITE_IP_OPTION",
318 "IPV4_UDPLITE_IP_FRAGMENT",
319 "IPV4_UDPLITE_SMALL_TTL",
Kiran Kumar C. S. K12998002014-09-04 17:09:03 +0530320 "IPV4_UDPLITE_NEEDS_FRAGMENTATION",
321 "IPV4_MC_UDP_NO_ICME",
322 "IPV4_MC_MEM_ALLOC_FAILURE",
323 "IPV4_MC_UPDATE_FAILURE",
324 "IPV4_MC_PBUF_ALLOC_FAILURE"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530325};
326
327/*
328 * nss_stats_str_if_exception_ipv6
329 * Interface stats strings for ipv6 exceptions
330 */
331static int8_t *nss_stats_str_if_exception_ipv6[NSS_EXCEPTION_EVENT_IPV6_MAX] = {
332 "IPV6_ICMP_HEADER_INCOMPLETE",
333 "IPV6_ICMP_UNHANDLED_TYPE",
334 "IPV6_ICMP_IPV6_HEADER_INCOMPLETE",
335 "IPV6_ICMP_IPV6_UDP_HEADER_INCOMPLETE",
336 "IPV6_ICMP_IPV6_TCP_HEADER_INCOMPLETE",
337 "IPV6_ICMP_IPV6_UNKNOWN_PROTOCOL",
338 "IPV6_ICMP_NO_ICME",
339 "IPV6_ICMP_FLUSH_TO_HOST",
340 "IPV6_TCP_HEADER_INCOMPLETE",
341 "IPV6_TCP_NO_ICME",
342 "IPV6_TCP_SMALL_HOP_LIMIT",
343 "IPV6_TCP_NEEDS_FRAGMENTATION",
344 "IPV6_TCP_FLAGS",
345 "IPV6_TCP_SEQ_EXCEEDS_RIGHT_EDGE",
346 "IPV6_TCP_SMALL_DATA_OFFS",
347 "IPV6_TCP_BAD_SACK",
348 "IPV6_TCP_BIG_DATA_OFFS",
349 "IPV6_TCP_SEQ_BEFORE_LEFT_EDGE",
350 "IPV6_TCP_ACK_EXCEEDS_RIGHT_EDGE",
351 "IPV6_TCP_ACK_BEFORE_LEFT_EDGE",
352 "IPV6_UDP_HEADER_INCOMPLETE",
353 "IPV6_UDP_NO_ICME",
354 "IPV6_UDP_SMALL_HOP_LIMIT",
355 "IPV6_UDP_NEEDS_FRAGMENTATION",
356 "IPV6_WRONG_TARGET_MAC",
357 "IPV6_HEADER_INCOMPLETE",
Radha krishna Simha Jiguru59a1a1c2014-01-27 18:29:40 +0530358 "IPV6_UNKNOWN_PROTOCOL",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700359 "IPV6_INGRESS_VID_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700360 "IPV6_INGRESS_VID_MISSING",
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700361 "IPV6_DSCP_MARKING_MISMATCH",
362 "IPV6_VLAN_MARKING_MISMATCH",
Thomas Wu8d6f4b22014-06-09 14:46:18 -0700363 "IPV6_INTERFACE_MISMATCH",
Saurabh Misra5b07cc02015-01-15 14:20:58 -0800364 "IPV6_GRE_NO_ICME",
365 "IPV6_GRE_NEEDS_FRAGMENTATION",
366 "IPV6_GRE_SMALL_HOP_LIMIT",
367 "IPV6_DESTROY",
368 "IPV6_ICMP_IPV6_UDPLITE_HEADER_INCOMPLETE",
369 "IPV6_UDPLITE_HEADER_INCOMPLETE",
370 "IPV6_UDPLITE_NO_ICME",
371 "IPV6_UDPLITE_SMALL_HOP_LIMIT",
Kiran Kumar C. S. K12998002014-09-04 17:09:03 +0530372 "IPV6_UDPLITE_NEEDS_FRAGMENTATION",
373 "IPV6_MC_UDP_NO_ICME",
374 "IPV6_MC_MEM_ALLOC_FAILURE",
375 "IPV6_MC_UPDATE_FAILURE",
376 "IPV6_MC_PBUF_ALLOC_FAILURE"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530377};
378
379/*
380 * nss_stats_str_if_exception_pppoe
381 * Interface stats strings for PPPoE exceptions
382 */
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +0530383static int8_t *nss_stats_str_if_exception_pppoe[NSS_PPPOE_EXCEPTION_EVENT_MAX] = {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530384 "PPPOE_WRONG_VERSION_OR_TYPE",
385 "PPPOE_WRONG_CODE",
386 "PPPOE_HEADER_INCOMPLETE",
Murat Sezgin7c5956a2014-05-12 09:59:51 -0700387 "PPPOE_UNSUPPORTED_PPP_PROTOCOL",
388 "PPPOE_INTERFACE_MISMATCH"
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530389};
390
391/*
Bharath M Kumarcc666e92014-12-24 19:17:28 +0530392 * nss_stats_str_wifi
393 * Wifi statistics strings
394 */
395static int8_t *nss_stats_str_wifi[NSS_STATS_WIFI_MAX] = {
396 "RX_PACKETS",
397 "RX_DROPPED",
398 "TX_PACKETS",
399 "TX_DROPPED",
400 "TX_TRANSMIT_COMPLETED",
401 "TX_MGMT_RECEIVED",
402 "TX_MGMT_TRANSMITTED",
403 "TX_MGMT_DROPPED",
404 "TX_MGMT_COMPLETED",
405 "TX_INV_PEER_ENQ_CNT",
406 "RX_INV_PEER_RCV_CNT",
407 "RX_PN_CHECK_FAILED",
408 "RX_PKTS_DELIVERD",
409};
410
411/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530412 * nss_stats_ipv4_read()
413 * Read IPV4 stats
414 */
415static ssize_t nss_stats_ipv4_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
416{
417 int32_t i;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530418 /*
419 * max output lines = #stats + start tag line + end tag line + three blank lines
420 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530421 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 +0530422 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
423 size_t size_wr = 0;
424 ssize_t bytes_read = 0;
425 uint64_t *stats_shadow;
426
427 char *lbuf = kzalloc(size_al, GFP_KERNEL);
428 if (unlikely(lbuf == NULL)) {
429 nss_warning("Could not allocate memory for local statistics buffer");
430 return 0;
431 }
432
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530433 /*
434 * Note: The assumption here is that exception event count is larger than other statistics count for IPv4
435 */
436 stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV4_MAX * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530437 if (unlikely(stats_shadow == NULL)) {
438 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530439 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530440 return 0;
441 }
442
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530443 size_wr = scnprintf(lbuf, size_al, "ipv4 stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530444
445 /*
446 * Common node stats
447 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530448 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530449 spin_lock_bh(&nss_top_main.stats_lock);
450 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
451 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV4_RX_INTERFACE][i];
452 }
453
454 spin_unlock_bh(&nss_top_main.stats_lock);
455
456 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
457 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
458 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
459 }
460
461 /*
462 * IPv4 node stats
463 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530464 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530465
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530466 spin_lock_bh(&nss_top_main.stats_lock);
467 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
468 stats_shadow[i] = nss_top_main.stats_ipv4[i];
469 }
470
471 spin_unlock_bh(&nss_top_main.stats_lock);
472
473 for (i = 0; (i < NSS_STATS_IPV4_MAX); i++) {
474 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
475 "%s = %llu\n", nss_stats_str_ipv4[i], stats_shadow[i]);
476 }
477
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530478 /*
479 * Exception stats
480 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530481 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530482
483 spin_lock_bh(&nss_top_main.stats_lock);
484 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
485 stats_shadow[i] = nss_top_main.stats_if_exception_ipv4[i];
486 }
487
488 spin_unlock_bh(&nss_top_main.stats_lock);
489
490 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV4_MAX); i++) {
491 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
492 "%s = %llu\n", nss_stats_str_if_exception_ipv4[i], stats_shadow[i]);
493 }
494
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530495 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530496 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
497 kfree(lbuf);
498 kfree(stats_shadow);
499
500 return bytes_read;
501}
502
503/*
Selin Dag6d9b0c12014-11-04 18:27:21 -0800504 * nss_stats_ipv4_reasm_read()
505 * Read IPV4 reassembly stats
506 */
507static ssize_t nss_stats_ipv4_reasm_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
508{
509 int32_t i;
510 /*
511 * max output lines = #stats + start tag line + end tag line + three blank lines
512 */
513 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV4_REASM_MAX + 3) + 5;
514 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
515 size_t size_wr = 0;
516 ssize_t bytes_read = 0;
517 uint64_t *stats_shadow;
518
519 char *lbuf = kzalloc(size_al, GFP_KERNEL);
520 if (unlikely(lbuf == NULL)) {
521 nss_warning("Could not allocate memory for local statistics buffer");
522 return 0;
523 }
524
525 stats_shadow = kzalloc(NSS_STATS_IPV4_REASM_MAX * 8, GFP_KERNEL);
526 if (unlikely(stats_shadow == NULL)) {
527 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530528 kfree(lbuf);
Selin Dag6d9b0c12014-11-04 18:27:21 -0800529 return 0;
530 }
531
532 size_wr = scnprintf(lbuf, size_al, "ipv4 reasm stats start:\n\n");
533
534 /*
535 * Common node stats
536 */
537 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
538 spin_lock_bh(&nss_top_main.stats_lock);
539 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
540 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV4_REASM_INTERFACE][i];
541 }
542
543 spin_unlock_bh(&nss_top_main.stats_lock);
544
545 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
546 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
547 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
548 }
549
550 /*
551 * IPv4 reasm node stats
552 */
553 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 reasm node stats:\n\n");
554
555 spin_lock_bh(&nss_top_main.stats_lock);
556 for (i = 0; (i < NSS_STATS_IPV4_REASM_MAX); i++) {
557 stats_shadow[i] = nss_top_main.stats_ipv4_reasm[i];
558 }
559
560 spin_unlock_bh(&nss_top_main.stats_lock);
561
562 for (i = 0; (i < NSS_STATS_IPV4_REASM_MAX); i++) {
563 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
564 "%s = %llu\n", nss_stats_str_ipv4_reasm[i], stats_shadow[i]);
565 }
566
567 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv4 reasm stats end\n\n");
568 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
569 kfree(lbuf);
570 kfree(stats_shadow);
571
572 return bytes_read;
573}
574
575/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530576 * nss_stats_ipv6_read()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530577 * Read IPV6 stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530578 */
579static ssize_t nss_stats_ipv6_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
580{
581 int32_t i;
582
583 /*
584 * max output lines = #stats + start tag line + end tag line + three blank lines
585 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530586 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 +0530587 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
588 size_t size_wr = 0;
589 ssize_t bytes_read = 0;
590 uint64_t *stats_shadow;
591
592 char *lbuf = kzalloc(size_al, GFP_KERNEL);
593 if (unlikely(lbuf == NULL)) {
594 nss_warning("Could not allocate memory for local statistics buffer");
595 return 0;
596 }
597
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530598 /*
599 * Note: The assumption here is that exception event count is larger than other statistics count for IPv4
600 */
601 stats_shadow = kzalloc(NSS_EXCEPTION_EVENT_IPV6_MAX * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530602 if (unlikely(stats_shadow == NULL)) {
603 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530604 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530605 return 0;
606 }
607
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530608 size_wr = scnprintf(lbuf, size_al, "ipv6 stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530609
610 /*
611 * Common node stats
612 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530613 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530614 spin_lock_bh(&nss_top_main.stats_lock);
615 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
616 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV6_RX_INTERFACE][i];
617 }
618
619 spin_unlock_bh(&nss_top_main.stats_lock);
620
621 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
622 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
623 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
624 }
625
626 /*
627 * IPv6 node stats
628 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530629 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530630
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530631 spin_lock_bh(&nss_top_main.stats_lock);
632 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
633 stats_shadow[i] = nss_top_main.stats_ipv6[i];
634 }
635
636 spin_unlock_bh(&nss_top_main.stats_lock);
637
638 for (i = 0; (i < NSS_STATS_IPV6_MAX); i++) {
639 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
640 "%s = %llu\n", nss_stats_str_ipv6[i], stats_shadow[i]);
641 }
642
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530643 /*
644 * Exception stats
645 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530646 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530647
648 spin_lock_bh(&nss_top_main.stats_lock);
649 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
650 stats_shadow[i] = nss_top_main.stats_if_exception_ipv6[i];
651 }
652
653 spin_unlock_bh(&nss_top_main.stats_lock);
654
655 for (i = 0; (i < NSS_EXCEPTION_EVENT_IPV6_MAX); i++) {
656 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
657 "%s = %llu\n", nss_stats_str_if_exception_ipv6[i], stats_shadow[i]);
658 }
659
660 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\nipv6 stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530661 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
662 kfree(lbuf);
663 kfree(stats_shadow);
664
665 return bytes_read;
666}
667
668/*
Selin Dag60a2f5b2015-06-29 14:39:49 -0700669 * nss_stats_ipv6_reasm_read()
670 * Read IPV6 reassembly stats
671 */
672static ssize_t nss_stats_ipv6_reasm_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
673{
674 int32_t i;
675 /*
676 * max output lines = #stats + start tag line + end tag line + three blank lines
677 */
678 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_IPV6_REASM_MAX + 3) + 5;
679 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
680 size_t size_wr = 0;
681 ssize_t bytes_read = 0;
682 uint64_t *stats_shadow;
683
684 char *lbuf = kzalloc(size_al, GFP_KERNEL);
685 if (unlikely(lbuf == NULL)) {
686 nss_warning("Could not allocate memory for local statistics buffer");
687 return 0;
688 }
689
690 stats_shadow = kzalloc(NSS_STATS_IPV6_REASM_MAX * 8, GFP_KERNEL);
691 if (unlikely(stats_shadow == NULL)) {
692 nss_warning("Could not allocate memory for local shadow buffer");
693 kfree(lbuf);
694 return 0;
695 }
696
697 size_wr = scnprintf(lbuf, size_al, "ipv6 reasm stats start:\n\n");
698
699 /*
700 * Common node stats
701 */
702 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
703 spin_lock_bh(&nss_top_main.stats_lock);
704 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
705 stats_shadow[i] = nss_top_main.stats_node[NSS_IPV6_REASM_INTERFACE][i];
706 }
707
708 spin_unlock_bh(&nss_top_main.stats_lock);
709
710 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
711 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
712 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
713 }
714
715 /*
716 * Ipv6 reasm node stats
717 */
718 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 reasm node stats:\n\n");
719
720 spin_lock_bh(&nss_top_main.stats_lock);
721 for (i = 0; (i < NSS_STATS_IPV6_REASM_MAX); i++) {
722 stats_shadow[i] = nss_top_main.stats_ipv6_reasm[i];
723 }
724
725 spin_unlock_bh(&nss_top_main.stats_lock);
726
727 for (i = 0; (i < NSS_STATS_IPV6_REASM_MAX); i++) {
728 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
729 "%s = %llu\n", nss_stats_str_ipv6_reasm[i], stats_shadow[i]);
730 }
731
732 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nipv6 reasm stats end\n\n");
733 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
734 kfree(lbuf);
735 kfree(stats_shadow);
736
737 return bytes_read;
738}
739
740/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530741 * nss_stats_eth_rx_read()
742 * Read ETH_RX stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530743 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530744static 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 +0530745{
746 int32_t i;
747
748 /*
749 * max output lines = #stats + start tag line + end tag line + three blank lines
750 */
Murat Sezgin99dab642014-08-28 14:40:34 -0700751 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 +0530752 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
753 size_t size_wr = 0;
754 ssize_t bytes_read = 0;
755 uint64_t *stats_shadow;
756
757 char *lbuf = kzalloc(size_al, GFP_KERNEL);
758 if (unlikely(lbuf == NULL)) {
759 nss_warning("Could not allocate memory for local statistics buffer");
760 return 0;
761 }
762
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530763 /*
764 * Note: The assumption here is that we do not have more than 64 stats
765 */
766 stats_shadow = kzalloc(64 * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530767 if (unlikely(stats_shadow == NULL)) {
768 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530769 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530770 return 0;
771 }
772
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530773 size_wr = scnprintf(lbuf, size_al,"eth_rx stats start:\n\n");
774
775 /*
776 * Common node stats
777 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530778 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530779 spin_lock_bh(&nss_top_main.stats_lock);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530780 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
781 stats_shadow[i] = nss_top_main.stats_node[NSS_ETH_RX_INTERFACE][i];
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530782 }
783
784 spin_unlock_bh(&nss_top_main.stats_lock);
785
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530786 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530787 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530788 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530789 }
790
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530791 /*
Murat Sezgin99dab642014-08-28 14:40:34 -0700792 * eth_rx node stats
793 */
794 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx node stats:\n\n");
795 spin_lock_bh(&nss_top_main.stats_lock);
796 for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) {
797 stats_shadow[i] = nss_top_main.stats_eth_rx[i];
798 }
799
800 spin_unlock_bh(&nss_top_main.stats_lock);
801
802 for (i = 0; (i < NSS_STATS_ETH_RX_MAX); i++) {
803 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
804 "%s = %llu\n", nss_stats_str_eth_rx[i], stats_shadow[i]);
805 }
806
807 /*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530808 * Exception stats
809 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530810 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\neth_rx exception stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530811
812 spin_lock_bh(&nss_top_main.stats_lock);
813 for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) {
814 stats_shadow[i] = nss_top_main.stats_if_exception_eth_rx[i];
815 }
816
817 spin_unlock_bh(&nss_top_main.stats_lock);
818
819 for (i = 0; (i < NSS_EXCEPTION_EVENT_ETH_RX_MAX); i++) {
820 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
821 "%s = %llu\n", nss_stats_str_if_exception_eth_rx[i], stats_shadow[i]);
822 }
823
824 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\neth_rx stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530825 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
826 kfree(lbuf);
827 kfree(stats_shadow);
828
829 return bytes_read;
830}
831
832/*
833 * nss_stats_n2h_read()
834 * Read N2H stats
835 */
836static ssize_t nss_stats_n2h_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
837{
838 int32_t i;
839
840 /*
841 * max output lines = #stats + start tag line + end tag line + three blank lines
842 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530843 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_N2H_MAX + 3) + 5;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530844 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
845 size_t size_wr = 0;
846 ssize_t bytes_read = 0;
847 uint64_t *stats_shadow;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700848 int max = NSS_STATS_N2H_MAX - NSS_STATS_NODE_MAX;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530849
850 char *lbuf = kzalloc(size_al, GFP_KERNEL);
851 if (unlikely(lbuf == NULL)) {
852 nss_warning("Could not allocate memory for local statistics buffer");
853 return 0;
854 }
855
856 stats_shadow = kzalloc(NSS_STATS_N2H_MAX * 8, GFP_KERNEL);
857 if (unlikely(stats_shadow == NULL)) {
858 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530859 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530860 return 0;
861 }
862
863 size_wr = scnprintf(lbuf, size_al, "n2h stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530864
865 /*
866 * Common node stats
867 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530868 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530869 spin_lock_bh(&nss_top_main.stats_lock);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530870 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
871 stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i];
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530872 }
873
874 spin_unlock_bh(&nss_top_main.stats_lock);
875
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530876 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
877 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
878 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
879 }
880
881 /*
882 * N2H node stats
883 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +0530884 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530885 spin_lock_bh(&nss_top_main.stats_lock);
886 for (i = NSS_STATS_NODE_MAX; (i < NSS_STATS_N2H_MAX); i++) {
887 stats_shadow[i] = nss_top_main.nss[0].stats_n2h[i];
888 }
889
890 spin_unlock_bh(&nss_top_main.stats_lock);
891
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700892 for (i = 0; i < max; i++) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530893 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700894 "%s = %llu\n", nss_stats_str_n2h[i], stats_shadow[i + NSS_STATS_NODE_MAX]);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530895 }
896
897 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nn2h stats end\n\n");
898 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
899 kfree(lbuf);
900 kfree(stats_shadow);
901
902 return bytes_read;
903}
904
905/*
Thomas Wuc3e382c2014-10-29 15:35:13 -0700906 * nss_stats_lso_rx_read()
907 * Read LSO_RX stats
908 */
909static ssize_t nss_stats_lso_rx_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
910{
911 int32_t i;
912
913 /*
914 * max output lines = #stats + start tag line + end tag line + three blank lines
915 */
916 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_LSO_RX_MAX + 3) + 5;
917 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
918 size_t size_wr = 0;
919 ssize_t bytes_read = 0;
920 uint64_t *stats_shadow;
921
922 char *lbuf = kzalloc(size_al, GFP_KERNEL);
923 if (unlikely(lbuf == NULL)) {
924 nss_warning("Could not allocate memory for local statistics buffer");
925 return 0;
926 }
927
928 stats_shadow = kzalloc(NSS_STATS_LSO_RX_MAX * 8, GFP_KERNEL);
929 if (unlikely(stats_shadow == NULL)) {
930 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +0530931 kfree(lbuf);
Thomas Wuc3e382c2014-10-29 15:35:13 -0700932 return 0;
933 }
934
935 size_wr = scnprintf(lbuf, size_al, "lso_rx stats start:\n\n");
936
937 /*
938 * Common node stats
939 */
940 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
941 spin_lock_bh(&nss_top_main.stats_lock);
942 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
943 stats_shadow[i] = nss_top_main.stats_node[NSS_LSO_RX_INTERFACE][i];
944 }
945
946 spin_unlock_bh(&nss_top_main.stats_lock);
947
948 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
949 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
950 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
951 }
952
953 /*
954 * lso_rx node stats
955 */
956 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nlso_rx node stats:\n\n");
957 spin_lock_bh(&nss_top_main.stats_lock);
958 for (i = 0; (i < NSS_STATS_LSO_RX_MAX); i++) {
959 stats_shadow[i] = nss_top_main.stats_lso_rx[i];
960 }
961
962 spin_unlock_bh(&nss_top_main.stats_lock);
963
964 for (i = 0; i < NSS_STATS_LSO_RX_MAX; i++) {
965 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
966 "%s = %llu\n", nss_stats_str_lso_rx[i], stats_shadow[i]);
967 }
968
969 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nlso_rx stats end\n\n");
970 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
971 kfree(lbuf);
972 kfree(stats_shadow);
973
974 return bytes_read;
975}
976
977/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530978 * nss_stats_drv_read()
979 * Read HLOS driver stats
980 */
981static ssize_t nss_stats_drv_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
982{
983 int32_t i;
984
985 /*
986 * max output lines = #stats + start tag line + end tag line + three blank lines
987 */
988 uint32_t max_output_lines = NSS_STATS_DRV_MAX + 5;
989 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
990 size_t size_wr = 0;
991 ssize_t bytes_read = 0;
992 uint64_t *stats_shadow;
993
994 char *lbuf = kzalloc(size_al, GFP_KERNEL);
995 if (unlikely(lbuf == NULL)) {
996 nss_warning("Could not allocate memory for local statistics buffer");
997 return 0;
998 }
999
1000 stats_shadow = kzalloc(NSS_STATS_DRV_MAX * 8, GFP_KERNEL);
1001 if (unlikely(stats_shadow == NULL)) {
1002 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +05301003 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301004 return 0;
1005 }
1006
1007 size_wr = scnprintf(lbuf, size_al, "drv stats start:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301008 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -08001009 stats_shadow[i] = NSS_PKT_STATS_READ(&nss_top_main.stats_drv[i]);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301010 }
1011
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301012 for (i = 0; (i < NSS_STATS_DRV_MAX); i++) {
1013 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1014 "%s = %llu\n", nss_stats_str_drv[i], stats_shadow[i]);
1015 }
1016
1017 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ndrv stats end\n\n");
1018 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
1019 kfree(lbuf);
1020 kfree(stats_shadow);
1021
1022 return bytes_read;
1023}
1024
1025/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301026 * nss_stats_pppoe_read()
1027 * Read PPPoE stats
1028 */
1029static ssize_t nss_stats_pppoe_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1030{
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301031 int32_t i, j, k;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301032
1033 /*
1034 * max output lines = #stats + start tag line + end tag line + three blank lines
1035 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301036 uint32_t max_output_lines = (NSS_STATS_NODE_MAX + 2) + (NSS_STATS_PPPOE_MAX + 3) +
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301037 ((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 +05301038 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
1039 size_t size_wr = 0;
1040 ssize_t bytes_read = 0;
1041 uint64_t *stats_shadow;
1042
1043 char *lbuf = kzalloc(size_al, GFP_KERNEL);
1044 if (unlikely(lbuf == NULL)) {
1045 nss_warning("Could not allocate memory for local statistics buffer");
1046 return 0;
1047 }
1048
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301049 stats_shadow = kzalloc(64 * 8, GFP_KERNEL);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301050 if (unlikely(stats_shadow == NULL)) {
1051 nss_warning("Could not allocate memory for local shadow buffer");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301052 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301053 return 0;
1054 }
1055
1056 size_wr = scnprintf(lbuf, size_al, "pppoe stats start:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301057
1058 /*
1059 * Common node stats
1060 */
Abhishek Rastogia1a07972014-04-01 19:43:33 +05301061 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301062 spin_lock_bh(&nss_top_main.stats_lock);
1063 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
1064 stats_shadow[i] = nss_top_main.stats_node[NSS_PPPOE_RX_INTERFACE][i];
1065 }
1066
1067 spin_unlock_bh(&nss_top_main.stats_lock);
1068
1069 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
1070 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1071 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
1072 }
1073
1074 /*
1075 * PPPoE node stats
1076 */
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001077 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe node stats:\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301078 spin_lock_bh(&nss_top_main.stats_lock);
1079 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
1080 stats_shadow[i] = nss_top_main.stats_pppoe[i];
1081 }
1082
1083 spin_unlock_bh(&nss_top_main.stats_lock);
1084
1085 for (i = 0; (i < NSS_STATS_PPPOE_MAX); i++) {
1086 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1087 "%s = %llu\n", nss_stats_str_pppoe[i], stats_shadow[i]);
1088 }
1089
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301090 /*
1091 * Exception stats
1092 */
1093 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nException PPPoE:\n\n");
1094
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001095 for (j = 1; j <= NSS_MAX_PHYSICAL_INTERFACES; j++) {
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301096 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nInterface %d:\n\n", j);
1097
1098 spin_lock_bh(&nss_top_main.stats_lock);
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001099 for (k = 1; k <= NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) {
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301100 for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) {
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001101 stats_shadow_pppoe_except[k - 1][i] = nss_top_main.stats_if_exception_pppoe[j][k][i];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301102 }
1103 }
1104
1105 spin_unlock_bh(&nss_top_main.stats_lock);
1106
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001107 for (k = 1; k <= NSS_PPPOE_NUM_SESSION_PER_INTERFACE; k++) {
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301108 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "%d. Session\n", k);
Ankit Dhanukaa1569ce2014-05-13 19:58:06 +05301109 for (i = 0; (i < NSS_PPPOE_EXCEPTION_EVENT_MAX); i++) {
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301110 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1111 "%s = %llu\n",
1112 nss_stats_str_if_exception_pppoe[i],
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001113 stats_shadow_pppoe_except[k - 1][i]);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301114 }
1115 }
1116
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301117 }
1118
Murat Sezgin2f9241a2015-06-25 13:01:51 -07001119 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\npppoe stats end\n\n");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301120 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
1121 kfree(lbuf);
1122 kfree(stats_shadow);
1123
1124 return bytes_read;
1125}
1126
1127/*
1128 * nss_stats_gmac_read()
1129 * Read GMAC stats
1130 */
1131static ssize_t nss_stats_gmac_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1132{
1133 uint32_t i, id;
1134
1135 /*
1136 * max output lines = ((#stats + start tag + one blank) * #GMACs) + start/end tag + 3 blank
1137 */
1138 uint32_t max_output_lines = ((NSS_STATS_GMAC_MAX + 2) * NSS_MAX_PHYSICAL_INTERFACES) + 5;
1139 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
1140 size_t size_wr = 0;
1141 ssize_t bytes_read = 0;
1142 uint64_t *stats_shadow;
1143
1144 char *lbuf = kzalloc(size_al, GFP_KERNEL);
1145 if (unlikely(lbuf == NULL)) {
1146 nss_warning("Could not allocate memory for local statistics buffer");
1147 return 0;
1148 }
1149
1150 stats_shadow = kzalloc(NSS_STATS_GMAC_MAX * 8, GFP_KERNEL);
1151 if (unlikely(stats_shadow == NULL)) {
1152 nss_warning("Could not allocate memory for local shadow buffer");
Ankit Dhanuka14999992014-11-12 15:35:11 +05301153 kfree(lbuf);
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301154 return 0;
1155 }
1156
1157 size_wr = scnprintf(lbuf, size_al, "gmac stats start:\n\n");
1158
1159 for (id = 0; id < NSS_MAX_PHYSICAL_INTERFACES; id++) {
1160 spin_lock_bh(&nss_top_main.stats_lock);
1161 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
1162 stats_shadow[i] = nss_top_main.stats_gmac[id][i];
1163 }
1164
1165 spin_unlock_bh(&nss_top_main.stats_lock);
1166
1167 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "GMAC ID: %d\n", id);
1168 for (i = 0; (i < NSS_STATS_GMAC_MAX); i++) {
1169 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1170 "%s = %llu\n", nss_stats_str_gmac[i], stats_shadow[i]);
1171 }
1172 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n");
1173 }
1174
1175 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\ngmac stats end\n\n");
1176 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
1177 kfree(lbuf);
1178 kfree(stats_shadow);
1179
1180 return bytes_read;
1181}
1182
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001183/*
Bharath M Kumarcc666e92014-12-24 19:17:28 +05301184 * nss_stats_wifi_read()
1185 * Read wifi statistics
1186 */
1187static ssize_t nss_stats_wifi_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1188{
1189 uint32_t i, id;
1190
1191 /*
1192 * max output lines = ((#stats + start tag + one blank) * #WIFI RADIOs) + start/end tag + 3 blank
1193 */
1194 uint32_t max_output_lines = ((NSS_STATS_WIFI_MAX + 2) * NSS_MAX_WIFI_RADIO_INTERFACES) + 5;
1195 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
1196 size_t size_wr = 0;
1197 ssize_t bytes_read = 0;
1198 uint64_t *stats_shadow;
1199
1200 char *lbuf = kzalloc(size_al, GFP_KERNEL);
1201 if (unlikely(lbuf == NULL)) {
1202 nss_warning("Could not allocate memory for local statistics buffer");
1203 return 0;
1204 }
1205
1206 stats_shadow = kzalloc(NSS_STATS_WIFI_MAX * 8, GFP_KERNEL);
1207 if (unlikely(stats_shadow == NULL)) {
1208 nss_warning("Could not allocate memory for local shadow buffer");
1209 kfree(lbuf);
1210 return 0;
1211 }
1212
1213 size_wr = scnprintf(lbuf, size_al, "wifi stats start:\n\n");
1214
1215 for (id = 0; id < NSS_MAX_WIFI_RADIO_INTERFACES; id++) {
1216 spin_lock_bh(&nss_top_main.stats_lock);
1217 for (i = 0; (i < NSS_STATS_WIFI_MAX); i++) {
1218 stats_shadow[i] = nss_top_main.stats_wifi[id][i];
1219 }
1220
1221 spin_unlock_bh(&nss_top_main.stats_lock);
1222
1223 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "WIFI ID: %d\n", id);
1224 for (i = 0; (i < NSS_STATS_WIFI_MAX); i++) {
1225 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1226 "%s = %llu\n", nss_stats_str_wifi[i], stats_shadow[i]);
1227 }
1228 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,"\n");
1229 }
1230
1231 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nwifi stats end\n\n");
1232 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
1233 kfree(lbuf);
1234 kfree(stats_shadow);
1235
1236 return bytes_read;
1237}
1238
1239/*
Ankit Dhanuka14999992014-11-12 15:35:11 +05301240 * nss_stats_sjack_read()
1241 * Read SJACK stats
1242 */
1243static ssize_t nss_stats_sjack_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1244{
1245 int32_t i;
1246 /*
1247 * max output lines = #stats + start tag line + end tag line + three blank lines
1248 */
1249 uint32_t max_output_lines = NSS_STATS_NODE_MAX + 5;
1250 size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
1251 size_t size_wr = 0;
1252 ssize_t bytes_read = 0;
1253 uint64_t *stats_shadow;
1254
1255 char *lbuf = kzalloc(size_al, GFP_KERNEL);
1256 if (unlikely(lbuf == NULL)) {
1257 nss_warning("Could not allocate memory for local statistics buffer");
1258 return 0;
1259 }
1260
1261 stats_shadow = kzalloc(NSS_STATS_NODE_MAX * 8, GFP_KERNEL);
1262 if (unlikely(stats_shadow == NULL)) {
1263 nss_warning("Could not allocate memory for local shadow buffer");
1264 kfree(lbuf);
1265 return 0;
1266 }
1267
1268 size_wr = scnprintf(lbuf, size_al, "sjack stats start:\n\n");
1269
1270 /*
1271 * Common node stats
1272 */
1273 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "common node stats:\n\n");
1274 spin_lock_bh(&nss_top_main.stats_lock);
1275 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
1276 stats_shadow[i] = nss_top_main.stats_node[NSS_SJACK_INTERFACE][i];
1277 }
1278
1279 spin_unlock_bh(&nss_top_main.stats_lock);
1280
1281 for (i = 0; (i < NSS_STATS_NODE_MAX); i++) {
1282 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
1283 "%s = %llu\n", nss_stats_str_node[i], stats_shadow[i]);
1284 }
1285
1286 size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nsjack stats end\n\n");
1287
1288 bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, strlen(lbuf));
1289 kfree(lbuf);
1290 kfree(stats_shadow);
1291
1292 return bytes_read;
1293}
1294
1295/*
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001296 * Make a row for CAPWAP encap stats.
1297 */
1298static ssize_t nss_stats_capwap_encap(char *line, int len, int i, struct nss_capwap_tunnel_stats *s)
1299{
Saurabh Misra3f66e872015-04-03 11:30:42 -07001300 char *header[] = { "packets", "bytes", "fragments", "drop_ref", "drop_ver", "drop_unalign",
1301 "drop_hroom", "drop_dtls", "drop_nwireless", "drop_qfull", "drop_memfail", "unknown" };
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001302 uint64_t tcnt = 0;
1303
1304 switch (i) {
1305 case 0:
1306 tcnt = s->pnode_stats.tx_packets;
1307 break;
1308 case 1:
1309 tcnt = s->pnode_stats.tx_bytes;
1310 break;
1311 case 2:
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001312 tcnt = s->tx_segments;
1313 break;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001314 case 3:
1315 tcnt = s->tx_dropped_sg_ref;
1316 break;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001317 case 4:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001318 tcnt = s->tx_dropped_ver_mis;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001319 break;
1320 case 5:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001321 tcnt = s->tx_dropped_unalign;
1322 break;
1323 case 6:
1324 tcnt = s->tx_dropped_hroom;
1325 break;
1326 case 7:
1327 tcnt = s->tx_dropped_dtls;
1328 break;
1329 case 8:
1330 tcnt = s->tx_dropped_nwireless;
1331 break;
1332 case 9:
1333 tcnt = s->tx_queue_full_drops;
1334 break;
1335 case 10:
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001336 tcnt = s->tx_mem_failure_drops;
1337 break;
1338 default:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001339 return 0;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001340 }
1341
Saurabh Misra3f66e872015-04-03 11:30:42 -07001342 return (snprintf(line, len, "%s = %llu\n", header[i], tcnt));
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001343}
1344
1345/*
1346 * Make a row for CAPWAP decap stats.
1347 */
1348static ssize_t nss_stats_capwap_decap(char *line, int len, int i, struct nss_capwap_tunnel_stats *s)
1349{
Saurabh Misra3f66e872015-04-03 11:30:42 -07001350 char *header[] = { "packets", "bytes", "DTLS_pkts", "fragments", "rx_dropped", "drop_oversize",
1351 "drop_frag_timeout", "drop_frag_dup", "drop_frag_gap", "drop_qfull", "drop_memfail",
1352 "drop_csum", "drop_malformed", "unknown" };
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001353 uint64_t tcnt = 0;
1354
1355 switch(i) {
1356 case 0:
1357 tcnt = s->pnode_stats.rx_packets;
1358 break;
1359 case 1:
1360 tcnt = s->pnode_stats.rx_bytes;
1361 break;
1362 case 2:
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001363 tcnt = s->dtls_pkts;
1364 break;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001365 case 3:
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001366 tcnt = s->rx_segments;
1367 break;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001368 case 4:
1369 tcnt = s->pnode_stats.rx_dropped;
1370 break;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001371 case 5:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001372 tcnt = s->rx_oversize_drops;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001373 break;
1374 case 6:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001375 tcnt = s->rx_frag_timeout_drops;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001376 break;
1377 case 7:
1378 tcnt = s->rx_dup_frag;
1379 break;
1380 case 8:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001381 tcnt = s->rx_frag_gap_drops;
1382 break;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001383 case 9:
Saurabh Misra3f66e872015-04-03 11:30:42 -07001384 tcnt = s->rx_queue_full_drops;
1385 return (snprintf(line, len, "%s = %llu (n2h = %llu)\n", header[i], tcnt, s->rx_n2h_queue_full_drops));
1386 case 10:
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001387 tcnt = s->rx_mem_failure_drops;
1388 break;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001389 case 11:
1390 tcnt = s->rx_csum_drops;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001391 break;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001392 case 12:
1393 tcnt = s->rx_malformed;
1394 break;
1395 default:
1396 return 0;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001397 }
1398
Saurabh Misra3f66e872015-04-03 11:30:42 -07001399 return (snprintf(line, len, "%s = %llu\n", header[i], tcnt));
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001400}
1401
1402/*
1403 * nss_stats_capwap_read()
1404 * Read CAPWAP stats
1405 */
1406static ssize_t nss_stats_capwap_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos, uint16_t type)
1407{
1408 struct nss_stats_data *data = fp->private_data;
1409 ssize_t bytes_read = 0;
1410 struct nss_capwap_tunnel_stats stats;
1411 size_t bytes;
1412 char line[80];
Saurabh Misra3f66e872015-04-03 11:30:42 -07001413 int start;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001414 uint32_t if_num = NSS_DYNAMIC_IF_START;
1415 uint32_t max_if_num = NSS_DYNAMIC_IF_START + NSS_MAX_DYNAMIC_INTERFACES;
1416
1417 if (data) {
1418 if_num = data->if_num;
1419 }
1420
1421 /*
1422 * If we are done accomodating all the CAPWAP tunnels.
1423 */
1424 if (if_num > max_if_num) {
1425 return 0;
1426 }
1427
1428 for (; if_num <= max_if_num; if_num++) {
1429 bool isthere;
1430
1431 if (nss_is_dynamic_interface(if_num) == false) {
1432 continue;
1433 }
1434
1435 if (nss_dynamic_interface_get_type(if_num) != NSS_DYNAMIC_INTERFACE_TYPE_CAPWAP) {
1436 continue;
1437 }
1438
1439 /*
1440 * If CAPWAP tunnel does not exists, then isthere will be false.
1441 */
1442 isthere = nss_capwap_get_stats(if_num, &stats);
1443 if (!isthere) {
1444 continue;
1445 }
1446
Saurabh Misra3f66e872015-04-03 11:30:42 -07001447 bytes = snprintf(line, sizeof(line), "----if_num : %2d----\n", if_num);
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001448 if ((bytes_read + bytes) > sz) {
1449 break;
1450 }
1451
1452 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1453 bytes_read = -EFAULT;
1454 goto fail;
1455 }
1456 bytes_read += bytes;
1457 start = 0;
Saurabh Misra3f66e872015-04-03 11:30:42 -07001458 while (bytes_read < sz) {
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001459 if (type == 1) {
1460 bytes = nss_stats_capwap_encap(line, sizeof(line), start, &stats);
1461 } else {
1462 bytes = nss_stats_capwap_decap(line, sizeof(line), start, &stats);
1463 }
1464
Saurabh Misra3f66e872015-04-03 11:30:42 -07001465 /*
1466 * If we don't have any more lines in decap/encap.
1467 */
1468 if (bytes == 0) {
1469 break;
1470 }
1471
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001472 if ((bytes_read + bytes) > sz)
1473 break;
1474
1475 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1476 bytes_read = -EFAULT;
1477 goto fail;
1478 }
1479
1480 bytes_read += bytes;
1481 start++;
1482 }
1483 }
1484
1485 if (bytes_read > 0) {
1486 *ppos = bytes_read;
1487 }
1488
1489 if (data) {
1490 data->if_num = if_num;
1491 }
1492fail:
1493 return bytes_read;
1494}
1495
1496/*
1497 * nss_stats_capwap_decap_read()
1498 * Read CAPWAP decap stats
1499 */
1500static ssize_t nss_stats_capwap_decap_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1501{
1502 return (nss_stats_capwap_read(fp, ubuf, sz, ppos, 0));
1503}
1504
1505/*
1506 * nss_stats_capwap_encap_read()
1507 * Read CAPWAP encap stats
1508 */
1509static ssize_t nss_stats_capwap_encap_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1510{
1511 return (nss_stats_capwap_read(fp, ubuf, sz, ppos, 1));
1512}
1513
1514/*
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +05301515 * nss_stats_gre_redir()
1516 * Make a row for GRE_REDIR stats.
1517 */
1518static ssize_t nss_stats_gre_redir(char *line, int len, int i, struct nss_gre_redir_tunnel_stats *s)
1519{
1520 char *header[] = { "TX Packets", "TX Bytes", "TX Drops", "RX Packets", "RX Bytes", "Rx Drops" };
1521 uint64_t tcnt = 0;
1522
1523 switch (i) {
1524 case 0:
1525 tcnt = s->node_stats.tx_packets;
1526 break;
1527 case 1:
1528 tcnt = s->node_stats.tx_bytes;
1529 break;
1530 case 2:
1531 tcnt = s->tx_dropped;
1532 break;
1533 case 3:
1534 tcnt = s->node_stats.rx_packets;
1535 break;
1536 case 4:
1537 tcnt = s->node_stats.rx_bytes;
1538 break;
1539 case 5:
1540 tcnt = s->node_stats.rx_dropped;
1541 break;
1542 default:
1543 i = 6;
1544 break;
1545 }
1546
1547 return (snprintf(line, len, "%s = %llu\n", header[i], tcnt));
1548}
1549
1550/*
1551 * nss_stats_gre_redir_read()
1552 * READ gre_redir tunnel stats.
1553 */
1554static ssize_t nss_stats_gre_redir_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1555{
1556 struct nss_stats_data *data = fp->private_data;
1557 ssize_t bytes_read = 0;
1558 struct nss_gre_redir_tunnel_stats stats;
1559 size_t bytes;
1560 char line[80];
1561 int start, end;
1562 int index = 0;
1563
1564 if (data) {
1565 index = data->index;
1566 }
1567
1568 /*
1569 * If we are done accomodating all the GRE_REDIR tunnels.
1570 */
1571 if (index >= NSS_GRE_REDIR_MAX_INTERFACES) {
1572 return 0;
1573 }
1574
1575 for (; index < NSS_GRE_REDIR_MAX_INTERFACES; index++) {
1576 bool isthere;
1577
1578 /*
1579 * If gre_redir tunnel does not exists, then isthere will be false.
1580 */
1581 isthere = nss_gre_redir_get_stats(index, &stats);
1582 if (!isthere) {
1583 continue;
1584 }
1585
1586 bytes = snprintf(line, sizeof(line), "\nTunnel if_num: %2d\n", stats.if_num);
1587 if ((bytes_read + bytes) > sz) {
1588 break;
1589 }
1590
1591 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1592 bytes_read = -EFAULT;
1593 goto fail;
1594 }
1595 bytes_read += bytes;
1596 start = 0;
1597 end = 6;
1598 while (bytes_read < sz && start < end) {
1599 bytes = nss_stats_gre_redir(line, sizeof(line), start, &stats);
1600
1601 if ((bytes_read + bytes) > sz)
1602 break;
1603
1604 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1605 bytes_read = -EFAULT;
1606 goto fail;
1607 }
1608
1609 bytes_read += bytes;
1610 start++;
1611 }
1612 }
1613
1614 if (bytes_read > 0) {
1615 *ppos = bytes_read;
1616 }
1617
1618 if (data) {
1619 data->index = index;
1620 }
1621
1622fail:
1623 return bytes_read;
1624}
1625
1626/*
Sundarajan Srinivasan273d9002015-03-03 15:43:16 -08001627 * nss_stats_wifi_if_read()
1628 * Read wifi_if statistics
1629 */
1630static ssize_t nss_stats_wifi_if_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
1631{
1632 struct nss_stats_data *data = fp->private_data;
1633 int32_t if_num = NSS_DYNAMIC_IF_START;
1634 int32_t max_if_num = if_num + NSS_MAX_DYNAMIC_INTERFACES;
1635 size_t bytes = 0;
1636 ssize_t bytes_read = 0;
1637 char line[80];
1638 int start, end;
1639
1640 if (data) {
1641 if_num = data->if_num;
1642 }
1643
1644 if (if_num > max_if_num) {
1645 return 0;
1646 }
1647
1648 for (; if_num < max_if_num; if_num++) {
1649 if (nss_dynamic_interface_get_type(if_num) != NSS_DYNAMIC_INTERFACE_TYPE_WIFI)
1650 continue;
1651
1652 bytes = scnprintf(line, sizeof(line), "if_num %d stats start:\n\n", if_num);
1653 if ((bytes_read + bytes) > sz)
1654 break;
1655
1656 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1657 bytes_read = -EFAULT;
1658 goto end;
1659 }
1660
1661 bytes_read += bytes;
1662
1663 start = 0;
1664 end = 7;
1665 while (bytes_read < sz && start < end) {
1666 bytes = nss_wifi_if_copy_stats(if_num, start, line);
1667 if (!bytes)
1668 break;
1669
1670 if ((bytes_read + bytes) > sz)
1671 break;
1672
1673 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1674 bytes_read = -EFAULT;
1675 goto end;
1676 }
1677
1678 bytes_read += bytes;
1679 start++;
1680 }
1681
1682 bytes = scnprintf(line, sizeof(line), "if_num %d stats end:\n\n", if_num);
1683 if (bytes_read > (sz - bytes))
1684 break;
1685
1686 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1687 bytes_read = -EFAULT;
1688 goto end;
1689 }
1690
1691 bytes_read += bytes;
1692 }
1693
1694 if (bytes_read > 0) {
1695 *ppos = bytes_read;
1696 }
1697
1698 if (data) {
1699 data->if_num = if_num;
1700 }
1701
1702end:
1703 return bytes_read;
1704}
1705
1706/*
Sundarajan Srinivasanab2c8562015-06-09 16:14:10 -07001707 * nss_stats_virt_if_read()
1708 * Read virt_if statistics
1709 */
1710static ssize_t nss_stats_virt_if_read(struct file *fp, char __user *ubuf,
1711 size_t sz, loff_t *ppos)
1712{
1713 struct nss_stats_data *data = fp->private_data;
1714 int32_t if_num = NSS_DYNAMIC_IF_START;
1715 int32_t max_if_num = if_num + NSS_MAX_DYNAMIC_INTERFACES;
1716 size_t bytes = 0;
1717 ssize_t bytes_read = 0;
1718 char line[80];
1719 int start, end;
1720
1721 if (data) {
1722 if_num = data->if_num;
1723 }
1724
1725 if (if_num > max_if_num) {
1726 return 0;
1727 }
1728
1729 for (; if_num < max_if_num; if_num++) {
1730 if (nss_dynamic_interface_get_type(if_num) != NSS_DYNAMIC_INTERFACE_TYPE_802_3_REDIR)
1731 continue;
1732
1733 bytes = scnprintf(line, sizeof(line), "if_num %d stats start:\n\n", if_num);
1734 if ((bytes_read + bytes) > sz)
1735 break;
1736
1737 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1738 bytes_read = -EFAULT;
1739 goto end;
1740 }
1741
1742 bytes_read += bytes;
1743
1744 start = 0;
1745 end = 7;
1746 while (bytes_read < sz && start < end) {
1747 bytes = nss_virt_if_copy_stats(if_num, start, line);
1748 if (!bytes)
1749 break;
1750
1751 if ((bytes_read + bytes) > sz)
1752 break;
1753
1754 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1755 bytes_read = -EFAULT;
1756 goto end;
1757 }
1758
1759 bytes_read += bytes;
1760 start++;
1761 }
1762
1763 bytes = scnprintf(line, sizeof(line), "if_num %d stats end:\n\n", if_num);
1764 if (bytes_read > (sz - bytes))
1765 break;
1766
1767 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1768 bytes_read = -EFAULT;
1769 goto end;
1770 }
1771
1772 bytes_read += bytes;
1773 }
1774
1775 if (bytes_read > 0) {
1776 *ppos = bytes_read;
1777 }
1778
1779 if (data) {
1780 data->if_num = if_num;
1781 }
1782
1783end:
1784 return bytes_read;
1785}
1786
1787/*
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -07001788 * nss_stats_tx_rx_virt_if_read()
1789 * Read tx_rx_virt_if statistics
1790 */
1791static ssize_t nss_stats_tx_rx_virt_if_read(struct file *fp, char __user *ubuf,
1792 size_t sz, loff_t *ppos)
1793{
1794 struct nss_stats_data *data = fp->private_data;
1795 int32_t if_num = NSS_DYNAMIC_IF_START;
1796 int32_t max_if_num = if_num + NSS_MAX_DYNAMIC_INTERFACES;
1797 size_t bytes = 0;
1798 ssize_t bytes_read = 0;
1799 char line[80];
1800 int start, end;
1801
1802 if (data) {
1803 if_num = data->if_num;
1804 }
1805
1806 if (if_num > max_if_num) {
1807 return 0;
1808 }
1809
1810 for (; if_num < max_if_num; if_num++) {
1811 if (nss_dynamic_interface_get_type(if_num) != NSS_DYNAMIC_INTERFACE_TYPE_VIRTIF_DEPRECATED)
1812 continue;
1813
1814 bytes = scnprintf(line, sizeof(line), "if_num %d stats start:\n\n", if_num);
1815 if ((bytes_read + bytes) > sz)
1816 break;
1817
1818 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1819 bytes_read = -EFAULT;
1820 goto end;
1821 }
1822
1823 bytes_read += bytes;
1824
1825 start = 0;
1826 end = 7;
1827 while (bytes_read < sz && start < end) {
1828 bytes = nss_tx_rx_virt_if_copy_stats(if_num, start, line);
1829 if (!bytes)
1830 break;
1831
1832 if ((bytes_read + bytes) > sz)
1833 break;
1834
1835 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1836 bytes_read = -EFAULT;
1837 goto end;
1838 }
1839
1840 bytes_read += bytes;
1841 start++;
1842 }
1843
1844 bytes = scnprintf(line, sizeof(line), "if_num %d stats end:\n\n", if_num);
1845 if (bytes_read > (sz - bytes))
1846 break;
1847
1848 if (copy_to_user(ubuf + bytes_read, line, bytes) != 0) {
1849 bytes_read = -EFAULT;
1850 goto end;
1851 }
1852
1853 bytes_read += bytes;
1854 }
1855
1856 if (bytes_read > 0) {
1857 *ppos = bytes_read;
1858 }
1859
1860 if (data) {
1861 data->if_num = if_num;
1862 }
1863
1864end:
1865 return bytes_read;
1866}
1867
1868/*
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001869 * nss_stats_open()
1870 */
1871static int nss_stats_open(struct inode *inode, struct file *filp)
1872{
1873 struct nss_stats_data *data = NULL;
1874
1875 data = kzalloc(sizeof(struct nss_stats_data), GFP_KERNEL);
1876 if (!data) {
1877 return -ENOMEM;
1878 }
1879 memset(data, 0, sizeof (struct nss_stats_data));
1880 data->if_num = NSS_DYNAMIC_IF_START;
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +05301881 data->index = 0;
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001882 filp->private_data = data;
1883
1884 return 0;
1885}
1886
1887/*
1888 * nss_stats_release()
1889 */
1890static int nss_stats_release(struct inode *inode, struct file *filp)
1891{
1892 struct nss_stats_data *data = filp->private_data;
1893
1894 if (data) {
1895 kfree(data);
1896 }
1897
1898 return 0;
1899}
1900
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301901#define NSS_STATS_DECLARE_FILE_OPERATIONS(name) \
1902static const struct file_operations nss_stats_##name##_ops = { \
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001903 .open = nss_stats_open, \
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301904 .read = nss_stats_##name##_read, \
1905 .llseek = generic_file_llseek, \
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001906 .release = nss_stats_release, \
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301907};
1908
1909/*
1910 * nss_ipv4_stats_ops
1911 */
1912NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4)
1913
1914/*
Selin Dag6d9b0c12014-11-04 18:27:21 -08001915 * ipv4_reasm_stats_ops
1916 */
1917NSS_STATS_DECLARE_FILE_OPERATIONS(ipv4_reasm)
1918
1919/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301920 * ipv6_stats_ops
1921 */
1922NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6)
1923
1924/*
Selin Dag60a2f5b2015-06-29 14:39:49 -07001925 * ipv6_reasm_stats_ops
1926 */
1927NSS_STATS_DECLARE_FILE_OPERATIONS(ipv6_reasm)
1928
1929/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301930 * n2h_stats_ops
1931 */
1932NSS_STATS_DECLARE_FILE_OPERATIONS(n2h)
Thomas Wuc3e382c2014-10-29 15:35:13 -07001933
1934/*
1935 * lso_rx_stats_ops
1936 */
1937NSS_STATS_DECLARE_FILE_OPERATIONS(lso_rx)
1938
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301939/*
1940 * drv_stats_ops
1941 */
1942NSS_STATS_DECLARE_FILE_OPERATIONS(drv)
1943
1944/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301945 * pppoe_stats_ops
1946 */
1947NSS_STATS_DECLARE_FILE_OPERATIONS(pppoe)
1948
1949/*
1950 * gmac_stats_ops
1951 */
1952NSS_STATS_DECLARE_FILE_OPERATIONS(gmac)
1953
1954/*
Saurabh Misra09dddeb2014-09-30 16:38:07 -07001955 * capwap_stats_ops
1956 */
1957NSS_STATS_DECLARE_FILE_OPERATIONS(capwap_encap)
1958NSS_STATS_DECLARE_FILE_OPERATIONS(capwap_decap)
1959
1960/*
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301961 * eth_rx_stats_ops
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301962 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301963NSS_STATS_DECLARE_FILE_OPERATIONS(eth_rx)
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301964
1965/*
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +05301966 * gre_redir_ops
1967 */
1968NSS_STATS_DECLARE_FILE_OPERATIONS(gre_redir)
1969
1970/*
Ankit Dhanuka14999992014-11-12 15:35:11 +05301971 * sjack_stats_ops
1972 */
1973NSS_STATS_DECLARE_FILE_OPERATIONS(sjack)
1974
Sundarajan Srinivasan273d9002015-03-03 15:43:16 -08001975NSS_STATS_DECLARE_FILE_OPERATIONS(wifi_if)
1976
Sundarajan Srinivasanab2c8562015-06-09 16:14:10 -07001977NSS_STATS_DECLARE_FILE_OPERATIONS(virt_if)
1978
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -07001979NSS_STATS_DECLARE_FILE_OPERATIONS(tx_rx_virt_if)
1980
Ankit Dhanuka14999992014-11-12 15:35:11 +05301981/*
Bharath M Kumarcc666e92014-12-24 19:17:28 +05301982 * wifi_stats_ops
1983 */
1984NSS_STATS_DECLARE_FILE_OPERATIONS(wifi)
1985
1986/*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05301987 * nss_stats_init()
1988 * Enable NSS statistics
1989 */
1990void nss_stats_init(void)
1991{
1992 /*
1993 * NSS driver entry
1994 */
1995 nss_top_main.top_dentry = debugfs_create_dir("qca-nss-drv", NULL);
1996 if (unlikely(nss_top_main.top_dentry == NULL)) {
1997 nss_warning("Failed to create qca-nss-drv directory in debugfs");
1998
1999 /*
2000 * Non availability of debugfs directory is not a catastrophy
2001 * We can still go ahead with other initialization
2002 */
2003 return;
2004 }
2005
2006 nss_top_main.stats_dentry = debugfs_create_dir("stats", nss_top_main.top_dentry);
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +05302007 if (unlikely(nss_top_main.stats_dentry == NULL)) {
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302008 nss_warning("Failed to create qca-nss-drv directory in debugfs");
2009
2010 /*
2011 * Non availability of debugfs directory is not a catastrophy
2012 * We can still go ahead with rest of initialization
2013 */
2014 return;
2015 }
2016
2017 /*
2018 * Create files to obtain statistics
2019 */
2020
2021 /*
2022 * ipv4_stats
2023 */
2024 nss_top_main.ipv4_dentry = debugfs_create_file("ipv4", 0400,
2025 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_ops);
2026 if (unlikely(nss_top_main.ipv4_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +05302027 nss_warning("Failed to create qca-nss-drv/stats/ipv4 file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302028 return;
2029 }
2030
2031 /*
Selin Dag6d9b0c12014-11-04 18:27:21 -08002032 * ipv4_reasm_stats
2033 */
2034 nss_top_main.ipv4_reasm_dentry = debugfs_create_file("ipv4_reasm", 0400,
2035 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv4_reasm_ops);
2036 if (unlikely(nss_top_main.ipv4_reasm_dentry == NULL)) {
2037 nss_warning("Failed to create qca-nss-drv/stats/ipv4_reasm file in debugfs");
2038 return;
2039 }
2040
2041 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302042 * ipv6_stats
2043 */
2044 nss_top_main.ipv6_dentry = debugfs_create_file("ipv6", 0400,
2045 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_ops);
2046 if (unlikely(nss_top_main.ipv6_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +05302047 nss_warning("Failed to create qca-nss-drv/stats/ipv6 file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302048 return;
2049 }
2050
2051 /*
Selin Dag60a2f5b2015-06-29 14:39:49 -07002052 * ipv6_reasm_stats
2053 */
2054 nss_top_main.ipv6_reasm_dentry = debugfs_create_file("ipv6_reasm", 0400,
2055 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_ipv6_reasm_ops);
2056 if (unlikely(nss_top_main.ipv6_reasm_dentry == NULL)) {
2057 nss_warning("Failed to create qca-nss-drv/stats/ipv6_reasm file in debugfs");
2058 return;
2059 }
2060
2061 /*
2062 * eth_rx__stats
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302063 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05302064 nss_top_main.eth_rx_dentry = debugfs_create_file("eth_rx", 0400,
2065 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_eth_rx_ops);
2066 if (unlikely(nss_top_main.eth_rx_dentry == NULL)) {
2067 nss_warning("Failed to create qca-nss-drv/stats/eth_rx file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302068 return;
2069 }
2070
2071 /*
2072 * n2h_stats
2073 */
2074 nss_top_main.n2h_dentry = debugfs_create_file("n2h", 0400,
2075 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_n2h_ops);
2076 if (unlikely(nss_top_main.n2h_dentry == NULL)) {
2077 nss_warning("Failed to create qca-nss-drv/stats/n2h directory in debugfs");
2078 return;
2079 }
2080
2081 /*
Thomas Wuc3e382c2014-10-29 15:35:13 -07002082 * lso_rx_stats
2083 */
2084 nss_top_main.lso_rx_dentry = debugfs_create_file("lso_rx", 0400,
2085 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_lso_rx_ops);
2086 if (unlikely(nss_top_main.lso_rx_dentry == NULL)) {
2087 nss_warning("Failed to create qca-nss-drv/stats/lso_rx file in debugfs");
2088 return;
2089 }
2090
2091 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302092 * drv_stats
2093 */
2094 nss_top_main.drv_dentry = debugfs_create_file("drv", 0400,
2095 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_drv_ops);
2096 if (unlikely(nss_top_main.drv_dentry == NULL)) {
2097 nss_warning("Failed to create qca-nss-drv/stats/drv directory in debugfs");
2098 return;
2099 }
2100
2101 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302102 * pppoe_stats
2103 */
2104 nss_top_main.pppoe_dentry = debugfs_create_file("pppoe", 0400,
2105 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_pppoe_ops);
2106 if (unlikely(nss_top_main.pppoe_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +05302107 nss_warning("Failed to create qca-nss-drv/stats/pppoe file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302108 return;
2109 }
2110
2111 /*
2112 * gmac_stats
2113 */
2114 nss_top_main.gmac_dentry = debugfs_create_file("gmac", 0400,
2115 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gmac_ops);
2116 if (unlikely(nss_top_main.gmac_dentry == NULL)) {
Abhishek Rastogi80f4eb12013-09-24 14:31:21 +05302117 nss_warning("Failed to create qca-nss-drv/stats/gmac file in debugfs");
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302118 return;
2119 }
Saurabh Misra09dddeb2014-09-30 16:38:07 -07002120
2121 /*
2122 * CAPWAP stats.
2123 */
2124 nss_top_main.capwap_encap_dentry = debugfs_create_file("capwap_encap", 0400,
2125 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_capwap_encap_ops);
2126 if (unlikely(nss_top_main.capwap_encap_dentry == NULL)) {
2127 nss_warning("Failed to create qca-nss-drv/stats/capwap_encap file in debugfs");
2128 return;
2129 }
2130
2131 nss_top_main.capwap_decap_dentry = debugfs_create_file("capwap_decap", 0400,
2132 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_capwap_decap_ops);
2133 if (unlikely(nss_top_main.capwap_decap_dentry == NULL)) {
2134 nss_warning("Failed to create qca-nss-drv/stats/capwap_decap file in debugfs");
2135 return;
2136 }
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +05302137
2138 /*
2139 * GRE_REDIR stats
2140 */
2141 nss_top_main.gre_redir_dentry = debugfs_create_file("gre_redir", 0400,
Ankit Dhanuka14999992014-11-12 15:35:11 +05302142 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_gre_redir_ops);
Ankit Dhanuka6228ebd2014-11-05 17:26:01 +05302143 if (unlikely(nss_top_main.gre_redir_dentry == NULL)) {
2144 nss_warning("Failed to create qca-nss-drv/stats/gre_redir file in debugfs");
2145 return;
2146 }
Ankit Dhanuka14999992014-11-12 15:35:11 +05302147
2148 /*
2149 * SJACK stats
2150 */
2151 nss_top_main.sjack_dentry = debugfs_create_file("sjack", 0400,
2152 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_sjack_ops);
2153 if (unlikely(nss_top_main.sjack_dentry == NULL)) {
2154 nss_warning("Failed to create qca-nss-drv/stats/sjack file in debugfs");
2155 return;
2156 }
Saurabh Misra96998db2014-07-10 12:15:48 -07002157
Bharath M Kumarcc666e92014-12-24 19:17:28 +05302158 /*
2159 * WIFI stats
2160 */
2161 nss_top_main.wifi_dentry = debugfs_create_file("wifi", 0400,
2162 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_wifi_ops);
2163 if (unlikely(nss_top_main.wifi_dentry == NULL)) {
2164 nss_warning("Failed to create qca-nss-drv/stats/wifi file in debugfs");
2165 return;
2166 }
2167
Sundarajan Srinivasan273d9002015-03-03 15:43:16 -08002168 /*
2169 * wifi_if stats
2170 */
2171 nss_top_main.wifi_if_dentry = debugfs_create_file("wifi_if", 0400,
2172 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_wifi_if_ops);
2173 if (unlikely(nss_top_main.wifi_if_dentry == NULL)) {
2174 nss_warning("Failed to create qca-nss-drv/stats/wifi_if file in debugfs");
2175 return;
2176 }
2177
Sundarajan Srinivasanab2c8562015-06-09 16:14:10 -07002178 nss_top_main.virt_if_dentry = debugfs_create_file("virt_if", 0400,
2179 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_virt_if_ops);
2180 if (unlikely(nss_top_main.virt_if_dentry == NULL)) {
2181 nss_warning("Failed to create qca-nss-drv/stats/virt_if file in debugfs");
2182 return;
2183 }
2184
Sundarajan Srinivasancd1631b2015-06-18 01:23:30 -07002185 nss_top_main.tx_rx_virt_if_dentry = debugfs_create_file("tx_rx_virt_if", 0400,
2186 nss_top_main.stats_dentry, &nss_top_main, &nss_stats_tx_rx_virt_if_ops);
2187 if (unlikely(nss_top_main.virt_if_dentry == NULL)) {
2188 nss_warning("Failed to create qca-nss-drv/stats/tx_rx_virt_if file in debugfs");
2189 return;
2190 }
2191
Saurabh Misra96998db2014-07-10 12:15:48 -07002192 nss_log_init();
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302193}
2194
2195
2196/*
2197 * nss_stats_clean()
2198 * Cleanup NSS statistics files
2199 */
2200void nss_stats_clean(void)
2201{
2202 /*
2203 * Remove debugfs tree
2204 */
2205 if (likely(nss_top_main.top_dentry != NULL)) {
2206 debugfs_remove_recursive(nss_top_main.top_dentry);
Stephen Wangdc8b5322015-06-27 20:11:50 -07002207 nss_top_main.top_dentry = NULL;
Abhishek Rastogi38cffff2013-06-02 11:25:47 +05302208 }
2209}