Commit 3c81501f authored by Chas Williams's avatar Chas Williams Committed by David S. Miller

[ATM]: Keep vcc's on global list instead of per device.

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