Commit c70df568 authored by David S. Miller's avatar David S. Miller

[ATM]: Revert vcc global list changes, broke the build.

parent b9bf3d83
......@@ -153,9 +153,9 @@ static void atmtcp_v_close(struct atm_vcc *vcc)
static int atmtcp_v_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg)
{
unsigned long flags;
struct atm_cirange ci;
struct atm_vcc *vcc;
struct sock *s;
if (cmd != ATM_SETCIRANGE) return -ENOIOCTLCMD;
if (copy_from_user(&ci,(void *) arg,sizeof(ci))) return -EFAULT;
......@@ -163,18 +163,14 @@ static int atmtcp_v_ioctl(struct atm_dev *dev,unsigned int cmd,void *arg)
if (ci.vci_bits == ATM_CI_MAX) ci.vci_bits = MAX_VCI_BITS;
if (ci.vpi_bits > MAX_VPI_BITS || ci.vpi_bits < 0 ||
ci.vci_bits > MAX_VCI_BITS || ci.vci_bits < 0) return -EINVAL;
read_lock(&vcc_sklist_lock);
for (s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->dev != dev)
continue;
spin_lock_irqsave(&dev->lock, flags);
for (vcc = dev->vccs; vcc; vcc = vcc->next)
if ((vcc->vpi >> ci.vpi_bits) ||
(vcc->vci >> ci.vci_bits)) {
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&dev->lock, flags);
return -EBUSY;
}
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&dev->lock, flags);
dev->ci_range = ci;
return 0;
}
......@@ -237,9 +233,9 @@ static int atmtcp_v_proc(struct atm_dev *dev,loff_t *pos,char *page)
static void atmtcp_c_close(struct atm_vcc *vcc)
{
unsigned long flags;
struct atm_dev *atmtcp_dev;
struct atmtcp_dev_data *dev_data;
struct sock *s;
struct atm_vcc *walk;
atmtcp_dev = (struct atm_dev *) vcc->dev_data;
......@@ -250,23 +246,19 @@ static void atmtcp_c_close(struct atm_vcc *vcc)
kfree(dev_data);
shutdown_atm_dev(atmtcp_dev);
vcc->dev_data = NULL;
read_lock(&vcc_sklist_lock);
for (s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != atmtcp_dev)
continue;
spin_lock_irqsave(&atmtcp_dev->lock, flags);
for (walk = atmtcp_dev->vccs; walk; walk = walk->next)
wake_up(&walk->sleep);
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&atmtcp_dev->lock, flags);
}
static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
{
unsigned long flags;
struct atm_dev *dev;
struct atmtcp_hdr *hdr;
struct sock *s;
struct atm_vcc *out_vcc = NULL;
struct atm_vcc *out_vcc;
struct sk_buff *new_skb;
int result = 0;
......@@ -278,17 +270,13 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
(struct atmtcp_control *) skb->data);
goto done;
}
read_lock(&vcc_sklist_lock);
for (s = vcc_sklist; s; s = s->sk_next) {
out_vcc = atm_sk(s);
if (out_vcc->dev != dev)
continue;
spin_lock_irqsave(&dev->lock, flags);
for (out_vcc = dev->vccs; out_vcc; out_vcc = out_vcc->next)
if (out_vcc->vpi == ntohs(hdr->vpi) &&
out_vcc->vci == ntohs(hdr->vci) &&
out_vcc->qos.rxtp.traffic_class != ATM_NONE)
break;
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&dev->lock, flags);
if (!out_vcc) {
atomic_inc(&vcc->stats->tx_err);
goto done;
......@@ -378,7 +366,7 @@ int atmtcp_attach(struct atm_vcc *vcc,int itf)
if (itf != -1) dev = atm_dev_lookup(itf);
if (dev) {
if (dev->ops != &atmtcp_v_dev_ops) {
atm_dev_put(dev);
atm_dev_release(dev);
return -EMEDIUMTYPE;
}
if (PRIV(dev)->vcc) return -EBUSY;
......@@ -390,8 +378,7 @@ int atmtcp_attach(struct atm_vcc *vcc,int itf)
if (error) return error;
}
PRIV(dev)->vcc = vcc;
vcc->dev = &atmtcp_control_dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc,&atmtcp_control_dev);
set_bit(ATM_VF_META,&vcc->flags);
set_bit(ATM_VF_READY,&vcc->flags);
vcc->dev_data = dev;
......@@ -415,7 +402,7 @@ int atmtcp_remove_persistent(int itf)
dev = atm_dev_lookup(itf);
if (!dev) return -ENODEV;
if (dev->ops != &atmtcp_v_dev_ops) {
atm_dev_put(dev);
atm_dev_release(dev);
return -EMEDIUMTYPE;
}
dev_data = PRIV(dev);
......@@ -423,7 +410,7 @@ int atmtcp_remove_persistent(int itf)
dev_data->persist = 0;
if (PRIV(dev)->vcc) return 0;
kfree(dev_data);
atm_dev_put(dev);
atm_dev_release(dev);
shutdown_atm_dev(dev);
return 0;
}
......
......@@ -1887,10 +1887,10 @@ static void eni_close(struct atm_vcc *vcc)
static int get_ci(struct atm_vcc *vcc,short *vpi,int *vci)
{
struct sock *s;
unsigned long flags;
struct atm_vcc *walk;
read_lock(&vcc_sklist_lock);
spin_lock_irqsave(&vcc->dev->lock, flags);
if (*vpi == ATM_VPI_ANY) *vpi = 0;
if (*vci == ATM_VCI_ANY) {
for (*vci = ATM_NOT_RSV_VCI; *vci < NR_VCI; (*vci)++) {
......@@ -1898,47 +1898,40 @@ static int get_ci(struct atm_vcc *vcc,short *vpi,int *vci)
ENI_DEV(vcc->dev)->rx_map[*vci])
continue;
if (vcc->qos.txtp.traffic_class != ATM_NONE) {
for (s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
for (walk = vcc->dev->vccs; walk;
walk = walk->next)
if (test_bit(ATM_VF_ADDR,&walk->flags)
&& walk->vci == *vci &&
walk->qos.txtp.traffic_class !=
ATM_NONE)
break;
}
if (s) continue;
if (walk) continue;
}
break;
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return *vci == NR_VCI ? -EADDRINUSE : 0;
}
if (*vci == ATM_VCI_UNSPEC) {
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
if (vcc->qos.rxtp.traffic_class != ATM_NONE &&
ENI_DEV(vcc->dev)->rx_map[*vci]) {
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return -EADDRINUSE;
}
if (vcc->qos.txtp.traffic_class == ATM_NONE) {
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
for (s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
for (walk = vcc->dev->vccs; walk; walk = walk->next)
if (test_bit(ATM_VF_ADDR,&walk->flags) && walk->vci == *vci &&
walk->qos.txtp.traffic_class != ATM_NONE) {
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return -EADDRINUSE;
}
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
......@@ -2146,7 +2139,7 @@ static unsigned char eni_phy_get(struct atm_dev *dev,unsigned long addr)
static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
{
struct sock *s;
unsigned long flags;
static const char *signal[] = { "LOST","unknown","okay" };
struct eni_dev *eni_dev = ENI_DEV(dev);
struct atm_vcc *vcc;
......@@ -2219,15 +2212,11 @@ static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
return sprintf(page,"%10sbacklog %u packets\n","",
skb_queue_len(&tx->backlog));
}
read_lock(&vcc_sklist_lock);
for (s = vcc_sklist; s; s = s->sk_next) {
struct eni_vcc *eni_vcc;
spin_lock_irqsave(&dev->lock, flags);
for (vcc = dev->vccs; vcc; vcc = vcc->next) {
struct eni_vcc *eni_vcc = ENI_VCC(vcc);
int length;
vcc = atm_sk(s);
if (vcc->dev != dev)
continue;
eni_vcc = ENI_VCC(vcc);
if (--left) continue;
length = sprintf(page,"vcc %4d: ",vcc->vci);
if (eni_vcc->rx) {
......@@ -2242,10 +2231,10 @@ static int eni_proc_read(struct atm_dev *dev,loff_t *pos,char *page)
length += sprintf(page+length,"tx[%d], txing %d bytes",
eni_vcc->tx->index,eni_vcc->txing);
page[length] = '\n';
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&dev->lock, flags);
return length+1;
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&dev->lock, flags);
for (i = 0; i < eni_dev->free_len; i++) {
struct eni_free *fe = eni_dev->free_list+i;
unsigned long offset;
......
......@@ -1069,22 +1069,18 @@ fore200e_supply(struct fore200e* fore200e)
static struct atm_vcc*
fore200e_find_vcc(struct fore200e* fore200e, struct rpd* rpd)
{
struct sock *s;
unsigned long flags;
struct atm_vcc* vcc;
read_lock(&vcc_sklist_lock);
for(s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->dev != fore200e->atm_dev)
continue;
if (vcc->vpi == rpd->atm_header.vpi && vcc->vci == rpd->atm_header.vci) {
read_unlock(&vcc_sklist_lock);
return vcc;
}
}
read_unlock(&vcc_sklist_lock);
spin_lock_irqsave(&fore200e->atm_dev->lock, flags);
for (vcc = fore200e->atm_dev->vccs; vcc; vcc = vcc->next) {
return NULL;
if (vcc->vpi == rpd->atm_header.vpi && vcc->vci == rpd->atm_header.vci)
break;
}
spin_unlock_irqrestore(&fore200e->atm_dev->lock, flags);
return vcc;
}
......@@ -1354,23 +1350,20 @@ fore200e_activate_vcin(struct fore200e* fore200e, int activate, struct atm_vcc*
static int
fore200e_walk_vccs(struct atm_vcc *vcc, short *vpi, int *vci)
{
unsigned long flags;
struct atm_vcc* walk;
struct sock *s;
/* find a free VPI */
read_lock(&vcc_sklist_lock);
spin_lock_irqsave(&vcc->dev->lock, flags);
if (*vpi == ATM_VPI_ANY) {
for (*vpi = 0, s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
for (*vpi = 0, walk = vcc->dev->vccs; walk; walk = walk->next) {
if ((walk->vci == *vci) && (walk->vpi == *vpi)) {
(*vpi)++;
s = vcc_sklist;
walk = vcc->dev->vccs;
}
}
}
......@@ -1378,19 +1371,16 @@ fore200e_walk_vccs(struct atm_vcc *vcc, short *vpi, int *vci)
/* find a free VCI */
if (*vci == ATM_VCI_ANY) {
for (*vci = ATM_NOT_RSV_VCI, s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
for (*vci = ATM_NOT_RSV_VCI, walk = vcc->dev->vccs; walk; walk = walk->next) {
if ((walk->vpi = *vpi) && (walk->vci == *vci)) {
*vci = walk->vci + 1;
s = vcc_sklist;
walk = vcc->dev->vccs;
}
}
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
......@@ -2652,7 +2642,7 @@ fore200e_module_cleanup(void)
static int
fore200e_proc_read(struct atm_dev *dev,loff_t* pos,char* page)
{
struct sock *s;
unsigned long flags;
struct fore200e* fore200e = FORE200E_DEV(dev);
int len, left = *pos;
......@@ -2899,12 +2889,8 @@ fore200e_proc_read(struct atm_dev *dev,loff_t* pos,char* page)
len = sprintf(page,"\n"
" VCCs:\n address\tVPI.VCI:AAL\t(min/max tx PDU size) (min/max rx PDU size)\n");
read_lock(&vcc_sklist_lock);
for (s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->dev != fore200e->atm_dev)
continue;
spin_lock_irqsave(&fore200e->atm_dev->lock, flags);
for (vcc = fore200e->atm_dev->vccs; vcc; vcc = vcc->next) {
fore200e_vcc = FORE200E_VCC(vcc);
......@@ -2918,7 +2904,7 @@ fore200e_proc_read(struct atm_dev *dev,loff_t* pos,char* page)
fore200e_vcc->rx_max_pdu
);
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&fore200e->atm_dev->lock, flags);
return len;
}
......
......@@ -79,6 +79,7 @@
#include <linux/sonet.h>
#define USE_TASKLET
#define USE_HE_FIND_VCC
#undef USE_SCATTERGATHER
#undef USE_CHECKSUM_HW /* still confused about this */
#define USE_RBPS
......@@ -327,24 +328,25 @@ he_readl_internal(struct he_dev *he_dev, unsigned addr, unsigned flags)
he_writel_rcm(dev, val, 0x00000 | (cid << 3) | 7)
static __inline__ struct atm_vcc*
__find_vcc(struct he_dev *he_dev, unsigned cid)
he_find_vcc(struct he_dev *he_dev, unsigned cid)
{
unsigned long flags;
struct atm_vcc *vcc;
struct sock *s;
short vpi;
int vci;
vpi = cid >> he_dev->vcibits;
vci = cid & ((1 << he_dev->vcibits) - 1);
for (s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->dev == he_dev->atm_dev &&
vcc->vci == vci && vcc->vpi == vpi &&
vcc->qos.rxtp.traffic_class != ATM_NONE) {
spin_lock_irqsave(&he_dev->atm_dev->lock, flags);
for (vcc = he_dev->atm_dev->vccs; vcc; vcc = vcc->next)
if (vcc->vci == vci && vcc->vpi == vpi
&& vcc->qos.rxtp.traffic_class != ATM_NONE) {
spin_unlock_irqrestore(&he_dev->atm_dev->lock, flags);
return vcc;
}
}
}
spin_unlock_irqrestore(&he_dev->atm_dev->lock, flags);
return NULL;
}
......@@ -1564,6 +1566,17 @@ he_start(struct atm_dev *dev)
reg |= RX_ENABLE;
he_writel(he_dev, reg, RC_CONFIG);
#ifndef USE_HE_FIND_VCC
he_dev->he_vcc_table = kmalloc(sizeof(struct he_vcc_table) *
(1 << (he_dev->vcibits + he_dev->vpibits)), GFP_KERNEL);
if (he_dev->he_vcc_table == NULL) {
hprintk("failed to alloc he_vcc_table\n");
return -ENOMEM;
}
memset(he_dev->he_vcc_table, 0, sizeof(struct he_vcc_table) *
(1 << (he_dev->vcibits + he_dev->vpibits)));
#endif
for (i = 0; i < HE_NUM_CS_STPER; ++i) {
he_dev->cs_stper[i].inuse = 0;
he_dev->cs_stper[i].pcr = -1;
......@@ -1699,6 +1712,11 @@ he_stop(struct he_dev *he_dev)
he_dev->tpd_base, he_dev->tpd_base_phys);
#endif
#ifndef USE_HE_FIND_VCC
if (he_dev->he_vcc_table)
kfree(he_dev->he_vcc_table);
#endif
if (he_dev->pci_dev) {
pci_read_config_word(he_dev->pci_dev, PCI_COMMAND, &command);
command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
......@@ -1780,7 +1798,6 @@ he_service_rbrq(struct he_dev *he_dev, int group)
int pdus_assembled = 0;
int updated = 0;
read_lock(&vcc_sklist_lock);
while (he_dev->rbrq_head != rbrq_tail) {
++updated;
......@@ -1806,10 +1823,13 @@ he_service_rbrq(struct he_dev *he_dev, int group)
buf_len = RBRQ_BUFLEN(he_dev->rbrq_head) * 4;
cid = RBRQ_CID(he_dev->rbrq_head);
#ifdef USE_HE_FIND_VCC
if (cid != lastcid)
vcc = __find_vcc(he_dev, cid);
vcc = he_find_vcc(he_dev, cid);
lastcid = cid;
#else
vcc = HE_LOOKUP_VCC(he_dev, cid);
#endif
if (vcc == NULL) {
hprintk("vcc == NULL (cid 0x%x)\n", cid);
if (!RBRQ_HBUF_ERR(he_dev->rbrq_head))
......@@ -1946,7 +1966,6 @@ he_service_rbrq(struct he_dev *he_dev, int group)
RBRQ_MASK(++he_dev->rbrq_head));
}
read_unlock(&vcc_sklist_lock);
if (updated) {
if (updated > he_dev->rbrq_peak)
......@@ -2546,6 +2565,10 @@ he_open(struct atm_vcc *vcc, short vpi, int vci)
#endif
spin_unlock_irqrestore(&he_dev->global_lock, flags);
#ifndef USE_HE_FIND_VCC
HE_LOOKUP_VCC(he_dev, cid) = vcc;
#endif
}
open_failed:
......@@ -2611,6 +2634,9 @@ he_close(struct atm_vcc *vcc)
if (timeout == 0)
hprintk("close rx timeout cid 0x%x\n", cid);
#ifndef USE_HE_FIND_VCC
HE_LOOKUP_VCC(he_dev, cid) = NULL;
#endif
HPRINTK("close rx cid 0x%x complete\n", cid);
}
......
......@@ -2403,43 +2403,37 @@ idt77252_init_rx(struct idt77252_dev *card, struct vc_map *vc,
static int
idt77252_find_vcc(struct atm_vcc *vcc, short *vpi, int *vci)
{
struct sock *s;
unsigned long flags;
struct atm_vcc *walk;
read_lock(&vcc_sklist_lock);
spin_lock_irqsave(&vcc->dev->lock, flags);
if (*vpi == ATM_VPI_ANY) {
*vpi = 0;
s = vcc_sklist;
while (s) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
walk = vcc->dev->vccs;
while (walk) {
if ((walk->vci == *vci) && (walk->vpi == *vpi)) {
(*vpi)++;
s = vcc_sklist;
walk = vcc->dev->vccs;
continue;
}
s = s->sk_next;
walk = walk->next;
}
}
if (*vci == ATM_VCI_ANY) {
*vci = ATM_NOT_RSV_VCI;
s = vcc_sklist;
while (s) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
walk = vcc->dev->vccs;
while (walk) {
if ((walk->vci == *vci) && (walk->vpi == *vpi)) {
(*vci)++;
s = vcc_sklist;
walk = vcc->dev->vccs;
continue;
}
s = s->sk_next;
walk = walk->next;
}
}
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
......
......@@ -293,6 +293,7 @@ struct atm_vcc {
struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
wait_queue_head_t sleep; /* if socket is busy */
struct sock *sk; /* socket backpointer */
struct atm_vcc *prev,*next;
/* SVC part --- may move later ------------------------------------- */
short itf; /* interface number */
struct sockaddr_atmsvc local;
......@@ -319,6 +320,8 @@ struct atm_dev {
/* (NULL) */
const char *type; /* device type name */
int number; /* device index */
struct atm_vcc *vccs; /* VCC table (or NULL) */
struct atm_vcc *last; /* last VCC (or undefined) */
void *dev_data; /* per-device data */
void *phy_data; /* private PHY date */
unsigned long flags; /* device flags (ATM_DF_*) */
......@@ -387,9 +390,6 @@ struct atm_skb_data {
unsigned long atm_options; /* ATM layer options */
};
extern struct sock *vcc_sklist;
extern rwlock_t vcc_sklist_lock;
#define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
......@@ -397,8 +397,7 @@ struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
struct atm_dev *atm_dev_lookup(int number);
void atm_dev_deregister(struct atm_dev *dev);
void shutdown_atm_dev(struct atm_dev *dev);
void vcc_insert_socket(struct sock *sk);
void vcc_remove_socket(struct sock *sk);
void bind_vcc(struct atm_vcc *vcc,struct atm_dev *dev);
/*
......@@ -437,7 +436,7 @@ static inline void atm_dev_hold(struct atm_dev *dev)
}
static inline void atm_dev_put(struct atm_dev *dev)
static inline void atm_dev_release(struct atm_dev *dev)
{
atomic_dec(&dev->refcnt);
......
......@@ -47,20 +47,15 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
static int check_ci(struct atm_vcc *vcc,short vpi,int vci)
{
struct sock *s;
struct atm_vcc *walk;
for (s = vcc_sklist; s; s = s->sk_next) {
walk = atm_sk(s);
if (walk->dev != vcc->dev)
continue;
for (walk = vcc->dev->vccs; walk; walk = walk->next)
if (test_bit(ATM_VF_ADDR,&walk->flags) && walk->vpi == vpi &&
walk->vci == vci && ((walk->qos.txtp.traffic_class !=
ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
(walk->qos.rxtp.traffic_class != ATM_NONE &&
vcc->qos.rxtp.traffic_class != ATM_NONE)))
return -EADDRINUSE;
}
/* allow VCCs with same VPI/VCI iff they don't collide on
TX/RX (but we may refuse such sharing for other reasons,
e.g. if protocol requires to have both channels) */
......@@ -70,16 +65,17 @@ static int check_ci(struct atm_vcc *vcc,short vpi,int vci)
int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci)
{
unsigned long flags;
static short p = 0; /* poor man's per-device cache */
static int c = 0;
short old_p;
int old_c;
int err;
read_lock(&vcc_sklist_lock);
spin_lock_irqsave(&vcc->dev->lock, flags);
if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
err = check_ci(vcc,*vpi,*vci);
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return err;
}
/* last scan may have left values out of bounds for current device */
......@@ -94,7 +90,7 @@ int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci)
if (!check_ci(vcc,p,c)) {
*vpi = p;
*vci = c;
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return 0;
}
if (*vci == ATM_VCI_ANY) {
......@@ -109,7 +105,7 @@ int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci)
}
}
while (old_p != p || old_c != c);
read_unlock(&vcc_sklist_lock);
spin_unlock_irqrestore(&vcc->dev->lock, flags);
return -EADDRINUSE;
}
......
......@@ -737,8 +737,7 @@ static int atm_init_atmarp(struct atm_vcc *vcc)
set_bit(ATM_VF_META,&vcc->flags);
set_bit(ATM_VF_READY,&vcc->flags);
/* allow replies and avoid getting closed if signaling dies */
vcc->dev = &atmarpd_dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc,&atmarpd_dev);
vcc->push = NULL;
vcc->pop = NULL; /* crash */
vcc->push_oam = NULL; /* crash */
......
......@@ -157,38 +157,6 @@ EXPORT_SYMBOL(br2684_ioctl_hook);
#endif
struct sock *vcc_sklist;
rwlock_t vcc_sklist_lock = RW_LOCK_UNLOCKED;
void __vcc_insert_socket(struct sock *sk)
{
sk->sk_next = vcc_sklist;
if (sk->sk_next)
vcc_sklist->sk_pprev = &sk->sk_next;
vcc_sklist = sk;
sk->sk_pprev = &vcc_sklist;
}
void vcc_insert_socket(struct sock *sk)
{
write_lock_irq(&vcc_sklist_lock);
__vcc_insert_socket(sk);
write_unlock_irq(&vcc_sklist_lock);
}
void vcc_remove_socket(struct sock *sk)
{
write_lock_irq(&vcc_sklist_lock);
if (sk->sk_pprev) {
if (sk->sk_next)
sk->sk_next->sk_pprev = sk->sk_pprev;
*sk->sk_pprev = sk->sk_next;
sk->sk_pprev = NULL;
}
write_unlock_irq(&vcc_sklist_lock);
}
static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
{
struct sk_buff *skb;
......@@ -207,45 +175,16 @@ static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
}
EXPORT_SYMBOL(vcc_sklist);
EXPORT_SYMBOL(vcc_sklist_lock);
EXPORT_SYMBOL(vcc_insert_socket);
EXPORT_SYMBOL(vcc_remove_socket);
static void vcc_sock_destruct(struct sock *sk)
{
struct atm_vcc *vcc = atm_sk(sk);
if (atomic_read(&vcc->sk->sk_rmem_alloc))
printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_rmem_alloc));
if (atomic_read(&vcc->sk->sk_wmem_alloc))
printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_wmem_alloc));
kfree(sk->sk_protinfo);
}
int vcc_create(struct socket *sock, int protocol, int family)
int atm_create(struct socket *sock,int protocol,int family)
{
struct sock *sk;
struct atm_vcc *vcc;
sock->sk = NULL;
if (sock->type == SOCK_STREAM)
return -EINVAL;
sk = sk_alloc(family, GFP_KERNEL, 1, NULL);
if (!sk)
return -ENOMEM;
sock_init_data(NULL, sk);
vcc = atm_sk(sk) = kmalloc(sizeof(*vcc), GFP_KERNEL);
if (!vcc) {
sk_free(sk);
return -ENOMEM;
}
memset(vcc, 0, sizeof(*vcc));
vcc->sk = sk;
if (sock->type == SOCK_STREAM) return -EINVAL;
if (!(sk = alloc_atm_vcc_sk(family))) return -ENOMEM;
vcc = atm_sk(sk);
memset(&vcc->flags,0,sizeof(vcc->flags));
vcc->dev = NULL;
vcc->callback = NULL;
memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc));
......@@ -260,49 +199,42 @@ int vcc_create(struct socket *sock, int protocol, int family)
vcc->atm_options = vcc->aal_options = 0;
init_waitqueue_head(&vcc->sleep);
sk->sk_sleep = &vcc->sleep;
sk->sk_destruct = vcc_sock_destruct;
sock->sk = sk;
return 0;
}
static void vcc_destroy_socket(struct sock *sk)
void atm_release_vcc_sk(struct sock *sk,int free_sk)
{
struct atm_vcc *vcc = atm_sk(sk);
struct sk_buff *skb;
clear_bit(ATM_VF_READY, &vcc->flags);
clear_bit(ATM_VF_READY,&vcc->flags);
if (vcc->dev) {
if (vcc->dev->ops->close)
vcc->dev->ops->close(vcc);
if (vcc->push)
vcc->push(vcc, NULL); /* atmarpd has no push */
vcc_remove_socket(sk); /* no more receive */
if (vcc->dev->ops->close) vcc->dev->ops->close(vcc);
if (vcc->push) vcc->push(vcc,NULL); /* atmarpd has no push */
while ((skb = skb_dequeue(&vcc->sk->sk_receive_queue))) {
atm_return(vcc,skb->truesize);
kfree_skb(skb);
}
module_put(vcc->dev->ops->owner);
atm_dev_put(vcc->dev);
atm_dev_release(vcc->dev);
if (atomic_read(&vcc->sk->sk_rmem_alloc))
printk(KERN_WARNING "atm_release_vcc: strange ... "
"rmem_alloc == %d after closing\n",
atomic_read(&vcc->sk->sk_rmem_alloc));
bind_vcc(vcc,NULL);
}
if (free_sk) free_atm_vcc_sk(sk);
}
int vcc_release(struct socket *sock)
int atm_release(struct socket *sock)
{
struct sock *sk = sock->sk;
if (sk) {
sock_orphan(sk);
lock_sock(sk);
vcc_destroy_socket(sock->sk);
release_sock(sk);
sock_put(sk);
}
if (sock->sk)
atm_release_vcc_sk(sock->sk,1);
return 0;
}
......@@ -357,8 +289,7 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
return -EPERM;
error = 0;
vcc->dev = dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc,dev);
switch (vcc->qos.aal) {
case ATM_AAL0:
error = atm_init_aal0(vcc);
......@@ -382,7 +313,7 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal);
if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal);
if (error) {
vcc_remove_socket(vcc->sk);
bind_vcc(vcc,NULL);
return error;
}
DPRINTK("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal);
......@@ -396,7 +327,7 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
error = dev->ops->open(vcc,vpi,vci);
if (error) {
module_put(dev->ops->owner);
vcc_remove_socket(vcc->sk);
bind_vcc(vcc,NULL);
return error;
}
}
......@@ -440,7 +371,7 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
dev = atm_dev_lookup(itf);
error = __vcc_connect(vcc, dev, vpi, vci);
if (error) {
atm_dev_put(dev);
atm_dev_release(dev);
return error;
}
} else {
......@@ -454,7 +385,7 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
spin_unlock(&atm_dev_lock);
if (!__vcc_connect(vcc, dev, vpi, vci))
break;
atm_dev_put(dev);
atm_dev_release(dev);
dev = NULL;
spin_lock(&atm_dev_lock);
}
......
......@@ -10,8 +10,8 @@
#include <linux/poll.h> /* for poll_table */
int vcc_create(struct socket *sock, int protocol, int family);
int vcc_release(struct socket *sock);
int atm_create(struct socket *sock,int protocol,int family);
int atm_release(struct socket *sock);
int vcc_connect(struct socket *sock, int itf, short vpi, int vci);
int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
int size, int flags);
......@@ -24,6 +24,7 @@ int vcc_setsockopt(struct socket *sock, int level, int optname, char *optval,
int vcc_getsockopt(struct socket *sock, int level, int optname, char *optval,
int *optlen);
void atm_release_vcc_sk(struct sock *sk,int free_sk);
void atm_shutdown_dev(struct atm_dev *dev);
int atmpvc_init(void);
......
......@@ -48,7 +48,7 @@ extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
#include "lec.h"
#include "lec_arpc.h"
#include "resources.h"
#include "resources.h" /* for bind_vcc() */
#if 0
#define DPRINTK printk
......@@ -810,8 +810,7 @@ lecd_attach(struct atm_vcc *vcc, int arg)
lec_arp_init(priv);
priv->itfnum = i; /* LANE2 addition */
priv->lecd = vcc;
vcc->dev = &lecatm_dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc, &lecatm_dev);
vcc->proto_data = dev_lec[i];
set_bit(ATM_VF_META,&vcc->flags);
......
......@@ -28,7 +28,7 @@
#include "lec.h"
#include "mpc.h"
#include "resources.h"
#include "resources.h" /* for bind_vcc() */
/*
* mpc.c: Implementation of MPOA client kernel part
......@@ -789,8 +789,7 @@ int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
}
mpc->mpoad_vcc = vcc;
vcc->dev = &mpc_dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc, &mpc_dev);
set_bit(ATM_VF_META,&vcc->flags);
set_bit(ATM_VF_READY,&vcc->flags);
......
......@@ -334,7 +334,9 @@ static int atm_devices_info(loff_t pos,char *buf)
static int atm_pvc_info(loff_t pos,char *buf)
{
struct sock *s;
unsigned long flags;
struct atm_dev *dev;
struct list_head *p;
struct atm_vcc *vcc;
int left, clip_info = 0;
......@@ -347,20 +349,25 @@ static int atm_pvc_info(loff_t pos,char *buf)
if (try_atm_clip_ops())
clip_info = 1;
#endif
read_lock(&vcc_sklist_lock);
for(s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->sk->sk_family == PF_ATMPVC && vcc->dev && !left--) {
pvc_info(vcc,buf,clip_info);
read_unlock(&vcc_sklist_lock);
spin_lock(&atm_dev_lock);
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
spin_lock_irqsave(&dev->lock, flags);
for (vcc = dev->vccs; vcc; vcc = vcc->next)
if (vcc->sk->sk_family == PF_ATMPVC &&
vcc->dev && !left--) {
pvc_info(vcc,buf,clip_info);
spin_unlock_irqrestore(&dev->lock, flags);
spin_unlock(&atm_dev_lock);
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
if (clip_info)
module_put(atm_clip_ops->owner);
if (clip_info)
module_put(atm_clip_ops->owner);
#endif
return strlen(buf);
}
return strlen(buf);
}
spin_unlock_irqrestore(&dev->lock, flags);
}
read_unlock(&vcc_sklist_lock);
spin_unlock(&atm_dev_lock);
#if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
if (clip_info)
module_put(atm_clip_ops->owner);
......@@ -371,8 +378,10 @@ static int atm_pvc_info(loff_t pos,char *buf)
static int atm_vc_info(loff_t pos,char *buf)
{
unsigned long flags;
struct atm_dev *dev;
struct list_head *p;
struct atm_vcc *vcc;
struct sock *s;
int left;
if (!pos)
......@@ -380,16 +389,20 @@ static int atm_vc_info(loff_t pos,char *buf)
"Address"," Itf VPI VCI Fam Flags Reply Send buffer"
" Recv buffer\n");
left = pos-1;
read_lock(&vcc_sklist_lock);
for(s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (!left--) {
vc_info(vcc,buf);
read_unlock(&vcc_sklist_lock);
return strlen(buf);
}
spin_lock(&atm_dev_lock);
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
spin_lock_irqsave(&dev->lock, flags);
for (vcc = dev->vccs; vcc; vcc = vcc->next)
if (!left--) {
vc_info(vcc,buf);
spin_unlock_irqrestore(&dev->lock, flags);
spin_unlock(&atm_dev_lock);
return strlen(buf);
}
spin_unlock_irqrestore(&dev->lock, flags);
}
read_unlock(&vcc_sklist_lock);
spin_unlock(&atm_dev_lock);
return 0;
}
......@@ -397,23 +410,29 @@ static int atm_vc_info(loff_t pos,char *buf)
static int atm_svc_info(loff_t pos,char *buf)
{
struct sock *s;
unsigned long flags;
struct atm_dev *dev;
struct list_head *p;
struct atm_vcc *vcc;
int left;
if (!pos)
return sprintf(buf,"Itf VPI VCI State Remote\n");
left = pos-1;
read_lock(&vcc_sklist_lock);
for(s = vcc_sklist; s; s = s->sk_next) {
vcc = atm_sk(s);
if (vcc->sk->sk_family == PF_ATMSVC && !left--) {
svc_info(vcc,buf);
read_unlock(&vcc_sklist_lock);
return strlen(buf);
}
spin_lock(&atm_dev_lock);
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
spin_lock_irqsave(&dev->lock, flags);
for (vcc = dev->vccs; vcc; vcc = vcc->next)
if (vcc->sk->sk_family == PF_ATMSVC && !left--) {
svc_info(vcc,buf);
spin_unlock_irqrestore(&dev->lock, flags);
spin_unlock(&atm_dev_lock);
return strlen(buf);
}
spin_unlock_irqrestore(&dev->lock, flags);
}
read_unlock(&vcc_sklist_lock);
spin_unlock(&atm_dev_lock);
return 0;
}
......
......@@ -17,6 +17,10 @@
#include "resources.h" /* devs and vccs */
#include "common.h" /* common for PVCs and SVCs */
#ifndef NULL
#define NULL 0
#endif
static int pvc_shutdown(struct socket *sock,int how)
{
......@@ -105,7 +109,7 @@ static int pvc_getname(struct socket *sock,struct sockaddr *sockaddr,
static struct proto_ops pvc_proto_ops = {
.family = PF_ATMPVC,
.release = vcc_release,
.release = atm_release,
.bind = pvc_bind,
.connect = pvc_connect,
.socketpair = sock_no_socketpair,
......@@ -127,7 +131,7 @@ static struct proto_ops pvc_proto_ops = {
static int pvc_create(struct socket *sock,int protocol)
{
sock->ops = &pvc_proto_ops;
return vcc_create(sock, protocol, PF_ATMPVC);
return atm_create(sock,protocol,PF_ATMPVC);
}
......
......@@ -23,6 +23,11 @@
#include "addr.h"
#ifndef NULL
#define NULL 0
#endif
LIST_HEAD(atm_devs);
spinlock_t atm_dev_lock = SPIN_LOCK_UNLOCKED;
......@@ -86,7 +91,7 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
spin_lock(&atm_dev_lock);
if (number != -1) {
if ((inuse = __atm_dev_lookup(number))) {
atm_dev_put(inuse);
atm_dev_release(inuse);
spin_unlock(&atm_dev_lock);
__free_atm_dev(dev);
return NULL;
......@@ -95,7 +100,7 @@ struct atm_dev *atm_dev_register(const char *type, const struct atmdev_ops *ops,
} else {
dev->number = 0;
while ((inuse = __atm_dev_lookup(dev->number))) {
atm_dev_put(inuse);
atm_dev_release(inuse);
dev->number++;
}
}
......@@ -397,12 +402,78 @@ int atm_dev_ioctl(unsigned int cmd, unsigned long arg)
else
error = 0;
done:
atm_dev_put(dev);
atm_dev_release(dev);
return error;
}
struct sock *alloc_atm_vcc_sk(int family)
{
struct sock *sk;
struct atm_vcc *vcc;
sk = sk_alloc(family, GFP_KERNEL, 1, NULL);
if (!sk)
return NULL;
vcc = atm_sk(sk) = kmalloc(sizeof(*vcc), GFP_KERNEL);
if (!vcc) {
sk_free(sk);
return NULL;
}
sock_init_data(NULL, sk);
memset(vcc, 0, sizeof(*vcc));
vcc->sk = sk;
return sk;
}
static void unlink_vcc(struct atm_vcc *vcc)
{
unsigned long flags;
if (vcc->dev) {
spin_lock_irqsave(&vcc->dev->lock, flags);
if (vcc->prev)
vcc->prev->next = vcc->next;
else
vcc->dev->vccs = vcc->next;
if (vcc->next)
vcc->next->prev = vcc->prev;
else
vcc->dev->last = vcc->prev;
spin_unlock_irqrestore(&vcc->dev->lock, flags);
}
}
void free_atm_vcc_sk(struct sock *sk)
{
unlink_vcc(atm_sk(sk));
sk_free(sk);
}
void bind_vcc(struct atm_vcc *vcc,struct atm_dev *dev)
{
unsigned long flags;
unlink_vcc(vcc);
vcc->dev = dev;
if (dev) {
spin_lock_irqsave(&dev->lock, flags);
vcc->next = NULL;
vcc->prev = dev->last;
if (dev->vccs)
dev->last->next = vcc;
else
dev->vccs = vcc;
dev->last = vcc;
spin_unlock_irqrestore(&dev->lock, flags);
}
}
EXPORT_SYMBOL(atm_dev_register);
EXPORT_SYMBOL(atm_dev_deregister);
EXPORT_SYMBOL(atm_dev_lookup);
EXPORT_SYMBOL(shutdown_atm_dev);
EXPORT_SYMBOL(bind_vcc);
......@@ -14,6 +14,8 @@ extern struct list_head atm_devs;
extern spinlock_t atm_dev_lock;
struct sock *alloc_atm_vcc_sk(int family);
void free_atm_vcc_sk(struct sock *sk);
int atm_dev_ioctl(unsigned int cmd, unsigned long arg);
......
......@@ -200,21 +200,26 @@ void sigd_enq(struct atm_vcc *vcc,enum atmsvc_msg_type type,
}
static void purge_vcc(struct atm_vcc *vcc)
static void purge_vccs(struct atm_vcc *vcc)
{
if (vcc->sk->sk_family == PF_ATMSVC &&
!test_bit(ATM_VF_META,&vcc->flags)) {
set_bit(ATM_VF_RELEASED,&vcc->flags);
vcc->reply = -EUNATCH;
vcc->sk->sk_err = EUNATCH;
wake_up(&vcc->sleep);
while (vcc) {
if (vcc->sk->sk_family == PF_ATMSVC &&
!test_bit(ATM_VF_META,&vcc->flags)) {
set_bit(ATM_VF_RELEASED,&vcc->flags);
vcc->reply = -EUNATCH;
vcc->sk->sk_err = EUNATCH;
wake_up(&vcc->sleep);
}
vcc = vcc->next;
}
}
static void sigd_close(struct atm_vcc *vcc)
{
struct sock *s;
unsigned long flags;
struct atm_dev *dev;
struct list_head *p;
DPRINTK("sigd_close\n");
sigd = NULL;
......@@ -222,14 +227,14 @@ static void sigd_close(struct atm_vcc *vcc)
printk(KERN_ERR "sigd_close: closing with requests pending\n");
skb_queue_purge(&vcc->sk->sk_receive_queue);
read_lock(&vcc_sklist_lock);
for(s = vcc_sklist; s; s = s->sk_next) {
struct atm_vcc *vcc = atm_sk(s);
if (vcc->dev)
purge_vcc(vcc);
spin_lock(&atm_dev_lock);
list_for_each(p, &atm_devs) {
dev = list_entry(p, struct atm_dev, dev_list);
spin_lock_irqsave(&dev->lock, flags);
purge_vccs(dev->vccs);
spin_unlock_irqrestore(&dev->lock, flags);
}
read_unlock(&vcc_sklist_lock);
spin_unlock(&atm_dev_lock);
}
......@@ -252,8 +257,7 @@ int sigd_attach(struct atm_vcc *vcc)
if (sigd) return -EADDRINUSE;
DPRINTK("sigd_attach\n");
sigd = vcc;
vcc->dev = &sigd_dev;
vcc_insert_socket(vcc->sk);
bind_vcc(vcc,&sigd_dev);
set_bit(ATM_VF_META,&vcc->flags);
set_bit(ATM_VF_READY,&vcc->flags);
wake_up(&sigd_sleep);
......
......@@ -88,21 +88,18 @@ static void svc_disconnect(struct atm_vcc *vcc)
static int svc_release(struct socket *sock)
{
struct sock *sk = sock->sk;
struct atm_vcc *vcc;
if (sk) {
vcc = ATM_SD(sock);
DPRINTK("svc_release %p\n", vcc);
clear_bit(ATM_VF_READY, &vcc->flags);
/* VCC pointer is used as a reference, so we must not free it
(thereby subjecting it to re-use) before all pending connections
are closed */
sock_hold(sk);
vcc_release(sock);
svc_disconnect(vcc);
sock_put(sk);
}
if (!sock->sk) return 0;
vcc = ATM_SD(sock);
DPRINTK("svc_release %p\n",vcc);
clear_bit(ATM_VF_READY,&vcc->flags);
atm_release_vcc_sk(sock->sk,0);
svc_disconnect(vcc);
/* VCC pointer is used as a reference, so we must not free it
(thereby subjecting it to re-use) before all pending connections
are closed */
free_atm_vcc_sk(sock->sk);
return 0;
}
......@@ -545,7 +542,7 @@ static int svc_create(struct socket *sock,int protocol)
int error;
sock->ops = &svc_proto_ops;
error = vcc_create(sock, protocol, AF_ATMSVC);
error = atm_create(sock,protocol,AF_ATMSVC);
if (error) return error;
ATM_SD(sock)->callback = svc_callback;
ATM_SD(sock)->local.sas_family = AF_ATMSVC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment