Lines Matching refs:sc
79 struct xhci_softc *sc; member
117 static void xhci_ctx_set_le32(struct xhci_softc *sc, volatile uint32_t *ptr, uint32_t val);
118 static uint32_t xhci_ctx_get_le32(struct xhci_softc *sc, volatile uint32_t *ptr);
119 static void xhci_ctx_set_le64(struct xhci_softc *sc, volatile uint64_t *ptr, uint64_t val);
121 static uint64_t xhci_ctx_get_le64(struct xhci_softc *sc, volatile uint64_t *ptr);
137 xhci_dump_endpoint(struct xhci_softc *sc, struct xhci_endp_ctx *pep) in xhci_dump_endpoint() argument
140 DPRINTFN(5, "dwEpCtx0=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx0)); in xhci_dump_endpoint()
141 DPRINTFN(5, "dwEpCtx1=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx1)); in xhci_dump_endpoint()
142 DPRINTFN(5, "qwEpCtx2=0x%016llx\n", (long long)xhci_ctx_get_le64(sc, &pep->qwEpCtx2)); in xhci_dump_endpoint()
143 DPRINTFN(5, "dwEpCtx4=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx4)); in xhci_dump_endpoint()
144 DPRINTFN(5, "dwEpCtx5=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx5)); in xhci_dump_endpoint()
145 DPRINTFN(5, "dwEpCtx6=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx6)); in xhci_dump_endpoint()
146 DPRINTFN(5, "dwEpCtx7=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx7)); in xhci_dump_endpoint()
150 xhci_dump_device(struct xhci_softc *sc, struct xhci_slot_ctx *psl) in xhci_dump_device() argument
153 DPRINTFN(5, "dwSctx0=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx0)); in xhci_dump_device()
154 DPRINTFN(5, "dwSctx1=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx1)); in xhci_dump_device()
155 DPRINTFN(5, "dwSctx2=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx2)); in xhci_dump_device()
156 DPRINTFN(5, "dwSctx3=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx3)); in xhci_dump_device()
173 struct xhci_softc *sc = XHCI_BUS2SC(bus); in xhci_iterate_hw_softc() local
176 cb(bus, &sc->sc_hw.root_pc, &sc->sc_hw.root_pg, in xhci_iterate_hw_softc()
179 cb(bus, &sc->sc_hw.ctx_pc, &sc->sc_hw.ctx_pg, in xhci_iterate_hw_softc()
182 for (i = 0; i != sc->sc_noscratch; i++) { in xhci_iterate_hw_softc()
183 cb(bus, &sc->sc_hw.scratch_pc[i], &sc->sc_hw.scratch_pg[i], in xhci_iterate_hw_softc()
189 xhci_ctx_set_le32(struct xhci_softc *sc, volatile uint32_t *ptr, uint32_t val) in xhci_ctx_set_le32() argument
192 if (sc->sc_ctx_is_64_byte) { in xhci_ctx_set_le32()
202 xhci_ctx_get_le32(struct xhci_softc *sc, volatile uint32_t *ptr) in xhci_ctx_get_le32() argument
205 if (sc->sc_ctx_is_64_byte) { in xhci_ctx_get_le32()
215 xhci_ctx_set_le64(struct xhci_softc *sc, volatile uint64_t *ptr, uint64_t val) in xhci_ctx_set_le64() argument
218 if (sc->sc_ctx_is_64_byte) { in xhci_ctx_set_le64()
229 xhci_ctx_get_le64(struct xhci_softc *sc, volatile uint64_t *ptr) in xhci_ctx_get_le64() argument
232 if (sc->sc_ctx_is_64_byte) { in xhci_ctx_get_le64()
243 xhci_reset_command_queue_locked(struct xhci_softc *sc) in xhci_reset_command_queue_locked() argument
252 temp = XREAD4(sc, oper, XHCI_CRCR_LO); in xhci_reset_command_queue_locked()
264 XWRITE4(sc, oper, XHCI_CRCR_LO, temp | XHCI_CRCR_LO_CS); in xhci_reset_command_queue_locked()
265 XWRITE4(sc, oper, XHCI_CRCR_HI, 0); in xhci_reset_command_queue_locked()
267 XWRITE4(sc, oper, XHCI_CRCR_LO, temp | XHCI_CRCR_LO_CA); in xhci_reset_command_queue_locked()
268 XWRITE4(sc, oper, XHCI_CRCR_HI, 0); in xhci_reset_command_queue_locked()
271 usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 4); in xhci_reset_command_queue_locked()
274 temp = XREAD4(sc, oper, XHCI_CRCR_LO); in xhci_reset_command_queue_locked()
282 sc->sc_command_ccs = 1; in xhci_reset_command_queue_locked()
283 sc->sc_command_idx = 0; in xhci_reset_command_queue_locked()
285 usbd_get_page(&sc->sc_hw.root_pc, 0, &buf_res); in xhci_reset_command_queue_locked()
297 usb_pc_cpu_flush(&sc->sc_hw.root_pc); in xhci_reset_command_queue_locked()
299 XWRITE4(sc, oper, XHCI_CRCR_LO, ((uint32_t)addr) | XHCI_CRCR_LO_RCS); in xhci_reset_command_queue_locked()
300 XWRITE4(sc, oper, XHCI_CRCR_HI, (uint32_t)(addr >> 32)); in xhci_reset_command_queue_locked()
306 xhci_start_controller(struct xhci_softc *sc) in xhci_start_controller() argument
318 sc->sc_event_ccs = 1; in xhci_start_controller()
319 sc->sc_event_idx = 0; in xhci_start_controller()
320 sc->sc_command_ccs = 1; in xhci_start_controller()
321 sc->sc_command_idx = 0; in xhci_start_controller()
324 XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); in xhci_start_controller()
328 temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | in xhci_start_controller()
329 (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); in xhci_start_controller()
335 device_printf(sc->sc_bus.parent, "Controller " in xhci_start_controller()
342 XREAD4(sc, oper, XHCI_CONFIG), sc->sc_noslot); in xhci_start_controller()
344 XWRITE4(sc, oper, XHCI_CONFIG, sc->sc_noslot); in xhci_start_controller()
346 temp = XREAD4(sc, oper, XHCI_USBSTS); in xhci_start_controller()
349 XWRITE4(sc, oper, XHCI_USBSTS, temp); in xhci_start_controller()
351 XWRITE4(sc, oper, XHCI_DNCTRL, 0); in xhci_start_controller()
354 usbd_get_page(&sc->sc_hw.ctx_pc, 0, &buf_res); in xhci_start_controller()
368 for (i = 0; i != sc->sc_noscratch; i++) { in xhci_start_controller()
370 usbd_get_page(&sc->sc_hw.scratch_pc[i], 0, &buf_scp); in xhci_start_controller()
376 XWRITE4(sc, oper, XHCI_DCBAAP_LO, (uint32_t)addr); in xhci_start_controller()
377 XWRITE4(sc, oper, XHCI_DCBAAP_HI, (uint32_t)(addr >> 32)); in xhci_start_controller()
378 XWRITE4(sc, oper, XHCI_DCBAAP_LO, (uint32_t)addr); in xhci_start_controller()
379 XWRITE4(sc, oper, XHCI_DCBAAP_HI, (uint32_t)(addr >> 32)); in xhci_start_controller()
383 XREAD4(sc, runt, XHCI_ERSTSZ(0)), sc->sc_erst_max); in xhci_start_controller()
385 XWRITE4(sc, runt, XHCI_ERSTSZ(0), XHCI_ERSTS_SET(sc->sc_erst_max)); in xhci_start_controller()
388 XWRITE4(sc, runt, XHCI_IMOD(0), sc->sc_imod_default); in xhci_start_controller()
390 usbd_get_page(&sc->sc_hw.root_pc, 0, &buf_res); in xhci_start_controller()
408 XWRITE4(sc, runt, XHCI_ERDP_LO(0), (uint32_t)addr); in xhci_start_controller()
409 XWRITE4(sc, runt, XHCI_ERDP_HI(0), (uint32_t)(addr >> 32)); in xhci_start_controller()
415 XWRITE4(sc, runt, XHCI_ERSTBA_LO(0), (uint32_t)addr); in xhci_start_controller()
416 XWRITE4(sc, runt, XHCI_ERSTBA_HI(0), (uint32_t)(addr >> 32)); in xhci_start_controller()
419 temp = XREAD4(sc, runt, XHCI_IMAN(0)); in xhci_start_controller()
421 XWRITE4(sc, runt, XHCI_IMAN(0), temp); in xhci_start_controller()
429 XWRITE4(sc, oper, XHCI_CRCR_LO, ((uint32_t)addr) | XHCI_CRCR_LO_RCS); in xhci_start_controller()
430 XWRITE4(sc, oper, XHCI_CRCR_HI, (uint32_t)(addr >> 32)); in xhci_start_controller()
434 usb_bus_mem_flush_all(&sc->sc_bus, &xhci_iterate_hw_softc); in xhci_start_controller()
437 XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_RS | in xhci_start_controller()
442 temp = XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_HCH; in xhci_start_controller()
447 XWRITE4(sc, oper, XHCI_USBCMD, 0); in xhci_start_controller()
448 device_printf(sc->sc_bus.parent, "Run timeout.\n"); in xhci_start_controller()
453 xhci_do_poll(&sc->sc_bus); in xhci_start_controller()
455 if (sc->sc_port_route != NULL) { in xhci_start_controller()
457 (void)sc->sc_port_route(sc->sc_bus.parent, in xhci_start_controller()
464 xhci_halt_controller(struct xhci_softc *sc) in xhci_halt_controller() argument
471 sc->sc_capa_off = 0; in xhci_halt_controller()
472 sc->sc_oper_off = XREAD1(sc, capa, XHCI_CAPLENGTH); in xhci_halt_controller()
473 sc->sc_runt_off = XREAD4(sc, capa, XHCI_RTSOFF) & ~0xF; in xhci_halt_controller()
474 sc->sc_door_off = XREAD4(sc, capa, XHCI_DBOFF) & ~0x3; in xhci_halt_controller()
477 XWRITE4(sc, oper, XHCI_USBCMD, 0); in xhci_halt_controller()
481 temp = XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_HCH; in xhci_halt_controller()
487 device_printf(sc->sc_bus.parent, "Controller halt timeout.\n"); in xhci_halt_controller()
494 xhci_reset_controller(struct xhci_softc *sc) in xhci_reset_controller() argument
502 XWRITE4(sc, oper, XHCI_USBCMD, XHCI_CMD_HCRST); in xhci_reset_controller()
506 temp = (XREAD4(sc, oper, XHCI_USBCMD) & XHCI_CMD_HCRST) | in xhci_reset_controller()
507 (XREAD4(sc, oper, XHCI_USBSTS) & XHCI_STS_CNR); in xhci_reset_controller()
513 device_printf(sc->sc_bus.parent, "Controller " in xhci_reset_controller()
521 xhci_init(struct xhci_softc *sc, device_t self, uint8_t dma32) in xhci_init() argument
528 sc->sc_bus.parent = self; in xhci_init()
531 sc->sc_bus.usbrev = USB_REV_3_0; in xhci_init()
534 sc->sc_bus.methods = &xhci_bus_methods; in xhci_init()
537 sc->sc_bus.devices = sc->sc_devices; in xhci_init()
538 sc->sc_bus.devices_max = XHCI_MAX_DEVICES; in xhci_init()
541 sc->sc_event_ccs = 1; in xhci_init()
542 sc->sc_command_ccs = 1; in xhci_init()
545 sc->sc_capa_off = 0; in xhci_init()
546 sc->sc_oper_off = XREAD1(sc, capa, XHCI_CAPLENGTH); in xhci_init()
547 sc->sc_runt_off = XREAD4(sc, capa, XHCI_RTSOFF) & ~0x1F; in xhci_init()
548 sc->sc_door_off = XREAD4(sc, capa, XHCI_DBOFF) & ~0x3; in xhci_init()
550 DPRINTF("CAPLENGTH=0x%x\n", sc->sc_oper_off); in xhci_init()
551 DPRINTF("RUNTIMEOFFSET=0x%x\n", sc->sc_runt_off); in xhci_init()
552 DPRINTF("DOOROFFSET=0x%x\n", sc->sc_door_off); in xhci_init()
554 DPRINTF("xHCI version = 0x%04x\n", XREAD2(sc, capa, XHCI_HCIVERSION)); in xhci_init()
556 if (!(XREAD4(sc, oper, XHCI_PAGESIZE) & XHCI_PAGESIZE_4K)) { in xhci_init()
557 device_printf(sc->sc_bus.parent, "Controller does " in xhci_init()
562 temp = XREAD4(sc, capa, XHCI_HCSPARAMS0); in xhci_init()
568 sc->sc_ctx_is_64_byte = 1; in xhci_init()
570 sc->sc_ctx_is_64_byte = 0; in xhci_init()
574 sc->sc_bus.dma_bits = (XHCI_HCS0_AC64(temp) && in xhci_init()
578 sc->sc_ctx_is_64_byte ? 64 : 32, (int)sc->sc_bus.dma_bits); in xhci_init()
580 temp = XREAD4(sc, capa, XHCI_HCSPARAMS1); in xhci_init()
583 sc->sc_noport = XHCI_HCS1_N_PORTS(temp); in xhci_init()
585 if (sc->sc_noport == 0) { in xhci_init()
586 device_printf(sc->sc_bus.parent, "Invalid number " in xhci_init()
587 "of ports: %u\n", sc->sc_noport); in xhci_init()
591 sc->sc_noslot = XHCI_HCS1_DEVSLOT_MAX(temp); in xhci_init()
593 DPRINTF("Max slots: %u\n", sc->sc_noslot); in xhci_init()
595 if (sc->sc_noslot > XHCI_MAX_DEVICES) in xhci_init()
596 sc->sc_noslot = XHCI_MAX_DEVICES; in xhci_init()
598 temp = XREAD4(sc, capa, XHCI_HCSPARAMS2); in xhci_init()
603 sc->sc_noscratch = XHCI_HCS2_SPB_MAX(temp); in xhci_init()
605 if (sc->sc_noscratch > XHCI_MAX_SCRATCHPADS) { in xhci_init()
606 device_printf(sc->sc_bus.parent, "XHCI request " in xhci_init()
611 DPRINTF("Max scratch: %u\n", sc->sc_noscratch); in xhci_init()
614 sc->sc_erst_max = 1U << XHCI_HCS2_ERST_MAX(temp); in xhci_init()
615 if (sc->sc_erst_max > XHCI_MAX_RSEG) in xhci_init()
616 sc->sc_erst_max = XHCI_MAX_RSEG; in xhci_init()
618 temp = XREAD4(sc, capa, XHCI_HCSPARAMS3); in xhci_init()
621 sc->sc_exit_lat_max = XHCI_HCS3_U1_DEL(temp) + in xhci_init()
625 if (sc->sc_imod_default == 0) in xhci_init()
626 sc->sc_imod_default = XHCI_IMOD_DEFAULT; in xhci_init()
629 if (usb_bus_mem_alloc_all(&sc->sc_bus, in xhci_init()
635 cv_init(&sc->sc_cmd_cv, "CMDQ"); in xhci_init()
636 sx_init(&sc->sc_cmd_sx, "CMDQ lock"); in xhci_init()
638 sc->sc_config_msg[0].hdr.pm_callback = &xhci_configure_msg; in xhci_init()
639 sc->sc_config_msg[0].bus = &sc->sc_bus; in xhci_init()
640 sc->sc_config_msg[1].hdr.pm_callback = &xhci_configure_msg; in xhci_init()
641 sc->sc_config_msg[1].bus = &sc->sc_bus; in xhci_init()
647 xhci_uninit(struct xhci_softc *sc) in xhci_uninit() argument
655 usb_bus_mem_free_all(&sc->sc_bus, &xhci_iterate_hw_softc); in xhci_uninit()
657 cv_destroy(&sc->sc_cmd_cv); in xhci_uninit()
658 sx_destroy(&sc->sc_cmd_sx); in xhci_uninit()
664 struct xhci_softc *sc = XHCI_BUS2SC(bus); in xhci_set_hw_power_sleep() local
669 (void)xhci_halt_controller(sc); in xhci_set_hw_power_sleep()
670 (void)xhci_reset_controller(sc); in xhci_set_hw_power_sleep()
674 (void)xhci_halt_controller(sc); in xhci_set_hw_power_sleep()
675 (void)xhci_reset_controller(sc); in xhci_set_hw_power_sleep()
679 (void)xhci_start_controller(sc); in xhci_set_hw_power_sleep()
856 xhci_check_transfer(struct xhci_softc *sc, struct xhci_trb *trb) in xhci_check_transfer() argument
888 if (index > sc->sc_noslot) { in xhci_check_transfer()
898 pepext = &sc->sc_hw.devs[index].endp[epno]; in xhci_check_transfer()
1024 xhci_check_command(struct xhci_softc *sc, struct xhci_trb *trb) in xhci_check_command() argument
1026 if (sc->sc_cmd_addr == trb->qwTrb0) { in xhci_check_command()
1028 sc->sc_cmd_result[0] = trb->dwTrb2; in xhci_check_command()
1029 sc->sc_cmd_result[1] = trb->dwTrb3; in xhci_check_command()
1030 (void)cv_signal(&sc->sc_cmd_cv); in xhci_check_command()
1037 xhci_interrupt_poll(struct xhci_softc *sc) in xhci_interrupt_poll() argument
1050 usbd_get_page(&sc->sc_hw.root_pc, 0, &buf_res); in xhci_interrupt_poll()
1056 usb_pc_cpu_invalidate(&sc->sc_hw.root_pc); in xhci_interrupt_poll()
1058 i = sc->sc_event_idx; in xhci_interrupt_poll()
1059 j = sc->sc_event_ccs; in xhci_interrupt_poll()
1079 xhci_check_transfer(sc, &phwr->hwr_events[i]); in xhci_interrupt_poll()
1082 retval |= xhci_check_command(sc, &phwr->hwr_events[i]); in xhci_interrupt_poll()
1101 sc->sc_event_idx = i; in xhci_interrupt_poll()
1102 sc->sc_event_ccs = j; in xhci_interrupt_poll()
1117 XWRITE4(sc, runt, XHCI_ERDP_LO(0), (uint32_t)addr); in xhci_interrupt_poll()
1118 XWRITE4(sc, runt, XHCI_ERDP_HI(0), (uint32_t)(addr >> 32)); in xhci_interrupt_poll()
1124 xhci_do_command(struct xhci_softc *sc, struct xhci_trb *trb, in xhci_do_command() argument
1136 XHCI_CMD_ASSERT_LOCKED(sc); in xhci_do_command()
1140 usbd_get_page(&sc->sc_hw.root_pc, 0, &buf_res); in xhci_do_command()
1146 USB_BUS_LOCK(&sc->sc_bus); in xhci_do_command()
1148 i = sc->sc_command_idx; in xhci_do_command()
1149 j = sc->sc_command_ccs; in xhci_do_command()
1160 usb_pc_cpu_flush(&sc->sc_hw.root_pc); in xhci_do_command()
1173 usb_pc_cpu_flush(&sc->sc_hw.root_pc); in xhci_do_command()
1178 sc->sc_cmd_addr = htole64(addr); in xhci_do_command()
1194 usb_pc_cpu_flush(&sc->sc_hw.root_pc); in xhci_do_command()
1200 sc->sc_command_idx = i; in xhci_do_command()
1201 sc->sc_command_ccs = j; in xhci_do_command()
1203 XWRITE4(sc, door, XHCI_DOORBELL(0), 0); in xhci_do_command()
1205 err = (usb_error_t)cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_mtx, in xhci_do_command()
1212 if ((err != 0) && (xhci_interrupt_poll(sc) != 0)) { in xhci_do_command()
1227 (xhci_reset_command_queue_locked(sc) == 0)) { in xhci_do_command()
1244 usb_bus_reset_async_locked(&sc->sc_bus); in xhci_do_command()
1250 temp = le32toh(sc->sc_cmd_result[0]); in xhci_do_command()
1253 (XHCI_TRB_3_SLOT_GET(le32toh(sc->sc_cmd_result[1]))))) { in xhci_do_command()
1258 trb->dwTrb2 = sc->sc_cmd_result[0]; in xhci_do_command()
1259 trb->dwTrb3 = sc->sc_cmd_result[1]; in xhci_do_command()
1262 USB_BUS_UNLOCK(&sc->sc_bus); in xhci_do_command()
1268 xhci_cmd_enable_slot(struct xhci_softc *sc, uint8_t *pslot) in xhci_cmd_enable_slot() argument
1280 err = xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */); in xhci_cmd_enable_slot()
1293 xhci_cmd_disable_slot(struct xhci_softc *sc, uint8_t slot_id) in xhci_cmd_disable_slot() argument
1307 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_disable_slot()
1311 xhci_cmd_set_address(struct xhci_softc *sc, uint64_t input_ctx, in xhci_cmd_set_address() argument
1329 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_set_address()
1337 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_set_address() local
1352 hdev = &sc->sc_hw.devs[index]; in xhci_set_address()
1357 XHCI_CMD_LOCK(sc); in xhci_set_address()
1411 err = xhci_cmd_set_address(sc, buf_inp.physaddr, in xhci_set_address()
1415 temp = le32toh(sc->sc_cmd_result[0]); in xhci_set_address()
1416 if ((address == 0) && (sc->sc_port_route != NULL) && in xhci_set_address()
1421 (void)sc->sc_port_route(sc->sc_bus.parent, 0, ~0); in xhci_set_address()
1435 temp = xhci_ctx_get_le32(sc, &pdev->ctx_slot.dwSctx3); in xhci_set_address()
1451 XHCI_CMD_UNLOCK(sc); in xhci_set_address()
1460 xhci_cmd_configure_ep(struct xhci_softc *sc, uint64_t input_ctx, in xhci_cmd_configure_ep() argument
1478 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_configure_ep()
1482 xhci_cmd_evaluate_ctx(struct xhci_softc *sc, uint64_t input_ctx, in xhci_cmd_evaluate_ctx() argument
1496 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_evaluate_ctx()
1500 xhci_cmd_reset_ep(struct xhci_softc *sc, uint8_t preserve, in xhci_cmd_reset_ep() argument
1519 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_reset_ep()
1523 xhci_cmd_set_tr_dequeue_ptr(struct xhci_softc *sc, uint64_t dequeue_ptr, in xhci_cmd_set_tr_dequeue_ptr() argument
1541 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_set_tr_dequeue_ptr()
1545 xhci_cmd_stop_ep(struct xhci_softc *sc, uint8_t suspend, in xhci_cmd_stop_ep() argument
1564 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_stop_ep()
1568 xhci_cmd_reset_dev(struct xhci_softc *sc, uint8_t slot_id) in xhci_cmd_reset_dev() argument
1582 return (xhci_do_command(sc, &trb, XHCI_DO_CMD_TIMEOUT/* ms */)); in xhci_cmd_reset_dev()
1589 xhci_interrupt(unsigned int irq, struct xhci_softc *sc) in xhci_interrupt() argument
1594 USB_BUS_LOCK(&sc->sc_bus); in xhci_interrupt()
1596 status = XREAD4(sc, oper, XHCI_USBSTS); in xhci_interrupt()
1600 XWRITE4(sc, oper, XHCI_USBSTS, status); in xhci_interrupt()
1604 temp = XREAD4(sc, runt, XHCI_IMAN(0)); in xhci_interrupt()
1608 XWRITE4(sc, runt, XHCI_IMAN(0), temp); in xhci_interrupt()
1611 (void)xhci_interrupt_poll(sc); in xhci_interrupt()
1616 xhci_root_intr(sc); in xhci_interrupt()
1634 USB_BUS_UNLOCK(&sc->sc_bus); in xhci_interrupt()
1656 struct xhci_softc *sc = XHCI_BUS2SC(bus); in xhci_do_poll() local
1658 USB_BUS_LOCK(&sc->sc_bus); in xhci_do_poll()
1659 (void)xhci_interrupt_poll(sc); in xhci_do_poll()
1660 USB_BUS_UNLOCK(&sc->sc_bus); in xhci_do_poll()
1980 temp.sc = XHCI_BUS2SC(xfer->xroot->bus); in xhci_setup_generic_chain()
2018 x = XREAD4(temp.sc, runt, XHCI_MFINDEX); in xhci_setup_generic_chain()
2063 usb_isoc_time_expand(&temp.sc->sc_bus, x / 8) + in xhci_setup_generic_chain()
2189 if (xhcictlstep || temp.sc->sc_ctlstep) { in xhci_setup_generic_chain()
2220 xhci_set_slot_pointer(struct xhci_softc *sc, uint8_t index, uint64_t dev_addr) in xhci_set_slot_pointer() argument
2225 usbd_get_page(&sc->sc_hw.ctx_pc, 0, &buf_res); in xhci_set_slot_pointer()
2233 usb_pc_cpu_flush(&sc->sc_hw.ctx_pc); in xhci_set_slot_pointer()
2239 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_configure_mask() local
2248 usbd_get_page(&sc->sc_hw.devs[index].input_pc, 0, &buf_inp); in xhci_configure_mask()
2254 xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx0, mask); in xhci_configure_mask()
2255 xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx1, 0); in xhci_configure_mask()
2261 xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx0, in xhci_configure_mask()
2265 xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx1, mask); in xhci_configure_mask()
2277 if (x > sc->sc_hw.devs[index].context_num) in xhci_configure_mask()
2278 sc->sc_hw.devs[index].context_num = x; in xhci_configure_mask()
2280 x = sc->sc_hw.devs[index].context_num; in xhci_configure_mask()
2283 temp = xhci_ctx_get_le32(sc, &pinp->ctx_slot.dwSctx0); in xhci_configure_mask()
2286 xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx0, temp); in xhci_configure_mask()
2288 usb_pc_cpu_flush(&sc->sc_hw.devs[index].input_pc); in xhci_configure_mask()
2300 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_configure_endpoint() local
2310 usbd_get_page(&sc->sc_hw.devs[index].input_pc, 0, &buf_inp); in xhci_configure_endpoint()
2388 xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx0, temp); in xhci_configure_endpoint()
2423 xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx1, temp); in xhci_configure_endpoint()
2424 xhci_ctx_set_le64(sc, &pinp->ctx_ep[epno - 1].qwEpCtx2, ring_addr); in xhci_configure_endpoint()
2441 xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx4, temp); in xhci_configure_endpoint()
2444 xhci_dump_endpoint(sc, &pinp->ctx_ep[epno - 1]); in xhci_configure_endpoint()
2446 usb_pc_cpu_flush(&sc->sc_hw.devs[index].input_pc); in xhci_configure_endpoint()
2497 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_configure_device() local
2513 pcinp = &sc->sc_hw.devs[index].input_pc; in xhci_configure_device()
2551 sc->sc_hw.devs[index].context_num + 1); in xhci_configure_device()
2565 if ((sc->sc_hw.devs[index].nports != 0) && in xhci_configure_device()
2585 is_hub = sc->sc_hw.devs[index].nports != 0 && in xhci_configure_device()
2592 xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx0, temp); in xhci_configure_device()
2598 sc->sc_hw.devs[index].nports); in xhci_configure_device()
2603 switch (sc->sc_hw.devs[index].state) { in xhci_configure_device()
2607 temp |= XHCI_SCTX_1_MAX_EL_SET(sc->sc_exit_lat_max); in xhci_configure_device()
2618 xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx1, temp); in xhci_configure_device()
2624 sc->sc_hw.devs[index].tt); in xhci_configure_device()
2644 xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx2, temp); in xhci_configure_device()
2653 xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx3, temp); in xhci_configure_device()
2656 xhci_dump_device(sc, &pinp->ctx_slot); in xhci_configure_device()
2666 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_alloc_device_ext() local
2678 pc = &sc->sc_hw.devs[index].device_pc; in xhci_alloc_device_ext()
2679 pg = &sc->sc_hw.devs[index].device_pg; in xhci_alloc_device_ext()
2682 pc->tag_parent = sc->sc_bus.dma_parent_tag; in xhci_alloc_device_ext()
2684 if (usb_pc_alloc_mem(pc, pg, sc->sc_ctx_is_64_byte ? in xhci_alloc_device_ext()
2691 pc = &sc->sc_hw.devs[index].input_pc; in xhci_alloc_device_ext()
2692 pg = &sc->sc_hw.devs[index].input_pg; in xhci_alloc_device_ext()
2695 pc->tag_parent = sc->sc_bus.dma_parent_tag; in xhci_alloc_device_ext()
2697 if (usb_pc_alloc_mem(pc, pg, sc->sc_ctx_is_64_byte ? in xhci_alloc_device_ext()
2706 pc = &sc->sc_hw.devs[index].endpoint_pc[i]; in xhci_alloc_device_ext()
2707 pg = &sc->sc_hw.devs[index].endpoint_pg[i]; in xhci_alloc_device_ext()
2710 pc->tag_parent = sc->sc_bus.dma_parent_tag; in xhci_alloc_device_ext()
2736 xhci_set_slot_pointer(sc, index, buf_dev.physaddr); in xhci_alloc_device_ext()
2749 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_free_device_ext() local
2754 xhci_set_slot_pointer(sc, index, 0); in xhci_free_device_ext()
2756 usb_pc_free_mem(&sc->sc_hw.devs[index].device_pc); in xhci_free_device_ext()
2757 usb_pc_free_mem(&sc->sc_hw.devs[index].input_pc); in xhci_free_device_ext()
2759 usb_pc_free_mem(&sc->sc_hw.devs[index].endpoint_pc[i]); in xhci_free_device_ext()
2765 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_get_endpoint_ext() local
2780 pc = &sc->sc_hw.devs[index].endpoint_pc[epno]; in xhci_get_endpoint_ext()
2784 pepext = &sc->sc_hw.devs[index].endp[epno]; in xhci_get_endpoint_ext()
2795 struct xhci_softc *sc = XHCI_BUS2SC(xfer->xroot->bus); in xhci_endpoint_doorbell() local
2807 XWRITE4(sc, door, XHCI_DOORBELL(index), in xhci_endpoint_doorbell()
2893 struct xhci_softc *sc = XHCI_BUS2SC(xfer->xroot->bus); in xhci_transfer_insert() local
2898 (void)usb_proc_msignal(USB_BUS_CONTROL_XFER_PROC(&sc->sc_bus), in xhci_transfer_insert()
2899 &sc->sc_config_msg[0], &sc->sc_config_msg[1]); in xhci_transfer_insert()
2977 xhci_root_intr(struct xhci_softc *sc) in xhci_root_intr() argument
2981 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); in xhci_root_intr()
2984 (void)memset_s(sc->sc_hub_idata, sizeof(sc->sc_hub_idata), 0, sizeof(sc->sc_hub_idata)); in xhci_root_intr()
2986 for (i = 1; i <= sc->sc_noport; i++) { in xhci_root_intr()
2988 if (XREAD4(sc, oper, XHCI_PORTSC(i)) & ( in xhci_root_intr()
2993 sc->sc_hub_idata[i / 8] |= 1 << (i % 8); in xhci_root_intr()
2997 uhub_root_intr(&sc->sc_bus, sc->sc_hub_idata, in xhci_root_intr()
2998 sizeof(sc->sc_hub_idata)); in xhci_root_intr()
3233 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_roothub_exec() local
3245 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); in xhci_roothub_exec()
3248 ptr = (const void *)&sc->sc_hub_desc; in xhci_roothub_exec()
3272 sc->sc_hub_desc.temp[0] = sc->sc_conf; in xhci_roothub_exec()
3310 str_ptr = sc->sc_vendor; in xhci_roothub_exec()
3323 sc->sc_hub_desc.temp, in xhci_roothub_exec()
3324 sizeof(sc->sc_hub_desc.temp), in xhci_roothub_exec()
3335 sc->sc_hub_desc.temp[0] = 0; in xhci_roothub_exec()
3339 USETW(sc->sc_hub_desc.stat.wStatus, UDS_SELF_POWERED); in xhci_roothub_exec()
3344 USETW(sc->sc_hub_desc.stat.wStatus, 0); in xhci_roothub_exec()
3357 sc->sc_conf = value; in xhci_roothub_exec()
3377 (index > sc->sc_noport)) { in xhci_roothub_exec()
3383 v = XREAD4(sc, oper, port); in xhci_roothub_exec()
3389 XWRITE4(sc, oper, port, v | XHCI_PS_WRC); in xhci_roothub_exec()
3392 XWRITE4(sc, oper, port, v | XHCI_PS_CEC); in xhci_roothub_exec()
3396 XWRITE4(sc, oper, port, v | XHCI_PS_PLC); in xhci_roothub_exec()
3399 XWRITE4(sc, oper, port, v | XHCI_PS_CSC); in xhci_roothub_exec()
3402 XWRITE4(sc, oper, port, v | XHCI_PS_PEC); in xhci_roothub_exec()
3405 XWRITE4(sc, oper, port, v | XHCI_PS_OCC); in xhci_roothub_exec()
3408 XWRITE4(sc, oper, port, v | XHCI_PS_PRC); in xhci_roothub_exec()
3411 XWRITE4(sc, oper, port, v | XHCI_PS_PED); in xhci_roothub_exec()
3414 XWRITE4(sc, oper, port, v & ~XHCI_PS_PP); in xhci_roothub_exec()
3417 XWRITE4(sc, oper, port, v & ~XHCI_PS_PIC_SET(3)); in xhci_roothub_exec()
3423 XWRITE4(sc, oper, port, v | in xhci_roothub_exec()
3428 usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 50); in xhci_roothub_exec()
3431 XWRITE4(sc, oper, port, v | in xhci_roothub_exec()
3446 v = XREAD4(sc, capa, XHCI_HCSPARAMS0); in xhci_roothub_exec()
3448 sc->sc_hub_desc.hubd = xhci_hubd; in xhci_roothub_exec()
3450 sc->sc_hub_desc.hubd.bNbrPorts = sc->sc_noport; in xhci_roothub_exec()
3462 USETW(sc->sc_hub_desc.hubd.wHubCharacteristics, i); in xhci_roothub_exec()
3465 sc->sc_hub_desc.hubd.bPwrOn2PwrGood = 10; in xhci_roothub_exec()
3467 for (j = 1; j <= sc->sc_noport; j++) { in xhci_roothub_exec()
3468 v = XREAD4(sc, oper, XHCI_PORTSC(j)); in xhci_roothub_exec()
3470 sc->sc_hub_desc.hubd. in xhci_roothub_exec()
3474 len = sc->sc_hub_desc.hubd.bLength; in xhci_roothub_exec()
3479 (void)memset_s(sc->sc_hub_desc.temp, sizeof(sc->sc_hub_desc.temp), 0, len); in xhci_roothub_exec()
3486 (index > sc->sc_noport)) { in xhci_roothub_exec()
3491 v = XREAD4(sc, oper, XHCI_PORTSC(index)); in xhci_roothub_exec()
3527 USETW(sc->sc_hub_desc.ps.wPortStatus, i); in xhci_roothub_exec()
3545 USETW(sc->sc_hub_desc.ps.wPortChange, i); in xhci_roothub_exec()
3546 len = sizeof(sc->sc_hub_desc.ps); in xhci_roothub_exec()
3562 (index > sc->sc_noport)) { in xhci_roothub_exec()
3568 v = XREAD4(sc, oper, port) & ~XHCI_PS_CLEAR; in xhci_roothub_exec()
3577 v = XREAD4(sc, oper, port); in xhci_roothub_exec()
3580 XWRITE4(sc, oper, port, v); in xhci_roothub_exec()
3588 v = XREAD4(sc, oper, port); in xhci_roothub_exec()
3591 XWRITE4(sc, oper, port, v); in xhci_roothub_exec()
3594 XWRITE4(sc, oper, port, v | XHCI_PS_WPR); in xhci_roothub_exec()
3597 XWRITE4(sc, oper, port, v | in xhci_roothub_exec()
3600 usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 250); in xhci_roothub_exec()
3613 XWRITE4(sc, oper, port, v | in xhci_roothub_exec()
3618 XWRITE4(sc, oper, port, v | XHCI_PS_PR); in xhci_roothub_exec()
3622 XWRITE4(sc, oper, port, v | XHCI_PS_PP); in xhci_roothub_exec()
3633 XWRITE4(sc, oper, port, v); in xhci_roothub_exec()
3760 struct xhci_softc *sc = XHCI_BUS2SC(xfer->xroot->bus); in xhci_configure_reset_endpoint() local
3777 pcinp = &sc->sc_hw.devs[index].input_pc; in xhci_configure_reset_endpoint()
3794 XHCI_CMD_LOCK(sc); in xhci_configure_reset_endpoint()
3801 XHCI_CMD_UNLOCK(sc); in xhci_configure_reset_endpoint()
3810 err = xhci_cmd_stop_ep(sc, 0, epno, index); in xhci_configure_reset_endpoint()
3815 err = xhci_cmd_reset_ep(sc, 0, epno, index); in xhci_configure_reset_endpoint()
3820 err = xhci_cmd_set_tr_dequeue_ptr(sc, in xhci_configure_reset_endpoint()
3836 err = xhci_cmd_configure_ep(sc, buf_inp.physaddr, 0, index); in xhci_configure_reset_endpoint()
3838 err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index); in xhci_configure_reset_endpoint()
3843 XHCI_CMD_UNLOCK(sc); in xhci_configure_reset_endpoint()
3857 struct xhci_softc *sc = XHCI_BUS2SC(xfer->xroot->bus); in xhci_start_dma_delay() local
3860 usbd_transfer_enqueue(&sc->sc_bus.intr_q, xfer); in xhci_start_dma_delay()
3862 (void)usb_proc_msignal(USB_BUS_CONTROL_XFER_PROC(&sc->sc_bus), in xhci_start_dma_delay()
3863 &sc->sc_config_msg[0], &sc->sc_config_msg[1]); in xhci_start_dma_delay()
3869 struct xhci_softc *sc; in xhci_configure_msg() local
3873 sc = XHCI_BUS2SC(((struct usb_bus_msg *)pm)->bus); in xhci_configure_msg()
3876 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) { in xhci_configure_msg()
3909 USB_BUS_UNLOCK(&sc->sc_bus); in xhci_configure_msg()
3913 USB_BUS_LOCK(&sc->sc_bus); in xhci_configure_msg()
3936 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) { in xhci_configure_msg()
4003 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_device_init() local
4011 XHCI_CMD_LOCK(sc); in xhci_device_init()
4015 udev->controller_slot_id = sc->sc_noslot + 1; in xhci_device_init()
4019 err = xhci_cmd_enable_slot(sc, &temp); in xhci_device_init()
4022 XHCI_CMD_UNLOCK(sc); in xhci_device_init()
4026 if (temp > sc->sc_noslot) { in xhci_device_init()
4027 XHCI_CMD_UNLOCK(sc); in xhci_device_init()
4031 if (sc->sc_hw.devs[temp].state != XHCI_ST_DISABLED) { in xhci_device_init()
4033 XHCI_CMD_UNLOCK(sc); in xhci_device_init()
4043 (void)memset_s(&sc->sc_hw.devs[temp], sizeof(sc->sc_hw.devs[0]), 0, sizeof(sc->sc_hw.devs[0])); in xhci_device_init()
4047 sc->sc_hw.devs[temp].state = XHCI_ST_ENABLED; in xhci_device_init()
4051 XHCI_CMD_UNLOCK(sc); in xhci_device_init()
4064 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_device_uninit() local
4071 XHCI_CMD_LOCK(sc); in xhci_device_uninit()
4075 if (index <= sc->sc_noslot) { in xhci_device_uninit()
4076 (void)xhci_cmd_disable_slot(sc, index); in xhci_device_uninit()
4077 sc->sc_hw.devs[index].state = XHCI_ST_DISABLED; in xhci_device_uninit()
4083 XHCI_CMD_UNLOCK(sc); in xhci_device_uninit()
4099 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_device_resume() local
4112 XHCI_CMD_LOCK(sc); in xhci_device_resume()
4120 XWRITE4(sc, door, XHCI_DOORBELL(index), in xhci_device_resume()
4127 XHCI_CMD_UNLOCK(sc); in xhci_device_resume()
4133 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_device_suspend() local
4146 XHCI_CMD_LOCK(sc); in xhci_device_suspend()
4151 err = xhci_cmd_stop_ep(sc, 1, n, index); in xhci_device_suspend()
4158 XHCI_CMD_UNLOCK(sc); in xhci_device_suspend()
4170 struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); in xhci_device_state_change() local
4184 err = uhub_query_info(udev, &sc->sc_hw.devs[index].nports, in xhci_device_state_change()
4185 &sc->sc_hw.devs[index].tt); in xhci_device_state_change()
4187 sc->sc_hw.devs[index].nports = 0; in xhci_device_state_change()
4190 XHCI_CMD_LOCK(sc); in xhci_device_state_change()
4194 if (sc->sc_hw.devs[index].state == XHCI_ST_DEFAULT) in xhci_device_state_change()
4198 sc->sc_hw.devs[index].state = XHCI_ST_DEFAULT; in xhci_device_state_change()
4201 sc->sc_hw.devs[index].context_num = 0; in xhci_device_state_change()
4203 err = xhci_cmd_reset_dev(sc, index); in xhci_device_state_change()
4212 if (sc->sc_hw.devs[index].state == XHCI_ST_ADDRESSED) in xhci_device_state_change()
4215 sc->sc_hw.devs[index].state = XHCI_ST_ADDRESSED; in xhci_device_state_change()
4220 err = xhci_cmd_configure_ep(sc, 0, 1, index); in xhci_device_state_change()
4229 if (sc->sc_hw.devs[index].state == XHCI_ST_CONFIGURED) in xhci_device_state_change()
4233 sc->sc_hw.devs[index].state = XHCI_ST_CONFIGURED; in xhci_device_state_change()
4236 sc->sc_hw.devs[index].context_num = 0; in xhci_device_state_change()
4238 usbd_get_page(&sc->sc_hw.devs[index].input_pc, 0, &buf_inp); in xhci_device_state_change()
4248 err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index); in xhci_device_state_change()
4258 XHCI_CMD_UNLOCK(sc); in xhci_device_state_change()