blob: db74c4fd03c5d0656f8a75aed96b8750146d6880 [file] [log] [blame]
Subash Abhinov Kasiviswanathan2139ce8a2016-10-14 11:01:48 -06001/* Copyright (c) 2014, 2016 The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 *
13 * RMNET Data statistics
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/export.h>
19#include <linux/skbuff.h>
20#include <linux/spinlock.h>
21#include <linux/netdevice.h>
22#include <net/rmnet_config.h>
23#include "rmnet_data_private.h"
24#include "rmnet_data_stats.h"
25#include "rmnet_data_config.h"
26#include "rmnet_map.h"
27
28enum rmnet_deagg_e {
29 RMNET_STATS_AGG_BUFF,
30 RMNET_STATS_AGG_PKT,
31 RMNET_STATS_AGG_MAX
32};
33
34static DEFINE_SPINLOCK(rmnet_skb_free_lock);
35unsigned long int skb_free[RMNET_STATS_SKBFREE_MAX];
36module_param_array(skb_free, ulong, 0, 0444);
37MODULE_PARM_DESC(skb_free, "SKBs dropped or freed");
38
39static DEFINE_SPINLOCK(rmnet_queue_xmit_lock);
40unsigned long int queue_xmit[RMNET_STATS_QUEUE_XMIT_MAX * 2];
41module_param_array(queue_xmit, ulong, 0, 0444);
42MODULE_PARM_DESC(queue_xmit, "SKBs queued for transmit");
43
Subash Abhinov Kasiviswanathan2139ce8a2016-10-14 11:01:48 -060044static DEFINE_SPINLOCK(rmnet_agg_count);
45unsigned long int agg_count[RMNET_STATS_AGG_MAX];
46module_param_array(agg_count, ulong, 0, 0444);
47MODULE_PARM_DESC(agg_count, "SKBs Aggregated");
48
49static DEFINE_SPINLOCK(rmnet_checksum_dl_stats);
50unsigned long int checksum_dl_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH];
51module_param_array(checksum_dl_stats, ulong, 0, 0444);
52MODULE_PARM_DESC(checksum_dl_stats, "Downlink Checksum Statistics");
53
54static DEFINE_SPINLOCK(rmnet_checksum_ul_stats);
55unsigned long int checksum_ul_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH];
56module_param_array(checksum_ul_stats, ulong, 0, 0444);
57MODULE_PARM_DESC(checksum_ul_stats, "Uplink Checksum Statistics");
58
59void rmnet_kfree_skb(struct sk_buff *skb, unsigned int reason)
60{
61 unsigned long flags;
62
63 if (reason >= RMNET_STATS_SKBFREE_MAX)
64 reason = RMNET_STATS_SKBFREE_UNKNOWN;
65
66 spin_lock_irqsave(&rmnet_skb_free_lock, flags);
67 skb_free[reason]++;
68 spin_unlock_irqrestore(&rmnet_skb_free_lock, flags);
69
Subash Abhinov Kasiviswanathan29e64522017-09-05 19:33:59 -060070 kfree_skb(skb);
Subash Abhinov Kasiviswanathan2139ce8a2016-10-14 11:01:48 -060071}
72
73void rmnet_stats_queue_xmit(int rc, unsigned int reason)
74{
75 unsigned long flags;
76
77 if (rc != 0)
78 reason += RMNET_STATS_QUEUE_XMIT_MAX;
79 if (reason >= RMNET_STATS_QUEUE_XMIT_MAX * 2)
80 reason = RMNET_STATS_SKBFREE_UNKNOWN;
81
82 spin_lock_irqsave(&rmnet_queue_xmit_lock, flags);
83 queue_xmit[reason]++;
84 spin_unlock_irqrestore(&rmnet_queue_xmit_lock, flags);
85}
86
87void rmnet_stats_agg_pkts(int aggcount)
88{
89 unsigned long flags;
90
91 spin_lock_irqsave(&rmnet_agg_count, flags);
92 agg_count[RMNET_STATS_AGG_BUFF]++;
93 agg_count[RMNET_STATS_AGG_PKT] += aggcount;
94 spin_unlock_irqrestore(&rmnet_agg_count, flags);
95}
96
Subash Abhinov Kasiviswanathan2139ce8a2016-10-14 11:01:48 -060097void rmnet_stats_dl_checksum(unsigned int rc)
98{
99 unsigned long flags;
100
101 if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH)
102 rc = RMNET_MAP_CHECKSUM_ERR_UNKNOWN;
103
104 spin_lock_irqsave(&rmnet_checksum_dl_stats, flags);
105 checksum_dl_stats[rc]++;
106 spin_unlock_irqrestore(&rmnet_checksum_dl_stats, flags);
107}
108
109void rmnet_stats_ul_checksum(unsigned int rc)
110{
111 unsigned long flags;
112
113 if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH)
114 rc = RMNET_MAP_CHECKSUM_ERR_UNKNOWN;
115
116 spin_lock_irqsave(&rmnet_checksum_ul_stats, flags);
117 checksum_ul_stats[rc]++;
118 spin_unlock_irqrestore(&rmnet_checksum_ul_stats, flags);
119}