Skip to contentSkip to conversation

Bluetooth: hci open callback for hci UART transport driver

PATCH In review Suraj Sumangala 3 participants 9 messages Sep 21, 2010 – Oct 5, 2010 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: hci open callback for hci UART transport driver

This patch provides option for hci transport driver protocol implementation to have a callback for hci open.

---
 drivers/bluetooth/hci_ldisc.c |    5 ++++-
 drivers/bluetooth/hci_uart.h  |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
drivers/bluetooth/hci_ldisc.c +4 -1
index 998833d..5e02501 100644
@@ -162,9 +162,12 @@ restart:
 /* Initialize device */
 static int hci_uart_open(struct hci_dev *hdev)
 {
+	struct hci_uart *hu  = (struct hci_uart *) hdev->driver_data;
+
 	BT_DBG("%s %p", hdev->name, hdev);
 
-	/* Nothing to do for UART driver */
+	if (hu->proto->hci_open)
+		hu->proto->hci_open(hu);
 
 	set_bit(HCI_RUNNING, &hdev->flags);
 
drivers/bluetooth/hci_uart.h +1 -0
index 99fb352..d0198ec 100644
@@ -51,6 +51,7 @@ struct hci_uart;
 struct hci_uart_proto {
 	unsigned int id;
 	int (*open)(struct hci_uart *hu);
+	int (*hci_open)(struct hci_uart *hu);
 	int (*close)(struct hci_uart *hu);
 	int (*flush)(struct hci_uart *hu);
 	int (*recv)(struct hci_uart *hu, void *data, int len);
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 Bluetooth: support to send power management enable during hci open

This patch enables HCI_UART_ATH3K transport driver to support sending Vendor specific hci commands during hci open to enable or disable power management feature.

---
 drivers/bluetooth/hci_ath.c |   59 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
drivers/bluetooth/hci_ath.c +59 -0
index 6a160c1..d4b0653 100644
@@ -49,6 +49,37 @@ struct ath_struct {
 	struct work_struct ctxtsw;
 };
 
+/* Form HCI command */
+static struct sk_buff *form_hci_cmd(struct hci_dev *hdev, __u16 opcode,
+						 __u32 plen, void *param)
+{
+	int len = HCI_COMMAND_HDR_SIZE + plen;
+	struct hci_command_hdr *hdr;
+	struct sk_buff *skb;
+
+	BT_DBG("%s opcode 0x%x plen %d", hdev->name, opcode, plen);
+
+	skb = bt_skb_alloc(len, GFP_ATOMIC);
+	if (!skb) {
+		BT_ERR("%s no memory for command", hdev->name);
+		return NULL;
+	}
+
+	hdr = (struct hci_command_hdr *) skb_put(skb, HCI_COMMAND_HDR_SIZE);
+	hdr->opcode = cpu_to_le16(opcode);
+	hdr->plen   = plen;
+
+	if (plen)
+		memcpy(skb_put(skb, plen), param, plen);
+
+	BT_DBG("skb len %d", skb->len);
+
+	bt_cb(skb)->pkt_type = HCI_COMMAND_PKT;
+	skb->dev = (void *) hdev;
+
+	return skb;
+}
+
 static int ath_wakeup_ar3k(struct tty_struct *tty)
 {
 	struct termios settings;
@@ -81,6 +112,26 @@ static int ath_wakeup_ar3k(struct tty_struct *tty)
 	return status;
 }
 
+#define HCI_OP_SLEEP_SET			0xFC04
+static void ath_hci_init_driver(struct hci_uart *hu)
+{
+	struct ath_struct *ath = hu->priv;
+	struct hci_dev *hdev = hu->hdev;
+	struct sk_buff *skb;
+
+	if (!hdev)
+		return;
+
+	if (!ath)
+		return;
+
+	skb = form_hci_cmd(hdev, HCI_OP_SLEEP_SET, 1, &ath->cur_sleep);
+	if (!skb)
+		return;
+
+	skb_queue_head(&hdev->driver_init, skb);
+}
+
 static void ath_hci_uart_work(struct work_struct *work)
 {
 	int status;
@@ -126,6 +177,13 @@ static int ath_open(struct hci_uart *hu)
 	return 0;
 }
 
+static int ath_hci_open(struct hci_uart *hu)
+{
+	ath_hci_init_driver(hu);
+
+	return 0;
+}
+
 /* Flush protocol data */
 static int ath_flush(struct hci_uart *hu)
 {
@@ -210,6 +268,7 @@ static int ath_recv(struct hci_uart *hu, void *data, int count)
 static struct hci_uart_proto athp = {
 	.id = HCI_UART_ATH3K,
 	.open = ath_open,
+	.hci_open = ath_hci_open,
 	.close = ath_close,
 	.recv = ath_recv,
 	.enqueue = ath_enqueue,
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 2/2] Bluetooth: support to send power management enable during hci open

Quoted 3 lines · Suraj Sumangala

This patch enables HCI_UART_ATH3K transport driver to support sending Vendor specific hci commands during hci open to enable or disable power management feature.

Why? shouldn't this be done from the hciattach? like for the other manufacturers?
If you want it to be sent before hci0 interface is exposed, send it over ttyXX, you have your _init function and if you require it to be sent after the hci0 is exposed - do it in the _post function.

Quoted 104 lines

---
 drivers/bluetooth/hci_ath.c |   59 +++++++++++++++++++++++++++++++++++++++++++

 1 files changed, 59 insertions(+), 0 deletions(-)
drivers/bluetooth/hci_ath.c +59 -1
index 6a160c1..d4b0653 100644
@@ -49,6 +49,37 @@ struct ath_struct {
        struct work_struct ctxtsw;
  };
 
+/* Form HCI command */
+static struct sk_buff *form_hci_cmd(struct hci_dev *hdev, __u16 opcode,
+                                                __u32 plen, void *param)
+{
+       int len = HCI_COMMAND_HDR_SIZE + plen;
+       struct hci_command_hdr *hdr;
+       struct sk_buff *skb;
+
+       BT_DBG("%s opcode 0x%x plen %d", hdev->name, opcode, plen);
+
+       skb = bt_skb_alloc(len, GFP_ATOMIC);
+       if (!skb) {
+               BT_ERR("%s no memory for command", hdev->name);
+               return NULL;
+       }
+
+       hdr = (struct hci_command_hdr *) skb_put(skb, HCI_COMMAND_HDR_SIZE);
+       hdr->opcode = cpu_to_le16(opcode);
+       hdr->plen   = plen;
+
+       if (plen)
+               memcpy(skb_put(skb, plen), param, plen);
+
+       BT_DBG("skb len %d", skb->len);
+
+       bt_cb(skb)->pkt_type = HCI_COMMAND_PKT;
+       skb->dev = (void *) hdev;
+
+       return skb;
+}
+
  static int ath_wakeup_ar3k(struct tty_struct *tty)
  {
        struct termios settings;
@@ -81,6 +112,26 @@ static int ath_wakeup_ar3k(struct tty_struct *tty)
        return status;
  }
 
+#define HCI_OP_SLEEP_SET                       0xFC04
+static void ath_hci_init_driver(struct hci_uart *hu)
+{
+       struct ath_struct *ath = hu->priv;
+       struct hci_dev *hdev = hu->hdev;
+       struct sk_buff *skb;
+
+       if (!hdev)
+               return;
+
+       if (!ath)
+               return;
+
+       skb = form_hci_cmd(hdev, HCI_OP_SLEEP_SET, 1, &ath->cur_sleep);
+       if (!skb)
+               return;
+
+       skb_queue_head(&hdev->driver_init, skb);
+}
+
  static void ath_hci_uart_work(struct work_struct *work)
  {
        int status;
@@ -126,6 +177,13 @@ static int ath_open(struct hci_uart *hu)
        return 0;
  }
 
+static int ath_hci_open(struct hci_uart *hu)
+{
+       ath_hci_init_driver(hu);
+
+       return 0;
+}
+
  /* Flush protocol data */
  static int ath_flush(struct hci_uart *hu)
  {
@@ -210,6 +268,7 @@ static int ath_recv(struct hci_uart *hu, void *data, int count)
  static struct hci_uart_proto athp = {
        .id = HCI_UART_ATH3K,
        .open = ath_open,
+       .hci_open = ath_hci_open,
        .close = ath_close,
        .recv = ath_recv,
        .enqueue = ath_enqueue,
--

1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH 2/2] Bluetooth: support to send power management enable during hci open

Hi Pavan,

Quoted 11 lines · Pavan Savoy
Quoted 3 lines · Suraj Sumangala

This patch enables HCI_UART_ATH3K transport driver to support sending Vendor specific hci commands during hci open to enable or disable power management feature.

Why? shouldn't this be done from the hciattach? like for the other manufacturers?
If you want it to be sent before hci0 interface is exposed, send it over ttyXX, you have your _init function and if you require it to be sent after the hci0 is exposed - do it in the _post function.

We are already using the _init and _post of hciattach.

The mentioned feature will get disabled in the controller on receiving a HCI RESET command.

If the user does an HCI close, this feature will be disabled and we need to enable it again when the user opens the HCI device again.

I guess the "hdev->driver_init" queue is provided for that reason.

An hciattach is called only once but hci open/close can be done multiple times.

Regards
Suraj

#4 lore raw

Re: [PATCH 2/2] Bluetooth: support to send power management enable during hci open

Suraj,

Quoted 22 lines · Suraj Sumangala

Hi Pavan,

Quoted 8 lines · Pavan Savoy
Quoted 4 lines · Suraj Sumangala

This patch enables HCI_UART_ATH3K transport driver to support sending Vendor specific hci commands during hci open to enable or disable power management feature.

Quoted 6 lines

Why? shouldn't this be done from the hciattach? like for the other manufacturers?
If you want it to be sent before hci0 interface is exposed, send it over ttyXX, you have your _init function and if you require it to be sent after the hci0 is exposed - do it in the _post function.

We are already using the _init and _post of hciattach.

The mentioned feature will get disabled in the controller on receiving a HCI RESET command.

Quoted 7 lines

If the user does an HCI close, this feature will be disabled and we need to enable it again when the user opens the HCI device again.

I guess the "hdev->driver_init" queue is provided for that reason.

An hciattach is called only once but hci open/close can be done multiple times.

Well this is debatable, I guess we had this discussion when our manufacturer came up with PM feature like this - As to what is the right BT on procedure?
Should hciattach be terminated when BT is Off or is it just a hciconfig hci0 down - So we decided to get rid of hciattach way of doing things.

Also HCI_QUIRK_NO_RESET allows you to not to have reset .. in certain cases, I guess with this your chip's firmware is able to remember the PM settings previously sent across?

Quoted 3 lines

Regards
Suraj

#5 lore raw

Re: [PATCH 2/2] Bluetooth: support to send power management enable during hci open

Hi Pavan,

Quoted 33 lines · Pavan Savoy

Suraj,

Quoted 22 lines · Suraj Sumangala

Hi Pavan,

Quoted 8 lines · Pavan Savoy
Quoted 4 lines · Suraj Sumangala

This patch enables HCI_UART_ATH3K transport driver to support sending Vendor specific hci commands during hci open to enable or disable power management feature.

Quoted 6 lines

Why? shouldn't this be done from the hciattach? like for the other manufacturers?
If you want it to be sent before hci0 interface is exposed, send it over ttyXX, you have your _init function and if you require it to be sent after the hci0 is exposed - do it in the _post function.

We are already using the _init and _post of hciattach.

The mentioned feature will get disabled in the controller on receiving a HCI RESET command.

Quoted 7 lines

If the user does an HCI close, this feature will be disabled and we need to enable it again when the user opens the HCI device again.

I guess the "hdev->driver_init" queue is provided for that reason.

An hciattach is called only once but hci open/close can be done multiple times.

Quoted 6 lines

Well this is debatable, I guess we had this discussion when our manufacturer came up with PM feature like this - As to what is the right BT on procedure?
Should hciattach be terminated when BT is Off or is it just a hciconfig hci0 down - So we decided to get rid of hciattach way of doing things.

Yes, it would work fine for me too on a customer platform. but my idea was to get it working on a generic x86 system running a normal distribution.

Moreover, if you looks at the "hdev->driver_init" queue, it looks like it is meant for exactly this requirement. Bluez already have code in hci_init_req() to take care of this scenario.

Quoted 4 lines

Also HCI_QUIRK_NO_RESET allows you to not to have reset .. in certain cases, I guess with this your chip's firmware is able to remember the PM settings previously sent across?

HCI_QUIRK_NO_RESET only lets you not send a HCI reset during initialization. I have no issues there, I am using the _post callback in hciattach to configure PM.

I am doing the testing in Ubuntu 10.04 using the Blueman as my Bluetooth agent.

From the UI if the user does a BT off. It sends an HCI reset command followed by ah HCI close. This is causing the firmware forget the PM parameters.

Quoted 4 lines
Quoted 4 lines

Regards
Suraj

Regards
Suraj

#7 lore raw

Hi,

Quoted 13 lines · Suraj Sumangala

*ping*

Quoted 9 lines · Suraj Sumangala

This patch provides option for hci transport driver protocol implementation to have a callback for hci open.

---
   drivers/bluetooth/hci_ldisc.c |    5 ++++-
   drivers/bluetooth/hci_uart.h  |    1 +
   2 files changed, 5 insertions(+), 1 deletions(-)
Quoted 2 lines

Regards
Suraj

Is there any comments on this patch?

Regards
Suraj

maintainer
#8 lore raw
In reply to Suraj Sumangala

Hi Suraj,

Quoted 32 lines

This patch provides option for hci transport driver protocol implementation to have a callback for hci open.

---
 drivers/bluetooth/hci_ldisc.c |    5 ++++-
 drivers/bluetooth/hci_uart.h  |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
drivers/bluetooth/hci_ldisc.c +4 -1
index 998833d..5e02501 100644
@@ -162,9 +162,12 @@ restart:
 /* Initialize device */
 static int hci_uart_open(struct hci_dev *hdev)
 {
+	struct hci_uart *hu  = (struct hci_uart *) hdev->driver_data;
+
 	BT_DBG("%s %p", hdev->name, hdev);
 
-	/* Nothing to do for UART driver */
+	if (hu->proto->hci_open)
+		hu->proto->hci_open(hu);
 
 	set_bit(HCI_RUNNING, &hdev->flags);
 
drivers/bluetooth/hci_uart.h +0 -0
index 99fb352..d0198ec 100644

drivers/bluetooth/hci_uart.h struct hci_uart; · line 57

Quoted 7 lines
drivers/bluetooth/hci_uart.h +1 -0
@@ -51,6 +51,7 @@ struct hci_uart;
 struct hci_uart_proto {
 	unsigned int id;
 	int (*open)(struct hci_uart *hu);
+	int (*hci_open)(struct hci_uart *hu);
 	int (*close)(struct hci_uart *hu);
 	int (*flush)(struct hci_uart *hu);
 	int (*recv)(struct hci_uart *hu, void *data, int len);

I don't like this. It is not what any other driver is doing. For me this is just hacking around something that would need to be solved for all Bluetooth transport drivers. Just trying to solve this for UART based drivers is not going to help.

So we talked about adding a setup stage to the HCI driver interface. That is the way you should proceed if doing this in hciattach is not enough for you.

Regards

Marcel