Skip to contentSkip to conversation

Bluetooth: Add hci_cmd_sync

PATCH In review Loic Poulain 3 participants 5 messages Sep 29, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 Bluetooth: Add hci_cmd_sync

Send a HCI command and wait for command complete event. This function serializes the requests by grabbing the req_lock.

---
v1: v2: no patch 1/2
v3: Add hci_cmd_sync function, used by regmap-ibt

 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_core.c         | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
include/net/bluetooth/hci_core.h +3 -0
index 256e673..61dc786 100644
@@ -1349,6 +1349,9 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
 
 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
 
+struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
+			     const void *param, u32 timeout);
+
 /* ----- HCI Sockets ----- */
 void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
 void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
net/bluetooth/hci_core.c +19 -0
index a7cdd99..7935646 100644
@@ -3580,6 +3580,25 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)
 	return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE;
 }
 
+/* Send HCI command and wait for command commplete event */
+struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
+			     const void *param, u32 timeout)
+{
+	struct sk_buff *skb;
+
+	if (!test_bit(HCI_UP, &hdev->flags))
+		return ERR_PTR(-ENETDOWN);
+
+	bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen);
+
+	hci_req_lock(hdev);
+	skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout);
+	hci_req_unlock(hdev);
+
+	return skb;
+}
+EXPORT_SYMBOL(hci_cmd_sync);
+
 /* Send ACL data */
 static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)
 {
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 2/2 regmap: Add iBT register access over HCI support

Add support for Intel Bluetooth silicon register access over HCI. Intel BT/FM combo chip allows to read/write some registers (e.g. FM registers) via its HCI interface.

Read/Write operations are performed via a HCI transaction composed of a HCI command (host->controller) followed by a HCI command complete event (controller->host). Read/Write Command opcodes can be specified to the regmap init function.
We define data formats which are intel/vendor specific.

Register Read/Write HCI command payload (Host):

Field: | REG ADDR | MODE | DATA_LEN | DATA... |
size:  |   32b    |  8b  |    8b    |  8b*    |

Register Read HCI command complete event payload (Controller):

Field: | CMD STATUS | REG ADDR | DATA... |
size:  |     8b     |   32b    |  8b*    |

Register Write HCI command complete event payload (Controller):

Field: | CMD_STATUS |
size:  |     8b     |

Since this payload is HCI encapsulated, Little Endian byte order is used.

Write/Read Example:

If we write 0x0000002a at address 0x00008c04, with opcode_write 0xfc5d, The resulting transaction is (btmon trace):

< HCI Command (0x3f|0x005d) plen 10 [hci0]

        04 8c 00 00 02 04 2a 00 00 00
Quoted 1 line

HCI Event (0x0e) plen 4

      Unknown (0x3f|0x005d) ncmd 1
        00

Then, if we read the same register with opcode_read 0xfc5e:

< HCI Command (0x3f|0x005e) plen 6 [hci0]

        04 8c 00 00 02 04
Quoted 1 line

HCI Event (0x0e) plen 12 [hci0]

      Unknown (0x3f|0x005e) ncmd 1
        00 04 8c 00 00 2a 00 00 00

---
v2: Change "hci" to "ibt" since it's intel specific
Add comments for clarification
Remove unjustified default opcodes
Protect __hci_cmd_sync call with hdev req_lock Replace BUG_ON with WARN_ONCE
v3: Use thread-safe hci_cmd_sync instead of __hci_cmd_sync
Update subject

 drivers/base/regmap/Kconfig      |   6 +-
 drivers/base/regmap/Makefile     |   1 +
 drivers/base/regmap/regmap-ibt.c | 276 +++++++++++++++++++++++++++++++++++++++
 include/linux/regmap.h           |   7 +
 4 files changed, 289 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/regmap/regmap-ibt.c
drivers/base/regmap/Kconfig +5 -1
index db9d00c3..e34675f 100644
@@ -3,7 +3,7 @@
 # subsystems should select the appropriate symbols.
 
 config REGMAP
-	default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ)
+	default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_IBT)
 	select LZO_COMPRESS
 	select LZO_DECOMPRESS
 	select IRQ_DOMAIN if REGMAP_IRQ
@@ -29,3 +29,7 @@ config REGMAP_MMIO
 
 config REGMAP_IRQ
 	bool
+
+config REGMAP_IBT
+	tristate
+	depends on BT
\ No newline at end of file
drivers/base/regmap/Makefile +1 -0
index 609e4c8..e7fd73f 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
 obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o
 obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
+obj-$(CONFIG_REGMAP_IBT) += regmap-ibt.o
drivers/base/regmap/regmap-ibt.c new file +276 -0

