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

[PATCH] USB speedtouch: code reorganization

Remove dead code from sarlib, reorganize live sarlib code (trivial transformations).
parent ec2b09d1
...@@ -151,21 +151,13 @@ struct udsl_control { ...@@ -151,21 +151,13 @@ struct udsl_control {
struct atmsar_vcc_data { struct atmsar_vcc_data {
struct atmsar_vcc_data *next; struct atmsar_vcc_data *next;
/* general atmsar flags, per connection */
int flags;
int type;
/* connection specific non-atmsar data */ /* connection specific non-atmsar data */
struct atm_vcc *vcc; struct atm_vcc *vcc;
struct k_atm_aal_stats *stats;
unsigned short mtu; /* max is actually 65k for AAL5... */ unsigned short mtu; /* max is actually 65k for AAL5... */
/* cell data */ /* cell data */
unsigned int vp; unsigned int vp;
unsigned int vc; unsigned int vc;
unsigned char gfc;
unsigned char pti;
unsigned int headerFlags;
unsigned long atmHeader; unsigned long atmHeader;
/* raw cell reassembly */ /* raw cell reassembly */
...@@ -259,7 +251,6 @@ static struct usb_driver udsl_usb_driver = { ...@@ -259,7 +251,6 @@ static struct usb_driver udsl_usb_driver = {
*************/ *************/
#define ATM_HDR_VPVC_MASK (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK) #define ATM_HDR_VPVC_MASK (ATM_HDR_VPI_MASK | ATM_HDR_VCI_MASK)
#define ATMSAR_USE_53BYTE_CELL 0x1L
struct sk_buff *atmsar_decode_rawcell (struct atmsar_vcc_data *list, struct sk_buff *skb, struct sk_buff *atmsar_decode_rawcell (struct atmsar_vcc_data *list, struct sk_buff *skb,
struct atmsar_vcc_data **ctx) struct atmsar_vcc_data **ctx)
...@@ -292,85 +283,49 @@ struct sk_buff *atmsar_decode_rawcell (struct atmsar_vcc_data *list, struct sk_b ...@@ -292,85 +283,49 @@ struct sk_buff *atmsar_decode_rawcell (struct atmsar_vcc_data *list, struct sk_b
(int) ((atmHeader & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT), (int) ((atmHeader & ATM_HDR_VPI_MASK) >> ATM_HDR_VPI_SHIFT),
(int) ((atmHeader & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT)); (int) ((atmHeader & ATM_HDR_VCI_MASK) >> ATM_HDR_VCI_SHIFT));
if (vcc && (skb->len >= (vcc->flags & ATMSAR_USE_53BYTE_CELL ? 53 : 52))) { if (vcc && (skb->len >= 53)) {
cell_payload = cell + (vcc->flags & ATMSAR_USE_53BYTE_CELL ? 5 : 4); cell_payload = cell + 5;
switch (vcc->type) { if (!vcc->reasBuffer)
case ATM_AAL0: vcc->reasBuffer = dev_alloc_skb (vcc->mtu);
/* case ATM_AAL1: when we have a decode AAL1 function... */
{ /* if alloc fails, we just drop the cell. it is possible that we can still
struct sk_buff *tmp = dev_alloc_skb (vcc->mtu); * receive cells on other vcc's
*/
if (tmp) { if (vcc->reasBuffer) {
memcpy (tmp->tail, cell_payload, 48); /* if (buffer overrun) discard received cells until now */
skb_put (tmp, 48); if ((vcc->reasBuffer->len) > (vcc->mtu - 48))
skb_trim (vcc->reasBuffer, 0);
if (vcc->stats)
atomic_inc (&vcc->stats->rx); /* copy data */
memcpy (vcc->reasBuffer->tail, cell_payload, 48);
skb_pull (skb, skb_put (vcc->reasBuffer, 48);
(vcc->
flags & ATMSAR_USE_53BYTE_CELL ? 53 : /* check for end of buffer */
52)); if (cell[3] & 0x2) {
dbg struct sk_buff *tmp;
("atmsar_decode_rawcell returns ATM_AAL0 pdu 0x%p with length %d",
tmp, tmp->len); /* the aal5 buffer ends here, cut the buffer. */
return tmp; /* 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->reasBuffer;
vcc->reasBuffer = NULL;
dbg
("atmsar_decode_rawcell returns ATM_AAL5 pdu 0x%p with length %d",
tmp, tmp->len);
return tmp;
} }
break; }
case ATM_AAL1:
case ATM_AAL2:
case ATM_AAL34:
/* not supported */
break;
case ATM_AAL5:
if (!vcc->reasBuffer)
vcc->reasBuffer = dev_alloc_skb (vcc->mtu);
/* if alloc fails, we just drop the cell. it is possible that we can still
* receive cells on other vcc's
*/
if (vcc->reasBuffer) {
/* if (buffer overrun) discard received cells until now */
if ((vcc->reasBuffer->len) > (vcc->mtu - 48))
skb_trim (vcc->reasBuffer, 0);
/* copy data */
memcpy (vcc->reasBuffer->tail, cell_payload, 48);
skb_put (vcc->reasBuffer, 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,
(vcc->
flags & ATMSAR_USE_53BYTE_CELL ? 53 :
52));
*ctx = vcc;
tmp = vcc->reasBuffer;
vcc->reasBuffer = NULL;
dbg
("atmsar_decode_rawcell returns ATM_AAL5 pdu 0x%p with length %d",
tmp, tmp->len);
return tmp;
}
}
break;
};
/* flush the cell */ /* flush the cell */
/* buffer will always contain at least one whole cell, so don't */ /* buffer will always contain at least one whole cell, so don't */
/* need to check return value from skb_pull */ /* need to check return value from skb_pull */
skb_pull (skb, (vcc->flags & ATMSAR_USE_53BYTE_CELL ? 53 : 52)); skb_pull (skb, 53);
} else { } else {
/* If data is corrupt and skb doesn't hold a whole cell, flush the lot */ /* If data is corrupt and skb doesn't hold a whole cell, flush the lot */
if (skb_pull (skb, (list->flags & ATMSAR_USE_53BYTE_CELL ? 53 : 52)) == if (skb_pull (skb, 53) == NULL)
NULL)
return NULL; return NULL;
} }
} }
...@@ -398,8 +353,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff ...@@ -398,8 +353,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff
/* is skb long enough ? */ /* is skb long enough ? */
if (skb->len < pdu_length) { if (skb->len < pdu_length) {
if (ctx->stats) if (ctx->vcc->stats)
atomic_inc (&ctx->stats->rx_err); atomic_inc (&ctx->vcc->stats->rx_err);
return NULL; return NULL;
} }
...@@ -419,8 +374,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff ...@@ -419,8 +374,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff
/* check crc */ /* check crc */
if (pdu_crc != crc) { if (pdu_crc != crc) {
dbg ("atmsar_decode_aal5: crc check failed!"); dbg ("atmsar_decode_aal5: crc check failed!");
if (ctx->stats) if (ctx->vcc->stats)
atomic_inc (&ctx->stats->rx_err); atomic_inc (&ctx->vcc->stats->rx_err);
return NULL; return NULL;
} }
...@@ -428,8 +383,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff ...@@ -428,8 +383,8 @@ struct sk_buff *atmsar_decode_aal5 (struct atmsar_vcc_data *ctx, struct sk_buff
skb_trim (skb, length); skb_trim (skb, length);
/* update stats */ /* update stats */
if (ctx->stats) if (ctx->vcc->stats)
atomic_inc (&ctx->stats->rx); atomic_inc (&ctx->vcc->stats->rx);
dbg ("atmsar_decode_aal5 returns pdu 0x%p with length %d", skb, skb->len); dbg ("atmsar_decode_aal5 returns pdu 0x%p with length %d", skb, skb->len);
return skb; return skb;
...@@ -602,35 +557,25 @@ static void udsl_process_receive (unsigned long data) ...@@ -602,35 +557,25 @@ static void udsl_process_receive (unsigned long data)
&atmsar_vcc)) != NULL) { &atmsar_vcc)) != NULL) {
dbg ("(after cell processing)skb->len = %d", new->len); dbg ("(after cell processing)skb->len = %d", new->len);
switch (atmsar_vcc->type) { tmp = new;
case ATM_AAL5: new = atmsar_decode_aal5 (atmsar_vcc, new);
tmp = new;
new = atmsar_decode_aal5 (atmsar_vcc, new); /* we can't send NULL skbs upstream, the ATM layer would try to close the vcc... */
if (new) {
/* we can't send NULL skbs upstream, the ATM layer would try to close the vcc... */ dbg ("(after aal5 decap) skb->len = %d", new->len);
if (new) { if (new->len && atm_charge (atmsar_vcc->vcc, new->truesize)) {
dbg ("(after aal5 decap) skb->len = %d", new->len); PACKETDEBUG (new->data, new->len);
if (new->len && atm_charge (atmsar_vcc->vcc, new->truesize)) { atmsar_vcc->vcc->push (atmsar_vcc->vcc, new);
PACKETDEBUG (new->data, new->len);
atmsar_vcc->vcc->push (atmsar_vcc->vcc, new);
} else {
dbg
("dropping incoming packet : rx_inuse = %d, vcc->sk->rcvbuf = %d, skb->true_size = %d",
atomic_read (&atmsar_vcc->vcc->rx_inuse),
atmsar_vcc->vcc->sk->rcvbuf, new->truesize);
dev_kfree_skb (new);
}
} else { } else {
dbg ("atmsar_decode_aal5 returned NULL!"); dbg
dev_kfree_skb (tmp); ("dropping incoming packet : rx_inuse = %d, vcc->sk->rcvbuf = %d, skb->true_size = %d",
atomic_read (&atmsar_vcc->vcc->rx_inuse),
atmsar_vcc->vcc->sk->rcvbuf, new->truesize);
dev_kfree_skb (new);
} }
break; } else {
default: dbg ("atmsar_decode_aal5 returned NULL!");
/* not supported. we delete the skb. */ dev_kfree_skb (tmp);
printk (KERN_INFO
"SpeedTouch USB: illegal vcc type. Dropping packet.\n");
dev_kfree_skb (new);
break;
} }
} }
...@@ -901,95 +846,6 @@ static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb) ...@@ -901,95 +846,6 @@ static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb)
** ATM ** ** ATM **
**********/ **********/
#define ATMSAR_DEF_MTU_AAL0 48
#define ATMSAR_DEF_MTU_AAL1 47
#define ATMSAR_DEF_MTU_AAL2 0 /* not supported */
#define ATMSAR_DEF_MTU_AAL34 0 /* not supported */
#define ATMSAR_DEF_MTU_AAL5 65535 /* max mtu .. */
struct atmsar_vcc_data *atmsar_open (struct atmsar_vcc_data **list, struct atm_vcc *vcc, uint type,
ushort vpi, ushort vci, unchar pti, unchar gfc, uint flags)
{
struct atmsar_vcc_data *new;
if (!vcc)
return NULL;
new = kmalloc (sizeof (struct atmsar_vcc_data), GFP_KERNEL);
if (!new)
return NULL;
memset (new, 0, sizeof (struct atmsar_vcc_data));
new->vcc = vcc;
new->stats = vcc->stats;
new->type = type;
new->next = NULL;
new->gfc = gfc;
new->vp = vpi;
new->vc = vci;
new->pti = pti;
switch (type) {
case ATM_AAL0:
new->mtu = ATMSAR_DEF_MTU_AAL0;
break;
case ATM_AAL1:
new->mtu = ATMSAR_DEF_MTU_AAL1;
break;
case ATM_AAL2:
new->mtu = ATMSAR_DEF_MTU_AAL2;
break;
case ATM_AAL34:
/* not supported */
new->mtu = ATMSAR_DEF_MTU_AAL34;
break;
case ATM_AAL5:
new->mtu = ATMSAR_DEF_MTU_AAL5;
break;
}
new->atmHeader = ((unsigned long) gfc << ATM_HDR_GFC_SHIFT)
| ((unsigned long) vpi << ATM_HDR_VPI_SHIFT)
| ((unsigned long) vci << ATM_HDR_VCI_SHIFT)
| ((unsigned long) pti << ATM_HDR_PTI_SHIFT);
new->flags = flags;
new->next = NULL;
new->reasBuffer = NULL;
new->next = *list;
*list = new;
dbg ("Allocated new SARLib vcc 0x%p with vp %d vc %d", new, vpi, vci);
return new;
}
void atmsar_close (struct atmsar_vcc_data **list, struct atmsar_vcc_data *vcc)
{
struct atmsar_vcc_data *work;
if (*list == vcc) {
*list = (*list)->next;
} else {
for (work = *list; work && work->next && (work->next != vcc); work = work->next);
/* return if not found */
if (work->next != vcc)
return;
work->next = work->next->next;
}
if (vcc->reasBuffer) {
dev_kfree_skb (vcc->reasBuffer);
}
dbg ("Allocated SARLib vcc 0x%p with vp %d vc %d", vcc, vcc->vp, vcc->vc);
kfree (vcc);
}
static void udsl_atm_dev_close (struct atm_dev *dev) static void udsl_atm_dev_close (struct atm_dev *dev)
{ {
struct udsl_instance_data *instance = dev->dev_data; struct udsl_instance_data *instance = dev->dev_data;
...@@ -1066,6 +922,7 @@ static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page) ...@@ -1066,6 +922,7 @@ static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page)
static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
{ {
struct udsl_instance_data *instance = vcc->dev->dev_data; struct udsl_instance_data *instance = vcc->dev->dev_data;
struct atmsar_vcc_data *new;
dbg ("udsl_atm_open called"); dbg ("udsl_atm_open called");
...@@ -1078,15 +935,28 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) ...@@ -1078,15 +935,28 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
if (vcc->qos.aal != ATM_AAL5) if (vcc->qos.aal != ATM_AAL5)
return -EINVAL; return -EINVAL;
if (!(new = kmalloc (sizeof (struct atmsar_vcc_data), GFP_KERNEL)))
return -ENOMEM;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
vcc->dev_data = memset (new, 0, sizeof (struct atmsar_vcc_data));
atmsar_open (&(instance->atmsar_vcc_list), vcc, ATM_AAL5, vpi, vci, 0, 0, new->vcc = vcc;
ATMSAR_USE_53BYTE_CELL | ATMSAR_SET_PTI); new->vp = vpi;
if (!vcc->dev_data) { new->vc = vci;
MOD_DEC_USE_COUNT;
return -ENOMEM; /* this is the only reason atmsar_open can fail... */ new->mtu = UDSL_MAX_AAL5_MRU;
}
new->atmHeader = ((unsigned long) vpi << ATM_HDR_VPI_SHIFT) |
((unsigned long) vci << ATM_HDR_VCI_SHIFT);
new->reasBuffer = NULL;
new->next = instance->atmsar_vcc_list;
instance->atmsar_vcc_list = new;
dbg ("Allocated new SARLib vcc 0x%p with vp %d vc %d", new, vpi, vci);
vcc->dev_data = new;
vcc->vpi = vpi; vcc->vpi = vpi;
vcc->vci = vci; vcc->vci = vci;
...@@ -1094,8 +964,6 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) ...@@ -1094,8 +964,6 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
set_bit (ATM_VF_PARTIAL, &vcc->flags); set_bit (ATM_VF_PARTIAL, &vcc->flags);
set_bit (ATM_VF_READY, &vcc->flags); set_bit (ATM_VF_READY, &vcc->flags);
((struct atmsar_vcc_data *)vcc->dev_data)->mtu = UDSL_MAX_AAL5_MRU;
if (instance->firmware_loaded) if (instance->firmware_loaded)
udsl_fire_receivers (instance); udsl_fire_receivers (instance);
...@@ -1106,6 +974,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci) ...@@ -1106,6 +974,7 @@ static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
static void udsl_atm_close (struct atm_vcc *vcc) static void udsl_atm_close (struct atm_vcc *vcc)
{ {
struct udsl_instance_data *instance = vcc->dev->dev_data; struct udsl_instance_data *instance = vcc->dev->dev_data;
struct atmsar_vcc_data *work;
dbg ("udsl_atm_close called"); dbg ("udsl_atm_close called");
...@@ -1118,7 +987,26 @@ static void udsl_atm_close (struct atm_vcc *vcc) ...@@ -1118,7 +987,26 @@ static void udsl_atm_close (struct atm_vcc *vcc)
/* cancel all sends on this vcc */ /* cancel all sends on this vcc */
udsl_cancel_send (instance, vcc); udsl_cancel_send (instance, vcc);
atmsar_close (&(instance->atmsar_vcc_list), vcc->dev_data); if (instance->atmsar_vcc_list == vcc->dev_data) {
instance->atmsar_vcc_list = instance->atmsar_vcc_list->next;
} else {
for (work = instance->atmsar_vcc_list; work && work->next && (work->next != vcc->dev_data); work = work->next);
/* return if not found */
if (work->next != vcc->dev_data)
BUG ();
work->next = work->next->next;
}
if (((struct atmsar_vcc_data *)vcc->dev_data)->reasBuffer) {
dev_kfree_skb (((struct atmsar_vcc_data *)vcc->dev_data)->reasBuffer);
}
dbg ("Deallocated SARLib vcc 0x%p with vp %d vc %d", vcc->dev_data, vcc->dev_data->vp, vcc->dev_data->vc);
kfree (vcc->dev_data);
vcc->dev_data = NULL; vcc->dev_data = NULL;
clear_bit (ATM_VF_PARTIAL, &vcc->flags); clear_bit (ATM_VF_PARTIAL, &vcc->flags);
......
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