USB: convert usb_hcd bitfields into atomic flags
authorAlan Stern <stern@rowland.harvard.edu>
Tue, 22 Jun 2010 20:39:10 +0000 (16:39 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 10 Aug 2010 21:35:37 +0000 (14:35 -0700)
This patch (as1393) converts several of the single-bit fields in
struct usb_hcd to atomic flags.  This is for safety's sake; not all
CPUs can update bitfield values atomically, and these flags are used
in multiple contexts.

The flag fields that are set only during registration or removal can
remain as they are, since non-atomic accesses at those times will not
cause any problems.

(Strictly speaking, the authorized_default flag should become atomic
as well.  I didn't bother with it because it gets changed only via
sysfs.  It can be done later, if anyone wants.)

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
21 files changed:
drivers/staging/usbip/vhci_hcd.c
drivers/usb/c67x00/c67x00-hcd.c
drivers/usb/core/hcd.c
drivers/usb/gadget/dummy_hcd.c
drivers/usb/host/ehci-dbg.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-hub.c
drivers/usb/host/ehci-q.c
drivers/usb/host/ehci-sched.c
drivers/usb/host/hwa-hc.c
drivers/usb/host/isp1760-hcd.c
drivers/usb/host/ohci-dbg.c
drivers/usb/host/ohci-hcd.c
drivers/usb/host/ohci-hub.c
drivers/usb/host/oxu210hp-hcd.c
drivers/usb/host/uhci-hcd.c
drivers/usb/host/uhci-hub.c
drivers/usb/host/whci/hcd.c
drivers/usb/host/xhci.c
drivers/usb/musb/musb_virthub.c
include/linux/usb/hcd.h

index be5d8db9816509338a181f09814649aa67f35fc3..0574d848b9000045c48b6b618b80a5e34b888205 100644 (file)
@@ -215,7 +215,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
        vhci = hcd_to_vhci(hcd);
 
        spin_lock_irqsave(&vhci->lock, flags);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                usbip_dbg_vhci_rh("hw accessible flag in on?\n");
                goto done;
        }
@@ -269,7 +269,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 
        u32 prev_port_status[VHCI_NPORTS];
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                return -ETIMEDOUT;
 
        /*
@@ -1041,7 +1041,7 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
        dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
 
        spin_lock_irq(&vhci->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                rc = -ESHUTDOWN;
        } else {
                /* vhci->rh_state = DUMMY_RH_RUNNING;
index a22b887f4e9ef05d27c4425cbba18885f125f639..d3e1356d091e57224f983d14bd727e7bf64c7d22 100644 (file)
@@ -264,7 +264,7 @@ static void c67x00_hcd_irq(struct c67x00_sie *sie, u16 int_status, u16 msg)
        if (unlikely(hcd->state == HC_STATE_HALT))
                return;
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                return;
 
        /* Handle Start of frame events */
@@ -282,7 +282,7 @@ static int c67x00_hcd_start(struct usb_hcd *hcd)
 {
        hcd->uses_new_polling = 1;
        hcd->state = HC_STATE_RUNNING;
-       hcd->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
 
        return 0;
 }
index 53f14c82ff2e47017f9179159a682a7b97422a63..f2fe7c8e991d77798b0c2ed3f56dcae0040f5766 100644 (file)
@@ -679,7 +679,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
                spin_lock_irqsave(&hcd_root_hub_lock, flags);
                urb = hcd->status_urb;
                if (urb) {
-                       hcd->poll_pending = 0;
+                       clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
                        hcd->status_urb = NULL;
                        urb->actual_length = length;
                        memcpy(urb->transfer_buffer, buffer, length);
@@ -690,7 +690,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
                        spin_lock(&hcd_root_hub_lock);
                } else {
                        length = 0;
-                       hcd->poll_pending = 1;
+                       set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
                }
                spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
        }
