Skip to content

Commit d0f1c24

Browse files
committed
Merge tag 'for-net-next-2021-10-01' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Luiz Augusto von Dentz says: ==================== bluetooth-next pull request for net-next: - Add support for MediaTek MT7922 and MT7921 - Enable support for AOSP extention in Qualcomm WCN399x and Realtek 8822C/8852A. - Add initial support for link quality and audio/codec offload. - Rework of sockets sendmsg to avoid locking issues. - Add vhci suspend/resume emulation. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 49ed8dd + 4539ca6 commit d0f1c24

35 files changed

+2789
-1084
lines changed

drivers/bluetooth/btintel.c

Lines changed: 201 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,9 @@ static bool btintel_firmware_version(struct hci_dev *hdev,
10371037

10381038
params = (void *)(fw_ptr + sizeof(*cmd));
10391039

1040-
bt_dev_info(hdev, "Boot Address: 0x%x",
1041-
le32_to_cpu(params->boot_addr));
1040+
*boot_addr = le32_to_cpu(params->boot_addr);
1041+
1042+
bt_dev_info(hdev, "Boot Address: 0x%x", *boot_addr);
10421043

10431044
bt_dev_info(hdev, "Firmware Version: %u-%u.%u",
10441045
params->fw_build_num, params->fw_build_ww,
@@ -1071,9 +1072,6 @@ int btintel_download_firmware(struct hci_dev *hdev,
10711072
/* Skip version checking */
10721073
break;
10731074
default:
1074-
/* Skip reading firmware file version in bootloader mode */
1075-
if (ver->fw_variant == 0x06)
1076-
break;
10771075

10781076
/* Skip download if firmware has the same version */
10791077
if (btintel_firmware_version(hdev, ver->fw_build_num,
@@ -1114,19 +1112,16 @@ static int btintel_download_fw_tlv(struct hci_dev *hdev,
11141112
int err;
11151113
u32 css_header_ver;
11161114

1117-
/* Skip reading firmware file version in bootloader mode */
1118-
if (ver->img_type != 0x01) {
1119-
/* Skip download if firmware has the same version */
1120-
if (btintel_firmware_version(hdev, ver->min_fw_build_nn,
1121-
ver->min_fw_build_cw,
1122-
ver->min_fw_build_yy,
1123-
fw, boot_param)) {
1124-
bt_dev_info(hdev, "Firmware already loaded");
1125-
/* Return -EALREADY to indicate that firmware has
1126-
* already been loaded.
1127-
*/
1128-
return -EALREADY;
1129-
}
1115+
/* Skip download if firmware has the same version */
1116+
if (btintel_firmware_version(hdev, ver->min_fw_build_nn,
1117+
ver->min_fw_build_cw,
1118+
ver->min_fw_build_yy,
1119+
fw, boot_param)) {
1120+
bt_dev_info(hdev, "Firmware already loaded");
1121+
/* Return -EALREADY to indicate that firmware has
1122+
* already been loaded.
1123+
*/
1124+
return -EALREADY;
11301125
}
11311126

11321127
/* The firmware variant determines if the device is in bootloader
@@ -1285,12 +1280,16 @@ static int btintel_read_debug_features(struct hci_dev *hdev,
12851280
static int btintel_set_debug_features(struct hci_dev *hdev,
12861281
const struct intel_debug_features *features)
12871282
{
1288-
u8 mask[11] = { 0x0a, 0x92, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00,
1283+
u8 mask[11] = { 0x0a, 0x92, 0x02, 0x7f, 0x00, 0x00, 0x00, 0x00,
12891284
0x00, 0x00, 0x00 };
1285+
u8 period[5] = { 0x04, 0x91, 0x02, 0x05, 0x00 };
1286+
u8 trace_enable = 0x02;
12901287
struct sk_buff *skb;
12911288

1292-
if (!features)
1289+
if (!features) {
1290+
bt_dev_warn(hdev, "Debug features not read");
12931291
return -EINVAL;
1292+
}
12941293

12951294
if (!(features->page1[0] & 0x3f)) {
12961295
bt_dev_info(hdev, "Telemetry exception format not supported");
@@ -1303,11 +1302,95 @@ static int btintel_set_debug_features(struct hci_dev *hdev,
13031302
PTR_ERR(skb));
13041303
return PTR_ERR(skb);
13051304
}
1305+
kfree_skb(skb);
1306+
1307+
skb = __hci_cmd_sync(hdev, 0xfc8b, 5, period, HCI_INIT_TIMEOUT);
1308+
if (IS_ERR(skb)) {
1309+
bt_dev_err(hdev, "Setting periodicity for link statistics traces failed (%ld)",
1310+
PTR_ERR(skb));
1311+
return PTR_ERR(skb);
1312+
}
1313+
kfree_skb(skb);
1314+
1315+
skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
1316+
if (IS_ERR(skb)) {
1317+
bt_dev_err(hdev, "Enable tracing of link statistics events failed (%ld)",
1318+
PTR_ERR(skb));
1319+
return PTR_ERR(skb);
1320+
}
1321+
kfree_skb(skb);
1322+
1323+
bt_dev_info(hdev, "set debug features: trace_enable 0x%02x mask 0x%02x",
1324+
trace_enable, mask[3]);
1325+
1326+
return 0;
1327+
}
1328+
1329+
static int btintel_reset_debug_features(struct hci_dev *hdev,
1330+
const struct intel_debug_features *features)
1331+
{
1332+
u8 mask[11] = { 0x0a, 0x92, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
1333+
0x00, 0x00, 0x00 };
1334+
u8 trace_enable = 0x00;
1335+
struct sk_buff *skb;
1336+
1337+
if (!features) {
1338+
bt_dev_warn(hdev, "Debug features not read");
1339+
return -EINVAL;
1340+
}
1341+
1342+
if (!(features->page1[0] & 0x3f)) {
1343+
bt_dev_info(hdev, "Telemetry exception format not supported");
1344+
return 0;
1345+
}
1346+
1347+
/* Should stop the trace before writing ddc event mask. */
1348+
skb = __hci_cmd_sync(hdev, 0xfca1, 1, &trace_enable, HCI_INIT_TIMEOUT);
1349+
if (IS_ERR(skb)) {
1350+
bt_dev_err(hdev, "Stop tracing of link statistics events failed (%ld)",
1351+
PTR_ERR(skb));
1352+
return PTR_ERR(skb);
1353+
}
1354+
kfree_skb(skb);
13061355

1356+
skb = __hci_cmd_sync(hdev, 0xfc8b, 11, mask, HCI_INIT_TIMEOUT);
1357+
if (IS_ERR(skb)) {
1358+
bt_dev_err(hdev, "Setting Intel telemetry ddc write event mask failed (%ld)",
1359+
PTR_ERR(skb));
1360+
return PTR_ERR(skb);
1361+
}
13071362
kfree_skb(skb);
1363+
1364+
bt_dev_info(hdev, "reset debug features: trace_enable 0x%02x mask 0x%02x",
1365+
trace_enable, mask[3]);
1366+
13081367
return 0;
13091368
}
13101369

1370+
int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
1371+
{
1372+
struct intel_debug_features features;
1373+
int err;
1374+
1375+
bt_dev_dbg(hdev, "enable %d", enable);
1376+
1377+
/* Read the Intel supported features and if new exception formats
1378+
* supported, need to load the additional DDC config to enable.
1379+
*/
1380+
err = btintel_read_debug_features(hdev, &features);
1381+
if (err)
1382+
return err;
1383+
1384+
/* Set or reset the debug features. */
1385+
if (enable)
1386+
err = btintel_set_debug_features(hdev, &features);
1387+
else
1388+
err = btintel_reset_debug_features(hdev, &features);
1389+
1390+
return err;
1391+
}
1392+
EXPORT_SYMBOL_GPL(btintel_set_quality_report);
1393+
13111394
static const struct firmware *btintel_legacy_rom_get_fw(struct hci_dev *hdev,
13121395
struct intel_version *ver)
13131396
{
@@ -1893,7 +1976,6 @@ static int btintel_bootloader_setup(struct hci_dev *hdev,
18931976
u32 boot_param;
18941977
char ddcname[64];
18951978
int err;
1896-
struct intel_debug_features features;
18971979

18981980
BT_DBG("%s", hdev->name);
18991981

@@ -1934,14 +2016,7 @@ static int btintel_bootloader_setup(struct hci_dev *hdev,
19342016
btintel_load_ddc_config(hdev, ddcname);
19352017
}
19362018

1937-
/* Read the Intel supported features and if new exception formats
1938-
* supported, need to load the additional DDC config to enable.
1939-
*/
1940-
err = btintel_read_debug_features(hdev, &features);
1941-
if (!err) {
1942-
/* Set DDC mask for available debug features */
1943-
btintel_set_debug_features(hdev, &features);
1944-
}
2019+
hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
19452020

19462021
/* Read the Intel version information after loading the FW */
19472022
err = btintel_read_version(hdev, &new_ver);
@@ -2083,13 +2158,102 @@ static int btintel_prepare_fw_download_tlv(struct hci_dev *hdev,
20832158
return err;
20842159
}
20852160

2161+
static int btintel_get_codec_config_data(struct hci_dev *hdev,
2162+
__u8 link, struct bt_codec *codec,
2163+
__u8 *ven_len, __u8 **ven_data)
2164+
{
2165+
int err = 0;
2166+
2167+
if (!ven_data || !ven_len)
2168+
return -EINVAL;
2169+
2170+
*ven_len = 0;
2171+
*ven_data = NULL;
2172+
2173+
if (link != ESCO_LINK) {
2174+
bt_dev_err(hdev, "Invalid link type(%u)", link);
2175+
return -EINVAL;
2176+
}
2177+
2178+
*ven_data = kmalloc(sizeof(__u8), GFP_KERNEL);
2179+
if (!*ven_data) {
2180+
err = -ENOMEM;
2181+
goto error;
2182+
}
2183+
2184+
/* supports only CVSD and mSBC offload codecs */
2185+
switch (codec->id) {
2186+
case 0x02:
2187+
**ven_data = 0x00;
2188+
break;
2189+
case 0x05:
2190+
**ven_data = 0x01;
2191+
break;
2192+
default:
2193+
err = -EINVAL;
2194+
bt_dev_err(hdev, "Invalid codec id(%u)", codec->id);
2195+
goto error;
2196+
}
2197+
/* codec and its capabilities are pre-defined to ids
2198+
* preset id = 0x00 represents CVSD codec with sampling rate 8K
2199+
* preset id = 0x01 represents mSBC codec with sampling rate 16K
2200+
*/
2201+
*ven_len = sizeof(__u8);
2202+
return err;
2203+
2204+
error:
2205+
kfree(*ven_data);
2206+
*ven_data = NULL;
2207+
return err;
2208+
}
2209+
2210+
static int btintel_get_data_path_id(struct hci_dev *hdev, __u8 *data_path_id)
2211+
{
2212+
/* Intel uses 1 as data path id for all the usecases */
2213+
*data_path_id = 1;
2214+
return 0;
2215+
}
2216+
2217+
static int btintel_configure_offload(struct hci_dev *hdev)
2218+
{
2219+
struct sk_buff *skb;
2220+
int err = 0;
2221+
struct intel_offload_use_cases *use_cases;
2222+
2223+
skb = __hci_cmd_sync(hdev, 0xfc86, 0, NULL, HCI_INIT_TIMEOUT);
2224+
if (IS_ERR(skb)) {
2225+
bt_dev_err(hdev, "Reading offload use cases failed (%ld)",
2226+
PTR_ERR(skb));
2227+
return PTR_ERR(skb);
2228+
}
2229+
2230+
if (skb->len < sizeof(*use_cases)) {
2231+
err = -EIO;
2232+
goto error;
2233+
}
2234+
2235+
use_cases = (void *)skb->data;
2236+
2237+
if (use_cases->status) {
2238+
err = -bt_to_errno(skb->data[0]);
2239+
goto error;
2240+
}
2241+
2242+
if (use_cases->preset[0] & 0x03) {
2243+
hdev->get_data_path_id = btintel_get_data_path_id;
2244+
hdev->get_codec_config_data = btintel_get_codec_config_data;
2245+
}
2246+
error:
2247+
kfree_skb(skb);
2248+
return err;
2249+
}
2250+
20862251
static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
20872252
struct intel_version_tlv *ver)
20882253
{
20892254
u32 boot_param;
20902255
char ddcname[64];
20912256
int err;
2092-
struct intel_debug_features features;
20932257
struct intel_version_tlv new_ver;
20942258

20952259
bt_dev_dbg(hdev, "");
@@ -2125,14 +2289,10 @@ static int btintel_bootloader_setup_tlv(struct hci_dev *hdev,
21252289
*/
21262290
btintel_load_ddc_config(hdev, ddcname);
21272291

2128-
/* Read the Intel supported features and if new exception formats
2129-
* supported, need to load the additional DDC config to enable.
2130-
*/
2131-
err = btintel_read_debug_features(hdev, &features);
2132-
if (!err) {
2133-
/* Set DDC mask for available debug features */
2134-
btintel_set_debug_features(hdev, &features);
2135-
}
2292+
/* Read supported use cases and set callbacks to fetch datapath id */
2293+
btintel_configure_offload(hdev);
2294+
2295+
hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);
21362296

21372297
/* Read the Intel version information after loading the FW */
21382298
err = btintel_read_version_tlv(hdev, &new_ver);
@@ -2232,6 +2392,9 @@ static int btintel_setup_combined(struct hci_dev *hdev)
22322392
set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
22332393
set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
22342394

2395+
/* Set up the quality report callback for Intel devices */
2396+
hdev->set_quality_report = btintel_set_quality_report;
2397+
22352398
/* For Legacy device, check the HW platform value and size */
22362399
if (skb->len == sizeof(ver) && skb->data[1] == 0x37) {
22372400
bt_dev_dbg(hdev, "Read the legacy Intel version information");

drivers/bluetooth/btintel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ struct intel_debug_features {
132132
__u8 page1[16];
133133
} __packed;
134134

135+
struct intel_offload_use_cases {
136+
__u8 status;
137+
__u8 preset[8];
138+
} __packed;
139+
135140
#define INTEL_HW_PLATFORM(cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8))
136141
#define INTEL_HW_VARIANT(cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16))
137142
#define INTEL_CNVX_TOP_TYPE(cnvx_top) ((cnvx_top) & 0x00000fff)
@@ -204,6 +209,7 @@ int btintel_configure_setup(struct hci_dev *hdev);
204209
void btintel_bootup(struct hci_dev *hdev, const void *ptr, unsigned int len);
205210
void btintel_secure_send_result(struct hci_dev *hdev,
206211
const void *ptr, unsigned int len);
212+
int btintel_set_quality_report(struct hci_dev *hdev, bool enable);
207213
#else
208214

209215
static inline int btintel_check_bdaddr(struct hci_dev *hdev)
@@ -294,4 +300,9 @@ static inline void btintel_secure_send_result(struct hci_dev *hdev,
294300
const void *ptr, unsigned int len)
295301
{
296302
}
303+
304+
static inline int btintel_set_quality_report(struct hci_dev *hdev, bool enable)
305+
{
306+
return -ENODEV;
307+
}
297308
#endif

drivers/bluetooth/btmrvl_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ static int btmrvl_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
587587
return 0;
588588
}
589589

590-
static bool btmrvl_prevent_wake(struct hci_dev *hdev)
590+
static bool btmrvl_wakeup(struct hci_dev *hdev)
591591
{
592592
struct btmrvl_private *priv = hci_get_drvdata(hdev);
593593
struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
594594

595-
return !device_may_wakeup(&card->func->dev);
595+
return device_may_wakeup(&card->func->dev);
596596
}
597597

598598
/*
@@ -696,7 +696,7 @@ int btmrvl_register_hdev(struct btmrvl_private *priv)
696696
hdev->send = btmrvl_send_frame;
697697
hdev->setup = btmrvl_setup;
698698
hdev->set_bdaddr = btmrvl_set_bdaddr;
699-
hdev->prevent_wake = btmrvl_prevent_wake;
699+
hdev->wakeup = btmrvl_wakeup;
700700
SET_HCIDEV_DEV(hdev, &card->func->dev);
701701

702702
hdev->dev_type = priv->btmrvl_dev.dev_type;

0 commit comments

Comments
 (0)