276 lines not on this page · raw message

include/linux/regmap.h +7 -0
index 59c55ea..af7c146 100644
@@ -28,6 +28,7 @@ struct regmap;
 struct regmap_range_cfg;
 struct regmap_field;
 struct snd_ac97;
+struct hci_dev;
 
 /* An enum of all the supported cache types */
 enum regcache_type {
@@ -343,6 +344,9 @@ struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id,
 				    const struct regmap_config *config);
 struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
 				const struct regmap_config *config);
+struct regmap *regmap_init_ibt(struct hci_dev *hdev,
+			       u16 opcode_read, u16 opcode_write,
+			       const struct regmap_config *config);
 
 struct regmap *devm_regmap_init(struct device *dev,
 				const struct regmap_bus *bus,
@@ -361,6 +365,9 @@ struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id,
 					 const struct regmap_config *config);
 struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
 				     const struct regmap_config *config);
+struct regmap *devm_regmap_init_ibt(struct hci_dev *hdev,
+				    u16 opcode_read, u16 opcode_write,
+				    const struct regmap_config *config);
 
 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
 
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v3 2/2] regmap: Add iBT register access over HCI support

Hi Loic,

Quoted 54 lines

Add support for Intel Bluetooth silicon register access over HCI. Intel BT/FM combo chip allows to read/write some registers (e.g. FM registers) via its HCI interface.

Read/Write operations are performed via a HCI transaction composed of a HCI command (host->controller) followed by a HCI command complete event (controller->host). Read/Write Command opcodes can be specified to the regmap init function.
We define data formats which are intel/vendor specific.

Register Read/Write HCI command payload (Host):

Field: | REG ADDR | MODE | DATA_LEN | DATA... |
size:  |   32b    |  8b  |    8b    |  8b*    |

Register Read HCI command complete event payload (Controller):

Field: | CMD STATUS | REG ADDR | DATA... |
size:  |     8b     |   32b    |  8b*    |

Register Write HCI command complete event payload (Controller):

Field: | CMD_STATUS |
size:  |     8b     |

Since this payload is HCI encapsulated, Little Endian byte order is used.

Write/Read Example:

If we write 0x0000002a at address 0x00008c04, with opcode_write 0xfc5d, The resulting transaction is (btmon trace):

< HCI Command (0x3f|0x005d) plen 10 [hci0]

       04 8c 00 00 02 04 2a 00 00 00
Quoted 1 line

HCI Event (0x0e) plen 4

     Unknown (0x3f|0x005d) ncmd 1
       00

Then, if we read the same register with opcode_read 0xfc5e:

< HCI Command (0x3f|0x005e) plen 6 [hci0]

       04 8c 00 00 02 04
Quoted 1 line

HCI Event (0x0e) plen 12 [hci0]

     Unknown (0x3f|0x005e) ncmd 1
       00 04 8c 00 00 2a 00 00 00

---
v2: Change "hci" to "ibt" since it's intel specific
Add comments for clarification
Remove unjustified default opcodes
Protect __hci_cmd_sync call with hdev req_lock Replace BUG_ON with WARN_ONCE
v3: Use thread-safe hci_cmd_sync instead of __hci_cmd_sync
Update subject

Quoted 6 lines
drivers/base/regmap/Kconfig      |   6 +-
drivers/base/regmap/Makefile     |   1 +
drivers/base/regmap/regmap-ibt.c | 276 +++++++++++++++++++++++++++++++++++++++
include/linux/regmap.h           |   7 +
4 files changed, 289 insertions(+), 1 deletion(-)

create mode 100644 drivers/base/regmap/regmap-ibt.c

patch looks good to me. Now lets get some ACKs for it so I can take it through bluetooth-next tree.

Regards

Marcel

maintainer
#3 lore raw

Re: [PATCH v3 2/2] regmap: Add iBT register access over HCI support

In reply to Loic Poulain
Quoted 3 lines · Loic Poulain

Add support for Intel Bluetooth silicon register access over HCI. Intel BT/FM combo chip allows to read/write some registers (e.g. FM registers) via its HCI interface.

If this is specific to some devices it should go into the driver for those devices rather than added as generic code in the subsystem.

maintainer
#4 lore raw
In reply to Loic Poulain

Hi Loic,

Quoted 11 lines

Send a HCI command and wait for command complete event. This function serializes the requests by grabbing the req_lock.

---
v1: v2: no patch 1/2
v3: Add hci_cmd_sync function, used by regmap-ibt

include/net/bluetooth/hci_core.h | 3 +++
net/bluetooth/hci_core.c | 19 +++++++++++++++++++

2 files changed, 22 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel