/* net/atm/atm_misc.c - Various functions for use by ATM drivers */

/* Written 1995-2000 by Werner Almesberger, EPFL ICA */

#include <linux/module.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
#include <linux/skbuff.h>
#include <linux/sonet.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/atomic.h>

int atm_charge(struct atm_vcc *vcc, int truesize)
{
	atm_force_charge(vcc, truesize);
	if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
		return 1;
	atm_return(vcc, truesize);
	atomic_inc(&vcc->stats->rx_drop);
	return 0;
}
EXPORT_SYMBOL(atm_charge);

struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
				 gfp_t gfp_flags)
{
	struct sock *sk = sk_atm(vcc);
	int guess = SKB_TRUESIZE(pdu_size);

	atm_force_charge(vcc, guess);
	if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) {
		struct sk_buff *skb = alloc_skb(pdu_size, gfp_flags);

		if (skb) {
			atomic_add(skb->truesize-guess,
				   &sk->sk_rmem_alloc);
			return skb;
		}
	}
	atm_return(vcc, guess);
	atomic_inc(&vcc->stats->rx_drop);
	return NULL;
}
EXPORT_SYMBOL(atm_alloc_charge);


/*
 * 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 *
 */

int atm_pcr_goal(const struct atm_trafprm *tp)
{
	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;
	return 0;
}
EXPORT_SYMBOL(atm_pcr_goal);

void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
{
#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
	__SONET_ITEMS
#undef __HANDLE_ITEM
}
EXPORT_SYMBOL(sonet_copy_stats);

void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
{
#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
	__SONET_ITEMS
#undef __HANDLE_ITEM
}
EXPORT_SYMBOL(sonet_subtract_stats);
git/commit/?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>root</a>/<a href='/cgit.cgi/linux/net-next.git/commit/net?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>net</a>/<a href='/cgit.cgi/linux/net-next.git/commit/net/caif?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>caif</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='id' value='88f0e3a5e6ed674f485d3a09d53c2ead0000378d'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Charles Keepax &lt;ckeepax@opensource.wolfsonmicro.com&gt;</td><td class='right'>2016-10-21 14:47:42 +0100</td></tr>
<tr><th>committer</th><td>Mark Brown &lt;broonie@kernel.org&gt;</td><td class='right'>2016-10-24 17:43:05 +0100</td></tr>
<tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/net/caif?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>88f0e3a5e6ed674f485d3a09d53c2ead0000378d</a> (<a href='/cgit.cgi/linux/net-next.git/patch/net/caif?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>8214d62db45ab4ab9a54c475e0b91ea8d7ebdfa9</a> /<a href='/cgit.cgi/linux/net-next.git/tree/net/caif?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>net/caif</a></td></tr>
<tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/net/caif?id=1001354ca34179f3db924eb66672442a173147dc'>1001354ca34179f3db924eb66672442a173147dc</a> (<a href='/cgit.cgi/linux/net-next.git/diff/net/caif?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d&amp;id2=1001354ca34179f3db924eb66672442a173147dc'>diff</a>)</td></tr></table>
<div class='commit-subject'>regulator: arizona-ldo1: Set appropriate value for ramp_delay</div><div class='commit-msg'>Signed-off-by: Charles Keepax &lt;ckeepax@opensource.wolfsonmicro.com&gt;
Signed-off-by: Mark Brown &lt;broonie@kernel.org&gt;
</div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?id=88f0e3a5e6ed674f485d3a09d53c2ead0000378d'>Diffstat</a> (limited to 'net/caif')</div><table summary='diffstat' class='diffstat'>