From patchwork Wed Nov 15 07:20:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitkumar Karwar X-Patchwork-Id: 10058897 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86E7B601D3 for ; Wed, 15 Nov 2017 07:28:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 773CA29DBE for ; Wed, 15 Nov 2017 07:28:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A76729DCF; Wed, 15 Nov 2017 07:28:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A470A29DBE for ; Wed, 15 Nov 2017 07:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754867AbdKOH2n (ORCPT ); Wed, 15 Nov 2017 02:28:43 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:54071 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754772AbdKOH2k (ORCPT ); Wed, 15 Nov 2017 02:28:40 -0500 Received: by mail-pf0-f194.google.com with SMTP id b6so16162182pff.10; Tue, 14 Nov 2017 23:28:39 -0800 (PST) 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; bh=aGgywK3ET+BgdQjwapF+cQzfjxkdM6PAMZkmcx97Yjw=; b=L17gchW/kv9vz/H2u56qIzgXJMgX1xVewqqexQ/SRZa17ij37vj2//G5mmSiGtj3oZ iUJwvOh5ZzTWP9fZ5Leeqt3L0+7uzdbzFV8//EaP23xMdOaHjUyv+bKfU3O7zKkrgsS6 xipLE2UumNQJrSMWS+PbT09NEOil13bZuabfaRA6y0UrzaIZzeoIXquRntflH2C4cUid CbuQnd8RFHUtEZhGcgqUEUDk9M6c6YRT7qIq8DEoLulYCGHdrG4PZJi9mzY6zw/KCWHP OmJLBduJMjaq1Og8Th1o8zXLlANLI6McGldlxtiQDzcyDmOufGxCK7fEb95fbeWXYsl5 v1TQ== 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; bh=aGgywK3ET+BgdQjwapF+cQzfjxkdM6PAMZkmcx97Yjw=; b=OpLTn7R9oSfuFwIkuy1onJGfm7LW/TNA6s3yzki1fDbIeDh0RbJCFVCdF1UEZWbJkf c2PnXHn/mgmzHGPguHBI0y+zJ7JghJu6lk+P4HpEJQ8y+pvb9MsNA/qIEiwqJljaz8B8 P37vPomIdgCPkRVE/8O7gVGbEs2zqOgZ1ycU9J53Wjl/+K29YQoCwLVh+SMAhr3adK9W aUvn/PDh74PcHP0RDWkhmkJ8axFMJGcWgEOr1RIFn9IMNgfMwsYQ04Oq45GsIudmzkSk ZM4n89jhJJumFCPJRdabecB6xXrvSIOKWhUIyh6oo15u/VQHK3bdvcbCKGun0xauWAeN cRSA== X-Gm-Message-State: AJaThX5Vhh0582JXbCOvPKeTLi2NudqSHFLC394xlrvcCFvB5Bg0geXS +1BkahDDHJohXpSAugNqjJ6xiQ== X-Google-Smtp-Source: AGs4zMakGeGvqP698HCEIRnb3mEQcHLCEt/XoWvBkhUw050F4px7Pae21Cqvv0kL0NzCIJiaFcXGEA== X-Received: by 10.84.164.104 with SMTP id m37mr15026155plg.242.1510730919298; Tue, 14 Nov 2017 23:28:39 -0800 (PST) Received: from cpu185.redpinesignals.com ([203.196.161.90]) by smtp.gmail.com with ESMTPSA id y5sm14975850pfa.128.2017.11.14.23.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Nov 2017 23:28:38 -0800 (PST) From: Amitkumar Karwar To: Kalle Valo , marcel@holtmann.org Cc: linux-wireless@vger.kernel.org, Amitkumar Karwar , Prameela Rani Garnepudi , linux-bluetooth@vger.kernel.org, Siva Rebbagondla Subject: [PATCH 5/8] Bluetooth: btrsi: add new rsi bluetooth driver Date: Wed, 15 Nov 2017 12:50:41 +0530 Message-Id: <1510730444-3237-6-git-send-email-amitkarwar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510730444-3237-1-git-send-email-amitkarwar@gmail.com> References: <1510730444-3237-1-git-send-email-amitkarwar@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Prameela Rani Garnepudi Redpine bluetooth driver is a thin driver which depends on 'rsi_91x' driver for transmitting and receiving packets to/from device. It creates hci interface when attach() is called from 'rsi_91x' module. Signed-off-by: Prameela Rani Garnepudi Signed-off-by: Siva Rebbagondla Signed-off-by: Amitkumar Karwar --- drivers/bluetooth/Kconfig | 12 ++ drivers/bluetooth/Makefile | 2 + drivers/bluetooth/btrsi.c | 268 ++++++++++++++++++++++++++++++++++++++++++++ drivers/bluetooth/rsi_hci.h | 51 +++++++++ 4 files changed, 333 insertions(+) create mode 100644 drivers/bluetooth/btrsi.c create mode 100644 drivers/bluetooth/rsi_hci.h diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 60e1c7d..ca58d74 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -378,4 +378,16 @@ config BT_QCOMSMD Say Y here to compile support for HCI over Qualcomm SMD into the kernel or say M to compile as a module. +config BT_RSI + tristate "Redpine HCI support" + depends on BT && BT_RFCOMM + default m + help + Redpine BT driver. + This driver handles BT traffic from upper layers and pass + to the RSI_91x coex module for further scheduling to device + + Say Y here to compile support for HCI over Qualcomm SMD into the + kernel or say M to compile as a module. + endmenu diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 4e4e44d..712af83a 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -28,6 +28,8 @@ obj-$(CONFIG_BT_QCA) += btqca.o obj-$(CONFIG_BT_HCIUART_NOKIA) += hci_nokia.o +obj-$(CONFIG_BT_RSI) += btrsi.o + btmrvl-y := btmrvl_main.o btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o diff --git a/drivers/bluetooth/btrsi.c b/drivers/bluetooth/btrsi.c new file mode 100644 index 0000000..c52f418 --- /dev/null +++ b/drivers/bluetooth/btrsi.c @@ -0,0 +1,268 @@ +/** + * Copyright (c) 2017 Redpine Signals Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +e* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include +#include +#include +#include "rsi_hci.h" + +static struct rsi_mod_ops rsi_bt_ops = { + .attach = rsi_hci_attach, + .detach = rsi_hci_detach, + .recv_pkt = rsi_hci_recv_pkt, +}; + +static int rsi_hci_open(struct hci_dev *hdev) +{ + BT_INFO("%s open\n", hdev->name); + + return 0; +} + +static int rsi_hci_close(struct hci_dev *hdev) +{ + BT_INFO("%s closed\n", hdev->name); + + return 0; +} + +static int rsi_hci_flush(struct hci_dev *hdev) +{ + BT_ERR("%s flush\n", hdev->name); + + return 0; +} + +static int rsi_hci_send_pkt(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct rsi_hci_adapter *h_adapter; + struct sk_buff *new_skb = NULL; + + int status = 0; + + h_adapter = hci_get_drvdata(hdev); + if (!h_adapter) { + status = -EFAULT; + goto fail; + } + + if (h_adapter->fsm_state != RSI_BT_FSM_DEVICE_READY) { + BT_INFO("BT Device not ready\n"); + status = -ENODEV; + goto fail; + } + + if (!test_bit(HCI_RUNNING, &hdev->flags)) { + status = -EBUSY; + goto fail; + } + + switch (bt_cb(skb)->pkt_type) { + case HCI_COMMAND_PKT: + hdev->stat.cmd_tx++; + break; + + case HCI_ACLDATA_PKT: + hdev->stat.acl_tx++; + break; + + case HCI_SCODATA_PKT: + hdev->stat.sco_tx++; + break; + + default: + dev_kfree_skb(skb); + status = -EILSEQ; + goto fail; + } + + if (skb_headroom(skb) < RSI_HEADROOM_FOR_BT_HAL) { + /* Re-allocate one more skb with sufficent headroom */ + /* Space for Descriptor (16 bytes) is required in head room */ + u16 new_len = skb->len + RSI_HEADROOM_FOR_BT_HAL; + + new_skb = dev_alloc_skb(new_len); + if (!new_skb) { + dev_kfree_skb(skb); + return -ENOMEM; + } + skb_reserve(new_skb, RSI_HEADROOM_FOR_BT_HAL); + skb_put(new_skb, skb->len); + memcpy(new_skb->data, skb->data, skb->len); + bt_cb(new_skb)->pkt_type = bt_cb(skb)->pkt_type; + dev_kfree_skb(skb); + skb = new_skb; + } + if (h_adapter->proto_ops->coex_send_pkt) + return h_adapter->proto_ops->coex_send_pkt(h_adapter->priv, skb, + RSI_BT_Q); + +fail: + dev_kfree_skb(skb); + return status; +} + +int rsi_hci_recv_pkt(void *priv, u8 *pkt) +{ + struct rsi_hci_adapter *h_adapter = (struct rsi_hci_adapter *)priv; + struct hci_dev *hdev = NULL; + struct sk_buff *skb; + int pkt_len = (le16_to_cpu(*(__le16 *)pkt)) & 0x0fff; + u8 queue_no = (le16_to_cpu(*(__le16 *)pkt) & 0x7000) >> 12; + + if (h_adapter->fsm_state != RSI_BT_FSM_DEVICE_READY) { + BT_INFO("BT Device not ready\n"); + return 0; + } + + if (queue_no == RSI_BT_MGMT_Q) { + u8 msg_type = pkt[14] & 0xFF; + + switch (msg_type) { + case RSI_RESULT_CONFIRM: + BT_INFO("BT Result Confirm\n"); + return 0; + case RSI_BT_BER: + BT_INFO("BT Ber\n"); + return 0; + case RSI_BT_CW: + BT_INFO("BT CW\n"); + return 0; + default: + break; + } + } + + skb = dev_alloc_skb(pkt_len); + if (!skb) + return -ENOMEM; + + hdev = h_adapter->hdev; + memcpy(skb->data, pkt + RSI_FRAME_DESC_SIZE, pkt_len); + skb_put(skb, pkt_len); + h_adapter->hdev->stat.byte_rx += skb->len; + + skb->dev = (void *)hdev; + bt_cb(skb)->pkt_type = pkt[14]; + + return hci_recv_frame(hdev, skb); +} +EXPORT_SYMBOL_GPL(rsi_hci_recv_pkt); + +int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops) +{ + struct rsi_hci_adapter *h_adapter = NULL; + struct hci_dev *hdev; + int status = 0; + + h_adapter = kzalloc(sizeof(*h_adapter), GFP_KERNEL); + if (!h_adapter) + return -ENOMEM; + + h_adapter->priv = priv; + ops->set_bt_context(priv, h_adapter); + h_adapter->proto_ops = ops; + ops->bt_ops = &rsi_bt_ops; + h_adapter->fsm_state = RSI_BT_FSM_DEVICE_READY; + + hdev = hci_alloc_dev(); + if (!hdev) { + BT_ERR("Failed to alloc HCI device\n"); + goto err; + } + h_adapter->hdev = hdev; + + if (ops->get_host_intf(priv) == RSI_HOST_INTF_SDIO) + hdev->bus = HCI_SDIO; + else + hdev->bus = HCI_USB; + + hci_set_drvdata(hdev, h_adapter); + hdev->dev_type = HCI_PRIMARY; + hdev->open = rsi_hci_open; + hdev->close = rsi_hci_close; + hdev->flush = rsi_hci_flush; + hdev->send = rsi_hci_send_pkt; + + status = hci_register_dev(hdev); + if (status < 0) { + BT_ERR("%s: HCI registration failed with errcode %d\n", + __func__, status); + goto err; + } + + BT_INFO("%s interface created\n", hdev->name); + + h_adapter->fsm_state = RSI_BT_FSM_DEVICE_READY; + + return 0; + +err: + if (hdev) { + hci_unregister_dev(hdev); + hci_free_dev(hdev); + h_adapter->hdev = NULL; + } + kfree(h_adapter); + + return -EINVAL; +} + +void rsi_hci_detach(void *priv) +{ + struct rsi_hci_adapter *h_adapter = (struct rsi_hci_adapter *)priv; + struct hci_dev *hdev; + + if (!h_adapter) + return; + + hdev = h_adapter->hdev; + + BT_INFO("Detaching %s\n", hdev->name); + + if (hdev) { + hci_unregister_dev(hdev); + hci_free_dev(hdev); + h_adapter->hdev = NULL; + } + + kfree(h_adapter); + h_adapter->fsm_state = RSI_BT_FSM_DEVICE_NOT_READY; +} + +struct rsi_mod_ops *rsi_get_hci_ops(void) +{ + return &rsi_bt_ops; +}; +EXPORT_SYMBOL_GPL(rsi_get_hci_ops); + +static int rsi_91x_bt_module_init(void) +{ + BT_INFO("%s: BT Module init called\n", __func__); + + return 0; +} + +static void rsi_91x_bt_module_exit(void) +{ + BT_INFO("%s: BT Module exit called\n", __func__); +} + +module_init(rsi_91x_bt_module_init); +module_exit(rsi_91x_bt_module_exit); +MODULE_AUTHOR("Redpine Signals Inc"); +MODULE_DESCRIPTION("RSI BT driver"); +MODULE_SUPPORTED_DEVICE("RSI-BT"); +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/bluetooth/rsi_hci.h b/drivers/bluetooth/rsi_hci.h new file mode 100644 index 0000000..6f44231 --- /dev/null +++ b/drivers/bluetooth/rsi_hci.h @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2017 Redpine Signals Inc. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __RSI_HCI_H__ +#define __RSI_HCI_H__ + +#include +#include +#include +#include + +/* RX frame types */ +#define RSI_RESULT_CONFIRM 0x80 +#define RSI_BT_PER 0x10 +#define RSI_BT_BER 0x11 +#define RSI_BT_CW 0x12 + +#define RSI_HEADROOM_FOR_BT_HAL 16 + +enum bt_fsm_state { + RSI_BT_FSM_DEVICE_NOT_READY = 0, + RSI_BT_FSM_DEVICE_READY, +}; + +struct rsi_hci_adapter { + void *priv; + struct rsi_proto_ops *proto_ops; + enum bt_fsm_state fsm_state; + struct hci_dev *hdev; +}; + +#define RSI_FRAME_DESC_SIZE 16 + +int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops); +void rsi_hci_detach(void *priv); +int rsi_hci_recv_pkt(void *data, u8 *pkt); + +#endif