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