From patchwork Mon Sep 4 07:18:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 111537 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1167575qge; Mon, 4 Sep 2017 00:18:08 -0700 (PDT) X-Received: by 10.84.175.195 with SMTP id t61mr11224594plb.190.1504509488793; Mon, 04 Sep 2017 00:18:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504509488; cv=none; d=google.com; s=arc-20160816; b=Ke9XixTnE7D5/oAwHehClgksDEmEMvlq03pypKCPyzoP+/cBbr4GqwKuDEqUtt3TU3 rp+4hHXXGXJni9/VNFX/3ICEBUMN6aevXpMTn+BO+XM5eEp94POzr3H1O9UmfEO27OjB DmHf5+Ukk4czD/dLJW9onOyc2Gw/qq+80eLVZ75IlJRoMBRbQvgMr+Do8b23BvY+82Mq ddNCtke1gtkTCNep+c1css/cY4EA9cPXts9Hl3cn+Zh/1TMMVQipSZcMwUO5uvajiEkM XdEp+xsY+E8gJtpw9jO4/w0Rbam1lbN0Jsf2cecYcGjtlnMDXgMY/1Rtvh1S0nq1Iy6g h5qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=H4g0aD7PP63j3lq65HkzTN3ymG9/Fuc1htbpKxEzcdY=; b=eaourY9g/M5BecLjuW6JnPprtb1HmuPYyJ0bC3KDYZfU4eTv5ARXvRoiN7BqgyRruN 5FWduEoPIEzKznPB9+7fG2OGtAikEfF+7OwEeQyfFFmuF821scH0D+zd2HPUAkgTWJ05 BU4vumc6g7J/WVSAbqh7vihMqEcEQxezMeom235Cs2UQtDhfwtqE3QEdOI8SuTFBQKeE ymzMftrPB1Z4wCJ9T8qYB9RWSSLeWuCyOtIwebeHGRnYxC8u2I6gOXUuLFimuLcwWVLy FI0I2gQVSwEQ+OZyGRBcuSh1+9D3HLpHNi/QjQbZuvMu/cDgqofFq3AftpTRo7zKTRDX bPjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=e6nOmaSG; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u132si4491426pgc.404.2017.09.04.00.18.08; Mon, 04 Sep 2017 00:18:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=e6nOmaSG; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753291AbdIDHSG (ORCPT + 9 others); Mon, 4 Sep 2017 03:18:06 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36732 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752624AbdIDHSE (ORCPT ); Mon, 4 Sep 2017 03:18:04 -0400 Received: by mail-wm0-f41.google.com with SMTP id i145so14196881wmf.1 for ; Mon, 04 Sep 2017 00:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=N+ss3hjDpmL5GRhLe04v8PX3dmgh0VHmsbmK9lzqXWk=; b=e6nOmaSGXH+F9XRv2ZlZwYjEwZ1nx6gf5wozCO93taDxFwd22Gt+cUYSSjFrnS63t0 ea7mN4DoFcuXwCP0b2ATRKo0nfQ1R9f+z18g9ZyIowxxIkREAyjNWQy0n3Kgc0Vz9qEI K4tnSo2tR1rZP63DlOc4ERd5rSfX1jKGTmb48= 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; bh=N+ss3hjDpmL5GRhLe04v8PX3dmgh0VHmsbmK9lzqXWk=; b=ba3MjsdISMBhnONPAtksWFknzJ0tdFQurjQENkbCpkgpPI5yqoYDVJPGxiUw/MZU/H g0jAkdJvS1z50/NI4SUgOmr3hZSTn9TInqMnq+4+NhGmnoBjAg/wEf8ew0j3IirE6jB6 EpfuH8A9SXsdpB4H1yjPHDkwKQYnOAlO4OWdqCsdTNBU15BYVaDoVPSet9FM8DJc7M6e z6FKZgAYVzhO5g5dteCv5/Wh2eParaHvkLNe0JYwJUB/9DazvTxuXUf40ngcXH8zwG8E OIMePvzpZ3fojSdqIKow6Ph4wHo7fj6LUk033+FeNVF0fdYn9RK7UplDaTj9gMfI9OdQ Lv+Q== X-Gm-Message-State: AHPjjUhdStBoxvODZMfRkLekDL3ceavYmrOCx7jsOpAHpkWsX+Ryt5mI xw/Aoh36C3CCd5lT X-Google-Smtp-Source: ADKCNb5ViRj3iGw/LCTJ5OzWMsJsVUUTZui2Qpds8uNF/VUSYEnGr0oturJGagfn1cvO6RlU4K+MLg== X-Received: by 10.28.137.19 with SMTP id l19mr3212508wmd.98.1504509483307; Mon, 04 Sep 2017 00:18:03 -0700 (PDT) Received: from localhost.localdomain ([80.12.59.52]) by smtp.gmail.com with ESMTPSA id g70sm11241533wrd.4.2017.09.04.00.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 00:18:02 -0700 (PDT) From: Loic Poulain To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, Loic Poulain Subject: [PATCH v2] Bluetooth: btqcomsmd: BD address setup Date: Mon, 4 Sep 2017 09:18:00 +0200 Message-Id: <1504509480-14082-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Bluetooth BD address can be retrieved in the same way as for wcnss-wlan MAC address. This patch mainly stores the local-mac-address property and sets the BD address during hci device setup. If the default BD address is detected, mark the device as unconfigured. Signed-off-by: Loic Poulain --- drivers/bluetooth/btqcomsmd.c | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) v2: Set device as unconfigured if default address detected Add warning if BD addr retrieved from DT -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c index d00c4fd..e07df69 100644 --- a/drivers/bluetooth/btqcomsmd.c +++ b/drivers/bluetooth/btqcomsmd.c @@ -15,6 +15,8 @@ #include #include #include +#include + #include #include @@ -23,9 +25,12 @@ #include "btqca.h" +#define BDADDR_QCOMSMD (&(bdaddr_t) {{0xAD, 0x5A, 0x00, 0x00, 0x00, 0x00}}) + struct btqcomsmd { struct hci_dev *hdev; + const bdaddr_t *addr; struct rpmsg_endpoint *acl_channel; struct rpmsg_endpoint *cmd_channel; }; @@ -100,6 +105,58 @@ static int btqcomsmd_close(struct hci_dev *hdev) return 0; } +static int btqcomsmd_setup(struct hci_dev *hdev) +{ + struct btqcomsmd *btq = hci_get_drvdata(hdev); + struct hci_rp_read_bd_addr *bda; + struct sk_buff *skb; + + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) + return PTR_ERR(skb); + kfree_skb(skb); + + if (btq->addr) { + bdaddr_t bdaddr; + + /* Having a unique BD address is critical, the retrieved address + * coming from the local-mac-address device-tree property must + * be provisioned with a valid per-device address. + * Usually, this address is added to the DT by the bootloader + * which has access to the provisioned data. + */ + bt_dev_warn(hdev, "BD address %pM coming from device-tree might" + " be invalid or non-unique", btq->addr); + + /* btq->addr stored with most significant byte first */ + baswap(&bdaddr, btq->addr); + qca_set_bdaddr_rome(hdev, &bdaddr); + } + + skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL, + HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) + return PTR_ERR(skb); + + if (skb->len != sizeof(*bda)) { + bt_dev_err(hdev, "Device address length mismatch"); + kfree_skb(skb); + return -EIO; + } + + /* Mark the controller with invalid BD address flag if the + * returned address is the default one (00:00:00:00:5A:AD). + */ + bda = (struct hci_rp_read_bd_addr *)skb->data; + if (!bacmp(&bda->bdaddr, BDADDR_QCOMSMD)) { + bt_dev_err(hdev, "Found invalid qcomsmd default address %pMR", + BDADDR_QCOMSMD); + set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + } + + return 0; +} + static int btqcomsmd_probe(struct platform_device *pdev) { struct btqcomsmd *btq; @@ -123,6 +180,11 @@ static int btqcomsmd_probe(struct platform_device *pdev) if (IS_ERR(btq->cmd_channel)) return PTR_ERR(btq->cmd_channel); + btq->addr = of_get_property(pdev->dev.of_node, "local-mac-address", + &ret); + if (ret != sizeof(bdaddr_t)) + btq->addr = NULL; + hdev = hci_alloc_dev(); if (!hdev) return -ENOMEM; @@ -135,6 +197,7 @@ static int btqcomsmd_probe(struct platform_device *pdev) hdev->open = btqcomsmd_open; hdev->close = btqcomsmd_close; hdev->send = btqcomsmd_send; + hdev->setup = btqcomsmd_setup; hdev->set_bdaddr = qca_set_bdaddr_rome; ret = hci_register_dev(hdev);