blob: fe1905c4beb2bbe941ac723c785653a3c8029e63 [file] [log] [blame]
Marcel Holtmanne9a2dd22015-04-04 16:13:03 -07001/*
2 *
3 * Bluetooth HCI UART driver for Broadcom devices
4 *
5 * Copyright (C) 2015 Intel Corporation
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/skbuff.h>
27
28#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h>
30
Marcel Holtmannbdd88182015-04-05 22:52:18 -070031#include "btbcm.h"
Marcel Holtmanne9a2dd22015-04-04 16:13:03 -070032#include "hci_uart.h"
Marcel Holtmannbdd88182015-04-05 22:52:18 -070033
34struct bcm_data {
35 struct sk_buff *rx_skb;
36 struct sk_buff_head txq;
37};
38
39static int bcm_open(struct hci_uart *hu)
40{
41 struct bcm_data *bcm;
42
43 BT_DBG("hu %p", hu);
44
45 bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
46 if (!bcm)
47 return -ENOMEM;
48
49 skb_queue_head_init(&bcm->txq);
50
51 hu->priv = bcm;
52 return 0;
53}
54
55static int bcm_close(struct hci_uart *hu)
56{
57 struct bcm_data *bcm = hu->priv;
58
59 BT_DBG("hu %p", hu);
60
61 skb_queue_purge(&bcm->txq);
62 kfree_skb(bcm->rx_skb);
63 kfree(bcm);
64
65 hu->priv = NULL;
66 return 0;
67}
68
69static int bcm_flush(struct hci_uart *hu)
70{
71 struct bcm_data *bcm = hu->priv;
72
73 BT_DBG("hu %p", hu);
74
75 skb_queue_purge(&bcm->txq);
76
77 return 0;
78}
79
80static int bcm_setup(struct hci_uart *hu)
81{
82 BT_DBG("hu %p", hu);
83
84 hu->hdev->set_bdaddr = btbcm_set_bdaddr;
85
86 return btbcm_setup_patchram(hu->hdev);
87}
88
89static int bcm_recv(struct hci_uart *hu, const void *data, int count)
90{
91 struct bcm_data *bcm = hu->priv;
92
93 if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
94 return -EUNATCH;
95
96 bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count);
97 if (IS_ERR(bcm->rx_skb)) {
98 int err = PTR_ERR(bcm->rx_skb);
99 BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err);
100 return err;
101 }
102
103 return count;
104}
105
106static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
107{
108 struct bcm_data *bcm = hu->priv;
109
110 BT_DBG("hu %p skb %p", hu, skb);
111
112 /* Prepend skb with frame type */
113 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
114 skb_queue_tail(&bcm->txq, skb);
115
116 return 0;
117}
118
119static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
120{
121 struct bcm_data *bcm = hu->priv;
122
123 return skb_dequeue(&bcm->txq);
124}
125
126static const struct hci_uart_proto bcm_proto = {
127 .id = HCI_UART_BCM,
128 .name = "BCM",
129 .open = bcm_open,
130 .close = bcm_close,
131 .flush = bcm_flush,
132 .setup = bcm_setup,
133 .recv = bcm_recv,
134 .enqueue = bcm_enqueue,
135 .dequeue = bcm_dequeue,
136};
137
138int __init bcm_init(void)
139{
140 return hci_uart_register_proto(&bcm_proto);
141}
142
143int __exit bcm_deinit(void)
144{
145 return hci_uart_unregister_proto(&bcm_proto);
146}