@@ -699,7 +699,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
         * exceed that limit if HZ is 100. The math is more clunky than
         * maybe expected, this is to make sure that all timers for USB devices
         * fire at the same time to give the CPU a break inbetween */
-       if (hcd->uses_new_polling ? hcd->poll_rh :
+       if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) :
                        (length == 0 && hcd->status_urb != NULL))
                mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
 }
@@ -736,7 +736,7 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
                mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
 
        /* If a status change has already occurred, report it ASAP */
-       else if (hcd->poll_pending)
+       else if (HCD_POLL_PENDING(hcd))
                mod_timer(&hcd->rh_timer, jiffies);
        retval = 0;
  done:
@@ -1150,8 +1150,7 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
         * finish unlinking the initial failed usb_set_address()
         * or device descriptor fetch.
         */
-       if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) &&
-                       !is_root_hub(urb->dev)) {
+       if (!HCD_SAW_IRQ(hcd) && !is_root_hub(urb->dev)) {
                dev_warn(hcd->self.controller, "Unlink after no-IRQ?  "
                        "Controller is probably using the wrong IRQ.\n");
                set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
@@ -2063,8 +2062,7 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
         */
        local_irq_save(flags);
 
-       if (unlikely(hcd->state == HC_STATE_HALT ||
-                    !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
+       if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) {
                rc = IRQ_NONE;
        } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
                rc = IRQ_NONE;
@@ -2098,7 +2096,7 @@ void usb_hc_died (struct usb_hcd *hcd)
 
        spin_lock_irqsave (&hcd_root_hub_lock, flags);
        if (hcd->rh_registered) {
-               hcd->poll_rh = 0;
+               clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
 
                /* make khubd clean up old urbs and devices */
                usb_set_device_state (hcd->self.root_hub,
@@ -2301,7 +2299,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
                       retval);
                goto error_create_attr_group;
        }
-       if (hcd->uses_new_polling && hcd->poll_rh)
+       if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
                usb_hcd_poll_rh_status(hcd);
        return retval;
 
@@ -2320,11 +2318,11 @@ error_create_attr_group:
        mutex_unlock(&usb_bus_list_lock);
 err_register_root_hub:
        hcd->rh_pollable = 0;
-       hcd->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        del_timer_sync(&hcd->rh_timer);
        hcd->driver->stop(hcd);
        hcd->state = HC_STATE_HALT;
-       hcd->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        del_timer_sync(&hcd->rh_timer);
 err_hcd_driver_start:
        if (hcd->irq >= 0)
@@ -2380,14 +2378,14 @@ void usb_remove_hcd(struct usb_hcd *hcd)
         * the hub_status_data() callback.
         */
        hcd->rh_pollable = 0;
-       hcd->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        del_timer_sync(&hcd->rh_timer);
 
        hcd->driver->stop(hcd);
        hcd->state = HC_STATE_HALT;
 
        /* In case the HCD restarted the timer, stop it again. */
-       hcd->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        del_timer_sync(&hcd->rh_timer);
 
        if (hcd->irq >= 0)
index 4f9e578cde9db01f17ac7ef36778c67c0a4ad089..dc6546248ed99407eefef93ef850b9a5980b23e5 100644 (file)
@@ -1542,7 +1542,7 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
        dum = hcd_to_dummy (hcd);
 
        spin_lock_irqsave (&dum->lock, flags);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                goto done;
 
        if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
@@ -1588,7 +1588,7 @@ static int dummy_hub_control (
        int             retval = 0;
        unsigned long   flags;
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                return -ETIMEDOUT;
 
        dum = hcd_to_dummy (hcd);
@@ -1739,7 +1739,7 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
        dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
 
        spin_lock_irq (&dum->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                rc = -ESHUTDOWN;
        } else {
                dum->rh_state = DUMMY_RH_RUNNING;
index df5546bb83679801d00c9363ba6c57ab89f72a44..4498efb49b95a66cc9cc9e5b08716df860892d02 100644 (file)
@@ -712,7 +712,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
 
        spin_lock_irqsave (&ehci->lock, flags);
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                size = scnprintf (next, size,
                        "bus %s, device %s\n"
                        "%s\n"
index 8697ad19f313c1d9002e2339e2871b18db6bb366..2a19336c9824fce2f5eee44e64df4f82bd4c4510 100644 (file)
@@ -642,7 +642,6 @@ static int ehci_run (struct usb_hcd *hcd)
        u32                     hcc_params;
 
        hcd->uses_new_polling = 1;
-       hcd->poll_rh = 0;
 
        /* EHCI spec section 4.1 */
        if ((retval = ehci_reset(ehci)) != 0) {
index 84e792d71c224c7f7918d8a58446f83a658a084b..0931f5a7dec4c288043fd310b40a327a69197001 100644 (file)
@@ -316,7 +316,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
        if (time_before (jiffies, ehci->next_statechange))
                msleep(5);
        spin_lock_irq (&ehci->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                spin_unlock_irq(&ehci->lock);
                return -ESHUTDOWN;
        }
index 11a79c4f4a9dbb67d5fad13ede3ae86a0c7097f5..233c288e3f931ce4f9399d5b54f25471139f6dfb 100644 (file)
@@ -1126,8 +1126,7 @@ submit_async (
 #endif
 
        spin_lock_irqsave (&ehci->lock, flags);
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                              &ehci_to_hcd(ehci)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                rc = -ESHUTDOWN;
                goto done;
        }
index 805ec633a652643c6952cd4e7b2595f2c9b10815..d640346f9b56b751f64673fbbbd8b918bc09a7ee 100644 (file)
@@ -880,8 +880,7 @@ static int intr_submit (
 
        spin_lock_irqsave (&ehci->lock, flags);
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                       &ehci_to_hcd(ehci)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
                goto done_not_linked;
        }
@@ -1815,8 +1814,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
 
        /* schedule ... need to lock */
        spin_lock_irqsave (&ehci->lock, flags);
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                              &ehci_to_hcd(ehci)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
                goto done_not_linked;
        }
@@ -2201,8 +2199,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
 
        /* schedule ... need to lock */
        spin_lock_irqsave (&ehci->lock, flags);
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                              &ehci_to_hcd(ehci)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
                goto done_not_linked;
        }
index 35742f8c7cdaf714d0562a9a1a5e3ae7a2f5d06e..9bfac657572e2eb4aadb9aaec3899ac887448986 100644 (file)
@@ -159,7 +159,7 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
                goto error_set_cluster_id;
 
        usb_hcd->uses_new_polling = 1;
-       usb_hcd->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
        usb_hcd->state = HC_STATE_RUNNING;
        result = 0;
 out:
@@ -776,7 +776,7 @@ static int hwahc_probe(struct usb_interface *usb_iface,
                goto error_alloc;
        }
        usb_hcd->wireless = 1;
-       usb_hcd->flags |= HCD_FLAG_SAW_IRQ;
+       set_bit(HCD_FLAG_SAW_IRQ, &usb_hcd->flags);
        wusbhc = usb_hcd_to_wusbhc(usb_hcd);
        hwahc = container_of(wusbhc, struct hwahc, wusbhc);
        hwahc_init(hwahc);
index dbcafa29c7753d9a6a41f46f09cb1ab959a3c7d7..d1a3dfc9a40873ea46df2a81668b065d105fb9cc 100644 (file)
@@ -482,7 +482,6 @@ static int isp1760_run(struct usb_hcd *hcd)
        u32 chipid;
 
        hcd->uses_new_polling = 1;
-       hcd->poll_rh = 0;
 
        hcd->state = HC_STATE_RUNNING;
        isp1760_enable_interrupts(hcd);
@@ -1450,7 +1449,7 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
        epnum = urb->ep->desc.bEndpointAddress;
 
        spin_lock_irqsave(&priv->lock, flags);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &priv_to_hcd(priv)->flags)) {
+       if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) {
                rc = -ESHUTDOWN;
                goto done;
        }
index 8ad2441b02848fb071bc8c49fded093ce2bc126a..36abd2baa3ea6671d185a62cbf2918d15410c1df 100644 (file)
@@ -645,7 +645,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
                hcd->product_desc,
                hcd_name);
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                size -= scnprintf (next, size,
                        "SUSPENDED (no register access)\n");
                goto done;
@@ -687,7 +687,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
        next += temp;
 
        temp = scnprintf (next, size, "hub poll timer %s\n",
-                       ohci_to_hcd(ohci)->poll_rh ? "ON" : "off");
+                       HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
        size -= temp;
        next += temp;
 
index 02864a237a2c1b54e91aeb097ab4a4a6212c409e..c3b4ccc7337b54577f6ae0d9c5ab934f9359d27f 100644 (file)
@@ -212,7 +212,7 @@ static int ohci_urb_enqueue (
        spin_lock_irqsave (&ohci->lock, flags);
 
        /* don't submit to a dead HC */
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                retval = -ENODEV;
                goto fail;
        }
@@ -685,7 +685,7 @@ retry:
        }
 
        /* use rhsc irqs after khubd is fully initialized */
-       hcd->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
        hcd->uses_new_polling = 1;
 
        /* start controller operations */
@@ -822,7 +822,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
        else if (ints & OHCI_INTR_RD) {
                ohci_vdbg(ohci, "resume detect\n");
                ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
-               hcd->poll_rh = 1;
+               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
                if (ohci->autostop) {
                        spin_lock (&ohci->lock);
                        ohci_rh_resume (ohci);
index 65cac8cc8921254718d835860a9ad2871d13b823..4dd39022c38846d4e8529b0686b7c311f18b5a74 100644 (file)
@@ -284,7 +284,7 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
 
        spin_lock_irq (&ohci->lock);
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
+       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
                rc = -ESHUTDOWN;
        else
                rc = ohci_rh_suspend (ohci, 0);
@@ -302,7 +302,7 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
 
        spin_lock_irq (&ohci->lock);
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
+       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
                rc = -ESHUTDOWN;
        else
                rc = ohci_rh_resume (ohci);
@@ -489,7 +489,7 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
        unsigned long   flags;
 
        spin_lock_irqsave (&ohci->lock, flags);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                goto done;
 
        /* undocumented erratum seen on at least rev D */
@@ -533,8 +533,12 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
                }
        }
 
-       hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed,
-                       any_connected, rhsc_status);
+       if (ohci_root_hub_state_changes(ohci, changed,
+                       any_connected, rhsc_status))
+               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+       else
+               clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+
 
 done:
        spin_unlock_irqrestore (&ohci->lock, flags);
