1 /* net/atm/atm_misc.c - Various functions for use by ATM drivers */
3 /* Written 1995-2000 by Werner Almesberger, EPFL ICA */
5 #include <linux/module.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>
14 int atm_charge(struct atm_vcc
*vcc
, int truesize
)
16 atm_force_charge(vcc
, truesize
);
17 if (atomic_read(&sk_atm(vcc
)->sk_rmem_alloc
) <= sk_atm(vcc
)->sk_rcvbuf
)
19 atm_return(vcc
, truesize
);
20 atomic_inc(&vcc
->stats
->rx_drop
);
23 EXPORT_SYMBOL(atm_charge
);
25 struct sk_buff
*atm_alloc_charge(struct atm_vcc
*vcc
, int pdu_size
,
28 struct sock
*sk
= sk_atm(vcc
);
29 int guess
= SKB_TRUESIZE(pdu_size
);
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
);
36 atomic_add(skb
->truesize
-guess
,
41 atm_return(vcc
, guess
);
42 atomic_inc(&vcc
->stats
->rx_drop
);
45 EXPORT_SYMBOL(atm_alloc_charge
);
49 * atm_pcr_goal returns the positive PCR if it should be rounded up, the
50 * negative PCR if it should be rounded down, and zero if the maximum available
51 * bandwidth should be used.
53 * The rules are as follows (* = maximum, - = absent (0), x = value "x",
54 * (x+ = x or next value above x, x- = x or next value below):
56 * min max pcr result min max pcr result
57 * - - - * (UBR only) x - - x+
67 * All non-error cases can be converted with the following simple set of rules:
70 * else if min == x && pcr == - then x+
71 * else if max == y then y-
75 int atm_pcr_goal(const struct atm_trafprm
*tp
)
77 if (tp
->pcr
&& tp
->pcr
!= ATM_MAX_PCR
)
79 if (tp
->min_pcr
&& !tp
->pcr
)
81 if (tp
->max_pcr
!= ATM_MAX_PCR
)
85 EXPORT_SYMBOL(atm_pcr_goal
);
87 void sonet_copy_stats(struct k_sonet_stats
*from
, struct sonet_stats
*to
)
89 #define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
93 EXPORT_SYMBOL(sonet_copy_stats
);
95 void sonet_subtract_stats(struct k_sonet_stats
*from
, struct sonet_stats
*to
)
97 #define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101 EXPORT_SYMBOL(sonet_subtract_stats
);