Mon Jan 21 07:37:06 2013 UTC ()
KNF


(skrll)
diff -r1.28 -r1.29 src/sys/dev/usb/dwc_otg.c

cvs diff -r1.28 -r1.29 src/sys/dev/usb/Attic/dwc_otg.c (expand / switch to unified diff)

--- src/sys/dev/usb/Attic/dwc_otg.c 2013/01/19 14:33:51 1.28
+++ src/sys/dev/usb/Attic/dwc_otg.c 2013/01/21 07:37:06 1.29
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dwc_otg.c,v 1.28 2013/01/19 14:33:51 skrll Exp $ */ 1/* $NetBSD: dwc_otg.c,v 1.29 2013/01/21 07:37:06 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2012 Hans Petter Selasky. All rights reserved. 4 * Copyright (c) 2012 Hans Petter Selasky. All rights reserved.
5 * Copyright (c) 2010-2011 Aleksandr Rybalko. All rights reserved. 5 * Copyright (c) 2010-2011 Aleksandr Rybalko. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 * POSSIBILITY OF SUCH DAMAGE. 55 * POSSIBILITY OF SUCH DAMAGE.
56 */ 56 */
57 57
58/* 58/*
59 * Designware USB 2.0 OTG 59 * Designware USB 2.0 OTG
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: dwc_otg.c,v 1.28 2013/01/19 14:33:51 skrll Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: dwc_otg.c,v 1.29 2013/01/21 07:37:06 skrll Exp $");
64 64
65#include <sys/param.h> 65#include <sys/param.h>
66#include <sys/systm.h> 66#include <sys/systm.h>
67#include <sys/kmem.h> 67#include <sys/kmem.h>
68#include <sys/kernel.h> 68#include <sys/kernel.h>
69#include <sys/device.h> 69#include <sys/device.h>
70#include <sys/select.h> 70#include <sys/select.h>
71#include <sys/proc.h> 71#include <sys/proc.h>
72#include <sys/queue.h> 72#include <sys/queue.h>
73#include <sys/cpu.h> 73#include <sys/cpu.h>
74 74
75#include <machine/endian.h> 75#include <machine/endian.h>
76 76
@@ -1172,49 +1172,49 @@ dwc_otg_root_ctrl_done(usbd_xfer_handle  @@ -1172,49 +1172,49 @@ dwc_otg_root_ctrl_done(usbd_xfer_handle
1172Static usbd_status 1172Static usbd_status
1173dwc_otg_root_intr_transfer(usbd_xfer_handle xfer) 1173dwc_otg_root_intr_transfer(usbd_xfer_handle xfer)
1174{ 1174{
1175 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private; 1175 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private;
1176 usbd_status err; 1176 usbd_status err;
1177 1177
1178 DPRINTF("\n"); 1178 DPRINTF("\n");
1179 1179
1180 /* Insert last in queue. */ 1180 /* Insert last in queue. */
1181 mutex_enter(&sc->sc_lock); 1181 mutex_enter(&sc->sc_lock);
1182 err = usb_insert_transfer(xfer); 1182 err = usb_insert_transfer(xfer);
1183 mutex_exit(&sc->sc_lock); 1183 mutex_exit(&sc->sc_lock);
1184 if (err) 1184 if (err)
1185 return (err); 1185 return err;
1186 1186
1187 /* Pipe isn't running, start first */ 1187 /* Pipe isn't running, start first */
1188 return (dwc_otg_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); 1188 return dwc_otg_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1189} 1189}
1190 1190
1191Static usbd_status 1191Static usbd_status
1192dwc_otg_root_intr_start(usbd_xfer_handle xfer) 1192dwc_otg_root_intr_start(usbd_xfer_handle xfer)
1193{ 1193{
1194 usbd_pipe_handle pipe = xfer->pipe; 1194 usbd_pipe_handle pipe = xfer->pipe;
1195 struct dwc_otg_softc *sc = pipe->device->bus->hci_private; 1195 struct dwc_otg_softc *sc = pipe->device->bus->hci_private;
1196 1196
1197 DPRINTF("\n"); 1197 DPRINTF("\n");
1198 1198
1199 if (sc->sc_dying) 1199 if (sc->sc_dying)
1200 return (USBD_IOERROR); 1200 return USBD_IOERROR;
1201 1201
1202 mutex_enter(&sc->sc_lock); 1202 mutex_enter(&sc->sc_lock);
1203 KASSERT(sc->sc_intrxfer == NULL); 1203 KASSERT(sc->sc_intrxfer == NULL);
1204 sc->sc_intrxfer = xfer; 1204 sc->sc_intrxfer = xfer;
1205 mutex_exit(&sc->sc_lock); 1205 mutex_exit(&sc->sc_lock);
1206 1206
1207 return (USBD_IN_PROGRESS); 1207 return USBD_IN_PROGRESS;
1208} 1208}
1209 1209
1210/* Abort a root interrupt request. */ 1210/* Abort a root interrupt request. */
1211Static void 1211Static void
1212dwc_otg_root_intr_abort(usbd_xfer_handle xfer) 1212dwc_otg_root_intr_abort(usbd_xfer_handle xfer)
1213{ 1213{
1214#ifdef DIAGNOSTIC 1214#ifdef DIAGNOSTIC
1215 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private; 1215 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private;
1216#endif 1216#endif
1217 DPRINTF("xfer=%p\n", xfer); 1217 DPRINTF("xfer=%p\n", xfer);
1218 1218
1219 KASSERT(mutex_owned(&sc->sc_lock)); 1219 KASSERT(mutex_owned(&sc->sc_lock));
1220 1220
@@ -1252,30 +1252,30 @@ dwc_otg_device_ctrl_transfer(usbd_xfer_h @@ -1252,30 +1252,30 @@ dwc_otg_device_ctrl_transfer(usbd_xfer_h
1252 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private; 1252 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private;
1253 usbd_status err; 1253 usbd_status err;
1254 1254
1255 DPRINTF("\n"); 1255 DPRINTF("\n");
1256 1256
1257 dwc_otg_xfer_setup(xfer); 1257 dwc_otg_xfer_setup(xfer);
1258 dwc_otg_setup_ctrl_chain(xfer); 1258 dwc_otg_setup_ctrl_chain(xfer);
1259 1259
1260 /* Insert last in queue. */ 1260 /* Insert last in queue. */
1261 mutex_enter(&sc->sc_lock); 1261 mutex_enter(&sc->sc_lock);
1262 err = usb_insert_transfer(xfer); 1262 err = usb_insert_transfer(xfer);
1263 mutex_exit(&sc->sc_lock); 1263 mutex_exit(&sc->sc_lock);
1264 if (err) 1264 if (err)
1265 return (err); 1265 return err;
1266 1266
1267 /* Pipe isn't running, start first */ 1267 /* Pipe isn't running, start first */
1268 return (dwc_otg_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); 1268 return dwc_otg_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1269} 1269}
1270 1270
1271Static usbd_status 1271Static usbd_status
1272dwc_otg_device_ctrl_start(usbd_xfer_handle xfer) 1272dwc_otg_device_ctrl_start(usbd_xfer_handle xfer)
1273{ 1273{
1274 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private; 1274 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private;
1275 1275
1276 DPRINTF("\n"); 1276 DPRINTF("\n");
1277 1277
1278 mutex_enter(&sc->sc_lock); 1278 mutex_enter(&sc->sc_lock);
1279 xfer->status = USBD_IN_PROGRESS; 1279 xfer->status = USBD_IN_PROGRESS;
1280 dwc_otg_xfer_start(xfer); 1280 dwc_otg_xfer_start(xfer);
1281 mutex_exit(&sc->sc_lock); 1281 mutex_exit(&sc->sc_lock);
@@ -1336,27 +1336,27 @@ dwc_otg_device_bulk_transfer(usbd_xfer_h @@ -1336,27 +1336,27 @@ dwc_otg_device_bulk_transfer(usbd_xfer_h
1336#endif 1336#endif
1337 1337
1338 dwc_otg_xfer_setup(xfer); 1338 dwc_otg_xfer_setup(xfer);
1339 dwc_otg_setup_bulk_chain(xfer); 1339 dwc_otg_setup_bulk_chain(xfer);
1340 1340
1341 /* Insert last in queue. */ 1341 /* Insert last in queue. */
1342 mutex_enter(&sc->sc_lock); 1342 mutex_enter(&sc->sc_lock);
1343 err = usb_insert_transfer(xfer); 1343 err = usb_insert_transfer(xfer);
1344 mutex_exit(&sc->sc_lock); 1344 mutex_exit(&sc->sc_lock);
1345 if (err) 1345 if (err)
1346 return err; 1346 return err;
1347 1347
1348 /* Pipe isn't running, start first */ 1348 /* Pipe isn't running, start first */
1349 return (dwc_otg_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); 1349 return dwc_otg_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1350} 1350}
1351 1351
1352Static usbd_status 1352Static usbd_status
1353dwc_otg_device_bulk_start(usbd_xfer_handle xfer) 1353dwc_otg_device_bulk_start(usbd_xfer_handle xfer)
1354{ 1354{
1355 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private; 1355 struct dwc_otg_softc *sc = xfer->pipe->device->bus->hci_private;
1356 1356
1357 DPRINTF("xfer=%p\n", xfer); 1357 DPRINTF("xfer=%p\n", xfer);
1358 1358
1359 mutex_enter(&sc->sc_lock); 1359 mutex_enter(&sc->sc_lock);
1360 xfer->status = USBD_IN_PROGRESS; 1360 xfer->status = USBD_IN_PROGRESS;
1361 dwc_otg_xfer_start(xfer); 1361 dwc_otg_xfer_start(xfer);
1362 mutex_exit(&sc->sc_lock); 1362 mutex_exit(&sc->sc_lock);
@@ -1413,27 +1413,27 @@ dwc_otg_device_intr_transfer(usbd_xfer_h @@ -1413,27 +1413,27 @@ dwc_otg_device_intr_transfer(usbd_xfer_h
1413 DPRINTF("\n"); 1413 DPRINTF("\n");
1414 1414
1415 dwc_otg_xfer_setup(xfer); 1415 dwc_otg_xfer_setup(xfer);
1416 dwc_otg_setup_intr_chain(xfer); 1416 dwc_otg_setup_intr_chain(xfer);
1417 1417
1418 /* Insert last in queue. */ 1418 /* Insert last in queue. */
1419 mutex_enter(&sc->sc_lock); 1419 mutex_enter(&sc->sc_lock);
1420 err = usb_insert_transfer(xfer); 1420 err = usb_insert_transfer(xfer);
1421 mutex_exit(&sc->sc_lock); 1421 mutex_exit(&sc->sc_lock);
1422 if (err) 1422 if (err)
1423 return err; 1423 return err;
1424 1424
1425 /* Pipe isn't running, start first */ 1425 /* Pipe isn't running, start first */
1426 return (dwc_otg_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); 1426 return dwc_otg_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1427} 1427}
1428 1428
1429Static usbd_status 1429Static usbd_status
1430dwc_otg_device_intr_start(usbd_xfer_handle xfer) 1430dwc_otg_device_intr_start(usbd_xfer_handle xfer)
1431{ 1431{
1432 struct dwc_otg_pipe *dpipe = (struct dwc_otg_pipe *)xfer->pipe; 1432 struct dwc_otg_pipe *dpipe = (struct dwc_otg_pipe *)xfer->pipe;
1433 usbd_device_handle dev = dpipe->pipe.device; 1433 usbd_device_handle dev = dpipe->pipe.device;
1434 struct dwc_otg_softc *sc = dev->bus->hci_private; 1434 struct dwc_otg_softc *sc = dev->bus->hci_private;
1435 1435
1436 DPRINTF("\n"); 1436 DPRINTF("\n");
1437 1437
1438 mutex_enter(&sc->sc_lock); 1438 mutex_enter(&sc->sc_lock);
1439 xfer->status = USBD_IN_PROGRESS; 1439 xfer->status = USBD_IN_PROGRESS;
@@ -1507,27 +1507,27 @@ dwc_otg_device_isoc_transfer(usbd_xfer_h @@ -1507,27 +1507,27 @@ dwc_otg_device_isoc_transfer(usbd_xfer_h
1507 usbd_status err; 1507 usbd_status err;
1508 1508
1509 DPRINTF("\n"); 1509 DPRINTF("\n");
1510 panic("not yet\n"); 1510 panic("not yet\n");
1511 1511
1512 /* Insert last in queue. */ 1512 /* Insert last in queue. */
1513 mutex_enter(&sc->sc_lock); 1513 mutex_enter(&sc->sc_lock);
1514 err = usb_insert_transfer(xfer); 1514 err = usb_insert_transfer(xfer);
1515 mutex_exit(&sc->sc_lock); 1515 mutex_exit(&sc->sc_lock);
1516 if (err) 1516 if (err)
1517 return err; 1517 return err;
1518 1518
1519 /* Pipe isn't running, start first */ 1519 /* Pipe isn't running, start first */
1520 return (dwc_otg_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue))); 1520 return dwc_otg_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1521} 1521}
1522 1522
1523#if 0 1523#if 0
1524void 1524void
1525dwc_otg_device_isoc_enter(usbd_xfer_handle xfer) 1525dwc_otg_device_isoc_enter(usbd_xfer_handle xfer)
1526{ 1526{
1527 struct dwc_otg_pipe *dpipe = (struct dwc_otg_pipe *)xfer->pipe; 1527 struct dwc_otg_pipe *dpipe = (struct dwc_otg_pipe *)xfer->pipe;
1528 usbd_device_handle dev = dpipe->pipe.device; 1528 usbd_device_handle dev = dpipe->pipe.device;
1529 struct dwc_otg_softc *sc = dev->bus->hci_private; 1529 struct dwc_otg_softc *sc = dev->bus->hci_private;
1530 1530
1531 DPRINTF("\n"); 1531 DPRINTF("\n");
1532 1532
1533 sc = sc; 1533 sc = sc;
@@ -2182,31 +2182,31 @@ dwc_otg_host_channel_wait(struct dwc_otg @@ -2182,31 +2182,31 @@ dwc_otg_host_channel_wait(struct dwc_otg
2182{ 2182{
2183 struct dwc_otg_softc *sc; 2183 struct dwc_otg_softc *sc;
2184 uint8_t x; 2184 uint8_t x;
2185 2185
2186 x = td->channel; 2186 x = td->channel;
2187 2187
2188 DPRINTF("CH=%d\n", x); 2188 DPRINTF("CH=%d\n", x);
2189 2189
2190 /* get pointer to softc */ 2190 /* get pointer to softc */
2191 sc = DWC_OTG_TD2SC(td); 2191 sc = DWC_OTG_TD2SC(td);
2192 2192
2193 if (sc->sc_chan_state[x].wait_sof == 0) { 2193 if (sc->sc_chan_state[x].wait_sof == 0) {
2194 dwc_otg_clear_hcint(sc, x); 2194 dwc_otg_clear_hcint(sc, x);
2195 return (1); /* done */ 2195 return 1; /* done */
2196 } 2196 }
2197 2197
2198 if (x == 0) 2198 if (x == 0)
2199 return (0); /* wait */ 2199 return 0; /* wait */
2200 2200
2201 /* find new disabled channel */ 2201 /* find new disabled channel */
2202 for (x = 1; x != sc->sc_host_ch_max; x++) { 2202 for (x = 1; x != sc->sc_host_ch_max; x++) {
2203 2203
2204 if (sc->sc_chan_state[x].allocated) 2204 if (sc->sc_chan_state[x].allocated)
2205 continue; 2205 continue;
2206 if (sc->sc_chan_state[x].wait_sof != 0) 2206 if (sc->sc_chan_state[x].wait_sof != 0)
2207 continue; 2207 continue;
2208 2208
2209 sc->sc_chan_state[td->channel].allocated = 0; 2209 sc->sc_chan_state[td->channel].allocated = 0;
2210 sc->sc_chan_state[x].allocated = 1; 2210 sc->sc_chan_state[x].allocated = 1;
2211 2211
2212 if (sc->sc_chan_state[td->channel].suspended) { 2212 if (sc->sc_chan_state[td->channel].suspended) {
@@ -2224,42 +2224,42 @@ dwc_otg_host_channel_wait(struct dwc_otg @@ -2224,42 +2224,42 @@ dwc_otg_host_channel_wait(struct dwc_otg
2224 if (sc->sc_last_rx_status != 0 && 2224 if (sc->sc_last_rx_status != 0 &&
2225 GRXSTSRD_CHNUM_GET(sc->sc_last_rx_status) == td->channel) { 2225 GRXSTSRD_CHNUM_GET(sc->sc_last_rx_status) == td->channel) {
2226 /* get rid of message */ 2226 /* get rid of message */
2227 dwc_otg_common_rx_ack(sc); 2227 dwc_otg_common_rx_ack(sc);
2228 } 2228 }
2229 2229
2230 /* move active channel */ 2230 /* move active channel */
2231 sc->sc_active_rx_ep &= ~(1 << td->channel); 2231 sc->sc_active_rx_ep &= ~(1 << td->channel);
2232 sc->sc_active_rx_ep |= (1 << x); 2232 sc->sc_active_rx_ep |= (1 << x);
2233 2233
2234 /* set channel */ 2234 /* set channel */
2235 td->channel = x; 2235 td->channel = x;
2236 2236
2237 return (1); /* new channel allocated */ 2237 return 1; /* new channel allocated */
2238 } 2238 }
2239 return (0); /* wait */ 2239 return 0; /* wait */
2240} 2240}
2241 2241
2242static uint8_t 2242static uint8_t
2243dwc_otg_host_channel_alloc(struct dwc_otg_td *td) 2243dwc_otg_host_channel_alloc(struct dwc_otg_td *td)
2244{ 2244{
2245 struct dwc_otg_softc *sc; 2245 struct dwc_otg_softc *sc;
2246 uint8_t x; 2246 uint8_t x;
2247 uint8_t max_channel; 2247 uint8_t max_channel;
2248 2248
2249 DPRINTFN(9, "\n"); 2249 DPRINTFN(9, "\n");
2250 2250
2251 if (td->channel < DWC_OTG_MAX_CHANNELS) { 2251 if (td->channel < DWC_OTG_MAX_CHANNELS) {
2252 return (0); /* already allocated */ 2252 return 0; /* already allocated */
2253 } 2253 }
2254 2254
2255 /* get pointer to softc */ 2255 /* get pointer to softc */
2256 sc = DWC_OTG_TD2SC(td); 2256 sc = DWC_OTG_TD2SC(td);
2257 2257
2258 if ((td->hcchar & HCCHAR_EPNUM_MASK) == 0) { 2258 if ((td->hcchar & HCCHAR_EPNUM_MASK) == 0) {
2259 max_channel = 1; 2259 max_channel = 1;
2260 x = 0; 2260 x = 0;
2261 } else { 2261 } else {
2262 max_channel = sc->sc_host_ch_max; 2262 max_channel = sc->sc_host_ch_max;
2263 x = 1; 2263 x = 1;
2264 } 2264 }
2265 2265
@@ -2274,29 +2274,29 @@ dwc_otg_host_channel_alloc(struct dwc_ot @@ -2274,29 +2274,29 @@ dwc_otg_host_channel_alloc(struct dwc_ot
2274 2274
2275 /* clear interrupts */ 2275 /* clear interrupts */
2276 dwc_otg_clear_hcint(sc, x); 2276 dwc_otg_clear_hcint(sc, x);
2277 2277
2278 DPRINTF("CH=%d HCCHAR=0x%08x HCSPLT=0x%08x\n", 2278 DPRINTF("CH=%d HCCHAR=0x%08x HCSPLT=0x%08x\n",
2279 x, td->hcchar, td->hcsplt); 2279 x, td->hcchar, td->hcsplt);
2280 2280
2281 /* set active channel */ 2281 /* set active channel */
2282 sc->sc_active_rx_ep |= (1 << x); 2282 sc->sc_active_rx_ep |= (1 << x);
2283 2283
2284 /* set channel */ 2284 /* set channel */
2285 td->channel = x; 2285 td->channel = x;
2286 2286
2287 return (0); /* allocated */ 2287 return 0; /* allocated */
2288 } 2288 }
2289 return (1); /* busy */ 2289 return 1; /* busy */
2290} 2290}
2291 2291
2292static void 2292static void
2293dwc_otg_host_channel_disable(struct dwc_otg_softc *sc, uint8_t x) 2293dwc_otg_host_channel_disable(struct dwc_otg_softc *sc, uint8_t x)
2294{ 2294{
2295 uint32_t hcchar; 2295 uint32_t hcchar;
2296 2296
2297 if (sc->sc_chan_state[x].wait_sof != 0) 2297 if (sc->sc_chan_state[x].wait_sof != 0)
2298 return; 2298 return;
2299 2299
2300 hcchar = DWC_OTG_READ_4(sc, DOTG_HCCHAR(x)); 2300 hcchar = DWC_OTG_READ_4(sc, DOTG_HCCHAR(x));
2301 if (hcchar & (HCCHAR_CHENA | HCCHAR_CHDIS)) { 2301 if (hcchar & (HCCHAR_CHENA | HCCHAR_CHDIS)) {
2302 /* disable channel */ 2302 /* disable channel */
@@ -2341,50 +2341,50 @@ dwc_otg_host_channel_free(struct dwc_otg @@ -2341,50 +2341,50 @@ dwc_otg_host_channel_free(struct dwc_otg
2341 /* clear active channel */ 2341 /* clear active channel */
2342 sc->sc_active_rx_ep &= ~(1 << x); 2342 sc->sc_active_rx_ep &= ~(1 << x);
2343} 2343}
2344 2344
2345static uint8_t 2345static uint8_t
2346dwc_otg_host_setup_tx(struct dwc_otg_td *td) 2346dwc_otg_host_setup_tx(struct dwc_otg_td *td)
2347{ 2347{
2348 usb_device_request_t req __aligned(4); 2348 usb_device_request_t req __aligned(4);
2349 struct dwc_otg_softc *sc; 2349 struct dwc_otg_softc *sc;
2350 uint32_t hcint; 2350 uint32_t hcint;
2351 uint32_t hcchar; 2351 uint32_t hcchar;
2352 2352
2353 if (dwc_otg_host_channel_alloc(td)) 2353 if (dwc_otg_host_channel_alloc(td))
2354 return (1); /* busy */ 2354 return 1; /* busy */
2355 2355
2356 /* get pointer to softc */ 2356 /* get pointer to softc */
2357 sc = DWC_OTG_TD2SC(td); 2357 sc = DWC_OTG_TD2SC(td);
2358 2358
2359 hcint = sc->sc_chan_state[td->channel].hcint; 2359 hcint = sc->sc_chan_state[td->channel].hcint;
2360 2360
2361 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n", 2361 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n",
2362 td->channel, td->state, hcint, 2362 td->channel, td->state, hcint,
2363 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)), 2363 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)),
2364 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel))); 2364 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel)));
2365 2365
2366 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2366 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2367 /* give success bits priority over failure bits */ 2367 /* give success bits priority over failure bits */
2368 } else if (hcint & HCINT_STALL) { 2368 } else if (hcint & HCINT_STALL) {
2369 DPRINTF("CH=%d STALL\n", td->channel); 2369 DPRINTF("CH=%d STALL\n", td->channel);
2370 td->error_stall = 1; 2370 td->error_stall = 1;
2371 td->error_any = 1; 2371 td->error_any = 1;
2372 return (0); /* complete */ 2372 return 0; /* complete */
2373 } else if (hcint & HCINT_ERRORS) { 2373 } else if (hcint & HCINT_ERRORS) {
2374 td->errcnt++; 2374 td->errcnt++;
2375 if (td->hcsplt != 0 || td->errcnt >= 3) { 2375 if (td->hcsplt != 0 || td->errcnt >= 3) {
2376 td->error_any = 1; 2376 td->error_any = 1;
2377 return (0); /* complete */ 2377 return 0; /* complete */
2378 } 2378 }
2379 } 2379 }
2380 2380
2381 /* channel must be disabled before we can complete the transfer */ 2381 /* channel must be disabled before we can complete the transfer */
2382 2382
2383 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2383 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2384 2384
2385 dwc_otg_host_channel_disable(sc, td->channel); 2385 dwc_otg_host_channel_disable(sc, td->channel);
2386 2386
2387 if (!(hcint & HCINT_ERRORS)) 2387 if (!(hcint & HCINT_ERRORS))
2388 td->errcnt = 0; 2388 td->errcnt = 0;
2389 } 2389 }
2390 2390
@@ -2395,27 +2395,27 @@ dwc_otg_host_setup_tx(struct dwc_otg_td  @@ -2395,27 +2395,27 @@ dwc_otg_host_setup_tx(struct dwc_otg_td
2395 case DWC_CHAN_ST_WAIT_ANE: 2395 case DWC_CHAN_ST_WAIT_ANE:
2396 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) { 2396 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) {
2397 if (!dwc_otg_host_channel_wait(td)) 2397 if (!dwc_otg_host_channel_wait(td))
2398 break; 2398 break;
2399 td->did_nak = 1; 2399 td->did_nak = 1;
2400 goto send_pkt; 2400 goto send_pkt;
2401 } 2401 }
2402 if (hcint & (HCINT_ACK | HCINT_NYET)) { 2402 if (hcint & (HCINT_ACK | HCINT_NYET)) {
2403 if (!dwc_otg_host_channel_wait(td)) 2403 if (!dwc_otg_host_channel_wait(td))
2404 break; 2404 break;
2405 td->offset += td->tx_bytes; 2405 td->offset += td->tx_bytes;
2406 td->remainder -= td->tx_bytes; 2406 td->remainder -= td->tx_bytes;
2407 td->toggle = 1; 2407 td->toggle = 1;
2408 return (0); /* complete */ 2408 return 0; /* complete */
2409 } 2409 }
2410 break; 2410 break;
2411 case DWC_CHAN_ST_WAIT_S_ANE: 2411 case DWC_CHAN_ST_WAIT_S_ANE:
2412 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) { 2412 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) {
2413 if (!dwc_otg_host_channel_wait(td)) 2413 if (!dwc_otg_host_channel_wait(td))
2414 break; 2414 break;
2415 td->did_nak = 1; 2415 td->did_nak = 1;
2416 goto send_pkt; 2416 goto send_pkt;
2417 } 2417 }
2418 if (hcint & (HCINT_ACK | HCINT_NYET)) { 2418 if (hcint & (HCINT_ACK | HCINT_NYET)) {
2419 if (!dwc_otg_host_channel_wait(td)) 2419 if (!dwc_otg_host_channel_wait(td))
2420 break; 2420 break;
2421 goto send_cpkt; 2421 goto send_cpkt;
@@ -2429,55 +2429,55 @@ dwc_otg_host_setup_tx(struct dwc_otg_td  @@ -2429,55 +2429,55 @@ dwc_otg_host_setup_tx(struct dwc_otg_td
2429 } 2429 }
2430 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) { 2430 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) {
2431 if (!dwc_otg_host_channel_wait(td)) 2431 if (!dwc_otg_host_channel_wait(td))
2432 break; 2432 break;
2433 td->did_nak = 1; 2433 td->did_nak = 1;
2434 goto send_pkt; 2434 goto send_pkt;
2435 } 2435 }
2436 if (hcint & HCINT_ACK) { 2436 if (hcint & HCINT_ACK) {
2437 if (!dwc_otg_host_channel_wait(td)) 2437 if (!dwc_otg_host_channel_wait(td))
2438 break; 2438 break;
2439 td->offset += td->tx_bytes; 2439 td->offset += td->tx_bytes;
2440 td->remainder -= td->tx_bytes; 2440 td->remainder -= td->tx_bytes;
2441 td->toggle = 1; 2441 td->toggle = 1;
2442 return (0); /* complete */ 2442 return 0; /* complete */
2443 } 2443 }
2444 break; 2444 break;
2445 case DWC_CHAN_ST_TX_PKT_SYNC: 2445 case DWC_CHAN_ST_TX_PKT_SYNC:
2446 goto send_pkt_sync; 2446 goto send_pkt_sync;
2447 default: 2447 default:
2448 break; 2448 break;
2449 } 2449 }
2450 return (1); /* busy */ 2450 return 1; /* busy */
2451 2451
2452send_pkt: 2452send_pkt:
2453 if (sizeof(req) != td->remainder) { 2453 if (sizeof(req) != td->remainder) {
2454 td->error_any = 1; 2454 td->error_any = 1;
2455 return (0); /* complete */ 2455 return 0; /* complete */
2456 } 2456 }
2457 2457
2458send_pkt_sync: 2458send_pkt_sync:
2459 if (td->hcsplt != 0) { 2459 if (td->hcsplt != 0) {
2460 uint32_t count; 2460 uint32_t count;
2461 2461
2462 count = DWC_OTG_READ_4(sc, DOTG_HFNUM) & 7; 2462 count = DWC_OTG_READ_4(sc, DOTG_HFNUM) & 7;
2463 /* check for not first microframe */ 2463 /* check for not first microframe */
2464 if (count != 0) { 2464 if (count != 0) {
2465 /* enable SOF interrupt */ 2465 /* enable SOF interrupt */
2466 dwc_otg_enable_sof_irq(sc); 2466 dwc_otg_enable_sof_irq(sc);
2467 /* set state */ 2467 /* set state */
2468 td->state = DWC_CHAN_ST_TX_PKT_SYNC; 2468 td->state = DWC_CHAN_ST_TX_PKT_SYNC;
2469 dwc_otg_host_channel_free(td); 2469 dwc_otg_host_channel_free(td);
2470 return (1); /* busy */ 2470 return 1; /* busy */
2471 } 2471 }
2472 2472
2473 td->hcsplt &= ~HCSPLT_COMPSPLT; 2473 td->hcsplt &= ~HCSPLT_COMPSPLT;
2474 td->state = DWC_CHAN_ST_WAIT_S_ANE; 2474 td->state = DWC_CHAN_ST_WAIT_S_ANE;
2475 } else { 2475 } else {
2476 td->state = DWC_CHAN_ST_WAIT_ANE; 2476 td->state = DWC_CHAN_ST_WAIT_ANE;
2477 } 2477 }
2478 2478
2479 /* XXX Why ? */ 2479 /* XXX Why ? */
2480 usbd_copy_out(td->buf, 0, &req, sizeof(req)); 2480 usbd_copy_out(td->buf, 0, &req, sizeof(req));
2481 2481
2482 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel), 2482 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel),
2483 (sizeof(req) << HCTSIZ_XFERSIZE_SHIFT) | 2483 (sizeof(req) << HCTSIZ_XFERSIZE_SHIFT) |
@@ -2490,45 +2490,45 @@ send_pkt_sync: @@ -2490,45 +2490,45 @@ send_pkt_sync:
2490 hcchar &= ~HCCHAR_EPDIR_IN; 2490 hcchar &= ~HCCHAR_EPDIR_IN;
2491 2491
2492 /* must enable channel before writing data to FIFO */ 2492 /* must enable channel before writing data to FIFO */
2493 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar); 2493 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar);
2494 2494
2495 /* transfer data into FIFO */ 2495 /* transfer data into FIFO */
2496 bus_space_write_region_4(sc->sc_iot, sc->sc_ioh, 2496 bus_space_write_region_4(sc->sc_iot, sc->sc_ioh,
2497 DOTG_DFIFO(td->channel), (uint32_t *)&req, sizeof(req) / 4); 2497 DOTG_DFIFO(td->channel), (uint32_t *)&req, sizeof(req) / 4);
2498 2498
2499 /* store number of bytes transmitted */ 2499 /* store number of bytes transmitted */
2500 td->tx_bytes = sizeof(req); 2500 td->tx_bytes = sizeof(req);
2501 2501
2502 2502
2503 return (1); /* busy */ 2503 return 1; /* busy */
2504 2504
2505send_cpkt: 2505send_cpkt:
2506 2506
2507 td->hcsplt |= HCSPLT_COMPSPLT; 2507 td->hcsplt |= HCSPLT_COMPSPLT;
2508 td->state = DWC_CHAN_ST_WAIT_C_ANE; 2508 td->state = DWC_CHAN_ST_WAIT_C_ANE;
2509 2509
2510 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel), 2510 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel),
2511 (HCTSIZ_PID_SETUP << HCTSIZ_PID_SHIFT)); 2511 (HCTSIZ_PID_SETUP << HCTSIZ_PID_SHIFT));
2512 2512
2513 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt); 2513 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt);
2514 2514
2515 hcchar = td->hcchar; 2515 hcchar = td->hcchar;
2516 hcchar &= ~HCCHAR_EPDIR_IN; 2516 hcchar &= ~HCCHAR_EPDIR_IN;
2517 2517
2518 /* must enable channel before writing data to FIFO */ 2518 /* must enable channel before writing data to FIFO */
2519 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar); 2519 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar);
2520 2520
2521 return (1); /* busy */ 2521 return 1; /* busy */
2522} 2522}
2523 2523
2524static uint8_t 2524static uint8_t
2525dwc_otg_host_rate_check(struct dwc_otg_td *td) 2525dwc_otg_host_rate_check(struct dwc_otg_td *td)
2526{ 2526{
2527 struct dwc_otg_softc *sc; 2527 struct dwc_otg_softc *sc;
2528 uint8_t ep_type; 2528 uint8_t ep_type;
2529 2529
2530 /* get pointer to softc */ 2530 /* get pointer to softc */
2531 sc = DWC_OTG_TD2SC(td); 2531 sc = DWC_OTG_TD2SC(td);
2532 2532
2533 ep_type = ((td->hcchar & 2533 ep_type = ((td->hcchar &
2534 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT); 2534 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT);
@@ -2549,71 +2549,71 @@ dwc_otg_host_rate_check(struct dwc_otg_t @@ -2549,71 +2549,71 @@ dwc_otg_host_rate_check(struct dwc_otg_t
2549 if (delta >= 128) 2549 if (delta >= 128)
2550 goto busy; 2550 goto busy;
2551 td->tmr_val = sc->sc_tmr_val + td->tmr_res; 2551 td->tmr_val = sc->sc_tmr_val + td->tmr_res;
2552 } else if (td->did_nak != 0) { 2552 } else if (td->did_nak != 0) {
2553 goto busy; 2553 goto busy;
2554 } 2554 }
2555 2555
2556 if (ep_type == UE_ISOCHRONOUS) { 2556 if (ep_type == UE_ISOCHRONOUS) {
2557 td->toggle = 0; 2557 td->toggle = 0;
2558 } else if (td->set_toggle) { 2558 } else if (td->set_toggle) {
2559 td->set_toggle = 0; 2559 td->set_toggle = 0;
2560 td->toggle = 1; 2560 td->toggle = 1;
2561 } 2561 }
2562 return (0); 2562 return 0;
2563busy: 2563busy:
2564 return (1); 2564 return 1;
2565} 2565}
2566 2566
2567static uint8_t 2567static uint8_t
2568dwc_otg_host_data_rx(struct dwc_otg_td *td) 2568dwc_otg_host_data_rx(struct dwc_otg_td *td)
2569{ 2569{
2570 struct dwc_otg_softc *sc; 2570 struct dwc_otg_softc *sc;
2571 uint32_t hcint; 2571 uint32_t hcint;
2572 uint32_t hcchar; 2572 uint32_t hcchar;
2573 uint32_t count; 2573 uint32_t count;
2574 uint8_t ep_type; 2574 uint8_t ep_type;
2575 2575
2576 if (dwc_otg_host_channel_alloc(td)) 2576 if (dwc_otg_host_channel_alloc(td))
2577 return (1); /* busy */ 2577 return 1; /* busy */
2578 2578
2579 /* get pointer to softc */ 2579 /* get pointer to softc */
2580 sc = DWC_OTG_TD2SC(td); 2580 sc = DWC_OTG_TD2SC(td);
2581 2581
2582 ep_type = ((td->hcchar & 2582 ep_type = ((td->hcchar &
2583 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT); 2583 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT);
2584 2584
2585 hcint = sc->sc_chan_state[td->channel].hcint; 2585 hcint = sc->sc_chan_state[td->channel].hcint;
2586 2586
2587 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n", 2587 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n",
2588 td->channel, td->state, hcint, 2588 td->channel, td->state, hcint,
2589 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)), 2589 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)),
2590 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel))); 2590 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel)));
2591 2591
2592 /* check interrupt bits */ 2592 /* check interrupt bits */
2593 2593
2594 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2594 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2595 /* give success bits priority over failure bits */ 2595 /* give success bits priority over failure bits */
2596 } else if (hcint & HCINT_STALL) { 2596 } else if (hcint & HCINT_STALL) {
2597 DPRINTF("CH=%d STALL\n", td->channel); 2597 DPRINTF("CH=%d STALL\n", td->channel);
2598 td->error_stall = 1; 2598 td->error_stall = 1;
2599 td->error_any = 1; 2599 td->error_any = 1;
2600 return (0); /* complete */ 2600 return 0; /* complete */
2601 } else if (hcint & HCINT_ERRORS) { 2601 } else if (hcint & HCINT_ERRORS) {
2602 DPRINTF("CH=%d ERROR\n", td->channel); 2602 DPRINTF("CH=%d ERROR\n", td->channel);
2603 td->errcnt++; 2603 td->errcnt++;
2604 if (td->hcsplt != 0 || td->errcnt >= 3) { 2604 if (td->hcsplt != 0 || td->errcnt >= 3) {
2605 td->error_any = 1; 2605 td->error_any = 1;
2606 return (0); /* complete */ 2606 return 0; /* complete */
2607 } 2607 }
2608 } 2608 }
2609 2609
2610 /* channel must be disabled before we can complete the transfer */ 2610 /* channel must be disabled before we can complete the transfer */
2611 2611
2612 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2612 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2613 2613
2614 dwc_otg_host_channel_disable(sc, td->channel); 2614 dwc_otg_host_channel_disable(sc, td->channel);
2615 2615
2616 if (!(hcint & HCINT_ERRORS)) 2616 if (!(hcint & HCINT_ERRORS))
2617 td->errcnt = 0; 2617 td->errcnt = 0;
2618 } 2618 }
2619 2619
@@ -2646,38 +2646,38 @@ dwc_otg_host_data_rx(struct dwc_otg_td * @@ -2646,38 +2646,38 @@ dwc_otg_host_data_rx(struct dwc_otg_td *
2646 2646
2647 /* verify the packet byte count */ 2647 /* verify the packet byte count */
2648 if (count != td->max_packet_size) { 2648 if (count != td->max_packet_size) {
2649 if (count < td->max_packet_size) { 2649 if (count < td->max_packet_size) {
2650 /* we have a short packet */ 2650 /* we have a short packet */
2651 td->short_pkt = 1; 2651 td->short_pkt = 1;
2652 td->got_short = 1; 2652 td->got_short = 1;
2653 } else { 2653 } else {
2654 /* invalid USB packet */ 2654 /* invalid USB packet */
2655 td->error_any = 1; 2655 td->error_any = 1;
2656 2656
2657 /* release FIFO */ 2657 /* release FIFO */
2658 dwc_otg_common_rx_ack(sc); 2658 dwc_otg_common_rx_ack(sc);
2659 return (0); /* we are complete */ 2659 return 0; /* we are complete */
2660 } 2660 }
2661 } 2661 }
2662 2662
2663 /* verify the packet byte count */ 2663 /* verify the packet byte count */
2664 if (count > td->remainder) { 2664 if (count > td->remainder) {
2665 /* invalid USB packet */ 2665 /* invalid USB packet */
2666 td->error_any = 1; 2666 td->error_any = 1;
2667 2667
2668 /* release FIFO */ 2668 /* release FIFO */
2669 dwc_otg_common_rx_ack(sc); 2669 dwc_otg_common_rx_ack(sc);
2670 return (0); /* we are complete */ 2670 return 0; /* we are complete */
2671 } 2671 }
2672 2672
2673 usbd_copy_in(td->buf, td->offset, 2673 usbd_copy_in(td->buf, td->offset,
2674 sc->sc_rx_bounce_buffer, count); 2674 sc->sc_rx_bounce_buffer, count);
2675 td->remainder -= count; 2675 td->remainder -= count;
2676 td->offset += count; 2676 td->offset += count;
2677 td->actlen += count; 2677 td->actlen += count;
2678 hcint |= HCINT_SOFTWARE_ONLY | HCINT_ACK; 2678 hcint |= HCINT_SOFTWARE_ONLY | HCINT_ACK;
2679 sc->sc_chan_state[td->channel].hcint = hcint; 2679 sc->sc_chan_state[td->channel].hcint = hcint;
2680 break; 2680 break;
2681 2681
2682 default: 2682 default:
2683 DPRINTF("OTHER\n"); 2683 DPRINTF("OTHER\n");
@@ -2712,27 +2712,27 @@ check_state: @@ -2712,27 +2712,27 @@ check_state:
2712 break; 2712 break;
2713 goto receive_pkt; 2713 goto receive_pkt;
2714 } 2714 }
2715 } 2715 }
2716 break; 2716 break;
2717 } 2717 }
2718 if (hcint & (HCINT_ACK | HCINT_NYET)) { 2718 if (hcint & (HCINT_ACK | HCINT_NYET)) {
2719 if (!dwc_otg_host_channel_wait(td)) 2719 if (!dwc_otg_host_channel_wait(td))
2720 break; 2720 break;
2721 2721
2722 /* check if we are complete */ 2722 /* check if we are complete */
2723 if ((td->remainder == 0) || (td->got_short != 0)) { 2723 if ((td->remainder == 0) || (td->got_short != 0)) {
2724 if (td->short_pkt) 2724 if (td->short_pkt)
2725 return (0); /* complete */ 2725 return 0; /* complete */
2726 2726
2727 /* 2727 /*
2728 * Else need to receive a zero length 2728 * Else need to receive a zero length
2729 * packet. 2729 * packet.
2730 */ 2730 */
2731 } 2731 }
2732 if (td->hcsplt != 0) 2732 if (td->hcsplt != 0)
2733 goto receive_spkt; 2733 goto receive_spkt;
2734 else 2734 else
2735 goto receive_pkt; 2735 goto receive_pkt;
2736 } 2736 }
2737 break; 2737 break;
2738 2738
@@ -2856,68 +2856,68 @@ receive_spkt_sync: @@ -2856,68 +2856,68 @@ receive_spkt_sync:
2856 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel), 2856 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel),
2857 (td->toggle ? (HCTSIZ_PID_DATA1 << HCTSIZ_PID_SHIFT) : 2857 (td->toggle ? (HCTSIZ_PID_DATA1 << HCTSIZ_PID_SHIFT) :
2858 (HCTSIZ_PID_DATA0 << HCTSIZ_PID_SHIFT))); 2858 (HCTSIZ_PID_DATA0 << HCTSIZ_PID_SHIFT)));
2859 2859
2860 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt); 2860 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt);
2861 2861
2862 hcchar = td->hcchar; 2862 hcchar = td->hcchar;
2863 hcchar |= HCCHAR_EPDIR_IN; 2863 hcchar |= HCCHAR_EPDIR_IN;
2864 2864
2865 /* must enable channel before data can be received */ 2865 /* must enable channel before data can be received */
2866 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar); 2866 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar);
2867 2867
2868busy: 2868busy:
2869 return (1); /* busy */ 2869 return 1; /* busy */
2870} 2870}
2871 2871
2872 2872
2873static uint8_t 2873static uint8_t
2874dwc_otg_host_data_tx(struct dwc_otg_td *td) 2874dwc_otg_host_data_tx(struct dwc_otg_td *td)
2875{ 2875{
2876 struct dwc_otg_softc *sc; 2876 struct dwc_otg_softc *sc;
2877 uint32_t count; 2877 uint32_t count;
2878 uint32_t hcint; 2878 uint32_t hcint;
2879 uint32_t hcchar; 2879 uint32_t hcchar;
2880 uint8_t ep_type; 2880 uint8_t ep_type;
2881 2881
2882 if (dwc_otg_host_channel_alloc(td)) 2882 if (dwc_otg_host_channel_alloc(td))
2883 return (1); /* busy */ 2883 return 1; /* busy */
2884 2884
2885 /* get pointer to softc */ 2885 /* get pointer to softc */
2886 sc = DWC_OTG_TD2SC(td); 2886 sc = DWC_OTG_TD2SC(td);
2887 2887
2888 ep_type = ((td->hcchar & 2888 ep_type = ((td->hcchar &
2889 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT); 2889 HCCHAR_EPTYPE_MASK) >> HCCHAR_EPTYPE_SHIFT);
2890 2890
2891 hcint = sc->sc_chan_state[td->channel].hcint; 2891 hcint = sc->sc_chan_state[td->channel].hcint;
2892 2892
2893 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n", 2893 DPRINTF("CH=%d ST=%d HCINT=0x%08x HCCHAR=0x%08x HCTSIZ=0x%08x\n",
2894 td->channel, td->state, hcint, 2894 td->channel, td->state, hcint,
2895 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)), 2895 DWC_OTG_READ_4(sc, DOTG_HCCHAR(td->channel)),
2896 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel))); 2896 DWC_OTG_READ_4(sc, DOTG_HCTSIZ(td->channel)));
2897 2897
2898 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2898 if (hcint & (HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2899 /* give success bits priority over failure bits */ 2899 /* give success bits priority over failure bits */
2900 } else if (hcint & HCINT_STALL) { 2900 } else if (hcint & HCINT_STALL) {
2901 DPRINTF("CH=%d STALL\n", td->channel); 2901 DPRINTF("CH=%d STALL\n", td->channel);
2902 td->error_stall = 1; 2902 td->error_stall = 1;
2903 td->error_any = 1; 2903 td->error_any = 1;
2904 return (0); /* complete */ 2904 return 0; /* complete */
2905 } else if (hcint & HCINT_ERRORS) { 2905 } else if (hcint & HCINT_ERRORS) {
2906 DPRINTF("CH=%d ERROR\n", td->channel); 2906 DPRINTF("CH=%d ERROR\n", td->channel);
2907 td->errcnt++; 2907 td->errcnt++;
2908 if (td->hcsplt != 0 || td->errcnt >= 3) { 2908 if (td->hcsplt != 0 || td->errcnt >= 3) {
2909 td->error_any = 1; 2909 td->error_any = 1;
2910 return (0); /* complete */ 2910 return 0; /* complete */
2911 } 2911 }
2912 } 2912 }
2913 2913
2914 /* channel must be disabled before we can complete the transfer */ 2914 /* channel must be disabled before we can complete the transfer */
2915 2915
2916 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) { 2916 if (hcint & (HCINT_ERRORS | HCINT_RETRY | HCINT_ACK | HCINT_NYET)) {
2917 2917
2918 dwc_otg_host_channel_disable(sc, td->channel); 2918 dwc_otg_host_channel_disable(sc, td->channel);
2919 2919
2920 if (!(hcint & HCINT_ERRORS)) 2920 if (!(hcint & HCINT_ERRORS))
2921 td->errcnt = 0; 2921 td->errcnt = 0;
2922 } 2922 }
2923 2923
@@ -2934,27 +2934,27 @@ dwc_otg_host_data_tx(struct dwc_otg_td * @@ -2934,27 +2934,27 @@ dwc_otg_host_data_tx(struct dwc_otg_td *
2934 } 2934 }
2935 if (hcint & (HCINT_ACK | HCINT_NYET)) { 2935 if (hcint & (HCINT_ACK | HCINT_NYET)) {
2936 if (!dwc_otg_host_channel_wait(td)) 2936 if (!dwc_otg_host_channel_wait(td))
2937 break; 2937 break;
2938 2938
2939 td->actlen += td->tx_bytes; 2939 td->actlen += td->tx_bytes;
2940 td->offset += td->tx_bytes; 2940 td->offset += td->tx_bytes;
2941 td->remainder -= td->tx_bytes; 2941 td->remainder -= td->tx_bytes;
2942 td->toggle ^= 1; 2942 td->toggle ^= 1;
2943 2943
2944 /* check remainder */ 2944 /* check remainder */
2945 if (td->remainder == 0) { 2945 if (td->remainder == 0) {
2946 if (td->short_pkt) 2946 if (td->short_pkt)
2947 return (0); /* complete */ 2947 return 0; /* complete */
2948 2948
2949 /* 2949 /*
2950 * Else we need to transmit a short 2950 * Else we need to transmit a short
2951 * packet: 2951 * packet:
2952 */ 2952 */
2953 } 2953 }
2954 goto send_pkt; 2954 goto send_pkt;
2955 } 2955 }
2956 break; 2956 break;
2957 case DWC_CHAN_ST_WAIT_S_ANE: 2957 case DWC_CHAN_ST_WAIT_S_ANE:
2958 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) { 2958 if (hcint & (HCINT_RETRY | HCINT_ERRORS)) {
2959 if (!dwc_otg_host_channel_wait(td)) 2959 if (!dwc_otg_host_channel_wait(td))
2960 break; 2960 break;
@@ -2980,27 +2980,27 @@ dwc_otg_host_data_tx(struct dwc_otg_td * @@ -2980,27 +2980,27 @@ dwc_otg_host_data_tx(struct dwc_otg_td *
2980 goto send_pkt; 2980 goto send_pkt;
2981 } 2981 }
2982 if (hcint & HCINT_ACK) { 2982 if (hcint & HCINT_ACK) {
2983 if (!dwc_otg_host_channel_wait(td)) 2983 if (!dwc_otg_host_channel_wait(td))
2984 break; 2984 break;
2985 td->actlen += td->tx_bytes; 2985 td->actlen += td->tx_bytes;
2986 td->offset += td->tx_bytes; 2986 td->offset += td->tx_bytes;
2987 td->remainder -= td->tx_bytes; 2987 td->remainder -= td->tx_bytes;
2988 td->toggle ^= 1; 2988 td->toggle ^= 1;
2989 2989
2990 /* check remainder */ 2990 /* check remainder */
2991 if (td->remainder == 0) { 2991 if (td->remainder == 0) {
2992 if (td->short_pkt) 2992 if (td->short_pkt)
2993 return (0); /* complete */ 2993 return 0; /* complete */
2994 2994
2995 /* else we need to transmit a short packet */ 2995 /* else we need to transmit a short packet */
2996 } 2996 }
2997 goto send_pkt; 2997 goto send_pkt;
2998 } 2998 }
2999 break; 2999 break;
3000 3000
3001 case DWC_CHAN_ST_TX_PKT: 3001 case DWC_CHAN_ST_TX_PKT:
3002 goto send_pkt; 3002 goto send_pkt;
3003 3003
3004 case DWC_CHAN_ST_TX_PKT_SYNC: 3004 case DWC_CHAN_ST_TX_PKT_SYNC:
3005 goto send_pkt_sync; 3005 goto send_pkt_sync;
3006 3006
@@ -3100,27 +3100,27 @@ send_cpkt: @@ -3100,27 +3100,27 @@ send_cpkt:
3100 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel), 3100 DWC_OTG_WRITE_4(sc, DOTG_HCTSIZ(td->channel),
3101 (td->toggle ? (HCTSIZ_PID_DATA1 << HCTSIZ_PID_SHIFT) : 3101 (td->toggle ? (HCTSIZ_PID_DATA1 << HCTSIZ_PID_SHIFT) :
3102 (HCTSIZ_PID_DATA0 << HCTSIZ_PID_SHIFT))); 3102 (HCTSIZ_PID_DATA0 << HCTSIZ_PID_SHIFT)));
3103 3103
3104 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt); 3104 DWC_OTG_WRITE_4(sc, DOTG_HCSPLT(td->channel), td->hcsplt);
3105 3105
3106 hcchar = td->hcchar; 3106 hcchar = td->hcchar;
3107 hcchar &= ~HCCHAR_EPDIR_IN; 3107 hcchar &= ~HCCHAR_EPDIR_IN;
3108 3108
3109 /* must enable channel before writing data to FIFO */ 3109 /* must enable channel before writing data to FIFO */
3110 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar); 3110 DWC_OTG_WRITE_4(sc, DOTG_HCCHAR(td->channel), hcchar);
3111 3111
3112busy: 3112busy:
3113 return (1); /* busy */ 3113 return 1; /* busy */
3114} 3114}
3115 3115
3116uint32_t fifoenters; 3116uint32_t fifoenters;
3117 3117
3118static uint8_t 3118static uint8_t
3119dwc_otg_xfer_do_fifo(usbd_xfer_handle xfer) 3119dwc_otg_xfer_do_fifo(usbd_xfer_handle xfer)
3120{ 3120{
3121 struct dwc_otg_xfer *dxfer = (struct dwc_otg_xfer *)xfer; 3121 struct dwc_otg_xfer *dxfer = (struct dwc_otg_xfer *)xfer;
3122 struct dwc_otg_td *td; 3122 struct dwc_otg_td *td;
3123 uint8_t toggle; 3123 uint8_t toggle;
3124 uint8_t channel; 3124 uint8_t channel;
3125 uint8_t tmr_val; 3125 uint8_t tmr_val;
3126 uint8_t tmr_res; 3126 uint8_t tmr_res;
@@ -3154,32 +3154,32 @@ dwc_otg_xfer_do_fifo(usbd_xfer_handle xf @@ -3154,32 +3154,32 @@ dwc_otg_xfer_do_fifo(usbd_xfer_handle xf
3154 */ 3154 */
3155 tmr_res = td->tmr_res; 3155 tmr_res = td->tmr_res;
3156 tmr_val = td->tmr_val; 3156 tmr_val = td->tmr_val;
3157 toggle = td->toggle; 3157 toggle = td->toggle;
3158 channel = td->channel; 3158 channel = td->channel;
3159 td = td->obj_next; 3159 td = td->obj_next;
3160 3160
3161 dxfer->td_transfer_cache = td; 3161 dxfer->td_transfer_cache = td;
3162 td->toggle = toggle; /* transfer toggle */ 3162 td->toggle = toggle; /* transfer toggle */
3163 td->channel = channel; /* transfer channel */ 3163 td->channel = channel; /* transfer channel */
3164 td->tmr_res = tmr_res; 3164 td->tmr_res = tmr_res;
3165 td->tmr_val = tmr_val; 3165 td->tmr_val = tmr_val;
3166 } 3166 }
3167 return (1); /* not complete */ 3167 return 1; /* not complete */
3168 3168
3169done: 3169done:
3170 /* compute all actual lengths */ 3170 /* compute all actual lengths */
3171 dwc_otg_standard_done(xfer); 3171 dwc_otg_standard_done(xfer);
3172 return (0); /* complete */ 3172 return 0; /* complete */
3173} 3173}
3174 3174
3175Static void 3175Static void
3176dwc_otg_timer_tick(void *_sc) 3176dwc_otg_timer_tick(void *_sc)
3177{ 3177{
3178 struct dwc_otg_softc *sc = _sc; 3178 struct dwc_otg_softc *sc = _sc;
3179 3179
3180 workqueue_enqueue(sc->sc_wq, (struct work *)&sc->sc_timer_work, NULL); 3180 workqueue_enqueue(sc->sc_wq, (struct work *)&sc->sc_timer_work, NULL);
3181} 3181}
3182 3182
3183Static void 3183Static void
3184dwc_otg_timer(struct dwc_otg_softc *sc) 3184dwc_otg_timer(struct dwc_otg_softc *sc)
3185{ 3185{
@@ -4044,27 +4044,27 @@ dwc_otg_standard_done_sub(usbd_xfer_hand @@ -4044,27 +4044,27 @@ dwc_otg_standard_done_sub(usbd_xfer_hand
4044 4044
4045 td = td->obj_next; 4045 td = td->obj_next;
4046 4046
4047 /* this USB frame is complete */ 4047 /* this USB frame is complete */
4048 error = 0; 4048 error = 0;
4049 break; 4049 break;
4050 4050
4051 } while (0); 4051 } while (0);
4052 4052
4053 /* update transfer cache */ 4053 /* update transfer cache */
4054 4054
4055 dxfer->td_transfer_cache = td; 4055 dxfer->td_transfer_cache = td;
4056 4056
4057 return (error); 4057 return error;
4058} 4058}
4059 4059
4060Static void 4060Static void
4061dwc_otg_standard_done(usbd_xfer_handle xfer) 4061dwc_otg_standard_done(usbd_xfer_handle xfer)
4062{ 4062{
4063 struct dwc_otg_xfer *dxfer = DWC_OTG_XFER2DXFER(xfer); 4063 struct dwc_otg_xfer *dxfer = DWC_OTG_XFER2DXFER(xfer);
4064 4064
4065 struct dwc_otg_td *td; 4065 struct dwc_otg_td *td;
4066 usbd_status err = 0; 4066 usbd_status err = 0;
4067 4067
4068 DPRINTFN(13, "xfer=%p endpoint=%p transfer done\n", 4068 DPRINTFN(13, "xfer=%p endpoint=%p transfer done\n",
4069 xfer, xfer->pipe->endpoint); 4069 xfer, xfer->pipe->endpoint);
4070 4070