summaryrefslogtreecommitdiff
path: root/net/rmnet_data/rmnet_data_stats.c
blob: 8fd3743799f854ae0261e22a9660a8301e11d7cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright (c) 2014, 2016 The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 * RMNET Data statistics
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/skbuff.h>
#include <linux/spinlock.h>
#include <linux/netdevice.h>
#include <net/rmnet_config.h>
#include "rmnet_data_private.h"
#include "rmnet_data_stats.h"
#include "rmnet_data_config.h"
#include "rmnet_map.h"

enum rmnet_deagg_e {
	RMNET_STATS_AGG_BUFF,
	RMNET_STATS_AGG_PKT,
	RMNET_STATS_AGG_MAX
};

static DEFINE_SPINLOCK(rmnet_skb_free_lock);
unsigned long int skb_free[RMNET_STATS_SKBFREE_MAX];
module_param_array(skb_free, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(skb_free, "SKBs dropped or freed");

static DEFINE_SPINLOCK(rmnet_queue_xmit_lock);
unsigned long int queue_xmit[RMNET_STATS_QUEUE_XMIT_MAX*2];
module_param_array(queue_xmit, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(queue_xmit, "SKBs queued for transmit");

static DEFINE_SPINLOCK(rmnet_deagg_count);
unsigned long int deagg_count[RMNET_STATS_AGG_MAX];
module_param_array(deagg_count, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(deagg_count, "SKBs De-aggregated");

static DEFINE_SPINLOCK(rmnet_agg_count);
unsigned long int agg_count[RMNET_STATS_AGG_MAX];
module_param_array(agg_count, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(agg_count, "SKBs Aggregated");

static DEFINE_SPINLOCK(rmnet_checksum_dl_stats);
unsigned long int checksum_dl_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH];
module_param_array(checksum_dl_stats, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(checksum_dl_stats, "Downlink Checksum Statistics");

static DEFINE_SPINLOCK(rmnet_checksum_ul_stats);
unsigned long int checksum_ul_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH];
module_param_array(checksum_ul_stats, ulong, 0, S_IRUGO);
MODULE_PARM_DESC(checksum_ul_stats, "Uplink Checksum Statistics");

void rmnet_kfree_skb(struct sk_buff *skb, unsigned int reason)
{
	unsigned long flags;

	if (reason >= RMNET_STATS_SKBFREE_MAX)
		reason = RMNET_STATS_SKBFREE_UNKNOWN;

	spin_lock_irqsave(&rmnet_skb_free_lock, flags);
	skb_free[reason]++;
	spin_unlock_irqrestore(&rmnet_skb_free_lock, flags);

	if (likely(skb)) {
		struct rmnet_phys_ep_conf_s *config;

		if (skb->destructor) {
			skb->destructor(skb);
			return;
		}

		config = (struct rmnet_phys_ep_conf_s *)rcu_dereference
			 (skb->dev->rx_handler_data);
		if (likely(config))
			config->recycle(skb);
		else
			kfree_skb(skb);
	}
}

void rmnet_stats_queue_xmit(int rc, unsigned int reason)
{
	unsigned long flags;

	if (rc != 0)
		reason += RMNET_STATS_QUEUE_XMIT_MAX;
	if (reason >= RMNET_STATS_QUEUE_XMIT_MAX*2)
		reason = RMNET_STATS_SKBFREE_UNKNOWN;

	spin_lock_irqsave(&rmnet_queue_xmit_lock, flags);
	queue_xmit[reason]++;
	spin_unlock_irqrestore(&rmnet_queue_xmit_lock, flags);
}

void rmnet_stats_agg_pkts(int aggcount)
{
	unsigned long flags;

	spin_lock_irqsave(&rmnet_agg_count, flags);
	agg_count[RMNET_STATS_AGG_BUFF]++;
	agg_count[RMNET_STATS_AGG_PKT] += aggcount;
	spin_unlock_irqrestore(&rmnet_agg_count, flags);
}

void rmnet_stats_deagg_pkts(int aggcount)
{
	unsigned long flags;

	spin_lock_irqsave(&rmnet_deagg_count, flags);
	deagg_count[RMNET_STATS_AGG_BUFF]++;
	deagg_count[RMNET_STATS_AGG_PKT] += aggcount;
	spin_unlock_irqrestore(&rmnet_deagg_count, flags);
}

void rmnet_stats_dl_checksum(unsigned int rc)
{
	unsigned long flags;

	if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH)
		rc = RMNET_MAP_CHECKSUM_ERR_UNKOWN;

	spin_lock_irqsave(&rmnet_checksum_dl_stats, flags);
	checksum_dl_stats[rc]++;
	spin_unlock_irqrestore(&rmnet_checksum_dl_stats, flags);
}

void rmnet_stats_ul_checksum(unsigned int rc)
{
	unsigned long flags;

	if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH)
		rc = RMNET_MAP_CHECKSUM_ERR_UNKOWN;

	spin_lock_irqsave(&rmnet_checksum_ul_stats, flags);
	checksum_ul_stats[rc]++;
	spin_unlock_irqrestore(&rmnet_checksum_ul_stats, flags);
}