Skip to contentSkip to conversation

Bluetooth: btusb: MediaTek ISO data transmission support

PATCH Superseded Chris Lu 3 participants 6 messages May 29, 2024

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Chris Lu

author
#0 lore raw

cover Bluetooth: btusb: MediaTek ISO data transmission support

Since SIG hasn't clearly defined the specification about ISO data over USB transmission yet, MediaTek adopts a method by adding an additional interrupt endpoint for ISO data transmission which is different from current way on Bluetooth upstream driver using existed bulk. Interrupt endpoint has guaranteed bandwidth, sufficient max data length for LE audio packet and support error checking. These characteristics are similar to the use of ISO data.

Chris Lu (3):
Bluetooth: net: add hci_iso_hdr function for iso data
Bluetooth: btmtk: add macro to get/set/clear MediaTek defined flags
Bluetooth: btusb: mediatek: add MediaTek ISO data transmission
function

 drivers/bluetooth/btmtk.c   |  35 +++++
 drivers/bluetooth/btmtk.h   |  46 ++++++
 drivers/bluetooth/btusb.c   | 293 +++++++++++++++++++++++++++++++++++-
 include/net/bluetooth/hci.h |   5 +
 4 files changed, 378 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH 1/3 Bluetooth: net: add hci_iso_hdr function for iso data

Add function hci_iso_hdr to get skb->data when packet type is ISO which is similar to other packet type.

---
 include/net/bluetooth/hci.h | 5 +++++
 1 file changed, 5 insertions(+)
include/net/bluetooth/hci.h +5 -0
index e372a88e8c3f..b9f8f91f6c7f 100644
@@ -2898,6 +2898,11 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
 	return (struct hci_sco_hdr *) skb->data;
 }
 
+static inline struct hci_iso_hdr *hci_iso_hdr(const struct sk_buff *skb)
+{
+	return (struct hci_iso_hdr *) skb->data;
+}
+
 /* Command opcode pack/unpack */
 #define hci_opcode_pack(ogf, ocf)	((__u16) ((ocf & 0x03ff)|(ogf << 10)))
 #define hci_opcode_ogf(op)		(op >> 10)
Signature · 1 line
2.18.0
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=856796

---Test result---

Test Summary:

CheckPatch                    PASS      2.70 seconds
GitLint                       PASS      1.01 seconds
SubjectPrefix                 PASS      0.40 seconds
BuildKernel                   PASS      29.71 seconds
CheckAllWarning               PASS      32.21 seconds
CheckSparse                   WARNING   38.80 seconds
CheckSmatch                   FAIL      34.50 seconds
BuildKernel32                 PASS      28.54 seconds
TestRunnerSetup               PASS      514.87 seconds
TestRunner_l2cap-tester       PASS      18.13 seconds
TestRunner_iso-tester         PASS      28.01 seconds
TestRunner_bnep-tester        PASS      4.73 seconds
TestRunner_mgmt-tester        PASS      106.75 seconds
TestRunner_rfcomm-tester      PASS      7.34 seconds
TestRunner_sco-tester         PASS      14.91 seconds
TestRunner_ioctl-tester       PASS      7.62 seconds
TestRunner_mesh-tester        PASS      9.42 seconds
TestRunner_smp-tester         PASS      6.86 seconds
TestRunner_userchan-tester    PASS      4.92 seconds
IncrementalBuild              PASS      39.11 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
drivers/bluetooth/btusb.c:1368:45: warning: incorrect type in assignment (different base types)drivers/bluetooth/btusb.c:1368:45: expected unsigned short [usertype] expectdrivers/bluetooth/btusb.c:1368:45: got restricted __le16 [usertype] dlen
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: net/bluetooth/hci_core.o] Error 139 make[4]: *** Deleting file 'net/bluetooth/hci_core.o'
make[3]: *** [scripts/Makefile.build:485: net/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:485: net] Error 2
make[2]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bcm203x.o] Error 139 make[4]: *** Deleting file 'drivers/bluetooth/bcm203x.o'
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:485: drivers/bluetooth] Error 2 make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1919: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2

