Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

UHCI: Add macros for computing DMA values

This patch (as855) adds some convenience macros to uhci-hcd, to help
simplify the code for computing hardware DMA pointers.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
28b9325e d0374f4f

+33 -36
+4 -5
drivers/usb/host/uhci-debug.c
··· 196 196 struct uhci_td *td = list_entry(urbp->td_list.next, 197 197 struct uhci_td, list); 198 198 199 - if (cpu_to_le32(td->dma_handle) != (element & ~UHCI_PTR_BITS)) 199 + if (element != LINK_TO_TD(td)) 200 200 out += sprintf(out, "%*s Element != First TD\n", 201 201 space, ""); 202 202 i = nurbs = 0; ··· 393 393 do { 394 394 td = list_entry(tmp, struct uhci_td, fl_list); 395 395 tmp = tmp->next; 396 - if (cpu_to_le32(td->dma_handle) != link) { 396 + if (link != LINK_TO_TD(td)) { 397 397 if (nframes > 0) 398 398 out += sprintf(out, " link does " 399 399 "not match list entry!\n"); ··· 440 440 if (qh->link != UHCI_PTR_TERM) 441 441 out += sprintf(out, " bandwidth reclamation on!\n"); 442 442 443 - if (qh_element(qh) != cpu_to_le32(uhci->term_td->dma_handle)) 443 + if (qh_element(qh) != LINK_TO_TD(uhci->term_td)) 444 444 out += sprintf(out, " skel_term_qh element is not set to term_td!\n"); 445 445 446 446 continue; ··· 461 461 out += sprintf(out, " Skipped %d QHs\n", cnt); 462 462 463 463 if (i > 1 && i < UHCI_NUM_SKELQH - 1) { 464 - if (qh->link != 465 - (cpu_to_le32(uhci->skelqh[j]->dma_handle) | UHCI_PTR_QH)) 464 + if (qh->link != LINK_TO_QH(uhci->skelqh[j])) 466 465 out += sprintf(out, " last QH not linked to next skeleton!\n"); 467 466 } 468 467 }
+9 -13
drivers/usb/host/uhci-hcd.c
··· 116 116 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); 117 117 if (skelnum <= 1) 118 118 skelnum = 9; 119 - return UHCI_PTR_QH | cpu_to_le32(uhci->skelqh[skelnum]->dma_handle); 119 + return LINK_TO_QH(uhci->skelqh[skelnum]); 120 120 } 121 121 122 122 #include "uhci-debug.c" ··· 635 635 uhci->skel_int16_qh->link = 636 636 uhci->skel_int8_qh->link = 637 637 uhci->skel_int4_qh->link = 638 - uhci->skel_int2_qh->link = UHCI_PTR_QH | 639 - cpu_to_le32(uhci->skel_int1_qh->dma_handle); 638 + uhci->skel_int2_qh->link = LINK_TO_QH( 639 + uhci->skel_int1_qh); 640 640 641 - uhci->skel_int1_qh->link = UHCI_PTR_QH | 642 - cpu_to_le32(uhci->skel_ls_control_qh->dma_handle); 643 - uhci->skel_ls_control_qh->link = UHCI_PTR_QH | 644 - cpu_to_le32(uhci->skel_fs_control_qh->dma_handle); 645 - uhci->skel_fs_control_qh->link = UHCI_PTR_QH | 646 - cpu_to_le32(uhci->skel_bulk_qh->dma_handle); 647 - uhci->skel_bulk_qh->link = UHCI_PTR_QH | 648 - cpu_to_le32(uhci->skel_term_qh->dma_handle); 641 + uhci->skel_int1_qh->link = LINK_TO_QH(uhci->skel_ls_control_qh); 642 + uhci->skel_ls_control_qh->link = LINK_TO_QH(uhci->skel_fs_control_qh); 643 + uhci->skel_fs_control_qh->link = LINK_TO_QH(uhci->skel_bulk_qh); 644 + uhci->skel_bulk_qh->link = LINK_TO_QH(uhci->skel_term_qh); 649 645 650 646 /* This dummy TD is to work around a bug in Intel PIIX controllers */ 651 647 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | 652 648 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); 653 - uhci->term_td->link = cpu_to_le32(uhci->term_td->dma_handle); 649 + uhci->term_td->link = LINK_TO_TD(uhci->term_td); 654 650 655 651 uhci->skel_term_qh->link = UHCI_PTR_TERM; 656 - uhci->skel_term_qh->element = cpu_to_le32(uhci->term_td->dma_handle); 652 + uhci->skel_term_qh->element = LINK_TO_TD(uhci->term_td); 657 653 658 654 /* 659 655 * Fill the frame list: make all entries point to the proper
+6 -2
drivers/usb/host/uhci-hcd.h
··· 129 129 __le32 element; /* Queue element (TD) pointer */ 130 130 131 131 /* Software fields */ 132 + dma_addr_t dma_handle; 133 + 132 134 struct list_head node; /* Node in the list of QHs */ 133 135 struct usb_host_endpoint *hep; /* Endpoint information */ 134 136 struct usb_device *udev; ··· 152 150 int state; /* QH_STATE_xxx; see above */ 153 151 int type; /* Queue type (control, bulk, etc) */ 154 152 155 - dma_addr_t dma_handle; 156 - 157 153 unsigned int initial_toggle:1; /* Endpoint's current toggle value */ 158 154 unsigned int needs_fixup:1; /* Must fix the TD toggle values */ 159 155 unsigned int is_stopped:1; /* Queue was stopped by error/unlink */ ··· 170 170 barrier(); 171 171 return element; 172 172 } 173 + 174 + #define LINK_TO_QH(qh) (UHCI_PTR_QH | cpu_to_le32((qh)->dma_handle)) 173 175 174 176 175 177 /* ··· 265 263 barrier(); 266 264 return le32_to_cpu(status); 267 265 } 266 + 267 + #define LINK_TO_TD(td) (cpu_to_le32((td)->dma_handle)) 268 268 269 269 270 270 /*
+14 -16
drivers/usb/host/uhci-q.c
··· 46 46 static void uhci_fsbr_on(struct uhci_hcd *uhci) 47 47 { 48 48 uhci->fsbr_is_on = 1; 49 - uhci->skel_term_qh->link = cpu_to_le32( 50 - uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; 49 + uhci->skel_term_qh->link = LINK_TO_QH(uhci->skel_fs_control_qh); 51 50 } 52 51 53 52 static void uhci_fsbr_off(struct uhci_hcd *uhci) ··· 157 158 158 159 td->link = ltd->link; 159 160 wmb(); 160 - ltd->link = cpu_to_le32(td->dma_handle); 161 + ltd->link = LINK_TO_TD(td); 161 162 } else { 162 163 td->link = uhci->frame[framenum]; 163 164 wmb(); 164 - uhci->frame[framenum] = cpu_to_le32(td->dma_handle); 165 + uhci->frame[framenum] = LINK_TO_TD(td); 165 166 uhci->frame_cpu[framenum] = td; 166 167 } 167 168 } ··· 183 184 struct uhci_td *ntd; 184 185 185 186 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); 186 - uhci->frame[td->frame] = cpu_to_le32(ntd->dma_handle); 187 + uhci->frame[td->frame] = LINK_TO_TD(ntd); 187 188 uhci->frame_cpu[td->frame] = ntd; 188 189 } 189 190 } else { ··· 420 421 struct uhci_td *td = list_entry(urbp->td_list.next, 421 422 struct uhci_td, list); 422 423 423 - qh->element = cpu_to_le32(td->dma_handle); 424 + qh->element = LINK_TO_TD(td); 424 425 } 425 426 426 427 /* Treat the queue as if it has just advanced */ ··· 442 443 pqh = list_entry(qh->node.prev, struct uhci_qh, node); 443 444 qh->link = pqh->link; 444 445 wmb(); 445 - pqh->link = UHCI_PTR_QH | cpu_to_le32(qh->dma_handle); 446 + pqh->link = LINK_TO_QH(qh); 446 447 } 447 448 448 449 /* ··· 736 737 td = uhci_alloc_td(uhci); 737 738 if (!td) 738 739 goto nomem; 739 - *plink = cpu_to_le32(td->dma_handle); 740 + *plink = LINK_TO_TD(td); 740 741 741 742 /* Alternate Data0/1 (start with Data1) */ 742 743 destination ^= TD_TOKEN_TOGGLE; ··· 756 757 td = uhci_alloc_td(uhci); 757 758 if (!td) 758 759 goto nomem; 759 - *plink = cpu_to_le32(td->dma_handle); 760 + *plink = LINK_TO_TD(td); 760 761 761 762 /* 762 763 * It's IN if the pipe is an output pipe or we're not expecting ··· 783 784 td = uhci_alloc_td(uhci); 784 785 if (!td) 785 786 goto nomem; 786 - *plink = cpu_to_le32(td->dma_handle); 787 + *plink = LINK_TO_TD(td); 787 788 788 789 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 789 790 wmb(); ··· 859 860 td = uhci_alloc_td(uhci); 860 861 if (!td) 861 862 goto nomem; 862 - *plink = cpu_to_le32(td->dma_handle); 863 + *plink = LINK_TO_TD(td); 863 864 } 864 865 uhci_add_td_to_urbp(td, urbp); 865 866 uhci_fill_td(td, status, ··· 887 888 td = uhci_alloc_td(uhci); 888 889 if (!td) 889 890 goto nomem; 890 - *plink = cpu_to_le32(td->dma_handle); 891 + *plink = LINK_TO_TD(td); 891 892 892 893 uhci_add_td_to_urbp(td, urbp); 893 894 uhci_fill_td(td, status, ··· 913 914 td = uhci_alloc_td(uhci); 914 915 if (!td) 915 916 goto nomem; 916 - *plink = cpu_to_le32(td->dma_handle); 917 + *plink = LINK_TO_TD(td); 917 918 918 919 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 919 920 wmb(); ··· 1004 1005 * the queue at the status stage transaction, which is 1005 1006 * the last TD. */ 1006 1007 WARN_ON(list_empty(&urbp->td_list)); 1007 - qh->element = cpu_to_le32(td->dma_handle); 1008 + qh->element = LINK_TO_TD(td); 1008 1009 tmp = td->list.prev; 1009 1010 ret = -EINPROGRESS; 1010 1011 ··· 1565 1566 if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { 1566 1567 1567 1568 /* Detect the Intel bug and work around it */ 1568 - if (qh->post_td && qh_element(qh) == 1569 - cpu_to_le32(qh->post_td->dma_handle)) { 1569 + if (qh->post_td && qh_element(qh) == LINK_TO_TD(qh->post_td)) { 1570 1570 qh->element = qh->post_td->link; 1571 1571 qh->advance_jiffies = jiffies; 1572 1572 ret = 1;