55#define CPUCFG_COHERENT_DMA 1
57#define ENDIAN_LITTLE 1
77#if defined(_CFE_) && ENDIAN_BIG
81#define BSWAP32(x) __builtin_bswap32(x)
90#define OHCI_VTOP(ptr) vtop(ptr)
91#define OHCI_PTOV(ptr) ptov(ptr)
92#define OHCI_VTOD(ptr) OHCI_VTOP(ptr)
93#define OHCI_DTOV(ptr) OHCI_PTOV(ptr)
94#define OHCI_WRITECSR(softc,x,y) \
95 *((volatile uint32_t *) ((softc)->ohci_regs + ((x)/sizeof(uint32_t)))) = (y)
96#define OHCI_READCSR(softc,x) \
97 *((volatile uint32_t *) ((softc)->ohci_regs + ((x)/sizeof(uint32_t))))
100#define OHCI_VTOP(ptr) ((uint32_t)PHYSADDR((long)(ptr)))
102#if CPUCFG_COHERENT_DMA
103#define OHCI_PTOV(ptr) ((void *)(KERNADDR(ptr)))
105#define OHCI_PTOV(ptr) ((void *)(UNCADDR(ptr)))
112#if ENDIAN_BIG && defined(BCM47XX)
113#define PHYS_TO_DMA(a) ((a) + 0x10000000)
114#define DMA_TO_PHYS(a) ((a) - 0x10000000)
116#define PHYS_TO_DMA(a) (a)
117#define DMA_TO_PHYS(a) (a)
120#define OHCI_DTOV(ptr) (OHCI_PTOV(DMA_TO_PHYS(ptr)))
121#define OHCI_VTOD(ptr) (PHYS_TO_DMA(OHCI_VTOP(ptr)))
123#define OHCI_WRITECSR(softc,x,y) \
124 write32(((softc)->ohci_regs + (x)),(y))
125#define OHCI_READCSR(softc,x) \
126 read32(((softc)->ohci_regs + (x)))
129#define OHCI_INVAL_RANGE(s,l) memdcbf(s,l)
130#define OHCI_FLUSH_RANGE(s,l) memdcbst(s,l)
139#define OHCIDEBUG(x) x
151 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c,
152 0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e,
153 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d,
154 0x03, 0x13, 0x0b, 0x1b, 0x07, 0x17, 0x0f, 0x1f
174#define ohci_td_from_transfer(softc,transfer) \
175 ((softc)->ohci_hwtdpool + ((transfer) - (softc)->ohci_transfer_pool))
177#define ohci_transfer_from_td(softc,td) \
178 ((softc)->ohci_transfer_pool + ((td) - (softc)->ohci_hwtdpool))
180#define ohci_ed_from_endpoint(softc,endpoint) \
181 ((softc)->ohci_hwedpool + ((endpoint) - (softc)->ohci_endpoint_pool))
183#define ohci_endpoint_from_ed(softc,ed) \
184 ((softc)->ohci_endpoint_pool + ((ed) - (softc)->ohci_hwedpool))
216 printf(
"HubStatus: %08X ",reg);
228 printf(
"Port %d: %08X ",idx,reg);
247 static char *
pids[4] = {
"SETUP",
"OUT",
"IN",
"RSVD"};
251 printf(
"[%08X] ctl=%08X (DP=%s,DI=%d,T=%d,EC=%d,CC=%d%s) cbp=%08X be=%08X next=%08X\n",
270 printf(
"%d:[%08X] ctl=%08X cbp=%08X be=%08X next=%08X ",
279 printf(
"Req=%p",transfer->
t_ref);
290 static char *
pids[4] = {
"FTD",
"OUT",
"IN",
"FTD"};
294 printf(
"[%08X] Ctl=%08X (MPS=%d%s%s%s,EN=%d,FA=%d,D=%s) Tailp=%08X headp=%08X next=%08X %s\n",
316 printf(
"---\nED#%d -> ",idx);
375 printf(
"AllocEpt: ");eptstats(softc);
382 OHCIDEBUG(printf(
"No endpoints left!\n"));
433 OHCIDEBUG(printf(
"No more transfer descriptors!\n"));
520#define CACHE_ALIGN 32
521#define ALIGN(n,align) (((n)+((align)-1)) & ~((align)-1))
523static void * _ohci_dma_alloc(
size_t size,
unsigned int align)
529#if (!CPUCFG_COHERENT_DMA)
572 OHCIDEBUG(printf(
"Could not allocate transfer descriptors\n"));
576#if (!CPUCFG_COHERENT_DMA)
595 OHCIDEBUG(printf(
"Could not allocate transfer descriptors\n"));
599#if (!CPUCFG_COHERENT_DMA)
616 OHCIDEBUG(printf(
"Could not allocate host communication area\n"));
620#if (!CPUCFG_COHERENT_DMA)
672 for (idx = 0; idx < 10000; idx++) {
722 reg = frameint * 9 / 10;
803 e = _ohci_allocept(softc);
987 ur = transfer->
t_ref;
988 printf(
"Done(%d): ",ur ? ur->
ur_tdcount : -1);
999 ur = transfer->
t_ref;
1000 printf(
"[%p Transfer error: %d %s %04X/%02X len=%d/%d (%s)]\n",ur,
val,
1012 ur = transfer->
t_ref;
1030 OHCIDEBUG(printf(
"Changing status of %p to CANCELLED\n",ur));
1041 _ohci_freexfer(softc,transfer);
1106 ohci_intr_procdoneq(softc, donehead);
1121 OHCIDEBUG(printf(
"UnrecoverableError\n"));
1134 printf(
"RootHubStatusChange: ");
1143 ohci_roothub_statchg(softc);
1193 if (!softc)
return NULL;
1215 if ((res = _ohci_initpools(softc)) != 0)
goto error;
1216 if ((res = _ohci_setupepts(softc)) != 0)
goto error;
1261 ept = _ohci_allocept(softc);
1264 tailtransfer = _ohci_allocxfer(softc);
1301 printf(
"Create endpoint %d addr %d flags %08X mps %d\n",
1302 eptnum,usbaddr,eptflags,mps);
1364 eptflags &= ~M_OHCI_ED_FA;
1394 eptflags &= ~M_OHCI_ED_MPS;
1467 OHCIDEBUG(printf(
"Invalid endpoint\n"));
1489 _ohci_deqept(softc,queue,ept);
1501 ur = transfer->
t_ref;
1507 if (
ohcidebug > 0) printf(
"dev %p Completing request due to closed pipe: %p (%s,%04X/%02X,%s)\n",
1519 _ohci_freexfer(softc,transfer);
1533 _ohci_freeept(softc,ept);
1576 return ohci_roothub_xfer(
bus,uept,ur);
1619 OHCIDEBUG(printf(
"Shouldn't happen!\n"));
1633 printf(
">> Queueing xfer addr %d pipe %d ED %08X ptr %016X length %d\n",
1647 newtailtransfer = _ohci_allocxfer(softc);
1653 curtransfer->
t_next = newtailtransfer;
1654 curtransfer->
t_ref = ur;
1666 if (amtcopy > pktlen) amtcopy = pktlen;
1667 newtailtransfer = _ohci_allocxfer(softc);
1673 curtransfer->
t_next = newtailtransfer;
1674 curtransfer->
t_ref = ur;
1727 ohci_ept_cleartoggle,
1820 *p++ = strlen(
str)*2 + 2;
1884 memcpy(
ptr,&ups,
sizeof(ups));
2010 softc->ohci_rh_newaddr = wValue;
2014 switch (wValue >> 8) {
2016 memcpy(
ptr,&ohci_root_devdsc,
sizeof(ohci_root_devdsc));
2017 ptr +=
sizeof(ohci_root_devdsc);
2020 memcpy(
ptr,&ohci_root_cfgdsc,
sizeof(ohci_root_cfgdsc));
2021 ptr +=
sizeof(ohci_root_cfgdsc);
2022 memcpy(
ptr,&ohci_root_ifdsc,
sizeof(ohci_root_ifdsc));
2023 ptr +=
sizeof(ohci_root_ifdsc);
2024 memcpy(
ptr,&ohci_root_epdsc,
sizeof(ohci_root_epdsc));
2025 ptr +=
sizeof(ohci_root_epdsc);
2028 switch (wValue & 0xFF) {
2030 ptr += ohci_roothub_strdscr(
ptr,
"Generic");
2033 ptr += ohci_roothub_strdscr(
ptr,
"Root Hub");
2047 memcpy(&hdsc,&ohci_root_hubdsc,sizeof(hdsc));
2060 memcpy(
ptr,&hdsc,
sizeof(hdsc));
2061 ptr +=
sizeof(hdsc);
2069 *
ptr++ = softc->ohci_rh_conf;
2073 softc->ohci_rh_conf = wValue;
2119 for (idx = 1; idx <= softc->
ohci_ndp; idx++) {
2122 portstat = (1<<idx);
2127 if (portstat != 0) {
2188 ohci_roothub_req(softc,req);
2190 if (res != 0) printf(
"Root hub request returned an error\n");
2244 OHCIDEBUG(printf(
"Unknown root hub transfer type\n"));
#define KMALLOC(size, align)
void q_enqueue(queue_t *qb, queue_t *item)
queue_t * q_deqnext(queue_t *qb)
void ohci_dumptdchain(ohci_softc_t *, ohci_td_t *td)
#define OHCI_FLUSH_RANGE(s, l)
void ohci_dumprhstat(uint32_t reg)
void ohci_dumpdoneq(ohci_softc_t *softc)
void ohci_dumpportstat(int idx, uint32_t reg)
#define ohci_td_from_transfer(softc, transfer)
#define OHCI_INVAL_RANGE(s, l)
#define ohci_ed_from_endpoint(softc, endpoint)
#define OHCI_READCSR(softc, x)
void ohci_dumptd(ohci_softc_t *, ohci_td_t *td)
#define OHCI_WRITECSR(softc, x, y)
void ohci_dumped(ohci_softc_t *, ohci_ed_t *ed)
void ohci_dumpedchain(ohci_softc_t *, ohci_ed_t *ed)
#define ohci_transfer_from_td(softc, td)
#define M_OHCI_CMDSTATUS_HCR
#define M_OHCI_ED_LOWSPEED
#define M_OHCI_RHSTATUS_OCIC
#define M_OHCI_RHPORTSTAT_PESC
#define G_OHCI_FMINTERVAL_FI(x)
#define M_OHCI_RHPORTSTAT_POCI
#define OHCI_INTTABLE_SIZE
#define R_OHCI_RHPORTSTATUS(x)
#define R_OHCI_FMINTERVAL
#define M_OHCI_RHPORTSTAT_ALLC
#define K_OHCI_TD_DT_TCARRY
#define K_OHCI_TD_DT_DATA1
#define K_OHCI_CC_NOTACCESSED
#define M_OHCI_CONTROL_CLE
#define M_OHCI_CONTROL_PLE
#define G_OHCI_RHDSCRA_POTPGT(x)
#define K_OHCI_TD_DT_DATA0
#define OHCI_CALC_FSMPS(x)
#define M_OHCI_ED_PTRMASK
#define M_OHCI_RHPORTSTAT_OCIC
#define V_OHCI_CONTROL_HCFS(x)
#define M_OHCI_RHDSCRA_PSM
#define M_OHCI_CONTROL_BLE
#define K_OHCI_ED_DIR_OUT
#define M_OHCI_RHSTATUS_OCI
#define K_OHCI_HCFS_RESET
#define V_OHCI_CONTROL_CBSR(x)
#define V_OHCI_FMINTERVAL_FI(x)
#define G_OHCI_RHDSCRA_NDP(x)
#define K_OHCI_ED_DIR_FROMTD
#define M_OHCI_RHSTATUS_LPS
#define M_OHCI_RHPORTSTAT_PRS
#define M_OHCI_CMDSTATUS_CLF
#define M_OHCI_ED_ISOCFMT
#define M_OHCI_RHSTATUS_LPSC
#define M_OHCI_RHPORTSTAT_PSS
#define R_OHCI_PERIODICSTART
#define OHCI_INTTREE_SIZE
#define M_OHCI_RHPORTSTAT_CCS
#define M_OHCI_CONTROL_IE
#define R_OHCI_INTDISABLE
#define M_OHCI_RHPORTSTAT_LSDA
#define M_OHCI_FMINTERVAL_FIT
#define V_OHCI_FMINTERVAL_FSMPS(x)
#define M_OHCI_RHPORTSTAT_CSC
#define M_OHCI_RHPORTSTAT_PPS
#define K_OHCI_HCFS_OPERATIONAL
#define M_OHCI_RHDSCRA_NPS
#define R_OHCI_BULKHEADED
#define R_OHCI_CONTROLHEADED
#define M_OHCI_RHPORTSTAT_PES
#define M_OHCI_CMDSTATUS_BLF
#define K_OHCI_CC_CANCELLED
#define M_OHCI_ED_TOGGLECARRY
#define M_OHCI_RHSTATUS_DRWE
#define M_OHCI_RHPORTSTAT_PRSC
#define M_OHCI_TD_SHORTOK
#define M_OHCI_RHPORTSTAT_PSSC
struct ohci_endpoint_s * ep_next
uint32_t hcca_inttable[OHCI_INTTABLE_SIZE]
ohci_endpoint_t * ohci_endpoint_pool
ohci_td_t * ohci_hwtdpool
ohci_endpoint_t * ohci_inttable[OHCI_INTTABLE_SIZE]
ohci_transfer_t * ohci_transfer_pool
ohci_ed_t * ohci_hwedpool
volatile uint32_t * ohci_regs
ohci_endpoint_t * ohci_ctl_list
ohci_endpoint_t * ohci_isoc_list
ohci_transfer_t * ohci_transfer_freelist
ohci_endpoint_t * ohci_edtable[OHCI_INTTREE_SIZE]
ohci_endpoint_t * ohci_bulk_list
ohci_endpoint_t * ohci_endpoint_freelist
struct ohci_transfer_s * t_next
uint8_t bDescriptorLength
uint8_t bRemoveAndPowerMask[64]
uint8_t bPowerOnToPowerGood
usb_ept_t * up_hwendpoint
struct usb_config_descr_s usb_config_descr_t
#define GETUSBFIELD(s, f)
#define USB_REQUEST_GET_STATUS
#define USB_GETSTATUS_SELF_POWERED
#define USB_REQUEST_GET_INTERFACE
#define USB_PORT_FEATURE_C_PORT_OVER_CURRENT
#define USB_ENDPOINT_TYPE_INTERRUPT
#define USB_PORT_FEATURE_C_PORT_CONNECTION
#define PUTUSBFIELD(s, f, v)
#define USB_REQUEST_GET_CONFIGURATION
#define USB_REQUEST_GET_DESCRIPTOR
#define USB_REQUEST_SET_DESCRIPTOR
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
#define USB_ENDPOINT_DESCRIPTOR_TYPE
#define REQCODE(req, dir, type, rec)
#define USB_HUB_DESCR_SIZE
#define USB_PORT_FEATURE_CONNECTION
#define USB_PORT_FEATURE_SUSPEND
struct usb_device_descr_s usb_device_descr_t
#define USB_DEVICE_DESCRIPTOR_TYPE
#define USBREQ_REC_ENDPOINT
#define USB_PORT_FEATURE_OVER_CURRENT
#define USB_PORT_FEATURE_C_PORT_RESET
#define USB_PORT_FEATURE_C_PORT_SUSPEND
#define USB_PORT_FEATURE_ENABLE
#define USB_PORT_FEATURE_LOW_SPEED
#define USB_PORT_FEATURE_RESET
#define USB_CONFIG_SELF_POWERED
#define USB_REQUEST_SYNC_FRAME
#define USB_ENDPOINT_DIRECTION_IN
#define USB_HUBCHAR_PWR_NONE
struct usb_endpoint_descr_s usb_endpoint_descr_t
#define USB_REQUEST_SET_FEATURE
#define USBREQ_TYPE_CLASS
#define USB_PORT_FEATURE_POWER
#define USBREQ_REC_DEVICE
#define USB_REQUEST_SET_CONFIGURATION
#define USB_HUB_DESCRIPTOR_TYPE
#define USB_STRING_DESCRIPTOR_TYPE
#define USB_DEVICE_CLASS_HUB
#define USB_REQUEST_CLEAR_FEATURE
struct usb_interface_descr_s usb_interface_descr_t
#define USB_REQUEST_SET_ADDRESS
#define USB_INTERFACE_DESCRIPTOR_TYPE
#define USB_PORT_FEATURE_C_PORT_ENABLE
#define USB_HUBCHAR_PWR_GANGED
#define USB_INTERFACE_CLASS_HUB
#define USBREQ_REC_INTERFACE
#define USB_HUBCHAR_PWR_IND
#define USB_REQUEST_SET_INTERFACE
void usb_complete_request(usbreq_t *ur, int status)
void usb_delay_ms(usbbus_t *bus, int ms)
#define UR_FLAG_STATUS_IN
struct usb_ept_s usb_ept_t
#define UR_FLAG_STATUS_OUT