Commit c13db862 authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[PATCH] USB: ohci, remove pre-byteswapped constants

This is the first of several patches from Dale Farnsworth,
laying groundwork for a patch that supports OHCI on more
chips (IBM STB04xxx and FreeScale MPC52xx).


Replace pre-byteswapped constants for in-memory data structures in ohci.h
with cpu-native constants, to help support "big-endian OHCI" hardware.
Signed-off-by: default avatarDale Farnsworth <dale@farnsworth.org>
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 9b94c90d
...@@ -336,7 +336,7 @@ static void __attribute__((unused)) ...@@ -336,7 +336,7 @@ static void __attribute__((unused))
ohci_dump_ed (const struct ohci_hcd *ohci, const char *label, ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
const struct ed *ed, int verbose) const struct ed *ed, int verbose)
{ {
__le32 tmp = ed->hwINFO; u32 tmp = le32_to_cpu (ed->hwINFO);
char *type = ""; char *type = "";
ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n", ohci_dbg (ohci, "%s, ed %p state 0x%x type %s; next ed %08x\n",
...@@ -349,19 +349,20 @@ ohci_dump_ed (const struct ohci_hcd *ohci, const char *label, ...@@ -349,19 +349,20 @@ ohci_dump_ed (const struct ohci_hcd *ohci, const char *label,
/* else from TDs ... control */ /* else from TDs ... control */
} }
ohci_dbg (ohci, ohci_dbg (ohci,
" info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", le32_to_cpu (tmp), " info %08x MAX=%d%s%s%s%s EP=%d%s DEV=%d\n", tmp,
0x03ff & (le32_to_cpu (tmp) >> 16), 0x03ff & (tmp >> 16),
(tmp & ED_DEQUEUE) ? " DQ" : "", (tmp & ED_DEQUEUE) ? " DQ" : "",
(tmp & ED_ISO) ? " ISO" : "", (tmp & ED_ISO) ? " ISO" : "",
(tmp & ED_SKIP) ? " SKIP" : "", (tmp & ED_SKIP) ? " SKIP" : "",
(tmp & ED_LOWSPEED) ? " LOW" : "", (tmp & ED_LOWSPEED) ? " LOW" : "",
0x000f & (le32_to_cpu (tmp) >> 7), 0x000f & (tmp >> 7),
type, type,
0x007f & le32_to_cpu (tmp)); 0x007f & tmp);
tmp = le32_to_cpup (&ed->hwHeadP);
ohci_dbg (ohci, " tds: head %08x %s%s tail %08x%s\n", ohci_dbg (ohci, " tds: head %08x %s%s tail %08x%s\n",
le32_to_cpup (&ed->hwHeadP), tmp,
(ed->hwHeadP & ED_C) ? data1 : data0, (tmp & ED_C) ? data1 : data0,
(ed->hwHeadP & ED_H) ? " HALT" : "", (tmp & ED_H) ? " HALT" : "",
le32_to_cpup (&ed->hwTailP), le32_to_cpup (&ed->hwTailP),
verbose ? "" : " (not listing)"); verbose ? "" : " (not listing)");
if (verbose) { if (verbose) {
...@@ -408,8 +409,8 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) ...@@ -408,8 +409,8 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
/* dump a snapshot of the bulk or control schedule */ /* dump a snapshot of the bulk or control schedule */
while (ed) { while (ed) {
__le32 info = ed->hwINFO; u32 info = le32_to_cpu (ed->hwINFO);
u32 scratch = le32_to_cpup (&ed->hwINFO); u32 headp = le32_to_cpu (ed->hwHeadP);
struct list_head *entry; struct list_head *entry;
struct td *td; struct td *td;
...@@ -417,14 +418,14 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) ...@@ -417,14 +418,14 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
"ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s", "ed/%p %cs dev%d ep%d%s max %d %08x%s%s %s",
ed, ed,
(info & ED_LOWSPEED) ? 'l' : 'f', (info & ED_LOWSPEED) ? 'l' : 'f',
scratch & 0x7f, info & 0x7f,
(scratch >> 7) & 0xf, (info >> 7) & 0xf,
(info & ED_IN) ? "in" : "out", (info & ED_IN) ? "in" : "out",
0x03ff & (scratch >> 16), 0x03ff & (info >> 16),
scratch, info,
(info & ED_SKIP) ? " s" : "", (info & ED_SKIP) ? " s" : "",
(ed->hwHeadP & ED_H) ? " H" : "", (headp & ED_H) ? " H" : "",
(ed->hwHeadP & ED_C) ? data1 : data0); (headp & ED_C) ? data1 : data0);
size -= temp; size -= temp;
buf += temp; buf += temp;
...@@ -432,21 +433,21 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) ...@@ -432,21 +433,21 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
u32 cbp, be; u32 cbp, be;
td = list_entry (entry, struct td, td_list); td = list_entry (entry, struct td, td_list);
scratch = le32_to_cpup (&td->hwINFO); info = le32_to_cpup (&td->hwINFO);
cbp = le32_to_cpup (&td->hwCBP); cbp = le32_to_cpup (&td->hwCBP);
be = le32_to_cpup (&td->hwBE); be = le32_to_cpup (&td->hwBE);
temp = scnprintf (buf, size, temp = scnprintf (buf, size,
"\n\ttd %p %s %d cc=%x urb %p (%08x)", "\n\ttd %p %s %d cc=%x urb %p (%08x)",
td, td,
({ char *pid; ({ char *pid;
switch (scratch & TD_DP) { switch (info & TD_DP) {
case TD_DP_SETUP: pid = "setup"; break; case TD_DP_SETUP: pid = "setup"; break;
case TD_DP_IN: pid = "in"; break; case TD_DP_IN: pid = "in"; break;
case TD_DP_OUT: pid = "out"; break; case TD_DP_OUT: pid = "out"; break;
default: pid = "(?)"; break; default: pid = "(?)"; break;
} pid;}), } pid;}),
cbp ? (be + 1 - cbp) : 0, cbp ? (be + 1 - cbp) : 0,
TD_CC_GET (scratch), td->urb, scratch); TD_CC_GET (info), td->urb, info);
size -= temp; size -= temp;
buf += temp; buf += temp;
} }
...@@ -534,8 +535,7 @@ show_periodic (struct class_device *class_dev, char *buf) ...@@ -534,8 +535,7 @@ show_periodic (struct class_device *class_dev, char *buf)
/* show more info the first time around */ /* show more info the first time around */
if (temp == seen_count) { if (temp == seen_count) {
__le32 info = ed->hwINFO; u32 info = le32_to_cpu (ed->hwINFO);
u32 scratch = le32_to_cpup (&ed->hwINFO);
struct list_head *entry; struct list_head *entry;
unsigned qlen = 0; unsigned qlen = 0;
...@@ -547,15 +547,16 @@ show_periodic (struct class_device *class_dev, char *buf) ...@@ -547,15 +547,16 @@ show_periodic (struct class_device *class_dev, char *buf)
" (%cs dev%d ep%d%s-%s qlen %u" " (%cs dev%d ep%d%s-%s qlen %u"
" max %d %08x%s%s)", " max %d %08x%s%s)",
(info & ED_LOWSPEED) ? 'l' : 'f', (info & ED_LOWSPEED) ? 'l' : 'f',
scratch & 0x7f, info & 0x7f,
(scratch >> 7) & 0xf, (info >> 7) & 0xf,
(info & ED_IN) ? "in" : "out", (info & ED_IN) ? "in" : "out",
(info & ED_ISO) ? "iso" : "int", (info & ED_ISO) ? "iso" : "int",
qlen, qlen,
0x03ff & (scratch >> 16), 0x03ff & (info >> 16),
scratch, info,
(info & ED_SKIP) ? " K" : "", (info & ED_SKIP) ? " K" : "",
(ed->hwHeadP & ED_H) ? " H" : ""); (ed->hwHeadP & cpu_to_le32(ED_H)) ?
" H" : "");
size -= temp; size -= temp;
next += temp; next += temp;
......
...@@ -815,7 +815,7 @@ static int ohci_restart (struct ohci_hcd *ohci) ...@@ -815,7 +815,7 @@ static int ohci_restart (struct ohci_hcd *ohci)
switch (ed->state) { switch (ed->state) {
case ED_OPER: case ED_OPER:
ed->state = ED_UNLINK; ed->state = ED_UNLINK;
ed->hwINFO |= ED_DEQUEUE; ed->hwINFO |= cpu_to_le32(ED_DEQUEUE);
ed_deschedule (ohci, ed); ed_deschedule (ohci, ed);
ed->ed_next = ohci->ed_rm_list; ed->ed_next = ohci->ed_rm_list;
......
...@@ -115,7 +115,7 @@ td_free (struct ohci_hcd *hc, struct td *td) ...@@ -115,7 +115,7 @@ td_free (struct ohci_hcd *hc, struct td *td)
prev = &(*prev)->td_hash; prev = &(*prev)->td_hash;
if (*prev) if (*prev)
*prev = td->td_hash; *prev = td->td_hash;
else if ((td->hwINFO & TD_DONE) != 0) else if ((td->hwINFO & cpu_to_le32(TD_DONE)) != 0)
ohci_dbg (hc, "no hash for td %p\n", td); ohci_dbg (hc, "no hash for td %p\n", td);
dma_pool_free (hc->td_cache, td, td->td_dma); dma_pool_free (hc->td_cache, td, td->td_dma);
} }
......
...@@ -131,7 +131,7 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed) ...@@ -131,7 +131,7 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
unsigned i; unsigned i;
ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n", ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n",
(ed->hwINFO & ED_ISO) ? "iso " : "", (ed->hwINFO & cpu_to_le32 (ED_ISO)) ? "iso " : "",
ed, ed->branch, ed->load, ed->interval); ed, ed->branch, ed->load, ed->interval);
for (i = ed->branch; i < NUM_INTS; i += ed->interval) { for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
...@@ -272,7 +272,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) ...@@ -272,7 +272,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
hcd_to_bus (&ohci->hcd)->bandwidth_allocated -= ed->load / ed->interval; hcd_to_bus (&ohci->hcd)->bandwidth_allocated -= ed->load / ed->interval;
ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
(ed->hwINFO & ED_ISO) ? "iso " : "", (ed->hwINFO & cpu_to_le32 (ED_ISO)) ? "iso " : "",
ed, ed->branch, ed->load, ed->interval); ed, ed->branch, ed->load, ed->interval);
} }
...@@ -300,7 +300,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) ...@@ -300,7 +300,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
*/ */
static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
{ {
ed->hwINFO |= ED_SKIP; ed->hwINFO |= cpu_to_le32 (ED_SKIP);
wmb (); wmb ();
ed->state = ED_UNLINK; ed->state = ED_UNLINK;
...@@ -427,21 +427,19 @@ static struct ed *ed_get ( ...@@ -427,21 +427,19 @@ static struct ed *ed_get (
*/ */
if (ed->state == ED_IDLE) { if (ed->state == ED_IDLE) {
u32 info; u32 info;
__le32 hw_info;
info = usb_pipedevice (pipe); info = usb_pipedevice (pipe);
info |= (ep >> 1) << 7; info |= (ep >> 1) << 7;
info |= usb_maxpacket (udev, pipe, is_out) << 16; info |= usb_maxpacket (udev, pipe, is_out) << 16;
hw_info = cpu_to_le32 (info);
if (udev->speed == USB_SPEED_LOW) if (udev->speed == USB_SPEED_LOW)
hw_info |= ED_LOWSPEED; info |= ED_LOWSPEED;
/* only control transfers store pids in tds */ /* only control transfers store pids in tds */
if (type != PIPE_CONTROL) { if (type != PIPE_CONTROL) {
hw_info |= is_out ? ED_OUT : ED_IN; info |= is_out ? ED_OUT : ED_IN;
if (type != PIPE_BULK) { if (type != PIPE_BULK) {
/* periodic transfers... */ /* periodic transfers... */
if (type == PIPE_ISOCHRONOUS) if (type == PIPE_ISOCHRONOUS)
hw_info |= ED_ISO; info |= ED_ISO;
else if (interval > 32) /* iso can be bigger */ else if (interval > 32) /* iso can be bigger */
interval = 32; interval = 32;
ed->interval = interval; ed->interval = interval;
...@@ -452,7 +450,7 @@ static struct ed *ed_get ( ...@@ -452,7 +450,7 @@ static struct ed *ed_get (
/ 1000; / 1000;
} }
} }
ed->hwINFO = hw_info; ed->hwINFO = cpu_to_le32(info);
} }
done: done:
...@@ -470,7 +468,7 @@ static struct ed *ed_get ( ...@@ -470,7 +468,7 @@ static struct ed *ed_get (
*/ */
static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed) static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
{ {
ed->hwINFO |= ED_DEQUEUE; ed->hwINFO |= cpu_to_le32 (ED_DEQUEUE);
ed_deschedule (ohci, ed); ed_deschedule (ohci, ed);
/* rm_list is just singly linked, for simplicity */ /* rm_list is just singly linked, for simplicity */
...@@ -594,7 +592,7 @@ static void td_submit_urb ( ...@@ -594,7 +592,7 @@ static void td_submit_urb (
if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) { if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
is_out, 1); is_out, 1);
urb_priv->ed->hwHeadP &= ~ED_C; urb_priv->ed->hwHeadP &= ~cpu_to_le32 (ED_C);
} }
urb_priv->td_cnt = 0; urb_priv->td_cnt = 0;
...@@ -790,14 +788,14 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev) ...@@ -790,14 +788,14 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
struct urb *urb = td->urb; struct urb *urb = td->urb;
struct ed *ed = td->ed; struct ed *ed = td->ed;
struct list_head *tmp = td->td_list.next; struct list_head *tmp = td->td_list.next;
__le32 toggle = ed->hwHeadP & ED_C; __le32 toggle = ed->hwHeadP & cpu_to_le32 (ED_C);
/* clear ed halt; this is the td that caused it, but keep it inactive /* clear ed halt; this is the td that caused it, but keep it inactive
* until its urb->complete() has a chance to clean up. * until its urb->complete() has a chance to clean up.
*/ */
ed->hwINFO |= ED_SKIP; ed->hwINFO |= cpu_to_le32 (ED_SKIP);
wmb (); wmb ();
ed->hwHeadP &= ~ED_H; ed->hwHeadP &= ~cpu_to_le32 (ED_H);
/* put any later tds from this urb onto the donelist, after 'td', /* put any later tds from this urb onto the donelist, after 'td',
* order won't matter here: no errors, and nothing was transferred. * order won't matter here: no errors, and nothing was transferred.
...@@ -889,7 +887,8 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) ...@@ -889,7 +887,8 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
* and dequeue any other TDs from this urb. * and dequeue any other TDs from this urb.
* No other TD could have caused the halt. * No other TD could have caused the halt.
*/ */
if (cc != TD_CC_NOERROR && (td->ed->hwHeadP & ED_H)) if (cc != TD_CC_NOERROR
&& (td->ed->hwHeadP & cpu_to_le32 (ED_H)))
td_rev = ed_halted (ohci, td, cc, td_rev); td_rev = ed_halted (ohci, td, cc, td_rev);
td->next_dl_td = td_rev; td->next_dl_td = td_rev;
...@@ -990,10 +989,10 @@ finish_unlinks (struct ohci_hcd *ohci, u16 tick, struct pt_regs *regs) ...@@ -990,10 +989,10 @@ finish_unlinks (struct ohci_hcd *ohci, u16 tick, struct pt_regs *regs)
/* ED's now officially unlinked, hc doesn't see */ /* ED's now officially unlinked, hc doesn't see */
ed->state = ED_IDLE; ed->state = ED_IDLE;
ed->hwHeadP &= ~ED_H; ed->hwHeadP &= ~cpu_to_le32(ED_H);
ed->hwNextED = 0; ed->hwNextED = 0;
wmb (); wmb ();
ed->hwINFO &= ~(ED_SKIP | ED_DEQUEUE); ed->hwINFO &= ~cpu_to_le32 (ED_SKIP | ED_DEQUEUE);
/* but if there's work queued, reschedule */ /* but if there's work queued, reschedule */
if (!list_empty (&ed->td_list)) { if (!list_empty (&ed->td_list)) {
...@@ -1072,10 +1071,11 @@ dl_done_list (struct ohci_hcd *ohci, struct pt_regs *regs) ...@@ -1072,10 +1071,11 @@ dl_done_list (struct ohci_hcd *ohci, struct pt_regs *regs)
start_ed_unlink (ohci, ed); start_ed_unlink (ohci, ed);
/* ... reenabling halted EDs only after fault cleanup */ /* ... reenabling halted EDs only after fault cleanup */
} else if ((ed->hwINFO & (ED_SKIP | ED_DEQUEUE)) == ED_SKIP) { } else if ((ed->hwINFO & cpu_to_le32 (ED_SKIP | ED_DEQUEUE))
== cpu_to_le32 (ED_SKIP)) {
td = list_entry (ed->td_list.next, struct td, td_list); td = list_entry (ed->td_list.next, struct td, td_list);
if (!(td->hwINFO & TD_DONE)) { if (!(td->hwINFO & cpu_to_le32 (TD_DONE))) {
ed->hwINFO &= ~ED_SKIP; ed->hwINFO &= ~cpu_to_le32 (ED_SKIP);
/* ... hc may need waking-up */ /* ... hc may need waking-up */
switch (ed->type) { switch (ed->type) {
case PIPE_CONTROL: case PIPE_CONTROL:
......
...@@ -18,17 +18,17 @@ struct ed { ...@@ -18,17 +18,17 @@ struct ed {
/* first fields are hardware-specified, le32 */ /* first fields are hardware-specified, le32 */
__le32 hwINFO; /* endpoint config bitmap */ __le32 hwINFO; /* endpoint config bitmap */
/* info bits defined by hcd */ /* info bits defined by hcd */
#define ED_DEQUEUE __constant_cpu_to_le32(1 << 27) #define ED_DEQUEUE (1 << 27)
/* info bits defined by the hardware */ /* info bits defined by the hardware */
#define ED_ISO __constant_cpu_to_le32(1 << 15) #define ED_ISO (1 << 15)
#define ED_SKIP __constant_cpu_to_le32(1 << 14) #define ED_SKIP (1 << 14)
#define ED_LOWSPEED __constant_cpu_to_le32(1 << 13) #define ED_LOWSPEED (1 << 13)
#define ED_OUT __constant_cpu_to_le32(0x01 << 11) #define ED_OUT (0x01 << 11)
#define ED_IN __constant_cpu_to_le32(0x02 << 11) #define ED_IN (0x02 << 11)
__le32 hwTailP; /* tail of TD list */ __le32 hwTailP; /* tail of TD list */
__le32 hwHeadP; /* head of TD list (hc r/w) */ __le32 hwHeadP; /* head of TD list (hc r/w) */
#define ED_C __constant_cpu_to_le32(0x02) /* toggle carry */ #define ED_C (0x02) /* toggle carry */
#define ED_H __constant_cpu_to_le32(0x01) /* halted */ #define ED_H (0x01) /* halted */
__le32 hwNextED; /* next ED in list */ __le32 hwNextED; /* next ED in list */
/* rest are purely for the driver's use */ /* rest are purely for the driver's use */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment