2006-08-09 13:35:12 -06:00
|
|
|
/*
|
|
|
|
* AIRcable USB Bluetooth Dongle Driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com)
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License version 2 as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* The device works as an standard CDC device, it has 2 interfaces, the first
|
|
|
|
* one is for firmware access and the second is the serial one.
|
|
|
|
* The protocol is very simply, there are two posibilities reading or writing.
|
2007-05-08 23:14:03 -06:00
|
|
|
* When writing the first urb must have a Header that starts with 0x20 0x29 the
|
2006-08-09 13:35:12 -06:00
|
|
|
* next two bytes must say how much data will be sended.
|
|
|
|
* When reading the process is almost equal except that the header starts with
|
|
|
|
* 0x00 0x20.
|
|
|
|
*
|
|
|
|
* The device simply need some stuff to understand data comming from the usb
|
|
|
|
* buffer: The First and Second byte is used for a Header, the Third and Fourth
|
|
|
|
* tells the device the amount of information the package holds.
|
|
|
|
* Packages are 60 bytes long Header Stuff.
|
2007-05-08 23:14:03 -06:00
|
|
|
* When writing to the device the first two bytes of the header are 0x20 0x29
|
2006-08-09 13:35:12 -06:00
|
|
|
* When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange
|
|
|
|
* situation, when too much data arrives to the device because it sends the data
|
|
|
|
* but with out the header. I will use a simply hack to override this situation,
|
|
|
|
* if there is data coming that does not contain any header, then that is data
|
|
|
|
* that must go directly to the tty, as there is no documentation about if there
|
|
|
|
* is any other control code, I will simply check for the first
|
|
|
|
* one.
|
|
|
|
*
|
|
|
|
* The driver registers himself with the USB-serial core and the USB Core. I had
|
|
|
|
* to implement a probe function agains USB-serial, because other way, the
|
|
|
|
* driver was attaching himself to both interfaces. I have tryed with different
|
|
|
|
* configurations of usb_serial_driver with out exit, only the probe function
|
|
|
|
* could handle this correctly.
|
|
|
|
*
|
|
|
|
* I have taken some info from a Greg Kroah-Hartman article:
|
|
|
|
* http://www.linuxjournal.com/article/6573
|
|
|
|
* And from Linux Device Driver Kit CD, which is a great work, the authors taken
|
|
|
|
* the work to recompile lots of information an knowladge in drivers development
|
|
|
|
* and made it all avaible inside a cd.
|
|
|
|
* URL: http://kernel.org/pub/linux/kernel/people/gregkh/ddk/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/tty.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2006-08-09 13:35:12 -06:00
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/serial.h>
|
|
|
|
|
|
|
|
static int debug;
|
|
|
|
|
|
|
|
/* Vendor and Product ID */
|
|
|
|
#define AIRCABLE_VID 0x16CA
|
|
|
|
#define AIRCABLE_USB_PID 0x1502
|
|
|
|
|
|
|
|
/* write buffer size defines */
|
|
|
|
#define AIRCABLE_BUF_SIZE 2048
|
|
|
|
|
|
|
|
/* Protocol Stuff */
|
|
|
|
#define HCI_HEADER_LENGTH 0x4
|
|
|
|
#define TX_HEADER_0 0x20
|
|
|
|
#define TX_HEADER_1 0x29
|
|
|
|
#define RX_HEADER_0 0x00
|
|
|
|
#define RX_HEADER_1 0x20
|
|
|
|
#define MAX_HCI_FRAMESIZE 60
|
|
|
|
#define HCI_COMPLETE_FRAME 64
|
|
|
|
|
|
|
|
/* rx_flags */
|
|
|
|
#define THROTTLED 0x01
|
|
|
|
#define ACTUALLY_THROTTLED 0x02
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION "v1.0b2"
|
|
|
|
#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>"
|
|
|
|
#define DRIVER_DESC "AIRcable USB Driver"
|
|
|
|
|
|
|
|
/* ID table that will be registered with USB core */
|
2010-01-10 07:34:24 -07:00
|
|
|
static const struct usb_device_id id_table[] = {
|
2006-08-09 13:35:12 -06:00
|
|
|
{ USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
|
|
|
|
|
|
|
|
|
|
|
/* Internal Structure */
|
|
|
|
struct aircable_private {
|
|
|
|
spinlock_t rx_lock; /* spinlock for the receive lines */
|
|
|
|
struct circ_buf *tx_buf; /* write buffer */
|
|
|
|
struct circ_buf *rx_buf; /* read buffer */
|
|
|
|
int rx_flags; /* for throttilng */
|
|
|
|
struct work_struct rx_work; /* work cue for the receiving line */
|
2006-11-22 07:57:56 -07:00
|
|
|
struct usb_serial_port *port; /* USB port with which associated */
|
2006-08-09 13:35:12 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Private methods */
|
|
|
|
|
|
|
|
/* Circular Buffer Methods, code from ti_usb_3410_5052 used */
|
|
|
|
/*
|
|
|
|
* serial_buf_clear
|
|
|
|
*
|
|
|
|
* Clear out all data in the circular buffer.
|
|
|
|
*/
|
|
|
|
static void serial_buf_clear(struct circ_buf *cb)
|
|
|
|
{
|
|
|
|
cb->head = cb->tail = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serial_buf_alloc
|
|
|
|
*
|
|
|
|
* Allocate a circular buffer and all associated memory.
|
|
|
|
*/
|
|
|
|
static struct circ_buf *serial_buf_alloc(void)
|
|
|
|
{
|
|
|
|
struct circ_buf *cb;
|
|
|
|
cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL);
|
|
|
|
if (cb == NULL)
|
|
|
|
return NULL;
|
|
|
|
cb->buf = kmalloc(AIRCABLE_BUF_SIZE, GFP_KERNEL);
|
|
|
|
if (cb->buf == NULL) {
|
|
|
|
kfree(cb);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
serial_buf_clear(cb);
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serial_buf_free
|
|
|
|
*
|
|
|
|
* Free the buffer and all associated memory.
|
|
|
|
*/
|
|
|
|
static void serial_buf_free(struct circ_buf *cb)
|
|
|
|
{
|
|
|
|
kfree(cb->buf);
|
|
|
|
kfree(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serial_buf_data_avail
|
|
|
|
*
|
|
|
|
* Return the number of bytes of data available in the circular
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
static int serial_buf_data_avail(struct circ_buf *cb)
|
|
|
|
{
|
2008-04-29 07:35:39 -06:00
|
|
|
return CIRC_CNT(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serial_buf_put
|
|
|
|
*
|
|
|
|
* Copy data data from a user buffer and put it into the circular buffer.
|
|
|
|
* Restrict to the amount of space available.
|
|
|
|
*
|
|
|
|
* Return the number of bytes copied.
|
|
|
|
*/
|
|
|
|
static int serial_buf_put(struct circ_buf *cb, const char *buf, int count)
|
|
|
|
{
|
|
|
|
int c, ret = 0;
|
|
|
|
while (1) {
|
|
|
|
c = CIRC_SPACE_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
|
|
|
|
if (count < c)
|
|
|
|
c = count;
|
|
|
|
if (c <= 0)
|
|
|
|
break;
|
|
|
|
memcpy(cb->buf + cb->head, buf, c);
|
|
|
|
cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1);
|
|
|
|
buf += c;
|
|
|
|
count -= c;
|
2008-04-29 07:35:39 -06:00
|
|
|
ret = c;
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serial_buf_get
|
|
|
|
*
|
|
|
|
* Get data from the circular buffer and copy to the given buffer.
|
|
|
|
* Restrict to the amount of data available.
|
|
|
|
*
|
|
|
|
* Return the number of bytes copied.
|
|
|
|
*/
|
|
|
|
static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
|
|
|
|
{
|
|
|
|
int c, ret = 0;
|
|
|
|
while (1) {
|
|
|
|
c = CIRC_CNT_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
|
|
|
|
if (count < c)
|
|
|
|
c = count;
|
|
|
|
if (c <= 0)
|
|
|
|
break;
|
|
|
|
memcpy(buf, cb->buf + cb->tail, c);
|
|
|
|
cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
|
|
|
|
buf += c;
|
|
|
|
count -= c;
|
2008-04-29 07:35:39 -06:00
|
|
|
ret = c;
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of circula buffer methods */
|
|
|
|
|
|
|
|
static void aircable_send(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
int count, result;
|
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
2008-04-29 07:35:39 -06:00
|
|
|
unsigned char *buf;
|
2008-04-28 00:00:16 -06:00
|
|
|
__le16 *dbuf;
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2006-08-09 13:35:12 -06:00
|
|
|
if (port->write_urb_busy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
count = min(serial_buf_data_avail(priv->tx_buf), MAX_HCI_FRAMESIZE);
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC);
|
|
|
|
if (!buf) {
|
2008-08-20 17:56:34 -06:00
|
|
|
dev_err(&port->dev, "%s- kzalloc(%d) failed.\n",
|
|
|
|
__func__, count + HCI_HEADER_LENGTH);
|
2006-08-09 13:35:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = TX_HEADER_0;
|
|
|
|
buf[1] = TX_HEADER_1;
|
2008-04-28 00:00:16 -06:00
|
|
|
dbuf = (__le16 *)&buf[2];
|
2007-03-26 08:55:16 -06:00
|
|
|
*dbuf = cpu_to_le16((u16)count);
|
2008-04-29 07:35:39 -06:00
|
|
|
serial_buf_get(priv->tx_buf, buf + HCI_HEADER_LENGTH,
|
|
|
|
MAX_HCI_FRAMESIZE);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
memcpy(port->write_urb->transfer_buffer, buf,
|
|
|
|
count + HCI_HEADER_LENGTH);
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
port->write_urb_busy = 1;
|
2008-03-03 17:08:34 -07:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__,
|
2006-08-09 13:35:12 -06:00
|
|
|
count + HCI_HEADER_LENGTH,
|
|
|
|
port->write_urb->transfer_buffer);
|
|
|
|
port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH;
|
|
|
|
port->write_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed submitting write urb, error %d\n",
|
2008-03-03 17:08:34 -07:00
|
|
|
__func__, result);
|
2006-08-09 13:35:12 -06:00
|
|
|
port->write_urb_busy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule_work(&port->work);
|
|
|
|
}
|
|
|
|
|
2006-11-22 07:57:56 -07:00
|
|
|
static void aircable_read(struct work_struct *work)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
2006-11-22 07:57:56 -07:00
|
|
|
struct aircable_private *priv =
|
|
|
|
container_of(work, struct aircable_private, rx_work);
|
|
|
|
struct usb_serial_port *port = priv->port;
|
2006-08-09 13:35:12 -06:00
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned char *data;
|
|
|
|
int count;
|
2008-04-29 07:35:39 -06:00
|
|
|
if (priv->rx_flags & THROTTLED) {
|
2006-08-09 13:35:12 -06:00
|
|
|
if (priv->rx_flags & ACTUALLY_THROTTLED)
|
|
|
|
schedule_work(&priv->rx_work);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By now I will flush data to the tty in packages of no more than
|
|
|
|
* 64 bytes, to ensure I do not get throttled.
|
|
|
|
* Ask USB mailing list for better aproach.
|
|
|
|
*/
|
2008-10-13 03:39:46 -06:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2006-11-15 11:14:27 -07:00
|
|
|
if (!tty) {
|
2006-08-09 13:35:12 -06:00
|
|
|
schedule_work(&priv->rx_work);
|
2008-08-20 17:56:34 -06:00
|
|
|
dev_err(&port->dev, "%s - No tty available\n", __func__);
|
2006-11-15 11:14:27 -07:00
|
|
|
return ;
|
|
|
|
}
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
count = min(64, serial_buf_data_avail(priv->rx_buf));
|
|
|
|
|
|
|
|
if (count <= 0)
|
2008-10-13 03:39:46 -06:00
|
|
|
goto out; /* We have finished sending everything. */
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
tty_prepare_flip_string(tty, &data, count);
|
2008-04-29 07:35:39 -06:00
|
|
|
if (!data) {
|
2008-10-13 03:39:46 -06:00
|
|
|
dev_err(&port->dev, "%s- kzalloc(%d) failed.",
|
|
|
|
__func__, count);
|
|
|
|
goto out;
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
serial_buf_get(priv->rx_buf, data, count);
|
|
|
|
|
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
|
|
|
|
if (serial_buf_data_avail(priv->rx_buf))
|
|
|
|
schedule_work(&priv->rx_work);
|
2008-10-13 03:39:46 -06:00
|
|
|
out:
|
|
|
|
tty_kref_put(tty);
|
2006-08-09 13:35:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* End of private methods */
|
|
|
|
|
|
|
|
static int aircable_probe(struct usb_serial *serial,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
2008-04-29 07:35:39 -06:00
|
|
|
struct usb_host_interface *iface_desc = serial->interface->
|
|
|
|
cur_altsetting;
|
2006-08-09 13:35:12 -06:00
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
2008-04-29 07:35:39 -06:00
|
|
|
int num_bulk_out = 0;
|
2006-08-09 13:35:12 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
|
|
|
|
endpoint = &iface_desc->endpoint[i].desc;
|
2006-10-26 10:02:45 -06:00
|
|
|
if (usb_endpoint_is_bulk_out(endpoint)) {
|
2006-08-09 13:35:12 -06:00
|
|
|
dbg("found bulk out on endpoint %d", i);
|
|
|
|
++num_bulk_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_bulk_out == 0) {
|
|
|
|
dbg("Invalid interface, discarding");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-29 07:35:39 -06:00
|
|
|
static int aircable_attach(struct usb_serial *serial)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = serial->port[0];
|
|
|
|
struct aircable_private *priv;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
|
2008-04-29 07:35:39 -06:00
|
|
|
if (!priv) {
|
2008-08-20 17:56:34 -06:00
|
|
|
dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
|
2006-08-09 13:35:12 -06:00
|
|
|
sizeof(struct aircable_private));
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocation of Circular Buffers */
|
|
|
|
priv->tx_buf = serial_buf_alloc();
|
|
|
|
if (priv->tx_buf == NULL) {
|
|
|
|
kfree(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->rx_buf = serial_buf_alloc();
|
|
|
|
if (priv->rx_buf == NULL) {
|
|
|
|
kfree(priv->tx_buf);
|
|
|
|
kfree(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
|
2006-11-22 07:57:56 -07:00
|
|
|
priv->port = port;
|
|
|
|
INIT_WORK(&priv->rx_work, aircable_read);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
usb_set_serial_port_data(serial->port[0], priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-02 09:53:55 -06:00
|
|
|
static void aircable_release(struct usb_serial *serial)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
struct usb_serial_port *port = serial->port[0];
|
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s", __func__);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
if (priv) {
|
|
|
|
serial_buf_free(priv->tx_buf);
|
|
|
|
serial_buf_free(priv->rx_buf);
|
|
|
|
kfree(priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-22 04:09:07 -06:00
|
|
|
static int aircable_write_room(struct tty_struct *tty)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
2008-07-22 04:09:07 -06:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2006-08-09 13:35:12 -06:00
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
return serial_buf_data_avail(priv->tx_buf);
|
|
|
|
}
|
|
|
|
|
2008-07-22 04:09:07 -06:00
|
|
|
static int aircable_write(struct tty_struct *tty, struct usb_serial_port *port,
|
2006-08-09 13:35:12 -06:00
|
|
|
const unsigned char *source, int count)
|
|
|
|
{
|
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int temp;
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - port %d, %d bytes", __func__, port->number, count);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__, count, source);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2008-04-29 07:35:39 -06:00
|
|
|
if (!count) {
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - write request of 0 bytes", __func__);
|
2006-08-09 13:35:12 -06:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = serial_buf_put(priv->tx_buf, source, count);
|
|
|
|
|
|
|
|
aircable_send(port);
|
|
|
|
|
|
|
|
if (count > AIRCABLE_BUF_SIZE)
|
|
|
|
count = AIRCABLE_BUF_SIZE;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static void aircable_write_bulk_callback(struct urb *urb)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
2007-06-15 16:44:13 -06:00
|
|
|
int status = urb->status;
|
2006-08-09 13:35:12 -06:00
|
|
|
int result;
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - urb status: %d", __func__ , status);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
/* This has been taken from cypress_m8.c cypress_write_int_callback */
|
2007-06-15 16:44:13 -06:00
|
|
|
switch (status) {
|
2008-04-29 07:35:39 -06:00
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
|
|
|
dbg("%s - urb shutting down with status: %d",
|
|
|
|
__func__, status);
|
|
|
|
port->write_urb_busy = 0;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
/* error in the urb, so we have to resubmit it */
|
|
|
|
dbg("%s - Overflow in write", __func__);
|
|
|
|
dbg("%s - nonzero write bulk status received: %d",
|
|
|
|
__func__, status);
|
|
|
|
port->write_urb->transfer_buffer_length = 1;
|
|
|
|
port->write_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s - failed resubmitting write urb, error %d\n",
|
|
|
|
__func__, result);
|
|
|
|
else
|
2006-08-09 13:35:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
port->write_urb_busy = 0;
|
|
|
|
|
|
|
|
aircable_send(port);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static void aircable_read_bulk_callback(struct urb *urb)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = urb->context;
|
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned long no_packages, remaining, package_length, i;
|
|
|
|
int result, shift = 0;
|
|
|
|
unsigned char *temp;
|
2007-06-15 16:44:13 -06:00
|
|
|
int status = urb->status;
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2007-06-15 16:44:13 -06:00
|
|
|
if (status) {
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - urb status = %d", __func__, status);
|
2007-06-15 16:44:13 -06:00
|
|
|
if (status == -EPROTO) {
|
2006-08-09 13:35:12 -06:00
|
|
|
dbg("%s - caught -EPROTO, resubmitting the urb",
|
2008-03-03 17:08:34 -07:00
|
|
|
__func__);
|
2006-08-09 13:35:12 -06:00
|
|
|
usb_fill_bulk_urb(port->read_urb, port->serial->dev,
|
2008-04-29 07:35:39 -06:00
|
|
|
usb_rcvbulkpipe(port->serial->dev,
|
|
|
|
port->bulk_in_endpointAddress),
|
|
|
|
port->read_urb->transfer_buffer,
|
|
|
|
port->read_urb->transfer_buffer_length,
|
|
|
|
aircable_read_bulk_callback, port);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s - failed resubmitting read urb, error %d\n",
|
2008-03-03 17:08:34 -07:00
|
|
|
__func__, result);
|
2006-08-09 13:35:12 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - unable to handle the error, exiting.", __func__);
|
2006-08-09 13:35:12 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__,
|
2008-04-29 07:35:39 -06:00
|
|
|
urb->actual_length, urb->transfer_buffer);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2008-10-13 03:39:46 -06:00
|
|
|
tty = tty_port_tty_get(&port->port);
|
2006-08-09 13:35:12 -06:00
|
|
|
if (tty && urb->actual_length) {
|
|
|
|
if (urb->actual_length <= 2) {
|
|
|
|
/* This is an incomplete package */
|
|
|
|
serial_buf_put(priv->rx_buf, urb->transfer_buffer,
|
|
|
|
urb->actual_length);
|
|
|
|
} else {
|
|
|
|
temp = urb->transfer_buffer;
|
|
|
|
if (temp[0] == RX_HEADER_0)
|
|
|
|
shift = HCI_HEADER_LENGTH;
|
|
|
|
|
|
|
|
remaining = urb->actual_length;
|
|
|
|
no_packages = urb->actual_length / (HCI_COMPLETE_FRAME);
|
|
|
|
|
|
|
|
if (urb->actual_length % HCI_COMPLETE_FRAME != 0)
|
2008-04-29 07:35:39 -06:00
|
|
|
no_packages++;
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2008-04-29 07:35:39 -06:00
|
|
|
for (i = 0; i < no_packages; i++) {
|
2006-08-09 13:35:12 -06:00
|
|
|
if (remaining > (HCI_COMPLETE_FRAME))
|
|
|
|
package_length = HCI_COMPLETE_FRAME;
|
|
|
|
else
|
|
|
|
package_length = remaining;
|
|
|
|
remaining -= package_length;
|
|
|
|
|
|
|
|
serial_buf_put(priv->rx_buf,
|
|
|
|
urb->transfer_buffer + shift +
|
|
|
|
(HCI_COMPLETE_FRAME) * (i),
|
|
|
|
package_length - shift);
|
|
|
|
}
|
|
|
|
}
|
2006-11-22 07:57:56 -07:00
|
|
|
aircable_read(&priv->rx_work);
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
2008-10-13 03:39:46 -06:00
|
|
|
tty_kref_put(tty);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2010-02-17 08:05:47 -07:00
|
|
|
/* Schedule the next read */
|
|
|
|
usb_fill_bulk_urb(port->read_urb, port->serial->dev,
|
|
|
|
usb_rcvbulkpipe(port->serial->dev,
|
|
|
|
port->bulk_in_endpointAddress),
|
|
|
|
port->read_urb->transfer_buffer,
|
|
|
|
port->read_urb->transfer_buffer_length,
|
|
|
|
aircable_read_bulk_callback, port);
|
|
|
|
|
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result && result != -EPERM)
|
|
|
|
dev_err(&urb->dev->dev,
|
|
|
|
"%s - failed resubmitting read urb, error %d\n",
|
|
|
|
__func__, result);
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Based on ftdi_sio.c throttle */
|
2008-07-22 04:09:07 -06:00
|
|
|
static void aircable_throttle(struct tty_struct *tty)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
2008-07-22 04:09:07 -06:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2006-08-09 13:35:12 -06:00
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2009-10-07 02:50:23 -06:00
|
|
|
spin_lock_irq(&priv->rx_lock);
|
2006-08-09 13:35:12 -06:00
|
|
|
priv->rx_flags |= THROTTLED;
|
2009-10-07 02:50:23 -06:00
|
|
|
spin_unlock_irq(&priv->rx_lock);
|
2006-08-09 13:35:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Based on ftdi_sio.c unthrottle */
|
2008-07-22 04:09:07 -06:00
|
|
|
static void aircable_unthrottle(struct tty_struct *tty)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
2008-07-22 04:09:07 -06:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2006-08-09 13:35:12 -06:00
|
|
|
struct aircable_private *priv = usb_get_serial_port_data(port);
|
|
|
|
int actually_throttled;
|
|
|
|
|
2008-03-03 17:08:34 -07:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
2009-10-07 02:50:23 -06:00
|
|
|
spin_lock_irq(&priv->rx_lock);
|
2006-08-09 13:35:12 -06:00
|
|
|
actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
|
|
|
|
priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
|
2009-10-07 02:50:23 -06:00
|
|
|
spin_unlock_irq(&priv->rx_lock);
|
2006-08-09 13:35:12 -06:00
|
|
|
|
|
|
|
if (actually_throttled)
|
|
|
|
schedule_work(&priv->rx_work);
|
|
|
|
}
|
|
|
|
|
2006-12-17 13:50:24 -07:00
|
|
|
static struct usb_driver aircable_driver = {
|
|
|
|
.name = "aircable",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table,
|
|
|
|
.no_dynamic_id = 1,
|
|
|
|
};
|
|
|
|
|
2006-08-09 13:35:12 -06:00
|
|
|
static struct usb_serial_driver aircable_device = {
|
2006-12-17 14:05:09 -07:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "aircable",
|
|
|
|
},
|
2006-12-17 13:50:24 -07:00
|
|
|
.usb_driver = &aircable_driver,
|
2006-08-09 13:35:12 -06:00
|
|
|
.id_table = id_table,
|
|
|
|
.num_ports = 1,
|
|
|
|
.attach = aircable_attach,
|
|
|
|
.probe = aircable_probe,
|
2009-06-02 09:53:55 -06:00
|
|
|
.release = aircable_release,
|
2006-08-09 13:35:12 -06:00
|
|
|
.write = aircable_write,
|
|
|
|
.write_room = aircable_write_room,
|
|
|
|
.write_bulk_callback = aircable_write_bulk_callback,
|
|
|
|
.read_bulk_callback = aircable_read_bulk_callback,
|
|
|
|
.throttle = aircable_throttle,
|
|
|
|
.unthrottle = aircable_unthrottle,
|
|
|
|
};
|
|
|
|
|
2008-04-29 07:35:39 -06:00
|
|
|
static int __init aircable_init(void)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
retval = usb_serial_register(&aircable_device);
|
|
|
|
if (retval)
|
|
|
|
goto failed_serial_register;
|
|
|
|
retval = usb_register(&aircable_driver);
|
|
|
|
if (retval)
|
|
|
|
goto failed_usb_register;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_usb_register:
|
2009-02-01 03:54:54 -07:00
|
|
|
usb_serial_deregister(&aircable_device);
|
|
|
|
failed_serial_register:
|
2006-08-09 13:35:12 -06:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-04-29 07:35:39 -06:00
|
|
|
static void __exit aircable_exit(void)
|
2006-08-09 13:35:12 -06:00
|
|
|
{
|
|
|
|
usb_deregister(&aircable_driver);
|
|
|
|
usb_serial_deregister(&aircable_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_VERSION(DRIVER_VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(aircable_init);
|
|
|
|
module_exit(aircable_exit);
|
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug enabled or not");
|