Blame view
net/atm/atm_misc.c
2.57 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 |
/* net/atm/atm_misc.c - Various functions for use by ATM drivers */ /* Written 1995-2000 by Werner Almesberger, EPFL ICA */ |
1da177e4c Linux-2.6.12-rc2 |
4 5 6 7 8 9 |
#include <linux/module.h> #include <linux/atm.h> #include <linux/atmdev.h> #include <linux/skbuff.h> #include <linux/sonet.h> #include <linux/bitops.h> |
3356b4d41 net/atm/atm_misc.... |
10 |
#include <linux/errno.h> |
60063497a atomic: use <linu... |
11 |
#include <linux/atomic.h> |
1da177e4c Linux-2.6.12-rc2 |
12 |
|
3356b4d41 net/atm/atm_misc.... |
13 |
int atm_charge(struct atm_vcc *vcc, int truesize) |
1da177e4c Linux-2.6.12-rc2 |
14 |
{ |
3356b4d41 net/atm/atm_misc.... |
15 |
atm_force_charge(vcc, truesize); |
1da177e4c Linux-2.6.12-rc2 |
16 17 |
if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf) return 1; |
3356b4d41 net/atm/atm_misc.... |
18 |
atm_return(vcc, truesize); |
1da177e4c Linux-2.6.12-rc2 |
19 20 21 |
atomic_inc(&vcc->stats->rx_drop); return 0; } |
3356b4d41 net/atm/atm_misc.... |
22 |
EXPORT_SYMBOL(atm_charge); |
1da177e4c Linux-2.6.12-rc2 |
23 |
|
3356b4d41 net/atm/atm_misc.... |
24 25 |
struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size, gfp_t gfp_flags) |
1da177e4c Linux-2.6.12-rc2 |
26 27 |
{ struct sock *sk = sk_atm(vcc); |
49f5ed425 atm: eliminate at... |
28 |
int guess = SKB_TRUESIZE(pdu_size); |
1da177e4c Linux-2.6.12-rc2 |
29 |
|
3356b4d41 net/atm/atm_misc.... |
30 |
atm_force_charge(vcc, guess); |
1da177e4c Linux-2.6.12-rc2 |
31 |
if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) { |
3356b4d41 net/atm/atm_misc.... |
32 |
struct sk_buff *skb = alloc_skb(pdu_size, gfp_flags); |
1da177e4c Linux-2.6.12-rc2 |
33 34 35 36 37 38 39 |
if (skb) { atomic_add(skb->truesize-guess, &sk->sk_rmem_alloc); return skb; } } |
3356b4d41 net/atm/atm_misc.... |
40 |
atm_return(vcc, guess); |
1da177e4c Linux-2.6.12-rc2 |
41 42 43 |
atomic_inc(&vcc->stats->rx_drop); return NULL; } |
3356b4d41 net/atm/atm_misc.... |
44 |
EXPORT_SYMBOL(atm_alloc_charge); |
1da177e4c Linux-2.6.12-rc2 |
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 |
/* * atm_pcr_goal returns the positive PCR if it should be rounded up, the * negative PCR if it should be rounded down, and zero if the maximum available * bandwidth should be used. * * The rules are as follows (* = maximum, - = absent (0), x = value "x", * (x+ = x or next value above x, x- = x or next value below): * * min max pcr result min max pcr result * - - - * (UBR only) x - - x+ * - - * * x - * * * - - z z- x - z z- * - * - * x * - x+ * - * * * x * * * * - * z z- x * z z- * - y - y- x y - x+ * - y * y- x y * y- * - y z z- x y z z- * * All non-error cases can be converted with the following simple set of rules: * * if pcr == z then z- * else if min == x && pcr == - then x+ * else if max == y then y- * else * */ |
c219750b2 [ATM]: atm_pcr_go... |
73 |
int atm_pcr_goal(const struct atm_trafprm *tp) |
1da177e4c Linux-2.6.12-rc2 |
74 |
{ |
c219750b2 [ATM]: atm_pcr_go... |
75 76 77 78 79 80 |
if (tp->pcr && tp->pcr != ATM_MAX_PCR) return -tp->pcr; if (tp->min_pcr && !tp->pcr) return tp->min_pcr; if (tp->max_pcr != ATM_MAX_PCR) return -tp->max_pcr; |
1da177e4c Linux-2.6.12-rc2 |
81 82 |
return 0; } |
3356b4d41 net/atm/atm_misc.... |
83 |
EXPORT_SYMBOL(atm_pcr_goal); |
1da177e4c Linux-2.6.12-rc2 |
84 |
|
3356b4d41 net/atm/atm_misc.... |
85 |
void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to) |
1da177e4c Linux-2.6.12-rc2 |
86 87 88 89 90 |
{ #define __HANDLE_ITEM(i) to->i = atomic_read(&from->i) __SONET_ITEMS #undef __HANDLE_ITEM } |
3356b4d41 net/atm/atm_misc.... |
91 |
EXPORT_SYMBOL(sonet_copy_stats); |
1da177e4c Linux-2.6.12-rc2 |
92 |
|
3356b4d41 net/atm/atm_misc.... |
93 |
void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to) |
1da177e4c Linux-2.6.12-rc2 |
94 |
{ |
3356b4d41 net/atm/atm_misc.... |
95 |
#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i) |
1da177e4c Linux-2.6.12-rc2 |
96 97 98 |
__SONET_ITEMS #undef __HANDLE_ITEM } |
1da177e4c Linux-2.6.12-rc2 |
99 |
EXPORT_SYMBOL(sonet_subtract_stats); |