Deleted Added
full compact
ehci.c (187172) ehci.c (187173)
1/*-
2 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
3 * Copyright (c) 2004 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 2004 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2004 Charles M. Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 30 unchanged lines hidden (view full) ---

39 */
40
41/*
42 * TODO:
43 * 1) command failures are not recovered correctly
44 */
45
46#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
3 * Copyright (c) 2004 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 2004 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2004 Charles M. Hannum. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 30 unchanged lines hidden (view full) ---

39 */
40
41/*
42 * TODO:
43 * 1) command failures are not recovered correctly
44 */
45
46#include <sys/cdefs.h>
47__FBSDID("$FreeBSD: head/sys/dev/usb2/controller/ehci2.c 187172 2009-01-13 19:03:01Z thompsa $");
47__FBSDID("$FreeBSD: head/sys/dev/usb2/controller/ehci2.c 187173 2009-01-13 19:03:12Z thompsa $");
48
49#include <dev/usb2/include/usb2_standard.h>
50#include <dev/usb2/include/usb2_mfunc.h>
51#include <dev/usb2/include/usb2_error.h>
52#include <dev/usb2/include/usb2_defs.h>
53
54#define USB_DEBUG_VAR ehcidebug
55

--- 910 unchanged lines hidden (view full) ---

966static void
967ehci_transfer_intr_enqueue(struct usb2_xfer *xfer)
968{
969 /* check for early completion */
970 if (ehci_check_transfer(xfer)) {
971 return;
972 }
973 /* put transfer on interrupt queue */
48
49#include <dev/usb2/include/usb2_standard.h>
50#include <dev/usb2/include/usb2_mfunc.h>
51#include <dev/usb2/include/usb2_error.h>
52#include <dev/usb2/include/usb2_defs.h>
53
54#define USB_DEBUG_VAR ehcidebug
55

--- 910 unchanged lines hidden (view full) ---

966static void
967ehci_transfer_intr_enqueue(struct usb2_xfer *xfer)
968{
969 /* check for early completion */
970 if (ehci_check_transfer(xfer)) {
971 return;
972 }
973 /* put transfer on interrupt queue */
974 usb2_transfer_enqueue(&xfer->udev->bus->intr_q, xfer);
974 usb2_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
975
976 /* start timeout, if any */
977 if (xfer->timeout != 0) {
978 usb2_transfer_timeout_ms(xfer, &ehci_timeout, xfer->timeout);
979 }
980}
981
982#define EHCI_APPEND_FS_TD(std,last) (last) = _ehci_append_fs_td(std,last)

--- 147 unchanged lines hidden (view full) ---

1130 usb2_pc_cpu_flush(sqh->page_cache);
1131 }
1132 return (last);
1133}
1134
1135static usb2_error_t
1136ehci_non_isoc_done_sub(struct usb2_xfer *xfer)
1137{
975
976 /* start timeout, if any */
977 if (xfer->timeout != 0) {
978 usb2_transfer_timeout_ms(xfer, &ehci_timeout, xfer->timeout);
979 }
980}
981
982#define EHCI_APPEND_FS_TD(std,last) (last) = _ehci_append_fs_td(std,last)

--- 147 unchanged lines hidden (view full) ---

