From patchwork Mon Feb 19 13:19:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitkumar Karwar X-Patchwork-Id: 10227849 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 5066E60392 for ; Mon, 19 Feb 2018 13:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F95528709 for ; Mon, 19 Feb 2018 13:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3464D28911; Mon, 19 Feb 2018 13:31:25 +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 6505628709 for ; Mon, 19 Feb 2018 13:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752884AbeBSNbW (ORCPT ); Mon, 19 Feb 2018 08:31:22 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35838 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752875AbeBSNbT (ORCPT ); Mon, 19 Feb 2018 08:31:19 -0500 Received: by mail-pg0-f65.google.com with SMTP id l131so5874271pga.2; Mon, 19 Feb 2018 05:31:19 -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=bUYsUw4d4p1dBtwx7ePT5j3u5VE1AcUuMWb3nxCNSCw=; b=TRJ7ltCBzxLpqRPBDQRqBUq4FlpLyQHboQrhUCY6jil2UA6L/1kZaM+0XmTozbS9Pm 8hK2HDG6GxN8ZVQYuRNyycFCb+j2CridlqBeZYiI060YE/rVy3CKGigIon40zVkMOwBt Qbxpnd3hZtwr8uaVn5Zg/9g3/7R43jGRTlxU/HqwvO4tnJCUpZdyIxMWG1Ra4YerdHoX wiFd9cbX94wiMkw+YpWo7gyC1U3z5jIy75vIA9OSZ4TaV+ohfk6u8+648GKaEw/og2oj p2B0u4MysK3TjoacxHAxJDZFTLK9oTV1rMDEpWb2jtaTJ4ZqSgBluUXFyoXTmLfoF4rL Epkg== 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=bUYsUw4d4p1dBtwx7ePT5j3u5VE1AcUuMWb3nxCNSCw=; b=rzjeEFi/WuO9B3CltoZ0+uh9GZMNLWs+Ic2kWWwfhdLhjiucwT8F3LtQttz9GQwLMP xuuKaI2LgQdvUhQZSgywuy4ON5t6UBKPveW5HhK2Tz1WoRUIeaHO8sxTTe8plrULhxkb w7VCf87HMekRy/vKxNuRk6qNDH5oy0WuK1GlATdz8lLBCE2w8vtnof4XbBTjn20Qx83n o1HpymaRIMwXzspk89khXynx6vA8rEnHc5R2GZ+zP8H88LT5UijEPJL3+Y+8cRPuz/mA l3shS6C7rXVfOOLaD8J4hwBfacm8Dr4tLd9xA7p1gzCRAabjwLN/32bXE3x71FQrwxQB 326Q== X-Gm-Message-State: APf1xPAqODgs90E1eZHrw6Jc4KkxOs1Zf6WDBvTdtydumADQagzhkXTY 7lImNDgL7Knh/kqwCGs2D3s= X-Google-Smtp-Source: AH8x224LuwETESsUpJZTLF2ZbAe+vlQu5MaFXkCUc+vRrjQJ1APAiAIkDmkzsgOwJGWVxhBwwgAQ1g== X-Received: by 10.101.65.9 with SMTP id w9mr12371843pgp.214.1519047078931; Mon, 19 Feb 2018 05:31:18 -0800 (PST) Received: from cpu185.redpinesignals.com ([203.196.161.90]) by smtp.gmail.com with ESMTPSA id m24sm32584982pgv.14.2018.02.19.05.31.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Feb 2018 05:31:18 -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: [v7 5/8] Bluetooth: btrsi: add new rsi bluetooth driver Date: Mon, 19 Feb 2018 18:49:36 +0530 Message-Id: <1519046379-10068-6-git-send-email-amitkarwar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519046379-10068-1-git-send-email-amitkarwar@gmail.com> References: <1519046379-10068-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 Acked-by: Marcel Holtmann Reviewed-by: Marcel Holtmann Signed-off-by: Amitkumar Karwar --- v7: Same as v6 v6: Renamed CONFIG_BT_RSI to CONFIG_BT_HCIRSI (Marcel) v5: Addressed review comments from Marcel. Removed reduntant switch case code from rsi_hci_recv_pkt() Changed bt_cb(skb)->pkt_type to hci_skb_pkt_type(skb) Removed reduntant '\n' from BT_ERR and redundant BT_INFO messages Changed u8 *pkt to const u8 *pkt in rsi_hci_recv_pkt() v4: Removed rsi_hci.h file. Made the functions static(Marcel) v3: Made BT_RSI module by default off(Marcel) Removed redundant exported function rsi_get_hci_ops()(Marcel) v2: Addressed review comments from Marcel Removed unnecessary 'depends on BT && BT_RFOMM' line in Kconfig Removed redundant BT_INFO messages h_adapter initialization and declaration in a single line. Removed unnecessary error checks for HCI_RUNNING and fsm_state Allocated new skb with skb_realloc_headroom() API if headroom is not sufficient Used get_unaligned_le16 helpers Moved a structure and union from header file to btrsi.c file --- drivers/bluetooth/Kconfig | 12 +++ drivers/bluetooth/Makefile | 2 + drivers/bluetooth/btrsi.c | 188 +++++++++++++++++++++++++++++++++++++++++++++ include/net/rsi_91x.h | 4 +- 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 drivers/bluetooth/btrsi.c diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 07e55cd..d8bbd66 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -392,4 +392,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_HCIRSI + tristate "Redpine HCI support" + default n + select RSI_COEX + 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 Redpine into the + kernel or say M to compile as a module. + endmenu diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 4e4e44d..03cfc1b 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_HCIRSI) += 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..803e045 --- /dev/null +++ b/drivers/bluetooth/btrsi.c @@ -0,0 +1,188 @@ +/** + * 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define RSI_HEADROOM_FOR_BT_HAL 16 +#define RSI_FRAME_DESC_SIZE 16 + +struct rsi_hci_adapter { + void *priv; + struct rsi_proto_ops *proto_ops; + struct hci_dev *hdev; +}; + +static int rsi_hci_open(struct hci_dev *hdev) +{ + return 0; +} + +static int rsi_hci_close(struct hci_dev *hdev) +{ + return 0; +} + +static int rsi_hci_flush(struct hci_dev *hdev) +{ + return 0; +} + +static int rsi_hci_send_pkt(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct rsi_hci_adapter *h_adapter = hci_get_drvdata(hdev); + struct sk_buff *new_skb = NULL; + + switch (hci_skb_pkt_type(skb)) { + 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; + } + + if (skb_headroom(skb) < RSI_HEADROOM_FOR_BT_HAL) { + /* Insufficient skb headroom - allocate a new skb */ + new_skb = skb_realloc_headroom(skb, RSI_HEADROOM_FOR_BT_HAL); + if (unlikely(!new_skb)) + return -ENOMEM; + bt_cb(new_skb)->pkt_type = hci_skb_pkt_type(skb); + kfree_skb(skb); + skb = new_skb; + } + + return h_adapter->proto_ops->coex_send_pkt(h_adapter->priv, skb, + RSI_BT_Q); +} + +static int rsi_hci_recv_pkt(void *priv, const u8 *pkt) +{ + struct rsi_hci_adapter *h_adapter = priv; + struct hci_dev *hdev = h_adapter->hdev; + struct sk_buff *skb; + int pkt_len = get_unaligned_le16(pkt) & 0x0fff; + + skb = dev_alloc_skb(pkt_len); + if (!skb) + return -ENOMEM; + + memcpy(skb->data, pkt + RSI_FRAME_DESC_SIZE, pkt_len); + skb_put(skb, pkt_len); + h_adapter->hdev->stat.byte_rx += skb->len; + + hci_skb_pkt_type(skb) = pkt[14]; + + return hci_recv_frame(hdev, skb); +} + +static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops) +{ + struct rsi_hci_adapter *h_adapter = NULL; + struct hci_dev *hdev; + int err = 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; + + hdev = hci_alloc_dev(); + if (!hdev) { + BT_ERR("Failed to alloc HCI device"); + 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; + + err = hci_register_dev(hdev); + if (err < 0) { + BT_ERR("HCI registration failed with errcode %d", err); + hci_free_dev(hdev); + goto err; + } + + return 0; +err: + h_adapter->hdev = NULL; + kfree(h_adapter); + return -EINVAL; +} + +static void rsi_hci_detach(void *priv) +{ + struct rsi_hci_adapter *h_adapter = priv; + struct hci_dev *hdev; + + if (!h_adapter) + return; + + hdev = h_adapter->hdev; + if (hdev) { + hci_unregister_dev(hdev); + hci_free_dev(hdev); + h_adapter->hdev = NULL; + } + + kfree(h_adapter); +} + +const struct rsi_mod_ops rsi_bt_ops = { + .attach = rsi_hci_attach, + .detach = rsi_hci_detach, + .recv_pkt = rsi_hci_recv_pkt, +}; +EXPORT_SYMBOL(rsi_bt_ops); + +static int rsi_91x_bt_module_init(void) +{ + return 0; +} + +static void rsi_91x_bt_module_exit(void) +{ + return; +} + +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/include/net/rsi_91x.h b/include/net/rsi_91x.h index 737ab4e..040f07b 100644 --- a/include/net/rsi_91x.h +++ b/include/net/rsi_91x.h @@ -49,6 +49,8 @@ struct rsi_proto_ops { struct rsi_mod_ops { int (*attach)(void *priv, struct rsi_proto_ops *ops); void (*detach)(void *priv); - int (*recv_pkt)(void *priv, u8 *msg); + int (*recv_pkt)(void *priv, const u8 *msg); }; + +extern const struct rsi_mod_ops rsi_bt_ops; #endif