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

[PATCH] USB ATM: new usbatm core

Rework the core usbatm code: minidrivers (i.e. drivers for particular
modems) now register themselves with the usbatm core, supplying methods
for binding/unbinding etc.  The design was inspired by usb-serial and
usbnet.  At the same time, more common code from the speedtch and
cxacru (patch 3/5) drivers was generalized and moved into the core.  The
transmission and reception parts have been unified and simplified.  Since
this is a major change and I don't like underscores in file names,
usb_atm.[ch] has been renamed usbatm.[ch].

Many thanks to Roman Kagan, who did a lot of the coding.
Signed-off-by: default avatarDuncan Sands <baldrick@free.fr>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent d49d4317
/****************************************************************************** /******************************************************************************
* usb_atm.c - Generic USB xDSL driver core * usbatm.c - Generic USB xDSL driver core
* *
* Copyright (C) 2001, Alcatel * Copyright (C) 2001, Alcatel
* Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
* Copyright (C) 2004, David Woodhouse * Copyright (C) 2004, David Woodhouse, Roman Kagan
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
******************************************************************************/ ******************************************************************************/
/* /*
* Written by Johan Verrept, maintained by Duncan Sands (duncan.sands@free.fr) * Written by Johan Verrept, Duncan Sands (duncan.sands@free.fr) and David Woodhouse
* *
* 1.7+: - See the check-in logs * 1.7+: - See the check-in logs
* *
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
* 1.5A: - Version for inclusion in 2.5 series kernel * 1.5A: - Version for inclusion in 2.5 series kernel
* - Modifications by Richard Purdie (rpurdie@rpsys.net) * - Modifications by Richard Purdie (rpurdie@rpsys.net)
* - made compatible with kernel 2.5.6 onwards by changing * - made compatible with kernel 2.5.6 onwards by changing
* udsl_usb_send_data_context->urb to a pointer and adding code * usbatm_usb_send_data_context->urb to a pointer and adding code
* to alloc and free it * to alloc and free it
* - remove_wait_queue() added to udsl_atm_processqueue_thread() * - remove_wait_queue() added to usbatm_atm_processqueue_thread()
* *
* 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL. * 1.5: - fixed memory leak when atmsar_decode_aal5 returned NULL.
* (reported by stephen.robinson@zen.co.uk) * (reported by stephen.robinson@zen.co.uk)
...@@ -57,35 +57,33 @@ ...@@ -57,35 +57,33 @@
* - fixed memory leak and vcc->tx_inuse starvation bug * - fixed memory leak and vcc->tx_inuse starvation bug
* when not enough memory left in vcc. * when not enough memory left in vcc.
* *
* 1.2: - Fixed race condition in udsl_usb_send_data() * 1.2: - Fixed race condition in usbatm_usb_send_data()
* 1.1: - Turned off packet debugging * 1.1: - Turned off packet debugging
* *
*/ */
#include "usbatm.h"
#include <asm/uaccess.h>
#include <linux/crc32.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/errno.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/wait.h>
#include <linux/list.h>
#include <asm/uaccess.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/interrupt.h> #include <linux/stat.h>
#include <linux/atm.h> #include <linux/timer.h>
#include <linux/atmdev.h> #include <linux/wait.h>
#include <linux/crc32.h>
#include <linux/init.h>
#include <linux/firmware.h>
#include "usb_atm.h"
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
static int udsl_print_packet(const unsigned char *data, int len); static int usbatm_print_packet(const unsigned char *data, int len);
#define PACKETDEBUG(arg...) udsl_print_packet (arg) #define PACKETDEBUG(arg...) usbatm_print_packet (arg)
#define vdbg(arg...) dbg (arg) #define vdbg(arg...) dbg (arg)
#else #else
#define PACKETDEBUG(arg...) #define PACKETDEBUG(arg...)
...@@ -93,76 +91,110 @@ static int udsl_print_packet(const unsigned char *data, int len); ...@@ -93,76 +91,110 @@ static int udsl_print_packet(const unsigned char *data, int len);
#endif #endif
#define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>" #define DRIVER_AUTHOR "Johan Verrept, Duncan Sands <duncan.sands@free.fr>"
#define DRIVER_VERSION "1.8" #define DRIVER_VERSION "1.9"
#define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION #define DRIVER_DESC "Generic USB ATM/DSL I/O, version " DRIVER_VERSION
static const char usbatm_driver_name[] = "usbatm";
#define UDSL_MAX_RCV_URBS 16
#define UDSL_MAX_SND_URBS 16
#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */
#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */
#define UDSL_DEFAULT_RCV_URBS 4
#define UDSL_DEFAULT_SND_URBS 4
#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */
#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */
#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
#define THROTTLE_MSECS 100 /* delay to recover processing after urb submission fails */
static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS; static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS; static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS;
static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS;
static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE; static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE; static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
module_param(num_rcv_urbs, uint, 0444); module_param(num_rcv_urbs, uint, S_IRUGO);
MODULE_PARM_DESC(num_rcv_urbs, MODULE_PARM_DESC(num_rcv_urbs,
"Number of urbs used for reception (range: 0-" "Number of urbs used for reception (range: 0-"
__MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: " __MODULE_STRING(UDSL_MAX_RCV_URBS) ", default: "
__MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")"); __MODULE_STRING(UDSL_DEFAULT_RCV_URBS) ")");
module_param(num_snd_urbs, uint, 0444); module_param(num_snd_urbs, uint, S_IRUGO);
MODULE_PARM_DESC(num_snd_urbs, MODULE_PARM_DESC(num_snd_urbs,
"Number of urbs used for transmission (range: 0-" "Number of urbs used for transmission (range: 0-"
__MODULE_STRING(UDSL_MAX_SND_URBS) ", default: " __MODULE_STRING(UDSL_MAX_SND_URBS) ", default: "
__MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")"); __MODULE_STRING(UDSL_DEFAULT_SND_URBS) ")");
module_param(num_rcv_bufs, uint, 0444); module_param(rcv_buf_size, uint, S_IRUGO);
MODULE_PARM_DESC(num_rcv_bufs,
"Number of buffers used for reception (range: 0-"
__MODULE_STRING(UDSL_MAX_RCV_BUFS) ", default: "
__MODULE_STRING(UDSL_DEFAULT_RCV_BUFS) ")");
module_param(num_snd_bufs, uint, 0444);
MODULE_PARM_DESC(num_snd_bufs,
"Number of buffers used for transmission (range: 0-"
__MODULE_STRING(UDSL_MAX_SND_BUFS) ", default: "
__MODULE_STRING(UDSL_DEFAULT_SND_BUFS) ")");
module_param(rcv_buf_size, uint, 0444);
MODULE_PARM_DESC(rcv_buf_size, MODULE_PARM_DESC(rcv_buf_size,
"Size of the buffers used for reception (range: 0-" "Size of the buffers used for reception in ATM cells (range: 1-"
__MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: " __MODULE_STRING(UDSL_MAX_RCV_BUF_SIZE) ", default: "
__MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")"); __MODULE_STRING(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
module_param(snd_buf_size, uint, 0444); module_param(snd_buf_size, uint, S_IRUGO);
MODULE_PARM_DESC(snd_buf_size, MODULE_PARM_DESC(snd_buf_size,
"Size of the buffers used for transmission (range: 0-" "Size of the buffers used for transmission in ATM cells (range: 1-"
__MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: " __MODULE_STRING(UDSL_MAX_SND_BUF_SIZE) ", default: "
__MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")"); __MODULE_STRING(UDSL_DEFAULT_SND_BUF_SIZE) ")");
/* receive */
struct usbatm_vcc_data {
/* vpi/vci lookup */
struct list_head list;
short vpi;
int vci;
struct atm_vcc *vcc;
/* raw cell reassembly */
struct sk_buff *sarb;
};
/* send */
struct usbatm_control {
struct atm_skb_data atm;
u32 len;
u32 crc;
};
#define UDSL_SKB(x) ((struct usbatm_control *)(x)->cb)
/* ATM */ /* ATM */
static void udsl_atm_dev_close(struct atm_dev *dev); static void usbatm_atm_dev_close(struct atm_dev *dev);
static int udsl_atm_open(struct atm_vcc *vcc); static int usbatm_atm_open(struct atm_vcc *vcc);
static void udsl_atm_close(struct atm_vcc *vcc); static void usbatm_atm_close(struct atm_vcc *vcc);
static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg); static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd, void __user * arg);
static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb); static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb);
static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page); static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page);
static struct atmdev_ops udsl_atm_devops = { static struct atmdev_ops usbatm_atm_devops = {
.dev_close = udsl_atm_dev_close, .dev_close = usbatm_atm_dev_close,
.open = udsl_atm_open, .open = usbatm_atm_open,
.close = udsl_atm_close, .close = usbatm_atm_close,
.ioctl = udsl_atm_ioctl, .ioctl = usbatm_atm_ioctl,
.send = udsl_atm_send, .send = usbatm_atm_send,
.proc_read = udsl_atm_proc_read, .proc_read = usbatm_atm_proc_read,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
/*********** /***********
** misc ** ** misc **
***********/ ***********/
static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb) static inline unsigned int usbatm_pdu_length(unsigned int length)
{
length += ATM_CELL_PAYLOAD - 1 + ATM_AAL5_TRAILER;
return length - length % ATM_CELL_PAYLOAD;
}
static inline void usbatm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
{ {
if (vcc->pop) if (vcc->pop)
vcc->pop(vcc, skb); vcc->pop(vcc, skb);
...@@ -170,14 +202,89 @@ static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb) ...@@ -170,14 +202,89 @@ static inline void udsl_pop(struct atm_vcc *vcc, struct sk_buff *skb)
dev_kfree_skb(skb); dev_kfree_skb(skb);
} }
/***********
** urbs **
************/
static inline struct urb *usbatm_pop_urb(struct usbatm_channel *channel)
{
struct urb *urb;
spin_lock_irq(&channel->lock);
if (list_empty(&channel->list)) {
spin_unlock_irq(&channel->lock);
return NULL;
}
urb = list_entry(channel->list.next, struct urb, urb_list);
list_del(&urb->urb_list);
spin_unlock_irq(&channel->lock);
return urb;
}
static inline int usbatm_submit_urb(struct urb *urb)
{
struct usbatm_channel *channel = urb->context;
int ret;
vdbg("%s: submitting urb 0x%p, size %u",
__func__, urb, urb->transfer_buffer_length);
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret) {
atm_dbg(channel->usbatm, "%s: urb 0x%p submission failed (%d)!\n",
__func__, urb, ret);
/* consider all errors transient and return the buffer back to the queue */
urb->status = -EAGAIN;
spin_lock_irq(&channel->lock);
/* must add to the front when sending; doesn't matter when receiving */
list_add(&urb->urb_list, &channel->list);
spin_unlock_irq(&channel->lock);
/* make sure the channel doesn't stall */
mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
}
return ret;
}
static void usbatm_complete(struct urb *urb, struct pt_regs *regs)
{
struct usbatm_channel *channel = urb->context;
unsigned long flags;
vdbg("%s: urb 0x%p, status %d, actual_length %d",
__func__, urb, urb->status, urb->actual_length);
/* usually in_interrupt(), but not always */
spin_lock_irqsave(&channel->lock, flags);
/* must add to the back when receiving; doesn't matter when sending */
list_add_tail(&urb->urb_list, &channel->list);
spin_unlock_irqrestore(&channel->lock, flags);
if (unlikely(urb->status))
/* throttle processing in case of an error */
mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
else
tasklet_schedule(&channel->tasklet);
}
/************* /*************
** decode ** ** decode **
*************/ *************/
static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *instance, static inline struct usbatm_vcc_data *usbatm_find_vcc(struct usbatm_data *instance,
short vpi, int vci) short vpi, int vci)
{ {
struct udsl_vcc_data *vcc; struct usbatm_vcc_data *vcc;
list_for_each_entry(vcc, &instance->vcc_list, list) list_for_each_entry(vcc, &instance->vcc_list, list)
if ((vcc->vci == vci) && (vcc->vpi == vpi)) if ((vcc->vci == vci) && (vcc->vpi == vpi))
...@@ -185,52 +292,59 @@ static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *ins ...@@ -185,52 +292,59 @@ static inline struct udsl_vcc_data *udsl_find_vcc(struct udsl_instance_data *ins
return NULL; return NULL;
} }
static void udsl_extract_cells(struct udsl_instance_data *instance, static void usbatm_extract_cells(struct usbatm_data *instance,
unsigned char *source, unsigned int howmany) unsigned char *source, unsigned int avail_data)
{ {
struct udsl_vcc_data *cached_vcc = NULL; struct usbatm_vcc_data *cached_vcc = NULL;
struct atm_vcc *vcc; struct atm_vcc *vcc;
struct sk_buff *sarb; struct sk_buff *sarb;
struct udsl_vcc_data *vcc_data; struct usbatm_vcc_data *vcc_data;
int cached_vci = 0; unsigned int stride = instance->rx_channel.stride;
unsigned int i; int vci, cached_vci = 0;
int pti; short vpi, cached_vpi = 0;
int vci; u8 pti;
short cached_vpi = 0;
short vpi; for (; avail_data >= stride; avail_data -= stride, source += stride) {
vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
for (i = 0; i < howmany;
i++, source += ATM_CELL_SIZE + instance->rcv_padding) {
vpi = ((source[0] & 0x0f) << 4) | (source[1] >> 4);
vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4); vci = ((source[1] & 0x0f) << 12) | (source[2] << 4) | (source[3] >> 4);
pti = (source[3] & 0x2) != 0; pti = ((source[3] & 0xe) >> 1);
vdbg("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti); vdbg("%s: vpi %hd, vci %d, pti %d", __func__, vpi, vci, pti);
if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi)) if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
vcc_data = cached_vcc; vcc_data = cached_vcc;
else if ((vcc_data = udsl_find_vcc(instance, vpi, vci))) { else if ((vcc_data = usbatm_find_vcc(instance, vpi, vci))) {
cached_vcc = vcc_data; cached_vcc = vcc_data;
cached_vpi = vpi; cached_vpi = vpi;
cached_vci = vci; cached_vci = vci;
} else { } else {
dbg("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, vci); atm_dbg(instance, "%s: unknown vpi/vci (%hd/%d)!\n", __func__, vpi, vci);
continue; continue;
} }
vcc = vcc_data->vcc; vcc = vcc_data->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 = vcc_data->sarb; sarb = vcc_data->sarb;
if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) { if (sarb->tail + ATM_CELL_PAYLOAD > sarb->end) {
dbg("udsl_extract_cells: buffer overrun (sarb->len %u, vcc: 0x%p)!", sarb->len, vcc); atm_dbg(instance, "%s: buffer overrun (sarb->len %u, vcc: 0x%p)!\n",
__func__, sarb->len, vcc);
/* discard cells already received */ /* discard cells already received */
skb_trim(sarb, 0); skb_trim(sarb, 0);
UDSL_ASSERT(sarb->tail + ATM_CELL_PAYLOAD <= sarb->end);
} }
memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD); memcpy(sarb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
__skb_put(sarb, ATM_CELL_PAYLOAD); __skb_put(sarb, ATM_CELL_PAYLOAD);
if (pti) { if (pti & 1) {
struct sk_buff *skb; struct sk_buff *skb;
unsigned int length; unsigned int length;
unsigned int pdu_length; unsigned int pdu_length;
...@@ -239,37 +353,40 @@ static void udsl_extract_cells(struct udsl_instance_data *instance, ...@@ -239,37 +353,40 @@ static void udsl_extract_cells(struct udsl_instance_data *instance,
/* guard against overflow */ /* guard against overflow */
if (length > ATM_MAX_AAL5_PDU) { if (length > ATM_MAX_AAL5_PDU) {
dbg("udsl_extract_cells: bogus length %u (vcc: 0x%p)!", length, vcc); atm_dbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
__func__, length, vcc);
atomic_inc(&vcc->stats->rx_err); atomic_inc(&vcc->stats->rx_err);
goto out; goto out;
} }
pdu_length = UDSL_NUM_CELLS(length) * ATM_CELL_PAYLOAD; pdu_length = usbatm_pdu_length(length);
if (sarb->len < pdu_length) { if (sarb->len < pdu_length) {
dbg("udsl_extract_cells: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!", pdu_length, sarb->len, vcc); 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); atomic_inc(&vcc->stats->rx_err);
goto out; goto out;
} }
if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) { if (crc32_be(~0, sarb->tail - pdu_length, pdu_length) != 0xc704dd7b) {
dbg("udsl_extract_cells: packet failed crc check (vcc: 0x%p)!", vcc); atm_dbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
__func__, vcc);
atomic_inc(&vcc->stats->rx_err); atomic_inc(&vcc->stats->rx_err);
goto out; goto out;
} }
vdbg("udsl_extract_cells: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", length, pdu_length, vcc); vdbg("%s: got packet (length: %u, pdu_length: %u, vcc: 0x%p)", __func__, length, pdu_length, vcc);
if (!(skb = dev_alloc_skb(length))) { if (!(skb = dev_alloc_skb(length))) {
dbg("udsl_extract_cells: no memory for skb (length: %u)!", length); atm_dbg(instance, "%s: no memory for skb (length: %u)!\n", __func__, length);
atomic_inc(&vcc->stats->rx_drop); atomic_inc(&vcc->stats->rx_drop);
goto out; goto out;
} }
vdbg("udsl_extract_cells: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", skb, skb->truesize); vdbg("%s: allocated new sk_buff (skb: 0x%p, skb->truesize: %u)", __func__, skb, skb->truesize);
if (!atm_charge(vcc, skb->truesize)) { if (!atm_charge(vcc, skb->truesize)) {
dbg("udsl_extract_cells: failed atm_charge (skb->truesize: %u)!", skb->truesize); atm_dbg(instance, "%s: failed atm_charge (skb->truesize: %u)!\n", __func__, skb->truesize);
dev_kfree_skb(skb); dev_kfree_skb(skb);
goto out; /* atm_charge increments rx_drop */ goto out; /* atm_charge increments rx_drop */
} }
...@@ -277,7 +394,8 @@ static void udsl_extract_cells(struct udsl_instance_data *instance, ...@@ -277,7 +394,8 @@ static void udsl_extract_cells(struct udsl_instance_data *instance,
memcpy(skb->data, sarb->tail - pdu_length, length); memcpy(skb->data, sarb->tail - pdu_length, length);
__skb_put(skb, length); __skb_put(skb, length);
vdbg("udsl_extract_cells: sending skb 0x%p, skb->len %u, skb->truesize %u", skb, skb->len, skb->truesize); vdbg("%s: sending skb 0x%p, skb->len %u, skb->truesize %u",
__func__, skb, skb->len, skb->truesize);
PACKETDEBUG(skb->data, skb->len); PACKETDEBUG(skb->data, skb->len);
...@@ -290,454 +408,282 @@ static void udsl_extract_cells(struct udsl_instance_data *instance, ...@@ -290,454 +408,282 @@ static void udsl_extract_cells(struct udsl_instance_data *instance,
} }
} }
/************* /*************
** encode ** ** encode **
*************/ *************/
static inline void udsl_fill_cell_header(unsigned char *target, struct atm_vcc *vcc) static unsigned int usbatm_write_cells(struct usbatm_data *instance,
struct sk_buff *skb,
u8 *target, unsigned int avail_space)
{ {
target[0] = vcc->vpi >> 4; struct usbatm_control *ctrl = UDSL_SKB(skb);
target[1] = (vcc->vpi << 4) | (vcc->vci >> 12); struct atm_vcc *vcc = ctrl->atm.vcc;
target[2] = vcc->vci >> 4; unsigned int num_written;
target[3] = vcc->vci << 4; unsigned int stride = instance->tx_channel.stride;
target[4] = 0xec;
}
static const unsigned char zeros[ATM_CELL_PAYLOAD]; vdbg("%s: skb->len=%d, avail_space=%u", __func__, skb->len, avail_space);
UDSL_ASSERT(!(avail_space % stride));
static void udsl_groom_skb(struct atm_vcc *vcc, struct sk_buff *skb) for (num_written = 0; num_written < avail_space && ctrl->len;
{ num_written += stride, target += stride) {
struct udsl_control *ctrl = UDSL_SKB(skb); unsigned int data_len = min_t(unsigned int, skb->len, ATM_CELL_PAYLOAD);
unsigned int zero_padding; unsigned int left = ATM_CELL_PAYLOAD - data_len;
u32 crc; u8 *ptr = target;
ctrl->atm_data.vcc = vcc; ptr[0] = vcc->vpi >> 4;
ptr[1] = (vcc->vpi << 4) | (vcc->vci >> 12);
ptr[2] = vcc->vci >> 4;
ptr[3] = vcc->vci << 4;
ptr[4] = 0xec;
ptr += ATM_CELL_HEADER;
ctrl->num_cells = UDSL_NUM_CELLS(skb->len); memcpy(ptr, skb->data, data_len);
ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD; ptr += data_len;
__skb_pull(skb, data_len);
zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - ATM_AAL5_TRAILER; if(!left)
continue;
if (ctrl->num_entire + 1 < ctrl->num_cells) memset(ptr, 0, left);
ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
else
ctrl->pdu_padding = zero_padding;
ctrl->aal5_trailer[0] = 0; /* UU = 0 */
ctrl->aal5_trailer[1] = 0; /* CPI = 0 */
ctrl->aal5_trailer[2] = skb->len >> 8;
ctrl->aal5_trailer[3] = skb->len;
crc = crc32_be(~0, skb->data, skb->len);
crc = crc32_be(crc, zeros, zero_padding);
crc = crc32_be(crc, ctrl->aal5_trailer, 4);
crc = ~crc;
ctrl->aal5_trailer[4] = crc >> 24;
ctrl->aal5_trailer[5] = crc >> 16;
ctrl->aal5_trailer[6] = crc >> 8;
ctrl->aal5_trailer[7] = crc;
}
static unsigned int udsl_write_cells(struct udsl_instance_data *instance, if (left >= ATM_AAL5_TRAILER) { /* trailer will go in this cell */
unsigned int howmany, struct sk_buff *skb, u8 *trailer = target + ATM_CELL_SIZE - ATM_AAL5_TRAILER;
unsigned char **target_p) /* trailer[0] = 0; UU = 0 */
{ /* trailer[1] = 0; CPI = 0 */
struct udsl_control *ctrl = UDSL_SKB(skb); trailer[2] = ctrl->len >> 8;
unsigned char *target = *target_p; trailer[3] = ctrl->len;
unsigned int nc, ne, i;
vdbg("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, ctrl->pdu_padding);
nc = ctrl->num_cells;
ne = min(howmany, ctrl->num_entire);
for (i = 0; i < ne; i++) {
udsl_fill_cell_header(target, ctrl->atm_data.vcc);
target += ATM_CELL_HEADER;
memcpy(target, skb->data, ATM_CELL_PAYLOAD);
target += ATM_CELL_PAYLOAD;
if (instance->snd_padding) {
memset(target, 0, instance->snd_padding);
target += instance->snd_padding;
}
__skb_pull(skb, ATM_CELL_PAYLOAD);
}
ctrl->num_entire -= ne; ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4);
if (!(ctrl->num_cells -= ne) || !(howmany -= ne)) trailer[4] = ctrl->crc >> 24;
goto out; trailer[5] = ctrl->crc >> 16;
trailer[6] = ctrl->crc >> 8;
trailer[7] = ctrl->crc;
udsl_fill_cell_header(target, ctrl->atm_data.vcc); target[3] |= 0x2; /* adjust PTI */
target += ATM_CELL_HEADER;
memcpy(target, skb->data, skb->len);
target += skb->len;
__skb_pull(skb, skb->len);
memset(target, 0, ctrl->pdu_padding);
target += ctrl->pdu_padding;
if (--ctrl->num_cells) { ctrl->len = 0; /* tag this skb finished */
if (!--howmany) {
ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
goto out;
} }
else
if (instance->snd_padding) { ctrl->crc = crc32_be(ctrl->crc, ptr, left);
memset(target, 0, instance->snd_padding);
target += instance->snd_padding;
}
udsl_fill_cell_header(target, ctrl->atm_data.vcc);
target += ATM_CELL_HEADER;
memset(target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
--ctrl->num_cells;
UDSL_ASSERT(!ctrl->num_cells);
} }
memcpy(target, ctrl->aal5_trailer, ATM_AAL5_TRAILER); return num_written;
target += ATM_AAL5_TRAILER;
/* set pti bit in last cell */
*(target + 3 - ATM_CELL_SIZE) |= 0x2;
if (instance->snd_padding) {
memset(target, 0, instance->snd_padding);
target += instance->snd_padding;
}
out:
*target_p = target;
return nc - ctrl->num_cells;
} }
/************** /**************
** receive ** ** receive **
**************/ **************/
static void udsl_complete_receive(struct urb *urb, struct pt_regs *regs) static void usbatm_rx_process(unsigned long data)
{
struct udsl_receive_buffer *buf;
struct udsl_instance_data *instance;
struct udsl_receiver *rcv;
unsigned long flags;
if (!urb || !(rcv = urb->context)) {
dbg("udsl_complete_receive: bad urb!");
return;
}
instance = rcv->instance;
buf = rcv->buffer;
buf->filled_cells = urb->actual_length / (ATM_CELL_SIZE + instance->rcv_padding);
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);
UDSL_ASSERT(buf->filled_cells <= rcv_buf_size);
/* may not be in_interrupt() */
spin_lock_irqsave(&instance->receive_lock, flags);
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);
spin_unlock_irqrestore(&instance->receive_lock, flags);
}
static void udsl_process_receive(unsigned long data)
{ {
struct udsl_receive_buffer *buf; struct usbatm_data *instance = (struct usbatm_data *)data;
struct udsl_instance_data *instance = (struct udsl_instance_data *)data; struct urb *urb;
struct udsl_receiver *rcv;
int err; while ((urb = usbatm_pop_urb(&instance->rx_channel))) {
vdbg("%s: processing urb 0x%p", __func__, urb);
made_progress:
while (!list_empty(&instance->spare_receive_buffers)) { if (usb_pipeisoc(urb->pipe)) {
spin_lock_irq(&instance->receive_lock); int i;
if (list_empty(&instance->spare_receivers)) { for (i = 0; i < urb->number_of_packets; i++)
spin_unlock_irq(&instance->receive_lock); if (!urb->iso_frame_desc[i].status)
break; usbatm_extract_cells(instance,
(u8 *)urb->transfer_buffer + urb->iso_frame_desc[i].offset,
urb->iso_frame_desc[i].actual_length);
} }
rcv = list_entry(instance->spare_receivers.next, else
struct udsl_receiver, list); if (!urb->status)
list_del(&rcv->list); usbatm_extract_cells(instance, urb->transfer_buffer, urb->actual_length);
spin_unlock_irq(&instance->receive_lock);
buf = list_entry(instance->spare_receive_buffers.next,
struct udsl_receive_buffer, list);
list_del(&buf->list);
rcv->buffer = buf;
usb_fill_bulk_urb(rcv->urb, instance->usb_dev,
usb_rcvbulkpipe(instance->usb_dev, instance->data_endpoint),
buf->base,
rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding),
udsl_complete_receive, rcv);
vdbg("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p",
rcv->urb, rcv, buf);
if ((err = usb_submit_urb(rcv->urb, GFP_ATOMIC)) < 0) {
dbg("udsl_process_receive: urb submission failed (%d)!", err);
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;
}
}
spin_lock_irq(&instance->receive_lock); if (usbatm_submit_urb(urb))
if (list_empty(&instance->filled_receive_buffers)) { return;
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;
} }
/*********** /***********
** send ** ** send **
***********/ ***********/
static void udsl_complete_send(struct urb *urb, struct pt_regs *regs) static void usbatm_tx_process(unsigned long data)
{ {
struct udsl_instance_data *instance; struct usbatm_data *instance = (struct usbatm_data *)data;
struct udsl_sender *snd; struct sk_buff *skb = instance->current_skb;
unsigned long flags; struct urb *urb = NULL;
const unsigned int buf_size = instance->tx_channel.buf_size;
unsigned int num_written = 0;
u8 *buffer = NULL;
if (!skb)
skb = skb_dequeue(&instance->sndqueue);
while (skb) {
if (!urb) {
urb = usbatm_pop_urb(&instance->tx_channel);
if (!urb)
break; /* no more senders */
buffer = urb->transfer_buffer;
num_written = (urb->status == -EAGAIN) ?
urb->transfer_buffer_length : 0;
}
if (!urb || !(snd = urb->context) || !(instance = snd->instance)) { num_written += usbatm_write_cells(instance, skb,
dbg("udsl_complete_send: bad urb!"); buffer + num_written,
return; buf_size - num_written);
}
vdbg("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb, vdbg("%s: wrote %u bytes from skb 0x%p to urb 0x%p",
urb->status, snd, snd->buffer); __func__, num_written, skb, urb);
/* may not be in_interrupt() */ if (!UDSL_SKB(skb)->len) {
spin_lock_irqsave(&instance->send_lock, flags); struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
list_add(&snd->list, &instance->spare_senders);
list_add(&snd->buffer->list, &instance->spare_send_buffers);
tasklet_schedule(&instance->send_tasklet);
spin_unlock_irqrestore(&instance->send_lock, flags);
}
static void udsl_process_send(unsigned long data) usbatm_pop(vcc, skb);
{ atomic_inc(&vcc->stats->tx);
struct udsl_send_buffer *buf;
struct udsl_instance_data *instance = (struct udsl_instance_data *)data;
struct sk_buff *skb;
struct udsl_sender *snd;
int err;
unsigned int num_written;
made_progress: skb = skb_dequeue(&instance->sndqueue);
spin_lock_irq(&instance->send_lock);
while (!list_empty(&instance->spare_senders)) {
if (!list_empty(&instance->filled_send_buffers)) {
buf = list_entry(instance->filled_send_buffers.next,
struct udsl_send_buffer, list);
list_del(&buf->list);
} else if ((buf = instance->current_buffer)) {
instance->current_buffer = NULL;
} else /* all buffers empty */
break;
snd = list_entry(instance->spare_senders.next,
struct udsl_sender, list);
list_del(&snd->list);
spin_unlock_irq(&instance->send_lock);
snd->buffer = buf;
usb_fill_bulk_urb(snd->urb, instance->usb_dev,
usb_sndbulkpipe(instance->usb_dev, instance->data_endpoint),
buf->base,
(snd_buf_size - buf->free_cells) * (ATM_CELL_SIZE + instance->snd_padding),
udsl_complete_send, snd);
vdbg("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, buf 0x%p",
snd->urb, snd_buf_size - buf->free_cells, snd, buf);
if ((err = usb_submit_urb(snd->urb, GFP_ATOMIC)) < 0) {
dbg("udsl_process_send: urb submission failed (%d)!", err);
spin_lock_irq(&instance->send_lock);
list_add(&snd->list, &instance->spare_senders);
spin_unlock_irq(&instance->send_lock);
list_add(&buf->list, &instance->filled_send_buffers);
return; /* bail out */
} }
spin_lock_irq(&instance->send_lock); if (num_written == buf_size || (!skb && num_written)) {
} /* while */ urb->transfer_buffer_length = num_written;
spin_unlock_irq(&instance->send_lock);
if (!instance->current_skb)
instance->current_skb = skb_dequeue(&instance->sndqueue);
if (!instance->current_skb)
return; /* done - no more skbs */
skb = instance->current_skb; if (usbatm_submit_urb(urb))
break;
if (!(buf = instance->current_buffer)) { urb = NULL;
spin_lock_irq(&instance->send_lock);
if (list_empty(&instance->spare_send_buffers)) {
instance->current_buffer = NULL;
spin_unlock_irq(&instance->send_lock);
return; /* done - no more buffers */
} }
buf = list_entry(instance->spare_send_buffers.next,
struct udsl_send_buffer, list);
list_del(&buf->list);
spin_unlock_irq(&instance->send_lock);
buf->free_start = buf->base;
buf->free_cells = snd_buf_size;
instance->current_buffer = buf;
}
num_written = udsl_write_cells(instance, buf->free_cells, skb, &buf->free_start);
vdbg("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p",
num_written, skb, buf);
if (!(buf->free_cells -= num_written)) {
list_add_tail(&buf->list, &instance->filled_send_buffers);
instance->current_buffer = NULL;
} }
vdbg("udsl_process_send: buffer contains %d cells, %d left", instance->current_skb = skb;
snd_buf_size - buf->free_cells, buf->free_cells);
if (!UDSL_SKB(skb)->num_cells) {
struct atm_vcc *vcc = UDSL_SKB(skb)->atm_data.vcc;
udsl_pop(vcc, skb);
instance->current_skb = NULL;
atomic_inc(&vcc->stats->tx);
}
goto made_progress;
} }
static void udsl_cancel_send(struct udsl_instance_data *instance, static void usbatm_cancel_send(struct usbatm_data *instance,
struct atm_vcc *vcc) struct atm_vcc *vcc)
{ {
struct sk_buff *skb, *n; struct sk_buff *skb, *n;
dbg("udsl_cancel_send entered"); atm_dbg(instance, "%s entered\n", __func__);
spin_lock_irq(&instance->sndqueue.lock); spin_lock_irq(&instance->sndqueue.lock);
for (skb = instance->sndqueue.next, n = skb->next; for (skb = instance->sndqueue.next, n = skb->next;
skb != (struct sk_buff *)&instance->sndqueue; skb != (struct sk_buff *)&instance->sndqueue;
skb = n, n = skb->next) skb = n, n = skb->next)
if (UDSL_SKB(skb)->atm_data.vcc == vcc) { if (UDSL_SKB(skb)->atm.vcc == vcc) {
dbg("udsl_cancel_send: popping skb 0x%p", skb); atm_dbg(instance, "%s: popping skb 0x%p\n", __func__, skb);
__skb_unlink(skb, &instance->sndqueue); __skb_unlink(skb, &instance->sndqueue);
udsl_pop(vcc, skb); usbatm_pop(vcc, skb);
} }
spin_unlock_irq(&instance->sndqueue.lock); spin_unlock_irq(&instance->sndqueue.lock);
tasklet_disable(&instance->send_tasklet); tasklet_disable(&instance->tx_channel.tasklet);
if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm_data.vcc == vcc)) { if ((skb = instance->current_skb) && (UDSL_SKB(skb)->atm.vcc == vcc)) {
dbg("udsl_cancel_send: popping current skb (0x%p)", skb); atm_dbg(instance, "%s: popping current skb (0x%p)\n", __func__, skb);
instance->current_skb = NULL; instance->current_skb = NULL;
udsl_pop(vcc, skb); usbatm_pop(vcc, skb);
} }
tasklet_enable(&instance->send_tasklet); tasklet_enable(&instance->tx_channel.tasklet);
dbg("udsl_cancel_send done"); atm_dbg(instance, "%s done\n", __func__);
} }
static int udsl_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
{ {
struct udsl_instance_data *instance = vcc->dev->dev_data; struct usbatm_data *instance = vcc->dev->dev_data;
struct usbatm_control *ctrl = UDSL_SKB(skb);
int err; int err;
vdbg("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len); vdbg("%s called (skb 0x%p, len %u)", __func__, skb, skb->len);
if (!instance) { if (!instance) {
dbg("udsl_atm_send: NULL data!"); dbg("%s: NULL data!", __func__);
err = -ENODEV; err = -ENODEV;
goto fail; goto fail;
} }
if (vcc->qos.aal != ATM_AAL5) { if (vcc->qos.aal != ATM_AAL5) {
dbg("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal); atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
err = -EINVAL; err = -EINVAL;
goto fail; goto fail;
} }
if (skb->len > ATM_MAX_AAL5_PDU) { if (skb->len > ATM_MAX_AAL5_PDU) {
dbg("udsl_atm_send: packet too long (%d vs %d)!", skb->len, atm_dbg(instance, "%s: packet too long (%d vs %d)!\n",
ATM_MAX_AAL5_PDU); __func__, skb->len, ATM_MAX_AAL5_PDU);
err = -EINVAL; err = -EINVAL;
goto fail; goto fail;
} }
PACKETDEBUG(skb->data, skb->len); PACKETDEBUG(skb->data, skb->len);
udsl_groom_skb(vcc, skb); /* initialize the control block */
ctrl->atm.vcc = vcc;
ctrl->len = skb->len;
ctrl->crc = crc32_be(~0, skb->data, skb->len);
skb_queue_tail(&instance->sndqueue, skb); skb_queue_tail(&instance->sndqueue, skb);
tasklet_schedule(&instance->send_tasklet); tasklet_schedule(&instance->tx_channel.tasklet);
return 0; return 0;
fail: fail:
udsl_pop(vcc, skb); usbatm_pop(vcc, skb);
return err; return err;
} }
/******************** /********************
** bean counting ** ** bean counting **
********************/ ********************/
static void udsl_destroy_instance(struct kref *kref) static void usbatm_destroy_instance(struct kref *kref)
{ {
struct udsl_instance_data *instance = struct usbatm_data *instance = container_of(kref, struct usbatm_data, refcount);
container_of(kref, struct udsl_instance_data, refcount);
tasklet_kill(&instance->receive_tasklet); dbg("%s", __func__);
tasklet_kill(&instance->send_tasklet);
tasklet_kill(&instance->rx_channel.tasklet);
tasklet_kill(&instance->tx_channel.tasklet);
usb_put_dev(instance->usb_dev); usb_put_dev(instance->usb_dev);
kfree(instance); kfree(instance);
} }
void udsl_get_instance(struct udsl_instance_data *instance) void usbatm_get_instance(struct usbatm_data *instance)
{ {
dbg("%s", __func__);
kref_get(&instance->refcount); kref_get(&instance->refcount);
} }
void udsl_put_instance(struct udsl_instance_data *instance) void usbatm_put_instance(struct usbatm_data *instance)
{ {
kref_put(&instance->refcount, udsl_destroy_instance); dbg("%s", __func__);
kref_put(&instance->refcount, usbatm_destroy_instance);
} }
/********** /**********
** ATM ** ** ATM **
**********/ **********/
static void udsl_atm_dev_close(struct atm_dev *dev) static void usbatm_atm_dev_close(struct atm_dev *dev)
{ {
struct udsl_instance_data *instance = dev->dev_data; struct usbatm_data *instance = dev->dev_data;
dbg("%s", __func__);
if (!instance)
return;
dev->dev_data = NULL; dev->dev_data = NULL;
udsl_put_instance(instance); usbatm_put_instance(instance); /* taken in usbatm_atm_init */
} }
static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page) static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
{ {
struct udsl_instance_data *instance = atm_dev->dev_data; struct usbatm_data *instance = atm_dev->dev_data;
int left = *pos; int left = *pos;
if (!instance) { if (!instance) {
dbg("udsl_atm_proc_read: NULL instance!"); dbg("%s: NULL instance!", __func__);
return -ENODEV; return -ENODEV;
} }
...@@ -759,98 +705,72 @@ static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page) ...@@ -759,98 +705,72 @@ static int udsl_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *page)
atomic_read(&atm_dev->stats.aal5.rx_err), atomic_read(&atm_dev->stats.aal5.rx_err),
atomic_read(&atm_dev->stats.aal5.rx_drop)); atomic_read(&atm_dev->stats.aal5.rx_drop));
if (!left--) { if (!left--)
switch (atm_dev->signal) { switch (atm_dev->signal) {
case ATM_PHY_SIG_FOUND: case ATM_PHY_SIG_FOUND:
sprintf(page, "Line up"); return sprintf(page, "Line up\n");
break;
case ATM_PHY_SIG_LOST: case ATM_PHY_SIG_LOST:
sprintf(page, "Line down"); return sprintf(page, "Line down\n");
break;
default: default:
sprintf(page, "Line state unknown"); return sprintf(page, "Line state unknown\n");
break;
} }
if (instance->usb_dev->state == USB_STATE_NOTATTACHED)
strcat(page, ", disconnected\n");
else {
if (instance->status == UDSL_LOADED_FIRMWARE)
strcat(page, ", firmware loaded\n");
else if (instance->status == UDSL_LOADING_FIRMWARE)
strcat(page, ", firmware loading\n");
else
strcat(page, ", no firmware\n");
}
return strlen(page);
}
return 0; return 0;
} }
static int udsl_atm_open(struct atm_vcc *vcc) static int usbatm_atm_open(struct atm_vcc *vcc)
{ {
struct udsl_instance_data *instance = vcc->dev->dev_data; struct usbatm_data *instance = vcc->dev->dev_data;
struct udsl_vcc_data *new; struct usbatm_vcc_data *new = NULL;
unsigned int max_pdu; int ret;
int vci = vcc->vci; int vci = vcc->vci;
short vpi = vcc->vpi; short vpi = vcc->vpi;
int err;
dbg("udsl_atm_open: vpi %hd, vci %d", vpi, vci);
if (!instance) { if (!instance) {
dbg("udsl_atm_open: NULL data!"); dbg("%s: NULL data!", __func__);
return -ENODEV; return -ENODEV;
} }
atm_dbg(instance, "%s: vpi %hd, vci %d\n", __func__, vpi, vci);
/* only support AAL5 */ /* only support AAL5 */
if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0)
|| (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) { || (vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU)) {
dbg("udsl_atm_open: unsupported ATM type %d!", vcc->qos.aal); atm_dbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
return -EINVAL; return -EINVAL;
} }
if (instance->firmware_wait && down(&instance->serialize); /* vs self, usbatm_atm_close */
(err = instance->firmware_wait(instance)) < 0) {
dbg("udsl_atm_open: firmware not loaded (%d)!", err);
return err;
}
down(&instance->serialize); /* vs self, udsl_atm_close */
if (udsl_find_vcc(instance, vpi, vci)) { if (usbatm_find_vcc(instance, vpi, vci)) {
dbg("udsl_atm_open: %hd/%d already in use!", vpi, vci); atm_dbg(instance, "%s: %hd/%d already in use!\n", __func__, vpi, vci);
up(&instance->serialize); ret = -EADDRINUSE;
return -EADDRINUSE; goto fail;
} }
if (!(new = kmalloc(sizeof(struct udsl_vcc_data), GFP_KERNEL))) { if (!(new = kmalloc(sizeof(struct usbatm_vcc_data), GFP_KERNEL))) {
dbg("udsl_atm_open: no memory for vcc_data!"); atm_dbg(instance, "%s: no memory for vcc_data!\n", __func__);
up(&instance->serialize); ret = -ENOMEM;
return -ENOMEM; goto fail;
} }
memset(new, 0, sizeof(struct udsl_vcc_data)); memset(new, 0, sizeof(struct usbatm_vcc_data));
new->vcc = vcc; new->vcc = vcc;
new->vpi = vpi; new->vpi = vpi;
new->vci = vci; new->vci = vci;
/* udsl_extract_cells requires at least one cell */ new->sarb = alloc_skb(usbatm_pdu_length(vcc->qos.rxtp.max_sdu), GFP_KERNEL);
max_pdu = max(1, UDSL_NUM_CELLS(vcc->qos.rxtp.max_sdu)) * ATM_CELL_PAYLOAD; if (!new->sarb) {
if (!(new->sarb = alloc_skb(max_pdu, GFP_KERNEL))) { atm_dbg(instance, "%s: no memory for SAR buffer!\n", __func__);
dbg("udsl_atm_open: no memory for SAR buffer!"); ret = -ENOMEM;
kfree(new); goto fail;
up(&instance->serialize);
return -ENOMEM;
} }
vcc->dev_data = new; vcc->dev_data = new;
tasklet_disable(&instance->receive_tasklet); tasklet_disable(&instance->rx_channel.tasklet);
list_add(&new->list, &instance->vcc_list); list_add(&new->list, &instance->vcc_list);
tasklet_enable(&instance->receive_tasklet); tasklet_enable(&instance->rx_channel.tasklet);
set_bit(ATM_VF_ADDR, &vcc->flags); set_bit(ATM_VF_ADDR, &vcc->flags);
set_bit(ATM_VF_PARTIAL, &vcc->flags); set_bit(ATM_VF_PARTIAL, &vcc->flags);
...@@ -858,35 +778,38 @@ static int udsl_atm_open(struct atm_vcc *vcc) ...@@ -858,35 +778,38 @@ static int udsl_atm_open(struct atm_vcc *vcc)
up(&instance->serialize); up(&instance->serialize);
tasklet_schedule(&instance->receive_tasklet); atm_dbg(instance, "%s: allocated vcc data 0x%p\n", __func__, new);
dbg("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, max_pdu);
return 0; return 0;
fail:
kfree(new);
up(&instance->serialize);
return ret;
} }
static void udsl_atm_close(struct atm_vcc *vcc) static void usbatm_atm_close(struct atm_vcc *vcc)
{ {
struct udsl_instance_data *instance = vcc->dev->dev_data; struct usbatm_data *instance = vcc->dev->dev_data;
struct udsl_vcc_data *vcc_data = vcc->dev_data; struct usbatm_vcc_data *vcc_data = vcc->dev_data;
dbg("udsl_atm_close called");
if (!instance || !vcc_data) { if (!instance || !vcc_data) {
dbg("udsl_atm_close: NULL data!"); dbg("%s: NULL data!", __func__);
return; return;
} }
dbg("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d", atm_dbg(instance, "%s entered\n", __func__);
vcc_data, vcc_data->vpi, vcc_data->vci);
udsl_cancel_send(instance, vcc); atm_dbg(instance, "%s: deallocating vcc 0x%p with vpi %d vci %d\n",
__func__, vcc_data, vcc_data->vpi, vcc_data->vci);
down(&instance->serialize); /* vs self, udsl_atm_open */ usbatm_cancel_send(instance, vcc);
tasklet_disable(&instance->receive_tasklet); down(&instance->serialize); /* vs self, usbatm_atm_open */
tasklet_disable(&instance->rx_channel.tasklet);
list_del(&vcc_data->list); list_del(&vcc_data->list);
tasklet_enable(&instance->receive_tasklet); tasklet_enable(&instance->rx_channel.tasklet);
kfree_skb(vcc_data->sarb); kfree_skb(vcc_data->sarb);
vcc_data->sarb = NULL; vcc_data->sarb = NULL;
...@@ -902,10 +825,10 @@ static void udsl_atm_close(struct atm_vcc *vcc) ...@@ -902,10 +825,10 @@ static void udsl_atm_close(struct atm_vcc *vcc)
up(&instance->serialize); up(&instance->serialize);
dbg("udsl_atm_close successful"); atm_dbg(instance, "%s successful\n", __func__);
} }
static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, static int usbatm_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
void __user * arg) void __user * arg)
{ {
switch (cmd) { switch (cmd) {
...@@ -916,121 +839,148 @@ static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd, ...@@ -916,121 +839,148 @@ static int udsl_atm_ioctl(struct atm_dev *dev, unsigned int cmd,
} }
} }
/********** static int usbatm_atm_init(struct usbatm_data *instance)
** USB **
**********/
int udsl_instance_setup(struct usb_device *dev,
struct udsl_instance_data *instance)
{ {
char *buf; struct atm_dev *atm_dev;
int i, length; int ret, i;
kref_init(&instance->refcount); /* one for USB */ /* ATM init */
udsl_get_instance(instance); /* one for ATM */ atm_dev = atm_dev_register(instance->driver_name, &usbatm_atm_devops, -1, NULL);
if (!atm_dev) {
usb_dbg(instance, "%s: failed to register ATM device!\n", __func__);
return -1;
}
init_MUTEX(&instance->serialize); instance->atm_dev = atm_dev;
instance->usb_dev = dev; atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
atm_dev->ci_range.vci_bits = ATM_CI_MAX;
atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
INIT_LIST_HEAD(&instance->vcc_list); /* temp init ATM device, set to 128kbit */
atm_dev->link_rate = 128 * 1000 / 424;
instance->status = UDSL_NO_FIRMWARE; if (instance->driver->atm_start && ((ret = instance->driver->atm_start(instance, atm_dev)) < 0)) {
init_waitqueue_head(&instance->firmware_waiters); atm_dbg(instance, "%s: atm_start failed: %d!\n", __func__, ret);
goto fail;
}
spin_lock_init(&instance->receive_lock); /* ready for ATM callbacks */
INIT_LIST_HEAD(&instance->spare_receivers); usbatm_get_instance(instance); /* dropped in usbatm_atm_dev_close */
INIT_LIST_HEAD(&instance->filled_receive_buffers); mb();
atm_dev->dev_data = instance;
tasklet_init(&instance->receive_tasklet, udsl_process_receive, (unsigned long)instance); /* submit all rx URBs */
INIT_LIST_HEAD(&instance->spare_receive_buffers); for (i = 0; i < num_rcv_urbs; i++)
usbatm_submit_urb(instance->urbs[i]);
skb_queue_head_init(&instance->sndqueue); return 0;
spin_lock_init(&instance->send_lock); fail:
INIT_LIST_HEAD(&instance->spare_senders); instance->atm_dev = NULL;
INIT_LIST_HEAD(&instance->spare_send_buffers); shutdown_atm_dev(atm_dev); /* usbatm_atm_dev_close will eventually be called */
return ret;
}
tasklet_init(&instance->send_tasklet, udsl_process_send,
(unsigned long)instance);
INIT_LIST_HEAD(&instance->filled_send_buffers);
/* receive init */ /**********
for (i = 0; i < num_rcv_urbs; i++) { ** USB **
struct udsl_receiver *rcv = &(instance->receivers[i]); **********/
if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { static int usbatm_do_heavy_init(void *arg)
dbg("udsl_usb_probe: no memory for receive urb %d!", i); {
goto fail; struct usbatm_data *instance = arg;
} int ret;
rcv->instance = instance; daemonize(instance->driver->driver_name);
allow_signal(SIGTERM);
list_add(&rcv->list, &instance->spare_receivers); complete(&instance->thread_started);
}
for (i = 0; i < num_rcv_bufs; i++) { ret = instance->driver->heavy_init(instance, instance->usb_intf);
struct udsl_receive_buffer *buf =
&(instance->receive_buffers[i]);
buf->base = kmalloc(rcv_buf_size * (ATM_CELL_SIZE + instance->rcv_padding), if (!ret)
GFP_KERNEL); ret = usbatm_atm_init(instance);
if (!buf->base) {
dbg("udsl_usb_probe: no memory for receive buffer %d!", i); down(&instance->serialize);
goto fail; instance->thread_pid = -1;
} up(&instance->serialize);
complete_and_exit(&instance->thread_exited, ret);
}
list_add(&buf->list, &instance->spare_receive_buffers); static int usbatm_heavy_init(struct usbatm_data *instance)
{
int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL);
if (ret < 0) {
usb_dbg(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
return ret;
} }
/* send init */ down(&instance->serialize);
for (i = 0; i < num_snd_urbs; i++) { instance->thread_pid = ret;
struct udsl_sender *snd = &(instance->senders[i]); up(&instance->serialize);
if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { wait_for_completion(&instance->thread_started);
dbg("udsl_usb_probe: no memory for send urb %d!", i);
goto fail;
}
snd->instance = instance; return 0;
}
list_add(&snd->list, &instance->spare_senders); static void usbatm_tasklet_schedule(unsigned long data)
} {
tasklet_schedule((struct tasklet_struct *) data);
}
for (i = 0; i < num_snd_bufs; i++) { static inline void usbatm_init_channel(struct usbatm_channel *channel)
struct udsl_send_buffer *buf = &(instance->send_buffers[i]); {
spin_lock_init(&channel->lock);
INIT_LIST_HEAD(&channel->list);
channel->delay.function = usbatm_tasklet_schedule;
channel->delay.data = (unsigned long) &channel->tasklet;
init_timer(&channel->delay);
}
buf->base = kmalloc(snd_buf_size * (ATM_CELL_SIZE + instance->snd_padding), int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
GFP_KERNEL); struct usbatm_driver *driver)
if (!buf->base) { {
dbg("udsl_usb_probe: no memory for send buffer %d!", i); struct device *dev = &intf->dev;
goto fail; struct usb_device *usb_dev = interface_to_usbdev(intf);
} struct usbatm_data *instance;
char *buf;
int error = -ENOMEM;
int i, length;
int need_heavy;
list_add(&buf->list, &instance->spare_send_buffers); dev_dbg(dev, "%s: trying driver %s with vendor=0x%x, product=0x%x, ifnum %d\n",
} __func__, driver->driver_name,
le16_to_cpu(usb_dev->descriptor.idVendor),
le16_to_cpu(usb_dev->descriptor.idProduct),
intf->altsetting->desc.bInterfaceNumber);
/* ATM init */ /* instance init */
instance->atm_dev = atm_dev_register(instance->driver_name, instance = kmalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs),
&udsl_atm_devops, -1, NULL); GFP_KERNEL);
if (!instance->atm_dev) { if (!instance) {
dbg("udsl_usb_probe: failed to register ATM device!"); dev_dbg(dev, "%s: no memory for instance data!\n", __func__);
goto fail; return -ENOMEM;
} }
instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX; memset(instance, 0, sizeof(*instance));
instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX;
instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
/* temp init ATM device, set to 128kbit */ /* public fields */
instance->atm_dev->link_rate = 128 * 1000 / 424;
instance->driver = driver;
snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name);
instance->usb_dev = usb_dev;
instance->usb_intf = intf;
/* device description */
buf = instance->description; buf = instance->description;
length = sizeof(instance->description); length = sizeof(instance->description);
if ((i = usb_string(dev, dev->descriptor.iProduct, buf, length)) < 0) if ((i = usb_string(usb_dev, usb_dev->descriptor.iProduct, buf, length)) < 0)
goto finish; goto bind;
buf += i; buf += i;
length -= i; length -= i;
...@@ -1039,126 +989,219 @@ int udsl_instance_setup(struct usb_device *dev, ...@@ -1039,126 +989,219 @@ int udsl_instance_setup(struct usb_device *dev,
buf += i; buf += i;
length -= i; length -= i;
if (length <= 0 || (i = usb_make_path(dev, buf, length)) < 0) if (length <= 0 || (i = usb_make_path(usb_dev, buf, length)) < 0)
goto finish; goto bind;
buf += i; buf += i;
length -= i; length -= i;
snprintf(buf, length, ")"); snprintf(buf, length, ")");
finish: bind:
/* ready for ATM callbacks */ need_heavy = 1;
wmb(); if (driver->bind && (error = driver->bind(instance, intf, id, &need_heavy)) < 0) {
instance->atm_dev->dev_data = instance; dev_dbg(dev, "%s: bind failed: %d!\n", __func__, error);
goto fail_free;
}
usb_get_dev(dev); /* private fields */
return 0; kref_init(&instance->refcount); /* dropped in usbatm_usb_disconnect */
init_MUTEX(&instance->serialize);
fail: instance->thread_pid = -1;
for (i = 0; i < num_snd_bufs; i++) init_completion(&instance->thread_started);
kfree(instance->send_buffers[i].base); init_completion(&instance->thread_exited);
for (i = 0; i < num_snd_urbs; i++) INIT_LIST_HEAD(&instance->vcc_list);
usb_free_urb(instance->senders[i].urb);
for (i = 0; i < num_rcv_bufs; i++) usbatm_init_channel(&instance->rx_channel);
kfree(instance->receive_buffers[i].base); usbatm_init_channel(&instance->tx_channel);
tasklet_init(&instance->rx_channel.tasklet, usbatm_rx_process, (unsigned long)instance);
tasklet_init(&instance->tx_channel.tasklet, usbatm_tx_process, (unsigned long)instance);
instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->in);
instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->out);
instance->rx_channel.stride = ATM_CELL_SIZE + driver->rx_padding;
instance->tx_channel.stride = ATM_CELL_SIZE + driver->tx_padding;
instance->rx_channel.buf_size = rcv_buf_size * instance->rx_channel.stride;
instance->tx_channel.buf_size = snd_buf_size * instance->tx_channel.stride;
instance->rx_channel.usbatm = instance->tx_channel.usbatm = instance;
for (i = 0; i < num_rcv_urbs; i++) skb_queue_head_init(&instance->sndqueue);
usb_free_urb(instance->receivers[i].urb);
for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
struct urb *urb;
u8 *buffer;
unsigned int iso_packets = 0, iso_size = 0;
struct usbatm_channel *channel = i < num_rcv_urbs ?
&instance->rx_channel : &instance->tx_channel;
if (usb_pipeisoc(channel->endpoint)) {
/* don't expect iso out endpoints */
iso_size = usb_maxpacket(instance->usb_dev, channel->endpoint, 0);
iso_size -= iso_size % channel->stride; /* alignment */
BUG_ON(!iso_size);
iso_packets = (channel->buf_size - 1) / iso_size + 1;
}
urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
if (!urb) {
dev_dbg(dev, "%s: no memory for urb %d!\n", __func__, i);
goto fail_unbind;
}
buffer = kmalloc(channel->buf_size, GFP_KERNEL);
if (!buffer) {
dev_dbg(dev, "%s: no memory for buffer %d!\n", __func__, i);
goto fail_unbind;
}
memset(buffer, 0, channel->buf_size);
usb_fill_bulk_urb(urb, instance->usb_dev, channel->endpoint,
buffer, channel->buf_size, usbatm_complete, channel);
if (iso_packets) {
int j;
urb->interval = 1;
urb->transfer_flags = URB_ISO_ASAP;
urb->number_of_packets = iso_packets;
for (j = 0; j < iso_packets; j++) {
urb->iso_frame_desc[j].offset = iso_size * j;
urb->iso_frame_desc[j].length = min_t(int, iso_size,
channel->buf_size - urb->iso_frame_desc[j].offset);
}
}
/* put all tx URBs on the list of spares */
if (i >= num_rcv_urbs)
list_add_tail(&urb->urb_list, &channel->list);
vdbg("%s: alloced buffer 0x%p buf size %u urb 0x%p",
__func__, urb->transfer_buffer, urb->transfer_buffer_length, urb);
instance->urbs[i] = urb;
}
if (need_heavy && driver->heavy_init) {
error = usbatm_heavy_init(instance);
} else {
complete(&instance->thread_exited); /* pretend that heavy_init was run */
error = usbatm_atm_init(instance);
}
return -ENOMEM; if (error < 0)
goto fail_unbind;
usb_get_dev(usb_dev);
usb_set_intfdata(intf, instance);
return 0;
fail_unbind:
if (instance->driver->unbind)
instance->driver->unbind(instance, intf);
fail_free:
for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
if (instance->urbs[i])
kfree(instance->urbs[i]->transfer_buffer);
usb_free_urb(instance->urbs[i]);
}
kfree (instance);
return error;
} }
EXPORT_SYMBOL_GPL(usbatm_usb_probe);
void udsl_instance_disconnect(struct udsl_instance_data *instance) void usbatm_usb_disconnect(struct usb_interface *intf)
{ {
struct device *dev = &intf->dev;
struct usbatm_data *instance = usb_get_intfdata(intf);
int i; int i;
dbg("udsl_instance_disconnect entered"); dev_dbg(dev, "%s entered\n", __func__);
if (!instance) { if (!instance) {
dbg("udsl_instance_disconnect: NULL instance!"); dev_dbg(dev, "%s: NULL instance!\n", __func__);
return; return;
} }
/* receive finalize */ usb_set_intfdata(intf, NULL);
tasklet_disable(&instance->receive_tasklet);
for (i = 0; i < num_rcv_urbs; i++) down(&instance->serialize);
usb_kill_urb(instance->receivers[i].urb); if (instance->thread_pid >= 0)
kill_proc(instance->thread_pid, SIGTERM, 1);
up(&instance->serialize);
/* no need to take the spinlock */ wait_for_completion(&instance->thread_exited);
INIT_LIST_HEAD(&instance->filled_receive_buffers);
INIT_LIST_HEAD(&instance->spare_receive_buffers);
tasklet_enable(&instance->receive_tasklet); tasklet_disable(&instance->rx_channel.tasklet);
tasklet_disable(&instance->tx_channel.tasklet);
for (i = 0; i < num_rcv_urbs; i++) for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++)
usb_free_urb(instance->receivers[i].urb); usb_kill_urb(instance->urbs[i]);
for (i = 0; i < num_rcv_bufs; i++) del_timer_sync(&instance->rx_channel.delay);
kfree(instance->receive_buffers[i].base); del_timer_sync(&instance->tx_channel.delay);
/* send finalize */ if (instance->atm_dev && instance->driver->atm_stop)
tasklet_disable(&instance->send_tasklet); instance->driver->atm_stop(instance, instance->atm_dev);
for (i = 0; i < num_snd_urbs; i++) if (instance->driver->unbind)
usb_kill_urb(instance->senders[i].urb); instance->driver->unbind(instance, intf);
/* no need to take the spinlock */ instance->driver_data = NULL;
INIT_LIST_HEAD(&instance->spare_senders);
INIT_LIST_HEAD(&instance->spare_send_buffers);
instance->current_buffer = NULL;
tasklet_enable(&instance->send_tasklet); /* turn usbatm_[rt]x_process into noop */
/* no need to take the spinlock */
INIT_LIST_HEAD(&instance->rx_channel.list);
INIT_LIST_HEAD(&instance->tx_channel.list);
for (i = 0; i < num_snd_urbs; i++) tasklet_enable(&instance->rx_channel.tasklet);
usb_free_urb(instance->senders[i].urb); tasklet_enable(&instance->tx_channel.tasklet);
for (i = 0; i < num_snd_bufs; i++) for (i = 0; i < num_rcv_urbs + num_snd_urbs; i++) {
kfree(instance->send_buffers[i].base); kfree(instance->urbs[i]->transfer_buffer);
usb_free_urb(instance->urbs[i]);
}
/* ATM finalize */ /* ATM finalize */
shutdown_atm_dev(instance->atm_dev); if (instance->atm_dev)
shutdown_atm_dev(instance->atm_dev);
usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
} }
EXPORT_SYMBOL_GPL(usbatm_usb_disconnect);
EXPORT_SYMBOL_GPL(udsl_get_instance);
EXPORT_SYMBOL_GPL(udsl_put_instance);
EXPORT_SYMBOL_GPL(udsl_instance_setup);
EXPORT_SYMBOL_GPL(udsl_instance_disconnect);
/*********** /***********
** init ** ** init **
***********/ ***********/
static int __init udsl_usb_init(void) static int __init usbatm_usb_init(void)
{ {
dbg("udsl_usb_init: driver version " DRIVER_VERSION); dbg("%s: driver version %s", __func__, DRIVER_VERSION);
if (sizeof(struct udsl_control) > sizeof(((struct sk_buff *) 0)->cb)) { if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) {
printk(KERN_ERR __FILE__ ": unusable with this kernel!\n"); printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name);
return -EIO; return -EIO;
} }
if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) if ((num_rcv_urbs > UDSL_MAX_RCV_URBS)
|| (num_snd_urbs > UDSL_MAX_SND_URBS) || (num_snd_urbs > UDSL_MAX_SND_URBS)
|| (num_rcv_bufs > UDSL_MAX_RCV_BUFS) || (rcv_buf_size < 1)
|| (num_snd_bufs > UDSL_MAX_SND_BUFS)
|| (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) || (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE)
|| (snd_buf_size < 1)
|| (snd_buf_size > UDSL_MAX_SND_BUF_SIZE)) || (snd_buf_size > UDSL_MAX_SND_BUF_SIZE))
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
module_init(usbatm_usb_init);
static void __exit udsl_usb_exit(void) static void __exit usbatm_usb_exit(void)
{ {
dbg("%s", __func__);
} }
module_exit(usbatm_usb_exit);
module_init(udsl_usb_init);
module_exit(udsl_usb_exit);
MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC); MODULE_DESCRIPTION(DRIVER_DESC);
...@@ -1170,7 +1213,7 @@ MODULE_VERSION(DRIVER_VERSION); ...@@ -1170,7 +1213,7 @@ MODULE_VERSION(DRIVER_VERSION);
************/ ************/
#ifdef VERBOSE_DEBUG #ifdef VERBOSE_DEBUG
static int udsl_print_packet(const unsigned char *data, int len) static int usbatm_print_packet(const unsigned char *data, int len)
{ {
unsigned char buffer[256]; unsigned char buffer[256];
int i = 0, j = 0; int i = 0, j = 0;
......
/****************************************************************************** /******************************************************************************
* usb_atm.h - Generic USB xDSL driver core * usbatm.h - Generic USB xDSL driver core
* *
* Copyright (C) 2001, Alcatel * Copyright (C) 2001, Alcatel
* Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
...@@ -21,12 +21,10 @@ ...@@ -21,12 +21,10 @@
* *
******************************************************************************/ ******************************************************************************/
#ifndef _USBATM_H_
#define _USBATM_H_
#include <linux/config.h> #include <linux/config.h>
#include <linux/list.h>
#include <linux/kref.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
#include <asm/semaphore.h>
/* /*
#define DEBUG #define DEBUG
...@@ -37,140 +35,149 @@ ...@@ -37,140 +35,149 @@
# define DEBUG # define DEBUG
#endif #endif
#include <asm/semaphore.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
#include <linux/completion.h>
#include <linux/device.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/stringify.h>
#include <linux/usb.h> #include <linux/usb.h>
#ifdef DEBUG #ifdef DEBUG
#define UDSL_ASSERT(x) BUG_ON(!(x)) #define UDSL_ASSERT(x) BUG_ON(!(x))
#else #else
#define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '" #x "' at line %d", __LINE__); } while(0) #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
#endif #endif
#define UDSL_MAX_RCV_URBS 4 #define usb_err(instance, format, arg...) \
#define UDSL_MAX_SND_URBS 4 dev_err(&(instance)->usb_intf->dev , format , ## arg)
#define UDSL_MAX_RCV_BUFS 8 #define usb_info(instance, format, arg...) \
#define UDSL_MAX_SND_BUFS 8 dev_info(&(instance)->usb_intf->dev , format , ## arg)
#define UDSL_MAX_RCV_BUF_SIZE 1024 /* ATM cells */ #define usb_warn(instance, format, arg...) \
#define UDSL_MAX_SND_BUF_SIZE 1024 /* ATM cells */ dev_warn(&(instance)->usb_intf->dev , format , ## arg)
#define UDSL_DEFAULT_RCV_URBS 2 #define usb_dbg(instance, format, arg...) \
#define UDSL_DEFAULT_SND_URBS 2 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
#define UDSL_DEFAULT_RCV_BUFS 4
#define UDSL_DEFAULT_SND_BUFS 4 /* FIXME: move to dev_* once ATM is driver model aware */
#define UDSL_DEFAULT_RCV_BUF_SIZE 64 /* ATM cells */ #define atm_printk(level, instance, format, arg...) \
#define UDSL_DEFAULT_SND_BUF_SIZE 64 /* ATM cells */ printk(level "ATM dev %d: " format , (instance)->atm_dev->number, ## arg)
#define ATM_CELL_HEADER (ATM_CELL_SIZE - ATM_CELL_PAYLOAD) #define atm_err(instance, format, arg...) \
#define UDSL_NUM_CELLS(x) (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 1) / ATM_CELL_PAYLOAD) atm_printk(KERN_ERR, instance , format , ## arg)
#define atm_info(instance, format, arg...) \
/* receive */ atm_printk(KERN_INFO, instance , format , ## arg)
#define atm_warn(instance, format, arg...) \
struct udsl_receive_buffer { atm_printk(KERN_WARNING, instance , format , ## arg)
struct list_head list; #ifdef DEBUG
unsigned char *base; #define atm_dbg(instance, format, arg...) \
unsigned int filled_cells; atm_printk(KERN_DEBUG, instance , format , ## arg)
}; #else
#define atm_dbg(instance, format, arg...) \
do {} while (0)
#endif
struct udsl_receiver {
struct list_head list;
struct udsl_receive_buffer *buffer;
struct urb *urb;
struct udsl_instance_data *instance;
};
struct udsl_vcc_data { /* mini driver */
/* vpi/vci lookup */
struct list_head list;
short vpi;
int vci;
struct atm_vcc *vcc;
/* raw cell reassembly */ struct usbatm_data;
struct sk_buff *sarb;
};
/* send */ /*
* Assuming all methods exist and succeed, they are called in this order:
*
* bind, heavy_init, atm_start, ..., atm_stop, unbind
*/
struct udsl_send_buffer { struct usbatm_driver {
struct list_head list; struct module *owner;
unsigned char *base;
unsigned char *free_start;
unsigned int free_cells;
};
struct udsl_sender { const char *driver_name;
struct list_head list;
struct udsl_send_buffer *buffer; /*
struct urb *urb; * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init
struct udsl_instance_data *instance; * method can avoid having it called by setting need_heavy_init to zero.
}; */
int (*bind) (struct usbatm_data *, struct usb_interface *,
const struct usb_device_id *id, int *need_heavy_init);
/* additional device initialization that is too slow to be done in probe() */
int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
/* cleanup device ... can sleep, but can't fail */
void (*unbind) (struct usbatm_data *, struct usb_interface *);
struct udsl_control { /* init ATM device ... can sleep, or cause ATM initialization failure */
struct atm_skb_data atm_data; int (*atm_start) (struct usbatm_data *, struct atm_dev *);
unsigned int num_cells;
unsigned int num_entire; /* cleanup ATM device ... can sleep, but can't fail */
unsigned int pdu_padding; void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
unsigned char aal5_trailer[ATM_AAL5_TRAILER];
int in; /* rx endpoint */
int out; /* tx endpoint */
unsigned rx_padding;
unsigned tx_padding;
}; };
#define UDSL_SKB(x) ((struct udsl_control *)(x)->cb) extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
struct usbatm_driver *driver);
extern void usbatm_usb_disconnect(struct usb_interface *intf);
/* main driver data */
enum udsl_status { struct usbatm_channel {
UDSL_NO_FIRMWARE, int endpoint; /* usb pipe */
UDSL_LOADING_FIRMWARE, unsigned int stride; /* ATM cell size + padding */
UDSL_LOADED_FIRMWARE unsigned int buf_size; /* urb buffer size */
spinlock_t lock;
struct list_head list;
struct tasklet_struct tasklet;
struct timer_list delay;
struct usbatm_data *usbatm;
}; };
struct udsl_instance_data { /* main driver data */
struct kref refcount;
struct semaphore serialize; struct usbatm_data {
/******************
* public fields *
******************/
/* USB device part */ /* mini driver */
struct usbatm_driver *driver;
void *driver_data;
char driver_name[16];
/* USB device */
struct usb_device *usb_dev; struct usb_device *usb_dev;
struct usb_interface *usb_intf;
char description[64]; char description[64];
int data_endpoint;
int snd_padding;
int rcv_padding;
const char *driver_name;
/* ATM device part */ /* ATM device */
struct atm_dev *atm_dev; struct atm_dev *atm_dev;
struct list_head vcc_list;
/* firmware */ /********************************
int (*firmware_wait) (struct udsl_instance_data *); * private fields - do not use *
enum udsl_status status; ********************************/
wait_queue_head_t firmware_waiters;
/* receive */ struct kref refcount;
struct udsl_receiver receivers[UDSL_MAX_RCV_URBS]; struct semaphore serialize;
struct udsl_receive_buffer receive_buffers[UDSL_MAX_RCV_BUFS];
spinlock_t receive_lock; /* heavy init */
struct list_head spare_receivers; int thread_pid;
struct list_head filled_receive_buffers; struct completion thread_started;
struct completion thread_exited;
struct tasklet_struct receive_tasklet; /* ATM device */
struct list_head spare_receive_buffers; struct list_head vcc_list;
/* send */ struct usbatm_channel rx_channel;
struct udsl_sender senders[UDSL_MAX_SND_URBS]; struct usbatm_channel tx_channel;
struct udsl_send_buffer send_buffers[UDSL_MAX_SND_BUFS];
struct sk_buff_head sndqueue; struct sk_buff_head sndqueue;
spinlock_t send_lock;
struct list_head spare_senders;
struct list_head spare_send_buffers;
struct tasklet_struct send_tasklet;
struct sk_buff *current_skb; /* being emptied */ struct sk_buff *current_skb; /* being emptied */
struct udsl_send_buffer *current_buffer; /* being filled */
struct list_head filled_send_buffers; struct urb *urbs[0];
}; };
extern int udsl_instance_setup(struct usb_device *dev, #endif /* _USBATM_H_ */
struct udsl_instance_data *instance);
extern void udsl_instance_disconnect(struct udsl_instance_data *instance);
extern void udsl_get_instance(struct udsl_instance_data *instance);
extern void udsl_put_instance(struct udsl_instance_data *instance);
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