Bluetooth: hci_uart: add prepare callbacks to hci_uart_proto structure.
PATCH v13 1/3 Bluetooth: hci_uart: add prepare callbacks to hci_uart_proto structure.
From: Ganapathi Bhat <[email protected]>
The new callback is used to prepare the device before HCI becomes ready. One can use this to download firmware if the download process doesn't use HCI commands. Also recv_for_prepare callback is introduced for receiving data from devices during prepare phase.
--- drivers/bluetooth/hci_ldisc.c | 11 ++++++++++- drivers/bluetooth/hci_uart.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/bluetooth/hci_ldisc.c +10 -1
@@ -551,8 +551,11 @@ static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data,if (!hu || tty != hu->tty)return ; -if (!test_bit (HCI_UART_PROTO_READY , &hu->flags)) +if (!test_bit (HCI_UART_PROTO_READY , &hu->flags)) { +if (hu->proto->recv_for_prepare) + hu->proto->recv_for_prepare (hu, data, count);return ; + }/* It does not need a lock here as it is already protected by a mutex in * tty caller
@@ -639,6 +642,12 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)return err; hu->proto = p; +if (p->prepare) { + err = p->prepare (hu); +if (err) +return err; + } +set_bit (HCI_UART_PROTO_READY , &hu->flags); err =hci_uart_register_dev (hu);
drivers/bluetooth/hci_uart.h +3 -0
@@ -67,8 +67,11 @@ struct hci_uart_proto {int (*close)(struct hci_uart *hu);int (*flush)(struct hci_uart *hu);int (*setup)(struct hci_uart *hu); +int (*prepare)(struct hci_uart *hu);int (*set_baudrate)(struct hci_uart *hu,unsigned int speed);int (*recv)(struct hci_uart *hu,const void *data,int len); +int (*recv_for_prepare)(struct hci_uart *hu,const void *data, +int len);int (*enqueue)(struct hci_uart *hu,struct sk_buff *skb);struct sk_buff *(*dequeue)(struct hci_uart *hu); };
Signature · 1 line
1.8.1.4
PATCH v13 2/3 Bluetooth: hci_uart: check if hdev is present before using it
From: Ganapathi Bhat <[email protected]>
The hdev struct might not have initialized in protocol receive handler. This patch adds necessary checks.
--- drivers/bluetooth/hci_ldisc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bluetooth/hci_ldisc.c +4 -2
@@ -154,7 +154,9 @@ restart:set_bit (TTY_DO_WRITE_WAKEUP , &tty->flags); len = tty->ops->write (tty, skb->data, skb->len); - hdev->stat.byte_tx += len; + +if (hdev) + hdev->stat.byte_tx += len;skb_pull (skb, len);if (skb->len) {
@@ -349,7 +351,7 @@ void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed)/* tty_set_termios() return not checked as it is always 0 */ tty_set_termios (tty, &ktermios); -BT_DBG ("%s: New tty speeds: %d/%d" , hu->hdev->name, +BT_DBG ("%s: New tty speeds: %d/%d" , hu->hdev ? hu->hdev->name :"" , tty->termios.c_ispeed, tty->termios.c_ospeed); }
Signature · 1 line
1.8.1.4
PATCH v13 3/3 Bluetooth: hci_uart: Support firmware download for Marvell
In reply to Amitkumar KarwarFrom: Ganapathi Bhat <[email protected]>
This patch implement firmware download feature for Marvell Bluetooth devices. If firmware is already downloaded, it will skip downloading.
---
v2: Fixed compilation warning reported by kbuild test robot
v3: Addressed review comments from Marcel Holtmann
a) Removed vendor specific code from hci_ldisc.c
b) Get rid of static forward declaration
c) Removed unnecessary heavy nesting
d) Git rid of module parameter and global variables
e) Add logic to pick right firmware image
v4: Addresses review comments from Alan
a) Use existing kernel helper APIs instead of writing own.
b) Replace mdelay() with msleep()
v5: Addresses review comments from Loic Poulain
a) Use bt_dev_err/warn/dbg helpers insted of BT_ERR/WARN/DBG
b) Used static functions where required and removed forward delcarations
c) Edited comments for the function hci_uart_recv_data
d) Made HCI_UART_DNLD_FW flag a part of driver private data
v6: Addresses review comments from Loic Poulain
a) Used skb instead of array to store firmware data during download
b) Used hci_uart_tx_wakeup and enqueued packets instead of tty write
c) Used GFP_KERNEL instead of GFP_ATOMIC
v7: Edited Kconfig to add dependency for BT_HCIUART_H4. The change resolves
errors reported by kbuild test robot.
v8: Addressed review comments from Marcel Holtmann
a) Removed unnecessary memory allocation failure messages
b) Get rid of btmrvl.h header file and add definitions in hci_mrvl.c file
v9: Addressed review comments from Marcel Holtmann
a) Moved firmware download code from setup to prepare handler.
b) Change messages from bt_dev_*->BT_*, as hdev isn't available during firmware download.
v10: Addressed review comments from Marcel Holtmann
a) Added new callback recv_for_prepare to receive data from device during prepare phase
b) Avoided using private flags (HCI_UART_DNLD_FW) as new receive callback is added for the same purpose
c) Used kernel API to handle unaligned data
d) Moved mrvl_set_baud functionality inside setup callback
v11: Write data through ldisc in mrvl_send_ack() instead of directly calling
write method(One Thousand Gnomes).
v12: a) Check for buffer length before copying to skb (Loic Poulain)
b) Rearrange skb memory allocation check
v13: Addressed review comments from Loic Poulain
a) Instead of hardcoding 115200, initialise init_speed as 115200
b) Allocate required length instead of max size.
--- drivers/bluetooth/Kconfig | 11 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/hci_ldisc.c | 6 + drivers/bluetooth/hci_mrvl.c | 548 ++++++++++++++++++++++++++++++++++++++++++ drivers/bluetooth/hci_uart.h | 8 +- 5 files changed, 573 insertions(+), 1 deletion(-) create mode 100644 drivers/bluetooth/hci_mrvl.c
drivers/bluetooth/Kconfig +11 -0
@@ -180,6 +180,17 @@ config BT_HCIUART_AG6XX Say Y here to compile support for Intel AG6XX protocol. +config BT_HCIUART_MRVL + bool "Marvell protocol support" + depends on BT_HCIUART + select BT_HCIUART_H4 + help + Marvell is serial protocol for communication between Bluetooth + device and host. This protocol is required for most Marvell Bluetooth + devices with UART interface. + + Say Y here to compile support for HCI MRVL protocol. + config BT_HCIBCM203X tristate "HCI BCM203x USB driver" depends on USB
drivers/bluetooth/Makefile +1 -0
@@ -38,6 +38,7 @@ hci_uart-$(CONFIG_BT_HCIUART_INTEL) += hci_intel.o hci_uart-$(CONFIG_BT_HCIUART_BCM) += hci_bcm.o hci_uart-$(CONFIG_BT_HCIUART_QCA) += hci_qca.o hci_uart-$(CONFIG_BT_HCIUART_AG6XX) += hci_ag6xx.o +hci_uart-$(CONFIG_BT_HCIUART_MRVL) += hci_mrvl.o hci_uart-objs := $(hci_uart-y) ccflags-y += -D__CHECK_ENDIAN__
drivers/bluetooth/hci_ldisc.c +6 -0
@@ -821,6 +821,9 @@ static int __init hci_uart_init(void)#ifdef CONFIG_BT_HCIUART_AG6XX ag6xx_init ();#endif +#ifdef CONFIG_BT_HCIUART_MRVL +mrvl_init (); +#endif return 0 ; }
@@ -856,6 +859,9 @@ static void __exit hci_uart_exit(void)#ifdef CONFIG_BT_HCIUART_AG6XX ag6xx_deinit ();#endif +#ifdef CONFIG_BT_HCIUART_MRVL +mrvl_deinit (); +#endif /* Release tty registration of line discipline */ err =tty_unregister_ldisc (N_HCI );
drivers/bluetooth/hci_mrvl.c new file +548 -0
548 lines not on this page · raw message
drivers/bluetooth/hci_uart.h +7 -1
@@ -35,7 +35,7 @@#define HCIUARTGETFLAGS _IOR('U', 204, int)/* UART protocols */ -#define HCI_UART_MAX_PROTO 10 +#define HCI_UART_MAX_PROTO 11#define HCI_UART_H4 0#define HCI_UART_BCSP 1
@@ -47,6 +47,7 @@#define HCI_UART_BCM 7#define HCI_UART_QCA 8#define HCI_UART_AG6XX 9 +#define HCI_UART_MRVL 10#define HCI_UART_RAW_DEVICE 0#define HCI_UART_RESET_ON_INIT 1
@@ -192,3 +193,8 @@ int qca_deinit(void);int ag6xx_init (void );int ag6xx_deinit (void );#endif + +#ifdef CONFIG_BT_HCIUART_MRVL +int mrvl_init (void ); +int mrvl_deinit (void ); +#endif
Signature · 1 line
1.8.1.4