From patchwork Tue Apr 23 07:22:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= X-Patchwork-Id: 1089106 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NhqYpduB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44pFKY66jTz9sNN for ; Tue, 23 Apr 2019 17:23:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726400AbfDWHXH (ORCPT ); Tue, 23 Apr 2019 03:23:07 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:34412 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbfDWHXD (ORCPT ); Tue, 23 Apr 2019 03:23:03 -0400 Received: by mail-pg1-f193.google.com with SMTP id v12so7151150pgq.1; Tue, 23 Apr 2019 00:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XoGcBhzMOQmRsEUerCGTGxvJxKBI0mfLgUxTBjjEjHY=; b=NhqYpduBypo7MY0/4J6+ts3/MGBcud2ymd3IwwIxlql5XqNA7/4OyjDZhGZyTpfNXf 9/lkv7UON7fm4OOxIvobwfthxWenm40lfay0jxXjqwztcO2aju0UKdzDNtmPd8mtYhg/ Tpn8+x0uQyiVmrsVY9pI0qxWkJWTWNrfot0GcX/t+KVwLM5GYfYLfxhJmUyLUHwByzK9 PK3MoZOvqCjU8dY4dG2mLAGUwHfKUmxNiVnQfip1K2V961dl0ir0ZwTBkzvsSeesVCaV ttG9+ZSz+VymmQfmA5ENWxvaaZZArsmSA15fRmK6Q9/D9Yl95MLm5KljWPdb8NM9FXwa 6iGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XoGcBhzMOQmRsEUerCGTGxvJxKBI0mfLgUxTBjjEjHY=; b=C1uHcf1U0XiFOHsX3U33VXjeCm5sxL2OzgNjMKJbJkyh/MHK55yuVpLPXlKuRTIGjc zvdGYtCnAKRtDxw3PQI64ubgFbInPluAlgplCbY61hHabfkGTxTWpn7HaUasz0bRQNzg 8kP5CgtHTfC4jyRs2kAFPa059ya1VbAGNWyXvYsHVJza1Ku2or1WMFaLKhPdOwJ3EgFN G/1aMy0zsj8S+ySFR9JikoteElzh1ZYKH7VDp+sojKg41hxqtSGCMYzSSZl9roHOC8fd 2N2wZwzNHp7shi0f6ubqOjb8J79ghB7XYvw1gPF2vsDzlCdEDLIrx+TC0lwgDZiEn2O4 WM0g== X-Gm-Message-State: APjAAAWsWkeofSbjiGra/BRSW+Wbs0ZD2U+Q1vaKybFZYmqNAMxUbI7g Xubj4yCV1uLEkzA1a6KfqsTK9Ei7ZK8MoQ== X-Google-Smtp-Source: APXvYqyCJJOVlEEYDd8zVWIHZjXKX+/5nEWhloC3WZ23ybn7yMUZ/kyl04xY89H8Ps+h1iZUt2GCDA== X-Received: by 2002:a63:4a5f:: with SMTP id j31mr21618772pgl.369.1556004181976; Tue, 23 Apr 2019 00:23:01 -0700 (PDT) Received: from localhost.localdomain (123-204-46-122.static.seed.net.tw. [123.204.46.122]) by smtp.gmail.com with ESMTPSA id p20sm12560594pgj.86.2019.04.23.00.22.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 00:23:01 -0700 (PDT) From: "=?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?=" X-Google-Original-From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= To: Marcel Holtmann , Johan Hedberg Cc: bgodavar@codeaurora.org, ytkim@qca.qualcomm.com, "David S . Miller" , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com, =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= Subject: [PATCH 1/2] Bluetooth: Create new HCI_QUIRK_WAIT_FOR_MATCHING_CC Date: Tue, 23 Apr 2019 15:22:35 +0800 Message-Id: <20190423072236.24999-2-jprvita@endlessm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190423072236.24999-1-jprvita@endlessm.com> References: <20190423072236.24999-1-jprvita@endlessm.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit creates a new quirk, HCI_QUIRK_WAIT_FOR_MATCHING_CC, which when set makes the kernel not send the next queued HCI command until a command complete arrives for the last HCI command sent to the controller. This avoids a state of confusion where the kernel believes a passive scanning procedure is being performed while in fact controller is performing an active scanning procedure, as requested by userspace and the kernel. This state of confusion is achieved when some buggy controllers send an extra command complete event for the LE_SET_RANDOM_ADDR after the kernel already sent the next queued command (LE_SET_SCAN_PARAM, for starting an active scanning procedure), as shown at timestamp 27.420131 on the btmon logs bellow. Bluetooth monitor ver 5.50 = Note: Linux version 5.0.0+ (x86_64) 0.352340 = Note: Bluetooth subsystem version 2.22 0.352343 = New Index: 80:C5:F2:8F:87:84 (Primary,USB,hci0) [hci0] 0.352344 = Open Index: 80:C5:F2:8F:87:84 [hci0] 0.352345 = Index Info: 80:C5:F2:8F:87:84 (Qualcomm) [hci0] 0.352346 @ MGMT Open: bluetoothd (privileged) version 1.14 {0x0001} 0.352347 @ MGMT Open: btmon (privileged) version 1.14 {0x0002} 0.352366 @ MGMT Open: btmgmt (privileged) version 1.14 {0x0003} 27.302164 @ MGMT Command: Start Discovery (0x0023) plen 1 {0x0003} [hci0] 27.302310 Address type: 0x06 LE Public LE Random < HCI Command: LE Set Random Address (0x08|0x0005) plen 6 #1 [hci0] 27.302496 Address: 15:60:F2:91:B2:24 (Non-Resolvable) > HCI Event: Command Complete (0x0e) plen 4 #2 [hci0] 27.419117 LE Set Random Address (0x08|0x0005) ncmd 1 Status: Success (0x00) < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 #3 [hci0] 27.419244 Type: Active (0x01) Interval: 11.250 msec (0x0012) Window: 11.250 msec (0x0012) Own address type: Random (0x01) Filter policy: Accept all advertisement (0x00) > HCI Event: Command Complete (0x0e) plen 4 #4 [hci0] 27.420131 LE Set Random Address (0x08|0x0005) ncmd 1 Status: Success (0x00) < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #5 [hci0] 27.420259 Scanning: Enabled (0x01) Filter duplicates: Enabled (0x01) > HCI Event: Command Complete (0x0e) plen 4 #6 [hci0] 27.420969 LE Set Scan Parameters (0x08|0x000b) ncmd 1 Status: Success (0x00) > HCI Event: Command Complete (0x0e) plen 4 #7 [hci0] 27.421983 LE Set Scan Enable (0x08|0x000c) ncmd 1 Status: Success (0x00) @ MGMT Event: Command Complete (0x0001) plen 4 {0x0003} [hci0] 27.422059 Start Discovery (0x0023) plen 1 Status: Success (0x00) Address type: 0x06 LE Public LE Random @ MGMT Event: Discovering (0x0013) plen 2 {0x0003} [hci0] 27.422067 Address type: 0x06 LE Public LE Random Discovery: Enabled (0x01) @ MGMT Event: Discovering (0x0013) plen 2 {0x0002} [hci0] 27.422067 Address type: 0x06 LE Public LE Random Discovery: Enabled (0x01) @ MGMT Event: Discovering (0x0013) plen 2 {0x0001} [hci0] 27.422067 Address type: 0x06 LE Public LE Random Discovery: Enabled (0x01) In this situation the kernel ends up not processing the command complete event for LE_SET_SCAN_PARAM, so hdev->le_scan_type is never updated to active scanning and no device found events are generated for ADV_SCAN_RSP PDUs. This makes impossible to discover BTLE devices with these controllers. Signed-off-by: João Paulo Rechi Vita --- include/net/bluetooth/hci.h | 4 ++++ include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 3 +++ net/bluetooth/hci_event.c | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index fbba43e9bef5..f100e9d566a0 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -204,6 +204,10 @@ enum { * */ HCI_QUIRK_NON_PERSISTENT_SETUP, + + /* When this quirk is set, no pending HCI commands will be sent until a + * matching command complete for the last command is received. */ + HCI_QUIRK_WAIT_FOR_MATCHING_CC, }; /* HCI device flags */ diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 094e61e07030..85bed4e916d3 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -364,6 +364,7 @@ struct hci_dev { struct sk_buff_head cmd_q; struct sk_buff *sent_cmd; + __u8 sent_cmd_pending_cc; struct mutex req_lock; wait_queue_head_t req_wait_q; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index d6b2540ba7f8..95ab8f9f2514 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -4383,6 +4383,8 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, return; } + hdev->sent_cmd_pending_cc = 0; + /* If the command succeeded and there's still more commands in * this request the request is not yet complete. */ @@ -4493,6 +4495,7 @@ static void hci_cmd_work(struct work_struct *work) hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); if (hdev->sent_cmd) { + hdev->sent_cmd_pending_cc = 1; atomic_dec(&hdev->cmd_cnt); hci_send_frame(hdev, skb); if (test_bit(HCI_RESET, &hdev->flags)) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 609fd6871c5a..1abbca8ce1c2 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3404,6 +3404,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, hci_req_cmd_complete(hdev, *opcode, *status, req_complete, req_complete_skb); + if (hdev->sent_cmd_pending_cc && + test_bit(HCI_QUIRK_WAIT_FOR_MATCHING_CC, &hdev->quirks)) + return; + if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) queue_work(hdev->workqueue, &hdev->cmd_work); } From patchwork Tue Apr 23 07:22:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= X-Patchwork-Id: 1089107 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="r8dIQV0/"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44pFKg2rZZz9s9G for ; Tue, 23 Apr 2019 17:23:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbfDWHXG (ORCPT ); Tue, 23 Apr 2019 03:23:06 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39957 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726385AbfDWHXF (ORCPT ); Tue, 23 Apr 2019 03:23:05 -0400 Received: by mail-pg1-f196.google.com with SMTP id d31so7138129pgl.7; Tue, 23 Apr 2019 00:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OlEwioMQ7r0YtuF2RvBtp1JPJLlQhSJVNXle47+PAQI=; b=r8dIQV0/4sByEXb/e+Jj4gshDSFYSb320uJvo8jVJ0up1Q7L5HM8rFtuav7lMvdaKU oSa3Q9+rTv2WH4KMsvEVDC0WNrf5r8P0nilPtgTSFesZb6oNVQy1p3emSKYL/jabSCkU HhO2+ILilnW8L/kgkXTpDwWaKiUmQ8oLUD5iI6ub4dog0wPOyctedLUaB7y/rW9ujCpU 8i0vIheNIzUBBsCLCGCYsFnGKzrNXG+FP9it+uHTI5yzq6A6vNHoo+VDtvV+0029WBnk LFuMCo5Z1axqbafcEhrkl3x7BXG3mJvwe96Xm1WgAKVWF/7M8triVarT+2Qhmh+3L3ty RLxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OlEwioMQ7r0YtuF2RvBtp1JPJLlQhSJVNXle47+PAQI=; b=ImpfD4q7zGMc6dlIDjSA0jVSZ/YyuFdVK7+eTTNMSSdVFWZWT5qhpKRjZrjAFjShz7 wRVEZH7Ofz5Wgmni5If3nvkCtbK+jji3nBV/dAXv5lo8pXOyfpUP9ncVx+npUNXnzwzw 7IqTzexAfyBtd9kU/jERTrJaUgBmxa+uvaA09JCUO9zcUDwruNjIGMM0CrBQFnEXaKE9 RxvQ4M6zrNnH4zQZ4bBUceHLAPcH+ocoLflXqZPRLxR7hCS6i0h7f5ChIYIjGYJtcg2F 4SG7nfwxRCW6O5GzlzH2Jd5KscYHkIEQTeBMNYvCZQwAFQKbHfZi6wGL40EpiyhedYXR Jh7w== X-Gm-Message-State: APjAAAU6zYKlMhDrDMnB2z/5EjM+BsBq/QUWtsmEY7SS23CLnkiXLRXl 8Y7pO0AHsyvd9Bbhr9Crdoo= X-Google-Smtp-Source: APXvYqxlTOTD4oTWMYMFxKPdKSvkuT9GMWkJEAy9GegJb6Ps/r/LeqE5ekxdqEnrmjuc4KvhvdxnuA== X-Received: by 2002:a62:fb0a:: with SMTP id x10mr24868078pfm.179.1556004184662; Tue, 23 Apr 2019 00:23:04 -0700 (PDT) Received: from localhost.localdomain (123-204-46-122.static.seed.net.tw. [123.204.46.122]) by smtp.gmail.com with ESMTPSA id p20sm12560594pgj.86.2019.04.23.00.23.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 00:23:04 -0700 (PDT) From: "=?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?=" X-Google-Original-From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= To: Marcel Holtmann , Johan Hedberg Cc: bgodavar@codeaurora.org, ytkim@qca.qualcomm.com, "David S . Miller" , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com, =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= Subject: [PATCH 2/2] Bluetooth: Set HCI_QUIRK_WAIT_FOR_MATCHING_CC for QCA9377 Date: Tue, 23 Apr 2019 15:22:36 +0800 Message-Id: <20190423072236.24999-3-jprvita@endlessm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190423072236.24999-1-jprvita@endlessm.com> References: <20190423072236.24999-1-jprvita@endlessm.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The QCA9377 devices send an extra command complete for the LE_SET_RANDOM_ADDR when trying to start an active scanning procedure. It has to be ignored to avoid confusing the kernel into thinking a passive scanning procedure is being performed instead, which makes impossible to discover BTLE devices since no device found events are generated for passive scanning. Signed-off-by: João Paulo Rechi Vita --- drivers/bluetooth/btusb.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index ded198328f21..650ba4b7908a 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -70,6 +70,7 @@ static struct usb_driver btusb_driver; #define BTUSB_BCM2045 0x40000 #define BTUSB_IFNUM_2 0x80000 #define BTUSB_CW6622 0x100000 +#define BTUSB_QCA9377 0x200000 static const struct usb_device_id btusb_table[] = { /* Generic Bluetooth USB device */ @@ -394,6 +395,10 @@ static const struct usb_device_id blacklist_table[] = { /* Silicon Wave based devices */ { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_SWAVE }, + /* QCA9377 devices */ + { USB_DEVICE(0x13d3, 0x3491), .driver_info = BTUSB_QCA9377 }, + { USB_DEVICE(0x13d3, 0x3501), .driver_info = BTUSB_QCA9377 }, + { } /* Terminating entry */ }; @@ -3196,6 +3201,10 @@ static int btusb_probe(struct usb_interface *intf, btusb_check_needs_reset_resume(intf); } + if (id->driver_info & BTUSB_QCA9377) { + set_bit(HCI_QUIRK_WAIT_FOR_MATCHING_CC, &hdev->quirks); + } + #ifdef CONFIG_BT_HCIBTUSB_RTL if (id->driver_info & BTUSB_REALTEK) { hdev->setup = btrtl_setup_realtek;