---
Regards,
Linux Bluetooth

author
#3 lore raw

PATCH 2/3 Bluetooth: btmtk: add macro to get/set/clear MediaTek defined flags

In reply to Chris Lu

Define a enumeration to store MediaTek specific flags and macro function to set/test/clear the flags in data structure.

---
 drivers/bluetooth/btmtk.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/bluetooth/btmtk.h +23 -0
index e76b8a358be8..6a0697a22b16 100644
@@ -128,6 +128,10 @@ struct btmtk_hci_wmt_params {
 
 typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *);
 
+enum {
+	__BTMTK_NUM_FLAGS,
+};
+
 struct btmtk_coredump_info {
 	const char *driver_name;
 	u32 fw_version;
@@ -136,11 +140,30 @@ struct btmtk_coredump_info {
 };
 
 struct btmediatek_data {
+	DECLARE_BITMAP(flags, __BTMTK_NUM_FLAGS);
+
 	u32 dev_id;
 	btmtk_reset_sync_func_t reset_sync;
 	struct btmtk_coredump_info cd_info;
 };
 
+#define btmtk_set_flag(hdev, nr)						\
+	do {									\
+		struct btmediatek_data *mediatek = hci_get_priv((hdev));	\
+		set_bit((nr), mediatek->flags);					\
+	} while (0)
+
+#define btmtk_clear_flag(hdev, nr)						\
+	do {									\
+		struct btmediatek_data *mediatek = hci_get_priv((hdev));	\
+		clear_bit((nr), mediatek->flags);				\
+	} while (0)
+
+#define btmtk_get_flag(hdev)							\
+	(((struct btmediatek_data *)hci_get_priv(hdev))->flags)
+
+#define btmtk_test_flag(hdev, nr)	test_bit((nr), btmtk_get_flag(hdev))
+
 typedef int (*wmt_cmd_sync_func_t)(struct hci_dev *,
 				   struct btmtk_hci_wmt_params *);
 
Signature · 1 line
2.18.0
author
#4 lore raw

PATCH 3/3 Bluetooth: btusb: mediatek: add MediaTek ISO data transmission function

In reply to Chris Lu

This patch implement function for ISO data send and receive in btusb driver for MediaTek Controller.

MediaTek define a specific interrupt endpoint for ISO data transmission because the characteristics of interrupt are similar to the application of ISO data which can ensure bandwidth, has enough data length and support error check.

Driver setup ISO interface in btusb_mtk_setup after download patch and submit interrtupt urb to handle ISO data send and receive.

---
 drivers/bluetooth/btmtk.c |  35 +++++
 drivers/bluetooth/btmtk.h |  23 +++
 drivers/bluetooth/btusb.c | 293 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 350 insertions(+), 1 deletion(-)
drivers/bluetooth/btmtk.c +35 -0
index a27c251bf56e..f0aecd319911 100644
@@ -4,6 +4,7 @@
  */
 #include <linux/module.h>
 #include <linux/firmware.h>
+#include <linux/usb.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
@@ -19,6 +20,9 @@
 #define MTK_SEC_MAP_COMMON_SIZE	12
 #define MTK_SEC_MAP_NEED_SEND_SIZE	52
 
+/* It is for mt79xx iso data transmission setting */
+#define MTK_ISO_THRESHOLD	264
+
 struct btmtk_patch_header {
 	u8 datetime[16];
 	u8 platform[4];
@@ -431,6 +435,37 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb)
 }
 EXPORT_SYMBOL_GPL(btmtk_process_coredump);
 
