Subash Abhinov Kasiviswanathan | 2139ce8a | 2016-10-14 11:01:48 -0600 | [diff] [blame] | 1 | /* 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 | |
| 28 | enum rmnet_deagg_e { |
| 29 | RMNET_STATS_AGG_BUFF, |
| 30 | RMNET_STATS_AGG_PKT, |
| 31 | RMNET_STATS_AGG_MAX |
| 32 | }; |
| 33 | |
| 34 | static DEFINE_SPINLOCK(rmnet_skb_free_lock); |
| 35 | unsigned long int skb_free[RMNET_STATS_SKBFREE_MAX]; |
| 36 | module_param_array(skb_free, ulong, 0, 0444); |
| 37 | MODULE_PARM_DESC(skb_free, "SKBs dropped or freed"); |
| 38 | |
| 39 | static DEFINE_SPINLOCK(rmnet_queue_xmit_lock); |
| 40 | unsigned long int queue_xmit[RMNET_STATS_QUEUE_XMIT_MAX * 2]; |
| 41 | module_param_array(queue_xmit, ulong, 0, 0444); |
| 42 | MODULE_PARM_DESC(queue_xmit, "SKBs queued for transmit"); |
| 43 | |
| 44 | static DEFINE_SPINLOCK(rmnet_deagg_count); |
| 45 | unsigned long int deagg_count[RMNET_STATS_AGG_MAX]; |
| 46 | module_param_array(deagg_count, ulong, 0, 0444); |
| 47 | MODULE_PARM_DESC(deagg_count, "SKBs De-aggregated"); |
| 48 | |
| 49 | static DEFINE_SPINLOCK(rmnet_agg_count); |
| 50 | unsigned long int agg_count[RMNET_STATS_AGG_MAX]; |
| 51 | module_param_array(agg_count, ulong, 0, 0444); |
| 52 | MODULE_PARM_DESC(agg_count, "SKBs Aggregated"); |
| 53 | |
| 54 | static DEFINE_SPINLOCK(rmnet_checksum_dl_stats); |
| 55 | unsigned long int checksum_dl_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH]; |
| 56 | module_param_array(checksum_dl_stats, ulong, 0, 0444); |
| 57 | MODULE_PARM_DESC(checksum_dl_stats, "Downlink Checksum Statistics"); |
| 58 | |
| 59 | static DEFINE_SPINLOCK(rmnet_checksum_ul_stats); |
| 60 | unsigned long int checksum_ul_stats[RMNET_MAP_CHECKSUM_ENUM_LENGTH]; |
| 61 | module_param_array(checksum_ul_stats, ulong, 0, 0444); |
| 62 | MODULE_PARM_DESC(checksum_ul_stats, "Uplink Checksum Statistics"); |
| 63 | |
| 64 | void rmnet_kfree_skb(struct sk_buff *skb, unsigned int reason) |
| 65 | { |
| 66 | unsigned long flags; |
| 67 | |
| 68 | if (reason >= RMNET_STATS_SKBFREE_MAX) |
| 69 | reason = RMNET_STATS_SKBFREE_UNKNOWN; |
| 70 | |
| 71 | spin_lock_irqsave(&rmnet_skb_free_lock, flags); |
| 72 | skb_free[reason]++; |
| 73 | spin_unlock_irqrestore(&rmnet_skb_free_lock, flags); |
| 74 | |
| 75 | if (likely(skb)) { |
| 76 | struct rmnet_phys_ep_conf_s *config; |
| 77 | |
| 78 | config = (struct rmnet_phys_ep_conf_s *)rcu_dereference |
| 79 | (skb->dev->rx_handler_data); |
| 80 | if (likely(config)) |
| 81 | config->recycle(skb); |
| 82 | else |
| 83 | kfree_skb(skb); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void rmnet_stats_queue_xmit(int rc, unsigned int reason) |
| 88 | { |
| 89 | unsigned long flags; |
| 90 | |
| 91 | if (rc != 0) |
| 92 | reason += RMNET_STATS_QUEUE_XMIT_MAX; |
| 93 | if (reason >= RMNET_STATS_QUEUE_XMIT_MAX * 2) |
| 94 | reason = RMNET_STATS_SKBFREE_UNKNOWN; |
| 95 | |
| 96 | spin_lock_irqsave(&rmnet_queue_xmit_lock, flags); |
| 97 | queue_xmit[reason]++; |
| 98 | spin_unlock_irqrestore(&rmnet_queue_xmit_lock, flags); |
| 99 | } |
| 100 | |
| 101 | void rmnet_stats_agg_pkts(int aggcount) |
| 102 | { |
| 103 | unsigned long flags; |
| 104 | |
| 105 | spin_lock_irqsave(&rmnet_agg_count, flags); |
| 106 | agg_count[RMNET_STATS_AGG_BUFF]++; |
| 107 | agg_count[RMNET_STATS_AGG_PKT] += aggcount; |
| 108 | spin_unlock_irqrestore(&rmnet_agg_count, flags); |
| 109 | } |
| 110 | |
| 111 | void rmnet_stats_deagg_pkts(int aggcount) |
| 112 | { |
| 113 | unsigned long flags; |
| 114 | |
| 115 | spin_lock_irqsave(&rmnet_deagg_count, flags); |
| 116 | deagg_count[RMNET_STATS_AGG_BUFF]++; |
| 117 | deagg_count[RMNET_STATS_AGG_PKT] += aggcount; |
| 118 | spin_unlock_irqrestore(&rmnet_deagg_count, flags); |
| 119 | } |
| 120 | |
| 121 | void rmnet_stats_dl_checksum(unsigned int rc) |
| 122 | { |
| 123 | unsigned long flags; |
| 124 | |
| 125 | if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH) |
| 126 | rc = RMNET_MAP_CHECKSUM_ERR_UNKNOWN; |
| 127 | |
| 128 | spin_lock_irqsave(&rmnet_checksum_dl_stats, flags); |
| 129 | checksum_dl_stats[rc]++; |
| 130 | spin_unlock_irqrestore(&rmnet_checksum_dl_stats, flags); |
| 131 | } |
| 132 | |
| 133 | void rmnet_stats_ul_checksum(unsigned int rc) |
| 134 | { |
| 135 | unsigned long flags; |
| 136 | |
| 137 | if (rc >= RMNET_MAP_CHECKSUM_ENUM_LENGTH) |
| 138 | rc = RMNET_MAP_CHECKSUM_ERR_UNKNOWN; |
| 139 | |
| 140 | spin_lock_irqsave(&rmnet_checksum_ul_stats, flags); |
| 141 | checksum_ul_stats[rc]++; |
| 142 | spin_unlock_irqrestore(&rmnet_checksum_ul_stats, flags); |
| 143 | } |