| @@ -1,23 +1,24 @@ | | | @@ -1,23 +1,24 @@ |
1 | /* $NetBSD: uhci.c,v 1.240.6.1 2011/12/04 13:23:17 jmcneill Exp $ */ | | 1 | /* $NetBSD: uhci.c,v 1.240.6.1.2.1 2011/12/08 08:56:57 mrg Exp $ */ |
2 | /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.33 1999/11/17 22:33:41 n_hibma Exp $ */ | | 2 | /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.33 1999/11/17 22:33:41 n_hibma Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. | | 5 | * Copyright (c) 1998, 2004, 2011 The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Lennart Augustsson (lennart@augustsson.net) at | | 9 | * by Lennart Augustsson (lennart@augustsson.net) at |
10 | * Carlstedt Research & Technology. | | 10 | * Carlstedt Research & Technology, Jared D. McNeill (jmcneill@invisible.ca) |
| | | 11 | * and Matthew R. Green. |
11 | * | | 12 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 13 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 14 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 15 | * are met: |
15 | * 1. Redistributions of source code must retain the above copyright | | 16 | * 1. Redistributions of source code must retain the above copyright |
16 | * notice, this list of conditions and the following disclaimer. | | 17 | * notice, this list of conditions and the following disclaimer. |
17 | * 2. Redistributions in binary form must reproduce the above copyright | | 18 | * 2. Redistributions in binary form must reproduce the above copyright |
18 | * notice, this list of conditions and the following disclaimer in the | | 19 | * notice, this list of conditions and the following disclaimer in the |
19 | * documentation and/or other materials provided with the distribution. | | 20 | * documentation and/or other materials provided with the distribution. |
20 | * | | 21 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 22 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 23 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 24 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| @@ -32,34 +33,34 @@ | | | @@ -32,34 +33,34 @@ |
32 | */ | | 33 | */ |
33 | | | 34 | |
34 | /* | | 35 | /* |
35 | * USB Universal Host Controller driver. | | 36 | * USB Universal Host Controller driver. |
36 | * Handles e.g. PIIX3 and PIIX4. | | 37 | * Handles e.g. PIIX3 and PIIX4. |
37 | * | | 38 | * |
38 | * UHCI spec: http://www.intel.com/technology/usb/spec.htm | | 39 | * UHCI spec: http://www.intel.com/technology/usb/spec.htm |
39 | * USB spec: http://www.usb.org/developers/docs/ | | 40 | * USB spec: http://www.usb.org/developers/docs/ |
40 | * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf | | 41 | * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf |
41 | * ftp://download.intel.com/design/intarch/datashts/29056201.pdf | | 42 | * ftp://download.intel.com/design/intarch/datashts/29056201.pdf |
42 | */ | | 43 | */ |
43 | | | 44 | |
44 | #include <sys/cdefs.h> | | 45 | #include <sys/cdefs.h> |
45 | __KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.240.6.1 2011/12/04 13:23:17 jmcneill Exp $"); | | 46 | __KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.240.6.1.2.1 2011/12/08 08:56:57 mrg Exp $"); |
46 | | | 47 | |
47 | #include "opt_usb.h" | | 48 | #include "opt_usb.h" |
48 | | | 49 | |
49 | #include <sys/param.h> | | 50 | #include <sys/param.h> |
50 | #include <sys/systm.h> | | 51 | #include <sys/systm.h> |
51 | #include <sys/kernel.h> | | 52 | #include <sys/kernel.h> |
52 | #include <sys/malloc.h> | | 53 | #include <sys/kmem.h> |
53 | #include <sys/device.h> | | 54 | #include <sys/device.h> |
54 | #include <sys/select.h> | | 55 | #include <sys/select.h> |
55 | #include <sys/extent.h> | | 56 | #include <sys/extent.h> |
56 | #include <sys/proc.h> | | 57 | #include <sys/proc.h> |
57 | #include <sys/queue.h> | | 58 | #include <sys/queue.h> |
58 | #include <sys/bus.h> | | 59 | #include <sys/bus.h> |
59 | | | 60 | |
60 | #include <machine/endian.h> | | 61 | #include <machine/endian.h> |
61 | | | 62 | |
62 | #include <dev/usb/usb.h> | | 63 | #include <dev/usb/usb.h> |
63 | #include <dev/usb/usbdi.h> | | 64 | #include <dev/usb/usbdi.h> |
64 | #include <dev/usb/usbdivar.h> | | 65 | #include <dev/usb/usbdivar.h> |
65 | #include <dev/usb/usb_mem.h> | | 66 | #include <dev/usb/usb_mem.h> |
| @@ -161,26 +162,28 @@ Static void uhci_remove_ls_ctrl(uhci_so | | | @@ -161,26 +162,28 @@ Static void uhci_remove_ls_ctrl(uhci_so |
161 | Static void uhci_remove_hs_ctrl(uhci_softc_t *,uhci_soft_qh_t *); | | 162 | Static void uhci_remove_hs_ctrl(uhci_softc_t *,uhci_soft_qh_t *); |
162 | Static void uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *); | | 163 | Static void uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *); |
163 | Static void uhci_add_loop(uhci_softc_t *sc); | | 164 | Static void uhci_add_loop(uhci_softc_t *sc); |
164 | Static void uhci_rem_loop(uhci_softc_t *sc); | | 165 | Static void uhci_rem_loop(uhci_softc_t *sc); |
165 | | | 166 | |
166 | Static usbd_status uhci_setup_isoc(usbd_pipe_handle pipe); | | 167 | Static usbd_status uhci_setup_isoc(usbd_pipe_handle pipe); |
167 | Static void uhci_device_isoc_enter(usbd_xfer_handle); | | 168 | Static void uhci_device_isoc_enter(usbd_xfer_handle); |
168 | | | 169 | |
169 | Static usbd_status uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t); | | 170 | Static usbd_status uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t); |
170 | Static void uhci_freem(struct usbd_bus *, usb_dma_t *); | | 171 | Static void uhci_freem(struct usbd_bus *, usb_dma_t *); |
171 | | | 172 | |
172 | Static usbd_xfer_handle uhci_allocx(struct usbd_bus *); | | 173 | Static usbd_xfer_handle uhci_allocx(struct usbd_bus *); |
173 | Static void uhci_freex(struct usbd_bus *, usbd_xfer_handle); | | 174 | Static void uhci_freex(struct usbd_bus *, usbd_xfer_handle); |
| | | 175 | Static void uhci_get_locks(struct usbd_bus *, kmutex_t **, |
| | | 176 | kmutex_t **); |
174 | | | 177 | |
175 | Static usbd_status uhci_device_ctrl_transfer(usbd_xfer_handle); | | 178 | Static usbd_status uhci_device_ctrl_transfer(usbd_xfer_handle); |
176 | Static usbd_status uhci_device_ctrl_start(usbd_xfer_handle); | | 179 | Static usbd_status uhci_device_ctrl_start(usbd_xfer_handle); |
177 | Static void uhci_device_ctrl_abort(usbd_xfer_handle); | | 180 | Static void uhci_device_ctrl_abort(usbd_xfer_handle); |
178 | Static void uhci_device_ctrl_close(usbd_pipe_handle); | | 181 | Static void uhci_device_ctrl_close(usbd_pipe_handle); |
179 | Static void uhci_device_ctrl_done(usbd_xfer_handle); | | 182 | Static void uhci_device_ctrl_done(usbd_xfer_handle); |
180 | | | 183 | |
181 | Static usbd_status uhci_device_intr_transfer(usbd_xfer_handle); | | 184 | Static usbd_status uhci_device_intr_transfer(usbd_xfer_handle); |
182 | Static usbd_status uhci_device_intr_start(usbd_xfer_handle); | | 185 | Static usbd_status uhci_device_intr_start(usbd_xfer_handle); |
183 | Static void uhci_device_intr_abort(usbd_xfer_handle); | | 186 | Static void uhci_device_intr_abort(usbd_xfer_handle); |
184 | Static void uhci_device_intr_close(usbd_pipe_handle); | | 187 | Static void uhci_device_intr_close(usbd_pipe_handle); |
185 | Static void uhci_device_intr_done(usbd_xfer_handle); | | 188 | Static void uhci_device_intr_done(usbd_xfer_handle); |
186 | | | 189 | |
| @@ -271,88 +274,88 @@ UREAD4(uhci_softc_t *sc, bus_size_t r) | | | @@ -271,88 +274,88 @@ UREAD4(uhci_softc_t *sc, bus_size_t r) |
271 | return bus_space_read_4(sc->iot, sc->ioh, r); | | 274 | return bus_space_read_4(sc->iot, sc->ioh, r); |
272 | } | | 275 | } |
273 | | | 276 | |
274 | #define UHCICMD(sc, cmd) UWRITE2(sc, UHCI_CMD, cmd) | | 277 | #define UHCICMD(sc, cmd) UWRITE2(sc, UHCI_CMD, cmd) |
275 | #define UHCISTS(sc) UREAD2(sc, UHCI_STS) | | 278 | #define UHCISTS(sc) UREAD2(sc, UHCI_STS) |
276 | | | 279 | |
277 | #define UHCI_RESET_TIMEOUT 100 /* ms, reset timeout */ | | 280 | #define UHCI_RESET_TIMEOUT 100 /* ms, reset timeout */ |
278 | | | 281 | |
279 | #define UHCI_CURFRAME(sc) (UREAD2(sc, UHCI_FRNUM) & UHCI_FRNUM_MASK) | | 282 | #define UHCI_CURFRAME(sc) (UREAD2(sc, UHCI_FRNUM) & UHCI_FRNUM_MASK) |
280 | | | 283 | |
281 | #define UHCI_INTR_ENDPT 1 | | 284 | #define UHCI_INTR_ENDPT 1 |
282 | | | 285 | |
283 | const struct usbd_bus_methods uhci_bus_methods = { | | 286 | const struct usbd_bus_methods uhci_bus_methods = { |
284 | uhci_open, | | 287 | .open_pipe = uhci_open, |
285 | uhci_softintr, | | 288 | .soft_intr = uhci_softintr, |
286 | uhci_poll, | | 289 | .do_poll = uhci_poll, |
287 | uhci_allocm, | | 290 | .allocm = uhci_allocm, |
288 | uhci_freem, | | 291 | .freem = uhci_freem, |
289 | uhci_allocx, | | 292 | .allocx = uhci_allocx, |
290 | uhci_freex, | | 293 | .freex = uhci_freex, |
291 | NULL, /* uhci_get_locks */ | | 294 | .get_locks = uhci_get_locks, |
292 | }; | | 295 | }; |
293 | | | 296 | |
294 | const struct usbd_pipe_methods uhci_root_ctrl_methods = { | | 297 | const struct usbd_pipe_methods uhci_root_ctrl_methods = { |
295 | uhci_root_ctrl_transfer, | | 298 | .transfer = uhci_root_ctrl_transfer, |
296 | uhci_root_ctrl_start, | | 299 | .start = uhci_root_ctrl_start, |
297 | uhci_root_ctrl_abort, | | 300 | .abort = uhci_root_ctrl_abort, |
298 | uhci_root_ctrl_close, | | 301 | .close = uhci_root_ctrl_close, |
299 | uhci_noop, | | 302 | .cleartoggle = uhci_noop, |
300 | uhci_root_ctrl_done, | | 303 | .done = uhci_root_ctrl_done, |
301 | }; | | 304 | }; |
302 | | | 305 | |
303 | const struct usbd_pipe_methods uhci_root_intr_methods = { | | 306 | const struct usbd_pipe_methods uhci_root_intr_methods = { |
304 | uhci_root_intr_transfer, | | 307 | .transfer = uhci_root_intr_transfer, |
305 | uhci_root_intr_start, | | 308 | .start = uhci_root_intr_start, |
306 | uhci_root_intr_abort, | | 309 | .abort = uhci_root_intr_abort, |
307 | uhci_root_intr_close, | | 310 | .close = uhci_root_intr_close, |
308 | uhci_noop, | | 311 | .cleartoggle = uhci_noop, |
309 | uhci_root_intr_done, | | 312 | .done = uhci_root_intr_done, |
310 | }; | | 313 | }; |
311 | | | 314 | |
312 | const struct usbd_pipe_methods uhci_device_ctrl_methods = { | | 315 | const struct usbd_pipe_methods uhci_device_ctrl_methods = { |
313 | uhci_device_ctrl_transfer, | | 316 | .transfer = uhci_device_ctrl_transfer, |
314 | uhci_device_ctrl_start, | | 317 | .start = uhci_device_ctrl_start, |
315 | uhci_device_ctrl_abort, | | 318 | .abort = uhci_device_ctrl_abort, |
316 | uhci_device_ctrl_close, | | 319 | .close = uhci_device_ctrl_close, |
317 | uhci_noop, | | 320 | .cleartoggle = uhci_noop, |
318 | uhci_device_ctrl_done, | | 321 | .done = uhci_device_ctrl_done, |
319 | }; | | 322 | }; |
320 | | | 323 | |
321 | const struct usbd_pipe_methods uhci_device_intr_methods = { | | 324 | const struct usbd_pipe_methods uhci_device_intr_methods = { |
322 | uhci_device_intr_transfer, | | 325 | .transfer = uhci_device_intr_transfer, |
323 | uhci_device_intr_start, | | 326 | .start = uhci_device_intr_start, |
324 | uhci_device_intr_abort, | | 327 | .abort = uhci_device_intr_abort, |
325 | uhci_device_intr_close, | | 328 | .close = uhci_device_intr_close, |
326 | uhci_device_clear_toggle, | | 329 | .cleartoggle = uhci_device_clear_toggle, |
327 | uhci_device_intr_done, | | 330 | .done = uhci_device_intr_done, |
328 | }; | | 331 | }; |
329 | | | 332 | |
330 | const struct usbd_pipe_methods uhci_device_bulk_methods = { | | 333 | const struct usbd_pipe_methods uhci_device_bulk_methods = { |
331 | uhci_device_bulk_transfer, | | 334 | .transfer = uhci_device_bulk_transfer, |
332 | uhci_device_bulk_start, | | 335 | .start = uhci_device_bulk_start, |
333 | uhci_device_bulk_abort, | | 336 | .abort = uhci_device_bulk_abort, |
334 | uhci_device_bulk_close, | | 337 | .close = uhci_device_bulk_close, |
335 | uhci_device_clear_toggle, | | 338 | .cleartoggle = uhci_device_clear_toggle, |
336 | uhci_device_bulk_done, | | 339 | .done = uhci_device_bulk_done, |
337 | }; | | 340 | }; |
338 | | | 341 | |
339 | const struct usbd_pipe_methods uhci_device_isoc_methods = { | | 342 | const struct usbd_pipe_methods uhci_device_isoc_methods = { |
340 | uhci_device_isoc_transfer, | | 343 | .transfer = uhci_device_isoc_transfer, |
341 | uhci_device_isoc_start, | | 344 | .start = uhci_device_isoc_start, |
342 | uhci_device_isoc_abort, | | 345 | .abort = uhci_device_isoc_abort, |
343 | uhci_device_isoc_close, | | 346 | .close = uhci_device_isoc_close, |
344 | uhci_noop, | | 347 | .cleartoggle = uhci_noop, |
345 | uhci_device_isoc_done, | | 348 | .done = uhci_device_isoc_done, |
346 | }; | | 349 | }; |
347 | | | 350 | |
348 | #define uhci_add_intr_info(sc, ii) \ | | 351 | #define uhci_add_intr_info(sc, ii) \ |
349 | LIST_INSERT_HEAD(&(sc)->sc_intrhead, (ii), list) | | 352 | LIST_INSERT_HEAD(&(sc)->sc_intrhead, (ii), list) |
350 | #define uhci_del_intr_info(ii) \ | | 353 | #define uhci_del_intr_info(ii) \ |
351 | do { \ | | 354 | do { \ |
352 | LIST_REMOVE((ii), list); \ | | 355 | LIST_REMOVE((ii), list); \ |
353 | (ii)->list.le_prev = NULL; \ | | 356 | (ii)->list.le_prev = NULL; \ |
354 | } while (0) | | 357 | } while (0) |
355 | #define uhci_active_intr_info(ii) ((ii)->list.le_prev != NULL) | | 358 | #define uhci_active_intr_info(ii) ((ii)->list.le_prev != NULL) |
356 | | | 359 | |
357 | static inline uhci_soft_qh_t * | | 360 | static inline uhci_soft_qh_t * |
358 | uhci_find_prev_qh(uhci_soft_qh_t *pqh, uhci_soft_qh_t *sqh) | | 361 | uhci_find_prev_qh(uhci_soft_qh_t *pqh, uhci_soft_qh_t *sqh) |
| @@ -513,27 +516,31 @@ uhci_init(uhci_softc_t *sc) | | | @@ -513,27 +516,31 @@ uhci_init(uhci_softc_t *sc) |
513 | j < UHCI_FRAMELIST_COUNT; | | 516 | j < UHCI_FRAMELIST_COUNT; |
514 | j += UHCI_VFRAMELIST_COUNT) | | 517 | j += UHCI_VFRAMELIST_COUNT) |
515 | sc->sc_pframes[j] = htole32(std->physaddr); | | 518 | sc->sc_pframes[j] = htole32(std->physaddr); |
516 | } | | 519 | } |
517 | usb_syncmem(&sc->sc_dma, 0, | | 520 | usb_syncmem(&sc->sc_dma, 0, |
518 | UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t), | | 521 | UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t), |
519 | BUS_DMASYNC_PREWRITE); | | 522 | BUS_DMASYNC_PREWRITE); |
520 | | | 523 | |
521 | | | 524 | |
522 | LIST_INIT(&sc->sc_intrhead); | | 525 | LIST_INIT(&sc->sc_intrhead); |
523 | | | 526 | |
524 | SIMPLEQ_INIT(&sc->sc_free_xfers); | | 527 | SIMPLEQ_INIT(&sc->sc_free_xfers); |
525 | | | 528 | |
526 | callout_init(&sc->sc_poll_handle, 0); | | 529 | callout_init(&sc->sc_poll_handle, CALLOUT_MPSAFE); |
| | | 530 | |
| | | 531 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); |
| | | 532 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); |
| | | 533 | cv_init(&sc->sc_softwake_cv, "uhciab"); |
527 | | | 534 | |
528 | /* Set up the bus struct. */ | | 535 | /* Set up the bus struct. */ |
529 | sc->sc_bus.methods = &uhci_bus_methods; | | 536 | sc->sc_bus.methods = &uhci_bus_methods; |
530 | sc->sc_bus.pipe_size = sizeof(struct uhci_pipe); | | 537 | sc->sc_bus.pipe_size = sizeof(struct uhci_pipe); |
531 | | | 538 | |
532 | UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */ | | 539 | UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */ |
533 | | | 540 | |
534 | DPRINTFN(1,("uhci_init: enabling\n")); | | 541 | DPRINTFN(1,("uhci_init: enabling\n")); |
535 | | | 542 | |
536 | err = uhci_run(sc, 1); /* and here we go... */ | | 543 | err = uhci_run(sc, 1); /* and here we go... */ |
537 | UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE | | | 544 | UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE | |
538 | UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */ | | 545 | UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */ |
539 | return err; | | 546 | return err; |
| @@ -570,67 +577,73 @@ uhci_detach(struct uhci_softc *sc, int f | | | @@ -570,67 +577,73 @@ uhci_detach(struct uhci_softc *sc, int f |
570 | | | 577 | |
571 | if (sc->sc_child != NULL) | | 578 | if (sc->sc_child != NULL) |
572 | rv = config_detach(sc->sc_child, flags); | | 579 | rv = config_detach(sc->sc_child, flags); |
573 | | | 580 | |
574 | if (rv != 0) | | 581 | if (rv != 0) |
575 | return (rv); | | 582 | return (rv); |
576 | | | 583 | |
577 | /* Free all xfers associated with this HC. */ | | 584 | /* Free all xfers associated with this HC. */ |
578 | for (;;) { | | 585 | for (;;) { |
579 | xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers); | | 586 | xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers); |
580 | if (xfer == NULL) | | 587 | if (xfer == NULL) |
581 | break; | | 588 | break; |
582 | SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next); | | 589 | SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next); |
583 | free(xfer, M_USB); | | 590 | kmem_free(xfer, sizeof(struct uhci_xfer)); |
584 | } | | 591 | } |
585 | | | 592 | |
586 | callout_halt(&sc->sc_poll_handle, NULL); | | 593 | callout_halt(&sc->sc_poll_handle, NULL); |
587 | callout_destroy(&sc->sc_poll_handle); | | 594 | callout_destroy(&sc->sc_poll_handle); |
588 | | | 595 | |
| | | 596 | cv_destroy(&sc->sc_softwake_cv); |
| | | 597 | |
| | | 598 | mutex_destroy(&sc->sc_lock); |
| | | 599 | mutex_destroy(&sc->sc_intr_lock); |
| | | 600 | |
589 | /* XXX free other data structures XXX */ | | 601 | /* XXX free other data structures XXX */ |
590 | | | 602 | |
591 | return (rv); | | 603 | return (rv); |
592 | } | | 604 | } |
593 | | | 605 | |
594 | usbd_status | | 606 | usbd_status |
595 | uhci_allocm(struct usbd_bus *bus, usb_dma_t *dma, u_int32_t size) | | 607 | uhci_allocm(struct usbd_bus *bus, usb_dma_t *dma, u_int32_t size) |
596 | { | | 608 | { |
597 | struct uhci_softc *sc = bus->hci_private; | | 609 | struct uhci_softc *sc = bus->hci_private; |
598 | usbd_status status; | | 610 | usbd_status status; |
599 | u_int32_t n; | | 611 | u_int32_t n; |
600 | | | 612 | |
601 | /* | | 613 | /* |
602 | * XXX | | 614 | * XXX |
603 | * Since we are allocating a buffer we can assume that we will | | 615 | * Since we are allocating a buffer we can assume that we will |
604 | * need TDs for it. Since we don't want to allocate those from | | 616 | * need TDs for it. Since we don't want to allocate those from |
605 | * an interrupt context, we allocate them here and free them again. | | 617 | * an interrupt context, we allocate them here and free them again. |
606 | * This is no guarantee that we'll get the TDs next time... | | 618 | * This is no guarantee that we'll get the TDs next time... |
607 | */ | | 619 | */ |
608 | n = size / 8; | | 620 | n = size / 8; |
609 | if (n > 16) { | | 621 | if (n > 16) { |
610 | u_int32_t i; | | 622 | u_int32_t i; |
611 | uhci_soft_td_t **stds; | | 623 | uhci_soft_td_t **stds; |
| | | 624 | |
612 | DPRINTF(("uhci_allocm: get %d TDs\n", n)); | | 625 | DPRINTF(("uhci_allocm: get %d TDs\n", n)); |
613 | stds = malloc(sizeof(uhci_soft_td_t *) * n, M_TEMP, | | 626 | stds = kmem_alloc(sizeof(uhci_soft_td_t *) * n, KM_SLEEP); |
614 | M_WAITOK|M_ZERO); | | 627 | if (!stds) |
615 | for(i=0; i < n; i++) | | 628 | return USBD_NOMEM; |
| | | 629 | for(i = 0; i < n; i++) |
616 | stds[i] = uhci_alloc_std(sc); | | 630 | stds[i] = uhci_alloc_std(sc); |
617 | for(i=0; i < n; i++) | | 631 | for(i = 0; i < n; i++) |
618 | if (stds[i] != NULL) | | 632 | if (stds[i] != NULL) |
619 | uhci_free_std(sc, stds[i]); | | 633 | uhci_free_std(sc, stds[i]); |
620 | free(stds, M_TEMP); | | 634 | kmem_free(stds, sizeof(uhci_soft_td_t *) * n); |
621 | } | | 635 | } |
622 | | | 636 | |
623 | | | | |
624 | status = usb_allocmem(&sc->sc_bus, size, 0, dma); | | 637 | status = usb_allocmem(&sc->sc_bus, size, 0, dma); |
625 | if (status == USBD_NOMEM) | | 638 | if (status == USBD_NOMEM) |
626 | status = usb_reserve_allocm(&sc->sc_dma_reserve, dma, size); | | 639 | status = usb_reserve_allocm(&sc->sc_dma_reserve, dma, size); |
627 | return status; | | 640 | return status; |
628 | } | | 641 | } |
629 | | | 642 | |
630 | void | | 643 | void |
631 | uhci_freem(struct usbd_bus *bus, usb_dma_t *dma) | | 644 | uhci_freem(struct usbd_bus *bus, usb_dma_t *dma) |
632 | { | | 645 | { |
633 | if (dma->block->flags & USB_DMA_RESERVE) { | | 646 | if (dma->block->flags & USB_DMA_RESERVE) { |
634 | usb_reserve_freem(&((struct uhci_softc *)bus)->sc_dma_reserve, | | 647 | usb_reserve_freem(&((struct uhci_softc *)bus)->sc_dma_reserve, |
635 | dma); | | 648 | dma); |
636 | return; | | 649 | return; |
| @@ -644,27 +657,27 @@ uhci_allocx(struct usbd_bus *bus) | | | @@ -644,27 +657,27 @@ uhci_allocx(struct usbd_bus *bus) |
644 | struct uhci_softc *sc = bus->hci_private; | | 657 | struct uhci_softc *sc = bus->hci_private; |
645 | usbd_xfer_handle xfer; | | 658 | usbd_xfer_handle xfer; |
646 | | | 659 | |
647 | xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers); | | 660 | xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers); |
648 | if (xfer != NULL) { | | 661 | if (xfer != NULL) { |
649 | SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next); | | 662 | SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, next); |
650 | #ifdef DIAGNOSTIC | | 663 | #ifdef DIAGNOSTIC |
651 | if (xfer->busy_free != XFER_FREE) { | | 664 | if (xfer->busy_free != XFER_FREE) { |
652 | printf("uhci_allocx: xfer=%p not free, 0x%08x\n", xfer, | | 665 | printf("uhci_allocx: xfer=%p not free, 0x%08x\n", xfer, |
653 | xfer->busy_free); | | 666 | xfer->busy_free); |
654 | } | | 667 | } |
655 | #endif | | 668 | #endif |
656 | } else { | | 669 | } else { |
657 | xfer = malloc(sizeof(struct uhci_xfer), M_USB, M_NOWAIT); | | 670 | xfer = kmem_alloc(sizeof(struct uhci_xfer), KM_SLEEP); |
658 | } | | 671 | } |
659 | if (xfer != NULL) { | | 672 | if (xfer != NULL) { |
660 | memset(xfer, 0, sizeof (struct uhci_xfer)); | | 673 | memset(xfer, 0, sizeof (struct uhci_xfer)); |
661 | UXFER(xfer)->iinfo.sc = sc; | | 674 | UXFER(xfer)->iinfo.sc = sc; |
662 | #ifdef DIAGNOSTIC | | 675 | #ifdef DIAGNOSTIC |
663 | UXFER(xfer)->iinfo.isdone = 1; | | 676 | UXFER(xfer)->iinfo.isdone = 1; |
664 | xfer->busy_free = XFER_BUSY; | | 677 | xfer->busy_free = XFER_BUSY; |
665 | #endif | | 678 | #endif |
666 | } | | 679 | } |
667 | return (xfer); | | 680 | return (xfer); |
668 | } | | 681 | } |
669 | | | 682 | |
670 | void | | 683 | void |
| @@ -675,41 +688,50 @@ uhci_freex(struct usbd_bus *bus, usbd_xf | | | @@ -675,41 +688,50 @@ uhci_freex(struct usbd_bus *bus, usbd_xf |
675 | #ifdef DIAGNOSTIC | | 688 | #ifdef DIAGNOSTIC |
676 | if (xfer->busy_free != XFER_BUSY) { | | 689 | if (xfer->busy_free != XFER_BUSY) { |
677 | printf("uhci_freex: xfer=%p not busy, 0x%08x\n", xfer, | | 690 | printf("uhci_freex: xfer=%p not busy, 0x%08x\n", xfer, |
678 | xfer->busy_free); | | 691 | xfer->busy_free); |
679 | } | | 692 | } |
680 | xfer->busy_free = XFER_FREE; | | 693 | xfer->busy_free = XFER_FREE; |
681 | if (!UXFER(xfer)->iinfo.isdone) { | | 694 | if (!UXFER(xfer)->iinfo.isdone) { |
682 | printf("uhci_freex: !isdone\n"); | | 695 | printf("uhci_freex: !isdone\n"); |
683 | } | | 696 | } |
684 | #endif | | 697 | #endif |
685 | SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next); | | 698 | SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next); |
686 | } | | 699 | } |
687 | | | 700 | |
| | | 701 | Static void |
| | | 702 | uhci_get_locks(struct usbd_bus *bus, kmutex_t **intr, kmutex_t **thread) |
| | | 703 | { |
| | | 704 | struct uhci_softc *sc = bus->hci_private; |
| | | 705 | |
| | | 706 | *intr = &sc->sc_intr_lock; |
| | | 707 | *thread = &sc->sc_lock; |
| | | 708 | } |
| | | 709 | |
| | | 710 | |
688 | /* | | 711 | /* |
689 | * Handle suspend/resume. | | 712 | * Handle suspend/resume. |
690 | * | | 713 | * |
691 | * We need to switch to polling mode here, because this routine is | | 714 | * We need to switch to polling mode here, because this routine is |
692 | * called from an interrupt context. This is all right since we | | 715 | * called from an interrupt context. This is all right since we |
693 | * are almost suspended anyway. | | 716 | * are almost suspended anyway. |
694 | */ | | 717 | */ |
695 | bool | | 718 | bool |
696 | uhci_resume(device_t dv, const pmf_qual_t *qual) | | 719 | uhci_resume(device_t dv, const pmf_qual_t *qual) |
697 | { | | 720 | { |
698 | uhci_softc_t *sc = device_private(dv); | | 721 | uhci_softc_t *sc = device_private(dv); |
699 | int cmd; | | 722 | int cmd; |
700 | int s; | | | |
701 | | | 723 | |
702 | s = splhardusb(); | | 724 | mutex_spin_enter(&sc->sc_intr_lock); |
703 | | | 725 | |
704 | cmd = UREAD2(sc, UHCI_CMD); | | 726 | cmd = UREAD2(sc, UHCI_CMD); |
705 | sc->sc_bus.use_polling++; | | 727 | sc->sc_bus.use_polling++; |
706 | UWRITE2(sc, UHCI_INTR, 0); | | 728 | UWRITE2(sc, UHCI_INTR, 0); |
707 | uhci_globalreset(sc); | | 729 | uhci_globalreset(sc); |
708 | uhci_reset(sc); | | 730 | uhci_reset(sc); |
709 | if (cmd & UHCI_CMD_RS) | | 731 | if (cmd & UHCI_CMD_RS) |
710 | uhci_run(sc, 0); | | 732 | uhci_run(sc, 0); |
711 | | | 733 | |
712 | /* restore saved state */ | | 734 | /* restore saved state */ |
713 | UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); | | 735 | UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); |
714 | UWRITE2(sc, UHCI_FRNUM, sc->sc_saved_frnum); | | 736 | UWRITE2(sc, UHCI_FRNUM, sc->sc_saved_frnum); |
715 | UWRITE1(sc, UHCI_SOF, sc->sc_saved_sof); | | 737 | UWRITE1(sc, UHCI_SOF, sc->sc_saved_sof); |
| @@ -722,65 +744,64 @@ uhci_resume(device_t dv, const pmf_qual_ | | | @@ -722,65 +744,64 @@ uhci_resume(device_t dv, const pmf_qual_ |
722 | UHCICMD(sc, UHCI_CMD_MAXP); | | 744 | UHCICMD(sc, UHCI_CMD_MAXP); |
723 | uhci_run(sc, 1); /* and start traffic again */ | | 745 | uhci_run(sc, 1); /* and start traffic again */ |
724 | usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY); | | 746 | usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY); |
725 | sc->sc_bus.use_polling--; | | 747 | sc->sc_bus.use_polling--; |
726 | if (sc->sc_intr_xfer != NULL) | | 748 | if (sc->sc_intr_xfer != NULL) |
727 | callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, | | 749 | callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, |
728 | sc->sc_intr_xfer); | | 750 | sc->sc_intr_xfer); |
729 | #ifdef UHCI_DEBUG | | 751 | #ifdef UHCI_DEBUG |
730 | if (uhcidebug > 2) | | 752 | if (uhcidebug > 2) |
731 | uhci_dumpregs(sc); | | 753 | uhci_dumpregs(sc); |
732 | #endif | | 754 | #endif |
733 | | | 755 | |
734 | sc->sc_suspend = PWR_RESUME; | | 756 | sc->sc_suspend = PWR_RESUME; |
735 | splx(s); | | 757 | mutex_spin_exit(&sc->sc_intr_lock); |
736 | | | 758 | |
737 | return true; | | 759 | return true; |
738 | } | | 760 | } |
739 | | | 761 | |
740 | bool | | 762 | bool |
741 | uhci_suspend(device_t dv, const pmf_qual_t *qual) | | 763 | uhci_suspend(device_t dv, const pmf_qual_t *qual) |
742 | { | | 764 | { |
743 | uhci_softc_t *sc = device_private(dv); | | 765 | uhci_softc_t *sc = device_private(dv); |
744 | int cmd; | | 766 | int cmd; |
745 | int s; | | | |
746 | | | 767 | |
747 | s = splhardusb(); | | 768 | mutex_spin_enter(&sc->sc_intr_lock); |
748 | | | 769 | |
749 | cmd = UREAD2(sc, UHCI_CMD); | | 770 | cmd = UREAD2(sc, UHCI_CMD); |
750 | | | 771 | |
751 | #ifdef UHCI_DEBUG | | 772 | #ifdef UHCI_DEBUG |
752 | if (uhcidebug > 2) | | 773 | if (uhcidebug > 2) |
753 | uhci_dumpregs(sc); | | 774 | uhci_dumpregs(sc); |
754 | #endif | | 775 | #endif |
755 | if (sc->sc_intr_xfer != NULL) | | 776 | if (sc->sc_intr_xfer != NULL) |
756 | callout_stop(&sc->sc_poll_handle); | | 777 | callout_stop(&sc->sc_poll_handle); |
757 | sc->sc_suspend = PWR_SUSPEND; | | 778 | sc->sc_suspend = PWR_SUSPEND; |
758 | sc->sc_bus.use_polling++; | | 779 | sc->sc_bus.use_polling++; |
759 | | | 780 | |
760 | uhci_run(sc, 0); /* stop the controller */ | | 781 | uhci_run(sc, 0); /* stop the controller */ |
761 | cmd &= ~UHCI_CMD_RS; | | 782 | cmd &= ~UHCI_CMD_RS; |
762 | | | 783 | |
763 | /* save some state if BIOS doesn't */ | | 784 | /* save some state if BIOS doesn't */ |
764 | sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM); | | 785 | sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM); |
765 | sc->sc_saved_sof = UREAD1(sc, UHCI_SOF); | | 786 | sc->sc_saved_sof = UREAD1(sc, UHCI_SOF); |
766 | | | 787 | |
767 | UWRITE2(sc, UHCI_INTR, 0); /* disable intrs */ | | 788 | UWRITE2(sc, UHCI_INTR, 0); /* disable intrs */ |
768 | | | 789 | |
769 | UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter suspend */ | | 790 | UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter suspend */ |
770 | usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT); | | 791 | usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT); |
771 | sc->sc_bus.use_polling--; | | 792 | sc->sc_bus.use_polling--; |
772 | | | 793 | |
773 | splx(s); | | 794 | mutex_spin_exit(&sc->sc_intr_lock); |
774 | | | 795 | |
775 | return true; | | 796 | return true; |
776 | } | | 797 | } |
777 | | | 798 | |
778 | #ifdef UHCI_DEBUG | | 799 | #ifdef UHCI_DEBUG |
779 | Static void | | 800 | Static void |
780 | uhci_dumpregs(uhci_softc_t *sc) | | 801 | uhci_dumpregs(uhci_softc_t *sc) |
781 | { | | 802 | { |
782 | DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, " | | 803 | DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, " |
783 | "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n", | | 804 | "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n", |
784 | device_xname(sc->sc_dev), | | 805 | device_xname(sc->sc_dev), |
785 | UREAD2(sc, UHCI_CMD), | | 806 | UREAD2(sc, UHCI_CMD), |
786 | UREAD2(sc, UHCI_STS), | | 807 | UREAD2(sc, UHCI_STS), |
| @@ -982,53 +1003,52 @@ void iidump(void) { uhci_dump_iis(thesc) | | | @@ -982,53 +1003,52 @@ void iidump(void) { uhci_dump_iis(thesc) |
982 | | | 1003 | |
983 | #endif | | 1004 | #endif |
984 | | | 1005 | |
985 | /* | | 1006 | /* |
986 | * This routine is executed periodically and simulates interrupts | | 1007 | * This routine is executed periodically and simulates interrupts |
987 | * from the root controller interrupt pipe for port status change. | | 1008 | * from the root controller interrupt pipe for port status change. |
988 | */ | | 1009 | */ |
989 | void | | 1010 | void |
990 | uhci_poll_hub(void *addr) | | 1011 | uhci_poll_hub(void *addr) |
991 | { | | 1012 | { |
992 | usbd_xfer_handle xfer = addr; | | 1013 | usbd_xfer_handle xfer = addr; |
993 | usbd_pipe_handle pipe = xfer->pipe; | | 1014 | usbd_pipe_handle pipe = xfer->pipe; |
994 | uhci_softc_t *sc; | | 1015 | uhci_softc_t *sc; |
995 | int s; | | | |
996 | u_char *p; | | 1016 | u_char *p; |
997 | | | 1017 | |
998 | DPRINTFN(20, ("uhci_poll_hub\n")); | | 1018 | DPRINTFN(20, ("uhci_poll_hub\n")); |
999 | | | 1019 | |
1000 | if (__predict_false(pipe->device == NULL || pipe->device->bus == NULL)) | | 1020 | if (__predict_false(pipe->device == NULL || pipe->device->bus == NULL)) |
1001 | return; /* device has detached */ | | 1021 | return; /* device has detached */ |
1002 | sc = pipe->device->bus->hci_private; | | 1022 | sc = pipe->device->bus->hci_private; |
1003 | callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer); | | 1023 | callout_reset(&sc->sc_poll_handle, sc->sc_ival, uhci_poll_hub, xfer); |
1004 | | | 1024 | |
1005 | p = KERNADDR(&xfer->dmabuf, 0); | | 1025 | p = KERNADDR(&xfer->dmabuf, 0); |
1006 | p[0] = 0; | | 1026 | p[0] = 0; |
1007 | if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC)) | | 1027 | if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC)) |
1008 | p[0] |= 1<<1; | | 1028 | p[0] |= 1<<1; |
1009 | if (UREAD2(sc, UHCI_PORTSC2) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC)) | | 1029 | if (UREAD2(sc, UHCI_PORTSC2) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC)) |
1010 | p[0] |= 1<<2; | | 1030 | p[0] |= 1<<2; |
1011 | if (p[0] == 0) | | 1031 | if (p[0] == 0) |
1012 | /* No change, try again in a while */ | | 1032 | /* No change, try again in a while */ |
1013 | return; | | 1033 | return; |
1014 | | | 1034 | |
1015 | xfer->actlen = 1; | | 1035 | xfer->actlen = 1; |
1016 | xfer->status = USBD_NORMAL_COMPLETION; | | 1036 | xfer->status = USBD_NORMAL_COMPLETION; |
1017 | s = splusb(); | | 1037 | mutex_enter(&sc->sc_lock); |
1018 | xfer->device->bus->intr_context++; | | 1038 | xfer->device->bus->intr_context++; |
1019 | usb_transfer_complete(xfer); | | 1039 | usb_transfer_complete(xfer); |
1020 | xfer->device->bus->intr_context--; | | 1040 | xfer->device->bus->intr_context--; |
1021 | splx(s); | | 1041 | mutex_exit(&sc->sc_lock); |
1022 | } | | 1042 | } |
1023 | | | 1043 | |
1024 | void | | 1044 | void |
1025 | uhci_root_intr_done(usbd_xfer_handle xfer) | | 1045 | uhci_root_intr_done(usbd_xfer_handle xfer) |
1026 | { | | 1046 | { |
1027 | } | | 1047 | } |
1028 | | | 1048 | |
1029 | void | | 1049 | void |
1030 | uhci_root_ctrl_done(usbd_xfer_handle xfer) | | 1050 | uhci_root_ctrl_done(usbd_xfer_handle xfer) |
1031 | { | | 1051 | { |
1032 | } | | 1052 | } |
1033 | | | 1053 | |
1034 | /* | | 1054 | /* |
| @@ -1067,54 +1087,54 @@ uhci_rem_loop(uhci_softc_t *sc) { | | | @@ -1067,54 +1087,54 @@ uhci_rem_loop(uhci_softc_t *sc) { |
1067 | usb_syncmem(&sc->sc_last_qh->dma, | | 1087 | usb_syncmem(&sc->sc_last_qh->dma, |
1068 | sc->sc_last_qh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1088 | sc->sc_last_qh->offs + offsetof(uhci_qh_t, qh_hlink), |
1069 | sizeof(sc->sc_last_qh->qh.qh_hlink), | | 1089 | sizeof(sc->sc_last_qh->qh.qh_hlink), |
1070 | BUS_DMASYNC_PREWRITE); | | 1090 | BUS_DMASYNC_PREWRITE); |
1071 | } | | 1091 | } |
1072 | } | | 1092 | } |
1073 | | | 1093 | |
1074 | /* Add high speed control QH, called at splusb(). */ | | 1094 | /* Add high speed control QH, called at splusb(). */ |
1075 | void | | 1095 | void |
1076 | uhci_add_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1096 | uhci_add_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1077 | { | | 1097 | { |
1078 | uhci_soft_qh_t *eqh; | | 1098 | uhci_soft_qh_t *eqh; |
1079 | | | 1099 | |
1080 | SPLUSBCHECK; | | 1100 | KASSERT(mutex_owned(&sc->sc_lock)); |
1081 | | | 1101 | |
1082 | DPRINTFN(10, ("uhci_add_ctrl: sqh=%p\n", sqh)); | | 1102 | DPRINTFN(10, ("uhci_add_ctrl: sqh=%p\n", sqh)); |
1083 | eqh = sc->sc_hctl_end; | | 1103 | eqh = sc->sc_hctl_end; |
1084 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1104 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1085 | sizeof(eqh->qh.qh_hlink), | | 1105 | sizeof(eqh->qh.qh_hlink), |
1086 | BUS_DMASYNC_POSTWRITE); | | 1106 | BUS_DMASYNC_POSTWRITE); |
1087 | sqh->hlink = eqh->hlink; | | 1107 | sqh->hlink = eqh->hlink; |
1088 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; | | 1108 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; |
1089 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 1109 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
1090 | BUS_DMASYNC_PREWRITE); | | 1110 | BUS_DMASYNC_PREWRITE); |
1091 | eqh->hlink = sqh; | | 1111 | eqh->hlink = sqh; |
1092 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); | | 1112 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); |
1093 | sc->sc_hctl_end = sqh; | | 1113 | sc->sc_hctl_end = sqh; |
1094 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1114 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1095 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); | | 1115 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); |
1096 | #ifdef UHCI_CTL_LOOP | | 1116 | #ifdef UHCI_CTL_LOOP |
1097 | uhci_add_loop(sc); | | 1117 | uhci_add_loop(sc); |
1098 | #endif | | 1118 | #endif |
1099 | } | | 1119 | } |
1100 | | | 1120 | |
1101 | /* Remove high speed control QH, called at splusb(). */ | | 1121 | /* Remove high speed control QH, called at splusb(). */ |
1102 | void | | 1122 | void |
1103 | uhci_remove_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1123 | uhci_remove_hs_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1104 | { | | 1124 | { |
1105 | uhci_soft_qh_t *pqh; | | 1125 | uhci_soft_qh_t *pqh; |
1106 | | | 1126 | |
1107 | SPLUSBCHECK; | | 1127 | KASSERT(mutex_owned(&sc->sc_lock)); |
1108 | | | 1128 | |
1109 | DPRINTFN(10, ("uhci_remove_hs_ctrl: sqh=%p\n", sqh)); | | 1129 | DPRINTFN(10, ("uhci_remove_hs_ctrl: sqh=%p\n", sqh)); |
1110 | #ifdef UHCI_CTL_LOOP | | 1130 | #ifdef UHCI_CTL_LOOP |
1111 | uhci_rem_loop(sc); | | 1131 | uhci_rem_loop(sc); |
1112 | #endif | | 1132 | #endif |
1113 | /* | | 1133 | /* |
1114 | * The T bit should be set in the elink of the QH so that the HC | | 1134 | * The T bit should be set in the elink of the QH so that the HC |
1115 | * doesn't follow the pointer. This condition may fail if the | | 1135 | * doesn't follow the pointer. This condition may fail if the |
1116 | * the transferred packet was short so that the QH still points | | 1136 | * the transferred packet was short so that the QH still points |
1117 | * at the last used TD. | | 1137 | * at the last used TD. |
1118 | * In this case we set the T bit and wait a little for the HC | | 1138 | * In this case we set the T bit and wait a little for the HC |
1119 | * to stop looking at the TD. | | 1139 | * to stop looking at the TD. |
1120 | * Note that if the TD chain is large enough, the controller | | 1140 | * Note that if the TD chain is large enough, the controller |
| @@ -1144,50 +1164,50 @@ uhci_remove_hs_ctrl(uhci_softc_t *sc, uh | | | @@ -1144,50 +1164,50 @@ uhci_remove_hs_ctrl(uhci_softc_t *sc, uh |
1144 | sizeof(pqh->qh.qh_hlink), | | 1164 | sizeof(pqh->qh.qh_hlink), |
1145 | BUS_DMASYNC_PREWRITE); | | 1165 | BUS_DMASYNC_PREWRITE); |
1146 | delay(UHCI_QH_REMOVE_DELAY); | | 1166 | delay(UHCI_QH_REMOVE_DELAY); |
1147 | if (sc->sc_hctl_end == sqh) | | 1167 | if (sc->sc_hctl_end == sqh) |
1148 | sc->sc_hctl_end = pqh; | | 1168 | sc->sc_hctl_end = pqh; |
1149 | } | | 1169 | } |
1150 | | | 1170 | |
1151 | /* Add low speed control QH, called at splusb(). */ | | 1171 | /* Add low speed control QH, called at splusb(). */ |
1152 | void | | 1172 | void |
1153 | uhci_add_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1173 | uhci_add_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1154 | { | | 1174 | { |
1155 | uhci_soft_qh_t *eqh; | | 1175 | uhci_soft_qh_t *eqh; |
1156 | | | 1176 | |
1157 | SPLUSBCHECK; | | 1177 | KASSERT(mutex_owned(&sc->sc_lock)); |
1158 | | | 1178 | |
1159 | DPRINTFN(10, ("uhci_add_ls_ctrl: sqh=%p\n", sqh)); | | 1179 | DPRINTFN(10, ("uhci_add_ls_ctrl: sqh=%p\n", sqh)); |
1160 | eqh = sc->sc_lctl_end; | | 1180 | eqh = sc->sc_lctl_end; |
1161 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1181 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1162 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_POSTWRITE); | | 1182 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_POSTWRITE); |
1163 | sqh->hlink = eqh->hlink; | | 1183 | sqh->hlink = eqh->hlink; |
1164 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; | | 1184 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; |
1165 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 1185 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
1166 | BUS_DMASYNC_PREWRITE); | | 1186 | BUS_DMASYNC_PREWRITE); |
1167 | eqh->hlink = sqh; | | 1187 | eqh->hlink = sqh; |
1168 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); | | 1188 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); |
1169 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1189 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1170 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); | | 1190 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); |
1171 | sc->sc_lctl_end = sqh; | | 1191 | sc->sc_lctl_end = sqh; |
1172 | } | | 1192 | } |
1173 | | | 1193 | |
1174 | /* Remove low speed control QH, called at splusb(). */ | | 1194 | /* Remove low speed control QH, called at splusb(). */ |
1175 | void | | 1195 | void |
1176 | uhci_remove_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1196 | uhci_remove_ls_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1177 | { | | 1197 | { |
1178 | uhci_soft_qh_t *pqh; | | 1198 | uhci_soft_qh_t *pqh; |
1179 | | | 1199 | |
1180 | SPLUSBCHECK; | | 1200 | KASSERT(mutex_owned(&sc->sc_lock)); |
1181 | | | 1201 | |
1182 | DPRINTFN(10, ("uhci_remove_ls_ctrl: sqh=%p\n", sqh)); | | 1202 | DPRINTFN(10, ("uhci_remove_ls_ctrl: sqh=%p\n", sqh)); |
1183 | /* See comment in uhci_remove_hs_ctrl() */ | | 1203 | /* See comment in uhci_remove_hs_ctrl() */ |
1184 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 1204 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(uhci_qh_t, qh_elink), |
1185 | sizeof(sqh->qh.qh_elink), | | 1205 | sizeof(sqh->qh.qh_elink), |
1186 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 1206 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
1187 | if (!(sqh->qh.qh_elink & htole32(UHCI_PTR_T))) { | | 1207 | if (!(sqh->qh.qh_elink & htole32(UHCI_PTR_T))) { |
1188 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); | | 1208 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); |
1189 | usb_syncmem(&sqh->dma, | | 1209 | usb_syncmem(&sqh->dma, |
1190 | sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 1210 | sqh->offs + offsetof(uhci_qh_t, qh_elink), |
1191 | sizeof(sqh->qh.qh_elink), | | 1211 | sizeof(sqh->qh.qh_elink), |
1192 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 1212 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
1193 | delay(UHCI_QH_REMOVE_DELAY); | | 1213 | delay(UHCI_QH_REMOVE_DELAY); |
| @@ -1201,51 +1221,51 @@ uhci_remove_ls_ctrl(uhci_softc_t *sc, uh | | | @@ -1201,51 +1221,51 @@ uhci_remove_ls_ctrl(uhci_softc_t *sc, uh |
1201 | sizeof(pqh->qh.qh_hlink), | | 1221 | sizeof(pqh->qh.qh_hlink), |
1202 | BUS_DMASYNC_PREWRITE); | | 1222 | BUS_DMASYNC_PREWRITE); |
1203 | delay(UHCI_QH_REMOVE_DELAY); | | 1223 | delay(UHCI_QH_REMOVE_DELAY); |
1204 | if (sc->sc_lctl_end == sqh) | | 1224 | if (sc->sc_lctl_end == sqh) |
1205 | sc->sc_lctl_end = pqh; | | 1225 | sc->sc_lctl_end = pqh; |
1206 | } | | 1226 | } |
1207 | | | 1227 | |
1208 | /* Add bulk QH, called at splusb(). */ | | 1228 | /* Add bulk QH, called at splusb(). */ |
1209 | void | | 1229 | void |
1210 | uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1230 | uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1211 | { | | 1231 | { |
1212 | uhci_soft_qh_t *eqh; | | 1232 | uhci_soft_qh_t *eqh; |
1213 | | | 1233 | |
1214 | SPLUSBCHECK; | | 1234 | KASSERT(mutex_owned(&sc->sc_lock)); |
1215 | | | 1235 | |
1216 | DPRINTFN(10, ("uhci_add_bulk: sqh=%p\n", sqh)); | | 1236 | DPRINTFN(10, ("uhci_add_bulk: sqh=%p\n", sqh)); |
1217 | eqh = sc->sc_bulk_end; | | 1237 | eqh = sc->sc_bulk_end; |
1218 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1238 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1219 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_POSTWRITE); | | 1239 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_POSTWRITE); |
1220 | sqh->hlink = eqh->hlink; | | 1240 | sqh->hlink = eqh->hlink; |
1221 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; | | 1241 | sqh->qh.qh_hlink = eqh->qh.qh_hlink; |
1222 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 1242 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
1223 | BUS_DMASYNC_PREWRITE); | | 1243 | BUS_DMASYNC_PREWRITE); |
1224 | eqh->hlink = sqh; | | 1244 | eqh->hlink = sqh; |
1225 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); | | 1245 | eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_QH); |
1226 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1246 | usb_syncmem(&eqh->dma, eqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1227 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); | | 1247 | sizeof(eqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); |
1228 | sc->sc_bulk_end = sqh; | | 1248 | sc->sc_bulk_end = sqh; |
1229 | uhci_add_loop(sc); | | 1249 | uhci_add_loop(sc); |
1230 | } | | 1250 | } |
1231 | | | 1251 | |
1232 | /* Remove bulk QH, called at splusb(). */ | | 1252 | /* Remove bulk QH, called at splusb(). */ |
1233 | void | | 1253 | void |
1234 | uhci_remove_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh) | | 1254 | uhci_remove_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh) |
1235 | { | | 1255 | { |
1236 | uhci_soft_qh_t *pqh; | | 1256 | uhci_soft_qh_t *pqh; |
1237 | | | 1257 | |
1238 | SPLUSBCHECK; | | 1258 | KASSERT(mutex_owned(&sc->sc_lock)); |
1239 | | | 1259 | |
1240 | DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh)); | | 1260 | DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh)); |
1241 | uhci_rem_loop(sc); | | 1261 | uhci_rem_loop(sc); |
1242 | /* See comment in uhci_remove_hs_ctrl() */ | | 1262 | /* See comment in uhci_remove_hs_ctrl() */ |
1243 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 1263 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(uhci_qh_t, qh_elink), |
1244 | sizeof(sqh->qh.qh_elink), | | 1264 | sizeof(sqh->qh.qh_elink), |
1245 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 1265 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
1246 | if (!(sqh->qh.qh_elink & htole32(UHCI_PTR_T))) { | | 1266 | if (!(sqh->qh.qh_elink & htole32(UHCI_PTR_T))) { |
1247 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); | | 1267 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); |
1248 | usb_syncmem(&sqh->dma, | | 1268 | usb_syncmem(&sqh->dma, |
1249 | sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 1269 | sqh->offs + offsetof(uhci_qh_t, qh_elink), |
1250 | sizeof(sqh->qh.qh_elink), | | 1270 | sizeof(sqh->qh.qh_elink), |
1251 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 1271 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
| @@ -1259,53 +1279,62 @@ uhci_remove_bulk(uhci_softc_t *sc, uhci_ | | | @@ -1259,53 +1279,62 @@ uhci_remove_bulk(uhci_softc_t *sc, uhci_ |
1259 | usb_syncmem(&pqh->dma, pqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 1279 | usb_syncmem(&pqh->dma, pqh->offs + offsetof(uhci_qh_t, qh_hlink), |
1260 | sizeof(pqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); | | 1280 | sizeof(pqh->qh.qh_hlink), BUS_DMASYNC_PREWRITE); |
1261 | delay(UHCI_QH_REMOVE_DELAY); | | 1281 | delay(UHCI_QH_REMOVE_DELAY); |
1262 | if (sc->sc_bulk_end == sqh) | | 1282 | if (sc->sc_bulk_end == sqh) |
1263 | sc->sc_bulk_end = pqh; | | 1283 | sc->sc_bulk_end = pqh; |
1264 | } | | 1284 | } |
1265 | | | 1285 | |
1266 | Static int uhci_intr1(uhci_softc_t *); | | 1286 | Static int uhci_intr1(uhci_softc_t *); |
1267 | | | 1287 | |
1268 | int | | 1288 | int |
1269 | uhci_intr(void *arg) | | 1289 | uhci_intr(void *arg) |
1270 | { | | 1290 | { |
1271 | uhci_softc_t *sc = arg; | | 1291 | uhci_softc_t *sc = arg; |
| | | 1292 | int ret = 0; |
| | | 1293 | |
| | | 1294 | mutex_spin_enter(&sc->sc_intr_lock); |
1272 | | | 1295 | |
1273 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) | | 1296 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) |
1274 | return (0); | | 1297 | goto done; |
1275 | | | 1298 | |
1276 | if (sc->sc_bus.use_polling || UREAD2(sc, UHCI_INTR) == 0) { | | 1299 | if (sc->sc_bus.use_polling || UREAD2(sc, UHCI_INTR) == 0) { |
1277 | #ifdef DIAGNOSTIC | | 1300 | #ifdef DIAGNOSTIC |
1278 | DPRINTFN(16, ("uhci_intr: ignored interrupt while polling\n")); | | 1301 | DPRINTFN(16, ("uhci_intr: ignored interrupt while polling\n")); |
1279 | #endif | | 1302 | #endif |
1280 | return (0); | | 1303 | goto done; |
1281 | } | | 1304 | } |
1282 | | | 1305 | |
1283 | return (uhci_intr1(sc)); | | 1306 | ret = uhci_intr1(sc); |
| | | 1307 | |
| | | 1308 | done: |
| | | 1309 | mutex_spin_exit(&sc->sc_intr_lock); |
| | | 1310 | return ret; |
1284 | } | | 1311 | } |
1285 | | | 1312 | |
1286 | int | | 1313 | int |
1287 | uhci_intr1(uhci_softc_t *sc) | | 1314 | uhci_intr1(uhci_softc_t *sc) |
1288 | { | | 1315 | { |
1289 | int status; | | 1316 | int status; |
1290 | int ack; | | 1317 | int ack; |
1291 | | | 1318 | |
1292 | #ifdef UHCI_DEBUG | | 1319 | #ifdef UHCI_DEBUG |
1293 | if (uhcidebug > 15) { | | 1320 | if (uhcidebug > 15) { |
1294 | DPRINTF(("%s: uhci_intr1\n", device_xname(sc->sc_dev))); | | 1321 | DPRINTF(("%s: uhci_intr1\n", device_xname(sc->sc_dev))); |
1295 | uhci_dumpregs(sc); | | 1322 | uhci_dumpregs(sc); |
1296 | } | | 1323 | } |
1297 | #endif | | 1324 | #endif |
1298 | | | 1325 | |
| | | 1326 | KASSERT(mutex_owned(&sc->sc_intr_lock)); |
| | | 1327 | |
1299 | status = UREAD2(sc, UHCI_STS) & UHCI_STS_ALLINTRS; | | 1328 | status = UREAD2(sc, UHCI_STS) & UHCI_STS_ALLINTRS; |
1300 | if (status == 0) /* The interrupt was not for us. */ | | 1329 | if (status == 0) /* The interrupt was not for us. */ |
1301 | return (0); | | 1330 | return (0); |
1302 | | | 1331 | |
1303 | if (sc->sc_suspend != PWR_RESUME) { | | 1332 | if (sc->sc_suspend != PWR_RESUME) { |
1304 | #ifdef DIAGNOSTIC | | 1333 | #ifdef DIAGNOSTIC |
1305 | printf("%s: interrupt while not operating ignored\n", | | 1334 | printf("%s: interrupt while not operating ignored\n", |
1306 | device_xname(sc->sc_dev)); | | 1335 | device_xname(sc->sc_dev)); |
1307 | #endif | | 1336 | #endif |
1308 | UWRITE2(sc, UHCI_STS, status); /* acknowledge the ints */ | | 1337 | UWRITE2(sc, UHCI_STS, status); /* acknowledge the ints */ |
1309 | return (0); | | 1338 | return (0); |
1310 | } | | 1339 | } |
1311 | | | 1340 | |
| @@ -1355,52 +1384,54 @@ uhci_intr1(uhci_softc_t *sc) | | | @@ -1355,52 +1384,54 @@ uhci_intr1(uhci_softc_t *sc) |
1355 | return (1); | | 1384 | return (1); |
1356 | } | | 1385 | } |
1357 | | | 1386 | |
1358 | void | | 1387 | void |
1359 | uhci_softintr(void *v) | | 1388 | uhci_softintr(void *v) |
1360 | { | | 1389 | { |
1361 | struct usbd_bus *bus = v; | | 1390 | struct usbd_bus *bus = v; |
1362 | uhci_softc_t *sc = bus->hci_private; | | 1391 | uhci_softc_t *sc = bus->hci_private; |
1363 | uhci_intr_info_t *ii, *nextii; | | 1392 | uhci_intr_info_t *ii, *nextii; |
1364 | | | 1393 | |
1365 | DPRINTFN(10,("%s: uhci_softintr (%d)\n", device_xname(sc->sc_dev), | | 1394 | DPRINTFN(10,("%s: uhci_softintr (%d)\n", device_xname(sc->sc_dev), |
1366 | sc->sc_bus.intr_context)); | | 1395 | sc->sc_bus.intr_context)); |
1367 | | | 1396 | |
| | | 1397 | mutex_enter(&sc->sc_lock); |
| | | 1398 | |
1368 | sc->sc_bus.intr_context++; | | 1399 | sc->sc_bus.intr_context++; |
1369 | | | 1400 | |
1370 | /* | | 1401 | /* |
1371 | * Interrupts on UHCI really suck. When the host controller | | 1402 | * Interrupts on UHCI really suck. When the host controller |
1372 | * interrupts because a transfer is completed there is no | | 1403 | * interrupts because a transfer is completed there is no |
1373 | * way of knowing which transfer it was. You can scan down | | 1404 | * way of knowing which transfer it was. You can scan down |
1374 | * the TDs and QHs of the previous frame to limit the search, | | 1405 | * the TDs and QHs of the previous frame to limit the search, |
1375 | * but that assumes that the interrupt was not delayed by more | | 1406 | * but that assumes that the interrupt was not delayed by more |
1376 | * than 1 ms, which may not always be true (e.g. after debug | | 1407 | * than 1 ms, which may not always be true (e.g. after debug |
1377 | * output on a slow console). | | 1408 | * output on a slow console). |
1378 | * We scan all interrupt descriptors to see if any have | | 1409 | * We scan all interrupt descriptors to see if any have |
1379 | * completed. | | 1410 | * completed. |
1380 | */ | | 1411 | */ |
1381 | for (ii = LIST_FIRST(&sc->sc_intrhead); ii; ii = nextii) { | | 1412 | for (ii = LIST_FIRST(&sc->sc_intrhead); ii; ii = nextii) { |
1382 | nextii = LIST_NEXT(ii, list); | | 1413 | nextii = LIST_NEXT(ii, list); |
1383 | uhci_check_intr(sc, ii); | | 1414 | uhci_check_intr(sc, ii); |
1384 | } | | 1415 | } |
1385 | | | 1416 | |
1386 | #ifdef USB_USE_SOFTINTR | | | |
1387 | if (sc->sc_softwake) { | | 1417 | if (sc->sc_softwake) { |
1388 | sc->sc_softwake = 0; | | 1418 | sc->sc_softwake = 0; |
1389 | wakeup(&sc->sc_softwake); | | 1419 | cv_broadcast(&sc->sc_softwake_cv); |
1390 | } | | 1420 | } |
1391 | #endif /* USB_USE_SOFTINTR */ | | | |
1392 | | | 1421 | |
1393 | sc->sc_bus.intr_context--; | | 1422 | sc->sc_bus.intr_context--; |
| | | 1423 | |
| | | 1424 | mutex_exit(&sc->sc_lock); |
1394 | } | | 1425 | } |
1395 | | | 1426 | |
1396 | /* Check for an interrupt. */ | | 1427 | /* Check for an interrupt. */ |
1397 | void | | 1428 | void |
1398 | uhci_check_intr(uhci_softc_t *sc, uhci_intr_info_t *ii) | | 1429 | uhci_check_intr(uhci_softc_t *sc, uhci_intr_info_t *ii) |
1399 | { | | 1430 | { |
1400 | uhci_soft_td_t *std, *lstd; | | 1431 | uhci_soft_td_t *std, *lstd; |
1401 | u_int32_t status; | | 1432 | u_int32_t status; |
1402 | | | 1433 | |
1403 | DPRINTFN(15, ("uhci_check_intr: ii=%p\n", ii)); | | 1434 | DPRINTFN(15, ("uhci_check_intr: ii=%p\n", ii)); |
1404 | #ifdef DIAGNOSTIC | | 1435 | #ifdef DIAGNOSTIC |
1405 | if (ii == NULL) { | | 1436 | if (ii == NULL) { |
1406 | printf("uhci_check_intr: no ii? %p\n", ii); | | 1437 | printf("uhci_check_intr: no ii? %p\n", ii); |
| @@ -1475,26 +1506,27 @@ uhci_check_intr(uhci_softc_t *sc, uhci_i | | | @@ -1475,26 +1506,27 @@ uhci_check_intr(uhci_softc_t *sc, uhci_i |
1475 | /* Called at splusb() */ | | 1506 | /* Called at splusb() */ |
1476 | void | | 1507 | void |
1477 | uhci_idone(uhci_intr_info_t *ii) | | 1508 | uhci_idone(uhci_intr_info_t *ii) |
1478 | { | | 1509 | { |
1479 | usbd_xfer_handle xfer = ii->xfer; | | 1510 | usbd_xfer_handle xfer = ii->xfer; |
1480 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 1511 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
1481 | uhci_soft_td_t *std; | | 1512 | uhci_soft_td_t *std; |
1482 | u_int32_t status = 0, nstatus; | | 1513 | u_int32_t status = 0, nstatus; |
1483 | int actlen; | | 1514 | int actlen; |
1484 | | | 1515 | |
1485 | DPRINTFN(12, ("uhci_idone: ii=%p\n", ii)); | | 1516 | DPRINTFN(12, ("uhci_idone: ii=%p\n", ii)); |
1486 | #ifdef DIAGNOSTIC | | 1517 | #ifdef DIAGNOSTIC |
1487 | { | | 1518 | { |
| | | 1519 | /* XXX SMP? */ |
1488 | int s = splhigh(); | | 1520 | int s = splhigh(); |
1489 | if (ii->isdone) { | | 1521 | if (ii->isdone) { |
1490 | splx(s); | | 1522 | splx(s); |
1491 | #ifdef UHCI_DEBUG | | 1523 | #ifdef UHCI_DEBUG |
1492 | printf("uhci_idone: ii is done!\n "); | | 1524 | printf("uhci_idone: ii is done!\n "); |
1493 | uhci_dump_ii(ii); | | 1525 | uhci_dump_ii(ii); |
1494 | #else | | 1526 | #else |
1495 | printf("uhci_idone: ii=%p is done!\n", ii); | | 1527 | printf("uhci_idone: ii=%p is done!\n", ii); |
1496 | #endif | | 1528 | #endif |
1497 | return; | | 1529 | return; |
1498 | } | | 1530 | } |
1499 | ii->isdone = 1; | | 1531 | ii->isdone = 1; |
1500 | splx(s); | | 1532 | splx(s); |
| @@ -1621,124 +1653,131 @@ uhci_timeout(void *addr) | | | @@ -1621,124 +1653,131 @@ uhci_timeout(void *addr) |
1621 | return; | | 1653 | return; |
1622 | } | | 1654 | } |
1623 | | | 1655 | |
1624 | /* Execute the abort in a process context. */ | | 1656 | /* Execute the abort in a process context. */ |
1625 | usb_init_task(&uxfer->abort_task, uhci_timeout_task, ii->xfer); | | 1657 | usb_init_task(&uxfer->abort_task, uhci_timeout_task, ii->xfer); |
1626 | usb_add_task(uxfer->xfer.pipe->device, &uxfer->abort_task, | | 1658 | usb_add_task(uxfer->xfer.pipe->device, &uxfer->abort_task, |
1627 | USB_TASKQ_HC); | | 1659 | USB_TASKQ_HC); |
1628 | } | | 1660 | } |
1629 | | | 1661 | |
1630 | void | | 1662 | void |
1631 | uhci_timeout_task(void *addr) | | 1663 | uhci_timeout_task(void *addr) |
1632 | { | | 1664 | { |
1633 | usbd_xfer_handle xfer = addr; | | 1665 | usbd_xfer_handle xfer = addr; |
1634 | int s; | | | |
1635 | | | 1666 | |
1636 | DPRINTF(("uhci_timeout_task: xfer=%p\n", xfer)); | | 1667 | DPRINTF(("uhci_timeout_task: xfer=%p\n", xfer)); |
1637 | | | 1668 | |
1638 | s = splusb(); | | | |
1639 | uhci_abort_xfer(xfer, USBD_TIMEOUT); | | 1669 | uhci_abort_xfer(xfer, USBD_TIMEOUT); |
1640 | splx(s); | | | |
1641 | } | | 1670 | } |
1642 | | | 1671 | |
1643 | /* | | 1672 | /* |
1644 | * Wait here until controller claims to have an interrupt. | | 1673 | * Wait here until controller claims to have an interrupt. |
1645 | * Then call uhci_intr and return. Use timeout to avoid waiting | | 1674 | * Then call uhci_intr and return. Use timeout to avoid waiting |
1646 | * too long. | | 1675 | * too long. |
1647 | * Only used during boot when interrupts are not enabled yet. | | 1676 | * Only used during boot when interrupts are not enabled yet. |
1648 | */ | | 1677 | */ |
1649 | void | | 1678 | void |
1650 | uhci_waitintr(uhci_softc_t *sc, usbd_xfer_handle xfer) | | 1679 | uhci_waitintr(uhci_softc_t *sc, usbd_xfer_handle xfer) |
1651 | { | | 1680 | { |
1652 | int timo = xfer->timeout; | | 1681 | int timo = xfer->timeout; |
1653 | uhci_intr_info_t *ii; | | 1682 | uhci_intr_info_t *ii; |
1654 | | | 1683 | |
| | | 1684 | mutex_enter(&sc->sc_lock); |
| | | 1685 | |
1655 | DPRINTFN(10,("uhci_waitintr: timeout = %dms\n", timo)); | | 1686 | DPRINTFN(10,("uhci_waitintr: timeout = %dms\n", timo)); |
1656 | | | 1687 | |
1657 | xfer->status = USBD_IN_PROGRESS; | | 1688 | xfer->status = USBD_IN_PROGRESS; |
1658 | for (; timo >= 0; timo--) { | | 1689 | for (; timo >= 0; timo--) { |
1659 | usb_delay_ms(&sc->sc_bus, 1); | | 1690 | usb_delay_ms(&sc->sc_bus, 1); |
1660 | DPRINTFN(20,("uhci_waitintr: 0x%04x\n", UREAD2(sc, UHCI_STS))); | | 1691 | DPRINTFN(20,("uhci_waitintr: 0x%04x\n", UREAD2(sc, UHCI_STS))); |
1661 | if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) { | | 1692 | if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) { |
| | | 1693 | mutex_spin_enter(&sc->sc_intr_lock); |
1662 | uhci_intr1(sc); | | 1694 | uhci_intr1(sc); |
| | | 1695 | mutex_spin_exit(&sc->sc_intr_lock); |
1663 | if (xfer->status != USBD_IN_PROGRESS) | | 1696 | if (xfer->status != USBD_IN_PROGRESS) |
1664 | return; | | 1697 | goto done; |
1665 | } | | 1698 | } |
1666 | } | | 1699 | } |
1667 | | | 1700 | |
1668 | /* Timeout */ | | 1701 | /* Timeout */ |
1669 | DPRINTF(("uhci_waitintr: timeout\n")); | | 1702 | DPRINTF(("uhci_waitintr: timeout\n")); |
1670 | for (ii = LIST_FIRST(&sc->sc_intrhead); | | 1703 | for (ii = LIST_FIRST(&sc->sc_intrhead); |
1671 | ii != NULL && ii->xfer != xfer; | | 1704 | ii != NULL && ii->xfer != xfer; |
1672 | ii = LIST_NEXT(ii, list)) | | 1705 | ii = LIST_NEXT(ii, list)) |
1673 | ; | | 1706 | ; |
1674 | #ifdef DIAGNOSTIC | | 1707 | #ifdef DIAGNOSTIC |
1675 | if (ii == NULL) | | 1708 | if (ii == NULL) |
1676 | panic("uhci_waitintr: lost intr_info"); | | 1709 | panic("uhci_waitintr: lost intr_info"); |
1677 | #endif | | 1710 | #endif |
1678 | uhci_idone(ii); | | 1711 | uhci_idone(ii); |
| | | 1712 | |
| | | 1713 | done: |
| | | 1714 | mutex_exit(&sc->sc_lock); |
1679 | } | | 1715 | } |
1680 | | | 1716 | |
1681 | void | | 1717 | void |
1682 | uhci_poll(struct usbd_bus *bus) | | 1718 | uhci_poll(struct usbd_bus *bus) |
1683 | { | | 1719 | { |
1684 | uhci_softc_t *sc = bus->hci_private; | | 1720 | uhci_softc_t *sc = bus->hci_private; |
1685 | | | 1721 | |
1686 | if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) | | 1722 | if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) { |
| | | 1723 | mutex_spin_enter(&sc->sc_intr_lock); |
1687 | uhci_intr1(sc); | | 1724 | uhci_intr1(sc); |
| | | 1725 | mutex_spin_exit(&sc->sc_intr_lock); |
| | | 1726 | } |
1688 | } | | 1727 | } |
1689 | | | 1728 | |
1690 | void | | 1729 | void |
1691 | uhci_reset(uhci_softc_t *sc) | | 1730 | uhci_reset(uhci_softc_t *sc) |
1692 | { | | 1731 | { |
1693 | int n; | | 1732 | int n; |
1694 | | | 1733 | |
1695 | UHCICMD(sc, UHCI_CMD_HCRESET); | | 1734 | UHCICMD(sc, UHCI_CMD_HCRESET); |
1696 | /* The reset bit goes low when the controller is done. */ | | 1735 | /* The reset bit goes low when the controller is done. */ |
1697 | for (n = 0; n < UHCI_RESET_TIMEOUT && | | 1736 | for (n = 0; n < UHCI_RESET_TIMEOUT && |
1698 | (UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET); n++) | | 1737 | (UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET); n++) |
1699 | usb_delay_ms(&sc->sc_bus, 1); | | 1738 | usb_delay_ms(&sc->sc_bus, 1); |
1700 | if (n >= UHCI_RESET_TIMEOUT) | | 1739 | if (n >= UHCI_RESET_TIMEOUT) |
1701 | printf("%s: controller did not reset\n", | | 1740 | printf("%s: controller did not reset\n", |
1702 | device_xname(sc->sc_dev)); | | 1741 | device_xname(sc->sc_dev)); |
1703 | } | | 1742 | } |
1704 | | | 1743 | |
1705 | usbd_status | | 1744 | usbd_status |
1706 | uhci_run(uhci_softc_t *sc, int run) | | 1745 | uhci_run(uhci_softc_t *sc, int run) |
1707 | { | | 1746 | { |
1708 | int s, n, running; | | 1747 | int n, running; |
1709 | u_int16_t cmd; | | 1748 | u_int16_t cmd; |
1710 | | | 1749 | |
1711 | run = run != 0; | | 1750 | run = run != 0; |
1712 | s = splhardusb(); | | 1751 | mutex_spin_enter(&sc->sc_intr_lock); |
1713 | DPRINTF(("uhci_run: setting run=%d\n", run)); | | 1752 | DPRINTF(("uhci_run: setting run=%d\n", run)); |
1714 | cmd = UREAD2(sc, UHCI_CMD); | | 1753 | cmd = UREAD2(sc, UHCI_CMD); |
1715 | if (run) | | 1754 | if (run) |
1716 | cmd |= UHCI_CMD_RS; | | 1755 | cmd |= UHCI_CMD_RS; |
1717 | else | | 1756 | else |
1718 | cmd &= ~UHCI_CMD_RS; | | 1757 | cmd &= ~UHCI_CMD_RS; |
1719 | UHCICMD(sc, cmd); | | 1758 | UHCICMD(sc, cmd); |
1720 | for(n = 0; n < 10; n++) { | | 1759 | for(n = 0; n < 10; n++) { |
1721 | running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH); | | 1760 | running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH); |
1722 | /* return when we've entered the state we want */ | | 1761 | /* return when we've entered the state we want */ |
1723 | if (run == running) { | | 1762 | if (run == running) { |
1724 | splx(s); | | 1763 | mutex_spin_exit(&sc->sc_intr_lock); |
1725 | DPRINTF(("uhci_run: done cmd=0x%x sts=0x%x\n", | | 1764 | DPRINTF(("uhci_run: done cmd=0x%x sts=0x%x\n", |
1726 | UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS))); | | 1765 | UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS))); |
1727 | return (USBD_NORMAL_COMPLETION); | | 1766 | return (USBD_NORMAL_COMPLETION); |
1728 | } | | 1767 | } |
1729 | usb_delay_ms(&sc->sc_bus, 1); | | 1768 | usb_delay_ms(&sc->sc_bus, 1); |
1730 | } | | 1769 | } |
1731 | splx(s); | | 1770 | mutex_spin_exit(&sc->sc_intr_lock); |
1732 | printf("%s: cannot %s\n", device_xname(sc->sc_dev), | | 1771 | printf("%s: cannot %s\n", device_xname(sc->sc_dev), |
1733 | run ? "start" : "stop"); | | 1772 | run ? "start" : "stop"); |
1734 | return (USBD_IOERROR); | | 1773 | return (USBD_IOERROR); |
1735 | } | | 1774 | } |
1736 | | | 1775 | |
1737 | /* | | 1776 | /* |
1738 | * Memory management routines. | | 1777 | * Memory management routines. |
1739 | * uhci_alloc_std allocates TDs | | 1778 | * uhci_alloc_std allocates TDs |
1740 | * uhci_alloc_sqh allocates QHs | | 1779 | * uhci_alloc_sqh allocates QHs |
1741 | * These two routines do their own free list management, | | 1780 | * These two routines do their own free list management, |
1742 | * partly for speed, partly because allocating DMAable memory | | 1781 | * partly for speed, partly because allocating DMAable memory |
1743 | * has page size granularaity so much memory would be wasted if | | 1782 | * has page size granularaity so much memory would be wasted if |
1744 | * only one TD/QH (32 bytes) was placed in each allocated chunk. | | 1783 | * only one TD/QH (32 bytes) was placed in each allocated chunk. |
| @@ -1748,27 +1787,27 @@ uhci_soft_td_t * | | | @@ -1748,27 +1787,27 @@ uhci_soft_td_t * |
1748 | uhci_alloc_std(uhci_softc_t *sc) | | 1787 | uhci_alloc_std(uhci_softc_t *sc) |
1749 | { | | 1788 | { |
1750 | uhci_soft_td_t *std; | | 1789 | uhci_soft_td_t *std; |
1751 | usbd_status err; | | 1790 | usbd_status err; |
1752 | int i, offs; | | 1791 | int i, offs; |
1753 | usb_dma_t dma; | | 1792 | usb_dma_t dma; |
1754 | | | 1793 | |
1755 | if (sc->sc_freetds == NULL) { | | 1794 | if (sc->sc_freetds == NULL) { |
1756 | DPRINTFN(2,("uhci_alloc_std: allocating chunk\n")); | | 1795 | DPRINTFN(2,("uhci_alloc_std: allocating chunk\n")); |
1757 | err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK, | | 1796 | err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK, |
1758 | UHCI_TD_ALIGN, &dma); | | 1797 | UHCI_TD_ALIGN, &dma); |
1759 | if (err) | | 1798 | if (err) |
1760 | return (0); | | 1799 | return (0); |
1761 | for(i = 0; i < UHCI_STD_CHUNK; i++) { | | 1800 | for (i = 0; i < UHCI_STD_CHUNK; i++) { |
1762 | offs = i * UHCI_STD_SIZE; | | 1801 | offs = i * UHCI_STD_SIZE; |
1763 | std = KERNADDR(&dma, offs); | | 1802 | std = KERNADDR(&dma, offs); |
1764 | std->physaddr = DMAADDR(&dma, offs); | | 1803 | std->physaddr = DMAADDR(&dma, offs); |
1765 | std->dma = dma; | | 1804 | std->dma = dma; |
1766 | std->offs = offs; | | 1805 | std->offs = offs; |
1767 | std->link.std = sc->sc_freetds; | | 1806 | std->link.std = sc->sc_freetds; |
1768 | sc->sc_freetds = std; | | 1807 | sc->sc_freetds = std; |
1769 | } | | 1808 | } |
1770 | } | | 1809 | } |
1771 | std = sc->sc_freetds; | | 1810 | std = sc->sc_freetds; |
1772 | sc->sc_freetds = std->link.std; | | 1811 | sc->sc_freetds = std->link.std; |
1773 | memset(&std->td, 0, sizeof(uhci_td_t)); | | 1812 | memset(&std->td, 0, sizeof(uhci_td_t)); |
1774 | return std; | | 1813 | return std; |
| @@ -1863,26 +1902,29 @@ uhci_alloc_std_chain(struct uhci_pipe *u | | | @@ -1863,26 +1902,29 @@ uhci_alloc_std_chain(struct uhci_pipe *u |
1863 | int rd, u_int16_t flags, usb_dma_t *dma, | | 1902 | int rd, u_int16_t flags, usb_dma_t *dma, |
1864 | uhci_soft_td_t **sp, uhci_soft_td_t **ep) | | 1903 | uhci_soft_td_t **sp, uhci_soft_td_t **ep) |
1865 | { | | 1904 | { |
1866 | uhci_soft_td_t *p, *lastp; | | 1905 | uhci_soft_td_t *p, *lastp; |
1867 | uhci_physaddr_t lastlink; | | 1906 | uhci_physaddr_t lastlink; |
1868 | int i, ntd, l, tog, maxp; | | 1907 | int i, ntd, l, tog, maxp; |
1869 | u_int32_t status; | | 1908 | u_int32_t status; |
1870 | int addr = upipe->pipe.device->address; | | 1909 | int addr = upipe->pipe.device->address; |
1871 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; | | 1910 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; |
1872 | | | 1911 | |
1873 | DPRINTFN(8, ("uhci_alloc_std_chain: addr=%d endpt=%d len=%d speed=%d " | | 1912 | DPRINTFN(8, ("uhci_alloc_std_chain: addr=%d endpt=%d len=%d speed=%d " |
1874 | "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len, | | 1913 | "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len, |
1875 | upipe->pipe.device->speed, flags)); | | 1914 | upipe->pipe.device->speed, flags)); |
| | | 1915 | |
| | | 1916 | KASSERT(mutex_owned(&sc->sc_lock)); |
| | | 1917 | |
1876 | maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize); | | 1918 | maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize); |
1877 | if (maxp == 0) { | | 1919 | if (maxp == 0) { |
1878 | printf("uhci_alloc_std_chain: maxp=0\n"); | | 1920 | printf("uhci_alloc_std_chain: maxp=0\n"); |
1879 | return (USBD_INVAL); | | 1921 | return (USBD_INVAL); |
1880 | } | | 1922 | } |
1881 | ntd = (len + maxp - 1) / maxp; | | 1923 | ntd = (len + maxp - 1) / maxp; |
1882 | if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0) | | 1924 | if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0) |
1883 | ntd++; | | 1925 | ntd++; |
1884 | DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd)); | | 1926 | DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd)); |
1885 | if (ntd == 0) { | | 1927 | if (ntd == 0) { |
1886 | *sp = *ep = 0; | | 1928 | *sp = *ep = 0; |
1887 | DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n")); | | 1929 | DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n")); |
1888 | return (USBD_NORMAL_COMPLETION); | | 1930 | return (USBD_NORMAL_COMPLETION); |
| @@ -1940,76 +1982,82 @@ uhci_device_clear_toggle(usbd_pipe_handl | | | @@ -1940,76 +1982,82 @@ uhci_device_clear_toggle(usbd_pipe_handl |
1940 | { | | 1982 | { |
1941 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 1983 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
1942 | upipe->nexttoggle = 0; | | 1984 | upipe->nexttoggle = 0; |
1943 | } | | 1985 | } |
1944 | | | 1986 | |
1945 | void | | 1987 | void |
1946 | uhci_noop(usbd_pipe_handle pipe) | | 1988 | uhci_noop(usbd_pipe_handle pipe) |
1947 | { | | 1989 | { |
1948 | } | | 1990 | } |
1949 | | | 1991 | |
1950 | usbd_status | | 1992 | usbd_status |
1951 | uhci_device_bulk_transfer(usbd_xfer_handle xfer) | | 1993 | uhci_device_bulk_transfer(usbd_xfer_handle xfer) |
1952 | { | | 1994 | { |
| | | 1995 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
1953 | usbd_status err; | | 1996 | usbd_status err; |
1954 | | | 1997 | |
1955 | /* Insert last in queue. */ | | 1998 | /* Insert last in queue. */ |
| | | 1999 | mutex_enter(&sc->sc_lock); |
1956 | err = usb_insert_transfer(xfer); | | 2000 | err = usb_insert_transfer(xfer); |
| | | 2001 | mutex_exit(&sc->sc_lock); |
1957 | if (err) | | 2002 | if (err) |
1958 | return (err); | | 2003 | return (err); |
1959 | | | 2004 | |
1960 | /* | | 2005 | /* |
1961 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 2006 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
1962 | * so start it first. | | 2007 | * so start it first. |
1963 | */ | | 2008 | */ |
1964 | return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); | | 2009 | return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); |
1965 | } | | 2010 | } |
1966 | | | 2011 | |
1967 | usbd_status | | 2012 | usbd_status |
1968 | uhci_device_bulk_start(usbd_xfer_handle xfer) | | 2013 | uhci_device_bulk_start(usbd_xfer_handle xfer) |
1969 | { | | 2014 | { |
1970 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2015 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
1971 | usbd_device_handle dev = upipe->pipe.device; | | 2016 | usbd_device_handle dev = upipe->pipe.device; |
1972 | uhci_softc_t *sc = dev->bus->hci_private; | | 2017 | uhci_softc_t *sc = dev->bus->hci_private; |
1973 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2018 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
1974 | uhci_soft_td_t *data, *dataend; | | 2019 | uhci_soft_td_t *data, *dataend; |
1975 | uhci_soft_qh_t *sqh; | | 2020 | uhci_soft_qh_t *sqh; |
1976 | usbd_status err; | | 2021 | usbd_status err; |
1977 | int len, isread, endpt; | | 2022 | int len, isread, endpt; |
1978 | int s; | | | |
1979 | | | 2023 | |
1980 | DPRINTFN(3, ("uhci_device_bulk_start: xfer=%p len=%d flags=%d ii=%p\n", | | 2024 | DPRINTFN(3, ("uhci_device_bulk_start: xfer=%p len=%d flags=%d ii=%p\n", |
1981 | xfer, xfer->length, xfer->flags, ii)); | | 2025 | xfer, xfer->length, xfer->flags, ii)); |
1982 | | | 2026 | |
1983 | if (sc->sc_dying) | | 2027 | if (sc->sc_dying) |
1984 | return (USBD_IOERROR); | | 2028 | return (USBD_IOERROR); |
1985 | | | 2029 | |
1986 | #ifdef DIAGNOSTIC | | 2030 | #ifdef DIAGNOSTIC |
1987 | if (xfer->rqflags & URQ_REQUEST) | | 2031 | if (xfer->rqflags & URQ_REQUEST) |
1988 | panic("uhci_device_bulk_transfer: a request"); | | 2032 | panic("uhci_device_bulk_transfer: a request"); |
1989 | #endif | | 2033 | #endif |
1990 | | | 2034 | |
| | | 2035 | mutex_enter(&sc->sc_lock); |
| | | 2036 | |
1991 | len = xfer->length; | | 2037 | len = xfer->length; |
1992 | endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; | | 2038 | endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; |
1993 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 2039 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
1994 | sqh = upipe->u.bulk.sqh; | | 2040 | sqh = upipe->u.bulk.sqh; |
1995 | | | 2041 | |
1996 | upipe->u.bulk.isread = isread; | | 2042 | upipe->u.bulk.isread = isread; |
1997 | upipe->u.bulk.length = len; | | 2043 | upipe->u.bulk.length = len; |
1998 | | | 2044 | |
1999 | err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags, | | 2045 | err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags, |
2000 | &xfer->dmabuf, &data, &dataend); | | 2046 | &xfer->dmabuf, &data, &dataend); |
2001 | if (err) | | 2047 | if (err) { |
| | | 2048 | mutex_exit(&sc->sc_lock); |
2002 | return (err); | | 2049 | return (err); |
| | | 2050 | } |
2003 | dataend->td.td_status |= htole32(UHCI_TD_IOC); | | 2051 | dataend->td.td_status |= htole32(UHCI_TD_IOC); |
2004 | usb_syncmem(&dataend->dma, | | 2052 | usb_syncmem(&dataend->dma, |
2005 | dataend->offs + offsetof(uhci_td_t, td_status), | | 2053 | dataend->offs + offsetof(uhci_td_t, td_status), |
2006 | sizeof(dataend->td.td_status), | | 2054 | sizeof(dataend->td.td_status), |
2007 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2055 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2008 | | | 2056 | |
2009 | | | 2057 | |
2010 | #ifdef UHCI_DEBUG | | 2058 | #ifdef UHCI_DEBUG |
2011 | if (uhcidebug > 8) { | | 2059 | if (uhcidebug > 8) { |
2012 | DPRINTF(("uhci_device_bulk_transfer: data(1)\n")); | | 2060 | DPRINTF(("uhci_device_bulk_transfer: data(1)\n")); |
2013 | uhci_dump_tds(data); | | 2061 | uhci_dump_tds(data); |
2014 | } | | 2062 | } |
2015 | #endif | | 2063 | #endif |
| @@ -2019,47 +2067,46 @@ uhci_device_bulk_start(usbd_xfer_handle | | | @@ -2019,47 +2067,46 @@ uhci_device_bulk_start(usbd_xfer_handle |
2019 | ii->stdstart = data; | | 2067 | ii->stdstart = data; |
2020 | ii->stdend = dataend; | | 2068 | ii->stdend = dataend; |
2021 | #ifdef DIAGNOSTIC | | 2069 | #ifdef DIAGNOSTIC |
2022 | if (!ii->isdone) { | | 2070 | if (!ii->isdone) { |
2023 | printf("uhci_device_bulk_transfer: not done, ii=%p\n", ii); | | 2071 | printf("uhci_device_bulk_transfer: not done, ii=%p\n", ii); |
2024 | } | | 2072 | } |
2025 | ii->isdone = 0; | | 2073 | ii->isdone = 0; |
2026 | #endif | | 2074 | #endif |
2027 | | | 2075 | |
2028 | sqh->elink = data; | | 2076 | sqh->elink = data; |
2029 | sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); | | 2077 | sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); |
2030 | /* uhci_add_bulk() will do usb_syncmem(sqh) */ | | 2078 | /* uhci_add_bulk() will do usb_syncmem(sqh) */ |
2031 | | | 2079 | |
2032 | s = splusb(); | | | |
2033 | uhci_add_bulk(sc, sqh); | | 2080 | uhci_add_bulk(sc, sqh); |
2034 | uhci_add_intr_info(sc, ii); | | 2081 | uhci_add_intr_info(sc, ii); |
2035 | | | 2082 | |
2036 | if (xfer->timeout && !sc->sc_bus.use_polling) { | | 2083 | if (xfer->timeout && !sc->sc_bus.use_polling) { |
2037 | callout_reset(&xfer->timeout_handle, mstohz(xfer->timeout), | | 2084 | callout_reset(&xfer->timeout_handle, mstohz(xfer->timeout), |
2038 | uhci_timeout, ii); | | 2085 | uhci_timeout, ii); |
2039 | } | | 2086 | } |
2040 | xfer->status = USBD_IN_PROGRESS; | | 2087 | xfer->status = USBD_IN_PROGRESS; |
2041 | splx(s); | | | |
2042 | | | 2088 | |
2043 | #ifdef UHCI_DEBUG | | 2089 | #ifdef UHCI_DEBUG |
2044 | if (uhcidebug > 10) { | | 2090 | if (uhcidebug > 10) { |
2045 | DPRINTF(("uhci_device_bulk_transfer: data(2)\n")); | | 2091 | DPRINTF(("uhci_device_bulk_transfer: data(2)\n")); |
2046 | uhci_dump_tds(data); | | 2092 | uhci_dump_tds(data); |
2047 | } | | 2093 | } |
2048 | #endif | | 2094 | #endif |
2049 | | | 2095 | |
2050 | if (sc->sc_bus.use_polling) | | 2096 | if (sc->sc_bus.use_polling) |
2051 | uhci_waitintr(sc, xfer); | | 2097 | uhci_waitintr(sc, xfer); |
2052 | | | 2098 | |
| | | 2099 | mutex_exit(&sc->sc_lock); |
2053 | return (USBD_IN_PROGRESS); | | 2100 | return (USBD_IN_PROGRESS); |
2054 | } | | 2101 | } |
2055 | | | 2102 | |
2056 | /* Abort a device bulk request. */ | | 2103 | /* Abort a device bulk request. */ |
2057 | void | | 2104 | void |
2058 | uhci_device_bulk_abort(usbd_xfer_handle xfer) | | 2105 | uhci_device_bulk_abort(usbd_xfer_handle xfer) |
2059 | { | | 2106 | { |
2060 | DPRINTF(("uhci_device_bulk_abort:\n")); | | 2107 | DPRINTF(("uhci_device_bulk_abort:\n")); |
2061 | uhci_abort_xfer(xfer, USBD_CANCELLED); | | 2108 | uhci_abort_xfer(xfer, USBD_CANCELLED); |
2062 | } | | 2109 | } |
2063 | | | 2110 | |
2064 | /* | | 2111 | /* |
2065 | * Abort a device request. | | 2112 | * Abort a device request. |
| @@ -2068,199 +2115,200 @@ uhci_device_bulk_abort(usbd_xfer_handle | | | @@ -2068,199 +2115,200 @@ uhci_device_bulk_abort(usbd_xfer_handle |
2068 | * for it will be called with USBD_CANCELLED status. | | 2115 | * for it will be called with USBD_CANCELLED status. |
2069 | * It's impossible to guarantee that the requested transfer will not | | 2116 | * It's impossible to guarantee that the requested transfer will not |
2070 | * have happened since the hardware runs concurrently. | | 2117 | * have happened since the hardware runs concurrently. |
2071 | * If the transaction has already happened we rely on the ordinary | | 2118 | * If the transaction has already happened we rely on the ordinary |
2072 | * interrupt processing to process it. | | 2119 | * interrupt processing to process it. |
2073 | */ | | 2120 | */ |
2074 | void | | 2121 | void |
2075 | uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) | | 2122 | uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) |
2076 | { | | 2123 | { |
2077 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2124 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2078 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2125 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2079 | uhci_softc_t *sc = upipe->pipe.device->bus->hci_private; | | 2126 | uhci_softc_t *sc = upipe->pipe.device->bus->hci_private; |
2080 | uhci_soft_td_t *std; | | 2127 | uhci_soft_td_t *std; |
2081 | int s; | | | |
2082 | int wake; | | 2128 | int wake; |
2083 | | | 2129 | |
2084 | DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status)); | | 2130 | DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status)); |
2085 | | | 2131 | |
2086 | if (sc->sc_dying) { | | 2132 | if (sc->sc_dying) { |
2087 | /* If we're dying, just do the software part. */ | | 2133 | /* If we're dying, just do the software part. */ |
2088 | s = splusb(); | | 2134 | mutex_enter(&sc->sc_lock); |
2089 | xfer->status = status; /* make software ignore it */ | | 2135 | xfer->status = status; /* make software ignore it */ |
2090 | callout_stop(&xfer->timeout_handle); | | 2136 | callout_stop(&xfer->timeout_handle); |
2091 | usb_transfer_complete(xfer); | | 2137 | usb_transfer_complete(xfer); |
2092 | splx(s); | | 2138 | mutex_exit(&sc->sc_lock); |
2093 | return; | | 2139 | return; |
2094 | } | | 2140 | } |
2095 | | | 2141 | |
2096 | if (xfer->device->bus->intr_context || !curproc) | | 2142 | if (xfer->device->bus->intr_context || !curproc) |
2097 | panic("uhci_abort_xfer: not in process context"); | | 2143 | panic("uhci_abort_xfer: not in process context"); |
2098 | | | 2144 | |
| | | 2145 | mutex_enter(&sc->sc_lock); |
| | | 2146 | |
2099 | /* | | 2147 | /* |
2100 | * If an abort is already in progress then just wait for it to | | 2148 | * If an abort is already in progress then just wait for it to |
2101 | * complete and return. | | 2149 | * complete and return. |
2102 | */ | | 2150 | */ |
2103 | if (xfer->hcflags & UXFER_ABORTING) { | | 2151 | if (xfer->hcflags & UXFER_ABORTING) { |
2104 | DPRINTFN(2, ("uhci_abort_xfer: already aborting\n")); | | 2152 | DPRINTFN(2, ("uhci_abort_xfer: already aborting\n")); |
2105 | #ifdef DIAGNOSTIC | | 2153 | #ifdef DIAGNOSTIC |
2106 | if (status == USBD_TIMEOUT) | | 2154 | if (status == USBD_TIMEOUT) |
2107 | printf("uhci_abort_xfer: TIMEOUT while aborting\n"); | | 2155 | printf("uhci_abort_xfer: TIMEOUT while aborting\n"); |
2108 | #endif | | 2156 | #endif |
2109 | /* Override the status which might be USBD_TIMEOUT. */ | | 2157 | /* Override the status which might be USBD_TIMEOUT. */ |
2110 | xfer->status = status; | | 2158 | xfer->status = status; |
2111 | DPRINTFN(2, ("uhci_abort_xfer: waiting for abort to finish\n")); | | 2159 | DPRINTFN(2, ("uhci_abort_xfer: waiting for abort to finish\n")); |
2112 | xfer->hcflags |= UXFER_ABORTWAIT; | | 2160 | xfer->hcflags |= UXFER_ABORTWAIT; |
2113 | while (xfer->hcflags & UXFER_ABORTING) | | 2161 | while (xfer->hcflags & UXFER_ABORTING) |
2114 | tsleep(&xfer->hcflags, PZERO, "uhciaw", 0); | | 2162 | cv_wait(&xfer->hccv, &sc->sc_lock); |
2115 | return; | | 2163 | goto done; |
2116 | } | | 2164 | } |
2117 | xfer->hcflags |= UXFER_ABORTING; | | 2165 | xfer->hcflags |= UXFER_ABORTING; |
2118 | | | 2166 | |
2119 | /* | | 2167 | /* |
2120 | * Step 1: Make interrupt routine and hardware ignore xfer. | | 2168 | * Step 1: Make interrupt routine and hardware ignore xfer. |
2121 | */ | | 2169 | */ |
2122 | s = splusb(); | | | |
2123 | xfer->status = status; /* make software ignore it */ | | 2170 | xfer->status = status; /* make software ignore it */ |
2124 | callout_stop(&xfer->timeout_handle); | | 2171 | callout_stop(&xfer->timeout_handle); |
2125 | DPRINTFN(1,("uhci_abort_xfer: stop ii=%p\n", ii)); | | 2172 | DPRINTFN(1,("uhci_abort_xfer: stop ii=%p\n", ii)); |
2126 | for (std = ii->stdstart; std != NULL; std = std->link.std) { | | 2173 | for (std = ii->stdstart; std != NULL; std = std->link.std) { |
2127 | usb_syncmem(&std->dma, | | 2174 | usb_syncmem(&std->dma, |
2128 | std->offs + offsetof(uhci_td_t, td_status), | | 2175 | std->offs + offsetof(uhci_td_t, td_status), |
2129 | sizeof(std->td.td_status), | | 2176 | sizeof(std->td.td_status), |
2130 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 2177 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
2131 | std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC)); | | 2178 | std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC)); |
2132 | usb_syncmem(&std->dma, | | 2179 | usb_syncmem(&std->dma, |
2133 | std->offs + offsetof(uhci_td_t, td_status), | | 2180 | std->offs + offsetof(uhci_td_t, td_status), |
2134 | sizeof(std->td.td_status), | | 2181 | sizeof(std->td.td_status), |
2135 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2182 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2136 | } | | 2183 | } |
2137 | splx(s); | | | |
2138 | | | 2184 | |
2139 | /* | | 2185 | /* |
2140 | * Step 2: Wait until we know hardware has finished any possible | | 2186 | * Step 2: Wait until we know hardware has finished any possible |
2141 | * use of the xfer. Also make sure the soft interrupt routine | | 2187 | * use of the xfer. Also make sure the soft interrupt routine |
2142 | * has run. | | 2188 | * has run. |
2143 | */ | | 2189 | */ |
2144 | usb_delay_ms(upipe->pipe.device->bus, 2); /* Hardware finishes in 1ms */ | | 2190 | usb_delay_ms(upipe->pipe.device->bus, 2); /* Hardware finishes in 1ms */ |
2145 | s = splusb(); | | | |
2146 | #ifdef USB_USE_SOFTINTR | | | |
2147 | sc->sc_softwake = 1; | | 2191 | sc->sc_softwake = 1; |
2148 | #endif /* USB_USE_SOFTINTR */ | | | |
2149 | usb_schedsoftintr(&sc->sc_bus); | | 2192 | usb_schedsoftintr(&sc->sc_bus); |
2150 | #ifdef USB_USE_SOFTINTR | | 2193 | DPRINTFN(1,("uhci_abort_xfer: cv_wait\n")); |
2151 | DPRINTFN(1,("uhci_abort_xfer: tsleep\n")); | | 2194 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); |
2152 | tsleep(&sc->sc_softwake, PZERO, "uhciab", 0); | | | |
2153 | #endif /* USB_USE_SOFTINTR */ | | | |
2154 | splx(s); | | | |
2155 | | | 2195 | |
2156 | /* | | 2196 | /* |
2157 | * Step 3: Execute callback. | | 2197 | * Step 3: Execute callback. |
2158 | */ | | 2198 | */ |
2159 | DPRINTFN(1,("uhci_abort_xfer: callback\n")); | | 2199 | DPRINTFN(1,("uhci_abort_xfer: callback\n")); |
2160 | s = splusb(); | | | |
2161 | #ifdef DIAGNOSTIC | | 2200 | #ifdef DIAGNOSTIC |
2162 | ii->isdone = 1; | | 2201 | ii->isdone = 1; |
2163 | #endif | | 2202 | #endif |
2164 | wake = xfer->hcflags & UXFER_ABORTWAIT; | | 2203 | wake = xfer->hcflags & UXFER_ABORTWAIT; |
2165 | xfer->hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); | | 2204 | xfer->hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); |
2166 | usb_transfer_complete(xfer); | | 2205 | usb_transfer_complete(xfer); |
2167 | if (wake) | | 2206 | if (wake) |
2168 | wakeup(&xfer->hcflags); | | 2207 | cv_broadcast(&xfer->hccv); |
2169 | splx(s); | | 2208 | done: |
| | | 2209 | mutex_exit(&sc->sc_lock); |
2170 | } | | 2210 | } |
2171 | | | 2211 | |
2172 | /* Close a device bulk pipe. */ | | 2212 | /* Close a device bulk pipe. */ |
2173 | void | | 2213 | void |
2174 | uhci_device_bulk_close(usbd_pipe_handle pipe) | | 2214 | uhci_device_bulk_close(usbd_pipe_handle pipe) |
2175 | { | | 2215 | { |
2176 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 2216 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
2177 | usbd_device_handle dev = upipe->pipe.device; | | 2217 | usbd_device_handle dev = upipe->pipe.device; |
2178 | uhci_softc_t *sc = dev->bus->hci_private; | | 2218 | uhci_softc_t *sc = dev->bus->hci_private; |
2179 | | | 2219 | |
2180 | uhci_free_sqh(sc, upipe->u.bulk.sqh); | | 2220 | uhci_free_sqh(sc, upipe->u.bulk.sqh); |
2181 | | | 2221 | |
2182 | pipe->endpoint->datatoggle = upipe->nexttoggle; | | 2222 | pipe->endpoint->datatoggle = upipe->nexttoggle; |
2183 | } | | 2223 | } |
2184 | | | 2224 | |
2185 | usbd_status | | 2225 | usbd_status |
2186 | uhci_device_ctrl_transfer(usbd_xfer_handle xfer) | | 2226 | uhci_device_ctrl_transfer(usbd_xfer_handle xfer) |
2187 | { | | 2227 | { |
| | | 2228 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
2188 | usbd_status err; | | 2229 | usbd_status err; |
2189 | | | 2230 | |
2190 | /* Insert last in queue. */ | | 2231 | /* Insert last in queue. */ |
| | | 2232 | mutex_enter(&sc->sc_lock); |
2191 | err = usb_insert_transfer(xfer); | | 2233 | err = usb_insert_transfer(xfer); |
| | | 2234 | mutex_exit(&sc->sc_lock); |
2192 | if (err) | | 2235 | if (err) |
2193 | return (err); | | 2236 | return (err); |
2194 | | | 2237 | |
2195 | /* | | 2238 | /* |
2196 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 2239 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
2197 | * so start it first. | | 2240 | * so start it first. |
2198 | */ | | 2241 | */ |
2199 | return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); | | 2242 | return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); |
2200 | } | | 2243 | } |
2201 | | | 2244 | |
2202 | usbd_status | | 2245 | usbd_status |
2203 | uhci_device_ctrl_start(usbd_xfer_handle xfer) | | 2246 | uhci_device_ctrl_start(usbd_xfer_handle xfer) |
2204 | { | | 2247 | { |
2205 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; | | 2248 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
2206 | usbd_status err; | | 2249 | usbd_status err; |
2207 | | | 2250 | |
2208 | if (sc->sc_dying) | | 2251 | if (sc->sc_dying) |
2209 | return (USBD_IOERROR); | | 2252 | return (USBD_IOERROR); |
2210 | | | 2253 | |
2211 | #ifdef DIAGNOSTIC | | 2254 | #ifdef DIAGNOSTIC |
2212 | if (!(xfer->rqflags & URQ_REQUEST)) | | 2255 | if (!(xfer->rqflags & URQ_REQUEST)) |
2213 | panic("uhci_device_ctrl_transfer: not a request"); | | 2256 | panic("uhci_device_ctrl_transfer: not a request"); |
2214 | #endif | | 2257 | #endif |
2215 | | | 2258 | |
| | | 2259 | mutex_enter(&sc->sc_lock); |
2216 | err = uhci_device_request(xfer); | | 2260 | err = uhci_device_request(xfer); |
| | | 2261 | mutex_exit(&sc->sc_lock); |
2217 | if (err) | | 2262 | if (err) |
2218 | return (err); | | 2263 | return (err); |
2219 | | | 2264 | |
2220 | if (sc->sc_bus.use_polling) | | 2265 | if (sc->sc_bus.use_polling) |
2221 | uhci_waitintr(sc, xfer); | | 2266 | uhci_waitintr(sc, xfer); |
2222 | return (USBD_IN_PROGRESS); | | 2267 | return (USBD_IN_PROGRESS); |
2223 | } | | 2268 | } |
2224 | | | 2269 | |
2225 | usbd_status | | 2270 | usbd_status |
2226 | uhci_device_intr_transfer(usbd_xfer_handle xfer) | | 2271 | uhci_device_intr_transfer(usbd_xfer_handle xfer) |
2227 | { | | 2272 | { |
| | | 2273 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
2228 | usbd_status err; | | 2274 | usbd_status err; |
2229 | | | 2275 | |
2230 | /* Insert last in queue. */ | | 2276 | /* Insert last in queue. */ |
| | | 2277 | mutex_enter(&sc->sc_lock); |
2231 | err = usb_insert_transfer(xfer); | | 2278 | err = usb_insert_transfer(xfer); |
| | | 2279 | mutex_exit(&sc->sc_lock); |
2232 | if (err) | | 2280 | if (err) |
2233 | return (err); | | 2281 | return (err); |
2234 | | | 2282 | |
2235 | /* | | 2283 | /* |
2236 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 2284 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
2237 | * so start it first. | | 2285 | * so start it first. |
2238 | */ | | 2286 | */ |
2239 | return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); | | 2287 | return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); |
2240 | } | | 2288 | } |
2241 | | | 2289 | |
2242 | usbd_status | | 2290 | usbd_status |
2243 | uhci_device_intr_start(usbd_xfer_handle xfer) | | 2291 | uhci_device_intr_start(usbd_xfer_handle xfer) |
2244 | { | | 2292 | { |
2245 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2293 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2246 | usbd_device_handle dev = upipe->pipe.device; | | 2294 | usbd_device_handle dev = upipe->pipe.device; |
2247 | uhci_softc_t *sc = dev->bus->hci_private; | | 2295 | uhci_softc_t *sc = dev->bus->hci_private; |
2248 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2296 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2249 | uhci_soft_td_t *data, *dataend; | | 2297 | uhci_soft_td_t *data, *dataend; |
2250 | uhci_soft_qh_t *sqh; | | 2298 | uhci_soft_qh_t *sqh; |
2251 | usbd_status err; | | 2299 | usbd_status err; |
2252 | int isread, endpt; | | 2300 | int isread, endpt; |
2253 | int i, s; | | 2301 | int i; |
2254 | | | 2302 | |
2255 | if (sc->sc_dying) | | 2303 | if (sc->sc_dying) |
2256 | return (USBD_IOERROR); | | 2304 | return (USBD_IOERROR); |
2257 | | | 2305 | |
2258 | DPRINTFN(3,("uhci_device_intr_transfer: xfer=%p len=%d flags=%d\n", | | 2306 | DPRINTFN(3,("uhci_device_intr_transfer: xfer=%p len=%d flags=%d\n", |
2259 | xfer, xfer->length, xfer->flags)); | | 2307 | xfer, xfer->length, xfer->flags)); |
2260 | | | 2308 | |
2261 | #ifdef DIAGNOSTIC | | 2309 | #ifdef DIAGNOSTIC |
2262 | if (xfer->rqflags & URQ_REQUEST) | | 2310 | if (xfer->rqflags & URQ_REQUEST) |
2263 | panic("uhci_device_intr_transfer: a request"); | | 2311 | panic("uhci_device_intr_transfer: a request"); |
2264 | #endif | | 2312 | #endif |
2265 | | | 2313 | |
2266 | endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; | | 2314 | endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; |
| @@ -2277,52 +2325,52 @@ uhci_device_intr_start(usbd_xfer_handle | | | @@ -2277,52 +2325,52 @@ uhci_device_intr_start(usbd_xfer_handle |
2277 | usb_syncmem(&dataend->dma, | | 2325 | usb_syncmem(&dataend->dma, |
2278 | dataend->offs + offsetof(uhci_td_t, td_status), | | 2326 | dataend->offs + offsetof(uhci_td_t, td_status), |
2279 | sizeof(dataend->td.td_status), | | 2327 | sizeof(dataend->td.td_status), |
2280 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2328 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2281 | | | 2329 | |
2282 | #ifdef UHCI_DEBUG | | 2330 | #ifdef UHCI_DEBUG |
2283 | if (uhcidebug > 10) { | | 2331 | if (uhcidebug > 10) { |
2284 | DPRINTF(("uhci_device_intr_transfer: data(1)\n")); | | 2332 | DPRINTF(("uhci_device_intr_transfer: data(1)\n")); |
2285 | uhci_dump_tds(data); | | 2333 | uhci_dump_tds(data); |
2286 | uhci_dump_qh(upipe->u.intr.qhs[0]); | | 2334 | uhci_dump_qh(upipe->u.intr.qhs[0]); |
2287 | } | | 2335 | } |
2288 | #endif | | 2336 | #endif |
2289 | | | 2337 | |
2290 | s = splusb(); | | 2338 | mutex_enter(&sc->sc_lock); |
2291 | /* Set up interrupt info. */ | | 2339 | /* Set up interrupt info. */ |
2292 | ii->xfer = xfer; | | 2340 | ii->xfer = xfer; |
2293 | ii->stdstart = data; | | 2341 | ii->stdstart = data; |
2294 | ii->stdend = dataend; | | 2342 | ii->stdend = dataend; |
2295 | #ifdef DIAGNOSTIC | | 2343 | #ifdef DIAGNOSTIC |
2296 | if (!ii->isdone) { | | 2344 | if (!ii->isdone) { |
2297 | printf("uhci_device_intr_transfer: not done, ii=%p\n", ii); | | 2345 | printf("uhci_device_intr_transfer: not done, ii=%p\n", ii); |
2298 | } | | 2346 | } |
2299 | ii->isdone = 0; | | 2347 | ii->isdone = 0; |
2300 | #endif | | 2348 | #endif |
2301 | | | 2349 | |
2302 | DPRINTFN(10,("uhci_device_intr_transfer: qhs[0]=%p\n", | | 2350 | DPRINTFN(10,("uhci_device_intr_transfer: qhs[0]=%p\n", |
2303 | upipe->u.intr.qhs[0])); | | 2351 | upipe->u.intr.qhs[0])); |
2304 | for (i = 0; i < upipe->u.intr.npoll; i++) { | | 2352 | for (i = 0; i < upipe->u.intr.npoll; i++) { |
2305 | sqh = upipe->u.intr.qhs[i]; | | 2353 | sqh = upipe->u.intr.qhs[i]; |
2306 | sqh->elink = data; | | 2354 | sqh->elink = data; |
2307 | sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); | | 2355 | sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); |
2308 | usb_syncmem(&sqh->dma, | | 2356 | usb_syncmem(&sqh->dma, |
2309 | sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 2357 | sqh->offs + offsetof(uhci_qh_t, qh_elink), |
2310 | sizeof(sqh->qh.qh_elink), | | 2358 | sizeof(sqh->qh.qh_elink), |
2311 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2359 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2312 | } | | 2360 | } |
2313 | uhci_add_intr_info(sc, ii); | | 2361 | uhci_add_intr_info(sc, ii); |
2314 | xfer->status = USBD_IN_PROGRESS; | | 2362 | xfer->status = USBD_IN_PROGRESS; |
2315 | splx(s); | | 2363 | mutex_exit(&sc->sc_lock); |
2316 | | | 2364 | |
2317 | #ifdef UHCI_DEBUG | | 2365 | #ifdef UHCI_DEBUG |
2318 | if (uhcidebug > 10) { | | 2366 | if (uhcidebug > 10) { |
2319 | DPRINTF(("uhci_device_intr_transfer: data(2)\n")); | | 2367 | DPRINTF(("uhci_device_intr_transfer: data(2)\n")); |
2320 | uhci_dump_tds(data); | | 2368 | uhci_dump_tds(data); |
2321 | uhci_dump_qh(upipe->u.intr.qhs[0]); | | 2369 | uhci_dump_qh(upipe->u.intr.qhs[0]); |
2322 | } | | 2370 | } |
2323 | #endif | | 2371 | #endif |
2324 | | | 2372 | |
2325 | return (USBD_IN_PROGRESS); | | 2373 | return (USBD_IN_PROGRESS); |
2326 | } | | 2374 | } |
2327 | | | 2375 | |
2328 | /* Abort a device control request. */ | | 2376 | /* Abort a device control request. */ |
| @@ -2348,65 +2396,65 @@ uhci_device_intr_abort(usbd_xfer_handle | | | @@ -2348,65 +2396,65 @@ uhci_device_intr_abort(usbd_xfer_handle |
2348 | DPRINTFN(1,("uhci_device_intr_abort: remove\n")); | | 2396 | DPRINTFN(1,("uhci_device_intr_abort: remove\n")); |
2349 | xfer->pipe->intrxfer = NULL; | | 2397 | xfer->pipe->intrxfer = NULL; |
2350 | } | | 2398 | } |
2351 | uhci_abort_xfer(xfer, USBD_CANCELLED); | | 2399 | uhci_abort_xfer(xfer, USBD_CANCELLED); |
2352 | } | | 2400 | } |
2353 | | | 2401 | |
2354 | /* Close a device interrupt pipe. */ | | 2402 | /* Close a device interrupt pipe. */ |
2355 | void | | 2403 | void |
2356 | uhci_device_intr_close(usbd_pipe_handle pipe) | | 2404 | uhci_device_intr_close(usbd_pipe_handle pipe) |
2357 | { | | 2405 | { |
2358 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 2406 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
2359 | uhci_softc_t *sc = pipe->device->bus->hci_private; | | 2407 | uhci_softc_t *sc = pipe->device->bus->hci_private; |
2360 | int i, npoll; | | 2408 | int i, npoll; |
2361 | int s; | | | |
2362 | | | 2409 | |
2363 | /* Unlink descriptors from controller data structures. */ | | 2410 | /* Unlink descriptors from controller data structures. */ |
2364 | npoll = upipe->u.intr.npoll; | | 2411 | npoll = upipe->u.intr.npoll; |
2365 | s = splusb(); | | 2412 | mutex_enter(&sc->sc_lock); |
2366 | for (i = 0; i < npoll; i++) | | 2413 | for (i = 0; i < npoll; i++) |
2367 | uhci_remove_intr(sc, upipe->u.intr.qhs[i]); | | 2414 | uhci_remove_intr(sc, upipe->u.intr.qhs[i]); |
2368 | splx(s); | | 2415 | mutex_exit(&sc->sc_lock); |
2369 | | | 2416 | |
2370 | /* | | 2417 | /* |
2371 | * We now have to wait for any activity on the physical | | 2418 | * We now have to wait for any activity on the physical |
2372 | * descriptors to stop. | | 2419 | * descriptors to stop. |
2373 | */ | | 2420 | */ |
2374 | usb_delay_ms(&sc->sc_bus, 2); | | 2421 | usb_delay_ms(&sc->sc_bus, 2); |
2375 | | | 2422 | |
2376 | for(i = 0; i < npoll; i++) | | 2423 | for(i = 0; i < npoll; i++) |
2377 | uhci_free_sqh(sc, upipe->u.intr.qhs[i]); | | 2424 | uhci_free_sqh(sc, upipe->u.intr.qhs[i]); |
2378 | free(upipe->u.intr.qhs, M_USBHC); | | 2425 | kmem_free(upipe->u.intr.qhs, npoll * sizeof(uhci_soft_qh_t *)); |
2379 | | | 2426 | |
2380 | /* XXX free other resources */ | | 2427 | /* XXX free other resources */ |
2381 | } | | 2428 | } |
2382 | | | 2429 | |
2383 | usbd_status | | 2430 | usbd_status |
2384 | uhci_device_request(usbd_xfer_handle xfer) | | 2431 | uhci_device_request(usbd_xfer_handle xfer) |
2385 | { | | 2432 | { |
2386 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2433 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2387 | usb_device_request_t *req = &xfer->request; | | 2434 | usb_device_request_t *req = &xfer->request; |
2388 | usbd_device_handle dev = upipe->pipe.device; | | 2435 | usbd_device_handle dev = upipe->pipe.device; |
2389 | uhci_softc_t *sc = dev->bus->hci_private; | | 2436 | uhci_softc_t *sc = dev->bus->hci_private; |
2390 | int addr = dev->address; | | 2437 | int addr = dev->address; |
2391 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; | | 2438 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; |
2392 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2439 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2393 | uhci_soft_td_t *setup, *data, *stat, *next, *dataend; | | 2440 | uhci_soft_td_t *setup, *data, *stat, *next, *dataend; |
2394 | uhci_soft_qh_t *sqh; | | 2441 | uhci_soft_qh_t *sqh; |
2395 | int len; | | 2442 | int len; |
2396 | u_int32_t ls; | | 2443 | u_int32_t ls; |
2397 | usbd_status err; | | 2444 | usbd_status err; |
2398 | int isread; | | 2445 | int isread; |
2399 | int s; | | 2446 | |
| | | 2447 | KASSERT(mutex_owned(&sc->sc_lock)); |
2400 | | | 2448 | |
2401 | DPRINTFN(3,("uhci_device_control type=0x%02x, request=0x%02x, " | | 2449 | DPRINTFN(3,("uhci_device_control type=0x%02x, request=0x%02x, " |
2402 | "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n", | | 2450 | "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n", |
2403 | req->bmRequestType, req->bRequest, UGETW(req->wValue), | | 2451 | req->bmRequestType, req->bRequest, UGETW(req->wValue), |
2404 | UGETW(req->wIndex), UGETW(req->wLength), | | 2452 | UGETW(req->wIndex), UGETW(req->wLength), |
2405 | addr, endpt)); | | 2453 | addr, endpt)); |
2406 | | | 2454 | |
2407 | ls = dev->speed == USB_SPEED_LOW ? UHCI_TD_LS : 0; | | 2455 | ls = dev->speed == USB_SPEED_LOW ? UHCI_TD_LS : 0; |
2408 | isread = req->bmRequestType & UT_READ; | | 2456 | isread = req->bmRequestType & UT_READ; |
2409 | len = UGETW(req->wLength); | | 2457 | len = UGETW(req->wLength); |
2410 | | | 2458 | |
2411 | setup = upipe->u.ctl.setup; | | 2459 | setup = upipe->u.ctl.setup; |
2412 | stat = upipe->u.ctl.stat; | | 2460 | stat = upipe->u.ctl.stat; |
| @@ -2466,27 +2514,26 @@ uhci_device_request(usbd_xfer_handle xfe | | | @@ -2466,27 +2514,26 @@ uhci_device_request(usbd_xfer_handle xfe |
2466 | ii->stdstart = setup; | | 2514 | ii->stdstart = setup; |
2467 | ii->stdend = stat; | | 2515 | ii->stdend = stat; |
2468 | #ifdef DIAGNOSTIC | | 2516 | #ifdef DIAGNOSTIC |
2469 | if (!ii->isdone) { | | 2517 | if (!ii->isdone) { |
2470 | printf("uhci_device_request: not done, ii=%p\n", ii); | | 2518 | printf("uhci_device_request: not done, ii=%p\n", ii); |
2471 | } | | 2519 | } |
2472 | ii->isdone = 0; | | 2520 | ii->isdone = 0; |
2473 | #endif | | 2521 | #endif |
2474 | | | 2522 | |
2475 | sqh->elink = setup; | | 2523 | sqh->elink = setup; |
2476 | sqh->qh.qh_elink = htole32(setup->physaddr | UHCI_PTR_TD); | | 2524 | sqh->qh.qh_elink = htole32(setup->physaddr | UHCI_PTR_TD); |
2477 | /* uhci_add_?s_ctrl() will do usb_syncmem(sqh) */ | | 2525 | /* uhci_add_?s_ctrl() will do usb_syncmem(sqh) */ |
2478 | | | 2526 | |
2479 | s = splusb(); | | | |
2480 | if (dev->speed == USB_SPEED_LOW) | | 2527 | if (dev->speed == USB_SPEED_LOW) |
2481 | uhci_add_ls_ctrl(sc, sqh); | | 2528 | uhci_add_ls_ctrl(sc, sqh); |
2482 | else | | 2529 | else |
2483 | uhci_add_hs_ctrl(sc, sqh); | | 2530 | uhci_add_hs_ctrl(sc, sqh); |
2484 | uhci_add_intr_info(sc, ii); | | 2531 | uhci_add_intr_info(sc, ii); |
2485 | #ifdef UHCI_DEBUG | | 2532 | #ifdef UHCI_DEBUG |
2486 | if (uhcidebug > 12) { | | 2533 | if (uhcidebug > 12) { |
2487 | uhci_soft_td_t *std; | | 2534 | uhci_soft_td_t *std; |
2488 | uhci_soft_qh_t *xqh; | | 2535 | uhci_soft_qh_t *xqh; |
2489 | uhci_soft_qh_t *sxqh; | | 2536 | uhci_soft_qh_t *sxqh; |
2490 | int maxqh = 0; | | 2537 | int maxqh = 0; |
2491 | uhci_physaddr_t link; | | 2538 | uhci_physaddr_t link; |
2492 | DPRINTF(("uhci_enter_ctl_q: follow from [0]\n")); | | 2539 | DPRINTF(("uhci_enter_ctl_q: follow from [0]\n")); |
| @@ -2504,67 +2551,69 @@ uhci_device_request(usbd_xfer_handle xfe | | | @@ -2504,67 +2551,69 @@ uhci_device_request(usbd_xfer_handle xfe |
2504 | xqh->hlink == xqh ? NULL : xqh->hlink)) { | | 2551 | xqh->hlink == xqh ? NULL : xqh->hlink)) { |
2505 | uhci_dump_qh(xqh); | | 2552 | uhci_dump_qh(xqh); |
2506 | } | | 2553 | } |
2507 | DPRINTF(("Enqueued QH:\n")); | | 2554 | DPRINTF(("Enqueued QH:\n")); |
2508 | uhci_dump_qh(sqh); | | 2555 | uhci_dump_qh(sqh); |
2509 | uhci_dump_tds(sqh->elink); | | 2556 | uhci_dump_tds(sqh->elink); |
2510 | } | | 2557 | } |
2511 | #endif | | 2558 | #endif |
2512 | if (xfer->timeout && !sc->sc_bus.use_polling) { | | 2559 | if (xfer->timeout && !sc->sc_bus.use_polling) { |
2513 | callout_reset(&xfer->timeout_handle, mstohz(xfer->timeout), | | 2560 | callout_reset(&xfer->timeout_handle, mstohz(xfer->timeout), |
2514 | uhci_timeout, ii); | | 2561 | uhci_timeout, ii); |
2515 | } | | 2562 | } |
2516 | xfer->status = USBD_IN_PROGRESS; | | 2563 | xfer->status = USBD_IN_PROGRESS; |
2517 | splx(s); | | | |
2518 | | | 2564 | |
2519 | return (USBD_NORMAL_COMPLETION); | | 2565 | return (USBD_NORMAL_COMPLETION); |
2520 | } | | 2566 | } |
2521 | | | 2567 | |
2522 | usbd_status | | 2568 | usbd_status |
2523 | uhci_device_isoc_transfer(usbd_xfer_handle xfer) | | 2569 | uhci_device_isoc_transfer(usbd_xfer_handle xfer) |
2524 | { | | 2570 | { |
| | | 2571 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
2525 | usbd_status err; | | 2572 | usbd_status err; |
2526 | | | 2573 | |
2527 | DPRINTFN(5,("uhci_device_isoc_transfer: xfer=%p\n", xfer)); | | 2574 | DPRINTFN(5,("uhci_device_isoc_transfer: xfer=%p\n", xfer)); |
2528 | | | 2575 | |
2529 | /* Put it on our queue, */ | | 2576 | /* Put it on our queue, */ |
| | | 2577 | mutex_enter(&sc->sc_lock); |
2530 | err = usb_insert_transfer(xfer); | | 2578 | err = usb_insert_transfer(xfer); |
| | | 2579 | mutex_exit(&sc->sc_lock); |
2531 | | | 2580 | |
2532 | /* bail out on error, */ | | 2581 | /* bail out on error, */ |
2533 | if (err && err != USBD_IN_PROGRESS) | | 2582 | if (err && err != USBD_IN_PROGRESS) |
2534 | return (err); | | 2583 | return (err); |
2535 | | | 2584 | |
2536 | /* XXX should check inuse here */ | | 2585 | /* XXX should check inuse here */ |
2537 | | | 2586 | |
2538 | /* insert into schedule, */ | | 2587 | /* insert into schedule, */ |
2539 | uhci_device_isoc_enter(xfer); | | 2588 | uhci_device_isoc_enter(xfer); |
2540 | | | 2589 | |
2541 | /* and start if the pipe wasn't running */ | | 2590 | /* and start if the pipe wasn't running */ |
2542 | if (!err) | | 2591 | if (!err) |
2543 | uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue)); | | 2592 | uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue)); |
2544 | | | 2593 | |
2545 | return (err); | | 2594 | return (err); |
2546 | } | | 2595 | } |
2547 | | | 2596 | |
2548 | void | | 2597 | void |
2549 | uhci_device_isoc_enter(usbd_xfer_handle xfer) | | 2598 | uhci_device_isoc_enter(usbd_xfer_handle xfer) |
2550 | { | | 2599 | { |
2551 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2600 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2552 | usbd_device_handle dev = upipe->pipe.device; | | 2601 | usbd_device_handle dev = upipe->pipe.device; |
2553 | uhci_softc_t *sc = dev->bus->hci_private; | | 2602 | uhci_softc_t *sc = dev->bus->hci_private; |
2554 | struct iso *iso = &upipe->u.iso; | | 2603 | struct iso *iso = &upipe->u.iso; |
2555 | uhci_soft_td_t *std; | | 2604 | uhci_soft_td_t *std; |
2556 | u_int32_t buf, len, status, offs; | | 2605 | u_int32_t buf, len, status, offs; |
2557 | int s, i, next, nframes; | | 2606 | int i, next, nframes; |
2558 | int rd = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; | | 2607 | int rd = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; |
2559 | | | 2608 | |
2560 | DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p " | | 2609 | DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p " |
2561 | "nframes=%d\n", | | 2610 | "nframes=%d\n", |
2562 | iso->inuse, iso->next, xfer, xfer->nframes)); | | 2611 | iso->inuse, iso->next, xfer, xfer->nframes)); |
2563 | | | 2612 | |
2564 | if (sc->sc_dying) | | 2613 | if (sc->sc_dying) |
2565 | return; | | 2614 | return; |
2566 | | | 2615 | |
2567 | if (xfer->status == USBD_IN_PROGRESS) { | | 2616 | if (xfer->status == USBD_IN_PROGRESS) { |
2568 | /* This request has already been entered into the frame list */ | | 2617 | /* This request has already been entered into the frame list */ |
2569 | printf("uhci_device_isoc_enter: xfer=%p in frame list\n", xfer); | | 2618 | printf("uhci_device_isoc_enter: xfer=%p in frame list\n", xfer); |
2570 | /* XXX */ | | 2619 | /* XXX */ |
| @@ -2581,27 +2630,27 @@ uhci_device_isoc_enter(usbd_xfer_handle | | | @@ -2581,27 +2630,27 @@ uhci_device_isoc_enter(usbd_xfer_handle |
2581 | next = (UREAD2(sc, UHCI_FRNUM) + 3) % UHCI_VFRAMELIST_COUNT; | | 2630 | next = (UREAD2(sc, UHCI_FRNUM) + 3) % UHCI_VFRAMELIST_COUNT; |
2582 | DPRINTFN(2,("uhci_device_isoc_enter: start next=%d\n", next)); | | 2631 | DPRINTFN(2,("uhci_device_isoc_enter: start next=%d\n", next)); |
2583 | } | | 2632 | } |
2584 | | | 2633 | |
2585 | xfer->status = USBD_IN_PROGRESS; | | 2634 | xfer->status = USBD_IN_PROGRESS; |
2586 | UXFER(xfer)->curframe = next; | | 2635 | UXFER(xfer)->curframe = next; |
2587 | | | 2636 | |
2588 | buf = DMAADDR(&xfer->dmabuf, 0); | | 2637 | buf = DMAADDR(&xfer->dmabuf, 0); |
2589 | offs = 0; | | 2638 | offs = 0; |
2590 | status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) | | | 2639 | status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) | |
2591 | UHCI_TD_ACTIVE | | | 2640 | UHCI_TD_ACTIVE | |
2592 | UHCI_TD_IOS); | | 2641 | UHCI_TD_IOS); |
2593 | nframes = xfer->nframes; | | 2642 | nframes = xfer->nframes; |
2594 | s = splusb(); | | 2643 | mutex_enter(&sc->sc_lock); |
2595 | for (i = 0; i < nframes; i++) { | | 2644 | for (i = 0; i < nframes; i++) { |
2596 | std = iso->stds[next]; | | 2645 | std = iso->stds[next]; |
2597 | if (++next >= UHCI_VFRAMELIST_COUNT) | | 2646 | if (++next >= UHCI_VFRAMELIST_COUNT) |
2598 | next = 0; | | 2647 | next = 0; |
2599 | len = xfer->frlengths[i]; | | 2648 | len = xfer->frlengths[i]; |
2600 | std->td.td_buffer = htole32(buf); | | 2649 | std->td.td_buffer = htole32(buf); |
2601 | usb_syncmem(&xfer->dmabuf, offs, len, | | 2650 | usb_syncmem(&xfer->dmabuf, offs, len, |
2602 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); | | 2651 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); |
2603 | if (i == nframes - 1) | | 2652 | if (i == nframes - 1) |
2604 | status |= UHCI_TD_IOC; | | 2653 | status |= UHCI_TD_IOC; |
2605 | std->td.td_status = htole32(status); | | 2654 | std->td.td_status = htole32(status); |
2606 | std->td.td_token &= htole32(~UHCI_TD_MAXLEN_MASK); | | 2655 | std->td.td_token &= htole32(~UHCI_TD_MAXLEN_MASK); |
2607 | std->td.td_token |= htole32(UHCI_TD_SET_MAXLEN(len)); | | 2656 | std->td.td_token |= htole32(UHCI_TD_SET_MAXLEN(len)); |
| @@ -2609,93 +2658,96 @@ uhci_device_isoc_enter(usbd_xfer_handle | | | @@ -2609,93 +2658,96 @@ uhci_device_isoc_enter(usbd_xfer_handle |
2609 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2658 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2610 | #ifdef UHCI_DEBUG | | 2659 | #ifdef UHCI_DEBUG |
2611 | if (uhcidebug > 5) { | | 2660 | if (uhcidebug > 5) { |
2612 | DPRINTFN(5,("uhci_device_isoc_enter: TD %d\n", i)); | | 2661 | DPRINTFN(5,("uhci_device_isoc_enter: TD %d\n", i)); |
2613 | uhci_dump_td(std); | | 2662 | uhci_dump_td(std); |
2614 | } | | 2663 | } |
2615 | #endif | | 2664 | #endif |
2616 | buf += len; | | 2665 | buf += len; |
2617 | offs += len; | | 2666 | offs += len; |
2618 | } | | 2667 | } |
2619 | iso->next = next; | | 2668 | iso->next = next; |
2620 | iso->inuse += xfer->nframes; | | 2669 | iso->inuse += xfer->nframes; |
2621 | | | 2670 | |
2622 | splx(s); | | 2671 | mutex_exit(&sc->sc_lock); |
2623 | } | | 2672 | } |
2624 | | | 2673 | |
2625 | usbd_status | | 2674 | usbd_status |
2626 | uhci_device_isoc_start(usbd_xfer_handle xfer) | | 2675 | uhci_device_isoc_start(usbd_xfer_handle xfer) |
2627 | { | | 2676 | { |
2628 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2677 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2629 | uhci_softc_t *sc = upipe->pipe.device->bus->hci_private; | | 2678 | uhci_softc_t *sc = upipe->pipe.device->bus->hci_private; |
2630 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2679 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2631 | uhci_soft_td_t *end; | | 2680 | uhci_soft_td_t *end; |
2632 | int s, i; | | 2681 | int i; |
2633 | | | 2682 | |
2634 | DPRINTFN(5,("uhci_device_isoc_start: xfer=%p\n", xfer)); | | 2683 | DPRINTFN(5,("uhci_device_isoc_start: xfer=%p\n", xfer)); |
2635 | | | 2684 | |
2636 | if (sc->sc_dying) | | 2685 | mutex_enter(&sc->sc_lock); |
| | | 2686 | |
| | | 2687 | if (sc->sc_dying) { |
| | | 2688 | mutex_exit(&sc->sc_lock); |
2637 | return (USBD_IOERROR); | | 2689 | return (USBD_IOERROR); |
| | | 2690 | } |
2638 | | | 2691 | |
2639 | #ifdef DIAGNOSTIC | | 2692 | #ifdef DIAGNOSTIC |
2640 | if (xfer->status != USBD_IN_PROGRESS) | | 2693 | if (xfer->status != USBD_IN_PROGRESS) |
2641 | printf("uhci_device_isoc_start: not in progress %p\n", xfer); | | 2694 | printf("uhci_device_isoc_start: not in progress %p\n", xfer); |
2642 | #endif | | 2695 | #endif |
2643 | | | 2696 | |
2644 | /* Find the last TD */ | | 2697 | /* Find the last TD */ |
2645 | i = UXFER(xfer)->curframe + xfer->nframes; | | 2698 | i = UXFER(xfer)->curframe + xfer->nframes; |
2646 | if (i >= UHCI_VFRAMELIST_COUNT) | | 2699 | if (i >= UHCI_VFRAMELIST_COUNT) |
2647 | i -= UHCI_VFRAMELIST_COUNT; | | 2700 | i -= UHCI_VFRAMELIST_COUNT; |
2648 | end = upipe->u.iso.stds[i]; | | 2701 | end = upipe->u.iso.stds[i]; |
2649 | | | 2702 | |
2650 | #ifdef DIAGNOSTIC | | 2703 | #ifdef DIAGNOSTIC |
2651 | if (end == NULL) { | | 2704 | if (end == NULL) { |
2652 | printf("uhci_device_isoc_start: end == NULL\n"); | | 2705 | printf("uhci_device_isoc_start: end == NULL\n"); |
2653 | return (USBD_INVAL); | | 2706 | return (USBD_INVAL); |
2654 | } | | 2707 | } |
2655 | #endif | | 2708 | #endif |
2656 | | | 2709 | |
2657 | s = splusb(); | | | |
2658 | | | | |
2659 | /* Set up interrupt info. */ | | 2710 | /* Set up interrupt info. */ |
2660 | ii->xfer = xfer; | | 2711 | ii->xfer = xfer; |
2661 | ii->stdstart = end; | | 2712 | ii->stdstart = end; |
2662 | ii->stdend = end; | | 2713 | ii->stdend = end; |
2663 | #ifdef DIAGNOSTIC | | 2714 | #ifdef DIAGNOSTIC |
2664 | if (!ii->isdone) | | 2715 | if (!ii->isdone) |
2665 | printf("uhci_device_isoc_start: not done, ii=%p\n", ii); | | 2716 | printf("uhci_device_isoc_start: not done, ii=%p\n", ii); |
2666 | ii->isdone = 0; | | 2717 | ii->isdone = 0; |
2667 | #endif | | 2718 | #endif |
2668 | uhci_add_intr_info(sc, ii); | | 2719 | uhci_add_intr_info(sc, ii); |
2669 | | | 2720 | |
2670 | splx(s); | | 2721 | mutex_exit(&sc->sc_lock); |
2671 | | | 2722 | |
2672 | return (USBD_IN_PROGRESS); | | 2723 | return (USBD_IN_PROGRESS); |
2673 | } | | 2724 | } |
2674 | | | 2725 | |
2675 | void | | 2726 | void |
2676 | uhci_device_isoc_abort(usbd_xfer_handle xfer) | | 2727 | uhci_device_isoc_abort(usbd_xfer_handle xfer) |
2677 | { | | 2728 | { |
| | | 2729 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
2678 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2730 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2679 | uhci_soft_td_t **stds = upipe->u.iso.stds; | | 2731 | uhci_soft_td_t **stds = upipe->u.iso.stds; |
2680 | uhci_soft_td_t *std; | | 2732 | uhci_soft_td_t *std; |
2681 | int i, n, s, nframes, maxlen, len; | | 2733 | int i, n, nframes, maxlen, len; |
2682 | | | 2734 | |
2683 | s = splusb(); | | 2735 | mutex_enter(&sc->sc_lock); |
2684 | | | 2736 | |
2685 | /* Transfer is already done. */ | | 2737 | /* Transfer is already done. */ |
2686 | if (xfer->status != USBD_NOT_STARTED && | | 2738 | if (xfer->status != USBD_NOT_STARTED && |
2687 | xfer->status != USBD_IN_PROGRESS) { | | 2739 | xfer->status != USBD_IN_PROGRESS) { |
2688 | splx(s); | | 2740 | mutex_exit(&sc->sc_lock); |
2689 | return; | | 2741 | return; |
2690 | } | | 2742 | } |
2691 | | | 2743 | |
2692 | /* Give xfer the requested abort code. */ | | 2744 | /* Give xfer the requested abort code. */ |
2693 | xfer->status = USBD_CANCELLED; | | 2745 | xfer->status = USBD_CANCELLED; |
2694 | | | 2746 | |
2695 | /* make hardware ignore it, */ | | 2747 | /* make hardware ignore it, */ |
2696 | nframes = xfer->nframes; | | 2748 | nframes = xfer->nframes; |
2697 | n = UXFER(xfer)->curframe; | | 2749 | n = UXFER(xfer)->curframe; |
2698 | maxlen = 0; | | 2750 | maxlen = 0; |
2699 | for (i = 0; i < nframes; i++) { | | 2751 | for (i = 0; i < nframes; i++) { |
2700 | std = stds[n]; | | 2752 | std = stds[n]; |
2701 | usb_syncmem(&std->dma, | | 2753 | usb_syncmem(&std->dma, |
| @@ -2717,157 +2769,162 @@ uhci_device_isoc_abort(usbd_xfer_handle | | | @@ -2717,157 +2769,162 @@ uhci_device_isoc_abort(usbd_xfer_handle |
2717 | if (++n >= UHCI_VFRAMELIST_COUNT) | | 2769 | if (++n >= UHCI_VFRAMELIST_COUNT) |
2718 | n = 0; | | 2770 | n = 0; |
2719 | } | | 2771 | } |
2720 | | | 2772 | |
2721 | /* and wait until we are sure the hardware has finished. */ | | 2773 | /* and wait until we are sure the hardware has finished. */ |
2722 | delay(maxlen); | | 2774 | delay(maxlen); |
2723 | | | 2775 | |
2724 | #ifdef DIAGNOSTIC | | 2776 | #ifdef DIAGNOSTIC |
2725 | UXFER(xfer)->iinfo.isdone = 1; | | 2777 | UXFER(xfer)->iinfo.isdone = 1; |
2726 | #endif | | 2778 | #endif |
2727 | /* Run callback and remove from interrupt list. */ | | 2779 | /* Run callback and remove from interrupt list. */ |
2728 | usb_transfer_complete(xfer); | | 2780 | usb_transfer_complete(xfer); |
2729 | | | 2781 | |
2730 | splx(s); | | 2782 | mutex_exit(&sc->sc_lock); |
2731 | } | | 2783 | } |
2732 | | | 2784 | |
2733 | void | | 2785 | void |
2734 | uhci_device_isoc_close(usbd_pipe_handle pipe) | | 2786 | uhci_device_isoc_close(usbd_pipe_handle pipe) |
2735 | { | | 2787 | { |
2736 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 2788 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
2737 | usbd_device_handle dev = upipe->pipe.device; | | 2789 | usbd_device_handle dev = upipe->pipe.device; |
2738 | uhci_softc_t *sc = dev->bus->hci_private; | | 2790 | uhci_softc_t *sc = dev->bus->hci_private; |
2739 | uhci_soft_td_t *std, *vstd; | | 2791 | uhci_soft_td_t *std, *vstd; |
2740 | struct iso *iso; | | 2792 | struct iso *iso; |
2741 | int i, s; | | 2793 | int i; |
2742 | | | 2794 | |
2743 | /* | | 2795 | /* |
2744 | * Make sure all TDs are marked as inactive. | | 2796 | * Make sure all TDs are marked as inactive. |
2745 | * Wait for completion. | | 2797 | * Wait for completion. |
2746 | * Unschedule. | | 2798 | * Unschedule. |
2747 | * Deallocate. | | 2799 | * Deallocate. |
2748 | */ | | 2800 | */ |
2749 | iso = &upipe->u.iso; | | 2801 | iso = &upipe->u.iso; |
2750 | | | 2802 | |
| | | 2803 | mutex_enter(&sc->sc_lock); |
2751 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { | | 2804 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { |
2752 | std = iso->stds[i]; | | 2805 | std = iso->stds[i]; |
2753 | usb_syncmem(&std->dma, | | 2806 | usb_syncmem(&std->dma, |
2754 | std->offs + offsetof(uhci_td_t, td_status), | | 2807 | std->offs + offsetof(uhci_td_t, td_status), |
2755 | sizeof(std->td.td_status), | | 2808 | sizeof(std->td.td_status), |
2756 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 2809 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
2757 | std->td.td_status &= htole32(~UHCI_TD_ACTIVE); | | 2810 | std->td.td_status &= htole32(~UHCI_TD_ACTIVE); |
2758 | usb_syncmem(&std->dma, | | 2811 | usb_syncmem(&std->dma, |
2759 | std->offs + offsetof(uhci_td_t, td_status), | | 2812 | std->offs + offsetof(uhci_td_t, td_status), |
2760 | sizeof(std->td.td_status), | | 2813 | sizeof(std->td.td_status), |
2761 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2814 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2762 | } | | 2815 | } |
2763 | usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */ | | 2816 | usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */ |
2764 | | | 2817 | |
2765 | s = splusb(); | | | |
2766 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { | | 2818 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { |
2767 | std = iso->stds[i]; | | 2819 | std = iso->stds[i]; |
2768 | for (vstd = sc->sc_vframes[i].htd; | | 2820 | for (vstd = sc->sc_vframes[i].htd; |
2769 | vstd != NULL && vstd->link.std != std; | | 2821 | vstd != NULL && vstd->link.std != std; |
2770 | vstd = vstd->link.std) | | 2822 | vstd = vstd->link.std) |
2771 | ; | | 2823 | ; |
2772 | if (vstd == NULL) { | | 2824 | if (vstd == NULL) { |
2773 | /*panic*/ | | 2825 | /*panic*/ |
2774 | printf("uhci_device_isoc_close: %p not found\n", std); | | 2826 | printf("uhci_device_isoc_close: %p not found\n", std); |
2775 | splx(s); | | 2827 | mutex_exit(&sc->sc_lock); |
2776 | return; | | 2828 | return; |
2777 | } | | 2829 | } |
2778 | vstd->link = std->link; | | 2830 | vstd->link = std->link; |
2779 | usb_syncmem(&std->dma, | | 2831 | usb_syncmem(&std->dma, |
2780 | std->offs + offsetof(uhci_td_t, td_link), | | 2832 | std->offs + offsetof(uhci_td_t, td_link), |
2781 | sizeof(std->td.td_link), | | 2833 | sizeof(std->td.td_link), |
2782 | BUS_DMASYNC_POSTWRITE); | | 2834 | BUS_DMASYNC_POSTWRITE); |
2783 | vstd->td.td_link = std->td.td_link; | | 2835 | vstd->td.td_link = std->td.td_link; |
2784 | usb_syncmem(&vstd->dma, | | 2836 | usb_syncmem(&vstd->dma, |
2785 | vstd->offs + offsetof(uhci_td_t, td_link), | | 2837 | vstd->offs + offsetof(uhci_td_t, td_link), |
2786 | sizeof(vstd->td.td_link), | | 2838 | sizeof(vstd->td.td_link), |
2787 | BUS_DMASYNC_PREWRITE); | | 2839 | BUS_DMASYNC_PREWRITE); |
2788 | uhci_free_std(sc, std); | | 2840 | uhci_free_std(sc, std); |
2789 | } | | 2841 | } |
2790 | splx(s); | | 2842 | mutex_exit(&sc->sc_lock); |
2791 | | | 2843 | |
2792 | free(iso->stds, M_USBHC); | | 2844 | kmem_free(iso->stds, UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *)); |
2793 | } | | 2845 | } |
2794 | | | 2846 | |
2795 | usbd_status | | 2847 | usbd_status |
2796 | uhci_setup_isoc(usbd_pipe_handle pipe) | | 2848 | uhci_setup_isoc(usbd_pipe_handle pipe) |
2797 | { | | 2849 | { |
2798 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 2850 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
2799 | usbd_device_handle dev = upipe->pipe.device; | | 2851 | usbd_device_handle dev = upipe->pipe.device; |
2800 | uhci_softc_t *sc = dev->bus->hci_private; | | 2852 | uhci_softc_t *sc = dev->bus->hci_private; |
2801 | int addr = upipe->pipe.device->address; | | 2853 | int addr = upipe->pipe.device->address; |
2802 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; | | 2854 | int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; |
2803 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; | | 2855 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; |
2804 | uhci_soft_td_t *std, *vstd; | | 2856 | uhci_soft_td_t *std, *vstd; |
2805 | u_int32_t token; | | 2857 | u_int32_t token; |
2806 | struct iso *iso; | | 2858 | struct iso *iso; |
2807 | int i, s; | | 2859 | int i; |
2808 | | | 2860 | |
2809 | iso = &upipe->u.iso; | | 2861 | iso = &upipe->u.iso; |
2810 | iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *), | | 2862 | iso->stds = kmem_alloc(UHCI_VFRAMELIST_COUNT * |
2811 | M_USBHC, M_WAITOK); | | 2863 | sizeof (uhci_soft_td_t *), |
| | | 2864 | KM_SLEEP); |
| | | 2865 | if (iso->stds == NULL) |
| | | 2866 | return USBD_NOMEM; |
2812 | | | 2867 | |
2813 | token = rd ? UHCI_TD_IN (0, endpt, addr, 0) : | | 2868 | token = rd ? UHCI_TD_IN (0, endpt, addr, 0) : |
2814 | UHCI_TD_OUT(0, endpt, addr, 0); | | 2869 | UHCI_TD_OUT(0, endpt, addr, 0); |
2815 | | | 2870 | |
| | | 2871 | mutex_enter(&sc->sc_lock); |
| | | 2872 | |
2816 | /* Allocate the TDs and mark as inactive; */ | | 2873 | /* Allocate the TDs and mark as inactive; */ |
2817 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { | | 2874 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { |
2818 | std = uhci_alloc_std(sc); | | 2875 | std = uhci_alloc_std(sc); |
2819 | if (std == 0) | | 2876 | if (std == 0) |
2820 | goto bad; | | 2877 | goto bad; |
2821 | std->td.td_status = htole32(UHCI_TD_IOS); /* iso, inactive */ | | 2878 | std->td.td_status = htole32(UHCI_TD_IOS); /* iso, inactive */ |
2822 | std->td.td_token = htole32(token); | | 2879 | std->td.td_token = htole32(token); |
2823 | usb_syncmem(&std->dma, std->offs, sizeof(std->td), | | 2880 | usb_syncmem(&std->dma, std->offs, sizeof(std->td), |
2824 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2881 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2825 | iso->stds[i] = std; | | 2882 | iso->stds[i] = std; |
2826 | } | | 2883 | } |
2827 | | | 2884 | |
2828 | /* Insert TDs into schedule. */ | | 2885 | /* Insert TDs into schedule. */ |
2829 | s = splusb(); | | | |
2830 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { | | 2886 | for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) { |
2831 | std = iso->stds[i]; | | 2887 | std = iso->stds[i]; |
2832 | vstd = sc->sc_vframes[i].htd; | | 2888 | vstd = sc->sc_vframes[i].htd; |
2833 | usb_syncmem(&vstd->dma, | | 2889 | usb_syncmem(&vstd->dma, |
2834 | vstd->offs + offsetof(uhci_td_t, td_link), | | 2890 | vstd->offs + offsetof(uhci_td_t, td_link), |
2835 | sizeof(vstd->td.td_link), | | 2891 | sizeof(vstd->td.td_link), |
2836 | BUS_DMASYNC_POSTWRITE); | | 2892 | BUS_DMASYNC_POSTWRITE); |
2837 | std->link = vstd->link; | | 2893 | std->link = vstd->link; |
2838 | std->td.td_link = vstd->td.td_link; | | 2894 | std->td.td_link = vstd->td.td_link; |
2839 | usb_syncmem(&std->dma, | | 2895 | usb_syncmem(&std->dma, |
2840 | std->offs + offsetof(uhci_td_t, td_link), | | 2896 | std->offs + offsetof(uhci_td_t, td_link), |
2841 | sizeof(std->td.td_link), | | 2897 | sizeof(std->td.td_link), |
2842 | BUS_DMASYNC_PREWRITE); | | 2898 | BUS_DMASYNC_PREWRITE); |
2843 | vstd->link.std = std; | | 2899 | vstd->link.std = std; |
2844 | vstd->td.td_link = htole32(std->physaddr | UHCI_PTR_TD); | | 2900 | vstd->td.td_link = htole32(std->physaddr | UHCI_PTR_TD); |
2845 | usb_syncmem(&vstd->dma, | | 2901 | usb_syncmem(&vstd->dma, |
2846 | vstd->offs + offsetof(uhci_td_t, td_link), | | 2902 | vstd->offs + offsetof(uhci_td_t, td_link), |
2847 | sizeof(vstd->td.td_link), | | 2903 | sizeof(vstd->td.td_link), |
2848 | BUS_DMASYNC_PREWRITE); | | 2904 | BUS_DMASYNC_PREWRITE); |
2849 | } | | 2905 | } |
2850 | splx(s); | | 2906 | mutex_exit(&sc->sc_lock); |
2851 | | | 2907 | |
2852 | iso->next = -1; | | 2908 | iso->next = -1; |
2853 | iso->inuse = 0; | | 2909 | iso->inuse = 0; |
2854 | | | 2910 | |
2855 | return (USBD_NORMAL_COMPLETION); | | 2911 | return (USBD_NORMAL_COMPLETION); |
2856 | | | 2912 | |
2857 | bad: | | 2913 | bad: |
2858 | while (--i >= 0) | | 2914 | while (--i >= 0) |
2859 | uhci_free_std(sc, iso->stds[i]); | | 2915 | uhci_free_std(sc, iso->stds[i]); |
2860 | free(iso->stds, M_USBHC); | | 2916 | mutex_exit(&sc->sc_lock); |
| | | 2917 | kmem_free(iso->stds, UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *)); |
2861 | return (USBD_NOMEM); | | 2918 | return (USBD_NOMEM); |
2862 | } | | 2919 | } |
2863 | | | 2920 | |
2864 | void | | 2921 | void |
2865 | uhci_device_isoc_done(usbd_xfer_handle xfer) | | 2922 | uhci_device_isoc_done(usbd_xfer_handle xfer) |
2866 | { | | 2923 | { |
2867 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2924 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2868 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2925 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2869 | int i, offs; | | 2926 | int i, offs; |
2870 | int rd = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; | | 2927 | int rd = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; |
2871 | | | 2928 | |
2872 | | | 2929 | |
2873 | DPRINTFN(4, ("uhci_isoc_done: length=%d, busy_free=0x%08x\n", | | 2930 | DPRINTFN(4, ("uhci_isoc_done: length=%d, busy_free=0x%08x\n", |
| @@ -2912,26 +2969,28 @@ uhci_device_isoc_done(usbd_xfer_handle x | | | @@ -2912,26 +2969,28 @@ uhci_device_isoc_done(usbd_xfer_handle x |
2912 | } | | 2969 | } |
2913 | | | 2970 | |
2914 | void | | 2971 | void |
2915 | uhci_device_intr_done(usbd_xfer_handle xfer) | | 2972 | uhci_device_intr_done(usbd_xfer_handle xfer) |
2916 | { | | 2973 | { |
2917 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 2974 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2918 | uhci_softc_t *sc = ii->sc; | | 2975 | uhci_softc_t *sc = ii->sc; |
2919 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 2976 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2920 | uhci_soft_qh_t *sqh; | | 2977 | uhci_soft_qh_t *sqh; |
2921 | int i, npoll, isread; | | 2978 | int i, npoll, isread; |
2922 | | | 2979 | |
2923 | DPRINTFN(5, ("uhci_device_intr_done: length=%d\n", xfer->actlen)); | | 2980 | DPRINTFN(5, ("uhci_device_intr_done: length=%d\n", xfer->actlen)); |
2924 | | | 2981 | |
| | | 2982 | KASSERT(mutex_owned(&sc->sc_lock)); |
| | | 2983 | |
2925 | npoll = upipe->u.intr.npoll; | | 2984 | npoll = upipe->u.intr.npoll; |
2926 | for(i = 0; i < npoll; i++) { | | 2985 | for(i = 0; i < npoll; i++) { |
2927 | sqh = upipe->u.intr.qhs[i]; | | 2986 | sqh = upipe->u.intr.qhs[i]; |
2928 | sqh->elink = NULL; | | 2987 | sqh->elink = NULL; |
2929 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); | | 2988 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); |
2930 | usb_syncmem(&sqh->dma, | | 2989 | usb_syncmem(&sqh->dma, |
2931 | sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 2990 | sqh->offs + offsetof(uhci_qh_t, qh_elink), |
2932 | sizeof(sqh->qh.qh_elink), | | 2991 | sizeof(sqh->qh.qh_elink), |
2933 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2992 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2934 | } | | 2993 | } |
2935 | uhci_free_std_chain(sc, ii->stdstart, NULL); | | 2994 | uhci_free_std_chain(sc, ii->stdstart, NULL); |
2936 | | | 2995 | |
2937 | isread = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; | | 2996 | isread = UE_GET_DIR(upipe->pipe.endpoint->edesc->bEndpointAddress) == UE_DIR_IN; |
| @@ -2988,26 +3047,28 @@ uhci_device_intr_done(usbd_xfer_handle x | | | @@ -2988,26 +3047,28 @@ uhci_device_intr_done(usbd_xfer_handle x |
2988 | } | | 3047 | } |
2989 | } | | 3048 | } |
2990 | | | 3049 | |
2991 | /* Deallocate request data structures */ | | 3050 | /* Deallocate request data structures */ |
2992 | void | | 3051 | void |
2993 | uhci_device_ctrl_done(usbd_xfer_handle xfer) | | 3052 | uhci_device_ctrl_done(usbd_xfer_handle xfer) |
2994 | { | | 3053 | { |
2995 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 3054 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
2996 | uhci_softc_t *sc = ii->sc; | | 3055 | uhci_softc_t *sc = ii->sc; |
2997 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 3056 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
2998 | int len = UGETW(xfer->request.wLength); | | 3057 | int len = UGETW(xfer->request.wLength); |
2999 | int isread = (xfer->request.bmRequestType & UT_READ); | | 3058 | int isread = (xfer->request.bmRequestType & UT_READ); |
3000 | | | 3059 | |
| | | 3060 | KASSERT(mutex_owned(&sc->sc_lock)); |
| | | 3061 | |
3001 | #ifdef DIAGNOSTIC | | 3062 | #ifdef DIAGNOSTIC |
3002 | if (!(xfer->rqflags & URQ_REQUEST)) | | 3063 | if (!(xfer->rqflags & URQ_REQUEST)) |
3003 | panic("uhci_device_ctrl_done: not a request"); | | 3064 | panic("uhci_device_ctrl_done: not a request"); |
3004 | #endif | | 3065 | #endif |
3005 | | | 3066 | |
3006 | if (!uhci_active_intr_info(ii)) | | 3067 | if (!uhci_active_intr_info(ii)) |
3007 | return; | | 3068 | return; |
3008 | | | 3069 | |
3009 | uhci_del_intr_info(ii); /* remove from active list */ | | 3070 | uhci_del_intr_info(ii); /* remove from active list */ |
3010 | | | 3071 | |
3011 | if (upipe->pipe.device->speed == USB_SPEED_LOW) | | 3072 | if (upipe->pipe.device->speed == USB_SPEED_LOW) |
3012 | uhci_remove_ls_ctrl(sc, upipe->u.ctl.sqh); | | 3073 | uhci_remove_ls_ctrl(sc, upipe->u.ctl.sqh); |
3013 | else | | 3074 | else |
| @@ -3027,26 +3088,28 @@ uhci_device_ctrl_done(usbd_xfer_handle x | | | @@ -3027,26 +3088,28 @@ uhci_device_ctrl_done(usbd_xfer_handle x |
3027 | } | | 3088 | } |
3028 | | | 3089 | |
3029 | /* Deallocate request data structures */ | | 3090 | /* Deallocate request data structures */ |
3030 | void | | 3091 | void |
3031 | uhci_device_bulk_done(usbd_xfer_handle xfer) | | 3092 | uhci_device_bulk_done(usbd_xfer_handle xfer) |
3032 | { | | 3093 | { |
3033 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; | | 3094 | uhci_intr_info_t *ii = &UXFER(xfer)->iinfo; |
3034 | uhci_softc_t *sc = ii->sc; | | 3095 | uhci_softc_t *sc = ii->sc; |
3035 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; | | 3096 | struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; |
3036 | | | 3097 | |
3037 | DPRINTFN(5,("uhci_device_bulk_done: xfer=%p ii=%p sc=%p upipe=%p\n", | | 3098 | DPRINTFN(5,("uhci_device_bulk_done: xfer=%p ii=%p sc=%p upipe=%p\n", |
3038 | xfer, ii, sc, upipe)); | | 3099 | xfer, ii, sc, upipe)); |
3039 | | | 3100 | |
| | | 3101 | KASSERT(mutex_owned(&sc->sc_lock)); |
| | | 3102 | |
3040 | if (!uhci_active_intr_info(ii)) | | 3103 | if (!uhci_active_intr_info(ii)) |
3041 | return; | | 3104 | return; |
3042 | | | 3105 | |
3043 | uhci_del_intr_info(ii); /* remove from active list */ | | 3106 | uhci_del_intr_info(ii); /* remove from active list */ |
3044 | | | 3107 | |
3045 | uhci_remove_bulk(sc, upipe->u.bulk.sqh); | | 3108 | uhci_remove_bulk(sc, upipe->u.bulk.sqh); |
3046 | | | 3109 | |
3047 | uhci_free_std_chain(sc, ii->stdstart, NULL); | | 3110 | uhci_free_std_chain(sc, ii->stdstart, NULL); |
3048 | | | 3111 | |
3049 | DPRINTFN(5, ("uhci_device_bulk_done: length=%d\n", xfer->actlen)); | | 3112 | DPRINTFN(5, ("uhci_device_bulk_done: length=%d\n", xfer->actlen)); |
3050 | } | | 3113 | } |
3051 | | | 3114 | |
3052 | /* Add interrupt QH, called with vflock. */ | | 3115 | /* Add interrupt QH, called with vflock. */ |
| @@ -3108,95 +3171,100 @@ uhci_remove_intr(uhci_softc_t *sc, uhci_ | | | @@ -3108,95 +3171,100 @@ uhci_remove_intr(uhci_softc_t *sc, uhci_ |
3108 | usb_syncmem(&pqh->dma, pqh->offs + offsetof(uhci_qh_t, qh_hlink), | | 3171 | usb_syncmem(&pqh->dma, pqh->offs + offsetof(uhci_qh_t, qh_hlink), |
3109 | sizeof(pqh->qh.qh_hlink), | | 3172 | sizeof(pqh->qh.qh_hlink), |
3110 | BUS_DMASYNC_PREWRITE); | | 3173 | BUS_DMASYNC_PREWRITE); |
3111 | delay(UHCI_QH_REMOVE_DELAY); | | 3174 | delay(UHCI_QH_REMOVE_DELAY); |
3112 | if (vf->eqh == sqh) | | 3175 | if (vf->eqh == sqh) |
3113 | vf->eqh = pqh; | | 3176 | vf->eqh = pqh; |
3114 | vf->bandwidth--; | | 3177 | vf->bandwidth--; |
3115 | } | | 3178 | } |
3116 | | | 3179 | |
3117 | usbd_status | | 3180 | usbd_status |
3118 | uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival) | | 3181 | uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival) |
3119 | { | | 3182 | { |
3120 | uhci_soft_qh_t *sqh; | | 3183 | uhci_soft_qh_t *sqh; |
3121 | int i, npoll, s; | | 3184 | int i, npoll; |
3122 | u_int bestbw, bw, bestoffs, offs; | | 3185 | u_int bestbw, bw, bestoffs, offs; |
3123 | | | 3186 | |
3124 | DPRINTFN(2, ("uhci_device_setintr: pipe=%p\n", upipe)); | | 3187 | DPRINTFN(2, ("uhci_device_setintr: pipe=%p\n", upipe)); |
3125 | if (ival == 0) { | | 3188 | if (ival == 0) { |
3126 | printf("uhci_device_setintr: 0 interval\n"); | | 3189 | printf("uhci_device_setintr: 0 interval\n"); |
3127 | return (USBD_INVAL); | | 3190 | return (USBD_INVAL); |
3128 | } | | 3191 | } |
3129 | | | 3192 | |
3130 | if (ival > UHCI_VFRAMELIST_COUNT) | | 3193 | if (ival > UHCI_VFRAMELIST_COUNT) |
3131 | ival = UHCI_VFRAMELIST_COUNT; | | 3194 | ival = UHCI_VFRAMELIST_COUNT; |
3132 | npoll = (UHCI_VFRAMELIST_COUNT + ival - 1) / ival; | | 3195 | npoll = (UHCI_VFRAMELIST_COUNT + ival - 1) / ival; |
3133 | DPRINTFN(2, ("uhci_device_setintr: ival=%d npoll=%d\n", ival, npoll)); | | 3196 | DPRINTFN(2, ("uhci_device_setintr: ival=%d npoll=%d\n", ival, npoll)); |
3134 | | | 3197 | |
3135 | upipe->u.intr.npoll = npoll; | | 3198 | upipe->u.intr.npoll = npoll; |
3136 | upipe->u.intr.qhs = | | 3199 | upipe->u.intr.qhs = |
3137 | malloc(npoll * sizeof(uhci_soft_qh_t *), M_USBHC, M_WAITOK); | | 3200 | kmem_alloc(npoll * sizeof(uhci_soft_qh_t *), KM_SLEEP); |
| | | 3201 | if (upipe->u.intr.qhs == NULL) |
| | | 3202 | return USBD_NOMEM; |
3138 | | | 3203 | |
3139 | /* | | 3204 | /* |
3140 | * Figure out which offset in the schedule that has most | | 3205 | * Figure out which offset in the schedule that has most |
3141 | * bandwidth left over. | | 3206 | * bandwidth left over. |
3142 | */ | | 3207 | */ |
3143 | #define MOD(i) ((i) & (UHCI_VFRAMELIST_COUNT-1)) | | 3208 | #define MOD(i) ((i) & (UHCI_VFRAMELIST_COUNT-1)) |
3144 | for (bestoffs = offs = 0, bestbw = ~0; offs < ival; offs++) { | | 3209 | for (bestoffs = offs = 0, bestbw = ~0; offs < ival; offs++) { |
3145 | for (bw = i = 0; i < npoll; i++) | | 3210 | for (bw = i = 0; i < npoll; i++) |
3146 | bw += sc->sc_vframes[MOD(i * ival + offs)].bandwidth; | | 3211 | bw += sc->sc_vframes[MOD(i * ival + offs)].bandwidth; |
3147 | if (bw < bestbw) { | | 3212 | if (bw < bestbw) { |
3148 | bestbw = bw; | | 3213 | bestbw = bw; |
3149 | bestoffs = offs; | | 3214 | bestoffs = offs; |
3150 | } | | 3215 | } |
3151 | } | | 3216 | } |
3152 | DPRINTFN(1, ("uhci_device_setintr: bw=%d offs=%d\n", bestbw, bestoffs)); | | 3217 | DPRINTFN(1, ("uhci_device_setintr: bw=%d offs=%d\n", bestbw, bestoffs)); |
3153 | | | 3218 | |
| | | 3219 | mutex_enter(&sc->sc_lock); |
3154 | for(i = 0; i < npoll; i++) { | | 3220 | for(i = 0; i < npoll; i++) { |
3155 | upipe->u.intr.qhs[i] = sqh = uhci_alloc_sqh(sc); | | 3221 | upipe->u.intr.qhs[i] = sqh = uhci_alloc_sqh(sc); |
3156 | sqh->elink = NULL; | | 3222 | sqh->elink = NULL; |
3157 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); | | 3223 | sqh->qh.qh_elink = htole32(UHCI_PTR_T); |
3158 | usb_syncmem(&sqh->dma, | | 3224 | usb_syncmem(&sqh->dma, |
3159 | sqh->offs + offsetof(uhci_qh_t, qh_elink), | | 3225 | sqh->offs + offsetof(uhci_qh_t, qh_elink), |
3160 | sizeof(sqh->qh.qh_elink), | | 3226 | sizeof(sqh->qh.qh_elink), |
3161 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3227 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3162 | sqh->pos = MOD(i * ival + bestoffs); | | 3228 | sqh->pos = MOD(i * ival + bestoffs); |
3163 | } | | 3229 | } |
3164 | #undef MOD | | 3230 | #undef MOD |
3165 | | | 3231 | |
3166 | s = splusb(); | | | |
3167 | /* Enter QHs into the controller data structures. */ | | 3232 | /* Enter QHs into the controller data structures. */ |
3168 | for(i = 0; i < npoll; i++) | | 3233 | for(i = 0; i < npoll; i++) |
3169 | uhci_add_intr(sc, upipe->u.intr.qhs[i]); | | 3234 | uhci_add_intr(sc, upipe->u.intr.qhs[i]); |
3170 | splx(s); | | 3235 | mutex_exit(&sc->sc_lock); |
3171 | | | 3236 | |
3172 | DPRINTFN(5, ("uhci_device_setintr: returns %p\n", upipe)); | | 3237 | DPRINTFN(5, ("uhci_device_setintr: returns %p\n", upipe)); |
3173 | return (USBD_NORMAL_COMPLETION); | | 3238 | return (USBD_NORMAL_COMPLETION); |
3174 | } | | 3239 | } |
3175 | | | 3240 | |
3176 | /* Open a new pipe. */ | | 3241 | /* Open a new pipe. */ |
3177 | usbd_status | | 3242 | usbd_status |
3178 | uhci_open(usbd_pipe_handle pipe) | | 3243 | uhci_open(usbd_pipe_handle pipe) |
3179 | { | | 3244 | { |
3180 | uhci_softc_t *sc = pipe->device->bus->hci_private; | | 3245 | uhci_softc_t *sc = pipe->device->bus->hci_private; |
3181 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; | | 3246 | struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; |
3182 | usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc; | | 3247 | usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc; |
3183 | usbd_status err; | | 3248 | usbd_status err = USBD_NOMEM; |
3184 | int ival; | | 3249 | int ival; |
3185 | | | 3250 | |
3186 | DPRINTFN(1, ("uhci_open: pipe=%p, addr=%d, endpt=%d (%d)\n", | | 3251 | DPRINTFN(1, ("uhci_open: pipe=%p, addr=%d, endpt=%d (%d)\n", |
3187 | pipe, pipe->device->address, | | 3252 | pipe, pipe->device->address, |
3188 | ed->bEndpointAddress, sc->sc_addr)); | | 3253 | ed->bEndpointAddress, sc->sc_addr)); |
3189 | | | 3254 | |
| | | 3255 | if (sc->sc_dying) |
| | | 3256 | return USBD_IOERROR; |
| | | 3257 | |
3190 | upipe->aborting = 0; | | 3258 | upipe->aborting = 0; |
3191 | /* toggle state needed for bulk endpoints */ | | 3259 | /* toggle state needed for bulk endpoints */ |
3192 | upipe->nexttoggle = pipe->endpoint->datatoggle; | | 3260 | upipe->nexttoggle = pipe->endpoint->datatoggle; |
3193 | | | 3261 | |
3194 | if (pipe->device->address == sc->sc_addr) { | | 3262 | if (pipe->device->address == sc->sc_addr) { |
3195 | switch (ed->bEndpointAddress) { | | 3263 | switch (ed->bEndpointAddress) { |
3196 | case USB_CONTROL_ENDPOINT: | | 3264 | case USB_CONTROL_ENDPOINT: |
3197 | pipe->methods = &uhci_root_ctrl_methods; | | 3265 | pipe->methods = &uhci_root_ctrl_methods; |
3198 | break; | | 3266 | break; |
3199 | case UE_DIR_IN | UHCI_INTR_ENDPT: | | 3267 | case UE_DIR_IN | UHCI_INTR_ENDPT: |
3200 | pipe->methods = &uhci_root_intr_methods; | | 3268 | pipe->methods = &uhci_root_intr_methods; |
3201 | break; | | 3269 | break; |
3202 | default: | | 3270 | default: |
| @@ -3240,27 +3308,27 @@ uhci_open(usbd_pipe_handle pipe) | | | @@ -3240,27 +3308,27 @@ uhci_open(usbd_pipe_handle pipe) |
3240 | pipe->methods = &uhci_device_isoc_methods; | | 3308 | pipe->methods = &uhci_device_isoc_methods; |
3241 | return (uhci_setup_isoc(pipe)); | | 3309 | return (uhci_setup_isoc(pipe)); |
3242 | case UE_BULK: | | 3310 | case UE_BULK: |
3243 | pipe->methods = &uhci_device_bulk_methods; | | 3311 | pipe->methods = &uhci_device_bulk_methods; |
3244 | upipe->u.bulk.sqh = uhci_alloc_sqh(sc); | | 3312 | upipe->u.bulk.sqh = uhci_alloc_sqh(sc); |
3245 | if (upipe->u.bulk.sqh == NULL) | | 3313 | if (upipe->u.bulk.sqh == NULL) |
3246 | goto bad; | | 3314 | goto bad; |
3247 | break; | | 3315 | break; |
3248 | } | | 3316 | } |
3249 | } | | 3317 | } |
3250 | return (USBD_NORMAL_COMPLETION); | | 3318 | return (USBD_NORMAL_COMPLETION); |
3251 | | | 3319 | |
3252 | bad: | | 3320 | bad: |
3253 | return (USBD_NOMEM); | | 3321 | return USBD_NOMEM; |
3254 | } | | 3322 | } |
3255 | | | 3323 | |
3256 | /* | | 3324 | /* |
3257 | * Data structures and routines to emulate the root hub. | | 3325 | * Data structures and routines to emulate the root hub. |
3258 | */ | | 3326 | */ |
3259 | usb_device_descriptor_t uhci_devd = { | | 3327 | usb_device_descriptor_t uhci_devd = { |
3260 | USB_DEVICE_DESCRIPTOR_SIZE, | | 3328 | USB_DEVICE_DESCRIPTOR_SIZE, |
3261 | UDESC_DEVICE, /* type */ | | 3329 | UDESC_DEVICE, /* type */ |
3262 | {0x00, 0x01}, /* USB version */ | | 3330 | {0x00, 0x01}, /* USB version */ |
3263 | UDCLASS_HUB, /* class */ | | 3331 | UDCLASS_HUB, /* class */ |
3264 | UDSUBCLASS_HUB, /* subclass */ | | 3332 | UDSUBCLASS_HUB, /* subclass */ |
3265 | UDPROTO_FSHUB, /* protocol */ | | 3333 | UDPROTO_FSHUB, /* protocol */ |
3266 | 64, /* max packet */ | | 3334 | 64, /* max packet */ |
| @@ -3405,48 +3473,51 @@ uhci_portreset(uhci_softc_t *sc, int ind | | | @@ -3405,48 +3473,51 @@ uhci_portreset(uhci_softc_t *sc, int ind |
3405 | return (USBD_TIMEOUT); | | 3473 | return (USBD_TIMEOUT); |
3406 | } | | 3474 | } |
3407 | | | 3475 | |
3408 | sc->sc_isreset = 1; | | 3476 | sc->sc_isreset = 1; |
3409 | return (USBD_NORMAL_COMPLETION); | | 3477 | return (USBD_NORMAL_COMPLETION); |
3410 | } | | 3478 | } |
3411 | | | 3479 | |
3412 | /* | | 3480 | /* |
3413 | * Simulate a hardware hub by handling all the necessary requests. | | 3481 | * Simulate a hardware hub by handling all the necessary requests. |
3414 | */ | | 3482 | */ |
3415 | usbd_status | | 3483 | usbd_status |
3416 | uhci_root_ctrl_transfer(usbd_xfer_handle xfer) | | 3484 | uhci_root_ctrl_transfer(usbd_xfer_handle xfer) |
3417 | { | | 3485 | { |
| | | 3486 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
3418 | usbd_status err; | | 3487 | usbd_status err; |
3419 | | | 3488 | |
3420 | /* Insert last in queue. */ | | 3489 | /* Insert last in queue. */ |
| | | 3490 | mutex_enter(&sc->sc_lock); |
3421 | err = usb_insert_transfer(xfer); | | 3491 | err = usb_insert_transfer(xfer); |
| | | 3492 | mutex_exit(&sc->sc_lock); |
3422 | if (err) | | 3493 | if (err) |
3423 | return (err); | | 3494 | return (err); |
3424 | | | 3495 | |
3425 | /* | | 3496 | /* |
3426 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 3497 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
3427 | * so start it first. | | 3498 | * so start it first. |
3428 | */ | | 3499 | */ |
3429 | return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); | | 3500 | return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); |
3430 | } | | 3501 | } |
3431 | | | 3502 | |
3432 | usbd_status | | 3503 | usbd_status |
3433 | uhci_root_ctrl_start(usbd_xfer_handle xfer) | | 3504 | uhci_root_ctrl_start(usbd_xfer_handle xfer) |
3434 | { | | 3505 | { |
3435 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; | | 3506 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
3436 | usb_device_request_t *req; | | 3507 | usb_device_request_t *req; |
3437 | void *buf = NULL; | | 3508 | void *buf = NULL; |
3438 | int port, x; | | 3509 | int port, x; |
3439 | int s, len, value, index, status, change, l, totlen = 0; | | 3510 | int len, value, index, status, change, l, totlen = 0; |
3440 | usb_port_status_t ps; | | 3511 | usb_port_status_t ps; |
3441 | usbd_status err; | | 3512 | usbd_status err; |
3442 | | | 3513 | |
3443 | if (sc->sc_dying) | | 3514 | if (sc->sc_dying) |
3444 | return (USBD_IOERROR); | | 3515 | return (USBD_IOERROR); |
3445 | | | 3516 | |
3446 | #ifdef DIAGNOSTIC | | 3517 | #ifdef DIAGNOSTIC |
3447 | if (!(xfer->rqflags & URQ_REQUEST)) | | 3518 | if (!(xfer->rqflags & URQ_REQUEST)) |
3448 | panic("uhci_root_ctrl_transfer: not a request"); | | 3519 | panic("uhci_root_ctrl_transfer: not a request"); |
3449 | #endif | | 3520 | #endif |
3450 | req = &xfer->request; | | 3521 | req = &xfer->request; |
3451 | | | 3522 | |
3452 | DPRINTFN(2,("uhci_root_ctrl_control type=0x%02x request=%02x\n", | | 3523 | DPRINTFN(2,("uhci_root_ctrl_control type=0x%02x request=%02x\n", |
| @@ -3749,29 +3820,29 @@ uhci_root_ctrl_start(usbd_xfer_handle xf | | | @@ -3749,29 +3820,29 @@ uhci_root_ctrl_start(usbd_xfer_handle xf |
3749 | default: | | 3820 | default: |
3750 | err = USBD_IOERROR; | | 3821 | err = USBD_IOERROR; |
3751 | goto ret; | | 3822 | goto ret; |
3752 | } | | 3823 | } |
3753 | break; | | 3824 | break; |
3754 | default: | | 3825 | default: |
3755 | err = USBD_IOERROR; | | 3826 | err = USBD_IOERROR; |
3756 | goto ret; | | 3827 | goto ret; |
3757 | } | | 3828 | } |
3758 | xfer->actlen = totlen; | | 3829 | xfer->actlen = totlen; |
3759 | err = USBD_NORMAL_COMPLETION; | | 3830 | err = USBD_NORMAL_COMPLETION; |
3760 | ret: | | 3831 | ret: |
3761 | xfer->status = err; | | 3832 | xfer->status = err; |
3762 | s = splusb(); | | 3833 | mutex_enter(&sc->sc_lock); |
3763 | usb_transfer_complete(xfer); | | 3834 | usb_transfer_complete(xfer); |
3764 | splx(s); | | 3835 | mutex_exit(&sc->sc_lock); |
3765 | return (USBD_IN_PROGRESS); | | 3836 | return (USBD_IN_PROGRESS); |
3766 | } | | 3837 | } |
3767 | | | 3838 | |
3768 | /* Abort a root control request. */ | | 3839 | /* Abort a root control request. */ |
3769 | void | | 3840 | void |
3770 | uhci_root_ctrl_abort(usbd_xfer_handle xfer) | | 3841 | uhci_root_ctrl_abort(usbd_xfer_handle xfer) |
3771 | { | | 3842 | { |
3772 | /* Nothing to do, all transfers are synchronous. */ | | 3843 | /* Nothing to do, all transfers are synchronous. */ |
3773 | } | | 3844 | } |
3774 | | | 3845 | |
3775 | /* Close the root pipe. */ | | 3846 | /* Close the root pipe. */ |
3776 | void | | 3847 | void |
3777 | uhci_root_ctrl_close(usbd_pipe_handle pipe) | | 3848 | uhci_root_ctrl_close(usbd_pipe_handle pipe) |
| @@ -3792,30 +3863,33 @@ uhci_root_intr_abort(usbd_xfer_handle xf | | | @@ -3792,30 +3863,33 @@ uhci_root_intr_abort(usbd_xfer_handle xf |
3792 | DPRINTF(("uhci_root_intr_abort: remove\n")); | | 3863 | DPRINTF(("uhci_root_intr_abort: remove\n")); |
3793 | xfer->pipe->intrxfer = 0; | | 3864 | xfer->pipe->intrxfer = 0; |
3794 | } | | 3865 | } |
3795 | xfer->status = USBD_CANCELLED; | | 3866 | xfer->status = USBD_CANCELLED; |
3796 | #ifdef DIAGNOSTIC | | 3867 | #ifdef DIAGNOSTIC |
3797 | UXFER(xfer)->iinfo.isdone = 1; | | 3868 | UXFER(xfer)->iinfo.isdone = 1; |
3798 | #endif | | 3869 | #endif |
3799 | usb_transfer_complete(xfer); | | 3870 | usb_transfer_complete(xfer); |
3800 | } | | 3871 | } |
3801 | | | 3872 | |
3802 | usbd_status | | 3873 | usbd_status |
3803 | uhci_root_intr_transfer(usbd_xfer_handle xfer) | | 3874 | uhci_root_intr_transfer(usbd_xfer_handle xfer) |
3804 | { | | 3875 | { |
| | | 3876 | uhci_softc_t *sc = xfer->pipe->device->bus->hci_private; |
3805 | usbd_status err; | | 3877 | usbd_status err; |
3806 | | | 3878 | |
3807 | /* Insert last in queue. */ | | 3879 | /* Insert last in queue. */ |
| | | 3880 | mutex_enter(&sc->sc_lock); |
3808 | err = usb_insert_transfer(xfer); | | 3881 | err = usb_insert_transfer(xfer); |
| | | 3882 | mutex_exit(&sc->sc_lock); |
3809 | if (err) | | 3883 | if (err) |
3810 | return (err); | | 3884 | return (err); |
3811 | | | 3885 | |
3812 | /* | | 3886 | /* |
3813 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 3887 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
3814 | * start first | | 3888 | * start first |
3815 | */ | | 3889 | */ |
3816 | return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); | | 3890 | return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); |
3817 | } | | 3891 | } |
3818 | | | 3892 | |
3819 | /* Start a transfer on the root interrupt pipe */ | | 3893 | /* Start a transfer on the root interrupt pipe */ |
3820 | usbd_status | | 3894 | usbd_status |
3821 | uhci_root_intr_start(usbd_xfer_handle xfer) | | 3895 | uhci_root_intr_start(usbd_xfer_handle xfer) |