@@ -701,7 +705,7 @@ static int ohci_hub_control (
        u32             temp;
        int             retval = 0;
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
+       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
                return -ESHUTDOWN;
 
        switch (typeReq) {
index f608dfd09a8aa8dccf76d71d13a6b944dbbdada1..d9c85a29273714b67a3feee118aef6d14f940be1 100644 (file)
@@ -1641,8 +1641,7 @@ static int submit_async(struct oxu_hcd    *oxu, struct urb *urb,
 #endif
 
        spin_lock_irqsave(&oxu->lock, flags);
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                              &oxu_to_hcd(oxu)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
                rc = -ESHUTDOWN;
                goto done;
        }
@@ -2209,8 +2208,7 @@ static int intr_submit(struct oxu_hcd *oxu, struct urb *urb,
 
        spin_lock_irqsave(&oxu->lock, flags);
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
-                              &oxu_to_hcd(oxu)->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
                status = -ESHUTDOWN;
                goto done;
        }
@@ -2715,7 +2713,6 @@ static int oxu_run(struct usb_hcd *hcd)
        u32 temp, hcc_params;
 
        hcd->uses_new_polling = 1;
-       hcd->poll_rh = 0;
 
        /* EHCI spec section 4.1 */
        retval = ehci_reset(oxu);
index d1dce2166eff5e429656359ca53bf40fc39126ad..2743ec770f0cbef80fc7a67ef9209fa22b1a4204 100644 (file)
@@ -140,7 +140,7 @@ static void finish_reset(struct uhci_hcd *uhci)
        uhci->rh_state = UHCI_RH_RESET;
        uhci->is_stopped = UHCI_IS_STOPPED;
        uhci_to_hcd(uhci)->state = HC_STATE_HALT;
-       uhci_to_hcd(uhci)->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
 
        uhci->dead = 0;         /* Full reset resurrects the controller */
 }
@@ -344,7 +344,10 @@ __acquires(uhci->lock)
        /* If interrupts don't work and remote wakeup is enabled then
         * the suspended root hub needs to be polled.
         */
-       uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable);
+       if (!int_enable && wakeup_enable)
+               set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
+       else
+               clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
 
        uhci_scan_schedule(uhci);
        uhci_fsbr_off(uhci);
