2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* AVM BlueFRITZ! USB driver
|
|
|
|
*
|
2006-07-06 21:45:23 +08:00
|
|
|
* Copyright (C) 2003-2006 Marcel Holtmann <marcel@holtmann.org>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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 Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
#include <net/bluetooth/hci_core.h>
|
|
|
|
|
|
|
|
#ifndef CONFIG_BT_HCIBFUSB_DEBUG
|
|
|
|
#undef BT_DBG
|
|
|
|
#define BT_DBG(D...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VERSION "1.1"
|
|
|
|
|
|
|
|
static int ignore = 0;
|
|
|
|
|
|
|
|
static struct usb_driver bfusb_driver;
|
|
|
|
|
|
|
|
static struct usb_device_id bfusb_table[] = {
|
|
|
|
/* AVM BlueFRITZ! USB */
|
|
|
|
{ USB_DEVICE(0x057c, 0x2200) },
|
|
|
|
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, bfusb_table);
|
|
|
|
|
|
|
|
#define BFUSB_MAX_BLOCK_SIZE 256
|
|
|
|
|
|
|
|
#define BFUSB_BLOCK_TIMEOUT 3000
|
|
|
|
|
|
|
|
#define BFUSB_TX_PROCESS 1
|
|
|
|
#define BFUSB_TX_WAKEUP 2
|
|
|
|
|
|
|
|
#define BFUSB_MAX_BULK_TX 2
|
|
|
|
#define BFUSB_MAX_BULK_RX 2
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct hci_dev *hdev;
|
|
|
|
|
|
|
|
unsigned long state;
|
|
|
|
|
|
|
|
struct usb_device *udev;
|
|
|
|
|
|
|
|
unsigned int bulk_in_ep;
|
|
|
|
unsigned int bulk_out_ep;
|
|
|
|
unsigned int bulk_pkt_size;
|
|
|
|
|
|
|
|
rwlock_t lock;
|
|
|
|
|
|
|
|
struct sk_buff_head transmit_q;
|
|
|
|
|
|
|
|
struct sk_buff *reassembly;
|
|
|
|
|
|
|
|
atomic_t pending_tx;
|
|
|
|
struct sk_buff_head pending_q;
|
|
|
|
struct sk_buff_head completed_q;
|
|
|
|
};
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data_scb {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct urb *urb;
|
|
|
|
};
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void bfusb_tx_complete(struct urb *urb);
|
|
|
|
static void bfusb_rx_complete(struct urb *urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static struct urb *bfusb_get_completed(struct bfusb_data *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct urb *urb = NULL;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p", data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb = skb_dequeue(&data->completed_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (skb) {
|
2006-07-06 21:45:23 +08:00
|
|
|
urb = ((struct bfusb_data_scb *) skb->cb)->urb;
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return urb;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static void bfusb_unlink_urbs(struct bfusb_data *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct urb *urb;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p", data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
while ((skb = skb_dequeue(&data->pending_q))) {
|
|
|
|
urb = ((struct bfusb_data_scb *) skb->cb)->urb;
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_kill_urb(urb);
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_tail(&data->completed_q, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
while ((urb = bfusb_get_completed(data)))
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data_scb *scb = (void *) skb->cb;
|
|
|
|
struct urb *urb = bfusb_get_completed(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
int err, pipe;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, skb->len,
|
2005-04-17 06:20:36 +08:00
|
|
|
bfusb_tx_complete, skb);
|
|
|
|
|
|
|
|
scb->urb = urb;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_tail(&data->pending_q, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("%s bulk tx submit failed urb %p err %d",
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->name, urb, err);
|
|
|
|
skb_unlink(skb, &data->pending_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_free_urb(urb);
|
|
|
|
} else
|
2006-07-06 21:45:23 +08:00
|
|
|
atomic_inc(&data->pending_tx);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static void bfusb_tx_wakeup(struct bfusb_data *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p", data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (test_and_set_bit(BFUSB_TX_PROCESS, &data->state)) {
|
|
|
|
set_bit(BFUSB_TX_WAKEUP, &data->state);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2006-07-06 21:45:23 +08:00
|
|
|
clear_bit(BFUSB_TX_WAKEUP, &data->state);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
while ((atomic_read(&data->pending_tx) < BFUSB_MAX_BULK_TX) &&
|
|
|
|
(skb = skb_dequeue(&data->transmit_q))) {
|
|
|
|
if (bfusb_send_bulk(data, skb) < 0) {
|
|
|
|
skb_queue_head(&data->transmit_q, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
} while (test_bit(BFUSB_TX_WAKEUP, &data->state));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
clear_bit(BFUSB_TX_PROCESS, &data->state);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void bfusb_tx_complete(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb = (struct sk_buff *) urb->context;
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = (struct bfusb_data *) skb->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p urb %p skb %p len %d", data, urb, skb, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
atomic_dec(&data->pending_tx);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (!test_bit(HCI_RUNNING, &data->hdev->flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!urb->status)
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->stat.byte_tx += skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->stat.err_tx++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_lock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_unlink(skb, &data->pending_q);
|
|
|
|
skb_queue_tail(&data->completed_q, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
bfusb_tx_wakeup(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_unlock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data_scb *scb;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
int err, pipe, size = HCI_MAX_FRAME_SIZE + 32;
|
|
|
|
|
|
|
|
BT_DBG("bfusb %p urb %p", bfusb, urb);
|
|
|
|
|
|
|
|
if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb = bt_skb_alloc(size, GFP_ATOMIC);
|
|
|
|
if (!skb) {
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_free_urb(urb);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb->dev = (void *) data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
scb = (struct bfusb_data_scb *) skb->cb;
|
2005-04-17 06:20:36 +08:00
|
|
|
scb->urb = urb;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_rcvbulkpipe(data->udev, data->bulk_in_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, size,
|
2005-04-17 06:20:36 +08:00
|
|
|
bfusb_rx_complete, skb);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_tail(&data->pending_q, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("%s bulk rx submit failed urb %p err %d",
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->name, urb, err);
|
|
|
|
skb_unlink(skb, &data->pending_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned char *buf, int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p hdr 0x%02x data %p len %d", data, hdr, buf, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (hdr & 0x10) {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s error in block", data->hdev->name);
|
|
|
|
if (data->reassembly)
|
|
|
|
kfree_skb(data->reassembly);
|
|
|
|
data->reassembly = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr & 0x04) {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned char pkt_type;
|
|
|
|
int pkt_len = 0;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (data->reassembly) {
|
|
|
|
BT_ERR("%s unexpected start block", data->hdev->name);
|
|
|
|
kfree_skb(data->reassembly);
|
|
|
|
data->reassembly = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (len < 1) {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s no packet type found", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pkt_type = *buf++; len--;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (pkt_type) {
|
|
|
|
case HCI_EVENT_PKT:
|
|
|
|
if (len >= HCI_EVENT_HDR_SIZE) {
|
2006-07-06 21:45:23 +08:00
|
|
|
struct hci_event_hdr *hdr = (struct hci_event_hdr *) buf;
|
2005-04-17 06:20:36 +08:00
|
|
|
pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen;
|
|
|
|
} else {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s event block is too short", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HCI_ACLDATA_PKT:
|
|
|
|
if (len >= HCI_ACL_HDR_SIZE) {
|
2006-07-06 21:45:23 +08:00
|
|
|
struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) buf;
|
2005-04-17 06:20:36 +08:00
|
|
|
pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen);
|
|
|
|
} else {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s data block is too short", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HCI_SCODATA_PKT:
|
|
|
|
if (len >= HCI_SCO_HDR_SIZE) {
|
2006-07-06 21:45:23 +08:00
|
|
|
struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) buf;
|
2005-04-17 06:20:36 +08:00
|
|
|
pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen;
|
|
|
|
} else {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s audio block is too short", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb = bt_skb_alloc(pkt_len, GFP_ATOMIC);
|
|
|
|
if (!skb) {
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_ERR("%s no memory for the packet", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb->dev = (void *) data->hdev;
|
2005-08-10 11:30:28 +08:00
|
|
|
bt_cb(skb)->pkt_type = pkt_type;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->reassembly = skb;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2006-07-06 21:45:23 +08:00
|
|
|
if (!data->reassembly) {
|
|
|
|
BT_ERR("%s unexpected continuation block", data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0)
|
2006-07-06 21:45:23 +08:00
|
|
|
memcpy(skb_put(data->reassembly, len), buf, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (hdr & 0x08) {
|
2006-07-06 21:45:23 +08:00
|
|
|
hci_recv_frame(data->reassembly);
|
|
|
|
data->reassembly = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static void bfusb_rx_complete(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb = (struct sk_buff *) urb->context;
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = (struct bfusb_data *) skb->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char *buf = urb->transfer_buffer;
|
|
|
|
int count = urb->actual_length;
|
|
|
|
int err, hdr, len;
|
|
|
|
|
|
|
|
BT_DBG("bfusb %p urb %p skb %p len %d", bfusb, urb, skb, skb->len);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_lock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (!test_bit(HCI_RUNNING, &data->hdev->flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
if (urb->status || !count)
|
|
|
|
goto resubmit;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->stat.byte_rx += count;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
skb_put(skb, count);
|
|
|
|
|
|
|
|
while (count) {
|
|
|
|
hdr = buf[0] | (buf[1] << 8);
|
|
|
|
|
|
|
|
if (hdr & 0x4000) {
|
|
|
|
len = 0;
|
|
|
|
count -= 2;
|
|
|
|
buf += 2;
|
|
|
|
} else {
|
|
|
|
len = (buf[2] == 0) ? 256 : buf[2];
|
|
|
|
count -= 3;
|
|
|
|
buf += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < len) {
|
|
|
|
BT_ERR("%s block extends over URB buffer ranges",
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((hdr & 0xe1) == 0xc1)
|
2006-07-06 21:45:23 +08:00
|
|
|
bfusb_recv_block(data, hdr, buf, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
count -= len;
|
|
|
|
buf += len;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_unlink(skb, &data->pending_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree_skb(skb);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
bfusb_rx_submit(data, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_unlock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
resubmit:
|
2006-07-06 21:45:23 +08:00
|
|
|
urb->dev = data->udev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (err) {
|
|
|
|
BT_ERR("%s bulk resubmit failed urb %p err %d",
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev->name, urb, err);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unlock:
|
2006-07-06 21:45:23 +08:00
|
|
|
read_unlock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_open(struct hci_dev *hdev)
|
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = hdev->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int i, err;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("hdev %p bfusb %p", hdev, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
|
|
|
|
return 0;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
write_lock_irqsave(&data->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
err = bfusb_rx_submit(data, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!err) {
|
|
|
|
for (i = 1; i < BFUSB_MAX_BULK_RX; i++)
|
2006-07-06 21:45:23 +08:00
|
|
|
bfusb_rx_submit(data, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
clear_bit(HCI_RUNNING, &hdev->flags);
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
write_unlock_irqrestore(&data->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_flush(struct hci_dev *hdev)
|
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = hdev->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("hdev %p bfusb %p", hdev, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_purge(&data->transmit_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_close(struct hci_dev *hdev)
|
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = hdev->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("hdev %p bfusb %p", hdev, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
|
|
|
|
return 0;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
write_lock_irqsave(&data->lock, flags);
|
|
|
|
write_unlock_irqrestore(&data->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
bfusb_unlink_urbs(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
bfusb_flush(hdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_send_frame(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = (struct hci_dev *) skb->dev;
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sk_buff *nskb;
|
|
|
|
unsigned char buf[3];
|
|
|
|
int sent = 0, size, count;
|
|
|
|
|
2005-08-10 11:30:28 +08:00
|
|
|
BT_DBG("hdev %p skb %p type %d len %d", hdev, skb, bt_cb(skb)->pkt_type, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!hdev) {
|
|
|
|
BT_ERR("Frame for unknown HCI device (hdev=NULL)");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!test_bit(HCI_RUNNING, &hdev->flags))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data = hdev->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-10 11:30:28 +08:00
|
|
|
switch (bt_cb(skb)->pkt_type) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case HCI_COMMAND_PKT:
|
|
|
|
hdev->stat.cmd_tx++;
|
|
|
|
break;
|
|
|
|
case HCI_ACLDATA_PKT:
|
|
|
|
hdev->stat.acl_tx++;
|
|
|
|
break;
|
|
|
|
case HCI_SCODATA_PKT:
|
|
|
|
hdev->stat.sco_tx++;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Prepend skb with frame type */
|
2005-08-10 11:30:28 +08:00
|
|
|
memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
count = skb->len;
|
|
|
|
|
|
|
|
/* Max HCI frame size seems to be 1511 + 1 */
|
2006-07-06 21:45:23 +08:00
|
|
|
nskb = bt_skb_alloc(count + 32, GFP_ATOMIC);
|
|
|
|
if (!nskb) {
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Can't allocate memory for new packet");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
nskb->dev = (void *) data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (count) {
|
|
|
|
size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE);
|
|
|
|
|
|
|
|
buf[0] = 0xc1 | ((sent == 0) ? 0x04 : 0) | ((count == size) ? 0x08 : 0);
|
|
|
|
buf[1] = 0x00;
|
|
|
|
buf[2] = (size == BFUSB_MAX_BLOCK_SIZE) ? 0 : size;
|
|
|
|
|
|
|
|
memcpy(skb_put(nskb, 3), buf, 3);
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data_offset(skb, sent, skb_put(nskb, size), size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sent += size;
|
|
|
|
count -= size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't send frame with multiple size of bulk max packet */
|
2006-07-06 21:45:23 +08:00
|
|
|
if ((nskb->len % data->bulk_pkt_size) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
buf[0] = 0xdd;
|
|
|
|
buf[1] = 0x00;
|
|
|
|
memcpy(skb_put(nskb, 2), buf, 2);
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_lock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_tail(&data->transmit_q, nskb);
|
|
|
|
bfusb_tx_wakeup(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
read_unlock(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfusb_destruct(struct hci_dev *hdev)
|
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = hdev->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("hdev %p bfusb %p", hdev, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
kfree(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
static int bfusb_load_firmware(struct bfusb_data *data, unsigned char *firmware, int count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char *buf;
|
|
|
|
int err, pipe, len, size, sent = 0;
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
BT_DBG("bfusb %p udev %p", data, data->udev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
BT_INFO("BlueFRITZ! USB loading firmware");
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_sndctrlpipe(data->udev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
|
2005-04-17 06:20:36 +08:00
|
|
|
0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
|
|
|
|
BT_ERR("Can't change to loading configuration");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->udev->toggle[0] = data->udev->toggle[1] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_ATOMIC);
|
|
|
|
if (!buf) {
|
|
|
|
BT_ERR("Can't allocate memory chunk for firmware");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while (count) {
|
|
|
|
size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3);
|
|
|
|
|
|
|
|
memcpy(buf, firmware + sent, size);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
err = usb_bulk_msg(data->udev, pipe, buf, size,
|
2005-04-17 06:20:36 +08:00
|
|
|
&len, BFUSB_BLOCK_TIMEOUT);
|
|
|
|
|
|
|
|
if (err || (len != size)) {
|
|
|
|
BT_ERR("Error in firmware loading");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
sent += size;
|
|
|
|
count -= size;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
err = usb_bulk_msg(data->udev, pipe, NULL, 0,
|
|
|
|
&len, BFUSB_BLOCK_TIMEOUT);
|
|
|
|
if (err < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Error in null packet request");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_sndctrlpipe(data->udev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
err = usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
|
|
|
|
0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
|
|
if (err < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Can't change to running configuration");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->udev->toggle[0] = data->udev->toggle[1] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
BT_INFO("BlueFRITZ! USB device ready");
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree(buf);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
pipe = usb_sndctrlpipe(data->udev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
|
2005-04-17 06:20:36 +08:00
|
|
|
0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
const struct firmware *firmware;
|
|
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
struct usb_host_endpoint *bulk_out_ep;
|
|
|
|
struct usb_host_endpoint *bulk_in_ep;
|
|
|
|
struct hci_dev *hdev;
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
BT_DBG("intf %p id %p", intf, id);
|
|
|
|
|
|
|
|
if (ignore)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Check number of endpoints */
|
|
|
|
if (intf->cur_altsetting->desc.bNumEndpoints < 2)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
bulk_out_ep = &intf->cur_altsetting->endpoint[0];
|
|
|
|
bulk_in_ep = &intf->cur_altsetting->endpoint[1];
|
|
|
|
|
|
|
|
if (!bulk_out_ep || !bulk_in_ep) {
|
|
|
|
BT_ERR("Bulk endpoints not found");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize control structure and load firmware */
|
2006-07-06 21:45:23 +08:00
|
|
|
data = kzalloc(sizeof(struct bfusb_data), GFP_KERNEL);
|
|
|
|
if (!data) {
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Can't allocate memory for control structure");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->udev = udev;
|
|
|
|
data->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress;
|
|
|
|
data->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress;
|
|
|
|
data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
rwlock_init(&data->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->reassembly = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
skb_queue_head_init(&data->transmit_q);
|
|
|
|
skb_queue_head_init(&data->pending_q);
|
|
|
|
skb_queue_head_init(&data->completed_q);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) {
|
|
|
|
BT_ERR("Firmware request failed");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_DBG("firmware data %p size %d", firmware->data, firmware->size);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
if (bfusb_load_firmware(data, firmware->data, firmware->size) < 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Firmware loading failed");
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
|
|
|
release_firmware(firmware);
|
|
|
|
|
|
|
|
/* Initialize and register HCI device */
|
|
|
|
hdev = hci_alloc_dev();
|
|
|
|
if (!hdev) {
|
|
|
|
BT_ERR("Can't allocate HCI device");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
data->hdev = hdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
hdev->type = HCI_USB;
|
2006-07-06 21:45:23 +08:00
|
|
|
hdev->driver_data = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
SET_HCIDEV_DEV(hdev, &intf->dev);
|
|
|
|
|
|
|
|
hdev->open = bfusb_open;
|
|
|
|
hdev->close = bfusb_close;
|
|
|
|
hdev->flush = bfusb_flush;
|
|
|
|
hdev->send = bfusb_send_frame;
|
|
|
|
hdev->destruct = bfusb_destruct;
|
|
|
|
hdev->ioctl = bfusb_ioctl;
|
|
|
|
|
|
|
|
hdev->owner = THIS_MODULE;
|
|
|
|
|
|
|
|
if (hci_register_dev(hdev) < 0) {
|
|
|
|
BT_ERR("Can't register HCI device");
|
|
|
|
hci_free_dev(hdev);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
usb_set_intfdata(intf, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
release:
|
|
|
|
release_firmware(firmware);
|
|
|
|
|
|
|
|
error:
|
2006-07-06 21:45:23 +08:00
|
|
|
kfree(data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfusb_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
2006-07-06 21:45:23 +08:00
|
|
|
struct bfusb_data *data = usb_get_intfdata(intf);
|
|
|
|
struct hci_dev *hdev = data->hdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
BT_DBG("intf %p", intf);
|
|
|
|
|
|
|
|
if (!hdev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
|
|
|
|
bfusb_close(hdev);
|
|
|
|
|
|
|
|
if (hci_unregister_dev(hdev) < 0)
|
|
|
|
BT_ERR("Can't unregister HCI device %s", hdev->name);
|
|
|
|
|
|
|
|
hci_free_dev(hdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver bfusb_driver = {
|
|
|
|
.name = "bfusb",
|
|
|
|
.probe = bfusb_probe,
|
|
|
|
.disconnect = bfusb_disconnect,
|
|
|
|
.id_table = bfusb_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init bfusb_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BT_INFO("BlueFRITZ! USB driver ver %s", VERSION);
|
|
|
|
|
2006-07-06 21:45:23 +08:00
|
|
|
err = usb_register(&bfusb_driver);
|
|
|
|
if (err < 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
BT_ERR("Failed to register BlueFRITZ! USB driver");
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit bfusb_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&bfusb_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(bfusb_init);
|
|
|
|
module_exit(bfusb_exit);
|
|
|
|
|
|
|
|
module_param(ignore, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(ignore, "Ignore devices from the matching table");
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
|
|
|
|
MODULE_DESCRIPTION("BlueFRITZ! USB driver ver " VERSION);
|
|
|
|
MODULE_VERSION(VERSION);
|
|
|
|
MODULE_LICENSE("GPL");
|
2007-02-18 06:59:02 +08:00
|
|
|
MODULE_FIRMWARE("bfubase.frm");
|