orinoco: encapsulate driver locking
authorDavid Kilroy <kilroyd@googlemail.com>
Sat, 1 May 2010 13:05:40 +0000 (14:05 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 3 May 2010 18:53:07 +0000 (14:53 -0400)
Local bus and USB drivers will need to do locking differently.

The original orinoco_usb patches had a boolean variable controlling
whether spin_lock_bh was used, or irq based locking. This version
provides wrappers for the lock functions and the drivers specify the
functions pointers needed.

This will introduce a performance penalty, but I'm not expecting it to
be noticable.

Signed-off-by: David Kilroy <kilroyd@googlemail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/orinoco/airport.c
drivers/net/wireless/orinoco/hermes.c
drivers/net/wireless/orinoco/hermes.h
drivers/net/wireless/orinoco/main.c
drivers/net/wireless/orinoco/orinoco.h
drivers/net/wireless/orinoco/orinoco_cs.c
drivers/net/wireless/orinoco/spectrum_cs.c

index 7dac5adb6c1c9e73689d817b6739d3ce8956ae86..9bcee10c9308f861089843ccfe7c9b3009907e6d 100644 (file)
@@ -77,9 +77,9 @@ airport_resume(struct macio_dev *mdev)
 
        enable_irq(card->irq);
 
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
        err = orinoco_up(priv);
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 
        return err;
 }
index a7df5240779c2d94612107f4c1caf40cec4581f3..845693fb25f320890440b3c1c6323ee77c818b1a 100644 (file)
@@ -529,6 +529,28 @@ static int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
        return err;
 }
 
+static void hermes_lock_irqsave(spinlock_t *lock,
+                               unsigned long *flags) __acquires(lock)
+{
+       spin_lock_irqsave(lock, *flags);
+}
+
+static void hermes_unlock_irqrestore(spinlock_t *lock,
+                                    unsigned long *flags) __releases(lock)
+{
+       spin_unlock_irqrestore(lock, *flags);
+}
+
+static void hermes_lock_irq(spinlock_t *lock) __acquires(lock)
+{
+       spin_lock_irq(lock);
+}
+
+static void hermes_unlock_irq(spinlock_t *lock) __releases(lock)
+{
+       spin_unlock_irq(lock);
+}
+
 /* Hermes operations for local buses */
 static const struct hermes_ops hermes_ops_local = {
        .init = hermes_init,
@@ -538,5 +560,9 @@ static const struct hermes_ops hermes_ops_local = {
        .read_ltv = hermes_read_ltv,
        .write_ltv = hermes_write_ltv,
        .bap_pread = hermes_bap_pread,
-       .bap_pwrite = hermes_bap_pwrite
+       .bap_pwrite = hermes_bap_pwrite,
+       .lock_irqsave = hermes_lock_irqsave,
+       .unlock_irqrestore = hermes_unlock_irqrestore,
+       .lock_irq = hermes_lock_irq,
+       .unlock_irq = hermes_unlock_irq,
 };
index 18b268c54dfea429a70401cfea7d66678ad28dc5..9e21ecdb4e702335bf1ec7ff692cc95cb5a80c75 100644 (file)
@@ -393,6 +393,10 @@ struct hermes_ops {
                         u16 id, u16 offset);
        int (*bap_pwrite)(struct hermes *hw, int bap, const void *buf,
                          int len, u16 id, u16 offset);
+       void (*lock_irqsave)(spinlock_t *lock, unsigned long *flags);
+       void (*unlock_irqrestore)(spinlock_t *lock, unsigned long *flags);
+       void (*lock_irq)(spinlock_t *lock);
+       void (*unlock_irq)(spinlock_t *lock);
 };
 
 /* Basic control structure */
index 7acb6bc3ebffec31d4fba242d7a4ef2f5488014c..36c4ba865c7cc7490413ada1d4a88a3decfd0bca 100644 (file)
@@ -281,13 +281,13 @@ int orinoco_stop(struct net_device *dev)
        /* We mustn't use orinoco_lock() here, because we need to be
           able to close the interface even if hw_unavailable is set
           (e.g. as we're released after a PC Card removal) */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
 
        priv->open = 0;
 
        err = __orinoco_down(priv);
 
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        return err;
 }
@@ -1741,7 +1741,7 @@ void orinoco_reset(struct work_struct *work)
        }
 
        /* This has to be called from user context */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
 
        priv->hw_unavailable--;
 
