~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/atm/atm_misc.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* net/atm/atm_misc.c - Various functions for use by ATM drivers */
  3 
  4 /* Written 1995-2000 by Werner Almesberger, EPFL ICA */
  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 <linux/errno.h>
 13 #include <linux/atomic.h>
 14 
 15 int atm_charge(struct atm_vcc *vcc, int truesize)
 16 {
 17         atm_force_charge(vcc, truesize);
 18         if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
 19                 return 1;
 20         atm_return(vcc, truesize);
 21         atomic_inc(&vcc->stats->rx_drop);
 22         return 0;
 23 }
 24 EXPORT_SYMBOL(atm_charge);
 25 
 26 struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
 27                                  gfp_t gfp_flags)
 28 {
 29         struct sock *sk = sk_atm(vcc);
 30         int guess = SKB_TRUESIZE(pdu_size);
 31 
 32         atm_force_charge(vcc, guess);
 33         if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) {
 34                 struct sk_buff *skb = alloc_skb(pdu_size, gfp_flags);
 35 
 36                 if (skb) {
 37                         atomic_add(skb->truesize-guess,
 38                                    &sk->sk_rmem_alloc);
 39                         return skb;
 40                 }
 41         }
 42         atm_return(vcc, guess);
 43         atomic_inc(&vcc->stats->rx_drop);
 44         return NULL;
 45 }
 46 EXPORT_SYMBOL(atm_alloc_charge);
 47 
 48 
 49 /*
 50  * atm_pcr_goal returns the positive PCR if it should be rounded up, the
 51  * negative PCR if it should be rounded down, and zero if the maximum available
 52  * bandwidth should be used.
 53  *
 54  * The rules are as follows (* = maximum, - = absent (0), x = value "x",
 55  * (x+ = x or next value above x, x- = x or next value below):
 56  *
 57  *      min max pcr     result          min max pcr     result
 58  *      -   -   -       * (UBR only)    x   -   -       x+
 59  *      -   -   *       *               x   -   *       *
 60  *      -   -   z       z-              x   -   z       z-
 61  *      -   *   -       *               x   *   -       x+
 62  *      -   *   *       *               x   *   *       *
 63  *      -   *   z       z-              x   *   z       z-
 64  *      -   y   -       y-              x   y   -       x+
 65  *      -   y   *       y-              x   y   *       y-
 66  *      -   y   z       z-              x   y   z       z-
 67  *
 68  * All non-error cases can be converted with the following simple set of rules:
 69  *
 70  *   if pcr == z then z-
 71  *   else if min == x && pcr == - then x+
 72  *     else if max == y then y-
 73  *       else *
 74  */
 75 
 76 int atm_pcr_goal(const struct atm_trafprm *tp)
 77 {
 78         if (tp->pcr && tp->pcr != ATM_MAX_PCR)
 79                 return -tp->pcr;
 80         if (tp->min_pcr && !tp->pcr)
 81                 return tp->min_pcr;
 82         if (tp->max_pcr != ATM_MAX_PCR)
 83                 return -tp->max_pcr;
 84         return 0;
 85 }
 86 EXPORT_SYMBOL(atm_pcr_goal);
 87 
 88 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
 89 {
 90 #define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
 91         __SONET_ITEMS
 92 #undef __HANDLE_ITEM
 93 }
 94 EXPORT_SYMBOL(sonet_copy_stats);
 95 
 96 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
 97 {
 98 #define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
 99         __SONET_ITEMS
100 #undef __HANDLE_ITEM
101 }
102 EXPORT_SYMBOL(sonet_subtract_stats);
103 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php