Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[cascardo/linux.git] / drivers / net / wireless / iwlwifi / iwl-io.h
index 9740fcc..7341a2d 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  *
- * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
+ * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
  *
  * Portions of this file are derived from the ipw3945 project.
  *
@@ -21,7 +21,7 @@
  * file called LICENSE.
  *
  * Contact Information:
- * James P. Ketrenos <ipw2100-admin@linux.intel.com>
+ *  Intel Linux Wireless <ilw@linux.intel.com>
  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  *
  *****************************************************************************/
@@ -55,7 +55,7 @@
  * _iwl_read32.)
  *
  * These declarations are *extremely* useful in quickly isolating code deltas
- * which result in misconfiguring of the hardware I/O.  In combination with
+ * which result in misconfiguration of the hardware I/O.  In combination with
  * git-bisect and the IO debug level you can quickly determine the specific
  * commit which breaks the IO sequence to the hardware.
  *
@@ -87,17 +87,18 @@ static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs)
 #define iwl_read32(p, o) _iwl_read32(p, o)
 #endif
 
+#define IWL_POLL_INTERVAL 10   /* microseconds */
 static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr,
                                u32 bits, u32 mask, int timeout)
 {
-       int i = 0;
+       int t = 0;
 
        do {
                if ((_iwl_read32(priv, addr) & mask) == (bits & mask))
-                       return i;
-               mdelay(10);
-               i += 10;
-       } while (i < timeout);
+                       return t;
+               udelay(IWL_POLL_INTERVAL);
+               t += IWL_POLL_INTERVAL;
+       } while (t < timeout);
 
        return -ETIMEDOUT;
 }
@@ -109,7 +110,7 @@ static inline int __iwl_poll_bit(const char *f, u32 l,
        int ret = _iwl_poll_bit(priv, addr, bits, mask, timeout);
        IWL_DEBUG_IO("poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n",
                     addr, bits, mask,
-                    unlikely(ret  == -ETIMEDOUT)?"timeout":"", f, l);
+                    unlikely(ret  == -ETIMEDOUT) ? "timeout" : "", f, l);
        return ret;
 }
 #define iwl_poll_bit(priv, addr, bits, mask, timeout) \
@@ -164,9 +165,9 @@ static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
        ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
                           CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
                           (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
-                           CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50);
+                           CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
        if (ret < 0) {
-               IWL_ERROR("MAC is in deep sleep!\n");
+               IWL_ERR(priv, "MAC is in deep sleep!\n");
                return -EIO;
        }
 
@@ -181,7 +182,7 @@ static inline int __iwl_grab_nic_access(const char *f, u32 l,
                                               struct iwl_priv *priv)
 {
        if (atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Grabbing access while already held %s %d.\n", f, l);
+               IWL_ERR(priv, "Grabbing access while already held %s %d.\n", f, l);
 
        IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l);
        return _iwl_grab_nic_access(priv);
@@ -206,7 +207,7 @@ static inline void __iwl_release_nic_access(const char *f, u32 l,
                                            struct iwl_priv *priv)
 {
        if (atomic_read(&priv->restrict_refcnt) <= 0)
-               IWL_ERROR("Release unheld nic access at line %s %d.\n", f, l);
+               IWL_ERR(priv, "Release unheld nic access at line %s %d.\n", f, l);
 
        IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l);
        _iwl_release_nic_access(priv);
@@ -228,7 +229,7 @@ static inline u32 __iwl_read_direct32(const char *f, u32 l,
 {
        u32 value = _iwl_read_direct32(priv, reg);
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s %d\n", f, l);
+               IWL_ERR(priv, "Nic access not held from %s %d\n", f, l);
        IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
                     f, l);
        return value;
@@ -249,7 +250,7 @@ static void __iwl_write_direct32(const char *f , u32 line,
                                   struct iwl_priv *priv, u32 reg, u32 value)
 {
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s line %d\n", f, line);
+               IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
        _iwl_write_direct32(priv, reg, value);
 }
 #define iwl_write_direct32(priv, reg, value) \
@@ -269,19 +270,10 @@ static inline void iwl_write_reg_buf(struct iwl_priv *priv,
        }
 }
 
-static inline int _iwl_poll_direct_bit(struct iwl_priv *priv,
-                                          u32 addr, u32 mask, int timeout)
+static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
+                                      u32 mask, int timeout)
 {
-       int i = 0;
-
-       do {
-               if ((_iwl_read_direct32(priv, addr) & mask) == mask)
-                       return i;
-               mdelay(10);
-               i += 10;
-       } while (i < timeout);
-
-       return -ETIMEDOUT;
+       return _iwl_poll_bit(priv, addr, mask, mask, timeout);
 }
 
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -308,6 +300,7 @@ static inline int __iwl_poll_direct_bit(const char *f, u32 l,
 static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
 {
        _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
+       rmb();
        return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
 }
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -315,7 +308,7 @@ static inline u32 __iwl_read_prph(const char *f, u32 line,
                                  struct iwl_priv *priv, u32 reg)
 {
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s line %d\n", f, line);
+               IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
        return _iwl_read_prph(priv, reg);
 }
 
@@ -330,6 +323,7 @@ static inline void _iwl_write_prph(struct iwl_priv *priv,
 {
        _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
                              ((addr & 0x0000FFFF) | (3 << 24)));
+       wmb();
        _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
 }
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -337,7 +331,7 @@ static inline void __iwl_write_prph(const char *f, u32 line,
                                    struct iwl_priv *priv, u32 addr, u32 val)
 {
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s line %d\n", f, line);
+               IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
        _iwl_write_prph(priv, addr, val);
 }
 
@@ -355,7 +349,7 @@ static inline void __iwl_set_bits_prph(const char *f, u32 line,
                                       u32 reg, u32 mask)
 {
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s line %d\n", f, line);
+               IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
 
        _iwl_set_bits_prph(priv, reg, mask);
 }
@@ -373,7 +367,7 @@ static inline void __iwl_set_bits_mask_prph(const char *f, u32 line,
                struct iwl_priv *priv, u32 reg, u32 bits, u32 mask)
 {
        if (!atomic_read(&priv->restrict_refcnt))
-               IWL_ERROR("Nic access not held from %s line %d\n", f, line);
+               IWL_ERR(priv, "Nic access not held from %s line %d\n", f, line);
        _iwl_set_bits_mask_prph(priv, reg, bits, mask);
 }
 #define iwl_set_bits_mask_prph(priv, reg, bits, mask) \
@@ -392,12 +386,14 @@ static inline void iwl_clear_bits_prph(struct iwl_priv
 static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
 {
        iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
+       rmb();
        return iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
 }
 
 static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
 {
        iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
+       wmb();
        iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
 }
 
@@ -405,6 +401,7 @@ static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
                                          u32 len, u32 *values)
 {
        iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
+       wmb();
        for (; 0 < len; len -= sizeof(u32), values++)
                iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
 }