1130 usb2_pc_cpu_flush(sqh->page_cache);
1131 }
1132 return (last);
1133}
1134
1135static usb2_error_t
1136ehci_non_isoc_done_sub(struct usb2_xfer *xfer)
1137{
1138 ehci_softc_t *sc = xfer->usb2_sc;
1138 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
1139 ehci_qtd_t *td;
1140 ehci_qtd_t *td_alt_next;
1141 uint32_t status;
1142 uint16_t len;
1143
1144 td = xfer->td_transfer_cache;
1145 td_alt_next = td->alt_next;
1146

--- 87 unchanged lines hidden (view full) ---

1234{
1235 usb2_error_t err = 0;
1236
1237 DPRINTFN(13, "xfer=%p pipe=%p transfer done\n",
1238 xfer, xfer->pipe);
1239
1240#if USB_DEBUG
1241 if (ehcidebug > 10) {
1139 ehci_qtd_t *td;
1140 ehci_qtd_t *td_alt_next;
1141 uint32_t status;
1142 uint16_t len;
1143
1144 td = xfer->td_transfer_cache;
1145 td_alt_next = td->alt_next;
1146

--- 87 unchanged lines hidden (view full) ---

1234{
1235 usb2_error_t err = 0;
1236
1237 DPRINTFN(13, "xfer=%p pipe=%p transfer done\n",
1238 xfer, xfer->pipe);
1239
1240#if USB_DEBUG
1241 if (ehcidebug > 10) {
1242 ehci_softc_t *sc = xfer->usb2_sc;
1242 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
1243
1244 ehci_dump_sqtds(sc, xfer->td_transfer_first);
1245 }
1246#endif
1247
1248 /* reset scanner */
1249
1250 xfer->td_transfer_cache = xfer->td_transfer_first;

--- 35 unchanged lines hidden (view full) ---

1286 * Return values:
1287 * 0: USB transfer is not finished
1288 * Else: USB transfer is finished
1289 *------------------------------------------------------------------------*/
1290static uint8_t
1291ehci_check_transfer(struct usb2_xfer *xfer)
1292{
1293 struct usb2_pipe_methods *methods = xfer->pipe->methods;
1243
1244 ehci_dump_sqtds(sc, xfer->td_transfer_first);
1245 }
1246#endif
1247
1248 /* reset scanner */
1249
1250 xfer->td_transfer_cache = xfer->td_transfer_first;

--- 35 unchanged lines hidden (view full) ---

1286 * Return values:
1287 * 0: USB transfer is not finished
1288 * Else: USB transfer is finished
1289 *------------------------------------------------------------------------*/
1290static uint8_t
1291ehci_check_transfer(struct usb2_xfer *xfer)
1292{
1293 struct usb2_pipe_methods *methods = xfer->pipe->methods;
1294 ehci_softc_t *sc = xfer->usb2_sc;
1294 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
1295
1296 uint32_t status;
1297
1298 DPRINTFN(13, "xfer=%p checking transfer\n", xfer);
1299
1300 if (methods == &ehci_device_isoc_fs_methods) {
1301 ehci_sitd_t *td;
1302

--- 213 unchanged lines hidden (view full) ---

1516 */
1517static void
1518ehci_timeout(void *arg)
1519{
1520 struct usb2_xfer *xfer = arg;
1521
1522 DPRINTF("xfer=%p\n", xfer);
1523
1295
1296 uint32_t status;
1297
1298 DPRINTFN(13, "xfer=%p checking transfer\n", xfer);
1299
1300 if (methods == &ehci_device_isoc_fs_methods) {
1301 ehci_sitd_t *td;
1302

--- 213 unchanged lines hidden (view full) ---

1516 */
1517static void
1518ehci_timeout(void *arg)
1519{
1520 struct usb2_xfer *xfer = arg;
1521
1522 DPRINTF("xfer=%p\n", xfer);
1523
1524 USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
1524 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1525
1526 /* transfer is transferred */
1527 ehci_device_done(xfer, USB_ERR_TIMEOUT);
1528}
1529
1530static void
1531ehci_do_poll(struct usb2_bus *bus)
1532{

--- 193 unchanged lines hidden (view full) ---

1726 ehci_qh_t *qh;
1727 ehci_qtd_t *td;
1728 uint32_t qh_endp;
1729 uint32_t qh_endphub;
1730 uint32_t x;
1731
1732 DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
1733 xfer->address, UE_GET_ADDR(xfer->endpoint),
1525
1526 /* transfer is transferred */
1527 ehci_device_done(xfer, USB_ERR_TIMEOUT);
1528}
1529
1530static void
1531ehci_do_poll(struct usb2_bus *bus)
1532{

--- 193 unchanged lines hidden (view full) ---

1726 ehci_qh_t *qh;
1727 ehci_qtd_t *td;
1728 uint32_t qh_endp;
1729 uint32_t qh_endphub;
1730 uint32_t x;
1731
1732 DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
1733 xfer->address, UE_GET_ADDR(xfer->endpoint),
1734 xfer->sumlen, usb2_get_speed(xfer->udev));
1734 xfer->sumlen, usb2_get_speed(xfer->xroot->udev));
1735
1736 temp.average = xfer->max_usb2_frame_size;
1737 temp.max_frame_size = xfer->max_frame_size;
1735
1736 temp.average = xfer->max_usb2_frame_size;
1737 temp.max_frame_size = xfer->max_frame_size;
1738 temp.sc = xfer->usb2_sc;
1738 temp.sc = EHCI_BUS2SC(xfer->xroot->bus);
1739
1740 /* toggle the DMA set we are using */
1741 xfer->flags_int.curr_dma_set ^= 1;
1742
1743 /* get next DMA set */
1744 td = xfer->td_start[xfer->flags_int.curr_dma_set];
1745
1746 xfer->td_transfer_first = td;

--- 11 unchanged lines hidden (view full) ---

1758 temp.qtd_status |=
1759 htoehci32(temp.sc, EHCI_QTD_SET_TOGGLE(1));
1760 }
1761 temp.auto_data_toggle = 0;
1762 } else {
1763 temp.auto_data_toggle = 1;
1764 }
1765
1739
1740 /* toggle the DMA set we are using */
1741 xfer->flags_int.curr_dma_set ^= 1;
1742
1743 /* get next DMA set */
1744 td = xfer->td_start[xfer->flags_int.curr_dma_set];
1745
1746 xfer->td_transfer_first = td;

--- 11 unchanged lines hidden (view full) ---

1758 temp.qtd_status |=
1759 htoehci32(temp.sc, EHCI_QTD_SET_TOGGLE(1));
1760 }
1761 temp.auto_data_toggle = 0;
1762 } else {
1763 temp.auto_data_toggle = 1;
1764 }
1765
1766 if (usb2_get_speed(xfer->udev) != USB_SPEED_HIGH) {
1766 if (usb2_get_speed(xfer->xroot->udev) != USB_SPEED_HIGH) {
1767 /* max 3 retries */
1768 temp.qtd_status |=
1769 htoehci32(temp.sc, EHCI_QTD_SET_CERR(3));
1770 }
1771 /* check if we should prepend a setup message */
1772
1773 if (xfer->flags_int.control_xfr) {
1774 if (xfer->flags_int.control_hdr) {

--- 114 unchanged lines hidden (view full) ---

1889
1890 /* the "qh_link" field is filled when the QH is added */
1891
1892 qh_endp =
1893 (EHCI_QH_SET_ADDR(xfer->address) |
1894 EHCI_QH_SET_ENDPT(UE_GET_ADDR(xfer->endpoint)) |
1895 EHCI_QH_SET_MPL(xfer->max_packet_size));
1896
1767 /* max 3 retries */
1768 temp.qtd_status |=
1769 htoehci32(temp.sc, EHCI_QTD_SET_CERR(3));
1770 }
1771 /* check if we should prepend a setup message */
1772
1773 if (xfer->flags_int.control_xfr) {
1774 if (xfer->flags_int.control_hdr) {

--- 114 unchanged lines hidden (view full) ---

1889
1890 /* the "qh_link" field is filled when the QH is added */
1891
1892 qh_endp =
1893 (EHCI_QH_SET_ADDR(xfer->address) |
1894 EHCI_QH_SET_ENDPT(UE_GET_ADDR(xfer->endpoint)) |
1895 EHCI_QH_SET_MPL(xfer->max_packet_size));
1896
1897 if (usb2_get_speed(xfer->udev) == USB_SPEED_HIGH) {
1897 if (usb2_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) {
1898 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH) |
1899 EHCI_QH_DTC | EHCI_QH_SET_NRL(8));
1900 } else {
1901
1898 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH) |
1899 EHCI_QH_DTC | EHCI_QH_SET_NRL(8));
1900 } else {
1901
1902 if (usb2_get_speed(xfer->udev) == USB_SPEED_FULL) {
1902 if (usb2_get_speed(xfer->xroot->udev) == USB_SPEED_FULL) {
1903 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_FULL) |
1904 EHCI_QH_DTC);
1905 } else {
1906 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_LOW) |
1907 EHCI_QH_DTC);
1908 }
1909
1910 if (methods == &ehci_device_ctrl_methods) {

--- 6 unchanged lines hidden (view full) ---

1917 }
1918
1919 qh->qh_endp = htoehci32(temp.sc, qh_endp);
1920
1921 qh_endphub =
1922 (EHCI_QH_SET_MULT(xfer->max_packet_count & 3) |
1923 EHCI_QH_SET_CMASK(xfer->usb2_cmask) |
1924 EHCI_QH_SET_SMASK(xfer->usb2_smask) |
1903 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_FULL) |
1904 EHCI_QH_DTC);
1905 } else {
1906 qh_endp |= (EHCI_QH_SET_EPS(EHCI_QH_SPEED_LOW) |
1907 EHCI_QH_DTC);
1908 }
1909
1910 if (methods == &ehci_device_ctrl_methods) {

--- 6 unchanged lines hidden (view full) ---

1917 }
1918
1919 qh->qh_endp = htoehci32(temp.sc, qh_endp);
1920
1921 qh_endphub =
1922 (EHCI_QH_SET_MULT(xfer->max_packet_count & 3) |
1923 EHCI_QH_SET_CMASK(xfer->usb2_cmask) |
1924 EHCI_QH_SET_SMASK(xfer->usb2_smask) |
1925 EHCI_QH_SET_HUBA(xfer->udev->hs_hub_addr) |
1926 EHCI_QH_SET_PORT(xfer->udev->hs_port_no));
1925 EHCI_QH_SET_HUBA(xfer->xroot->udev->hs_hub_addr) |
1926 EHCI_QH_SET_PORT(xfer->xroot->udev->hs_port_no));
1927
1928 qh->qh_endphub = htoehci32(temp.sc, qh_endphub);
1929 qh->qh_curqtd = htoehci32(temp.sc, 0);
1930
1931 /* fill the overlay qTD */
1932 qh->qh_qtd.qtd_status = htoehci32(temp.sc, 0);
1933
1934 if (temp.auto_data_toggle) {

--- 11 unchanged lines hidden (view full) ---

1946 td = xfer->td_transfer_first;
1947
1948 qh->qh_qtd.qtd_next = td->qtd_self;
1949 qh->qh_qtd.qtd_altnext =
1950 htoehci32(temp.sc, EHCI_LINK_TERMINATE);
1951
1952 usb2_pc_cpu_flush(qh->page_cache);
1953
1927
1928 qh->qh_endphub = htoehci32(temp.sc, qh_endphub);
1929 qh->qh_curqtd = htoehci32(temp.sc, 0);
1930
1931 /* fill the overlay qTD */
1932 qh->qh_qtd.qtd_status = htoehci32(temp.sc, 0);
1933
1934 if (temp.auto_data_toggle) {

--- 11 unchanged lines hidden (view full) ---

1946 td = xfer->td_transfer_first;
1947
1948 qh->qh_qtd.qtd_next = td->qtd_self;
1949 qh->qh_qtd.qtd_altnext =
1950 htoehci32(temp.sc, EHCI_LINK_TERMINATE);
1951
1952 usb2_pc_cpu_flush(qh->page_cache);
1953
1954 if (xfer->udev->pwr_save.suspended == 0) {
1954 if (xfer->xroot->udev->pwr_save.suspended == 0) {
1955 EHCI_APPEND_QH(qh, *qh_last);
1956 }
1957}
1958
1959static void
1960ehci_root_intr_done(struct usb2_xfer *xfer,
1961 struct usb2_sw_transfer *std)
1962{
1955 EHCI_APPEND_QH(qh, *qh_last);
1956 }
1957}
1958
1959static void
1960ehci_root_intr_done(struct usb2_xfer *xfer,
1961 struct usb2_sw_transfer *std)
1962{
1963 ehci_softc_t *sc = xfer->usb2_sc;
1963 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
1964 uint16_t i;
1965 uint16_t m;
1966
1967 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
1968
1969 if (std->state != USB_SW_TR_PRE_DATA) {
1970 if (std->state == USB_SW_TR_PRE_CALLBACK) {
1971 /* transfer transferred */

--- 140 unchanged lines hidden (view full) ---

2112
2113/* NOTE: "done" can be run two times in a row,
2114 * from close and from interrupt
2115 */
2116static void
2117ehci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
2118{
2119 struct usb2_pipe_methods *methods = xfer->pipe->methods;
1964 uint16_t i;
1965 uint16_t m;
1966
1967 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
1968
1969 if (std->state != USB_SW_TR_PRE_DATA) {
1970 if (std->state == USB_SW_TR_PRE_CALLBACK) {
1971 /* transfer transferred */

--- 140 unchanged lines hidden (view full) ---

2112
2113/* NOTE: "done" can be run two times in a row,
2114 * from close and from interrupt
2115 */
2116static void
2117ehci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
2118{
2119 struct usb2_pipe_methods *methods = xfer->pipe->methods;
2120 ehci_softc_t *sc = xfer->usb2_sc;
2120 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2121
2122 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
2123
2124 DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
2125 xfer, xfer->pipe, error);
2126
2127 if ((methods == &ehci_device_bulk_methods) ||
2128 (methods == &ehci_device_ctrl_methods)) {
2129#if USB_DEBUG
2130 if (ehcidebug > 8) {
2131 DPRINTF("nexttog=%d; data after transfer:\n",
2132 xfer->pipe->toggle_next);
2121
2122 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
2123
2124 DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
2125 xfer, xfer->pipe, error);
2126
2127 if ((methods == &ehci_device_bulk_methods) ||
2128 (methods == &ehci_device_ctrl_methods)) {
2129#if USB_DEBUG
2130 if (ehcidebug > 8) {
2131 DPRINTF("nexttog=%d; data after transfer:\n",
2132 xfer->pipe->toggle_next);
2133 ehci_dump_sqtds(xfer->usb2_sc,
2133 ehci_dump_sqtds(sc,
2134 xfer->td_transfer_first);
2135 }
2136#endif
2137
2138 EHCI_REMOVE_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
2139 sc->sc_async_p_last);
2140 }
2141 if (methods == &ehci_device_intr_methods) {

--- 38 unchanged lines hidden (view full) ---

2180ehci_device_bulk_enter(struct usb2_xfer *xfer)
2181{
2182 return;
2183}
2184
2185static void
2186ehci_device_bulk_start(struct usb2_xfer *xfer)
2187{
2134 xfer->td_transfer_first);
2135 }
2136#endif
2137
2138 EHCI_REMOVE_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
2139 sc->sc_async_p_last);
2140 }
2141 if (methods == &ehci_device_intr_methods) {

--- 38 unchanged lines hidden (view full) ---

2180ehci_device_bulk_enter(struct usb2_xfer *xfer)
2181{
2182 return;
2183}
2184
2185static void
2186ehci_device_bulk_start(struct usb2_xfer *xfer)
2187{
2188 ehci_softc_t *sc = xfer->usb2_sc;
2188 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2189
2190 /* setup TD's and QH */
2191 ehci_setup_standard_chain(xfer, &sc->sc_async_p_last);
2192
2193 /* put transfer on interrupt queue */
2194 ehci_transfer_intr_enqueue(xfer);
2195}
2196

--- 26 unchanged lines hidden (view full) ---

2223ehci_device_ctrl_enter(struct usb2_xfer *xfer)
2224{
2225 return;
2226}
2227
2228static void
2229ehci_device_ctrl_start(struct usb2_xfer *xfer)
2230{
2189
2190 /* setup TD's and QH */
2191 ehci_setup_standard_chain(xfer, &sc->sc_async_p_last);
2192
2193 /* put transfer on interrupt queue */
2194 ehci_transfer_intr_enqueue(xfer);
2195}
2196

--- 26 unchanged lines hidden (view full) ---

2223ehci_device_ctrl_enter(struct usb2_xfer *xfer)
2224{
2225 return;
2226}
2227
2228static void
2229ehci_device_ctrl_start(struct usb2_xfer *xfer)
2230{
2231 ehci_softc_t *sc = xfer->usb2_sc;
2231 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2232
2233 /* setup TD's and QH */
2234 ehci_setup_standard_chain(xfer, &sc->sc_async_p_last);
2235
2236 /* put transfer on interrupt queue */
2237 ehci_transfer_intr_enqueue(xfer);
2238}
2239

--- 8 unchanged lines hidden (view full) ---

2248};
2249
2250/*------------------------------------------------------------------------*
2251 * ehci interrupt support
2252 *------------------------------------------------------------------------*/
2253static void
2254ehci_device_intr_open(struct usb2_xfer *xfer)
2255{
2232
2233 /* setup TD's and QH */
2234 ehci_setup_standard_chain(xfer, &sc->sc_async_p_last);
2235
2236 /* put transfer on interrupt queue */
2237 ehci_transfer_intr_enqueue(xfer);
2238}
2239

--- 8 unchanged lines hidden (view full) ---

2248};
2249
2250/*------------------------------------------------------------------------*
2251 * ehci interrupt support
2252 *------------------------------------------------------------------------*/
2253static void
2254ehci_device_intr_open(struct usb2_xfer *xfer)
2255{
2256 ehci_softc_t *sc = xfer->usb2_sc;
2256 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2257 uint16_t best;
2258 uint16_t bit;
2259 uint16_t x;
2260 uint8_t slot;
2261
2262 /* Allocate a microframe slot first: */
2263
2264 slot = usb2_intr_schedule_adjust
2257 uint16_t best;
2258 uint16_t bit;
2259 uint16_t x;
2260 uint8_t slot;
2261
2262 /* Allocate a microframe slot first: */
2263
2264 slot = usb2_intr_schedule_adjust
2265 (xfer->udev, xfer->max_frame_size, USB_HS_MICRO_FRAMES_MAX);
2265 (xfer->xroot->udev, xfer->max_frame_size, USB_HS_MICRO_FRAMES_MAX);
2266
2266
2267 if (usb2_get_speed(xfer->udev) == USB_SPEED_HIGH) {
2267 if (usb2_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) {
2268 xfer->usb2_uframe = slot;
2269 xfer->usb2_smask = (1 << slot) & 0xFF;
2270 xfer->usb2_cmask = 0;
2271 } else {
2272 xfer->usb2_uframe = slot;
2273 xfer->usb2_smask = (1 << slot) & 0x3F;
2274 xfer->usb2_cmask = (-(4 << slot)) & 0xFE;
2275 }

--- 25 unchanged lines hidden (view full) ---

2301
2302 DPRINTFN(3, "best=%d interval=%d\n",
2303 best, xfer->interval);
2304}
2305
2306static void
2307ehci_device_intr_close(struct usb2_xfer *xfer)
2308{
2268 xfer->usb2_uframe = slot;
2269 xfer->usb2_smask = (1 << slot) & 0xFF;
2270 xfer->usb2_cmask = 0;
2271 } else {
2272 xfer->usb2_uframe = slot;
2273 xfer->usb2_smask = (1 << slot) & 0x3F;
2274 xfer->usb2_cmask = (-(4 << slot)) & 0xFE;
2275 }

--- 25 unchanged lines hidden (view full) ---

2301
2302 DPRINTFN(3, "best=%d interval=%d\n",
2303 best, xfer->interval);
2304}
2305
2306static void
2307ehci_device_intr_close(struct usb2_xfer *xfer)
2308{
2309 ehci_softc_t *sc = xfer->usb2_sc;
2309 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2310 uint8_t slot;
2311
2312 slot = usb2_intr_schedule_adjust
2310 uint8_t slot;
2311
2312 slot = usb2_intr_schedule_adjust
2313 (xfer->udev, -(xfer->max_frame_size), xfer->usb2_uframe);
2313 (xfer->xroot->udev, -(xfer->max_frame_size), xfer->usb2_uframe);
2314
2315 sc->sc_intr_stat[xfer->qh_pos]--;
2316
2317 ehci_device_done(xfer, USB_ERR_CANCELLED);
2318}
2319
2320static void
2321ehci_device_intr_enter(struct usb2_xfer *xfer)
2322{
2323 return;
2324}
2325
2326static void
2327ehci_device_intr_start(struct usb2_xfer *xfer)
2328{
2314
2315 sc->sc_intr_stat[xfer->qh_pos]--;
2316
2317 ehci_device_done(xfer, USB_ERR_CANCELLED);
2318}
2319
2320static void
2321ehci_device_intr_enter(struct usb2_xfer *xfer)
2322{
2323 return;
2324}
2325
2326static void
2327ehci_device_intr_start(struct usb2_xfer *xfer)
2328{
2329 ehci_softc_t *sc = xfer->usb2_sc;
2329 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2330
2331 /* setup TD's and QH */
2332 ehci_setup_standard_chain(xfer, &sc->sc_intr_p_last[xfer->qh_pos]);
2333
2334 /* put transfer on interrupt queue */
2335 ehci_transfer_intr_enqueue(xfer);
2336}
2337

--- 8 unchanged lines hidden (view full) ---

2346};
2347
2348/*------------------------------------------------------------------------*
2349 * ehci full speed isochronous support
2350 *------------------------------------------------------------------------*/
2351static void
2352ehci_device_isoc_fs_open(struct usb2_xfer *xfer)
2353{
2330
2331 /* setup TD's and QH */
2332 ehci_setup_standard_chain(xfer, &sc->sc_intr_p_last[xfer->qh_pos]);
2333
2334 /* put transfer on interrupt queue */
2335 ehci_transfer_intr_enqueue(xfer);
2336}
2337

--- 8 unchanged lines hidden (view full) ---

2346};
2347
2348/*------------------------------------------------------------------------*
2349 * ehci full speed isochronous support
2350 *------------------------------------------------------------------------*/
2351static void
2352ehci_device_isoc_fs_open(struct usb2_xfer *xfer)
2353{
2354 ehci_softc_t *sc = xfer->usb2_sc;
2354 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2355 ehci_sitd_t *td;
2356 uint32_t sitd_portaddr;
2357 uint8_t ds;
2358
2359 sitd_portaddr =
2360 EHCI_SITD_SET_ADDR(xfer->address) |
2361 EHCI_SITD_SET_ENDPT(UE_GET_ADDR(xfer->endpoint)) |
2355 ehci_sitd_t *td;
2356 uint32_t sitd_portaddr;
2357 uint8_t ds;
2358
2359 sitd_portaddr =
2360 EHCI_SITD_SET_ADDR(xfer->address) |
2361 EHCI_SITD_SET_ENDPT(UE_GET_ADDR(xfer->endpoint)) |
2362 EHCI_SITD_SET_HUBA(xfer->udev->hs_hub_addr) |
2363 EHCI_SITD_SET_PORT(xfer->udev->hs_port_no);
2362 EHCI_SITD_SET_HUBA(xfer->xroot->udev->hs_hub_addr) |
2363 EHCI_SITD_SET_PORT(xfer->xroot->udev->hs_port_no);
2364
2365 if (UE_GET_DIR(xfer->endpoint) == UE_DIR_IN) {
2366 sitd_portaddr |= EHCI_SITD_SET_DIR_IN;
2367 }
2368 sitd_portaddr = htoehci32(sc, sitd_portaddr);
2369
2370 /* initialize all TD's */
2371

--- 22 unchanged lines hidden (view full) ---

2394{
2395 ehci_device_done(xfer, USB_ERR_CANCELLED);
2396}
2397
2398static void
2399ehci_device_isoc_fs_enter(struct usb2_xfer *xfer)
2400{
2401 struct usb2_page_search buf_res;
2364
2365 if (UE_GET_DIR(xfer->endpoint) == UE_DIR_IN) {
2366 sitd_portaddr |= EHCI_SITD_SET_DIR_IN;
2367 }
2368 sitd_portaddr = htoehci32(sc, sitd_portaddr);
2369
2370 /* initialize all TD's */
2371

--- 22 unchanged lines hidden (view full) ---

2394{
2395 ehci_device_done(xfer, USB_ERR_CANCELLED);
2396}
2397
2398static void
2399ehci_device_isoc_fs_enter(struct usb2_xfer *xfer)
2400{
2401 struct usb2_page_search buf_res;
2402 ehci_softc_t *sc = xfer->usb2_sc;
2402 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2403 struct usb2_fs_isoc_schedule *fss_start;
2404 struct usb2_fs_isoc_schedule *fss_end;
2405 struct usb2_fs_isoc_schedule *fss;
2406 ehci_sitd_t *td;
2407 ehci_sitd_t *td_last = NULL;
2408 ehci_sitd_t **pp_last;
2409 uint32_t *plen;
2410 uint32_t buf_offset;

--- 44 unchanged lines hidden (view full) ---

2455 buf_offset = (xfer->pipe->isoc_next - nframes) &
2456 (EHCI_VIRTUAL_FRAMELIST_COUNT - 1);
2457
2458 /*
2459 * pre-compute when the isochronous transfer will be finished:
2460 */
2461 xfer->isoc_time_complete =
2462 usb2_fs_isoc_schedule_isoc_time_expand
2403 struct usb2_fs_isoc_schedule *fss_start;
2404 struct usb2_fs_isoc_schedule *fss_end;
2405 struct usb2_fs_isoc_schedule *fss;
2406 ehci_sitd_t *td;
2407 ehci_sitd_t *td_last = NULL;
2408 ehci_sitd_t **pp_last;
2409 uint32_t *plen;
2410 uint32_t buf_offset;

--- 44 unchanged lines hidden (view full) ---

2455 buf_offset = (xfer->pipe->isoc_next - nframes) &
2456 (EHCI_VIRTUAL_FRAMELIST_COUNT - 1);
2457
2458 /*
2459 * pre-compute when the isochronous transfer will be finished:
2460 */
2461 xfer->isoc_time_complete =
2462 usb2_fs_isoc_schedule_isoc_time_expand
2463 (xfer->udev, &fss_start, &fss_end, nframes) + buf_offset +
2463 (xfer->xroot->udev, &fss_start, &fss_end, nframes) + buf_offset +
2464 xfer->nframes;
2465
2466 /* get the real number of frames */
2467
2468 nframes = xfer->nframes;
2469
2470 buf_offset = 0;
2471

--- 159 unchanged lines hidden (view full) ---

2631};
2632
2633/*------------------------------------------------------------------------*
2634 * ehci high speed isochronous support
2635 *------------------------------------------------------------------------*/
2636static void
2637ehci_device_isoc_hs_open(struct usb2_xfer *xfer)
2638{
2464 xfer->nframes;
2465
2466 /* get the real number of frames */
2467
2468 nframes = xfer->nframes;
2469
2470 buf_offset = 0;
2471

--- 159 unchanged lines hidden (view full) ---

2631};
2632
2633/*------------------------------------------------------------------------*
2634 * ehci high speed isochronous support
2635 *------------------------------------------------------------------------*/
2636static void
2637ehci_device_isoc_hs_open(struct usb2_xfer *xfer)
2638{
2639 ehci_softc_t *sc = xfer->usb2_sc;
2639 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2640 ehci_itd_t *td;
2641 uint32_t temp;
2642 uint8_t ds;
2643
2644 /* initialize all TD's */
2645
2646 for (ds = 0; ds != 2; ds++) {
2647

--- 37 unchanged lines hidden (view full) ---

2685{
2686 ehci_device_done(xfer, USB_ERR_CANCELLED);
2687}
2688
2689static void
2690ehci_device_isoc_hs_enter(struct usb2_xfer *xfer)
2691{
2692 struct usb2_page_search buf_res;
2640 ehci_itd_t *td;
2641 uint32_t temp;
2642 uint8_t ds;
2643
2644 /* initialize all TD's */
2645
2646 for (ds = 0; ds != 2; ds++) {
2647

--- 37 unchanged lines hidden (view full) ---

2685{
2686 ehci_device_done(xfer, USB_ERR_CANCELLED);
2687}
2688
2689static void
2690ehci_device_isoc_hs_enter(struct usb2_xfer *xfer)
2691{
2692 struct usb2_page_search buf_res;
2693 ehci_softc_t *sc = xfer->usb2_sc;
2693 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2694 ehci_itd_t *td;
2695 ehci_itd_t *td_last = NULL;
2696 ehci_itd_t **pp_last;
2697 bus_size_t page_addr;
2698 uint32_t *plen;
2699 uint32_t status;
2700 uint32_t buf_offset;
2701 uint32_t nframes;

--- 207 unchanged lines hidden (view full) ---

2909ehci_root_ctrl_open(struct usb2_xfer *xfer)
2910{
2911 return;
2912}
2913
2914static void
2915ehci_root_ctrl_close(struct usb2_xfer *xfer)
2916{
2694 ehci_itd_t *td;
2695 ehci_itd_t *td_last = NULL;
2696 ehci_itd_t **pp_last;
2697 bus_size_t page_addr;
2698 uint32_t *plen;
2699 uint32_t status;
2700 uint32_t buf_offset;
2701 uint32_t nframes;

--- 207 unchanged lines hidden (view full) ---

2909ehci_root_ctrl_open(struct usb2_xfer *xfer)
2910{
2911 return;
2912}
2913
2914static void
2915ehci_root_ctrl_close(struct usb2_xfer *xfer)
2916{
2917 ehci_softc_t *sc = xfer->usb2_sc;
2917 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
2918
2919 if (sc->sc_root_ctrl.xfer == xfer) {
2920 sc->sc_root_ctrl.xfer = NULL;
2921 }
2922 ehci_device_done(xfer, USB_ERR_CANCELLED);
2923}
2924
2925/* data structures and routines

--- 90 unchanged lines hidden (view full) ---

3016ehci_root_ctrl_enter(struct usb2_xfer *xfer)
3017{
3018 return;
3019}
3020
3021static void
3022ehci_root_ctrl_start(struct usb2_xfer *xfer)
3023{
2918
2919 if (sc->sc_root_ctrl.xfer == xfer) {
2920 sc->sc_root_ctrl.xfer = NULL;
2921 }
2922 ehci_device_done(xfer, USB_ERR_CANCELLED);
2923}
2924
2925/* data structures and routines

--- 90 unchanged lines hidden (view full) ---

3016ehci_root_ctrl_enter(struct usb2_xfer *xfer)
3017{
3018 return;
3019}
3020
3021static void
3022ehci_root_ctrl_start(struct usb2_xfer *xfer)
3023{
3024 ehci_softc_t *sc = xfer->usb2_sc;
3024 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
3025
3026 DPRINTF("\n");
3027
3028 sc->sc_root_ctrl.xfer = xfer;
3029
3025
3026 DPRINTF("\n");
3027
3028 sc->sc_root_ctrl.xfer = xfer;
3029
3030 usb2_bus_roothub_exec(xfer->udev->bus);
3030 usb2_bus_roothub_exec(xfer->xroot->bus);
3031}
3032
3033static void
3034ehci_root_ctrl_task(struct usb2_bus *bus)
3035{
3036 ehci_root_ctrl_poll(EHCI_BUS2SC(bus));
3037}
3038
3039static void
3040ehci_root_ctrl_done(struct usb2_xfer *xfer,
3041 struct usb2_sw_transfer *std)
3042{
3031}
3032
3033static void
3034ehci_root_ctrl_task(struct usb2_bus *bus)
3035{
3036 ehci_root_ctrl_poll(EHCI_BUS2SC(bus));
3037}
3038
3039static void
3040ehci_root_ctrl_done(struct usb2_xfer *xfer,
3041 struct usb2_sw_transfer *std)
3042{
3043 ehci_softc_t *sc = xfer->usb2_sc;
3043 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
3044 char *ptr;
3045 uint32_t port;
3046 uint32_t v;
3047 uint16_t i;
3048 uint16_t value;
3049 uint16_t index;
3050 uint8_t l;
3051 uint8_t use_polling;

--- 9 unchanged lines hidden (view full) ---

3061 }
3062 /* buffer reset */
3063 std->ptr = sc->sc_hub_desc.temp;
3064 std->len = 0;
3065
3066 value = UGETW(std->req.wValue);
3067 index = UGETW(std->req.wIndex);
3068
3044 char *ptr;
3045 uint32_t port;
3046 uint32_t v;
3047 uint16_t i;
3048 uint16_t value;
3049 uint16_t index;
3050 uint8_t l;
3051 uint8_t use_polling;

--- 9 unchanged lines hidden (view full) ---

3061 }
3062 /* buffer reset */
3063 std->ptr = sc->sc_hub_desc.temp;
3064 std->len = 0;
3065
3066 value = UGETW(std->req.wValue);
3067 index = UGETW(std->req.wIndex);
3068
3069 use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
3069 use_polling = mtx_owned(xfer->xroot->xfer_mtx) ? 1 : 0;
3070
3071 DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
3072 "wValue=0x%04x wIndex=0x%04x\n",
3073 std->req.bmRequestType, std->req.bRequest,
3074 UGETW(std->req.wLength), value, index);
3075
3076#define C(x,y) ((x) | ((y) << 8))
3077 switch (C(std->req.bRequest, std->req.bmRequestType)) {

--- 400 unchanged lines hidden (view full) ---

3478ehci_root_intr_open(struct usb2_xfer *xfer)
3479{
3480 return;
3481}
3482
3483static void
3484ehci_root_intr_close(struct usb2_xfer *xfer)
3485{
3070
3071 DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
3072 "wValue=0x%04x wIndex=0x%04x\n",
3073 std->req.bmRequestType, std->req.bRequest,
3074 UGETW(std->req.wLength), value, index);
3075
3076#define C(x,y) ((x) | ((y) << 8))
3077 switch (C(std->req.bRequest, std->req.bmRequestType)) {

--- 400 unchanged lines hidden (view full) ---

3478ehci_root_intr_open(struct usb2_xfer *xfer)
3479{
3480 return;
3481}
3482
3483static void
3484ehci_root_intr_close(struct usb2_xfer *xfer)
3485{
3486 ehci_softc_t *sc = xfer->usb2_sc;
3486 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
3487
3488 if (sc->sc_root_intr.xfer == xfer) {
3489 sc->sc_root_intr.xfer = NULL;
3490 }
3491 ehci_device_done(xfer, USB_ERR_CANCELLED);
3492}
3493
3494static void
3495ehci_root_intr_enter(struct usb2_xfer *xfer)
3496{
3497 return;
3498}
3499
3500static void
3501ehci_root_intr_start(struct usb2_xfer *xfer)
3502{
3487
3488 if (sc->sc_root_intr.xfer == xfer) {
3489 sc->sc_root_intr.xfer = NULL;
3490 }
3491 ehci_device_done(xfer, USB_ERR_CANCELLED);
3492}
3493
3494static void
3495ehci_root_intr_enter(struct usb2_xfer *xfer)
3496{
3497 return;
3498}
3499
3500static void
3501ehci_root_intr_start(struct usb2_xfer *xfer)
3502{
3503 ehci_softc_t *sc = xfer->usb2_sc;
3503 ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
3504
3505 sc->sc_root_intr.xfer = xfer;
3506}
3507
3508struct usb2_pipe_methods ehci_root_intr_methods =
3509{
3510 .open = ehci_root_intr_open,
3511 .close = ehci_root_intr_close,

--- 21 unchanged lines hidden (view full) ---

3533 xfer = parm->curr_xfer;
3534
3535 nqtd = 0;
3536 nqh = 0;
3537 nsitd = 0;
3538 nitd = 0;
3539
3540 /*
3504
3505 sc->sc_root_intr.xfer = xfer;
3506}
3507
3508struct usb2_pipe_methods ehci_root_intr_methods =
3509{
3510 .open = ehci_root_intr_open,
3511 .close = ehci_root_intr_close,

--- 21 unchanged lines hidden (view full) ---

3533 xfer = parm->curr_xfer;
3534
3535 nqtd = 0;
3536 nqh = 0;
3537 nsitd = 0;
3538 nitd = 0;
3539
3540 /*
3541 * setup xfer
3542 */
3543 xfer->usb2_sc = sc;
3544
3545 /*
3546 * compute maximum number of some structures
3547 */
3548 if (parm->methods == &ehci_device_ctrl_methods) {
3549
3550 /*
3551 * The proof for the "nqtd" formula is illustrated like
3552 * this:
3553 *

--- 305 unchanged lines hidden (view full) ---

3859 struct usb2_pipe_methods *methods;
3860
3861 DPRINTF("\n");
3862
3863 USB_BUS_LOCK(udev->bus);
3864
3865 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
3866
3541 * compute maximum number of some structures
3542 */
3543 if (parm->methods == &ehci_device_ctrl_methods) {
3544
3545 /*
3546 * The proof for the "nqtd" formula is illustrated like
3547 * this:
3548 *

--- 305 unchanged lines hidden (view full) ---

3854 struct usb2_pipe_methods *methods;
3855
3856 DPRINTF("\n");
3857
3858 USB_BUS_LOCK(udev->bus);
3859
3860 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
3861
3867 if (xfer->udev == udev) {
3862 if (xfer->xroot->udev == udev) {
3868
3869 methods = xfer->pipe->methods;
3870
3871 if ((methods == &ehci_device_bulk_methods) ||
3872 (methods == &ehci_device_ctrl_methods)) {
3873 EHCI_APPEND_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
3874 sc->sc_async_p_last);
3875 }

--- 17 unchanged lines hidden (view full) ---

3893 struct usb2_pipe_methods *methods;
3894
3895 DPRINTF("\n");
3896
3897 USB_BUS_LOCK(udev->bus);
3898
3899 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
3900
3863
3864 methods = xfer->pipe->methods;
3865
3866 if ((methods == &ehci_device_bulk_methods) ||
3867 (methods == &ehci_device_ctrl_methods)) {
3868 EHCI_APPEND_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
3869 sc->sc_async_p_last);
3870 }

--- 17 unchanged lines hidden (view full) ---

3888 struct usb2_pipe_methods *methods;
3889
3890 DPRINTF("\n");
3891
3892 USB_BUS_LOCK(udev->bus);
3893
3894 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
3895
3901 if (xfer->udev == udev) {
3896 if (xfer->xroot->udev == udev) {
3902
3903 methods = xfer->pipe->methods;
3904
3905 if ((methods == &ehci_device_bulk_methods) ||
3906 (methods == &ehci_device_ctrl_methods)) {
3907 EHCI_REMOVE_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
3908 sc->sc_async_p_last);
3909 }

--- 58 unchanged lines hidden ---
3897
3898 methods = xfer->pipe->methods;
3899
3900 if ((methods == &ehci_device_bulk_methods) ||
3901 (methods == &ehci_device_ctrl_methods)) {
3902 EHCI_REMOVE_QH(xfer->qh_start[xfer->flags_int.curr_dma_set],
3903 sc->sc_async_p_last);
3904 }

--- 58 unchanged lines hidden ---