Skip to content

Commit 7d70989

Browse files
Hsin-chen ChuangVudentz
authored andcommitted
Bluetooth: btusb: Add HCI Drv commands for configuring altsetting
Although commit 75ddcd5 ("Bluetooth: btusb: Configure altsetting for HCI_USER_CHANNEL") has enabled the HCI_USER_CHANNEL user to send out SCO data through USB Bluetooth chips, it's observed that with the patch HFP is flaky on most of the existing USB Bluetooth controllers: Intel chips sometimes send out no packet for Transparent codec; MTK chips may generate SCO data with a wrong handle for CVSD codec; RTK could split the data with a wrong packet size for Transparent codec; ... etc. To address the issue above one needs to reset the altsetting back to zero when there is no active SCO connection, which is the same as the BlueZ behavior, and another benefit is the bus doesn't need to reserve bandwidth when no SCO connection. This patch adds "Supported Altsettings" and "Switch Altsetting" commands that allow the user space program to configure the altsetting freely. This patch is tested on ChromeOS devices. The USB Bluetooth models (CVSD, TRANS alt3, and TRANS alt6) could pass the stress HFP test narrow band speech and wide band speech. Cc: chromeos-bluetooth-upstreaming@chromium.org Fixes: b16b327 ("Bluetooth: btusb: add sysfs attribute to control USB alt setting") Signed-off-by: Hsin-chen Chuang <chharry@chromium.org> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 0442529 commit 7d70989

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

drivers/bluetooth/btusb.c

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3801,12 +3801,31 @@ static ssize_t isoc_alt_store(struct device *dev,
38013801

38023802
static DEVICE_ATTR_RW(isoc_alt);
38033803

3804+
#define BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS \
3805+
hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0000)
3806+
#define BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE 0
3807+
struct btusb_hci_drv_rp_supported_altsettings {
3808+
__u8 num;
3809+
__u8 altsettings[];
3810+
} __packed;
3811+
3812+
#define BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING \
3813+
hci_opcode_pack(HCI_DRV_OGF_DRIVER_SPECIFIC, 0x0001)
3814+
#define BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE 1
3815+
struct btusb_hci_drv_cmd_switch_altsetting {
3816+
__u8 altsetting;
3817+
} __packed;
3818+
38043819
static const struct {
38053820
u16 opcode;
38063821
const char *desc;
38073822
} btusb_hci_drv_supported_commands[] = {
38083823
/* Common commands */
38093824
{ HCI_DRV_OP_READ_INFO, "Read Info" },
3825+
3826+
/* Driver specific commands */
3827+
{ BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS, "Supported Altsettings" },
3828+
{ BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING, "Switch Altsetting" },
38103829
};
38113830
static int btusb_hci_drv_read_info(struct hci_dev *hdev, void *data,
38123831
u16 data_len)
@@ -3843,11 +3862,65 @@ static int btusb_hci_drv_read_info(struct hci_dev *hdev, void *data,
38433862
return err;
38443863
}
38453864

3865+
static int btusb_hci_drv_supported_altsettings(struct hci_dev *hdev, void *data,
3866+
u16 data_len)
3867+
{
3868+
struct btusb_data *drvdata = hci_get_drvdata(hdev);
3869+
struct btusb_hci_drv_rp_supported_altsettings *rp;
3870+
size_t rp_size;
3871+
int err;
3872+
u8 i;
3873+
3874+
/* There are at most 7 alt (0 - 6) */
3875+
rp = kmalloc(sizeof(*rp) + 7, GFP_KERNEL);
3876+
3877+
rp->num = 0;
3878+
if (!drvdata->isoc)
3879+
goto done;
3880+
3881+
for (i = 0; i <= 6; i++) {
3882+
if (btusb_find_altsetting(drvdata, i))
3883+
rp->altsettings[rp->num++] = i;
3884+
}
3885+
3886+
done:
3887+
rp_size = sizeof(*rp) + rp->num;
3888+
3889+
err = hci_drv_cmd_complete(hdev, BTUSB_HCI_DRV_OP_SUPPORTED_ALTSETTINGS,
3890+
HCI_DRV_STATUS_SUCCESS, rp, rp_size);
3891+
kfree(rp);
3892+
return err;
3893+
}
3894+
3895+
static int btusb_hci_drv_switch_altsetting(struct hci_dev *hdev, void *data,
3896+
u16 data_len)
3897+
{
3898+
struct btusb_hci_drv_cmd_switch_altsetting *cmd = data;
3899+
u8 status;
3900+
3901+
if (cmd->altsetting > 6) {
3902+
status = HCI_DRV_STATUS_INVALID_PARAMETERS;
3903+
} else {
3904+
if (btusb_switch_alt_setting(hdev, cmd->altsetting))
3905+
status = HCI_DRV_STATUS_UNSPECIFIED_ERROR;
3906+
else
3907+
status = HCI_DRV_STATUS_SUCCESS;
3908+
}
3909+
3910+
return hci_drv_cmd_status(hdev, BTUSB_HCI_DRV_OP_SWITCH_ALTSETTING,
3911+
status);
3912+
}
3913+
38463914
static const struct hci_drv_handler btusb_hci_drv_common_handlers[] = {
38473915
{ btusb_hci_drv_read_info, HCI_DRV_READ_INFO_SIZE },
38483916
};
38493917

3850-
static const struct hci_drv_handler btusb_hci_drv_specific_handlers[] = {};
3918+
static const struct hci_drv_handler btusb_hci_drv_specific_handlers[] = {
3919+
{ btusb_hci_drv_supported_altsettings,
3920+
BTUSB_HCI_DRV_SUPPORTED_ALTSETTINGS_SIZE },
3921+
{ btusb_hci_drv_switch_altsetting,
3922+
BTUSB_HCI_DRV_SWITCH_ALTSETTING_SIZE },
3923+
};
38513924

38523925
static struct hci_drv btusb_hci_drv = {
38533926
.common_handler_count = ARRAY_SIZE(btusb_hci_drv_common_handlers),

0 commit comments

Comments
 (0)