OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [atm/] [atm_misc.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/* net/atm/atm_misc.c - Various functions for use by ATM drivers */
/* net/atm/atm_misc.c - Various functions for use by ATM drivers */
 
 
/* Written 1995-2000 by Werner Almesberger, EPFL ICA */
/* Written 1995-2000 by Werner Almesberger, EPFL ICA */
 
 
 
 
#include <linux/module.h>
#include <linux/module.h>
#include <linux/atm.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
#include <linux/atmdev.h>
#include <linux/skbuff.h>
#include <linux/skbuff.h>
#include <linux/sonet.h>
#include <linux/sonet.h>
#include <linux/bitops.h>
#include <linux/bitops.h>
#include <asm/atomic.h>
#include <asm/atomic.h>
#include <asm/errno.h>
#include <asm/errno.h>
 
 
 
 
int atm_charge(struct atm_vcc *vcc,int truesize)
int atm_charge(struct atm_vcc *vcc,int truesize)
{
{
        atm_force_charge(vcc,truesize);
        atm_force_charge(vcc,truesize);
        if (atomic_read(&vcc->sk->rmem_alloc) <= vcc->sk->rcvbuf) return 1;
        if (atomic_read(&vcc->sk->rmem_alloc) <= vcc->sk->rcvbuf) return 1;
        atm_return(vcc,truesize);
        atm_return(vcc,truesize);
        atomic_inc(&vcc->stats->rx_drop);
        atomic_inc(&vcc->stats->rx_drop);
        return 0;
        return 0;
}
}
 
 
 
 
struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
    int gfp_flags)
    int gfp_flags)
{
{
        int guess = atm_guess_pdu2truesize(pdu_size);
        int guess = atm_guess_pdu2truesize(pdu_size);
 
 
        atm_force_charge(vcc,guess);
        atm_force_charge(vcc,guess);
        if (atomic_read(&vcc->sk->rmem_alloc) <= vcc->sk->rcvbuf) {
        if (atomic_read(&vcc->sk->rmem_alloc) <= vcc->sk->rcvbuf) {
                struct sk_buff *skb = alloc_skb(pdu_size,gfp_flags);
                struct sk_buff *skb = alloc_skb(pdu_size,gfp_flags);
 
 
                if (skb) {
                if (skb) {
                        atomic_add(skb->truesize-guess,&vcc->sk->rmem_alloc);
                        atomic_add(skb->truesize-guess,&vcc->sk->rmem_alloc);
                        return skb;
                        return skb;
                }
                }
        }
        }
        atm_return(vcc,guess);
        atm_return(vcc,guess);
        atomic_inc(&vcc->stats->rx_drop);
        atomic_inc(&vcc->stats->rx_drop);
        return NULL;
        return NULL;
}
}
 
 
 
 
static int check_ci(struct atm_vcc *vcc,short vpi,int vci)
static int check_ci(struct atm_vcc *vcc,short vpi,int vci)
{
{
        struct sock *s;
        struct sock *s;
        struct atm_vcc *walk;
        struct atm_vcc *walk;
 
 
        for (s = vcc_sklist; s; s = s->next) {
        for (s = vcc_sklist; s; s = s->next) {
                walk = s->protinfo.af_atm;
                walk = s->protinfo.af_atm;
                if (walk->dev != vcc->dev)
                if (walk->dev != vcc->dev)
                        continue;
                        continue;
                if (test_bit(ATM_VF_ADDR,&walk->flags) && walk->vpi == vpi &&
                if (test_bit(ATM_VF_ADDR,&walk->flags) && walk->vpi == vpi &&
                    walk->vci == vci && ((walk->qos.txtp.traffic_class !=
                    walk->vci == vci && ((walk->qos.txtp.traffic_class !=
                    ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
                    ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
                    (walk->qos.rxtp.traffic_class != ATM_NONE &&
                    (walk->qos.rxtp.traffic_class != ATM_NONE &&
                    vcc->qos.rxtp.traffic_class != ATM_NONE)))
                    vcc->qos.rxtp.traffic_class != ATM_NONE)))
                        return -EADDRINUSE;
                        return -EADDRINUSE;
        }
        }
                /* allow VCCs with same VPI/VCI iff they don't collide on
                /* allow VCCs with same VPI/VCI iff they don't collide on
                   TX/RX (but we may refuse such sharing for other reasons,
                   TX/RX (but we may refuse such sharing for other reasons,
                   e.g. if protocol requires to have both channels) */
                   e.g. if protocol requires to have both channels) */
        return 0;
        return 0;
}
}
 
 
 
 
int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci)
int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci)
{
{
        static short p = 0; /* poor man's per-device cache */
        static short p = 0; /* poor man's per-device cache */
        static int c = 0;
        static int c = 0;
        short old_p;
        short old_p;
        int old_c;
        int old_c;
        int err;
        int err;
 
 
        read_lock(&vcc_sklist_lock);
        read_lock(&vcc_sklist_lock);
        if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
        if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
                err = check_ci(vcc,*vpi,*vci);
                err = check_ci(vcc,*vpi,*vci);
                read_unlock(&vcc_sklist_lock);
                read_unlock(&vcc_sklist_lock);
                return err;
                return err;
        }
        }
        /* last scan may have left values out of bounds for current device */
        /* last scan may have left values out of bounds for current device */
        if (*vpi != ATM_VPI_ANY) p = *vpi;
        if (*vpi != ATM_VPI_ANY) p = *vpi;
        else if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0;
        else if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0;
        if (*vci != ATM_VCI_ANY) c = *vci;
        if (*vci != ATM_VCI_ANY) c = *vci;
        else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
        else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
                        c = ATM_NOT_RSV_VCI;
                        c = ATM_NOT_RSV_VCI;
        old_p = p;
        old_p = p;
        old_c = c;
        old_c = c;
        do {
        do {
                if (!check_ci(vcc,p,c)) {
                if (!check_ci(vcc,p,c)) {
                        *vpi = p;
                        *vpi = p;
                        *vci = c;
                        *vci = c;
                        read_unlock(&vcc_sklist_lock);
                        read_unlock(&vcc_sklist_lock);
                        return 0;
                        return 0;
                }
                }
                if (*vci == ATM_VCI_ANY) {
                if (*vci == ATM_VCI_ANY) {
                        c++;
                        c++;
                        if (c >= 1 << vcc->dev->ci_range.vci_bits)
                        if (c >= 1 << vcc->dev->ci_range.vci_bits)
                                c = ATM_NOT_RSV_VCI;
                                c = ATM_NOT_RSV_VCI;
                }
                }
                if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
                if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
                    *vpi == ATM_VPI_ANY) {
                    *vpi == ATM_VPI_ANY) {
                        p++;
                        p++;
                        if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0;
                        if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0;
                }
                }
        }
        }
        while (old_p != p || old_c != c);
        while (old_p != p || old_c != c);
        read_unlock(&vcc_sklist_lock);
        read_unlock(&vcc_sklist_lock);
        return -EADDRINUSE;
        return -EADDRINUSE;
}
}
 
 
 
 
/*
/*
 * atm_pcr_goal returns the positive PCR if it should be rounded up, the
 * 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
 * negative PCR if it should be rounded down, and zero if the maximum available
 * bandwidth should be used.
 * bandwidth should be used.
 *
 *
 * The rules are as follows (* = maximum, - = absent (0), x = value "x",
 * The rules are as follows (* = maximum, - = absent (0), x = value "x",
 * (x+ = x or next value above x, x- = x or next value below):
 * (x+ = x or next value above x, x- = x or next value below):
 *
 *
 *      min max pcr     result          min max pcr     result
 *      min max pcr     result          min max pcr     result
 *      -   -   -       * (UBR only)    x   -   -       x+
 *      -   -   -       * (UBR only)    x   -   -       x+
 *      -   -   *       *               x   -   *       *
 *      -   -   *       *               x   -   *       *
 *      -   -   z       z-              x   -   z       z-
 *      -   -   z       z-              x   -   z       z-
 *      -   *   -       *               x   *   -       x+
 *      -   *   -       *               x   *   -       x+
 *      -   *   *       *               x   *   *       *
 *      -   *   *       *               x   *   *       *
 *      -   *   z       z-              x   *   z       z-
 *      -   *   z       z-              x   *   z       z-
 *      -   y   -       y-              x   y   -       x+
 *      -   y   -       y-              x   y   -       x+
 *      -   y   *       y-              x   y   *       y-
 *      -   y   *       y-              x   y   *       y-
 *      -   y   z       z-              x   y   z       z-
 *      -   y   z       z-              x   y   z       z-
 *
 *
 * All non-error cases can be converted with the following simple set of rules:
 * All non-error cases can be converted with the following simple set of rules:
 *
 *
 *   if pcr == z then z-
 *   if pcr == z then z-
 *   else if min == x && pcr == - then x+
 *   else if min == x && pcr == - then x+
 *     else if max == y then y-
 *     else if max == y then y-
 *       else *
 *       else *
 */
 */
 
 
 
 