@@ -1756,7 +1756,7 @@ void orinoco_reset(struct work_struct *work)
                        dev->trans_start = jiffies;
        }
 
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        return;
  disable:
@@ -2073,9 +2073,9 @@ int orinoco_init(struct orinoco_private *priv)
 
        /* Make the hardware available, as long as it hasn't been
         * removed elsewhere (e.g. by PCMCIA hot unplug) */
-       spin_lock_irq(&priv->lock);
+       orinoco_lock_irq(priv);
        priv->hw_unavailable--;
-       spin_unlock_irq(&priv->lock);
+       orinoco_unlock_irq(priv);
 
        dev_dbg(dev, "Ready\n");
 
@@ -2317,7 +2317,7 @@ int orinoco_up(struct orinoco_private *priv)
        unsigned long flags;
        int err;
 
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
 
        err = orinoco_reinit_firmware(priv);
        if (err) {
@@ -2337,7 +2337,7 @@ int orinoco_up(struct orinoco_private *priv)
        }
 
 exit:
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 
        return 0;
 }
@@ -2349,7 +2349,7 @@ void orinoco_down(struct orinoco_private *priv)
        unsigned long flags;
        int err;
 
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
        err = __orinoco_down(priv);
        if (err)
                printk(KERN_WARNING "%s: Error %d downing interface\n",
@@ -2357,7 +2357,7 @@ void orinoco_down(struct orinoco_private *priv)
 
        netif_device_detach(dev);
        priv->hw_unavailable++;
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 }
 EXPORT_SYMBOL(orinoco_down);
 
index f1901d6e6af8e71c3f1dfa8633ea35005c9d9760..80a1386ce0b4b3f361fb4cecba9b8452e590adce 100644 (file)
@@ -212,11 +212,11 @@ void orinoco_tx_timeout(struct net_device *dev);
 static inline int orinoco_lock(struct orinoco_private *priv,
                               unsigned long *flags)
 {
-       spin_lock_irqsave(&priv->lock, *flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, flags);
        if (priv->hw_unavailable) {
                DEBUG(1, "orinoco_lock() called with hw_unavailable (dev=%p)\n",
                       priv->ndev);
-               spin_unlock_irqrestore(&priv->lock, *flags);
+               priv->hw.ops->unlock_irqrestore(&priv->lock, flags);
                return -EBUSY;
        }
        return 0;
@@ -225,7 +225,17 @@ static inline int orinoco_lock(struct orinoco_private *priv,
 static inline void orinoco_unlock(struct orinoco_private *priv,
                                  unsigned long *flags)
 {
-       spin_unlock_irqrestore(&priv->lock, *flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, flags);
+}
+
+static inline void orinoco_lock_irq(struct orinoco_private *priv)
+{
+       priv->hw.ops->lock_irq(&priv->lock);
+}
+
+static inline void orinoco_unlock_irq(struct orinoco_private *priv)
+{
+       priv->hw.ops->unlock_irq(&priv->lock);
 }
 
 /*** Navigate from net_device to orinoco_private ***/
index 525f74e68294785af20e3d88c936e0c2c3a99738..f99b13ba92b36bb536bda9787f4f3a223da555c1 100644 (file)
@@ -327,9 +327,9 @@ orinoco_cs_release(struct pcmcia_device *link)
 
        /* We're committed to taking the device away now, so mark the
         * hardware as unavailable */
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
        priv->hw_unavailable++;
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 
        pcmcia_disable_device(link);
        if (priv->hw.iobase)
index 77b58717d18589053c0dd4e5a437bfaaa1d7eaf7..b4f68ef771e4bea04990fa40dd8403b4eef2b297 100644 (file)
@@ -405,9 +405,9 @@ spectrum_cs_release(struct pcmcia_device *link)
 
        /* We're committed to taking the device away now, so mark the
         * hardware as unavailable */
-       spin_lock_irqsave(&priv->lock, flags);
+       priv->hw.ops->lock_irqsave(&priv->lock, &flags);
        priv->hw_unavailable++;
-       spin_unlock_irqrestore(&priv->lock, flags);
+       priv->hw.ops->unlock_irqrestore(&priv->lock, &flags);
 
        pcmcia_disable_device(link);
        if (priv->hw.iobase)