提交 80aae7a1 编写于 作者: D Duncan Sands 提交者: Greg Kroah-Hartman

[PATCH] USBATM: allow isochronous transfer

While the usbatm core has had some support for using isoc urbs
for some time, there was no way for users to turn it on.  While
use of isoc transfer should still be considered experimental, it
now works well enough to let users turn it on.  Minidrivers signal
to the core that they want to use isoc transfer by setting the new
UDSL_USE_ISOC flag.  The speedtch minidriver gets a new module
parameter enable_isoc (defaults to false), plus some logic that
checks for the existence of an isoc receive endpoint (not all
speedtouch modems have one).
Signed-off-by: NDuncan Sands <baldrick@free.fr>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 6f749475
......@@ -836,8 +836,8 @@ static struct usbatm_driver cxacru_driver = {
.heavy_init = cxacru_heavy_init,
.unbind = cxacru_unbind,
.atm_start = cxacru_atm_start,
.in = CXACRU_EP_DATA,
.out = CXACRU_EP_DATA,
.bulk_in = CXACRU_EP_DATA,
.bulk_out = CXACRU_EP_DATA,
.rx_padding = 3,
.tx_padding = 11,
};
......
......@@ -35,6 +35,8 @@
#include <linux/slab.h>
#include <linux/stat.h>
#include <linux/timer.h>
#include <linux/types.h>
#include <linux/usb_ch9.h>
#include <linux/workqueue.h>
#include "usbatm.h"
......@@ -66,24 +68,33 @@ static const char speedtch_driver_name[] = "speedtch";
#define RESUBMIT_DELAY 1000 /* milliseconds */
#define DEFAULT_ALTSETTING 1
#define DEFAULT_BULK_ALTSETTING 1
#define DEFAULT_ISOC_ALTSETTING 2
#define DEFAULT_DL_512_FIRST 0
#define DEFAULT_ENABLE_ISOC 0
#define DEFAULT_SW_BUFFERING 0
static int altsetting = DEFAULT_ALTSETTING;
static unsigned int altsetting = 0; /* zero means: use the default */
static int dl_512_first = DEFAULT_DL_512_FIRST;
static int enable_isoc = DEFAULT_ENABLE_ISOC;
static int sw_buffering = DEFAULT_SW_BUFFERING;
module_param(altsetting, int, S_IRUGO | S_IWUSR);
module_param(altsetting, uint, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(altsetting,
"Alternative setting for data interface (default: "
__MODULE_STRING(DEFAULT_ALTSETTING) ")");
"Alternative setting for data interface (bulk_default: "
__MODULE_STRING(DEFAULT_BULK_ALTSETTING) "; isoc_default: "
__MODULE_STRING(DEFAULT_ISOC_ALTSETTING) ")");
module_param(dl_512_first, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(dl_512_first,
"Read 512 bytes before sending firmware (default: "
__MODULE_STRING(DEFAULT_DL_512_FIRST) ")");
module_param(enable_isoc, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(enable_isoc,
"Use isochronous transfers if available (default: "
__MODULE_STRING(DEFAULT_ENABLE_ISOC) ")");
module_param(sw_buffering, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(sw_buffering,
"Enable software buffering (default: "
......@@ -91,7 +102,8 @@ MODULE_PARM_DESC(sw_buffering,
#define INTERFACE_DATA 1
#define ENDPOINT_INT 0x81
#define ENDPOINT_DATA 0x07
#define ENDPOINT_BULK_DATA 0x07
#define ENDPOINT_ISOC_DATA 0x07
#define ENDPOINT_FIRMWARE 0x05
#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
......@@ -687,11 +699,12 @@ static int speedtch_bind(struct usbatm_data *usbatm,
const struct usb_device_id *id)
{
struct usb_device *usb_dev = interface_to_usbdev(intf);
struct usb_interface *cur_intf;
struct usb_interface *cur_intf, *data_intf;
struct speedtch_instance_data *instance;
int ifnum = intf->altsetting->desc.bInterfaceNumber;
int num_interfaces = usb_dev->actconfig->desc.bNumInterfaces;
int i, ret;
int use_isoc;
usb_dbg(usbatm, "%s entered\n", __func__);
......@@ -702,6 +715,11 @@ static int speedtch_bind(struct usbatm_data *usbatm,
return -ENODEV;
}
if (!(data_intf = usb_ifnum_to_if(usb_dev, INTERFACE_DATA))) {
usb_err(usbatm, "%s: data interface not found!\n", __func__);
return -ENODEV;
}
/* claim all interfaces */
for (i=0; i < num_interfaces; i++) {
......@@ -728,8 +746,9 @@ static int speedtch_bind(struct usbatm_data *usbatm,
instance->usbatm = usbatm;
/* altsetting may change at any moment, so take a snapshot */
/* altsetting and enable_isoc may change at any moment, so take a snapshot */
instance->altsetting = altsetting;
use_isoc = enable_isoc;
if (instance->altsetting)
if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, instance->altsetting)) < 0) {
......@@ -737,14 +756,44 @@ static int speedtch_bind(struct usbatm_data *usbatm,
instance->altsetting = 0; /* fall back to default */
}
if (!instance->altsetting) {
if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ALTSETTING)) < 0) {
usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ALTSETTING, ret);
goto fail_free;
if (!instance->altsetting && use_isoc)
if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_ISOC_ALTSETTING)) < 0) {
usb_dbg(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_ISOC_ALTSETTING, ret);
use_isoc = 0; /* fall back to bulk */
}
instance->altsetting = DEFAULT_ALTSETTING;
if (use_isoc) {
const struct usb_host_interface *desc = data_intf->cur_altsetting;
const __u8 target_address = USB_DIR_IN | usbatm->driver->isoc_in;
int i;
use_isoc = 0; /* fall back to bulk if endpoint not found */
for (i=0; i<desc->desc.bNumEndpoints; i++) {
const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc;
if ((endpoint_desc->bEndpointAddress == target_address)) {
use_isoc = (endpoint_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
USB_ENDPOINT_XFER_ISOC;
break;
}
}
if (!use_isoc)
usb_info(usbatm, "isochronous transfer not supported - using bulk\n");
}
if (!use_isoc && !instance->altsetting)
if ((ret = usb_set_interface(usb_dev, INTERFACE_DATA, DEFAULT_BULK_ALTSETTING)) < 0) {
usb_err(usbatm, "%s: setting interface to %2d failed (%d)!\n", __func__, DEFAULT_BULK_ALTSETTING, ret);
goto fail_free;
}
if (!instance->altsetting)
instance->altsetting = use_isoc ? DEFAULT_ISOC_ALTSETTING : DEFAULT_BULK_ALTSETTING;
usbatm->flags |= (use_isoc ? UDSL_USE_ISOC : 0);
INIT_WORK(&instance->status_checker, (void *)speedtch_check_status, instance);
instance->status_checker.timer.function = speedtch_status_poll;
......@@ -771,7 +820,7 @@ static int speedtch_bind(struct usbatm_data *usbatm,
0x12, 0xc0, 0x07, 0x00,
instance->scratch_buffer + OFFSET_7, SIZE_7, 500);
usbatm->flags = (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0);
usbatm->flags |= (ret == SIZE_7 ? UDSL_SKIP_HEAVY_INIT : 0);
usb_dbg(usbatm, "%s: firmware %s loaded\n", __func__, usbatm->flags & UDSL_SKIP_HEAVY_INIT ? "already" : "not");
......@@ -817,8 +866,9 @@ static struct usbatm_driver speedtch_usbatm_driver = {
.unbind = speedtch_unbind,
.atm_start = speedtch_atm_start,
.atm_stop = speedtch_atm_stop,
.in = ENDPOINT_DATA,
.out = ENDPOINT_DATA
.bulk_in = ENDPOINT_BULK_DATA,
.bulk_out = ENDPOINT_BULK_DATA,
.isoc_in = ENDPOINT_ISOC_DATA
};
static int speedtch_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
......
......@@ -1705,8 +1705,8 @@ static struct usbatm_driver uea_usbatm_driver = {
.atm_start = uea_atm_open,
.unbind = uea_unbind,
.heavy_init = uea_heavy,
.in = UEA_BULK_DATA_PIPE,
.out = UEA_BULK_DATA_PIPE,
.bulk_in = UEA_BULK_DATA_PIPE,
.bulk_out = UEA_BULK_DATA_PIPE,
};
static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
......
......@@ -1049,17 +1049,23 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
init_completion(&instance->thread_exited);
INIT_LIST_HEAD(&instance->vcc_list);
skb_queue_head_init(&instance->sndqueue);
usbatm_init_channel(&instance->rx_channel);
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.usbatm = instance->tx_channel.usbatm = instance;
if ((instance->flags & UDSL_USE_ISOC) && driver->isoc_in)
instance->rx_channel.endpoint = usb_rcvisocpipe(usb_dev, driver->isoc_in);
else
instance->rx_channel.endpoint = usb_rcvbulkpipe(usb_dev, driver->bulk_in);
instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out);
/* tx buffer size must be a positive multiple of the stride */
instance->tx_channel.buf_size = max (instance->tx_channel.stride,
snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride));
......@@ -1080,6 +1086,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
num_packets--;
instance->rx_channel.buf_size = num_packets * maxpacket;
instance->rx_channel.packet_size = maxpacket;
#ifdef DEBUG
for (i = 0; i < 2; i++) {
......@@ -1090,22 +1097,16 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
}
#endif
skb_queue_head_init(&instance->sndqueue);
/* initialize urbs */
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;
struct urb *urb;
unsigned int iso_packets = usb_pipeisoc(channel->endpoint) ? channel->buf_size / channel->packet_size : 0;
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;
}
UDSL_ASSERT(!usb_pipeisoc(channel->endpoint) || usb_pipein(channel->endpoint));
urb = usb_alloc_urb(iso_packets, GFP_KERNEL);
if (!urb) {
......@@ -1132,9 +1133,8 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
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);
urb->iso_frame_desc[j].offset = channel->packet_size * j;
urb->iso_frame_desc[j].length = channel->packet_size;
}
}
......
......@@ -87,6 +87,7 @@
/* flags, set by mini-driver in bind() */
#define UDSL_SKIP_HEAVY_INIT (1<<0)
#define UDSL_USE_ISOC (1<<1)
/* mini driver */
......@@ -118,8 +119,9 @@ struct usbatm_driver {
/* cleanup ATM device ... can sleep, but can't fail */
void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
int in; /* rx endpoint */
int out; /* tx endpoint */
int bulk_in; /* bulk rx endpoint */
int isoc_in; /* isochronous rx endpoint */
int bulk_out; /* bulk tx endpoint */
unsigned rx_padding;
unsigned tx_padding;
......@@ -134,6 +136,7 @@ struct usbatm_channel {
int endpoint; /* usb pipe */
unsigned int stride; /* ATM cell size + padding */
unsigned int buf_size; /* urb buffer size */
unsigned int packet_size; /* endpoint maxpacket */
spinlock_t lock;
struct list_head list;
struct tasklet_struct tasklet;
......
......@@ -210,8 +210,8 @@ static int __init xusbatm_init(void)
xusbatm_drivers[i].bind = xusbatm_bind;
xusbatm_drivers[i].unbind = xusbatm_unbind;
xusbatm_drivers[i].atm_start = xusbatm_atm_start;
xusbatm_drivers[i].in = rx_endpoint[i];
xusbatm_drivers[i].out = tx_endpoint[i];
xusbatm_drivers[i].bulk_in = rx_endpoint[i];
xusbatm_drivers[i].bulk_out = tx_endpoint[i];
xusbatm_drivers[i].rx_padding = rx_padding[i];
xusbatm_drivers[i].tx_padding = tx_padding[i];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册