1
2
3
4
5#include <linux/module.h>
6#include <linux/atm.h>
7#include <linux/atmdev.h>
8#include <linux/skbuff.h>
9#include <linux/sonet.h>
10#include <linux/bitops.h>
11#include <linux/errno.h>
12#include <linux/atomic.h>
13
14int atm_charge(struct atm_vcc *vcc, int truesize)
15{
16 atm_force_charge(vcc, truesize);
17 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
18 return 1;
19 atm_return(vcc, truesize);
20 atomic_inc(&vcc->stats->rx_drop);
21 return 0;
22}
23EXPORT_SYMBOL(atm_charge);
24
25struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
26 gfp_t gfp_flags)
27{
28 struct sock *sk = sk_atm(vcc);
29 int guess = SKB_TRUESIZE(pdu_size);
30
31 atm_force_charge(vcc, guess);
32 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) {
33 struct sk_buff *skb = alloc_skb(pdu_size, gfp_flags);
34
35 if (skb) {
36 atomic_add(skb->truesize-guess,
37 &sk->sk_rmem_alloc);
38 return skb;
39 }
40 }
41 atm_return(vcc, guess);
42 atomic_inc(&vcc->stats->rx_drop);
43 return NULL;
44}
45EXPORT_SYMBOL(atm_alloc_charge);
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
75int atm_pcr_goal(const struct atm_trafprm *tp)
76{
77 if (tp->pcr && tp->pcr != ATM_MAX_PCR)
78 return -tp->pcr;
79 if (tp->min_pcr && !tp->pcr)
80 return tp->min_pcr;
81 if (tp->max_pcr != ATM_MAX_PCR)
82 return -tp->max_pcr;
83 return 0;
84}
85EXPORT_SYMBOL(atm_pcr_goal);
86
87void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
88{
89#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90 __SONET_ITEMS
91#undef __HANDLE_ITEM
92}
93EXPORT_SYMBOL(sonet_copy_stats);
94
95void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96{
97#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
98 __SONET_ITEMS
99#undef __HANDLE_ITEM
100}
101EXPORT_SYMBOL(sonet_subtract_stats);
102