Commit 74265588 authored by Duncan Sands's avatar Duncan Sands Committed by Greg Kroah-Hartman

[PATCH] USB speedtouch: receive code rewrite

Main points:
- receive buffers are decoupled from urbs, so an urb can be
resubmitted with a new buffer before the old buffer is processed.
- the packet reconstruction code is much simpler.
- locking is simplified by the fact that only the tasklet launches
receive urbs
parent d7a30724
...@@ -104,8 +104,9 @@ static const char udsl_driver_name [] = "speedtch"; ...@@ -104,8 +104,9 @@ static const char udsl_driver_name [] = "speedtch";
#define UDSL_NUM_RCV_URBS 1 #define UDSL_NUM_RCV_URBS 1
#define UDSL_NUM_SND_URBS 1 #define UDSL_NUM_SND_URBS 1
#define UDSL_NUM_RCV_BUFS (2*UDSL_NUM_RCV_URBS)
#define UDSL_NUM_SND_BUFS (2*UDSL_NUM_SND_URBS) #define UDSL_NUM_SND_BUFS (2*UDSL_NUM_SND_URBS)
#define UDSL_RCV_BUF_SIZE 64 /* ATM cells */ #define UDSL_RCV_BUF_SIZE 32 /* ATM cells */
#define UDSL_SND_BUF_SIZE 64 /* ATM cells */ #define UDSL_SND_BUF_SIZE 64 /* ATM cells */
#define UDSL_IOCTL_LINE_UP 1 #define UDSL_IOCTL_LINE_UP 1
...@@ -128,9 +129,15 @@ MODULE_DEVICE_TABLE (usb, udsl_usb_ids); ...@@ -128,9 +129,15 @@ MODULE_DEVICE_TABLE (usb, udsl_usb_ids);
/* receive */ /* receive */
struct udsl_receive_buffer {
struct list_head list;
unsigned char *base;
unsigned int filled_cells;
};
struct udsl_receiver { struct udsl_receiver {
struct list_head list; struct list_head list;
struct sk_buff *skb; struct udsl_receive_buffer *buffer;
struct urb *urb; struct urb *urb;
struct udsl_instance_data *instance; struct udsl_instance_data *instance;
}; };
...@@ -190,14 +197,14 @@ struct udsl_instance_data { ...@@ -190,14 +197,14 @@ struct udsl_instance_data {
/* receive */ /* receive */
struct udsl_receiver receivers [UDSL_NUM_RCV_URBS]; struct udsl_receiver receivers [UDSL_NUM_RCV_URBS];
struct udsl_receive_buffer receive_buffers [UDSL_NUM_RCV_BUFS];
spinlock_t spare_receivers_lock; spinlock_t receive_lock;
struct list_head spare_receivers; struct list_head spare_receivers;
struct list_head filled_receive_buffers;
spinlock_t completed_receivers_lock;
struct list_head completed_receivers;
struct tasklet_struct receive_tasklet; struct tasklet_struct receive_tasklet;
struct list_head spare_receive_buffers;
/* send */ /* send */
struct udsl_sender senders [UDSL_NUM_SND_URBS]; struct udsl_sender senders [UDSL_NUM_SND_URBS];
...@@ -262,133 +269,110 @@ static inline struct udsl_vcc_data *udsl_find_vcc (struct udsl_instance_data *in ...@@ -262,133 +269,110 @@ static inline struct udsl_vcc_data *udsl_find_vcc (struct udsl_instance_data *in
return NULL; return NULL;
} }
static struct sk_buff *udsl_decode_rawcell (struct udsl_instance_data *instance, struct sk_buff *skb, struct udsl_vcc_data **ctx) static void udsl_extract_cells (struct udsl_instance_data *instance, unsigned char *source, unsigned int howmany)
{ {
if (!instance || !skb || !ctx) struct udsl_vcc_data *cached_vcc = NULL;
return NULL; struct atm_vcc *vcc;
if (!skb->data || !skb->tail) struct sk_buff *skb;
return NULL; struct udsl_vcc_data *vcc_data;
int cached_vci = 0;
while (skb->len) { unsigned int i;
unsigned char *cell = skb->data; unsigned int length;
unsigned char *cell_payload; unsigned int pdu_length;
struct udsl_vcc_data *vcc; int pti;
short vpi;
int vci; int vci;
short cached_vpi = 0;
short vpi;
vpi = ((cell [0] & 0x0f) << 4) | (cell [1] >> 4); for (i = 0; i < howmany; i++, source += ATM_CELL_SIZE) {
vci = ((cell [1] & 0x0f) << 12) | (cell [2] << 4) | (cell [3] >> 4); vpi = ((source [0] & 0x0f) << 4) | (source [1] >> 4);
vci = ((source [1] & 0x0f) << 12) | (source [2] << 4) | (source [3] >> 4);
vdbg ("udsl_decode_rawcell (0x%p, 0x%p, 0x%p) called", instance, skb, ctx); pti = (source [3] & 0x2) != 0;
vdbg ("udsl_decode_rawcell skb->data %p, skb->tail %p", skb->data, skb->tail);
/* here should the header CRC check be... */ vdbg ("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti);
if (!(vcc = udsl_find_vcc (instance, vpi, vci))) { if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
dbg ("udsl_decode_rawcell: no vcc found for packet on vpi %d, vci %d", vpi, vci); vcc_data = cached_vcc;
__skb_pull (skb, min (skb->len, (unsigned) 53)); else if ((vcc_data = udsl_find_vcc (instance, vpi, vci))) {
cached_vcc = vcc_data;
cached_vpi = vpi;
cached_vci = vci;
} else { } else {
vdbg ("udsl_decode_rawcell found vcc %p for packet on vpi %d, vci %d", vcc, vpi, vci); dbg ("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, vci);
continue;
if (skb->len >= 53) { }
cell_payload = cell + 5;
if (!vcc->skb) vcc = vcc_data->vcc;
vcc->skb = dev_alloc_skb (vcc->max_pdu);
/* if alloc fails, we just drop the cell. it is possible that we can still if (!vcc_data->skb && !(vcc_data->skb = dev_alloc_skb (vcc_data->max_pdu))) {
* receive cells on other vcc's dbg ("udsl_extract_cells: no memory for skb (vcc: 0x%p)!", vcc);
*/ if (pti)
if (vcc->skb) { atomic_inc (&vcc->stats->rx_err);
/* if (buffer overrun) discard received cells until now */ continue;
if ((vcc->skb->len) > (vcc->max_pdu - 48))
skb_trim (vcc->skb, 0);
/* copy data */
memcpy (vcc->skb->tail, cell_payload, 48);
skb_put (vcc->skb, 48);
/* check for end of buffer */
if (cell [3] & 0x2) {
struct sk_buff *tmp;
/* the aal5 buffer ends here, cut the buffer. */
/* buffer will always have at least one whole cell, so */
/* don't need to check return from skb_pull */
skb_pull (skb, 53);
*ctx = vcc;
tmp = vcc->skb;
vcc->skb = NULL;
vdbg ("udsl_decode_rawcell returns ATM_AAL5 pdu 0x%p with length %d", tmp, tmp->len);
return tmp;
}
}
/* flush the cell */
/* buffer will always contain at least one whole cell, so don't */
/* need to check return value from skb_pull */
skb_pull (skb, 53);
} else {
/* If data is corrupt and skb doesn't hold a whole cell, flush the lot */
__skb_pull (skb, skb->len);
return NULL;
}
}
} }
return NULL; skb = vcc_data->skb;
}
static struct sk_buff *udsl_decode_aal5 (struct udsl_vcc_data *ctx, struct sk_buff *skb) if (skb->len + ATM_CELL_PAYLOAD > vcc_data->max_pdu) {
{ dbg ("udsl_extract_cells: buffer overrun (max_pdu: %u, skb->len %u, vcc: 0x%p)", vcc_data->max_pdu, skb->len, vcc);
uint crc = 0xffffffff; /* discard cells already received */
uint length, pdu_crc, pdu_length; skb_trim (skb, 0);
BUG_ON (vcc_data->max_pdu < ATM_CELL_PAYLOAD);
}
vdbg ("udsl_decode_aal5 (0x%p, 0x%p) called", ctx, skb); memcpy (skb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
__skb_put (skb, ATM_CELL_PAYLOAD);
if (skb->len && (skb->len % 48)) if (pti) {
return NULL; length = (source [ATM_CELL_SIZE - 6] << 8) + source [ATM_CELL_SIZE - 5];
length = (skb->tail [-6] << 8) + skb->tail [-5]; /* guard against overflow */
pdu_crc = if (length > ATM_MAX_AAL5_PDU) {
(skb->tail [-4] << 24) + (skb->tail [-3] << 16) + (skb->tail [-2] << 8) + skb->tail [-1]; dbg ("udsl_extract_cells: bogus length %u (vcc: 0x%p)", length, vcc);
pdu_length = ((length + 47 + 8) / 48) * 48; goto drop;
}
vdbg ("udsl_decode_aal5: skb->len = %d, length = %d, pdu_crc = 0x%x, pdu_length = %d", skb->len, length, pdu_crc, pdu_length); pdu_length = UDSL_NUM_CELLS (length) * ATM_CELL_PAYLOAD;
/* is skb long enough ? */
if (skb->len < pdu_length) { if (skb->len < pdu_length) {
atomic_inc (&ctx->vcc->stats->rx_err); dbg ("udsl_extract_cells: bogus pdu_length %u (skb->len: %u, vcc: 0x%p)", pdu_length, skb->len, vcc);
return NULL; goto drop;
} }
/* is skb too long ? */ if (crc32_be (~0, skb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
if (skb->len > pdu_length) { dbg ("udsl_extract_cells: packet failed crc check (vcc: 0x%p)", vcc);
dbg ("udsl_decode_aal5: Warning: readjusting illegal size %d -> %d", skb->len, pdu_length); goto drop;
/* buffer is too long. we can try to recover
* if we discard the first part of the skb.
* the crc will decide whether this was ok
*/
skb_pull (skb, skb->len - pdu_length);
} }
crc = ~crc32_be (crc, skb->data, pdu_length - 4); if (!atm_charge (vcc, skb->truesize)) {
dbg ("udsl_extract_cells: failed atm_charge (skb->truesize: %u)", skb->truesize);
/* check crc */ goto drop_no_stats; /* atm_charge increments rx_drop */
if (pdu_crc != crc) {
dbg ("udsl_decode_aal5: crc check failed!");
atomic_inc (&ctx->vcc->stats->rx_err);
return NULL;
} }
/* pdu is ok */ /* now that we are sure to send the skb, it is ok to change skb->data */
skb_trim (skb, length); if (skb->len > pdu_length)
skb_pull (skb, skb->len - pdu_length); /* discard initial junk */
skb_trim (skb, length); /* drop zero padding and trailer */
atomic_inc (&vcc->stats->rx);
PACKETDEBUG (skb->data, skb->len);
vdbg ("udsl_extract_cells: sending skb 0x%p, skb->len %u, skb->truesize %u", skb, skb->len, skb->truesize);
vcc->push (vcc, skb);
vcc_data->skb = NULL;
/* update stats */ continue;
atomic_inc (&ctx->vcc->stats->rx);
vdbg ("udsl_decode_aal5 returns pdu 0x%p with length %d", skb, skb->len); drop:
return skb; atomic_inc (&vcc->stats->rx_err);
drop_no_stats:
skb_trim (skb, 0);
}
}
} }
...@@ -500,145 +484,89 @@ static unsigned int udsl_write_cells (unsigned int howmany, struct sk_buff *skb, ...@@ -500,145 +484,89 @@ static unsigned int udsl_write_cells (unsigned int howmany, struct sk_buff *skb,
static void udsl_complete_receive (struct urb *urb, struct pt_regs *regs) static void udsl_complete_receive (struct urb *urb, struct pt_regs *regs)
{ {
struct udsl_receive_buffer *buf;
struct udsl_instance_data *instance; struct udsl_instance_data *instance;
struct udsl_receiver *rcv; struct udsl_receiver *rcv;
unsigned long flags; unsigned long flags;
if (!urb || !(rcv = urb->context) || !(instance = rcv->instance)) { if (!urb || !(rcv = urb->context)) {
dbg ("udsl_complete_receive: bad urb!"); dbg ("udsl_complete_receive: bad urb!");
return; return;
} }
vdbg ("udsl_complete_receive entered (urb 0x%p, status %d)", urb, urb->status); instance = rcv->instance;
buf = rcv->buffer;
buf->filled_cells = urb->actual_length / ATM_CELL_SIZE;
vdbg ("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, buf->filled_cells, rcv, buf);
BUG_ON (buf->filled_cells > UDSL_RCV_BUF_SIZE);
/* may not be in_interrupt() */ /* may not be in_interrupt() */
spin_lock_irqsave (&instance->completed_receivers_lock, flags); spin_lock_irqsave (&instance->receive_lock, flags);
list_add_tail (&rcv->list, &instance->completed_receivers); list_add (&rcv->list, &instance->spare_receivers);
list_add_tail (&buf->list, &instance->filled_receive_buffers);
if (likely (!urb->status))
tasklet_schedule (&instance->receive_tasklet); tasklet_schedule (&instance->receive_tasklet);
spin_unlock_irqrestore (&instance->completed_receivers_lock, flags); spin_unlock_irqrestore (&instance->receive_lock, flags);
} }
static void udsl_process_receive (unsigned long data) static void udsl_process_receive (unsigned long data)
{ {
struct udsl_receive_buffer *buf;
struct udsl_instance_data *instance = (struct udsl_instance_data *) data; struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
struct udsl_receiver *rcv; struct udsl_receiver *rcv;
unsigned char *data_start;
struct sk_buff *skb;
struct urb *urb;
struct udsl_vcc_data *atmsar_vcc = NULL;
struct sk_buff *new = NULL, *tmp = NULL;
int err; int err;
vdbg ("udsl_process_receive entered"); made_progress:
while (!list_empty (&instance->spare_receive_buffers)) {
spin_lock_irq (&instance->completed_receivers_lock); spin_lock_irq (&instance->receive_lock);
while (!list_empty (&instance->completed_receivers)) { if (list_empty (&instance->spare_receivers)) {
rcv = list_entry (instance->completed_receivers.next, struct udsl_receiver, list); spin_unlock_irq (&instance->receive_lock);
list_del (&rcv->list);
spin_unlock_irq (&instance->completed_receivers_lock);
urb = rcv->urb;
vdbg ("udsl_process_receive: got packet %p with length %d and status %d", urb, urb->actual_length, urb->status);
switch (urb->status) {
case 0:
vdbg ("udsl_process_receive: processing urb with rcv %p, urb %p, skb %p", rcv, urb, rcv->skb);
/* update the skb structure */
skb = rcv->skb;
skb_trim (skb, 0);
skb_put (skb, urb->actual_length);
data_start = skb->data;
vdbg ("skb->len = %d", skb->len);
PACKETDEBUG (skb->data, skb->len);
while ((new = udsl_decode_rawcell (instance, skb, &atmsar_vcc))) {
vdbg ("(after cell processing)skb->len = %d", new->len);
tmp = new;
new = udsl_decode_aal5 (atmsar_vcc, new);
/* we can't send NULL skbs upstream, the ATM layer would try to close the vcc... */
if (new) {
vdbg ("(after aal5 decap) skb->len = %d", new->len);
if (new->len && atm_charge (atmsar_vcc->vcc, new->truesize)) {
PACKETDEBUG (new->data, new->len);
atmsar_vcc->vcc->push (atmsar_vcc->vcc, new);
} else {
dbg
("dropping incoming packet : vcc->sk->rcvbuf = %d, skb->true_size = %d",
atmsar_vcc->vcc->sk->rcvbuf, new->truesize);
dev_kfree_skb (new);
}
} else {
dbg ("udsl_decode_aal5 returned NULL!");
dev_kfree_skb (tmp);
}
}
/* restore skb */
skb_push (skb, skb->data - data_start);
usb_fill_bulk_urb (urb,
instance->usb_dev,
usb_rcvbulkpipe (instance->usb_dev, UDSL_ENDPOINT_DATA_IN),
(unsigned char *) rcv->skb->data,
UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE,
udsl_complete_receive,
rcv);
if (!(err = usb_submit_urb (urb, GFP_ATOMIC)))
break;
dbg ("udsl_process_receive: submission failed (%d)", err);
/* fall through */
default: /* error or urb unlinked */
vdbg ("udsl_process_receive: adding to spare_receivers");
spin_lock_irq (&instance->spare_receivers_lock);
list_add (&rcv->list, &instance->spare_receivers);
spin_unlock_irq (&instance->spare_receivers_lock);
break; break;
} /* switch */ }
rcv = list_entry (instance->spare_receivers.next, struct udsl_receiver, list);
spin_lock_irq (&instance->completed_receivers_lock); list_del (&rcv->list);
} /* while */ spin_unlock_irq (&instance->receive_lock);
spin_unlock_irq (&instance->completed_receivers_lock);
vdbg ("udsl_process_receive successful");
}
static void udsl_fire_receivers (struct udsl_instance_data *instance)
{
struct list_head receivers, *pos, *n;
INIT_LIST_HEAD (&receivers);
down (&instance->serialize);
spin_lock_irq (&instance->spare_receivers_lock);
list_splice_init (&instance->spare_receivers, &receivers);
spin_unlock_irq (&instance->spare_receivers_lock);
list_for_each_safe (pos, n, &receivers) { buf = list_entry (instance->spare_receive_buffers.next, struct udsl_receive_buffer, list);
struct udsl_receiver *rcv = list_entry (pos, struct udsl_receiver, list); list_del (&buf->list);
dbg ("udsl_fire_receivers: firing urb %p", rcv->urb); rcv->buffer = buf;
usb_fill_bulk_urb (rcv->urb, usb_fill_bulk_urb (rcv->urb,
instance->usb_dev, instance->usb_dev,
usb_rcvbulkpipe (instance->usb_dev, UDSL_ENDPOINT_DATA_IN), usb_rcvbulkpipe (instance->usb_dev, UDSL_ENDPOINT_DATA_IN),
(unsigned char *) rcv->skb->data, buf->base,
UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE, UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE,
udsl_complete_receive, udsl_complete_receive,
rcv); rcv);
if (usb_submit_urb (rcv->urb, GFP_KERNEL) < 0) { vdbg ("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
dbg ("udsl_fire_receivers: submit failed!");
spin_lock_irq (&instance->spare_receivers_lock); if ((err = usb_submit_urb(rcv->urb, GFP_ATOMIC)) < 0) {
list_move (pos, &instance->spare_receivers); dbg ("udsl_process_receive: urb submission failed (%d)!", err);
spin_unlock_irq (&instance->spare_receivers_lock); list_add (&buf->list, &instance->spare_receive_buffers);
spin_lock_irq (&instance->receive_lock);
list_add (&rcv->list, &instance->spare_receivers);
spin_unlock_irq (&instance->receive_lock);
break;
} }
} }
up (&instance->serialize); spin_lock_irq (&instance->receive_lock);
if (list_empty (&instance->filled_receive_buffers)) {
spin_unlock_irq (&instance->receive_lock);
return; /* done - no more buffers */
}
buf = list_entry (instance->filled_receive_buffers.next, struct udsl_receive_buffer, list);
list_del (&buf->list);
spin_unlock_irq (&instance->receive_lock);
vdbg ("udsl_process_receive: processing buf 0x%p", buf);
udsl_extract_cells (instance, buf->base, buf->filled_cells);
list_add (&buf->list, &instance->spare_receive_buffers);
goto made_progress;
} }
...@@ -839,6 +767,7 @@ static void udsl_atm_dev_close (struct atm_dev *dev) ...@@ -839,6 +767,7 @@ static void udsl_atm_dev_close (struct atm_dev *dev)
dbg ("udsl_atm_dev_close: queue has %u elements", instance->sndqueue.qlen); dbg ("udsl_atm_dev_close: queue has %u elements", instance->sndqueue.qlen);
tasklet_kill (&instance->receive_tasklet);
tasklet_kill (&instance->send_tasklet); tasklet_kill (&instance->send_tasklet);
kfree (instance); kfree (instance);
dev->dev_data = NULL; dev->dev_data = NULL;
...@@ -913,7 +842,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) ...@@ -913,7 +842,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
return -EINVAL; return -EINVAL;
/* only support AAL5 */ /* only support AAL5 */
if (vcc->qos.aal != ATM_AAL5 || vcc->qos.rxtp.max_sdu < 0 || vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU) if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU))
return -EINVAL; return -EINVAL;
if (!instance->firmware_loaded) { if (!instance->firmware_loaded) {
...@@ -953,7 +882,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) ...@@ -953,7 +882,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
up (&instance->serialize); up (&instance->serialize);
udsl_fire_receivers (instance); tasklet_schedule (&instance->receive_tasklet);
dbg ("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, new->max_pdu); dbg ("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, new->max_pdu);
...@@ -1029,7 +958,9 @@ static int udsl_set_alternate (struct udsl_instance_data *instance) ...@@ -1029,7 +958,9 @@ static int udsl_set_alternate (struct udsl_instance_data *instance)
instance->firmware_loaded = 1; instance->firmware_loaded = 1;
} }
up (&instance->serialize); up (&instance->serialize);
udsl_fire_receivers (instance);
tasklet_schedule (&instance->receive_tasklet);
return 0; return 0;
} }
...@@ -1089,13 +1020,12 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i ...@@ -1089,13 +1020,12 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i
INIT_LIST_HEAD (&instance->vcc_list); INIT_LIST_HEAD (&instance->vcc_list);
spin_lock_init (&instance->spare_receivers_lock); spin_lock_init (&instance->receive_lock);
INIT_LIST_HEAD (&instance->spare_receivers); INIT_LIST_HEAD (&instance->spare_receivers);
INIT_LIST_HEAD (&instance->filled_receive_buffers);
spin_lock_init (&instance->completed_receivers_lock);
INIT_LIST_HEAD (&instance->completed_receivers);
tasklet_init (&instance->receive_tasklet, udsl_process_receive, (unsigned long) instance); tasklet_init (&instance->receive_tasklet, udsl_process_receive, (unsigned long) instance);
INIT_LIST_HEAD (&instance->spare_receive_buffers);
skb_queue_head_init (&instance->sndqueue); skb_queue_head_init (&instance->sndqueue);
...@@ -1110,11 +1040,6 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i ...@@ -1110,11 +1040,6 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i
for (i = 0; i < UDSL_NUM_RCV_URBS; i++) { for (i = 0; i < UDSL_NUM_RCV_URBS; i++) {
struct udsl_receiver *rcv = &(instance->receivers [i]); struct udsl_receiver *rcv = &(instance->receivers [i]);
if (!(rcv->skb = dev_alloc_skb (UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE))) {
dbg ("udsl_usb_probe: no memory for skb %d!", i);
goto fail;
}
if (!(rcv->urb = usb_alloc_urb (0, GFP_KERNEL))) { if (!(rcv->urb = usb_alloc_urb (0, GFP_KERNEL))) {
dbg ("udsl_usb_probe: no memory for receive urb %d!", i); dbg ("udsl_usb_probe: no memory for receive urb %d!", i);
goto fail; goto fail;
...@@ -1123,8 +1048,17 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i ...@@ -1123,8 +1048,17 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i
rcv->instance = instance; rcv->instance = instance;
list_add (&rcv->list, &instance->spare_receivers); list_add (&rcv->list, &instance->spare_receivers);
}
for (i = 0; i < UDSL_NUM_RCV_BUFS; i++) {
struct udsl_receive_buffer *buf = &(instance->receive_buffers [i]);
if (!(buf->base = kmalloc (UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE, GFP_KERNEL))) {
dbg ("udsl_usb_probe: no memory for receive buffer %d!", i);
goto fail;
}
dbg ("udsl_usb_probe: skb->truesize = %d (asked for %d)", rcv->skb->truesize, UDSL_RCV_BUF_SIZE * ATM_CELL_SIZE); list_add (&buf->list, &instance->spare_receive_buffers);
} }
/* send init */ /* send init */
...@@ -1209,14 +1143,11 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i ...@@ -1209,14 +1143,11 @@ static int udsl_usb_probe (struct usb_interface *intf, const struct usb_device_i
for (i = 0; i < UDSL_NUM_SND_URBS; i++) for (i = 0; i < UDSL_NUM_SND_URBS; i++)
usb_free_urb (instance->senders [i].urb); usb_free_urb (instance->senders [i].urb);
for (i = 0; i < UDSL_NUM_RCV_URBS; i++) { for (i = 0; i < UDSL_NUM_RCV_BUFS; i++)
struct udsl_receiver *rcv = &(instance->receivers [i]); kfree (instance->receive_buffers [i].base);
usb_free_urb (rcv->urb); for (i = 0; i < UDSL_NUM_RCV_URBS; i++)
usb_free_urb (instance->receivers [i].urb);
if (rcv->skb)
dev_kfree_skb (rcv->skb);
}
kfree (instance); kfree (instance);
...@@ -1227,7 +1158,7 @@ static void udsl_usb_disconnect (struct usb_interface *intf) ...@@ -1227,7 +1158,7 @@ static void udsl_usb_disconnect (struct usb_interface *intf)
{ {
struct udsl_instance_data *instance = usb_get_intfdata (intf); struct udsl_instance_data *instance = usb_get_intfdata (intf);
struct list_head *pos; struct list_head *pos;
unsigned int count = 0; unsigned int count;
int result, i; int result, i;
dbg ("udsl_usb_disconnect entered"); dbg ("udsl_usb_disconnect entered");
...@@ -1239,20 +1170,8 @@ static void udsl_usb_disconnect (struct usb_interface *intf) ...@@ -1239,20 +1170,8 @@ static void udsl_usb_disconnect (struct usb_interface *intf)
return; return;
} }
tasklet_disable (&instance->receive_tasklet);
/* receive finalize */ /* receive finalize */
down (&instance->serialize); /* vs udsl_fire_receivers */ tasklet_disable (&instance->receive_tasklet);
/* no need to take the spinlock */
list_for_each (pos, &instance->spare_receivers)
if (++count > UDSL_NUM_RCV_URBS)
panic (__FILE__ ": memory corruption detected at line %d!\n", __LINE__);
INIT_LIST_HEAD (&instance->spare_receivers);
up (&instance->serialize);
dbg ("udsl_usb_disconnect: flushed %u spare receivers", count);
count = UDSL_NUM_RCV_URBS - count;
for (i = 0; i < UDSL_NUM_RCV_URBS; i++) for (i = 0; i < UDSL_NUM_RCV_URBS; i++)
if ((result = usb_unlink_urb (instance->receivers [i].urb)) < 0) if ((result = usb_unlink_urb (instance->receivers [i].urb)) < 0)
...@@ -1260,17 +1179,16 @@ static void udsl_usb_disconnect (struct usb_interface *intf) ...@@ -1260,17 +1179,16 @@ static void udsl_usb_disconnect (struct usb_interface *intf)
/* wait for completion handlers to finish */ /* wait for completion handlers to finish */
do { do {
unsigned int completed = 0; count = 0;
spin_lock_irq (&instance->receive_lock);
spin_lock_irq (&instance->completed_receivers_lock); list_for_each (pos, &instance->spare_receivers)
list_for_each (pos, &instance->completed_receivers) if (++count > UDSL_NUM_RCV_URBS)
if (++completed > count)
panic (__FILE__ ": memory corruption detected at line %d!\n", __LINE__); panic (__FILE__ ": memory corruption detected at line %d!\n", __LINE__);
spin_unlock_irq (&instance->completed_receivers_lock); spin_unlock_irq (&instance->receive_lock);
dbg ("udsl_usb_disconnect: found %u completed receivers", completed); dbg ("udsl_usb_disconnect: found %u spare receivers", count);
if (completed == count) if (count == UDSL_NUM_RCV_URBS)
break; break;
set_current_state (TASK_RUNNING); set_current_state (TASK_RUNNING);
...@@ -1278,17 +1196,16 @@ static void udsl_usb_disconnect (struct usb_interface *intf) ...@@ -1278,17 +1196,16 @@ static void udsl_usb_disconnect (struct usb_interface *intf)
} while (1); } while (1);
/* no need to take the spinlock */ /* no need to take the spinlock */
INIT_LIST_HEAD (&instance->completed_receivers); INIT_LIST_HEAD (&instance->filled_receive_buffers);
INIT_LIST_HEAD (&instance->spare_receive_buffers);
tasklet_enable (&instance->receive_tasklet); tasklet_enable (&instance->receive_tasklet);
tasklet_kill (&instance->receive_tasklet);
for (i = 0; i < UDSL_NUM_RCV_URBS; i++) { for (i = 0; i < UDSL_NUM_RCV_URBS; i++)
struct udsl_receiver *rcv = &(instance->receivers [i]); usb_free_urb (instance->receivers [i].urb);
usb_free_urb (rcv->urb); for (i = 0; i < UDSL_NUM_RCV_BUFS; i++)
dev_kfree_skb (rcv->skb); kfree (instance->receive_buffers [i].base);
}
/* send finalize */ /* send finalize */
tasklet_disable (&instance->send_tasklet); tasklet_disable (&instance->send_tasklet);
...@@ -1332,7 +1249,7 @@ static void udsl_usb_disconnect (struct usb_interface *intf) ...@@ -1332,7 +1249,7 @@ static void udsl_usb_disconnect (struct usb_interface *intf)
instance->usb_dev = NULL; instance->usb_dev = NULL;
/* ATM finalize */ /* ATM finalize */
shutdown_atm_dev (instance->atm_dev); /* frees instance */ shutdown_atm_dev (instance->atm_dev); /* frees instance, kills tasklets */
} }
......
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