int atm_pcr_goal(struct atm_trafprm *tp)
int atm_pcr_goal(struct atm_trafprm *tp)
{
{
        if (tp->pcr && tp->pcr != ATM_MAX_PCR) return -tp->pcr;
        if (tp->pcr && tp->pcr != ATM_MAX_PCR) return -tp->pcr;
        if (tp->min_pcr && !tp->pcr) return tp->min_pcr;
        if (tp->min_pcr && !tp->pcr) return tp->min_pcr;
        if (tp->max_pcr != ATM_MAX_PCR) return -tp->max_pcr;
        if (tp->max_pcr != ATM_MAX_PCR) return -tp->max_pcr;
        return 0;
        return 0;
}
}
 
 
 
 
void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
{
{
#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
        __SONET_ITEMS
        __SONET_ITEMS
#undef __HANDLE_ITEM
#undef __HANDLE_ITEM
}
}
 
 
 
 
void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
{
{
#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
        __SONET_ITEMS
        __SONET_ITEMS
#undef __HANDLE_ITEM
#undef __HANDLE_ITEM
}
}
 
 
 
 
EXPORT_SYMBOL(atm_charge);
EXPORT_SYMBOL(atm_charge);
EXPORT_SYMBOL(atm_alloc_charge);
EXPORT_SYMBOL(atm_alloc_charge);
EXPORT_SYMBOL(atm_find_ci);
EXPORT_SYMBOL(atm_find_ci);
EXPORT_SYMBOL(atm_pcr_goal);
EXPORT_SYMBOL(atm_pcr_goal);
EXPORT_SYMBOL(sonet_copy_stats);
EXPORT_SYMBOL(sonet_copy_stats);
EXPORT_SYMBOL(sonet_subtract_stats);
EXPORT_SYMBOL(sonet_subtract_stats);
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.