+ edhead->tdcount--;
+ }
+
+ n = next;
+ prev = 0;
+ while(virt_to_phys(n)) {
+#ifdef _DU_OHCI_F
+ dump_address(n, sizeof(struct general_td), "n(after)");
+#endif
+ if(n->buflen > 0) {
+ sync_before_read((void*) n->bufaddr, n->buflen);
+#ifdef _DU_OHCI_F
+ dump_address((void*) n->bufaddr, n->buflen, "n->bufaddr(after)");
+#endif
+ }
+#ifdef _DU_OHCI_F
+ dbg_td_flag(LE(n->flags));
+#endif
+ prev = n;
+ n = (struct general_td*) n->nexttd;
+ free(prev);
+ }
+
+out:
+ set_target_hcca(reg);
+ sync_before_read(hcca, sizeof(struct ohci_hcca));
+
+ u8 jtmp;
+ switch(edhead->type) {
+ case USB_CTRL:
+ write32(reg+OHCI_HC_CONTROL, read32(reg+OHCI_HC_CONTROL)&~OHCI_CTRL_CLE);
+ break;
+
+ case USB_INTR:
+ write32(reg+OHCI_HC_CONTROL, read32(reg+OHCI_HC_CONTROL)&~OHCI_CTRL_PLE);
+ for(jtmp = 0; jtmp < NUM_INITS; jtmp++) {
+ hcca->int_table[jtmp] = 0;
+ }
+ break;
+
+ case USB_BULK:
+ write32(reg+OHCI_HC_CONTROL, read32(reg+OHCI_HC_CONTROL)&~OHCI_CTRL_BLE);
+ break;
+
+ case USB_ISOC:
+ break;
+ }
+
+ hcca->done_head = 0;
+ sync_after_write(hcca, sizeof(struct ohci_hcca));
+
+ edhead = 0;
+
+#ifdef _DU_OHCI_F
+ printf("<^> <^> <^> hcdi_fire(end)\n");
+#endif
+}
+
+/**
+ * Enqueue a transfer descriptor.
+ */
+u8 hcdi_enqueue(const struct usb_transfer_descriptor *td, u32 reg) {
+#ifdef _DU_OHCI_Q
+ printf("*()*()*()*()*()*()*() hcdi_enqueue(start)\n");
+#endif
+ if(!edhead) {
+ edhead = &_edhead;
+ memset(edhead, 0, sizeof(struct endpoint_descriptor));
+ edhead->flags = LE(OHCI_ENDPOINT_GENERAL_FORMAT);
+ edhead->headp = edhead->tailp = edhead->nexted = LE(0);
+ if(td->fullspeed) {
+ edhead->flags |= LE(OHCI_ENDPOINT_FULL_SPEED);
+ } else {
+ edhead->flags |= LE(OHCI_ENDPOINT_LOW_SPEED);
+ }
+ edhead->flags |= LE(OHCI_ENDPOINT_SET_DEVICE_ADDRESS(td->devaddress) |
+ OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(td->endpoint) |
+ OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(td->maxp));
+ edhead->tdcount = 0;
+ edhead->type = td->type;
+ }
+
+ struct general_td *tdhw = allocate_general_td();
+ general_td_fill(tdhw, td);
+ edhead->tdcount ++;
+
+ if(!edhead->headp) {
+ /* first transfer */
+ edhead->headp = LE(virt_to_phys((void*) ((u32)tdhw & OHCI_ENDPOINT_HEAD_MASK)));
+ }
+ else {
+ /* headp in endpoint already exists
+ * => go to list end
+ */
+ struct general_td *n = (struct general_td*) phys_to_virt(LE(edhead->headp) & OHCI_ENDPOINT_HEAD_MASK);
+ while(LE(n->nexttd)) {
+ n = phys_to_virt(LE(n->nexttd));
+ }
+ n->nexttd = LE(virt_to_phys((void*) ((u32)tdhw & OHCI_ENDPOINT_HEAD_MASK)));
+#ifdef _DU_OHCI_Q
+ printf("n: 0x%08X\n", n);
+ printf("n->nexttd: 0x%08X\n", phys_to_virt(LE(n->nexttd)));
+#endif
+ }
+
+#ifdef _DU_OHCI_Q
+ printf("*()*()*()*()*()*()*() hcdi_enqueue(end)\n");