hci_unit.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: hci_unit.c,v 1.1.2.2 2006/06/21 15:10:51 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*-
4 1.1.2.2 yamt * Copyright (c) 2005 Iain Hibbert.
5 1.1.2.2 yamt * Copyright (c) 2006 Itronix Inc.
6 1.1.2.2 yamt * All rights reserved.
7 1.1.2.2 yamt *
8 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 yamt * modification, are permitted provided that the following conditions
10 1.1.2.2 yamt * are met:
11 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
16 1.1.2.2 yamt * 3. The name of Itronix Inc. may not be used to endorse
17 1.1.2.2 yamt * or promote products derived from this software without specific
18 1.1.2.2 yamt * prior written permission.
19 1.1.2.2 yamt *
20 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21 1.1.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24 1.1.2.2 yamt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 1.1.2.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 1.1.2.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 1.1.2.2 yamt * ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
31 1.1.2.2 yamt */
32 1.1.2.2 yamt
33 1.1.2.2 yamt #include <sys/cdefs.h>
34 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: hci_unit.c,v 1.1.2.2 2006/06/21 15:10:51 yamt Exp $");
35 1.1.2.2 yamt
36 1.1.2.2 yamt #include <sys/param.h>
37 1.1.2.2 yamt #include <sys/conf.h>
38 1.1.2.2 yamt #include <sys/device.h>
39 1.1.2.2 yamt #include <sys/kernel.h>
40 1.1.2.2 yamt #include <sys/malloc.h>
41 1.1.2.2 yamt #include <sys/mbuf.h>
42 1.1.2.2 yamt #include <sys/proc.h>
43 1.1.2.2 yamt #include <sys/queue.h>
44 1.1.2.2 yamt #include <sys/systm.h>
45 1.1.2.2 yamt
46 1.1.2.2 yamt #include <netbt/bluetooth.h>
47 1.1.2.2 yamt #include <netbt/hci.h>
48 1.1.2.2 yamt
49 1.1.2.2 yamt struct hci_unit_list hci_unit_list = SIMPLEQ_HEAD_INITIALIZER(hci_unit_list);
50 1.1.2.2 yamt
51 1.1.2.2 yamt MALLOC_DEFINE(M_BLUETOOTH, "Bluetooth", "Bluetooth System Memory");
52 1.1.2.2 yamt
53 1.1.2.2 yamt /*
54 1.1.2.2 yamt * HCI Input Queue max lengths.
55 1.1.2.2 yamt */
56 1.1.2.2 yamt int hci_eventq_max = 20;
57 1.1.2.2 yamt int hci_aclrxq_max = 50;
58 1.1.2.2 yamt int hci_scorxq_max = 50;
59 1.1.2.2 yamt
60 1.1.2.2 yamt /*
61 1.1.2.2 yamt * bluetooth unit functions
62 1.1.2.2 yamt */
63 1.1.2.2 yamt static void hci_intr (void *);
64 1.1.2.2 yamt
65 1.1.2.2 yamt void
66 1.1.2.2 yamt hci_attach(struct hci_unit *unit)
67 1.1.2.2 yamt {
68 1.1.2.2 yamt
69 1.1.2.2 yamt KASSERT(unit->hci_softc);
70 1.1.2.2 yamt KASSERT(unit->hci_devname);
71 1.1.2.2 yamt KASSERT(unit->hci_enable);
72 1.1.2.2 yamt KASSERT(unit->hci_disable);
73 1.1.2.2 yamt KASSERT(unit->hci_start_cmd);
74 1.1.2.2 yamt KASSERT(unit->hci_start_acl);
75 1.1.2.2 yamt KASSERT(unit->hci_start_sco);
76 1.1.2.2 yamt
77 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_eventq);
78 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_aclrxq);
79 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_scorxq);
80 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_cmdq);
81 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_cmdwait);
82 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_acltxq);
83 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_scotxq);
84 1.1.2.2 yamt MBUFQ_INIT(&unit->hci_scodone);
85 1.1.2.2 yamt
86 1.1.2.2 yamt TAILQ_INIT(&unit->hci_links);
87 1.1.2.2 yamt LIST_INIT(&unit->hci_memos);
88 1.1.2.2 yamt
89 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&hci_unit_list, unit, hci_next);
90 1.1.2.2 yamt }
91 1.1.2.2 yamt
92 1.1.2.2 yamt void
93 1.1.2.2 yamt hci_detach(struct hci_unit *unit)
94 1.1.2.2 yamt {
95 1.1.2.2 yamt
96 1.1.2.2 yamt hci_disable(unit);
97 1.1.2.2 yamt
98 1.1.2.2 yamt SIMPLEQ_REMOVE(&hci_unit_list, unit, hci_unit, hci_next);
99 1.1.2.2 yamt }
100 1.1.2.2 yamt
101 1.1.2.2 yamt int
102 1.1.2.2 yamt hci_enable(struct hci_unit *unit)
103 1.1.2.2 yamt {
104 1.1.2.2 yamt int s, err;
105 1.1.2.2 yamt
106 1.1.2.2 yamt /*
107 1.1.2.2 yamt * Bluetooth spec says that a device can accept one
108 1.1.2.2 yamt * command on power up until they send a Command Status
109 1.1.2.2 yamt * or Command Complete event with more information, but
110 1.1.2.2 yamt * it seems that some devices cant and prefer to send a
111 1.1.2.2 yamt * No-op Command Status packet when they are ready, so
112 1.1.2.2 yamt * we set this here and allow the driver (bt3c) to zero
113 1.1.2.2 yamt * it.
114 1.1.2.2 yamt */
115 1.1.2.2 yamt unit->hci_num_cmd_pkts = 1;
116 1.1.2.2 yamt unit->hci_num_acl_pkts = 0;
117 1.1.2.2 yamt unit->hci_num_sco_pkts = 0;
118 1.1.2.2 yamt
119 1.1.2.2 yamt /*
120 1.1.2.2 yamt * only allow the basic packet types until
121 1.1.2.2 yamt * the features report is in
122 1.1.2.2 yamt */
123 1.1.2.2 yamt unit->hci_acl_mask = HCI_PKT_DM1 | HCI_PKT_DH1;
124 1.1.2.2 yamt unit->hci_packet_type = unit->hci_acl_mask;
125 1.1.2.2 yamt
126 1.1.2.2 yamt unit->hci_rxint = softintr_establish(IPL_SOFTNET, &hci_intr, unit);
127 1.1.2.2 yamt if (unit->hci_rxint == NULL)
128 1.1.2.2 yamt return EIO;
129 1.1.2.2 yamt
130 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
131 1.1.2.2 yamt err = (*unit->hci_enable)(unit);
132 1.1.2.2 yamt splx(s);
133 1.1.2.2 yamt if (err)
134 1.1.2.2 yamt goto bad1;
135 1.1.2.2 yamt
136 1.1.2.2 yamt /*
137 1.1.2.2 yamt * Reset the device, this will trigger initialisation
138 1.1.2.2 yamt * and wake us up.
139 1.1.2.2 yamt */
140 1.1.2.2 yamt unit->hci_flags |= BTF_INIT;
141 1.1.2.2 yamt
142 1.1.2.2 yamt err = hci_send_cmd(unit, HCI_CMD_RESET, NULL, 0);
143 1.1.2.2 yamt if (err)
144 1.1.2.2 yamt goto bad2;
145 1.1.2.2 yamt
146 1.1.2.2 yamt while (unit->hci_flags & BTF_INIT) {
147 1.1.2.2 yamt err = tsleep(unit, PWAIT | PCATCH, __func__, hz);
148 1.1.2.2 yamt if (err)
149 1.1.2.2 yamt goto bad2;
150 1.1.2.2 yamt
151 1.1.2.2 yamt /* XXX
152 1.1.2.2 yamt * "What If", while we were sleeping, the device
153 1.1.2.2 yamt * was removed and detached? Ho Hum.
154 1.1.2.2 yamt */
155 1.1.2.2 yamt }
156 1.1.2.2 yamt
157 1.1.2.2 yamt return 0;
158 1.1.2.2 yamt
159 1.1.2.2 yamt bad2:
160 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
161 1.1.2.2 yamt (*unit->hci_disable)(unit);
162 1.1.2.2 yamt splx(s);
163 1.1.2.2 yamt
164 1.1.2.2 yamt bad1:
165 1.1.2.2 yamt softintr_disestablish(unit->hci_rxint);
166 1.1.2.2 yamt unit->hci_rxint = NULL;
167 1.1.2.2 yamt
168 1.1.2.2 yamt return err;
169 1.1.2.2 yamt }
170 1.1.2.2 yamt
171 1.1.2.2 yamt void
172 1.1.2.2 yamt hci_disable(struct hci_unit *unit)
173 1.1.2.2 yamt {
174 1.1.2.2 yamt struct hci_link *link, *next;
175 1.1.2.2 yamt struct hci_memo *memo;
176 1.1.2.2 yamt int s, acl;
177 1.1.2.2 yamt
178 1.1.2.2 yamt if (unit->hci_rxint) {
179 1.1.2.2 yamt softintr_disestablish(unit->hci_rxint);
180 1.1.2.2 yamt unit->hci_rxint = NULL;
181 1.1.2.2 yamt }
182 1.1.2.2 yamt
183 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
184 1.1.2.2 yamt (*unit->hci_disable)(unit);
185 1.1.2.2 yamt splx(s);
186 1.1.2.2 yamt
187 1.1.2.2 yamt /*
188 1.1.2.2 yamt * close down any links, take care to close SCO first since
189 1.1.2.2 yamt * they may depend on ACL links.
190 1.1.2.2 yamt */
191 1.1.2.2 yamt for (acl = 0 ; acl < 2 ; acl++) {
192 1.1.2.2 yamt next = TAILQ_FIRST(&unit->hci_links);
193 1.1.2.2 yamt while ((link = next) != NULL) {
194 1.1.2.2 yamt next = TAILQ_NEXT(link, hl_next);
195 1.1.2.2 yamt if (acl || link->hl_type != HCI_LINK_ACL)
196 1.1.2.2 yamt hci_link_free(link, ECONNABORTED);
197 1.1.2.2 yamt }
198 1.1.2.2 yamt }
199 1.1.2.2 yamt
200 1.1.2.2 yamt while ((memo = LIST_FIRST(&unit->hci_memos)) != NULL)
201 1.1.2.2 yamt hci_memo_free(memo);
202 1.1.2.2 yamt
203 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_eventq);
204 1.1.2.2 yamt unit->hci_eventqlen = 0;
205 1.1.2.2 yamt
206 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_aclrxq);
207 1.1.2.2 yamt unit->hci_aclrxqlen = 0;
208 1.1.2.2 yamt
209 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_scorxq);
210 1.1.2.2 yamt unit->hci_scorxqlen = 0;
211 1.1.2.2 yamt
212 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_cmdq);
213 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_cmdwait);
214 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_acltxq);
215 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_scotxq);
216 1.1.2.2 yamt MBUFQ_DRAIN(&unit->hci_scodone);
217 1.1.2.2 yamt }
218 1.1.2.2 yamt
219 1.1.2.2 yamt struct hci_unit *
220 1.1.2.2 yamt hci_unit_lookup(bdaddr_t *addr)
221 1.1.2.2 yamt {
222 1.1.2.2 yamt struct hci_unit *unit;
223 1.1.2.2 yamt
224 1.1.2.2 yamt SIMPLEQ_FOREACH(unit, &hci_unit_list, hci_next) {
225 1.1.2.2 yamt if ((unit->hci_flags & BTF_UP) == 0)
226 1.1.2.2 yamt continue;
227 1.1.2.2 yamt
228 1.1.2.2 yamt if (bdaddr_same(&unit->hci_bdaddr, addr))
229 1.1.2.2 yamt break;
230 1.1.2.2 yamt }
231 1.1.2.2 yamt
232 1.1.2.2 yamt return unit;
233 1.1.2.2 yamt }
234 1.1.2.2 yamt
235 1.1.2.2 yamt /*
236 1.1.2.2 yamt * construct and queue a HCI command packet
237 1.1.2.2 yamt */
238 1.1.2.2 yamt int
239 1.1.2.2 yamt hci_send_cmd(struct hci_unit *unit, uint16_t opcode, void *buf, uint8_t len)
240 1.1.2.2 yamt {
241 1.1.2.2 yamt struct mbuf *m;
242 1.1.2.2 yamt hci_cmd_hdr_t *p;
243 1.1.2.2 yamt
244 1.1.2.2 yamt KASSERT(unit);
245 1.1.2.2 yamt
246 1.1.2.2 yamt m = m_gethdr(M_DONTWAIT, MT_DATA);
247 1.1.2.2 yamt if (m == NULL)
248 1.1.2.2 yamt return ENOMEM;
249 1.1.2.2 yamt
250 1.1.2.2 yamt p = mtod(m, hci_cmd_hdr_t *);
251 1.1.2.2 yamt p->type = HCI_CMD_PKT;
252 1.1.2.2 yamt p->opcode = htole16(opcode);
253 1.1.2.2 yamt p->length = len;
254 1.1.2.2 yamt m->m_pkthdr.len = m->m_len = sizeof(hci_cmd_hdr_t);
255 1.1.2.2 yamt
256 1.1.2.2 yamt if (len) {
257 1.1.2.2 yamt KASSERT(buf);
258 1.1.2.2 yamt
259 1.1.2.2 yamt m_copyback(m, sizeof(hci_cmd_hdr_t), len, buf);
260 1.1.2.2 yamt if (m->m_pkthdr.len != (sizeof(hci_cmd_hdr_t) + len)) {
261 1.1.2.2 yamt m_freem(m);
262 1.1.2.2 yamt return ENOMEM;
263 1.1.2.2 yamt }
264 1.1.2.2 yamt }
265 1.1.2.2 yamt
266 1.1.2.2 yamt DPRINTFN(2, "(%s) opcode (%3.3x|%4.4x)\n", unit->hci_devname,
267 1.1.2.2 yamt HCI_OGF(opcode), HCI_OCF(opcode));
268 1.1.2.2 yamt
269 1.1.2.2 yamt /* and send it on */
270 1.1.2.2 yamt if (unit->hci_num_cmd_pkts == 0)
271 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_cmdwait, m);
272 1.1.2.2 yamt else
273 1.1.2.2 yamt hci_output_cmd(unit, m);
274 1.1.2.2 yamt
275 1.1.2.2 yamt return 0;
276 1.1.2.2 yamt }
277 1.1.2.2 yamt
278 1.1.2.2 yamt /*
279 1.1.2.2 yamt * Incoming packet processing. Since the code is single threaded
280 1.1.2.2 yamt * in any case (IPL_SOFTNET), we handle it all in one interrupt function
281 1.1.2.2 yamt * picking our way through more important packets first so that hopefully
282 1.1.2.2 yamt * we will never get clogged up with bulk data.
283 1.1.2.2 yamt */
284 1.1.2.2 yamt static void
285 1.1.2.2 yamt hci_intr(void *arg)
286 1.1.2.2 yamt {
287 1.1.2.2 yamt struct hci_unit *unit = arg;
288 1.1.2.2 yamt struct mbuf *m;
289 1.1.2.2 yamt int s;
290 1.1.2.2 yamt
291 1.1.2.2 yamt another:
292 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
293 1.1.2.2 yamt
294 1.1.2.2 yamt if (unit->hci_eventqlen > 0) {
295 1.1.2.2 yamt MBUFQ_DEQUEUE(&unit->hci_eventq, m);
296 1.1.2.2 yamt unit->hci_eventqlen--;
297 1.1.2.2 yamt KASSERT(m != NULL);
298 1.1.2.2 yamt splx(s);
299 1.1.2.2 yamt
300 1.1.2.2 yamt DPRINTFN(10, "(%s) recv event, len = %d\n",
301 1.1.2.2 yamt unit->hci_devname, m->m_pkthdr.len);
302 1.1.2.2 yamt
303 1.1.2.2 yamt m->m_flags |= M_LINK0; /* mark incoming packet */
304 1.1.2.2 yamt hci_mtap(m, unit);
305 1.1.2.2 yamt hci_event(m, unit);
306 1.1.2.2 yamt
307 1.1.2.2 yamt goto another;
308 1.1.2.2 yamt }
309 1.1.2.2 yamt
310 1.1.2.2 yamt if (unit->hci_scorxqlen > 0) {
311 1.1.2.2 yamt MBUFQ_DEQUEUE(&unit->hci_scorxq, m);
312 1.1.2.2 yamt unit->hci_scorxqlen--;
313 1.1.2.2 yamt KASSERT(m != NULL);
314 1.1.2.2 yamt splx(s);
315 1.1.2.2 yamt
316 1.1.2.2 yamt DPRINTFN(10, "(%s) recv SCO, len = %d\n",
317 1.1.2.2 yamt unit->hci_devname, m->m_pkthdr.len);
318 1.1.2.2 yamt
319 1.1.2.2 yamt m->m_flags |= M_LINK0; /* mark incoming packet */
320 1.1.2.2 yamt hci_mtap(m, unit);
321 1.1.2.2 yamt hci_sco_recv(m, unit);
322 1.1.2.2 yamt
323 1.1.2.2 yamt goto another;
324 1.1.2.2 yamt }
325 1.1.2.2 yamt
326 1.1.2.2 yamt if (unit->hci_aclrxqlen > 0) {
327 1.1.2.2 yamt MBUFQ_DEQUEUE(&unit->hci_aclrxq, m);
328 1.1.2.2 yamt unit->hci_aclrxqlen--;
329 1.1.2.2 yamt KASSERT(m != NULL);
330 1.1.2.2 yamt splx(s);
331 1.1.2.2 yamt
332 1.1.2.2 yamt DPRINTFN(10, "(%s) recv ACL, len = %d\n",
333 1.1.2.2 yamt unit->hci_devname, m->m_pkthdr.len);
334 1.1.2.2 yamt
335 1.1.2.2 yamt m->m_flags |= M_LINK0; /* mark incoming packet */
336 1.1.2.2 yamt hci_mtap(m, unit);
337 1.1.2.2 yamt hci_acl_recv(m, unit);
338 1.1.2.2 yamt
339 1.1.2.2 yamt goto another;
340 1.1.2.2 yamt }
341 1.1.2.2 yamt
342 1.1.2.2 yamt MBUFQ_DEQUEUE(&unit->hci_scodone, m);
343 1.1.2.2 yamt if (m != NULL) {
344 1.1.2.2 yamt struct hci_link *link;
345 1.1.2.2 yamt splx(s);
346 1.1.2.2 yamt
347 1.1.2.2 yamt DPRINTFN(11, "(%s) complete SCO\n",
348 1.1.2.2 yamt unit->hci_devname);
349 1.1.2.2 yamt
350 1.1.2.2 yamt TAILQ_FOREACH(link, &unit->hci_links, hl_next) {
351 1.1.2.2 yamt if (link == M_GETCTX(m, struct hci_link *)) {
352 1.1.2.2 yamt hci_sco_complete(link, 1);
353 1.1.2.2 yamt break;
354 1.1.2.2 yamt }
355 1.1.2.2 yamt }
356 1.1.2.2 yamt
357 1.1.2.2 yamt unit->hci_num_sco_pkts++;
358 1.1.2.2 yamt m_freem(m);
359 1.1.2.2 yamt
360 1.1.2.2 yamt goto another;
361 1.1.2.2 yamt }
362 1.1.2.2 yamt
363 1.1.2.2 yamt splx(s);
364 1.1.2.2 yamt
365 1.1.2.2 yamt DPRINTFN(10, "done\n");
366 1.1.2.2 yamt }
367 1.1.2.2 yamt
368 1.1.2.2 yamt /**********************************************************************
369 1.1.2.2 yamt *
370 1.1.2.2 yamt * IO routines
371 1.1.2.2 yamt *
372 1.1.2.2 yamt * input & complete routines will be called from device driver
373 1.1.2.2 yamt * (at unit->hci_ipl)
374 1.1.2.2 yamt */
375 1.1.2.2 yamt
376 1.1.2.2 yamt void
377 1.1.2.2 yamt hci_input_event(struct hci_unit *unit, struct mbuf *m)
378 1.1.2.2 yamt {
379 1.1.2.2 yamt
380 1.1.2.2 yamt if (unit->hci_eventqlen > hci_eventq_max || unit->hci_rxint == NULL) {
381 1.1.2.2 yamt DPRINTF("(%s) dropped event packet.\n", unit->hci_devname);
382 1.1.2.2 yamt unit->hci_stats.err_rx++;
383 1.1.2.2 yamt m_freem(m);
384 1.1.2.2 yamt } else {
385 1.1.2.2 yamt unit->hci_eventqlen++;
386 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_eventq, m);
387 1.1.2.2 yamt softintr_schedule(unit->hci_rxint);
388 1.1.2.2 yamt }
389 1.1.2.2 yamt }
390 1.1.2.2 yamt
391 1.1.2.2 yamt void
392 1.1.2.2 yamt hci_input_acl(struct hci_unit *unit, struct mbuf *m)
393 1.1.2.2 yamt {
394 1.1.2.2 yamt
395 1.1.2.2 yamt if (unit->hci_aclrxqlen > hci_aclrxq_max || unit->hci_rxint == NULL) {
396 1.1.2.2 yamt DPRINTF("(%s) dropped ACL packet.\n", unit->hci_devname);
397 1.1.2.2 yamt unit->hci_stats.err_rx++;
398 1.1.2.2 yamt m_freem(m);
399 1.1.2.2 yamt } else {
400 1.1.2.2 yamt unit->hci_aclrxqlen++;
401 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_aclrxq, m);
402 1.1.2.2 yamt softintr_schedule(unit->hci_rxint);
403 1.1.2.2 yamt }
404 1.1.2.2 yamt }
405 1.1.2.2 yamt
406 1.1.2.2 yamt void
407 1.1.2.2 yamt hci_input_sco(struct hci_unit *unit, struct mbuf *m)
408 1.1.2.2 yamt {
409 1.1.2.2 yamt
410 1.1.2.2 yamt if (unit->hci_scorxqlen > hci_scorxq_max || unit->hci_rxint == NULL) {
411 1.1.2.2 yamt DPRINTF("(%s) dropped SCO packet.\n", unit->hci_devname);
412 1.1.2.2 yamt unit->hci_stats.err_rx++;
413 1.1.2.2 yamt m_freem(m);
414 1.1.2.2 yamt } else {
415 1.1.2.2 yamt unit->hci_scorxqlen++;
416 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_scorxq, m);
417 1.1.2.2 yamt softintr_schedule(unit->hci_rxint);
418 1.1.2.2 yamt }
419 1.1.2.2 yamt }
420 1.1.2.2 yamt
421 1.1.2.2 yamt void
422 1.1.2.2 yamt hci_output_cmd(struct hci_unit *unit, struct mbuf *m)
423 1.1.2.2 yamt {
424 1.1.2.2 yamt void *arg;
425 1.1.2.2 yamt int s;
426 1.1.2.2 yamt
427 1.1.2.2 yamt hci_mtap(m, unit);
428 1.1.2.2 yamt
429 1.1.2.2 yamt DPRINTFN(10, "(%s) num_cmd_pkts=%d\n", unit->hci_devname,
430 1.1.2.2 yamt unit->hci_num_cmd_pkts);
431 1.1.2.2 yamt
432 1.1.2.2 yamt unit->hci_num_cmd_pkts--;
433 1.1.2.2 yamt
434 1.1.2.2 yamt /*
435 1.1.2.2 yamt * If context is set, this was from a HCI raw socket
436 1.1.2.2 yamt * and a record needs to be dropped from the sockbuf.
437 1.1.2.2 yamt */
438 1.1.2.2 yamt arg = M_GETCTX(m, void *);
439 1.1.2.2 yamt if (arg != NULL)
440 1.1.2.2 yamt hci_drop(arg);
441 1.1.2.2 yamt
442 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
443 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_cmdq, m);
444 1.1.2.2 yamt if ((unit->hci_flags & BTF_XMIT_CMD) == 0)
445 1.1.2.2 yamt (*unit->hci_start_cmd)(unit);
446 1.1.2.2 yamt
447 1.1.2.2 yamt splx(s);
448 1.1.2.2 yamt }
449 1.1.2.2 yamt
450 1.1.2.2 yamt void
451 1.1.2.2 yamt hci_output_acl(struct hci_unit *unit, struct mbuf *m)
452 1.1.2.2 yamt {
453 1.1.2.2 yamt int s;
454 1.1.2.2 yamt
455 1.1.2.2 yamt hci_mtap(m, unit);
456 1.1.2.2 yamt
457 1.1.2.2 yamt DPRINTFN(10, "(%s) num_acl_pkts=%d\n", unit->hci_devname,
458 1.1.2.2 yamt unit->hci_num_acl_pkts);
459 1.1.2.2 yamt
460 1.1.2.2 yamt unit->hci_num_acl_pkts--;
461 1.1.2.2 yamt
462 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
463 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_acltxq, m);
464 1.1.2.2 yamt if ((unit->hci_flags & BTF_XMIT_ACL) == 0)
465 1.1.2.2 yamt (*unit->hci_start_acl)(unit);
466 1.1.2.2 yamt
467 1.1.2.2 yamt splx(s);
468 1.1.2.2 yamt }
469 1.1.2.2 yamt
470 1.1.2.2 yamt void
471 1.1.2.2 yamt hci_output_sco(struct hci_unit *unit, struct mbuf *m)
472 1.1.2.2 yamt {
473 1.1.2.2 yamt int s;
474 1.1.2.2 yamt
475 1.1.2.2 yamt hci_mtap(m, unit);
476 1.1.2.2 yamt
477 1.1.2.2 yamt DPRINTFN(10, "(%s) num_sco_pkts=%d\n", unit->hci_devname,
478 1.1.2.2 yamt unit->hci_num_sco_pkts);
479 1.1.2.2 yamt
480 1.1.2.2 yamt unit->hci_num_sco_pkts--;
481 1.1.2.2 yamt
482 1.1.2.2 yamt s = splraiseipl(unit->hci_ipl);
483 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_scotxq, m);
484 1.1.2.2 yamt if ((unit->hci_flags & BTF_XMIT_SCO) == 0)
485 1.1.2.2 yamt (*unit->hci_start_sco)(unit);
486 1.1.2.2 yamt
487 1.1.2.2 yamt splx(s);
488 1.1.2.2 yamt }
489 1.1.2.2 yamt
490 1.1.2.2 yamt void
491 1.1.2.2 yamt hci_complete_sco(struct hci_unit *unit, struct mbuf *m)
492 1.1.2.2 yamt {
493 1.1.2.2 yamt
494 1.1.2.2 yamt if (unit->hci_rxint == NULL) {
495 1.1.2.2 yamt DPRINTFN(10, "(%s) complete SCO!\n", unit->hci_devname);
496 1.1.2.2 yamt unit->hci_stats.err_rx++;
497 1.1.2.2 yamt m_freem(m);
498 1.1.2.2 yamt } else {
499 1.1.2.2 yamt MBUFQ_ENQUEUE(&unit->hci_scodone, m);
500 1.1.2.2 yamt softintr_schedule(unit->hci_rxint);
501 1.1.2.2 yamt }
502 1.1.2.2 yamt }
503