@@ -363,7 +366,7 @@ static void start_rh(struct uhci_hcd *uhci)
                        uhci->io_addr + USBINTR);
        mb();
        uhci->rh_state = UHCI_RH_RUNNING;
-       uhci_to_hcd(uhci)->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
 }
 
 static void wakeup_rh(struct uhci_hcd *uhci)
@@ -733,7 +736,7 @@ static void uhci_stop(struct usb_hcd *hcd)
        struct uhci_hcd *uhci = hcd_to_uhci(hcd);
 
        spin_lock_irq(&uhci->lock);
-       if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead)
+       if (HCD_HW_ACCESSIBLE(hcd) && !uhci->dead)
                uhci_hc_died(uhci);
        uhci_scan_schedule(uhci);
        spin_unlock_irq(&uhci->lock);
@@ -750,7 +753,7 @@ static int uhci_rh_suspend(struct usb_hcd *hcd)
        int rc = 0;
 
        spin_lock_irq(&uhci->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                rc = -ESHUTDOWN;
        else if (uhci->dead)
                ;               /* Dead controllers tell no tales */
@@ -777,7 +780,7 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
        int rc = 0;
 
        spin_lock_irq(&uhci->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
+       if (!HCD_HW_ACCESSIBLE(hcd))
                rc = -ESHUTDOWN;
        else if (!uhci->dead)
                wakeup_rh(uhci);
@@ -793,7 +796,7 @@ static int uhci_pci_suspend(struct usb_hcd *hcd)
        dev_dbg(uhci_dev(uhci), "%s\n", __func__);
 
        spin_lock_irq(&uhci->lock);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
+       if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
                goto done_okay;         /* Already suspended or dead */
 
        if (uhci->rh_state > UHCI_RH_SUSPENDED) {
@@ -807,7 +810,7 @@ static int uhci_pci_suspend(struct usb_hcd *hcd)
         */
        pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
        mb();
-       hcd->poll_rh = 0;
+       clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
 
        /* FIXME: Enable non-PME# remote wakeup? */
 
@@ -860,7 +863,7 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
         * the suspended root hub needs to be polled.
         */
        if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) {
-               hcd->poll_rh = 1;
+               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
                usb_hcd_poll_rh_status(hcd);
        }
        return 0;
index 8270055848cacd2a8e32379d873b1f624006db71..f0c58116c0adf27e781928e5ae5cb1b37ed2b098 100644 (file)
@@ -190,7 +190,7 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
        spin_lock_irqsave(&uhci->lock, flags);
 
        uhci_scan_schedule(uhci);
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
+       if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
                goto done;
        uhci_check_ports(uhci);
 
@@ -246,7 +246,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
        u16 wPortChange, wPortStatus;
        unsigned long flags;
 
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
+       if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
                return -ETIMEDOUT;
 
        spin_lock_irqsave(&uhci->lock, flags);
index e0d3401285c8d99e59e3ed78ce6e14ae76448091..72b6892fda67d381c16b6948256aa10b8f6945be 100644 (file)
@@ -68,7 +68,7 @@ static int whc_start(struct usb_hcd *usb_hcd)
        whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
 
        usb_hcd->uses_new_polling = 1;
-       usb_hcd->poll_rh = 1;
+       set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
        usb_hcd->state = HC_STATE_RUNNING;
 
 out:
index 343f1047f5d081689fea81c2f959aeace12e705d..5e73386b389962f058ba709d8836a870253d54ae 100644 (file)
@@ -427,7 +427,6 @@ int xhci_run(struct usb_hcd *hcd)
        void (*doorbell)(struct xhci_hcd *) = NULL;
 
        hcd->uses_new_polling = 1;
-       hcd->poll_rh = 0;
 
        xhci_dbg(xhci, "xhci_run\n");
 #if 0  /* FIXME: MSI not setup yet */
@@ -733,7 +732,7 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
                ret = -EINVAL;
                goto exit;
        }
-       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
+       if (!HCD_HW_ACCESSIBLE(hcd)) {
                if (!in_interrupt())
                        xhci_dbg(xhci, "urb submitted during PCI suspend\n");
                ret = -ESHUTDOWN;
index 92e85e027cfb822c61b2b0a42fce9a4e0c4b61e3..43233c397b6e64954e9aafbd2cff95a75a5716fd 100644 (file)
@@ -244,7 +244,7 @@ int musb_hub_control(
 
        spin_lock_irqsave(&musb->lock, flags);
 
-       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
+       if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) {
                spin_unlock_irqrestore(&musb->lock, flags);
                return -ESHUTDOWN;
        }
index 9b867e64a0f463af086bd1e99bcadef6360b642a..f8f8fa7a56e89a456d78563f715af3994a6728f3 100644 (file)
@@ -89,19 +89,31 @@ struct usb_hcd {
         */
        const struct hc_driver  *driver;        /* hw-specific hooks */
 
-       /* Flags that need to be manipulated atomically */
+       /* Flags that need to be manipulated atomically because they can
+        * change while the host controller is running.  Always use
+        * set_bit() or clear_bit() to change their values.
+        */
        unsigned long           flags;
-#define HCD_FLAG_HW_ACCESSIBLE 0x00000001
-#define HCD_FLAG_SAW_IRQ       0x00000002
+#define HCD_FLAG_HW_ACCESSIBLE         0       /* at full power */
+#define HCD_FLAG_SAW_IRQ               1
+#define HCD_FLAG_POLL_RH               2       /* poll for rh status? */
+#define HCD_FLAG_POLL_PENDING          3       /* status has changed? */
+
+       /* The flags can be tested using these macros; they are likely to
+        * be slightly faster than test_bit().
+        */
+#define HCD_HW_ACCESSIBLE(hcd) ((hcd)->flags & (1U << HCD_FLAG_HW_ACCESSIBLE))
+#define HCD_SAW_IRQ(hcd)       ((hcd)->flags & (1U << HCD_FLAG_SAW_IRQ))
+#define HCD_POLL_RH(hcd)       ((hcd)->flags & (1U << HCD_FLAG_POLL_RH))
+#define HCD_POLL_PENDING(hcd)  ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING))
 
+       /* Flags that get set only during HCD registration or removal. */
        unsigned                rh_registered:1;/* is root hub registered? */
        unsigned                rh_pollable:1;  /* may we poll the root hub? */
 
        /* The next flag is a stopgap, to be removed when all the HCDs
         * support the new root-hub polling mechanism. */
        unsigned                uses_new_polling:1;
-       unsigned                poll_rh:1;      /* poll for rh status? */
-       unsigned                poll_pending:1; /* status has changed? */
        unsigned                wireless:1;     /* Wireless USB HCD */
        unsigned                authorized_default:1;
        unsigned                has_tt:1;       /* Integrated TT in root hub */