[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
byteswap in uhci.c and ohci.c (Re: uhci on macppc)
筒井です。
<200003071445.XAA08705@mirage.ceres.dti.ne.jp>の記事において
私は書きました。
> あまり関係ありませんが、 uhci の USB PCI カード買ったので
> NetBSD/macppc で試してみました。
この件いろいろ調べてたんですが、どうも endian とは関係ない
ところでおかしいみたいでまだよくわかってません。
(DEBUG 用コードを除いて byteswap は問題なさそう)
で、 byteswap まわりを調べているうちに LE() なんてのを
使ってるのが耐えられなくなったので htole32()/le32toh()
で置き換えてみました。
ついでに ohci.c も htole32()/le32toh() に置き換えて
みたんですが、こちらは以下の二つで byteswap に問題が
あるような気がします。
(1) ohci_close_pipe() の中の td
(2) ohci_abort_xfer_end() の中の p->physaddr
こちらでは big endian で ohci な実機がないので
確認できないんですが、実際のところどうなんでしょう?
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp
--- ohci.c.orig Fri Mar 10 21:43:18 2000
+++ ohci.c Fri Mar 10 22:25:32 2000
@@ -101,10 +101,13 @@
* The OHCI controller is little endian, so on big endian machines
* the data strored in memory needs to be swapped.
*/
+#if defined(__FreeBSD__)
#if BYTE_ORDER == BIG_ENDIAN
-#define LE(x) (bswap32(x))
+#define htole32(x) (bswap32(x))
+#define le32toh(x) (bswap32(x))
#else
-#define LE(x) (x)
+#define htole32(x) (x)
+#define le32toh(x) (x)
#endif
struct ohci_pipe;
@@ -508,11 +511,11 @@
len -= curlen;
intr = len == 0 ? OHCI_TD_SET_DI(1) : OHCI_TD_NOINTR;
- cur->td.td_flags = LE(tdflags | intr);
- cur->td.td_cbp = LE(dataphys);
+ cur->td.td_flags = htole32(tdflags | intr);
+ cur->td.td_cbp = htole32(dataphys);
cur->nexttd = next;
- cur->td.td_nexttd = LE(next->physaddr);
- cur->td.td_be = LE(dataphys + curlen - 1);
+ cur->td.td_nexttd = htole32(next->physaddr);
+ cur->td.td_be = htole32(dataphys + curlen - 1);
cur->len = curlen;
cur->flags = OHCI_ADD_LEN;
DPRINTFN(10,("ohci_alloc_std_chain: cbp=0x%08x be=0x%08x\n",
@@ -530,11 +533,11 @@
if (next == 0)
goto nomem;
- cur->td.td_flags = LE(tdflags | OHCI_TD_SET_DI(1));
+ cur->td.td_flags = htole32(tdflags | OHCI_TD_SET_DI(1));
cur->td.td_cbp = 0; /* indicate 0 length packet */
cur->nexttd = next;
- cur->td.td_nexttd = LE(next->physaddr);
- cur->td.td_be = LE(dataphys - 1);
+ cur->td.td_nexttd = htole32(next->physaddr);
+ cur->td.td_be = htole32(dataphys - 1);
cur->len = 0;
cur->flags = 0;
cur = next;
@@ -654,7 +657,7 @@
err = USBD_NOMEM;
goto bad1;
}
- sc->sc_ctrl_head->ed.ed_flags |= LE(OHCI_ED_SKIP);
+ sc->sc_ctrl_head->ed.ed_flags |= htole32(OHCI_ED_SKIP);
/* Allocate dummy ED that starts the bulk list. */
sc->sc_bulk_head = ohci_alloc_sed(sc);
@@ -662,7 +665,7 @@
err = USBD_NOMEM;
goto bad2;
}
- sc->sc_bulk_head->ed.ed_flags |= LE(OHCI_ED_SKIP);
+ sc->sc_bulk_head->ed.ed_flags |= htole32(OHCI_ED_SKIP);
/* Allocate dummy ED that starts the isochronous list. */
sc->sc_isoc_head = ohci_alloc_sed(sc);
@@ -670,7 +673,7 @@
err = USBD_NOMEM;
goto bad3;
}
- sc->sc_isoc_head->ed.ed_flags |= LE(OHCI_ED_SKIP);
+ sc->sc_isoc_head->ed.ed_flags |= htole32(OHCI_ED_SKIP);
/* Allocate all the dummy EDs that make up the interrupt tree. */
for (i = 0; i < OHCI_NO_EDS; i++) {
@@ -683,13 +686,13 @@
}
/* All ED fields are set to 0. */
sc->sc_eds[i] = sed;
- sed->ed.ed_flags |= LE(OHCI_ED_SKIP);
+ sed->ed.ed_flags |= htole32(OHCI_ED_SKIP);
if (i != 0)
psed = sc->sc_eds[(i-1) / 2];
else
psed= sc->sc_isoc_head;
sed->next = psed;
- sed->ed.ed_nexted = LE(psed->physaddr);
+ sed->ed.ed_nexted = htole32(psed->physaddr);
}
/*
* Fill HCCA interrupt table. The bit reversal is to get
@@ -697,7 +700,7 @@
*/
for (i = 0; i < OHCI_NO_INTRS; i++)
sc->sc_hcca->hcca_interrupt_table[revbits[i]] =
- LE(sc->sc_eds[OHCI_NO_EDS-OHCI_NO_INTRS+i]->physaddr);
+ htole32(sc->sc_eds[OHCI_NO_EDS-OHCI_NO_INTRS+i]->physaddr);
#ifdef OHCI_DEBUG
if (ohcidebug > 15) {
@@ -960,8 +963,8 @@
OREAD4(sc, OHCI_RH_PORT_STATUS(1)),
OREAD4(sc, OHCI_RH_PORT_STATUS(2))));
DPRINTF((" HCCA: frame_number=0x%04x done_head=0x%08x\n",
- LE(sc->sc_hcca->hcca_frame_number),
- LE(sc->sc_hcca->hcca_done_head)));
+ le32toh(sc->sc_hcca->hcca_frame_number),
+ le32toh(sc->sc_hcca->hcca_done_head)));
}
#endif
@@ -1000,7 +1003,7 @@
}
intrs = 0;
- done = LE(sc->sc_hcca->hcca_done_head);
+ done = le32toh(sc->sc_hcca->hcca_done_head);
if (done != 0) {
if (done & ~OHCI_DONE_INTRS)
intrs = OHCI_WDH;
@@ -1039,9 +1042,9 @@
ohci_soft_td_t *std;
for (ldone = sc->sc_done; ldone != 0;
- ldone = LE(std->td.td_nexttd))
+ ldone = le32toh(std->td.td_nexttd))
std = ohci_hash_find_td(sc, ldone);
- std->td.td_nexttd = LE(done);
+ std->td.td_nexttd = htole32(done);
}
sc->sc_hcca->hcca_done_head = 0;
usb_schedsoftintr(&sc->sc_bus);
@@ -1133,7 +1136,7 @@
DPRINTFN(10,("ohci_process_done: done=0x%08lx\n", (u_long)done));
/* Reverse the done list. */
- for (sdone = NULL; done != 0; done = LE(std->td.td_nexttd)) {
+ for (sdone = NULL; done != 0; done = le32toh(std->td.td_nexttd)) {
std = ohci_hash_find_td(sc, done);
std->dnext = sdone;
sdone = std;
@@ -1158,7 +1161,7 @@
*/
continue;
}
- cc = OHCI_TD_GET_CC(LE(std->td.td_flags));
+ cc = OHCI_TD_GET_CC(le32toh(std->td.td_flags));
usb_untimeout(ohci_timeout, xfer, xfer->timo_handle);
if (xfer->status == USBD_CANCELLED ||
xfer->status == USBD_TIMEOUT) {
@@ -1168,8 +1171,8 @@
} else if (cc == OHCI_CC_NO_ERROR) {
len = std->len;
if (std->td.td_cbp != 0)
- len -= LE(std->td.td_be) -
- LE(std->td.td_cbp) + 1;
+ len -= le32toh(std->td.td_be) -
+ le32toh(std->td.td_cbp) + 1;
if (std->flags & OHCI_ADD_LEN)
xfer->actlen += len;
if (std->flags & OHCI_CALL_DONE) {
@@ -1188,8 +1191,8 @@
(struct ohci_pipe *)xfer->pipe;
DPRINTFN(15,("ohci_process_done: error cc=%d (%s)\n",
- OHCI_TD_GET_CC(LE(std->td.td_flags)),
- ohci_cc_strs[OHCI_TD_GET_CC(LE(std->td.td_flags))]));
+ OHCI_TD_GET_CC(le32toh(std->td.td_flags)),
+ ohci_cc_strs[OHCI_TD_GET_CC(le32toh(std->td.td_flags))]));
/* remove TDs */
for (p = std; p->xfer == xfer; p = n) {
@@ -1198,7 +1201,7 @@
}
/* clear halt */
- opipe->sed->ed.ed_headp = LE(p->physaddr);
+ opipe->sed->ed.ed_headp = htole32(p->physaddr);
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
if (cc == OHCI_CC_STALL)
@@ -1250,22 +1253,23 @@
}
tail->xfer = NULL;
- data->td.td_flags = LE(
+ data->td.td_flags = htole32(
OHCI_TD_IN | OHCI_TD_NOCC |
OHCI_TD_SET_DI(1) | OHCI_TD_TOGGLE_CARRY);
if (xfer->flags & USBD_SHORT_XFER_OK)
- data->td.td_flags |= LE(OHCI_TD_R);
- data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->td.td_flags |= htole32(OHCI_TD_R);
+ data->td.td_cbp = htole32(DMAADDR(&xfer->dmabuf));
data->nexttd = tail;
- data->td.td_nexttd = LE(tail->physaddr);
- data->td.td_be = LE(LE(data->td.td_cbp) + xfer->length - 1);
+ data->td.td_nexttd = htole32(tail->physaddr);
+ data->td.td_be = htole32(le32toh(data->td.td_cbp) +
+ xfer->length - 1);
data->len = xfer->length;
data->xfer = xfer;
data->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
xfer->hcpriv = data;
xfer->actlen = 0;
- sed->ed.ed_tailp = LE(tail->physaddr);
+ sed->ed.ed_tailp = htole32(tail->physaddr);
opipe->tail.td = tail;
}
}
@@ -1421,8 +1425,8 @@
/* Update device address and length since they may have changed. */
/* XXX This only needs to be done once, but it's too early in open. */
- sed->ed.ed_flags = LE(
- (LE(sed->ed.ed_flags) & ~(OHCI_ED_ADDRMASK | OHCI_ED_MAXPMASK)) |
+ sed->ed.ed_flags = htole32(
+ (le32toh(sed->ed.ed_flags) & ~(OHCI_ED_ADDRMASK | OHCI_ED_MAXPMASK)) |
OHCI_ED_SET_FA(addr) |
OHCI_ED_SET_MAXP(UGETW(opipe->pipe.endpoint->edesc->wMaxPacketSize)));
@@ -1433,14 +1437,14 @@
err = USBD_NOMEM;
goto bad3;
}
- data->td.td_flags = LE(
+ data->td.td_flags = htole32(
(isread ? OHCI_TD_IN : OHCI_TD_OUT) | OHCI_TD_NOCC |
OHCI_TD_TOGGLE_1 | OHCI_TD_NOINTR |
(xfer->flags & USBD_SHORT_XFER_OK ? OHCI_TD_R : 0));
- data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->td.td_cbp = htole32(DMAADDR(&xfer->dmabuf));
data->nexttd = stat;
- data->td.td_nexttd = LE(stat->physaddr);
- data->td.td_be = LE(LE(data->td.td_cbp) + len - 1);
+ data->td.td_nexttd = htole32(stat->physaddr);
+ data->td.td_be = htole32(le32toh(data->td.td_cbp) + len - 1);
data->len = len;
data->xfer = xfer;
data->flags = OHCI_ADD_LEN;
@@ -1455,23 +1459,23 @@
memcpy(KERNADDR(&opipe->u.ctl.reqdma), req, sizeof *req);
- setup->td.td_flags = LE(OHCI_TD_SETUP | OHCI_TD_NOCC |
- OHCI_TD_TOGGLE_0 | OHCI_TD_NOINTR);
- setup->td.td_cbp = LE(DMAADDR(&opipe->u.ctl.reqdma));
+ setup->td.td_flags = htole32(OHCI_TD_SETUP | OHCI_TD_NOCC |
+ OHCI_TD_TOGGLE_0 | OHCI_TD_NOINTR);
+ setup->td.td_cbp = htole32(DMAADDR(&opipe->u.ctl.reqdma));
setup->nexttd = next;
- setup->td.td_nexttd = LE(next->physaddr);
- setup->td.td_be = LE(LE(setup->td.td_cbp) + sizeof *req - 1);
+ setup->td.td_nexttd = htole32(next->physaddr);
+ setup->td.td_be = htole32(le32toh(setup->td.td_cbp) + sizeof *req - 1);
setup->len = 0; /* XXX The number of byte we count */
setup->xfer = xfer;
setup->flags = 0;
xfer->hcpriv = setup;
- stat->td.td_flags = LE(
+ stat->td.td_flags = htole32(
(isread ? OHCI_TD_OUT : OHCI_TD_IN) | OHCI_TD_NOCC |
OHCI_TD_TOGGLE_1 | OHCI_TD_SET_DI(1));
stat->td.td_cbp = 0;
stat->nexttd = tail;
- stat->td.td_nexttd = LE(tail->physaddr);
+ stat->td.td_nexttd = htole32(tail->physaddr);
stat->td.td_be = 0;
stat->len = 0;
stat->xfer = xfer;
@@ -1486,7 +1490,7 @@
/* Insert ED in schedule */
s = splusb();
- sed->ed.ed_tailp = LE(tail->physaddr);
+ sed->ed.ed_tailp = htole32(tail->physaddr);
opipe->tail.td = tail;
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
if (xfer->timeout && !sc->sc_bus.use_polling) {
@@ -1527,7 +1531,7 @@
sed->next = head->next;
sed->ed.ed_nexted = head->ed.ed_nexted;
head->next = sed;
- head->ed.ed_nexted = LE(sed->physaddr);
+ head->ed.ed_nexted = htole32(sed->physaddr);
}
/*
@@ -1634,13 +1638,14 @@
DPRINTF(("TD(%p) at %08lx: %b delay=%d ec=%d cc=%d\ncbp=0x%08lx "
"nexttd=0x%08lx be=0x%08lx\n",
std, (u_long)std->physaddr,
- (int)LE(std->td.td_flags),
+ (int)le32toh(std->td.td_flags),
"\20\23R\24OUT\25IN\31TOG1\32SETTOGGLE",
- OHCI_TD_GET_DI(LE(std->td.td_flags)),
- OHCI_TD_GET_EC(LE(std->td.td_flags)),
- OHCI_TD_GET_CC(LE(std->td.td_flags)),
- (u_long)LE(std->td.td_cbp),
- (u_long)LE(std->td.td_nexttd), (u_long)LE(std->td.td_be)));
+ OHCI_TD_GET_DI(le32toh(std->td.td_flags)),
+ OHCI_TD_GET_EC(le32toh(std->td.td_flags)),
+ OHCI_TD_GET_CC(le32toh(std->td.td_flags)),
+ (u_long)le32toh(std->td.td_cbp),
+ (u_long)le32toh(std->td.td_nexttd),
+ (u_long)le32toh(std->td.td_be)));
}
void
@@ -1650,16 +1655,16 @@
DPRINTF(("ED(%p) at 0x%08lx: addr=%d endpt=%d maxp=%d %b\ntailp=0x%08lx "
"headflags=%b headp=0x%08lx nexted=0x%08lx\n",
sed, (u_long)sed->physaddr,
- OHCI_ED_GET_FA(LE(sed->ed.ed_flags)),
- OHCI_ED_GET_EN(LE(sed->ed.ed_flags)),
- OHCI_ED_GET_MAXP(LE(sed->ed.ed_flags)),
- (int)LE(sed->ed.ed_flags),
+ OHCI_ED_GET_FA(le32toh(sed->ed.ed_flags)),
+ OHCI_ED_GET_EN(le32toh(sed->ed.ed_flags)),
+ OHCI_ED_GET_MAXP(le32toh(sed->ed.ed_flags)),
+ (int)le32toh(sed->ed.ed_flags),
"\20\14OUT\15IN\16LOWSPEED\17SKIP\20ISO",
- (u_long)LE(sed->ed.ed_tailp),
- (u_long)LE(sed->ed.ed_headp),
+ (u_long)le32toh(sed->ed.ed_tailp),
+ (u_long)le32toh(sed->ed.ed_headp),
"\20\1HALT\2CARRY",
- (u_long)LE(sed->ed.ed_headp),
- (u_long)LE(sed->ed.ed_nexted)));
+ (u_long)le32toh(sed->ed.ed_headp),
+ (u_long)le32toh(sed->ed.ed_nexted)));
}
#endif
@@ -1707,7 +1712,7 @@
goto bad1;
}
opipe->tail.itd = sitd;
- tdphys = LE(sitd->physaddr);
+ tdphys = sitd->physaddr;
fmt = OHCI_ED_FORMAT_ISO;
} else {
std = ohci_alloc_std(sc);
@@ -1716,16 +1721,16 @@
goto bad1;
}
opipe->tail.td = std;
- tdphys = LE(std->physaddr);
+ tdphys = std->physaddr;
fmt = OHCI_ED_FORMAT_GEN;
}
- sed->ed.ed_flags = LE(
+ sed->ed.ed_flags = htole32(
OHCI_ED_SET_FA(addr) |
OHCI_ED_SET_EN(ed->bEndpointAddress) |
OHCI_ED_DIR_TD |
(dev->lowspeed ? OHCI_ED_SPEED : 0) | fmt |
OHCI_ED_SET_MAXP(UGETW(ed->wMaxPacketSize)));
- sed->ed.ed_headp = sed->ed.ed_tailp = tdphys;
+ sed->ed.ed_headp = sed->ed.ed_tailp = htole32(tdphys);
switch (xfertype) {
case UE_CONTROL:
@@ -1783,10 +1788,10 @@
s = splusb();
#ifdef DIAGNOSTIC
- sed->ed.ed_flags |= LE(OHCI_ED_SKIP);
- if ((sed->ed.ed_tailp & LE(OHCI_HEADMASK)) !=
- (sed->ed.ed_headp & LE(OHCI_HEADMASK))) {
- ohci_physaddr_t td = sed->ed.ed_headp;
+ sed->ed.ed_flags |= htole32(OHCI_ED_SKIP);
+ if ((le32toh(sed->ed.ed_tailp) & OHCI_HEADMASK) !=
+ (le32toh(sed->ed.ed_headp) & OHCI_HEADMASK)) {
+ ohci_physaddr_t td = le32toh(sed->ed.ed_headp);
ohci_soft_td_t *std;
for (std = LIST_FIRST(&sc->sc_hash_tds[HASH(td)]);
std != NULL;
@@ -1795,11 +1800,12 @@
break;
printf("ohci_close_pipe: pipe not empty sed=%p hd=0x%x "
"tl=0x%x pipe=%p, std=%p\n", sed,
- (int)LE(sed->ed.ed_headp), (int)LE(sed->ed.ed_tailp),
+ (int)le32toh(sed->ed.ed_headp),
+ (int)le32toh(sed->ed.ed_tailp),
pipe, std);
usb_delay_ms(&sc->sc_bus, 2);
- if ((sed->ed.ed_tailp & LE(OHCI_HEADMASK)) !=
- (sed->ed.ed_headp & LE(OHCI_HEADMASK)))
+ if ((le32toh(sed->ed.ed_tailp) & OHCI_HEADMASK) !=
+ (le32toh(sed->ed.ed_headp) & OHCI_HEADMASK))
printf("ohci_close_pipe: pipe still not empty\n");
}
#endif
@@ -1834,7 +1840,7 @@
sed = opipe->sed;
DPRINTFN(1,("ohci_abort_xfer: stop ed=%p\n", sed));
- sed->ed.ed_flags |= LE(OHCI_ED_SKIP); /* force hardware skip */
+ sed->ed.ed_flags |= htole32(OHCI_ED_SKIP); /* force hardware skip */
#if 1
if (xfer->device->bus->intr_context) {
@@ -1881,9 +1887,9 @@
sed = opipe->sed;
DPRINTFN(2,("ohci_abort_xfer: set hd=%x, tl=%x\n",
- (int)LE(p->physaddr), (int)LE(sed->ed.ed_tailp)));
- sed->ed.ed_headp = p->physaddr; /* unlink TDs */
- sed->ed.ed_flags &= LE(~OHCI_ED_SKIP); /* remove hardware skip */
+ (int)p->physaddr, (int)le32toh(sed->ed.ed_tailp)));
+ sed->ed.ed_headp = htole32(p->physaddr); /* unlink TDs */
+ sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP); /* remove hardware skip */
usb_transfer_complete(xfer);
@@ -2431,7 +2437,7 @@
{
struct ohci_pipe *opipe = (struct ohci_pipe *)pipe;
- opipe->sed->ed.ed_headp &= LE(~OHCI_TOGGLECARRY);
+ opipe->sed->ed.ed_headp &= htole32(~OHCI_TOGGLECARRY);
}
static void
@@ -2489,8 +2495,8 @@
opipe->u.bulk.length = len;
/* Update device address */
- sed->ed.ed_flags = LE(
- (LE(sed->ed.ed_flags) & ~OHCI_ED_ADDRMASK) |
+ sed->ed.ed_flags = htole32(
+ (le32toh(sed->ed.ed_flags) & ~OHCI_ED_ADDRMASK) |
OHCI_ED_SET_FA(addr));
/* Allocate a chain of new TDs (including a new tail). */
@@ -2505,8 +2511,10 @@
DPRINTFN(4,("ohci_device_bulk_start: ed_flags=0x%08x td_flags=0x%08x "
"td_cbp=0x%08x td_be=0x%08x\n",
- (int)LE(sed->ed.ed_flags), (int)LE(data->td.td_flags),
- (int)LE(data->td.td_cbp), (int)LE(data->td.td_be)));
+ (int)le32toh(sed->ed.ed_flags),
+ (int)le32toh(data->td.td_flags),
+ (int)le32toh(data->td.td_cbp),
+ (int)le32toh(data->td.td_be)));
#ifdef OHCI_DEBUG
if (ohcidebug > 4) {
@@ -2520,9 +2528,9 @@
for (tdp = data; tdp != tail; tdp = tdp->nexttd) {
tdp->xfer = xfer;
}
- sed->ed.ed_tailp = LE(tail->physaddr);
+ sed->ed.ed_tailp = htole32(tail->physaddr);
opipe->tail.td = tail;
- sed->ed.ed_flags &= LE(~OHCI_ED_SKIP);
+ sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_BLF);
if (xfer->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, xfer,
@@ -2614,15 +2622,15 @@
return (USBD_NOMEM);
tail->xfer = NULL;
- data->td.td_flags = LE(
+ data->td.td_flags = htole32(
OHCI_TD_IN | OHCI_TD_NOCC |
OHCI_TD_SET_DI(1) | OHCI_TD_TOGGLE_CARRY);
if (xfer->flags & USBD_SHORT_XFER_OK)
- data->td.td_flags |= LE(OHCI_TD_R);
- data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->td.td_flags |= htole32(OHCI_TD_R);
+ data->td.td_cbp = htole32(DMAADDR(&xfer->dmabuf));
data->nexttd = tail;
- data->td.td_nexttd = LE(tail->physaddr);
- data->td.td_be = LE(LE(data->td.td_cbp) + len - 1);
+ data->td.td_nexttd = htole32(tail->physaddr);
+ data->td.td_be = htole32(le32toh(data->td.td_cbp) + len - 1);
data->len = len;
data->xfer = xfer;
data->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
@@ -2638,9 +2646,9 @@
/* Insert ED in schedule */
s = splusb();
- sed->ed.ed_tailp = LE(tail->physaddr);
+ sed->ed.ed_tailp = htole32(tail->physaddr);
opipe->tail.td = tail;
- sed->ed.ed_flags &= LE(~OHCI_ED_SKIP);
+ sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);
#if 0
/*
@@ -2689,9 +2697,9 @@
DPRINTFN(1,("ohci_device_intr_close: pipe=%p nslots=%d pos=%d\n",
pipe, nslots, pos));
s = splusb();
- sed->ed.ed_flags |= LE(OHCI_ED_SKIP);
- if ((sed->ed.ed_tailp & LE(OHCI_HEADMASK)) !=
- (sed->ed.ed_headp & LE(OHCI_HEADMASK)))
+ sed->ed.ed_flags |= htole32(OHCI_ED_SKIP);
+ if ((le32toh(sed->ed.ed_tailp) & OHCI_HEADMASK) !=
+ (le32toh(sed->ed.ed_headp) & OHCI_HEADMASK))
usb_delay_ms(&sc->sc_bus, 2);
for (p = sc->sc_eds[pos]; p && p->next != sed; p = p->next)
@@ -2764,7 +2772,7 @@
sed->next = hsed->next;
sed->ed.ed_nexted = hsed->ed.ed_nexted;
hsed->next = sed;
- hsed->ed.ed_nexted = LE(sed->physaddr);
+ hsed->ed.ed_nexted = htole32(sed->physaddr);
splx(s);
for (j = 0; j < nslots; j++)
@@ -2823,7 +2831,7 @@
s = splusb();
sitd = opipe->tail.itd;
buf = DMAADDR(&xfer->dmabuf);
- sitd->itd.itd_bp0 = LE(buf & OHCI_ITD_PAGE_MASK);
+ sitd->itd.itd_bp0 = htole32(buf & OHCI_ITD_PAGE_MASK);
nframes = xfer->nframes;
offs = buf & OHCI_ITD_OFFSET_MASK;
for (i = ncur = 0; i < nframes; i++, ncur++) {
@@ -2836,14 +2844,16 @@
return;
}
sitd->nextitd = nsitd;
- sitd->itd.itd_nextitd = LE(nsitd->physaddr);
- sitd->itd.itd_flags = LE(
+ sitd->itd.itd_nextitd = htole32(nsitd->physaddr);
+ sitd->itd.itd_flags = htole32(
OHCI_ITD_NOCC |
OHCI_ITD_SET_SF(iso->next) |
OHCI_ITD_NOINTR |
OHCI_ITD_SET_FC(OHCI_ITD_NOFFSET));
- sitd->itd.itd_be = LE(LE(sitd->itd.itd_bp0) + offs - 1);
- nsitd->itd.itd_bp0 = LE((buf + offs) & OHCI_ITD_PAGE_MASK);
+ sitd->itd.itd_be = htole32(
+ le32toh(sitd->itd.itd_bp0) + offs - 1);
+ nsitd->itd.itd_bp0 = htole32(
+ (buf + offs) & OHCI_ITD_PAGE_MASK);
sitd = nsitd;
iso->next = iso->next + ncur;
ncur = 0;
@@ -2861,17 +2871,17 @@
return;
}
sitd->nextitd = nsitd;
- sitd->itd.itd_nextitd = LE(nsitd->physaddr);
- sitd->itd.itd_flags = LE(
+ sitd->itd.itd_nextitd = htole32(nsitd->physaddr);
+ sitd->itd.itd_flags = le32toh(
OHCI_ITD_NOCC |
OHCI_ITD_SET_SF(iso->next) |
OHCI_ITD_SET_DI(0) |
OHCI_ITD_SET_FC(ncur));
- sitd->itd.itd_be = LE(LE(sitd->itd.itd_bp0) + offs - 1);
+ sitd->itd.itd_be = htole32(le32toh(sitd->itd.itd_bp0) + offs - 1);
iso->next = iso->next + ncur;
opipe->tail.itd = nsitd;
- sed->ed.ed_tailp = LE(nsitd->physaddr);
+ sed->ed.ed_tailp = htole32(nsitd->physaddr);
/* XXX update ED */
splx(s);
}
--- uhci.c.orig Fri Mar 10 21:43:24 2000
+++ uhci.c Fri Mar 10 22:04:59 2000
@@ -105,10 +105,14 @@
* The UHCI controller is little endian, so on big endian machines
* the data strored in memory needs to be swapped.
*/
+#if defined(__FreeBSD__)
#if BYTE_ORDER == BIG_ENDIAN
-#define LE(x) (bswap32(x))
+#define htole32(x) (bswap32(x))
+#define le32toh(x) (bswap32(x))
#else
-#define LE(x) (x)
+#define htole32(x) (x)
+#define le32toh(x) (x)
+#endif
#endif
struct uhci_pipe {
@@ -382,8 +386,8 @@
bsqh = uhci_alloc_sqh(sc);
if (bsqh == NULL)
return (USBD_NOMEM);
- bsqh->qh.qh_hlink = LE(UHCI_PTR_T); /* end of QH chain */
- bsqh->qh.qh_elink = LE(UHCI_PTR_T);
+ bsqh->qh.qh_hlink = htole32(UHCI_PTR_T); /* end of QH chain */
+ bsqh->qh.qh_elink = htole32(UHCI_PTR_T);
sc->sc_bulk_start = sc->sc_bulk_end = bsqh;
/* Allocate the dummy QH where control traffic will be queued. */
@@ -391,8 +395,8 @@
if (csqh == NULL)
return (USBD_NOMEM);
csqh->hlink = bsqh;
- csqh->qh.qh_hlink = LE(bsqh->physaddr | UHCI_PTR_Q);
- csqh->qh.qh_elink = LE(UHCI_PTR_T);
+ csqh->qh.qh_hlink = htole32(bsqh->physaddr | UHCI_PTR_Q);
+ csqh->qh.qh_elink = htole32(UHCI_PTR_T);
sc->sc_ctl_start = sc->sc_ctl_end = csqh;
/*
@@ -406,14 +410,14 @@
if (std == NULL || sqh == NULL)
return (USBD_NOMEM);
std->link.sqh = sqh;
- std->td.td_link = LE(sqh->physaddr | UHCI_PTR_Q);
- std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
- std->td.td_token = LE(0);
- std->td.td_buffer = LE(0);
+ std->td.td_link = htole32(sqh->physaddr | UHCI_PTR_Q);
+ std->td.td_status = htole32(UHCI_TD_IOS); /* iso, inactive */
+ std->td.td_token = htole32(0);
+ std->td.td_buffer = htole32(0);
sqh->hlink = csqh;
- sqh->qh.qh_hlink = LE(csqh->physaddr | UHCI_PTR_Q);
+ sqh->qh.qh_hlink = htole32(csqh->physaddr | UHCI_PTR_Q);
sqh->elink = 0;
- sqh->qh.qh_elink = LE(UHCI_PTR_T);
+ sqh->qh.qh_elink = htole32(UHCI_PTR_T);
sc->sc_vframes[i].htd = std;
sc->sc_vframes[i].etd = std;
sc->sc_vframes[i].hqh = sqh;
@@ -421,7 +425,7 @@
for (j = i;
j < UHCI_FRAMELIST_COUNT;
j += UHCI_VFRAMELIST_COUNT)
- sc->sc_pframes[j] = LE(std->physaddr);
+ sc->sc_pframes[j] = htole32(std->physaddr);
}
LIST_INIT(&sc->sc_intrhead);
@@ -594,7 +598,7 @@
/* save some state if BIOS doesn't */
sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);
sc->sc_saved_sof = UREAD1(sc, UHCI_SOF);
-
+
UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter global suspend */
usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
sc->sc_suspend = why;
@@ -659,24 +663,24 @@
DPRINTFN(-1,("TD(%p) at %08lx = link=0x%08lx status=0x%08lx "
"token=0x%08lx buffer=0x%08lx\n",
p, (long)p->physaddr,
- (long)LE(p->td.td_link),
- (long)LE(p->td.td_status),
- (long)LE(p->td.td_token),
- (long)LE(p->td.td_buffer)));
+ (long)le32toh(p->td.td_link),
+ (long)le32toh(p->td.td_status),
+ (long)le32toh(p->td.td_token),
+ (long)le32toh(p->td.td_buffer)));
DPRINTFN(-1,(" %b %b,errcnt=%d,actlen=%d pid=%02x,addr=%d,endpt=%d,"
"D=%d,maxlen=%d\n",
- (int)LE(p->td.td_link),
+ (int)le32toh(p->td.td_link),
"\20\1T\2Q\3VF",
- (int)LE(p->td.td_status),
+ (int)le32toh(p->td.td_status),
"\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
"STALLED\30ACTIVE\31IOC\32ISO\33LS\36SPD",
- UHCI_TD_GET_ERRCNT(LE(p->td.td_status)),
- UHCI_TD_GET_ACTLEN(LE(p->td.td_status)),
- UHCI_TD_GET_PID(LE(p->td.td_token)),
- UHCI_TD_GET_DEVADDR(LE(p->td.td_token)),
- UHCI_TD_GET_ENDPT(LE(p->td.td_token)),
- UHCI_TD_GET_DT(LE(p->td.td_token)),
- UHCI_TD_GET_MAXLEN(LE(p->td.td_token))));
+ UHCI_TD_GET_ERRCNT(le32toh(p->td.td_status)),
+ UHCI_TD_GET_ACTLEN(le32toh(p->td.td_status)),
+ UHCI_TD_GET_PID(le32toh(p->td.td_token)),
+ UHCI_TD_GET_DEVADDR(le32toh(p->td.td_token)),
+ UHCI_TD_GET_ENDPT(le32toh(p->td.td_token)),
+ UHCI_TD_GET_DT(le32toh(p->td.td_token)),
+ UHCI_TD_GET_MAXLEN(le32toh(p->td.td_token))));
}
void
@@ -684,7 +688,8 @@
uhci_soft_qh_t *sqh;
{
DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", sqh,
- (int)sqh->physaddr, LE(sqh->qh.qh_hlink), LE(sqh->qh.qh_elink)));
+ (int)sqh->physaddr, le32toh(sqh->qh.qh_hlink),
+ le32toh(sqh->qh.qh_elink)));
}
@@ -723,12 +728,12 @@
*/
- if (sqh->hlink != NULL && !(sqh->qh.qh_hlink & UHCI_PTR_T))
+ if (sqh->hlink != NULL && !(le32toh(sqh->qh.qh_hlink) & UHCI_PTR_T))
uhci_dump_qhs(sqh->hlink);
else
DPRINTF(("No QH\n"));
- if (sqh->elink != NULL && !(sqh->qh.qh_elink & UHCI_PTR_T))
+ if (sqh->elink != NULL && !(le32toh(sqh->qh.qh_elink) & UHCI_PTR_T))
uhci_dump_tds(sqh->elink);
else
DPRINTF(("No TD\n"));
@@ -748,8 +753,8 @@
* printing the free list in case the queue/TD has
* already been moved there (seatbelt).
*/
- if (td->td.td_link & UHCI_PTR_T ||
- td->td.td_link == 0)
+ if (le32toh(td->td.td_link) & UHCI_PTR_T ||
+ le32toh(td->td.td_link) == 0)
break;
}
}
@@ -877,7 +882,7 @@
sqh->hlink = eqh->hlink;
sqh->qh.qh_hlink = eqh->qh.qh_hlink;
eqh->hlink = sqh;
- eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
+ eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_Q);
sc->sc_ctl_end = sqh;
}
@@ -894,7 +899,7 @@
DPRINTFN(10, ("uhci_remove_ctrl: sqh=%p\n", sqh));
for (pqh = sc->sc_ctl_start; pqh->hlink != sqh; pqh=pqh->hlink)
#if defined(DIAGNOSTIC) || defined(UHCI_DEBUG)
- if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
+ if (le32toh(pqh->qh.qh_hlink) & UHCI_PTR_T) {
printf("uhci_remove_ctrl: QH not found\n");
return;
}
@@ -922,7 +927,7 @@
sqh->hlink = eqh->hlink;
sqh->qh.qh_hlink = eqh->qh.qh_hlink;
eqh->hlink = sqh;
- eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
+ eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_Q);
sc->sc_bulk_end = sqh;
}
@@ -939,7 +944,7 @@
DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh));
for (pqh = sc->sc_bulk_start; pqh->hlink != sqh; pqh = pqh->hlink)
#if defined(DIAGNOSTIC) || defined(UHCI_DEBUG)
- if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
+ if (le32toh(pqh->qh.qh_hlink) & UHCI_PTR_T) {
printf("uhci_remove_bulk: QH not found\n");
return;
}
@@ -1072,10 +1077,10 @@
* is a an error somewhere in the middle, or whether there was a
* short packet (SPD and not ACTIVE).
*/
- if (LE(lstd->td.td_status) & UHCI_TD_ACTIVE) {
+ if (le32toh(lstd->td.td_status) & UHCI_TD_ACTIVE) {
DPRINTFN(15, ("uhci_check_intr: active ii=%p\n", ii));
for (std = ii->stdstart; std != lstd; std = std->link.std) {
- status = LE(std->td.td_status);
+ status = le32toh(std->td.td_status);
/* If there's an active TD the xfer isn't done. */
if (status & UHCI_TD_ACTIVE)
break;
@@ -1085,7 +1090,7 @@
/* We want short packets, and it is short: it's done */
if ((status & UHCI_TD_SPD) &&
UHCI_TD_GET_ACTLEN(status) <
- UHCI_TD_GET_MAXLEN(LE(std->td.td_token)))
+ UHCI_TD_GET_MAXLEN(le32toh(std->td.td_token)))
goto done;
}
DPRINTFN(15, ("uhci_check_intr: ii=%p std=%p still active\n",
@@ -1148,7 +1153,7 @@
#endif
if (++n >= UHCI_VFRAMELIST_COUNT)
n = 0;
- status = LE(std->td.td_status);
+ status = le32toh(std->td.td_status);
actlen += UHCI_TD_GET_ACTLEN(status);
}
upipe->u.iso.inuse -= nframes;
@@ -1169,17 +1174,18 @@
/* The transfer is done, compute actual length and status. */
actlen = 0;
for (std = ii->stdstart; std != NULL; std = std->link.std) {
- nstatus = LE(std->td.td_status);
+ nstatus = le32toh(std->td.td_status);
if (nstatus & UHCI_TD_ACTIVE)
break;
status = nstatus;
- if (UHCI_TD_GET_PID(LE(std->td.td_token)) != UHCI_TD_PID_SETUP)
+ if (UHCI_TD_GET_PID(le32toh(std->td.td_token)) !=
+ UHCI_TD_PID_SETUP)
actlen += UHCI_TD_GET_ACTLEN(status);
}
/* If there are left over TDs we need to update the toggle. */
if (std != NULL)
- upipe->nexttoggle = UHCI_TD_GET_DT(LE(std->td.td_token));
+ upipe->nexttoggle = UHCI_TD_GET_DT(le32toh(std->td.td_token));
status &= UHCI_TD_ERROR;
DPRINTFN(10, ("uhci_check_intr: actlen=%d, status=0x%x\n",
@@ -1375,11 +1381,11 @@
{
#ifdef DIAGNOSTIC
#define TD_IS_FREE 0x12345678
- if (std->td.td_token == LE(TD_IS_FREE)) {
+ if (le32toh(std->td.td_token) == TD_IS_FREE) {
printf("uhci_free_std: freeing free TD %p\n", std);
return;
}
- std->td.td_token = LE(TD_IS_FREE);
+ std->td.td_token = htole32(TD_IS_FREE);
#endif
std->link.std = sc->sc_freetds;
sc->sc_freetds = std;
@@ -1506,12 +1512,12 @@
}
p->link.std = lastp;
if (lastlink == UHCI_PTR_T)
- p->td.td_link = LE(lastlink);
+ p->td.td_link = htole32(lastlink);
else
- p->td.td_link = LE(lastlink|UHCI_PTR_VF);
+ p->td.td_link = htole32(lastlink|UHCI_PTR_VF);
lastp = p;
lastlink = p->physaddr;
- p->td.td_status = LE(status);
+ p->td.td_status = htole32(status);
if (i == ntd) {
/* last TD */
l = len % maxp;
@@ -1521,9 +1527,9 @@
} else
l = maxp;
p->td.td_token =
- LE(rd ? UHCI_TD_IN (l, endpt, addr, tog) :
- UHCI_TD_OUT(l, endpt, addr, tog));
- p->td.td_buffer = LE(DMAADDR(dma) + i * maxp);
+ htole32(rd ? UHCI_TD_IN (l, endpt, addr, tog) :
+ UHCI_TD_OUT(l, endpt, addr, tog));
+ p->td.td_buffer = htole32(DMAADDR(dma) + i * maxp);
tog ^= 1;
}
*sp = lastp;
@@ -1600,7 +1606,7 @@
&xfer->dmabuf, &data, &dataend);
if (err)
return (err);
- dataend->td.td_status |= LE(UHCI_TD_IOC);
+ dataend->td.td_status |= htole32(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
if (uhcidebug > 8) {
@@ -1624,7 +1630,7 @@
#endif
sqh->elink = data;
- sqh->qh.qh_elink = LE(data->physaddr);
+ sqh->qh.qh_elink = htole32(data->physaddr);
sqh->intr_info = ii;
s = splusb();
@@ -1678,7 +1684,7 @@
/* make hardware ignore it, */
for (std = ii->stdstart; std != 0; std = std->link.std)
- std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
+ std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
xfer->hcpriv = ii;
@@ -1814,7 +1820,7 @@
&xfer->dmabuf, &data, &dataend);
if (err)
return (err);
- dataend->td.td_status |= LE(UHCI_TD_IOC);
+ dataend->td.td_status |= htole32(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
if (uhcidebug > 10) {
@@ -1844,7 +1850,7 @@
for (i = 0; i < upipe->u.intr.npoll; i++) {
sqh = upipe->u.intr.qhs[i];
sqh->elink = data;
- sqh->qh.qh_elink = LE(data->physaddr);
+ sqh->qh.qh_elink = htole32(data->physaddr);
}
splx(s);
@@ -1971,7 +1977,7 @@
return (err);
next = data;
dataend->link.std = stat;
- dataend->td.td_link = LE(stat->physaddr | UHCI_PTR_VF);
+ dataend->td.td_link = htole32(stat->physaddr | UHCI_PTR_VF);
} else {
next = stat;
}
@@ -1980,19 +1986,20 @@
memcpy(KERNADDR(&upipe->u.ctl.reqdma), req, sizeof *req);
setup->link.std = next;
- setup->td.td_link = LE(next->physaddr | UHCI_PTR_VF);
- setup->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls | UHCI_TD_ACTIVE);
- setup->td.td_token = LE(UHCI_TD_SETUP(sizeof *req, endpt, addr));
- setup->td.td_buffer = LE(DMAADDR(&upipe->u.ctl.reqdma));
+ setup->td.td_link = htole32(next->physaddr | UHCI_PTR_VF);
+ setup->td.td_status = htole32(UHCI_TD_SET_ERRCNT(3) | ls |
+ UHCI_TD_ACTIVE);
+ setup->td.td_token = htole32(UHCI_TD_SETUP(sizeof *req, endpt, addr));
+ setup->td.td_buffer = htole32(DMAADDR(&upipe->u.ctl.reqdma));
stat->link.std = 0;
- stat->td.td_link = LE(UHCI_PTR_T);
- stat->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls |
+ stat->td.td_link = htole32(UHCI_PTR_T);
+ stat->td.td_status = htole32(UHCI_TD_SET_ERRCNT(3) | ls |
UHCI_TD_ACTIVE | UHCI_TD_IOC);
stat->td.td_token =
- LE(isread ? UHCI_TD_OUT(0, endpt, addr, 1) :
- UHCI_TD_IN (0, endpt, addr, 1));
- stat->td.td_buffer = LE(0);
+ htole32(isread ? UHCI_TD_OUT(0, endpt, addr, 1) :
+ UHCI_TD_IN (0, endpt, addr, 1));
+ stat->td.td_buffer = htole32(0);
#ifdef UHCI_DEBUG
if (uhcidebug > 10) {
@@ -2016,7 +2023,7 @@
#endif
sqh->elink = setup;
- sqh->qh.qh_elink = LE(setup->physaddr);
+ sqh->qh.qh_elink = htole32(setup->physaddr);
sqh->intr_info = ii;
s = splusb();
@@ -2033,7 +2040,7 @@
for (std = sc->sc_vframes[0].htd, link = 0;
(link & UHCI_PTR_Q) == 0;
std = std->link.std) {
- link = LE(std->td.td_link);
+ link = le32toh(std->td.td_link);
uhci_dump_td(std);
}
sxqh = (uhci_soft_qh_t *)std;
@@ -2125,9 +2132,9 @@
xfer->hcprivint = next;
buf = DMAADDR(&xfer->dmabuf);
- status = LE(UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
- UHCI_TD_ACTIVE |
- UHCI_TD_IOS));
+ status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
+ UHCI_TD_ACTIVE |
+ UHCI_TD_IOS);
nframes = xfer->nframes;
s = splusb();
for (i = 0; i < nframes; i++) {
@@ -2135,12 +2142,12 @@
if (++next >= UHCI_VFRAMELIST_COUNT)
next = 0;
len = xfer->frlengths[i];
- std->td.td_buffer = LE(buf);
+ std->td.td_buffer = htole32(buf);
if (i == nframes - 1)
- status |= LE(UHCI_TD_IOC);
- std->td.td_status = status;
- std->td.td_token &= LE(~UHCI_TD_MAXLEN_MASK);
- std->td.td_token |= LE(UHCI_TD_SET_MAXLEN(len));
+ status |= UHCI_TD_IOC;
+ std->td.td_status = htole32(status);
+ std->td.td_token &= htole32(~UHCI_TD_MAXLEN_MASK);
+ std->td.td_token |= htole32(UHCI_TD_SET_MAXLEN(len));
#ifdef UHCI_DEBUG
if (uhcidebug > 5) {
DPRINTFN(5,("uhci_device_isoc_enter: TD %d\n", i));
@@ -2219,7 +2226,7 @@
n = xfer->hcprivint;
for (i = 0; i < nframes; i++) {
std = stds[n];
- std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
+ std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
if (++n >= UHCI_VFRAMELIST_COUNT)
n = 0;
}
@@ -2257,7 +2264,7 @@
iso = &upipe->u.iso;
for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++)
- iso->stds[i]->td.td_status &= LE(~UHCI_TD_ACTIVE);
+ iso->stds[i]->td.td_status &= htole32(~UHCI_TD_ACTIVE);
usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */
uhci_lock_frames(sc);
@@ -2301,16 +2308,16 @@
iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *),
M_USBHC, M_WAITOK);
- token = LE(rd ? UHCI_TD_IN (0, endpt, addr, 0) :
- UHCI_TD_OUT(0, endpt, addr, 0));
+ token = rd ? UHCI_TD_IN (0, endpt, addr, 0) :
+ UHCI_TD_OUT(0, endpt, addr, 0);
/* Allocate the TDs and mark as inactive; */
for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
std = uhci_alloc_std(sc);
if (std == 0)
goto bad;
- std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
- std->td.td_token = token;
+ std->td.td_status = htole32(UHCI_TD_IOS); /* iso, inactive */
+ std->td.td_token = htole32(token);
iso->stds[i] = std;
}
@@ -2322,7 +2329,7 @@
std->link = vstd->link;
std->td.td_link = vstd->td.td_link;
vstd->link.std = std;
- vstd->td.td_link = LE(std->physaddr);
+ vstd->td.td_link = htole32(std->physaddr);
}
uhci_unlock_frames(sc);
@@ -2347,7 +2354,7 @@
DPRINTFN(4, ("uhci_isoc_done: length=%d\n", xfer->actlen));
/* Turn off the interrupt since it is active even if the TD is not. */
- ii->stdend->td.td_status &= LE(~UHCI_TD_IOC);
+ ii->stdend->td.td_status &= htole32(~UHCI_TD_IOC);
LIST_REMOVE(ii, list); /* remove from active list */
}
@@ -2368,7 +2375,7 @@
for(i = 0; i < npoll; i++) {
sqh = upipe->u.intr.qhs[i];
sqh->elink = 0;
- sqh->qh.qh_elink = LE(UHCI_PTR_T);
+ sqh->qh.qh_elink = htole32(UHCI_PTR_T);
}
uhci_free_std_chain(sc, ii->stdstart, 0);
@@ -2379,7 +2386,7 @@
/* This alloc cannot fail since we freed the chain above. */
uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
&xfer->dmabuf, &data, &dataend);
- dataend->td.td_status |= LE(UHCI_TD_IOC);
+ dataend->td.td_status |= htole32(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
if (uhcidebug > 10) {
@@ -2403,7 +2410,7 @@
for (i = 0; i < npoll; i++) {
sqh = upipe->u.intr.qhs[i];
sqh->elink = data;
- sqh->qh.qh_elink = LE(data->physaddr);
+ sqh->qh.qh_elink = htole32(data->physaddr);
}
} else {
ii->stdstart = 0; /* mark as inactive */
@@ -2467,7 +2474,7 @@
sqh->hlink = eqh->hlink;
sqh->qh.qh_hlink = eqh->qh.qh_hlink;
eqh->hlink = sqh;
- eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
+ eqh->qh.qh_hlink = htole32(sqh->physaddr | UHCI_PTR_Q);
vf->eqh = sqh;
vf->bandwidth++;
}
@@ -2486,7 +2493,7 @@
for (pqh = vf->hqh; pqh->hlink != sqh; pqh = pqh->hlink)
#if defined(DIAGNOSTIC) || defined(UHCI_DEBUG)
- if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
+ if (le32toh(pqh->qh.qh_hlink) & UHCI_PTR_T) {
DPRINTF(("uhci_remove_intr: QH not found\n"));
return;
}
@@ -2544,7 +2551,7 @@
for(i = 0; i < npoll; i++) {
upipe->u.intr.qhs[i] = sqh = uhci_alloc_sqh(sc);
sqh->elink = 0;
- sqh->qh.qh_elink = LE(UHCI_PTR_T);
+ sqh->qh.qh_elink = htole32(UHCI_PTR_T);
sqh->pos = MOD(i * ival + bestoffs);
sqh->intr_info = upipe->iinfo;
}