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

OHCI: remove uses of hcd->state

This patch (as1500) removes all uses of the objectionable hcd->state
variable from the ohci-hcd family of drivers. It is replaced by a
private ohci->rh_state field, just as in uhci-hcd and ehci-hcd.

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
b7463c71 c6249ff7

+45 -49
+1 -4
drivers/usb/host/ohci-au1xxx.c
··· 173 173 * mark HW unaccessible, bail out if RH has been resumed. Use 174 174 * the spinlock to properly synchronize with possible pending 175 175 * RH suspend or resume activity. 176 - * 177 - * This is still racy as hcd->state is manipulated outside of 178 - * any locks =P But that will be a different fix. 179 176 */ 180 177 spin_lock_irqsave(&ohci->lock, flags); 181 - if (hcd->state != HC_STATE_SUSPENDED) { 178 + if (ohci->rh_state != OHCI_RH_SUSPENDED) { 182 179 rc = -EINVAL; 183 180 goto bail; 184 181 }
+16 -2
drivers/usb/host/ohci-dbg.c
··· 127 127 return "?"; 128 128 } 129 129 130 + static const char *rh_state_string(struct ohci_hcd *ohci) 131 + { 132 + switch (ohci->rh_state) { 133 + case OHCI_RH_HALTED: 134 + return "halted"; 135 + case OHCI_RH_SUSPENDED: 136 + return "suspended"; 137 + case OHCI_RH_RUNNING: 138 + return "running"; 139 + } 140 + return "?"; 141 + } 142 + 130 143 // dump control and status registers 131 144 static void 132 145 ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size) ··· 149 136 150 137 temp = ohci_readl (controller, &regs->revision) & 0xff; 151 138 ohci_dbg_sw (controller, next, size, 152 - "OHCI %d.%d, %s legacy support registers\n", 139 + "OHCI %d.%d, %s legacy support registers, rh state %s\n", 153 140 0x03 & (temp >> 4), (temp & 0x0f), 154 - (temp & 0x0100) ? "with" : "NO"); 141 + (temp & 0x0100) ? "with" : "NO", 142 + rh_state_string(controller)); 155 143 156 144 temp = ohci_readl (controller, &regs->control); 157 145 ohci_dbg_sw (controller, next, size,
-2
drivers/usb/host/ohci-ep93xx.c
··· 179 179 ohci->next_statechange = jiffies; 180 180 181 181 ep93xx_stop_hc(&pdev->dev); 182 - hcd->state = HC_STATE_SUSPENDED; 183 - 184 182 return 0; 185 183 } 186 184
+13 -13
drivers/usb/host/ohci-hcd.c
··· 209 209 retval = -ENODEV; 210 210 goto fail; 211 211 } 212 - if (!HC_IS_RUNNING(hcd->state)) { 212 + if (ohci->rh_state != OHCI_RH_RUNNING) { 213 213 retval = -ENODEV; 214 214 goto fail; 215 215 } ··· 274 274 rc = usb_hcd_check_unlink_urb(hcd, urb, status); 275 275 if (rc) { 276 276 ; /* Do nothing */ 277 - } else if (HC_IS_RUNNING(hcd->state)) { 277 + } else if (ohci->rh_state == OHCI_RH_RUNNING) { 278 278 urb_priv_t *urb_priv; 279 279 280 280 /* Unless an IRQ completed the unlink while it was being ··· 321 321 rescan: 322 322 spin_lock_irqsave (&ohci->lock, flags); 323 323 324 - if (!HC_IS_RUNNING (hcd->state)) { 324 + if (ohci->rh_state != OHCI_RH_RUNNING) { 325 325 sanitize: 326 326 ed->state = ED_IDLE; 327 327 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) ··· 377 377 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 378 378 ohci->hc_control &= OHCI_CTRL_RWC; 379 379 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 380 + ohci->rh_state = OHCI_RH_HALTED; 380 381 } 381 382 382 383 /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and ··· 504 503 if (distrust_firmware) 505 504 ohci->flags |= OHCI_QUIRK_HUB_POWER; 506 505 507 - disable (ohci); 506 + ohci->rh_state = OHCI_RH_HALTED; 508 507 ohci->regs = hcd->regs; 509 508 510 509 /* REVISIT this BIOS handshake is now moved into PCI "quirks", and ··· 579 578 int first = ohci->fminterval == 0; 580 579 struct usb_hcd *hcd = ohci_to_hcd(ohci); 581 580 582 - disable (ohci); 581 + ohci->rh_state = OHCI_RH_HALTED; 583 582 584 583 /* boot firmware should have set this up (5.1.1.3.1) */ 585 584 if (first) { ··· 692 691 ohci->hc_control &= OHCI_CTRL_RWC; 693 692 ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 694 693 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 695 - hcd->state = HC_STATE_RUNNING; 694 + ohci->rh_state = OHCI_RH_RUNNING; 696 695 697 696 /* wake on ConnectStatusChange, matching external hubs */ 698 697 ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status); ··· 729 728 730 729 // POTPGT delay is bits 24-31, in 2 ms units. 731 730 mdelay ((val >> 23) & 0x1fe); 732 - hcd->state = HC_STATE_RUNNING; 733 731 734 732 if (quirk_zfmicro(ohci)) { 735 733 /* Create timer to watch for bad queue state on ZF Micro */ ··· 764 764 * of dead, unclocked, or unplugged (CardBus...) devices 765 765 */ 766 766 if (ints == ~(u32)0) { 767 - disable (ohci); 767 + ohci->rh_state = OHCI_RH_HALTED; 768 768 ohci_dbg (ohci, "device removed!\n"); 769 769 usb_hc_died(hcd); 770 770 return IRQ_HANDLED; ··· 774 774 ints &= ohci_readl(ohci, &regs->intrenable); 775 775 776 776 /* interrupt for some other device? */ 777 - if (ints == 0 || unlikely(hcd->state == HC_STATE_HALT)) 777 + if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED)) 778 778 return IRQ_NOTMINE; 779 779 780 780 if (ints & OHCI_INTR_UE) { ··· 789 789 790 790 schedule_work (&ohci->nec_work); 791 791 } else { 792 - disable (ohci); 793 792 ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); 793 + ohci->rh_state = OHCI_RH_HALTED; 794 794 usb_hc_died(hcd); 795 795 } 796 796 ··· 874 874 if ((ints & OHCI_INTR_SF) != 0 875 875 && !ohci->ed_rm_list 876 876 && !ohci->ed_to_check 877 - && HC_IS_RUNNING(hcd->state)) 877 + && ohci->rh_state == OHCI_RH_RUNNING) 878 878 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable); 879 879 spin_unlock (&ohci->lock); 880 880 881 - if (HC_IS_RUNNING(hcd->state)) { 881 + if (ohci->rh_state == OHCI_RH_RUNNING) { 882 882 ohci_writel (ohci, ints, &regs->intrstatus); 883 883 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable); 884 884 // flush those writes ··· 932 932 struct urb_priv *priv; 933 933 934 934 spin_lock_irq(&ohci->lock); 935 - disable (ohci); 935 + ohci->rh_state = OHCI_RH_HALTED; 936 936 937 937 /* Recycle any "live" eds/tds (and urbs). */ 938 938 if (!list_empty (&ohci->pending))
+3 -4
drivers/usb/host/ohci-hub.c
··· 111 111 if (!autostop) { 112 112 ohci->next_statechange = jiffies + msecs_to_jiffies (5); 113 113 ohci->autostop = 0; 114 + ohci->rh_state = OHCI_RH_SUSPENDED; 114 115 } 115 116 116 117 done: ··· 141 140 142 141 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 143 142 /* this can happen after resuming a swsusp snapshot */ 144 - if (hcd->state == HC_STATE_RESUMING) { 143 + if (ohci->rh_state != OHCI_RH_RUNNING) { 145 144 ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 146 145 ohci->hc_control); 147 146 status = -EBUSY; ··· 275 274 (void) ohci_readl (ohci, &ohci->regs->control); 276 275 } 277 276 277 + ohci->rh_state = OHCI_RH_RUNNING; 278 278 return 0; 279 279 } 280 280 ··· 338 336 /* If needed, reinitialize and suspend the root hub */ 339 337 if (need_reinit) { 340 338 spin_lock_irq(&ohci->lock); 341 - hcd->state = HC_STATE_RESUMING; 342 339 ohci_rh_resume(ohci); 343 - hcd->state = HC_STATE_QUIESCING; 344 340 ohci_rh_suspend(ohci, 0); 345 - hcd->state = HC_STATE_SUSPENDED; 346 341 spin_unlock_irq(&ohci->lock); 347 342 } 348 343
-1
drivers/usb/host/ohci-omap.c
··· 516 516 ohci->next_statechange = jiffies; 517 517 518 518 omap_ohci_clock_power(0); 519 - ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 520 519 return 0; 521 520 } 522 521
+1 -4
drivers/usb/host/ohci-pci.c
··· 334 334 * mark HW unaccessible, bail out if RH has been resumed. Use 335 335 * the spinlock to properly synchronize with possible pending 336 336 * RH suspend or resume activity. 337 - * 338 - * This is still racy as hcd->state is manipulated outside of 339 - * any locks =P But that will be a different fix. 340 337 */ 341 338 spin_lock_irqsave (&ohci->lock, flags); 342 - if (hcd->state != HC_STATE_SUSPENDED) { 339 + if (ohci->rh_state != OHCI_RH_SUSPENDED) { 343 340 rc = -EINVAL; 344 341 goto bail; 345 342 }
-2
drivers/usb/host/ohci-pxa27x.c
··· 502 502 ohci->ohci.next_statechange = jiffies; 503 503 504 504 pxa27x_stop_hc(ohci, dev); 505 - hcd->state = HC_STATE_SUSPENDED; 506 - 507 505 return 0; 508 506 } 509 507
+3 -5
drivers/usb/host/ohci-q.c
··· 912 912 /* only take off EDs that the HC isn't using, accounting for 913 913 * frame counter wraps and EDs with partially retired TDs 914 914 */ 915 - if (likely (HC_IS_RUNNING(ohci_to_hcd(ohci)->state))) { 915 + if (likely(ohci->rh_state == OHCI_RH_RUNNING)) { 916 916 if (tick_before (tick, ed->tick)) { 917 917 skip_ed: 918 918 last = &ed->ed_next; ··· 1012 1012 1013 1013 /* but if there's work queued, reschedule */ 1014 1014 if (!list_empty (&ed->td_list)) { 1015 - if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state)) 1015 + if (ohci->rh_state == OHCI_RH_RUNNING) 1016 1016 ed_schedule (ohci, ed); 1017 1017 } 1018 1018 ··· 1021 1021 } 1022 1022 1023 1023 /* maybe reenable control and bulk lists */ 1024 - if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state) 1025 - && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING 1026 - && !ohci->ed_rm_list) { 1024 + if (ohci->rh_state == OHCI_RH_RUNNING && !ohci->ed_rm_list) { 1027 1025 u32 command = 0, control = 0; 1028 1026 1029 1027 if (ohci->ed_controltail) {
-1
drivers/usb/host/ohci-sh.c
··· 29 29 ohci_hcd_init(ohci); 30 30 ohci_init(ohci); 31 31 ohci_run(ohci); 32 - hcd->state = HC_STATE_RUNNING; 33 32 return 0; 34 33 } 35 34
-1
drivers/usb/host/ohci-sm501.c
··· 224 224 ohci->next_statechange = jiffies; 225 225 226 226 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); 227 - ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 228 227 return 0; 229 228 } 230 229
-1
drivers/usb/host/ohci-spear.c
··· 203 203 ohci->next_statechange = jiffies; 204 204 205 205 spear_stop_ohci(ohci_p); 206 - ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED; 207 206 return 0; 208 207 } 209 208
-3
drivers/usb/host/ohci-tmio.c
··· 318 318 if (ret) 319 319 return ret; 320 320 } 321 - 322 - hcd->state = HC_STATE_SUSPENDED; 323 - 324 321 return 0; 325 322 } 326 323
+8 -6
drivers/usb/host/ohci.h
··· 344 344 * a subset of what the full implementation needs. (Linus) 345 345 */ 346 346 347 + enum ohci_rh_state { 348 + OHCI_RH_HALTED, 349 + OHCI_RH_SUSPENDED, 350 + OHCI_RH_RUNNING 351 + }; 352 + 347 353 struct ohci_hcd { 348 354 spinlock_t lock; 349 355 ··· 390 384 /* 391 385 * driver state 392 386 */ 387 + enum ohci_rh_state rh_state; 393 388 int num_ports; 394 389 int load [NUM_INTS]; 395 390 u32 hc_control; /* copy of hc control reg */ ··· 687 680 688 681 /*-------------------------------------------------------------------------*/ 689 682 690 - static inline void disable (struct ohci_hcd *ohci) 691 - { 692 - ohci_to_hcd(ohci)->state = HC_STATE_HALT; 693 - } 694 - 695 683 #define FI 0x2edf /* 12000 bits per frame (-1) */ 696 684 #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7)) 697 685 #define FIT (1 << 31) ··· 710 708 #define read_roothub(hc, register, mask) ({ \ 711 709 u32 temp = ohci_readl (hc, &hc->regs->roothub.register); \ 712 710 if (temp == -1) \ 713 - disable (hc); \ 711 + hc->rh_state = OHCI_RH_HALTED; \ 714 712 else if (hc->flags & OHCI_QUIRK_AMD756) \ 715 713 while (temp & mask) \ 716 714 temp = ohci_readl (hc, &hc->regs->roothub.register); \