Hi Matthieu
On Tuesday 20 of September 2005 00:15, matthieu castet wrote:
> I am busy and I didn't had time to review your patch.
>
> Could you resend it without indent stuff. A diff with '-b' should be
> fine. It will be easier to see what changed.
I also expect you tell me how fast driver work in bulk mode
(remember about tuning timeout) but don't hurry, we have time :)
Staszek Gruszka
diff -bprN usbatm_iso-orig/usbatm.c usbatm_iso/usbatm.c
*** usbatm_iso-orig/usbatm.c 2005-09-20 16:01:44.000000000 +0200
--- usbatm_iso/usbatm.c 2005-09-20 16:02:19.000000000 +0200
*************** static inline struct usbatm_vcc_data *us
*** 294,395 ****
return NULL;
}
! static void usbatm_extract_cells(struct usbatm_data *instance,
! unsigned char *source, unsigned int avail_data)
{
- struct usbatm_vcc_data *cached_vcc = NULL;
struct atm_vcc *vcc;
! struct sk_buff *sarb;
! unsigned int stride = instance->rx_channel.stride;
! int vci, cached_vci = 0;
! short vpi, cached_vpi = 0;
! u8 pti;
!
! for (; avail_data >= stride; avail_data -= stride, source += stride) {
! vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
! vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
! pti = ((source[3] & 0xe) >> 1);
vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
! if ((vci != cached_vci) || (vpi != cached_vpi)) {
! cached_vpi = vpi;
! cached_vci = vci;
! cached_vcc = usbatm_find_vcc(instance, vpi, vci);
! if (!cached_vcc)
! atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
}
! if (!cached_vcc)
! continue;
! vcc = cached_vcc->vcc;
/* OAM F5 end-to-end */
if (pti == ATM_PTI_E2EF5) {
! atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n", __func__, vpi, vci);
atomic_inc(&vcc->stats->rx_err);
! continue;
}
! sarb = cached_vcc->sarb;
if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
! atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
__func__, sarb->len, vcc);
/* discard cells already received */
skb_trim(sarb, 0);
UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
}
! memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
__skb_put(sarb, ATM_CELL_PAYLOAD);
! if (pti & 1) {
! struct sk_buff *skb;
! unsigned int length;
! unsigned int pdu_length;
! length = (source[ATM_CELL_SIZE - 6] << 8) + source[ATM_CELL_SIZE - 5];
/* guard against overflow */
if (length > ATM_MAX_AAL5_PDU) {
atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
__func__, length, vcc);
! atomic_inc(&vcc->stats->rx_err);
! goto out;
}
pdu_length = usbatm_pdu_length(length);
if (sarb->len < pdu_length) {
! atm_dbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
! __func__, pdu_length, sarb->len, vcc);
! atomic_inc(&vcc->stats->rx_err);
! goto out;
}
if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
__func__, vcc);
! atomic_inc(&vcc->stats->rx_err);
! goto out;
}
! vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
if (!(skb = dev_alloc_skb(length))) {
! atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length);
atomic_inc(&vcc->stats->rx_drop);
goto out;
}
! vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
if (!atm_charge(vcc, skb->truesize)) {
! atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize);
dev_kfree_skb(skb);
goto out; /* atm_charge increments rx_drop */
}
--- 294,392 ----
return NULL;
}
! static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char *cell)
{
struct atm_vcc *vcc;
! struct sk_buff *sarb, *skb;
! unsigned int length, pdu_length;
! short vpi = ((cell[0] & 0x0f) << 4) | (cell[1] >> 4);
! int vci = ((cell[1] & 0x0f) << 12) | (cell[2] << 4) | (cell[3] >> 4);
! u8 pti = ((cell[3] & 0xe) >> 1);
vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
! if ((vci != instance->cached_vci) || (vpi != instance->cached_vpi)) {
! instance->cached_vpi = vpi;
! instance->cached_vci = vci;
! instance->cached_vcc = usbatm_find_vcc(instance, vpi, vci);
! if (!instance->cached_vcc)
! atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n",
! __func__, vpi, vci);
}
! if (!instance->cached_vcc)
! return;
! vcc = instance->cached_vcc->vcc;
/* OAM F5 end-to-end */
if (pti == ATM_PTI_E2EF5) {
! atm_warn(instance,
! "%s: OAM not supported (vpi %d, vci %d)!\n",
! __func__, vpi, vci);
atomic_inc(&vcc->stats->rx_err);
! return;
}
! sarb = instance->cached_vcc->sarb;
if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
! atm_dbg(instance,
! "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
__func__, sarb->len, vcc);
/* discard cells already received */
skb_trim(sarb, 0);
UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
}
! memcpy(sarb->tail, cell + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
__skb_put(sarb, ATM_CELL_PAYLOAD);
! if ((pti & 1) == 0)
! return;
! length = (cell[ATM_CELL_SIZE - 6] << 8) + cell[ATM_CELL_SIZE - 5];
/* guard against overflow */
if (length > ATM_MAX_AAL5_PDU) {
atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
__func__, length, vcc);
! goto err;
}
pdu_length = usbatm_pdu_length(length);
if (sarb->len < pdu_length) {
! atm_dbg(instance,
! "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n", __func__, pdu_length, sarb->len, vcc);
! goto err;
}
if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
__func__, vcc);
! goto err;
}
! vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)",
! __func__, length, pdu_length, vcc);
if (!(skb = dev_alloc_skb(length))) {
! atm_dbg(instance, "%s: no memory for skb (length: %u)!\n",
! __func__, length);
atomic_inc(&vcc->stats->rx_drop);
goto out;
}
! vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)",
! __func__, skb, skb->truesize);
if (!atm_charge(vcc, skb->truesize)) {
! atm_dbg(instance,
! "%s: failed atm_charge (skb->truesize: %u)!\n",
! __func__, skb->truesize);
dev_kfree_skb(skb);
goto out; /* atm_charge increments rx_drop */
}
*************** static void usbatm_extract_cells(struct
*** 403,413 ****
PACKETDEBUG(skb->data, skb->len);
vcc->push(vcc, skb);
-
atomic_inc(&vcc->stats->rx);
! out:
skb_trim(sarb, 0);
}
}
}
--- 400,454 ----
PACKETDEBUG(skb->data, skb->len);
vcc->push(vcc, skb);
atomic_inc(&vcc->stats->rx);
!
! out:
skb_trim(sarb, 0);
+ return;
+
+ err:
+ atomic_inc(&vcc->stats->rx_err);
+ /* XXX: do we need this */
+ //instance->cell_len = 0;
+ goto out;
+ }
+
+ static void usbatm_extract_cells(struct usbatm_data *instance,
+ unsigned char *source, unsigned int avail_data)
+ {
+ unsigned int stride = instance->rx_channel.stride;
+ unsigned int cell_len = instance->cell_len;
+
+ UDSL_ASSERT(cell_len < stride);
+
+ if (cell_len > 0) {
+ /* we have partially received atm cell */
+ unsigned int remain_data = stride - cell_len;
+ unsigned char *cell_buf = instance->cell_buf;
+
+ if (avail_data >= remain_data) {
+ /* add new data and process cell */
+ memcpy(cell_buf + cell_len, source, remain_data);
+ source += remain_data;
+ avail_data -= remain_data;
+ usbatm_extract_one_cell(instance, cell_buf);
+ instance->cell_len = 0;
+ } else {
+ /* too small data chunk to fill cell */
+ memcpy(cell_buf + cell_len, source, avail_data);
+ instance->cell_len = cell_len + avail_data;
+ return;
+ }
}
+
+ for (; avail_data >= stride; avail_data -= stride, source += stride)
+ usbatm_extract_one_cell(instance, source);
+
+ if (avail_data > 0) {
+ /* length was not multiple of stride,
+ * save remain data to next call */
+ memcpy(instance->cell_buf, source, avail_data);
+ instance->cell_len = avail_data;
}
}
*************** static int usbatm_atm_open(struct atm_vc
*** 772,777 ****
--- 813,822 ----
vcc->dev_data = new;
tasklet_disable(&instance->rx_channel.tasklet);
+ instance->cached_vcc = new;
+ instance->cached_vpi = vpi;
+ instance->cached_vci = vci;
+ instance->cell_len = 0;
list_add(&new->list, &instance->vcc_list);
tasklet_enable(&instance->rx_channel.tasklet);
*************** static void usbatm_atm_close(struct atm_
*** 811,816 ****
--- 856,865 ----
down(&instance->serialize); /* vs self, usbatm_atm_open */
tasklet_disable(&instance->rx_channel.tasklet);
+ instance->cached_vcc = NULL;
+ instance->cached_vpi = ATM_VPI_UNSPEC;
+ instance->cached_vci = ATM_VCI_UNSPEC;
+ instance->cell_len = 0;
list_del(&vcc_data->list);
tasklet_enable(&instance->rx_channel.tasklet);
*************** static void usbatm_atm_close(struct atm_
*** 822,827 ****
--- 871,877 ----
vcc->vpi = ATM_VPI_UNSPEC;
vcc->vci = ATM_VCI_UNSPEC;
+
clear_bit(ATM_VF_READY, &vcc->flags);
clear_bit(ATM_VF_PARTIAL, &vcc->flags);
clear_bit(ATM_VF_ADDR, &vcc->flags);
*************** int usbatm_usb_probe(struct usb_interfac
*** 1032,1037 ****
--- 1082,1097 ----
skb_queue_head_init(&instance->sndqueue);
+ instance->cached_vpi = ATM_VPI_UNSPEC;
+ instance->cached_vci = ATM_VCI_UNSPEC;
+ instance->cell_buf = kmalloc(instance->rx_channel.stride, GFP_KERNEL);
+
+ if (!instance->cell_buf) {
+ dev_dbg(dev, "%s: no memory for cell buffer\n", __func__);
+ error = -ENOMEM;
+ goto fail_unbind;
+ }
+
for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
struct urb *urb;
u8 *buffer;
diff -bprN usbatm_iso-orig/usbatm.h usbatm_iso/usbatm.h
*** usbatm_iso-orig/usbatm.h 2005-09-20 16:01:44.000000000 +0200
--- usbatm_iso/usbatm.h 2005-09-20 16:02:19.000000000 +0200
*************** struct usbatm_data {
*** 184,189 ****
--- 184,196 ----
struct sk_buff_head sndqueue;
struct sk_buff *current_skb; /* being emptied */
+ struct usbatm_vcc_data *cached_vcc;
+ int cached_vci;
+ short cached_vpi;
+
+ unsigned char *cell_buf;
+ unsigned int cell_len;
+
struct urb *urbs[0];
};