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