+int btmtk_isointf_setup(struct hci_dev *hdev)
+{
+	u8 iso_param[2] = { 0x08, 0x01 };
+	struct sk_buff *skb;
+
+	skb = __hci_cmd_sync(hdev, 0xfd98, sizeof(iso_param), iso_param,
+			     HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		bt_dev_err(hdev, "Failed to apply iso setting (%ld)", PTR_ERR(skb));
+		return PTR_ERR(skb);
+	}
+	kfree_skb(skb);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(btmtk_isointf_setup);
+
+int btmtk_isopkt_pad(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	if (skb->len > MTK_ISO_THRESHOLD)
+		return -EINVAL;
+
+	if (skb_pad(skb, MTK_ISO_THRESHOLD - skb->len))
+		return -ENOMEM;
+
+	__skb_put(skb, MTK_ISO_THRESHOLD - skb->len);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(btmtk_isopkt_pad);
+
 MODULE_AUTHOR("Sean Wang <[email protected]>");
 MODULE_AUTHOR("Mark Chen <[email protected]>");
 MODULE_DESCRIPTION("Bluetooth support for MediaTek devices ver " VERSION);
drivers/bluetooth/btmtk.h +23 -0
index 6a0697a22b16..afc914e921dd 100644
@@ -129,6 +129,8 @@ struct btmtk_hci_wmt_params {
 typedef int (*btmtk_reset_sync_func_t)(struct hci_dev *, void *);
 
 enum {
+	BTMTK_ISOPKT_OVER_INTR,
+
 	__BTMTK_NUM_FLAGS,
 };
 
@@ -139,12 +141,19 @@ struct btmtk_coredump_info {
 	int state;
 };
 
+struct btmtk_isopkt_info {
+	struct usb_interface *isopkt_intf;
+	struct usb_endpoint_descriptor *isopkt_tx_ep;
+	struct usb_endpoint_descriptor *isopkt_rx_ep;
+};
+
 struct btmediatek_data {
 	DECLARE_BITMAP(flags, __BTMTK_NUM_FLAGS);
 
 	u32 dev_id;
 	btmtk_reset_sync_func_t reset_sync;
 	struct btmtk_coredump_info cd_info;
+	struct btmtk_isopkt_info isopkt_info;
 };
 
 #define btmtk_set_flag(hdev, nr)						\
@@ -186,6 +195,10 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb);
 
 void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id, u32 fw_ver,
 			   u32 fw_flavor);
+
+int btmtk_isointf_setup(struct hci_dev *hdev);
+
+int btmtk_isopkt_pad(struct hci_dev *hdev, struct sk_buff *skb);
 #else
 
 static inline int btmtk_set_bdaddr(struct hci_dev *hdev,
@@ -225,4 +238,14 @@ static void btmtk_fw_get_filename(char *buf, size_t size, u32 dev_id,
 				  u32 fw_ver, u32 fw_flavor)
 {
 }
+
+static int btmtk_isointf_setup(struct hci_dev *hdev)
+{
+	return -EOPNOTSUPP;
+}
+
+static int btmtk_isopkt_pad(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	return -EOPNOTSUPP;
+}
 #endif
drivers/bluetooth/btusb.c +292 -1

394 lines not on this page · raw message

Signature · 1 line
2.18.0
#5 lore raw
In reply to Chris Lu

Hi,

Quoted 14 lines · Chris Lu

Since SIG hasn't clearly defined the specification about ISO data over USB transmission yet, MediaTek adopts a method by adding an additional interrupt endpoint for ISO data transmission which is different from current way on Bluetooth upstream driver using existed bulk. Interrupt endpoint has guaranteed bandwidth, sufficient max data length for LE audio packet and support error checking. These characteristics are similar to the use of ISO data.

Chris Lu (3):
Bluetooth: net: add hci_iso_hdr function for iso data
Bluetooth: btmtk: add macro to get/set/clear MediaTek defined flags
Bluetooth: btusb: mediatek: add MediaTek ISO data transmission
function

Quoted 5 lines
 drivers/bluetooth/btmtk.c   |  35 +++++
 drivers/bluetooth/btmtk.h   |  46 ++++++
 drivers/bluetooth/btusb.c   | 293 +++++++++++++++++++++++++++++++++++-
 include/net/bluetooth/hci.h |   5 +
 4 files changed, 378 insertions(+), 1 deletion(-)

This probably needs to be handled in btmtk.c though, since it is not standard we shall avoid having vendor specific transports like this in btusb.c

Signature · 1 line
Luiz Augusto von Dentz