All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amitkumar Karwar <amitkarwar@gmail.com>
To: Kalle Valo <kvalo@codeaurora.org>, marcel@holtmann.org
Cc: linux-wireless@vger.kernel.org,
	Amitkumar Karwar <amit.karwar@redpinesignals.com>,
	Prameela Rani Garnepudi <prameela.j04cs@gmail.com>,
	linux-bluetooth@vger.kernel.org,
	Siva Rebbagondla <siva.rebbagondla@redpinesignals.com>
Subject: [v5 5/8] Bluetooth: btrsi: add new rsi bluetooth driver
Date: Wed, 13 Dec 2017 18:12:54 +0530	[thread overview]
Message-ID: <1513168977-2121-6-git-send-email-amitkarwar@gmail.com> (raw)
In-Reply-To: <1513168977-2121-1-git-send-email-amitkarwar@gmail.com>

From: Prameela Rani Garnepudi <prameela.j04cs@gmail.com>

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 <prameela.j04cs@gmail.com>
Signed-off-by: Siva Rebbagondla <siva.rebbagondla@redpinesignals.com>
Signed-off-by: Amitkumar Karwar <amit.karwar@redpinesignals.com>
---
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  |  11 +++
 drivers/bluetooth/Makefile |   2 +
 drivers/bluetooth/btrsi.c  | 188 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/rsi_header.h |   4 +-
 4 files changed, 204 insertions(+), 1 deletion(-)
 create mode 100644 drivers/bluetooth/btrsi.c

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 60e1c7d..33d7514 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -378,4 +378,15 @@ 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"
+	default n
+	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..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..c9e92cc
--- /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 <linux/version.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+#include <linux/unaligned/le_byteshift.h>
+#include <linux/rsi_header.h>
+#include <net/genetlink.h>
+
+#define RSI_HEADROOM_FOR_BT_HAL	16
+#define RSI_FRAME_DESC_SIZE	16
+
+static 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/linux/rsi_header.h b/include/linux/rsi_header.h
index 737ab4e..040f07b 100644
--- a/include/linux/rsi_header.h
+++ b/include/linux/rsi_header.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
-- 
2.7.4

  parent reply	other threads:[~2017-12-13 12:51 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 12:42 [v5 0/8] rsi: add bluetooth and coex support Amitkumar Karwar
2017-12-13 12:42 ` [v5 1/8] rsi: add rx control block to handle rx packets in USB Amitkumar Karwar
2018-02-01  6:30   ` Kalle Valo
2018-02-01  6:30     ` Kalle Valo
2018-02-13 10:20     ` Amitkumar Karwar
2017-12-13 12:42 ` [v5 2/8] rsi: add bluetooth rx endpoint Amitkumar Karwar
2017-12-13 12:42 ` [v5 3/8] rsi: add header file rsi_header Amitkumar Karwar
2018-02-01  6:39   ` Kalle Valo
2018-02-01  6:39     ` Kalle Valo
2018-02-13 10:22     ` Amitkumar Karwar
2017-12-13 12:42 ` [v5 4/8] rsi: add coex support Amitkumar Karwar
2018-02-01  6:56   ` Kalle Valo
2018-02-01  6:56     ` Kalle Valo
2018-02-13 10:39     ` Amitkumar Karwar
2018-02-13 15:37       ` Kalle Valo
2018-02-13 15:37         ` Kalle Valo
2018-02-16 14:46         ` Amitkumar Karwar
2018-02-01  7:08   ` Kalle Valo
2018-02-01  7:08     ` Kalle Valo
2018-02-13 10:40     ` Amitkumar Karwar
2017-12-13 12:42 ` Amitkumar Karwar [this message]
2017-12-13 13:46   ` [v5 5/8] Bluetooth: btrsi: add new rsi bluetooth driver Marcel Holtmann
2017-12-14 14:22     ` Amitkumar Karwar
2018-01-19  6:53       ` Amitkumar Karwar
2018-02-01  6:58     ` Kalle Valo
2018-02-01  6:58       ` Kalle Valo
2018-02-01  8:16       ` Marcel Holtmann
2018-02-01  8:34         ` Kalle Valo
2018-02-01  8:34           ` Kalle Valo
2017-12-13 12:42 ` [v5 6/8] rsi: handle BT traffic in driver Amitkumar Karwar
2018-02-01  7:10   ` Kalle Valo
2018-02-01  7:10     ` Kalle Valo
2017-12-13 12:42 ` [v5 7/8] rsi: add module parameter operating mode Amitkumar Karwar
2018-02-01  7:11   ` Kalle Valo
2018-02-01  7:11     ` Kalle Valo
2018-02-01  8:20     ` Marcel Holtmann
2018-02-01  8:36       ` Kalle Valo
2018-02-01  8:36         ` Kalle Valo
2017-12-13 12:42 ` [v5 8/8] rsi: sdio changes to support BT Amitkumar Karwar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513168977-2121-6-git-send-email-amitkarwar@gmail.com \
    --to=amitkarwar@gmail.com \
    --cc=amit.karwar@redpinesignals.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=prameela.j04cs@gmail.com \
    --cc=siva.rebbagondla@redpinesignals.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.