]>
Commit | Line | Data |
---|---|---|
e9a2dd26 MH |
1 | /* |
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> | |
18aeb444 | 27 | #include <linux/firmware.h> |
e9a2dd26 MH |
28 | |
29 | #include <net/bluetooth/bluetooth.h> | |
30 | #include <net/bluetooth/hci_core.h> | |
31 | ||
bdd8818e | 32 | #include "btbcm.h" |
e9a2dd26 | 33 | #include "hci_uart.h" |
bdd8818e MH |
34 | |
35 | struct bcm_data { | |
36 | struct sk_buff *rx_skb; | |
37 | struct sk_buff_head txq; | |
38 | }; | |
39 | ||
40 | static int bcm_open(struct hci_uart *hu) | |
41 | { | |
42 | struct bcm_data *bcm; | |
43 | ||
44 | BT_DBG("hu %p", hu); | |
45 | ||
46 | bcm = kzalloc(sizeof(*bcm), GFP_KERNEL); | |
47 | if (!bcm) | |
48 | return -ENOMEM; | |
49 | ||
50 | skb_queue_head_init(&bcm->txq); | |
51 | ||
52 | hu->priv = bcm; | |
53 | return 0; | |
54 | } | |
55 | ||
56 | static int bcm_close(struct hci_uart *hu) | |
57 | { | |
58 | struct bcm_data *bcm = hu->priv; | |
59 | ||
60 | BT_DBG("hu %p", hu); | |
61 | ||
62 | skb_queue_purge(&bcm->txq); | |
63 | kfree_skb(bcm->rx_skb); | |
64 | kfree(bcm); | |
65 | ||
66 | hu->priv = NULL; | |
67 | return 0; | |
68 | } | |
69 | ||
70 | static int bcm_flush(struct hci_uart *hu) | |
71 | { | |
72 | struct bcm_data *bcm = hu->priv; | |
73 | ||
74 | BT_DBG("hu %p", hu); | |
75 | ||
76 | skb_queue_purge(&bcm->txq); | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | static int bcm_setup(struct hci_uart *hu) | |
82 | { | |
83 | BT_DBG("hu %p", hu); | |
84 | ||
85 | hu->hdev->set_bdaddr = btbcm_set_bdaddr; | |
86 | ||
87 | return btbcm_setup_patchram(hu->hdev); | |
88 | } | |
89 | ||
79b8df93 MH |
90 | static const struct h4_recv_pkt bcm_recv_pkts[] = { |
91 | { H4_RECV_ACL, .recv = hci_recv_frame }, | |
92 | { H4_RECV_SCO, .recv = hci_recv_frame }, | |
93 | { H4_RECV_EVENT, .recv = hci_recv_frame }, | |
94 | }; | |
95 | ||
bdd8818e MH |
96 | static int bcm_recv(struct hci_uart *hu, const void *data, int count) |
97 | { | |
98 | struct bcm_data *bcm = hu->priv; | |
99 | ||
100 | if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) | |
101 | return -EUNATCH; | |
102 | ||
79b8df93 MH |
103 | bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count, |
104 | bcm_recv_pkts, ARRAY_SIZE(bcm_recv_pkts)); | |
bdd8818e MH |
105 | if (IS_ERR(bcm->rx_skb)) { |
106 | int err = PTR_ERR(bcm->rx_skb); | |
107 | BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err); | |
108 | return err; | |
109 | } | |
110 | ||
111 | return count; | |
112 | } | |
113 | ||
114 | static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb) | |
115 | { | |
116 | struct bcm_data *bcm = hu->priv; | |
117 | ||
118 | BT_DBG("hu %p skb %p", hu, skb); | |
119 | ||
120 | /* Prepend skb with frame type */ | |
121 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | |
122 | skb_queue_tail(&bcm->txq, skb); | |
123 | ||
124 | return 0; | |
125 | } | |
126 | ||
127 | static struct sk_buff *bcm_dequeue(struct hci_uart *hu) | |
128 | { | |
129 | struct bcm_data *bcm = hu->priv; | |
130 | ||
131 | return skb_dequeue(&bcm->txq); | |
132 | } | |
133 | ||
134 | static const struct hci_uart_proto bcm_proto = { | |
135 | .id = HCI_UART_BCM, | |
136 | .name = "BCM", | |
137 | .open = bcm_open, | |
138 | .close = bcm_close, | |
139 | .flush = bcm_flush, | |
140 | .setup = bcm_setup, | |
141 | .recv = bcm_recv, | |
142 | .enqueue = bcm_enqueue, | |
143 | .dequeue = bcm_dequeue, | |
144 | }; | |
145 | ||
146 | int __init bcm_init(void) | |
147 | { | |
148 | return hci_uart_register_proto(&bcm_proto); | |
149 | } | |
150 | ||
151 | int __exit bcm_deinit(void) | |
152 | { | |
153 | return hci_uart_unregister_proto(&bcm_proto); | |
154 | } |