Bluetooth: btusb: Separate TX URB allocation and submission
The complete TX URB handling is done via a switch statement in the btusb_send_frame function. To allow for more clear separation between control, bulk and isoc URBs, split them into allocation and submission. Previously the inc_tx function has been used for tracking in-flight URB for HCI commands and ACL data packets. Convert that into a common function that either submits the URB or queues it when needed. This provides the flexibility to allow vendor specific hdev->send_frame callbacks without having to duplicate the whole URB handling logic. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Родитель
e9753eff1b
Коммит
047b2ec8d3
|
@ -296,20 +296,6 @@ struct btusb_data {
|
||||||
int suspend_count;
|
int suspend_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int inc_tx(struct btusb_data *data)
|
|
||||||
{
|
|
||||||
unsigned long flags;
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&data->txlock, flags);
|
|
||||||
rv = test_bit(BTUSB_SUSPENDING, &data->flags);
|
|
||||||
if (!rv)
|
|
||||||
data->tx_in_flight++;
|
|
||||||
spin_unlock_irqrestore(&data->txlock, flags);
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void btusb_intr_complete(struct urb *urb)
|
static void btusb_intr_complete(struct urb *urb)
|
||||||
{
|
{
|
||||||
struct hci_dev *hdev = urb->context;
|
struct hci_dev *hdev = urb->context;
|
||||||
|
@ -752,100 +738,96 @@ static int btusb_flush(struct hci_dev *hdev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
|
static struct urb *alloc_ctrl_urb(struct hci_dev *hdev, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct btusb_data *data = hci_get_drvdata(hdev);
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
struct usb_ctrlrequest *dr;
|
struct usb_ctrlrequest *dr;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
unsigned int pipe;
|
unsigned int pipe;
|
||||||
int err;
|
|
||||||
|
|
||||||
BT_DBG("%s", hdev->name);
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
if (!urb)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
if (!test_bit(HCI_RUNNING, &hdev->flags))
|
dr = kmalloc(sizeof(*dr), GFP_KERNEL);
|
||||||
return -EBUSY;
|
if (!dr) {
|
||||||
|
usb_free_urb(urb);
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
dr->bRequestType = data->cmdreq_type;
|
||||||
|
dr->bRequest = 0;
|
||||||
|
dr->wIndex = 0;
|
||||||
|
dr->wValue = 0;
|
||||||
|
dr->wLength = __cpu_to_le16(skb->len);
|
||||||
|
|
||||||
|
pipe = usb_sndctrlpipe(data->udev, 0x00);
|
||||||
|
|
||||||
|
usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
|
||||||
|
skb->data, skb->len, btusb_tx_complete, skb);
|
||||||
|
|
||||||
skb->dev = (void *) hdev;
|
skb->dev = (void *) hdev;
|
||||||
|
|
||||||
switch (bt_cb(skb)->pkt_type) {
|
return urb;
|
||||||
case HCI_COMMAND_PKT:
|
}
|
||||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
||||||
if (!urb)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
dr = kmalloc(sizeof(*dr), GFP_KERNEL);
|
static struct urb *alloc_bulk_urb(struct hci_dev *hdev, struct sk_buff *skb)
|
||||||
if (!dr) {
|
{
|
||||||
usb_free_urb(urb);
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
return -ENOMEM;
|
struct urb *urb;
|
||||||
}
|
unsigned int pipe;
|
||||||
|
|
||||||
dr->bRequestType = data->cmdreq_type;
|
if (!data->bulk_tx_ep)
|
||||||
dr->bRequest = 0;
|
return ERR_PTR(-ENODEV);
|
||||||
dr->wIndex = 0;
|
|
||||||
dr->wValue = 0;
|
|
||||||
dr->wLength = __cpu_to_le16(skb->len);
|
|
||||||
|
|
||||||
pipe = usb_sndctrlpipe(data->udev, 0x00);
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
if (!urb)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
|
pipe = usb_sndbulkpipe(data->udev, data->bulk_tx_ep->bEndpointAddress);
|
||||||
skb->data, skb->len, btusb_tx_complete, skb);
|
|
||||||
|
|
||||||
hdev->stat.cmd_tx++;
|
usb_fill_bulk_urb(urb, data->udev, pipe,
|
||||||
break;
|
skb->data, skb->len, btusb_tx_complete, skb);
|
||||||
|
|
||||||
case HCI_ACLDATA_PKT:
|
skb->dev = (void *) hdev;
|
||||||
if (!data->bulk_tx_ep)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
return urb;
|
||||||
if (!urb)
|
}
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
pipe = usb_sndbulkpipe(data->udev,
|
static struct urb *alloc_isoc_urb(struct hci_dev *hdev, struct sk_buff *skb)
|
||||||
data->bulk_tx_ep->bEndpointAddress);
|
{
|
||||||
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
|
struct urb *urb;
|
||||||
|
unsigned int pipe;
|
||||||
|
|
||||||
usb_fill_bulk_urb(urb, data->udev, pipe,
|
if (!data->isoc_tx_ep)
|
||||||
skb->data, skb->len, btusb_tx_complete, skb);
|
return ERR_PTR(-ENODEV);
|
||||||
|
|
||||||
hdev->stat.acl_tx++;
|
urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
|
||||||
break;
|
if (!urb)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
case HCI_SCODATA_PKT:
|
pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
|
||||||
if (!data->isoc_tx_ep || hci_conn_num(hdev, SCO_LINK) < 1)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
|
usb_fill_int_urb(urb, data->udev, pipe,
|
||||||
if (!urb)
|
skb->data, skb->len, btusb_isoc_tx_complete,
|
||||||
return -ENOMEM;
|
skb, data->isoc_tx_ep->bInterval);
|
||||||
|
|
||||||
pipe = usb_sndisocpipe(data->udev,
|
urb->transfer_flags = URB_ISO_ASAP;
|
||||||
data->isoc_tx_ep->bEndpointAddress);
|
|
||||||
|
|
||||||
usb_fill_int_urb(urb, data->udev, pipe,
|
__fill_isoc_descriptor(urb, skb->len,
|
||||||
skb->data, skb->len, btusb_isoc_tx_complete,
|
le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
|
||||||
skb, data->isoc_tx_ep->bInterval);
|
|
||||||
|
|
||||||
urb->transfer_flags = URB_ISO_ASAP;
|
skb->dev = (void *) hdev;
|
||||||
|
|
||||||
__fill_isoc_descriptor(urb, skb->len,
|
return urb;
|
||||||
le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
|
}
|
||||||
|
|
||||||
hdev->stat.sco_tx++;
|
static int submit_tx_urb(struct hci_dev *hdev, struct urb *urb)
|
||||||
goto skip_waking;
|
{
|
||||||
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
|
int err;
|
||||||
|
|
||||||
default:
|
|
||||||
return -EILSEQ;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = inc_tx(data);
|
|
||||||
if (err) {
|
|
||||||
usb_anchor_urb(urb, &data->deferred);
|
|
||||||
schedule_work(&data->waker);
|
|
||||||
err = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
skip_waking:
|
|
||||||
usb_anchor_urb(urb, &data->tx_anchor);
|
usb_anchor_urb(urb, &data->tx_anchor);
|
||||||
|
|
||||||
err = usb_submit_urb(urb, GFP_KERNEL);
|
err = usb_submit_urb(urb, GFP_KERNEL);
|
||||||
|
@ -859,11 +841,73 @@ skip_waking:
|
||||||
usb_mark_last_busy(data->udev);
|
usb_mark_last_busy(data->udev);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
usb_free_urb(urb);
|
usb_free_urb(urb);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int submit_or_queue_tx_urb(struct hci_dev *hdev, struct urb *urb)
|
||||||
|
{
|
||||||
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
|
unsigned long flags;
|
||||||
|
bool suspending;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&data->txlock, flags);
|
||||||
|
suspending = test_bit(BTUSB_SUSPENDING, &data->flags);
|
||||||
|
if (!suspending)
|
||||||
|
data->tx_in_flight++;
|
||||||
|
spin_unlock_irqrestore(&data->txlock, flags);
|
||||||
|
|
||||||
|
if (!suspending)
|
||||||
|
return submit_tx_urb(hdev, urb);
|
||||||
|
|
||||||
|
usb_anchor_urb(urb, &data->deferred);
|
||||||
|
schedule_work(&data->waker);
|
||||||
|
|
||||||
|
usb_free_urb(urb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int btusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
|
||||||
|
{
|
||||||
|
struct urb *urb;
|
||||||
|
|
||||||
|
BT_DBG("%s", hdev->name);
|
||||||
|
|
||||||
|
if (!test_bit(HCI_RUNNING, &hdev->flags))
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
|
switch (bt_cb(skb)->pkt_type) {
|
||||||
|
case HCI_COMMAND_PKT:
|
||||||
|
urb = alloc_ctrl_urb(hdev, skb);
|
||||||
|
if (IS_ERR(urb))
|
||||||
|
return PTR_ERR(urb);
|
||||||
|
|
||||||
|
hdev->stat.cmd_tx++;
|
||||||
|
return submit_or_queue_tx_urb(hdev, urb);
|
||||||
|
|
||||||
|
case HCI_ACLDATA_PKT:
|
||||||
|
urb = alloc_bulk_urb(hdev, skb);
|
||||||
|
if (IS_ERR(urb))
|
||||||
|
return PTR_ERR(urb);
|
||||||
|
|
||||||
|
hdev->stat.acl_tx++;
|
||||||
|
return submit_or_queue_tx_urb(hdev, urb);
|
||||||
|
|
||||||
|
case HCI_SCODATA_PKT:
|
||||||
|
if (hci_conn_num(hdev, SCO_LINK) < 1)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
urb = alloc_isoc_urb(hdev, skb);
|
||||||
|
if (IS_ERR(urb))
|
||||||
|
return PTR_ERR(urb);
|
||||||
|
|
||||||
|
hdev->stat.sco_tx++;
|
||||||
|
return submit_tx_urb(hdev, urb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return -EILSEQ;
|
||||||
|
}
|
||||||
|
|
||||||
static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
|
static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
|
||||||
{
|
{
|
||||||
struct btusb_data *data = hci_get_drvdata(hdev);
|
struct btusb_data *data = hci_get_drvdata(hdev);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче