Bluetooth: Add HCI init setup stage
Subsystems (2)
v2 cover Bluetooth: Add HCI init setup stage
Hi,
This is a resend of Marcel's patches that were sent in November, rebased and fixed-up for bluetooth-next. They are a pre-requsite of some follow-up work I'm doing to have a simple way of doing synchronous single-command requests that will be needed by some HCI driver setup routines.
Johan
----------------------------------------------------------------
Marcel Holtmann (3):
Bluetooth: Add driver setup stage for early init
Bluetooth: Convert BCM92035 support to driver setup callback
Bluetooth: Remove driver init queue from core
drivers/bluetooth/btusb.c | 28 +++++++++++-------- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 56 ++++++++++++++------------------------ 3 files changed, 38 insertions(+), 49 deletions(-)
PATCH v2 1/3 Bluetooth: Add driver setup stage for early init
From: Marcel Holtmann <[email protected]>
Some drivers require a special stage for their early init. This is always specific to the driver or transport. So call back into driver to allow bringing up the device.
The advantage with this stage is that the Bluetooth core is actually handling the HCI layer now. This means that command and event processing is available.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -292,6 +292,7 @@ struct hci_dev {int (*open)(struct hci_dev *hdev);int (*close)(struct hci_dev *hdev);int (*flush)(struct hci_dev *hdev); +int (*setup)(struct hci_dev *hdev);int (*send)(struct sk_buff *skb);void (*notify)(struct hci_dev *hdev,unsigned int evt);int (*ioctl)(struct hci_dev *hdev,unsigned int cmd,unsigned long arg);
net/bluetooth/hci_core.c +20 -13
@@ -1012,26 +1012,33 @@ int hci_dev_open(__u16 dev) goto done; } -if (test_bit (HCI_QUIRK_RAW_DEVICE , &hdev->quirks)) -set_bit (HCI_RAW , &hdev->flags); - -/* Treat all non BR/EDR controllers as raw devices if -enable_hs is not set */ -if (hdev->dev_type !=HCI_BREDR && !enable_hs) -set_bit (HCI_RAW , &hdev->flags); -if (hdev->open (hdev)) { ret = -EIO ; goto done; } -if (!test_bit (HCI_RAW , &hdev->flags)) { -atomic_set (&hdev->cmd_cnt,1 ); -set_bit (HCI_INIT , &hdev->flags); - ret =__hci_init (hdev); -clear_bit (HCI_INIT , &hdev->flags); +atomic_set (&hdev->cmd_cnt,1 ); +set_bit (HCI_INIT , &hdev->flags); + +if (hdev->setup &&test_bit (HCI_SETUP , &hdev->dev_flags)) + ret = hdev->setup (hdev); + +if (!ret) { +/* Treat all non BR/EDR controllers as raw devices if +* enable_hs is not set. +*/ +if (hdev->dev_type !=HCI_BREDR && !enable_hs) +set_bit (HCI_RAW , &hdev->flags); + +if (test_bit (HCI_QUIRK_RAW_DEVICE , &hdev->quirks)) +set_bit (HCI_RAW , &hdev->flags); + +if (!test_bit (HCI_RAW , &hdev->flags)) + ret =__hci_init (hdev); } +clear_bit (HCI_INIT , &hdev->flags); +if (!ret) {hci_dev_hold (hdev);set_bit (HCI_UP , &hdev->flags);
Signature · 1 line
1.7.10.4
PATCH v2 2/3 Bluetooth: Convert BCM92035 support to driver setup callback
In reply to Johan HedbergFrom: Marcel Holtmann <[email protected]>
With the early init stage during setup, this quirk can be simplified and kept fully inside the driver.
--- drivers/bluetooth/btusb.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/bluetooth/btusb.c +17 -11
@@ -242,6 +242,7 @@ struct btusb_data {struct usb_endpoint_descriptor *isoc_rx_ep;__u8 cmdreq_type; +unsigned long driver_info;unsigned int sco_num;int isoc_altsetting;
@@ -695,6 +696,20 @@ static int btusb_flush(struct hci_dev *hdev)return 0 ; } +static int btusb_setup (struct hci_dev *hdev) +{ +struct btusb_data *data =hci_get_drvdata (hdev); + +BT_DBG ("%s" , hdev->name); + +if (data->driver_info &BTUSB_BCM92035 ) { +__u8 val =0x00 ; +hci_send_cmd (hdev,0xfc3b ,1 , &val); + } + +return 0 ; +} +static int btusb_send_frame (struct sk_buff *skb) {struct hci_dev *hdev = (struct hci_dev *) skb->dev;
@@ -992,6 +1007,7 @@ static int btusb_probe(struct usb_interface *intf,return -ENODEV ; data->cmdreq_type =USB_TYPE_CLASS ; + data->driver_info = id->driver_info; data->udev =interface_to_usbdev (intf); data->intf = intf;
@@ -1022,6 +1038,7 @@ static int btusb_probe(struct usb_interface *intf, hdev->open = btusb_open; hdev->close = btusb_close; hdev->flush = btusb_flush; + hdev->setup = btusb_setup; hdev->send = btusb_send_frame; hdev->notify = btusb_notify;
@@ -1062,17 +1079,6 @@ static int btusb_probe(struct usb_interface *intf, data->isoc =NULL ; } -if (id->driver_info &BTUSB_BCM92035 ) { -unsigned char cmd[] = {0x3b ,0xfc ,0x01 ,0x00 }; -struct sk_buff *skb; - - skb =bt_skb_alloc (sizeof (cmd),GFP_KERNEL ); -if (skb) { -memcpy (skb_put (skb,sizeof (cmd)), cmd,sizeof (cmd)); -skb_queue_tail (&hdev->driver_init, skb); - } - } -if (data->isoc) { err =usb_driver_claim_interface (&btusb_driver, data->isoc, data);
Signature · 1 line
1.7.10.4
PATCH v2 3/3 Bluetooth: Remove driver init queue from core
In reply to Johan HedbergFrom: Marcel Holtmann <[email protected]>
The driver init queue is no longer needed. This can be all handled inside the drivers now. So remove it.
--- include/net/bluetooth/hci_core.h | 2 -- net/bluetooth/hci_core.c | 23 ----------------------- 2 files changed, 25 deletions(-)
include/net/bluetooth/hci_core.h +0 -2
@@ -268,8 +268,6 @@ struct hci_dev {struct hci_dev_stats stat; -struct sk_buff_head driver_init; -atomic_t promisc;struct dentry *debugfs;
net/bluetooth/hci_core.c +0 -23
@@ -201,29 +201,9 @@ static void amp_init(struct hci_request *req)static void hci_init1_req (struct hci_request *req,unsigned long opt) {struct hci_dev *hdev = req->hdev; -struct hci_request init_req; -struct sk_buff *skb;BT_DBG ("%s %ld" , hdev->name, opt); -/* Driver initialization */ - -hci_req_init (&init_req, hdev); - -/* Special commands */ -while ((skb =skb_dequeue (&hdev->driver_init))) { -bt_cb (skb)->pkt_type =HCI_COMMAND_PKT ; - skb->dev = (void *) hdev; - -if (skb_queue_empty (&init_req.cmd_q)) -bt_cb (skb)->req.start = true; - -skb_queue_tail (&init_req.cmd_q, skb); - } -skb_queue_purge (&hdev->driver_init); - -hci_req_run (&init_req,NULL ); -/* Reset */ if (!test_bit (HCI_QUIRK_RESET_ON_CLOSE , &hdev->quirks))hci_reset_req (req,0 );
@@ -2026,7 +2006,6 @@ struct hci_dev *hci_alloc_dev(void)INIT_DELAYED_WORK (&hdev->discov_off, hci_discov_off);INIT_DELAYED_WORK (&hdev->le_scan_disable, le_scan_disable_work); -skb_queue_head_init (&hdev->driver_init);skb_queue_head_init (&hdev->rx_q);skb_queue_head_init (&hdev->cmd_q);skb_queue_head_init (&hdev->raw_q);
@@ -2045,8 +2024,6 @@ EXPORT_SYMBOL(hci_alloc_dev);/* Free HCI device */ void hci_free_dev (struct hci_dev *hdev) { -skb_queue_purge (&hdev->driver_init); -/* will free via device release */ put_device (&hdev->dev); }
Signature · 1 line
1.7.10.4
Hi,
Quoted 14 lines · Johan Hedberg
This is a resend of Marcel's patches that were sent in November, rebased and fixed-up for bluetooth-next. They are a pre-requsite of some follow-up work I'm doing to have a simple way of doing synchronous single-command requests that will be needed by some HCI driver setup routines.
Johan
----------------------------------------------------------------
Marcel Holtmann (3):
Bluetooth: Add driver setup stage for early init
Bluetooth: Convert BCM92035 support to driver setup callback
Bluetooth: Remove driver init queue from core
Quoted 4 lines
drivers/bluetooth/btusb.c | 28 +++++++++++-------- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 56 ++++++++++++++------------------------ 3 files changed, 38 insertions(+), 49 deletions(-)
There patches have now been pushed to the bluetooth-next tree.
Johan
Hi Marcel,
Quoted 15 lines · Johan Hedberg
Quoted 14 lines · Johan Hedberg
This is a resend of Marcel's patches that were sent in November, rebased and fixed-up for bluetooth-next. They are a pre-requsite of some follow-up work I'm doing to have a simple way of doing synchronous single-command requests that will be needed by some HCI driver setup routines.
Johan
----------------------------------------------------------------
Marcel Holtmann (3):
Bluetooth: Add driver setup stage for early init
Bluetooth: Convert BCM92035 support to driver setup callback
Bluetooth: Remove driver init queue from core
Quoted 6 lines
Quoted 4 lines
drivers/bluetooth/btusb.c | 28 +++++++++++-------- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 56 ++++++++++++++------------------------ 3 files changed, 38 insertions(+), 49 deletions(-)There patches have now been pushed to the bluetooth-next tree.
I had to temporarily remove these since they cause build breakage when building as modules:
Quoted 1 line
Quoted 1 line
ERROR: "
hci_send_cmd" [drivers/bluetooth/btusb.ko] undefined!
It seems the reason is a missing EXPORT_SYMBOL declaration for hci_send_cmd which the attached patch should fix. I'll also send a revised patch set of my own function additions since those too will need this declaration.
Johan
Quoted 1 line
From
74b40041d3caeae96d9cbdd2f0ac8a478b79c7c1Mon Sep 17 00:00:00 2001
From: Johan Hedberg <[email protected]>
Date: Thu, 4 Apr 2013 12:39:53 +0300
Subject: [PATCH] Bluetooth: Export hci_send_cmd outside of the HCI core
This function will be needed by HCI drivers when we enable the driver setup sequence to use the HCI core functionality. Hence, export the symbol using EXPORT_SYMBOL.
--- net/bluetooth/hci_core.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/hci_core.c +1 -0
@@ -2538,6 +2538,7 @@ int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param)return 0 ; } +EXPORT_SYMBOL (hci_send_cmd);/* Queue a command to an asynchronous HCI request */ void hci_req_add (struct hci_request *req,u16 opcode,u32 plen,void *param)
Signature · 1 line
1.7.10.4
Marcel Holtmann
maintainerHi Johan,
Quoted 24 lines
Quoted 14 lines
Quoted 14 lines
This is a resend of Marcel's patches that were sent in November, rebased and fixed-up for bluetooth-next. They are a pre-requsite of some follow-up work I'm doing to have a simple way of doing synchronous single-command requests that will be needed by some HCI driver setup routines.
Johan
----------------------------------------------------------------
Marcel Holtmann (3):
Bluetooth: Add driver setup stage for early init
Bluetooth: Convert BCM92035 support to driver setup callback
Bluetooth: Remove driver init queue from coreQuoted 6 lines
Quoted 4 lines
drivers/bluetooth/btusb.c | 28 +++++++++++-------- include/net/bluetooth/hci_core.h | 3 +- net/bluetooth/hci_core.c | 56 ++++++++++++++------------------------ 3 files changed, 38 insertions(+), 49 deletions(-)There patches have now been pushed to the bluetooth-next tree.
I had to temporarily remove these since they cause build breakage when building as modules:
Quoted 6 lines
Quoted 1 line
Quoted 1 line
ERROR: "
hci_send_cmd" [drivers/bluetooth/btusb.ko] undefined!It seems the reason is a missing
EXPORT_SYMBOLdeclaration forhci_send_cmdwhich the attached patch should fix. I'll also send a revised patch set of my own function additions since those too will need this declaration.
can we just switch over to use __hci_cmd_sync() for this as well. I really like to keep hci_send_cmd() internal.
Regards
Marcel