| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
| Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4 | * | 
|  | 5 | * Portions of this file are derived from the ipw3945 project. | 
|  | 6 | * | 
|  | 7 | * This program is free software; you can redistribute it and/or modify it | 
|  | 8 | * under the terms of version 2 of the GNU General Public License as | 
|  | 9 | * published by the Free Software Foundation. | 
|  | 10 | * | 
|  | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 13 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 14 | * more details. | 
|  | 15 | * | 
|  | 16 | * You should have received a copy of the GNU General Public License along with | 
|  | 17 | * this program; if not, write to the Free Software Foundation, Inc., | 
|  | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | 
|  | 19 | * | 
|  | 20 | * The full GNU General Public License is included in this distribution in the | 
|  | 21 | * file called LICENSE. | 
|  | 22 | * | 
|  | 23 | * Contact Information: | 
| Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 24 | *  Intel Linux Wireless <ilw@linux.intel.com> | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 25 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 26 | * | 
|  | 27 | *****************************************************************************/ | 
|  | 28 |  | 
|  | 29 | #ifndef __iwl_io_h__ | 
|  | 30 | #define __iwl_io_h__ | 
|  | 31 |  | 
|  | 32 | #include <linux/io.h> | 
|  | 33 |  | 
| Tejun Heo | ed391f4 | 2010-03-23 15:55:39 +0900 | [diff] [blame] | 34 | #include "iwl-dev.h" | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 35 | #include "iwl-debug.h" | 
| Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 36 | #include "iwl-devtrace.h" | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | /* | 
|  | 39 | * IO, register, and NIC memory access functions | 
|  | 40 | * | 
|  | 41 | * NOTE on naming convention and macro usage for these | 
|  | 42 | * | 
|  | 43 | * A single _ prefix before a an access function means that no state | 
|  | 44 | * check or debug information is printed when that function is called. | 
|  | 45 | * | 
|  | 46 | * A double __ prefix before an access function means that state is checked | 
| Tomas Winkler | 775ea37 | 2008-03-25 16:33:38 -0700 | [diff] [blame] | 47 | * and the current line number and caller function name are printed in addition | 
|  | 48 | * to any other debug output. | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 49 | * | 
|  | 50 | * The non-prefixed name is the #define that maps the caller into a | 
| Tomas Winkler | 775ea37 | 2008-03-25 16:33:38 -0700 | [diff] [blame] | 51 | * #define that provides the caller's name and __LINE__ to the double | 
|  | 52 | * prefix version. | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 53 | * | 
|  | 54 | * If you wish to call the function without any debug or state checking, | 
|  | 55 | * you should use the single _ prefix version (as is used by dependent IO | 
|  | 56 | * routines, for example _iwl_read_direct32 calls the non-check version of | 
|  | 57 | * _iwl_read32.) | 
|  | 58 | * | 
|  | 59 | * These declarations are *extremely* useful in quickly isolating code deltas | 
| Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 60 | * which result in misconfiguration of the hardware I/O.  In combination with | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 61 | * git-bisect and the IO debug level you can quickly determine the specific | 
|  | 62 | * commit which breaks the IO sequence to the hardware. | 
|  | 63 | * | 
|  | 64 | */ | 
|  | 65 |  | 
| Ben Cahill | 4e03185 | 2009-11-20 12:04:52 -0800 | [diff] [blame] | 66 | static inline void _iwl_write8(struct iwl_priv *priv, u32 ofs, u8 val) | 
|  | 67 | { | 
|  | 68 | trace_iwlwifi_dev_iowrite8(priv, ofs, val); | 
|  | 69 | iowrite8(val, priv->hw_base + ofs); | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 73 | static inline void __iwl_write8(const char *f, u32 l, struct iwl_priv *priv, | 
|  | 74 | u32 ofs, u8 val) | 
|  | 75 | { | 
|  | 76 | IWL_DEBUG_IO(priv, "write8(0x%08X, 0x%02X) - %s %d\n", ofs, val, f, l); | 
|  | 77 | _iwl_write8(priv, ofs, val); | 
|  | 78 | } | 
|  | 79 | #define iwl_write8(priv, ofs, val) \ | 
|  | 80 | __iwl_write8(__FILE__, __LINE__, priv, ofs, val) | 
|  | 81 | #else | 
|  | 82 | #define iwl_write8(priv, ofs, val) _iwl_write8(priv, ofs, val) | 
|  | 83 | #endif | 
|  | 84 |  | 
|  | 85 |  | 
| Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 86 | static inline void _iwl_write32(struct iwl_priv *priv, u32 ofs, u32 val) | 
|  | 87 | { | 
|  | 88 | trace_iwlwifi_dev_iowrite32(priv, ofs, val); | 
|  | 89 | iowrite32(val, priv->hw_base + ofs); | 
|  | 90 | } | 
|  | 91 |  | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 93 | static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv, | 
|  | 94 | u32 ofs, u32 val) | 
|  | 95 | { | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 96 | IWL_DEBUG_IO(priv, "write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 97 | _iwl_write32(priv, ofs, val); | 
|  | 98 | } | 
|  | 99 | #define iwl_write32(priv, ofs, val) \ | 
|  | 100 | __iwl_write32(__FILE__, __LINE__, priv, ofs, val) | 
|  | 101 | #else | 
|  | 102 | #define iwl_write32(priv, ofs, val) _iwl_write32(priv, ofs, val) | 
|  | 103 | #endif | 
|  | 104 |  | 
| Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 105 | static inline u32 _iwl_read32(struct iwl_priv *priv, u32 ofs) | 
|  | 106 | { | 
|  | 107 | u32 val = ioread32(priv->hw_base + ofs); | 
|  | 108 | trace_iwlwifi_dev_ioread32(priv, ofs, val); | 
|  | 109 | return val; | 
|  | 110 | } | 
|  | 111 |  | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 112 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 113 | static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs) | 
|  | 114 | { | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 115 | IWL_DEBUG_IO(priv, "read_direct32(0x%08X) - %s %d\n", ofs, f, l); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 116 | return _iwl_read32(priv, ofs); | 
|  | 117 | } | 
|  | 118 | #define iwl_read32(priv, ofs) __iwl_read32(__FILE__, __LINE__, priv, ofs) | 
|  | 119 | #else | 
|  | 120 | #define iwl_read32(p, o) _iwl_read32(p, o) | 
|  | 121 | #endif | 
|  | 122 |  | 
| Wu, Fengguang | 4087f6f | 2008-12-17 16:52:32 +0800 | [diff] [blame] | 123 | #define IWL_POLL_INTERVAL 10	/* microseconds */ | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 124 | static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr, | 
|  | 125 | u32 bits, u32 mask, int timeout) | 
|  | 126 | { | 
| Wu, Fengguang | 4087f6f | 2008-12-17 16:52:32 +0800 | [diff] [blame] | 127 | int t = 0; | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 128 |  | 
|  | 129 | do { | 
|  | 130 | if ((_iwl_read32(priv, addr) & mask) == (bits & mask)) | 
| Wu, Fengguang | 4087f6f | 2008-12-17 16:52:32 +0800 | [diff] [blame] | 131 | return t; | 
|  | 132 | udelay(IWL_POLL_INTERVAL); | 
|  | 133 | t += IWL_POLL_INTERVAL; | 
|  | 134 | } while (t < timeout); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 135 |  | 
|  | 136 | return -ETIMEDOUT; | 
|  | 137 | } | 
|  | 138 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 139 | static inline int __iwl_poll_bit(const char *f, u32 l, | 
|  | 140 | struct iwl_priv *priv, u32 addr, | 
|  | 141 | u32 bits, u32 mask, int timeout) | 
|  | 142 | { | 
|  | 143 | int ret = _iwl_poll_bit(priv, addr, bits, mask, timeout); | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 144 | IWL_DEBUG_IO(priv, "poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n", | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 145 | addr, bits, mask, | 
| Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 146 | unlikely(ret  == -ETIMEDOUT) ? "timeout" : "", f, l); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 147 | return ret; | 
|  | 148 | } | 
|  | 149 | #define iwl_poll_bit(priv, addr, bits, mask, timeout) \ | 
|  | 150 | __iwl_poll_bit(__FILE__, __LINE__, priv, addr, bits, mask, timeout) | 
|  | 151 | #else | 
|  | 152 | #define iwl_poll_bit(p, a, b, m, t) _iwl_poll_bit(p, a, b, m, t) | 
|  | 153 | #endif | 
|  | 154 |  | 
|  | 155 | static inline void _iwl_set_bit(struct iwl_priv *priv, u32 reg, u32 mask) | 
|  | 156 | { | 
|  | 157 | _iwl_write32(priv, reg, _iwl_read32(priv, reg) | mask); | 
|  | 158 | } | 
|  | 159 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 160 | static inline void __iwl_set_bit(const char *f, u32 l, | 
|  | 161 | struct iwl_priv *priv, u32 reg, u32 mask) | 
|  | 162 | { | 
|  | 163 | u32 val = _iwl_read32(priv, reg) | mask; | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 164 | IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 165 | _iwl_write32(priv, reg, val); | 
|  | 166 | } | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 167 | static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m) | 
|  | 168 | { | 
|  | 169 | unsigned long reg_flags; | 
|  | 170 |  | 
|  | 171 | spin_lock_irqsave(&p->reg_lock, reg_flags); | 
|  | 172 | __iwl_set_bit(__FILE__, __LINE__, p, r, m); | 
|  | 173 | spin_unlock_irqrestore(&p->reg_lock, reg_flags); | 
|  | 174 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 175 | #else | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 176 | static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m) | 
|  | 177 | { | 
|  | 178 | unsigned long reg_flags; | 
|  | 179 |  | 
|  | 180 | spin_lock_irqsave(&p->reg_lock, reg_flags); | 
|  | 181 | _iwl_set_bit(p, r, m); | 
|  | 182 | spin_unlock_irqrestore(&p->reg_lock, reg_flags); | 
|  | 183 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 184 | #endif | 
|  | 185 |  | 
|  | 186 | static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask) | 
|  | 187 | { | 
|  | 188 | _iwl_write32(priv, reg, _iwl_read32(priv, reg) & ~mask); | 
|  | 189 | } | 
|  | 190 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 191 | static inline void __iwl_clear_bit(const char *f, u32 l, | 
|  | 192 | struct iwl_priv *priv, u32 reg, u32 mask) | 
|  | 193 | { | 
|  | 194 | u32 val = _iwl_read32(priv, reg) & ~mask; | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 195 | IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 196 | _iwl_write32(priv, reg, val); | 
|  | 197 | } | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 198 | static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m) | 
|  | 199 | { | 
|  | 200 | unsigned long reg_flags; | 
|  | 201 |  | 
|  | 202 | spin_lock_irqsave(&p->reg_lock, reg_flags); | 
|  | 203 | __iwl_clear_bit(__FILE__, __LINE__, p, r, m); | 
|  | 204 | spin_unlock_irqrestore(&p->reg_lock, reg_flags); | 
|  | 205 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 206 | #else | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 207 | static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m) | 
|  | 208 | { | 
|  | 209 | unsigned long reg_flags; | 
|  | 210 |  | 
|  | 211 | spin_lock_irqsave(&p->reg_lock, reg_flags); | 
|  | 212 | _iwl_clear_bit(p, r, m); | 
|  | 213 | spin_unlock_irqrestore(&p->reg_lock, reg_flags); | 
|  | 214 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 215 | #endif | 
|  | 216 |  | 
|  | 217 | static inline int _iwl_grab_nic_access(struct iwl_priv *priv) | 
|  | 218 | { | 
|  | 219 | int ret; | 
| Reinette Chatre | 18d426c | 2009-03-11 11:18:00 -0700 | [diff] [blame] | 220 | u32 val; | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 221 |  | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 222 | /* this bit wakes up the NIC */ | 
|  | 223 | _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); | 
| Ben Cahill | a7e6611 | 2009-11-06 14:53:00 -0800 | [diff] [blame] | 224 |  | 
|  | 225 | /* | 
|  | 226 | * These bits say the device is running, and should keep running for | 
|  | 227 | * at least a short while (at least as long as MAC_ACCESS_REQ stays 1), | 
|  | 228 | * but they do not indicate that embedded SRAM is restored yet; | 
|  | 229 | * 3945 and 4965 have volatile SRAM, and must save/restore contents | 
|  | 230 | * to/from host DRAM when sleeping/waking for power-saving. | 
|  | 231 | * Each direction takes approximately 1/4 millisecond; with this | 
|  | 232 | * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a | 
|  | 233 | * series of register accesses are expected (e.g. reading Event Log), | 
|  | 234 | * to keep device from sleeping. | 
|  | 235 | * | 
|  | 236 | * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that | 
|  | 237 | * SRAM is okay/restored.  We don't check that here because this call | 
|  | 238 | * is just for hardware register access; but GP1 MAC_SLEEP check is a | 
|  | 239 | * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log). | 
|  | 240 | * | 
|  | 241 | * 5000 series and later (including 1000 series) have non-volatile SRAM, | 
|  | 242 | * and do not save/restore SRAM when power cycling. | 
|  | 243 | */ | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 244 | ret = _iwl_poll_bit(priv, CSR_GP_CNTRL, | 
|  | 245 | CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN, | 
|  | 246 | (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY | | 
| Abbas, Mohamed | e9414b6 | 2009-01-20 21:33:55 -0800 | [diff] [blame] | 247 | CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 248 | if (ret < 0) { | 
| Reinette Chatre | 18d426c | 2009-03-11 11:18:00 -0700 | [diff] [blame] | 249 | val = _iwl_read32(priv, CSR_GP_CNTRL); | 
|  | 250 | IWL_ERR(priv, "MAC is in deep sleep!.  CSR_GP_CNTRL = 0x%08X\n", val); | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 251 | _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 252 | return -EIO; | 
|  | 253 | } | 
|  | 254 |  | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 255 | return 0; | 
|  | 256 | } | 
|  | 257 |  | 
|  | 258 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 259 | static inline int __iwl_grab_nic_access(const char *f, u32 l, | 
|  | 260 | struct iwl_priv *priv) | 
|  | 261 | { | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 262 | IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 263 | return _iwl_grab_nic_access(priv); | 
|  | 264 | } | 
|  | 265 | #define iwl_grab_nic_access(priv) \ | 
|  | 266 | __iwl_grab_nic_access(__FILE__, __LINE__, priv) | 
|  | 267 | #else | 
|  | 268 | #define iwl_grab_nic_access(priv) \ | 
|  | 269 | _iwl_grab_nic_access(priv) | 
|  | 270 | #endif | 
|  | 271 |  | 
|  | 272 | static inline void _iwl_release_nic_access(struct iwl_priv *priv) | 
|  | 273 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 274 | _iwl_clear_bit(priv, CSR_GP_CNTRL, | 
|  | 275 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 276 | } | 
|  | 277 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 278 | static inline void __iwl_release_nic_access(const char *f, u32 l, | 
|  | 279 | struct iwl_priv *priv) | 
|  | 280 | { | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 281 |  | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 282 | IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 283 | _iwl_release_nic_access(priv); | 
|  | 284 | } | 
|  | 285 | #define iwl_release_nic_access(priv) \ | 
|  | 286 | __iwl_release_nic_access(__FILE__, __LINE__, priv) | 
|  | 287 | #else | 
|  | 288 | #define iwl_release_nic_access(priv) \ | 
|  | 289 | _iwl_release_nic_access(priv) | 
|  | 290 | #endif | 
|  | 291 |  | 
|  | 292 | static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg) | 
|  | 293 | { | 
|  | 294 | return _iwl_read32(priv, reg); | 
|  | 295 | } | 
|  | 296 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 297 | static inline u32 __iwl_read_direct32(const char *f, u32 l, | 
|  | 298 | struct iwl_priv *priv, u32 reg) | 
|  | 299 | { | 
|  | 300 | u32 value = _iwl_read_direct32(priv, reg); | 
| Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 301 | IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d\n", reg, value, | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 302 | f, l); | 
|  | 303 | return value; | 
|  | 304 | } | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 305 | static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg) | 
|  | 306 | { | 
|  | 307 | u32 value; | 
|  | 308 | unsigned long reg_flags; | 
|  | 309 |  | 
|  | 310 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 311 | iwl_grab_nic_access(priv); | 
|  | 312 | value = __iwl_read_direct32(__FILE__, __LINE__, priv, reg); | 
|  | 313 | iwl_release_nic_access(priv); | 
|  | 314 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
|  | 315 | return value; | 
|  | 316 | } | 
|  | 317 |  | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 318 | #else | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 319 | static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg) | 
|  | 320 | { | 
|  | 321 | u32 value; | 
|  | 322 | unsigned long reg_flags; | 
|  | 323 |  | 
|  | 324 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 325 | iwl_grab_nic_access(priv); | 
|  | 326 | value = _iwl_read_direct32(priv, reg); | 
|  | 327 | iwl_release_nic_access(priv); | 
|  | 328 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
|  | 329 | return value; | 
|  | 330 |  | 
|  | 331 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 332 | #endif | 
|  | 333 |  | 
|  | 334 | static inline void _iwl_write_direct32(struct iwl_priv *priv, | 
|  | 335 | u32 reg, u32 value) | 
|  | 336 | { | 
|  | 337 | _iwl_write32(priv, reg, value); | 
|  | 338 | } | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 339 | static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value) | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 340 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 341 | unsigned long reg_flags; | 
|  | 342 |  | 
|  | 343 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 344 | if (!iwl_grab_nic_access(priv)) { | 
|  | 345 | _iwl_write_direct32(priv, reg, value); | 
|  | 346 | iwl_release_nic_access(priv); | 
|  | 347 | } | 
|  | 348 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 349 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 350 |  | 
|  | 351 | static inline void iwl_write_reg_buf(struct iwl_priv *priv, | 
|  | 352 | u32 reg, u32 len, u32 *values) | 
|  | 353 | { | 
|  | 354 | u32 count = sizeof(u32); | 
|  | 355 |  | 
|  | 356 | if ((priv != NULL) && (values != NULL)) { | 
|  | 357 | for (; 0 < len; len -= count, reg += count, values++) | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 358 | iwl_write_direct32(priv, reg, *values); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 359 | } | 
|  | 360 | } | 
|  | 361 |  | 
| Zhu, Yi | 73d7b5a | 2008-12-05 07:58:40 -0800 | [diff] [blame] | 362 | static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr, | 
|  | 363 | u32 mask, int timeout) | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 364 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 365 | int t = 0; | 
|  | 366 |  | 
|  | 367 | do { | 
|  | 368 | if ((iwl_read_direct32(priv, addr) & mask) == mask) | 
|  | 369 | return t; | 
|  | 370 | udelay(IWL_POLL_INTERVAL); | 
|  | 371 | t += IWL_POLL_INTERVAL; | 
|  | 372 | } while (t < timeout); | 
|  | 373 |  | 
|  | 374 | return -ETIMEDOUT; | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
|  | 377 | #ifdef CONFIG_IWLWIFI_DEBUG | 
|  | 378 | static inline int __iwl_poll_direct_bit(const char *f, u32 l, | 
|  | 379 | struct iwl_priv *priv, | 
|  | 380 | u32 addr, u32 mask, int timeout) | 
|  | 381 | { | 
|  | 382 | int ret  = _iwl_poll_direct_bit(priv, addr, mask, timeout); | 
|  | 383 |  | 
|  | 384 | if (unlikely(ret == -ETIMEDOUT)) | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 385 | IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) - " | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 386 | "timedout - %s %d\n", addr, mask, f, l); | 
|  | 387 | else | 
| Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 388 | IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) = 0x%08X " | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 389 | "- %s %d\n", addr, mask, ret, f, l); | 
|  | 390 | return ret; | 
|  | 391 | } | 
|  | 392 | #define iwl_poll_direct_bit(priv, addr, mask, timeout) \ | 
|  | 393 | __iwl_poll_direct_bit(__FILE__, __LINE__, priv, addr, mask, timeout) | 
|  | 394 | #else | 
|  | 395 | #define iwl_poll_direct_bit _iwl_poll_direct_bit | 
|  | 396 | #endif | 
|  | 397 |  | 
|  | 398 | static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg) | 
|  | 399 | { | 
|  | 400 | _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24)); | 
| Zhu, Yi | a8ec42c | 2008-12-05 07:58:41 -0800 | [diff] [blame] | 401 | rmb(); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 402 | return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT); | 
|  | 403 | } | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 404 | static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg) | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 405 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 406 | unsigned long reg_flags; | 
|  | 407 | u32 val; | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 408 |  | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 409 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 410 | iwl_grab_nic_access(priv); | 
|  | 411 | val = _iwl_read_prph(priv, reg); | 
|  | 412 | iwl_release_nic_access(priv); | 
|  | 413 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
|  | 414 | return val; | 
|  | 415 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 416 |  | 
|  | 417 | static inline void _iwl_write_prph(struct iwl_priv *priv, | 
|  | 418 | u32 addr, u32 val) | 
|  | 419 | { | 
|  | 420 | _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR, | 
|  | 421 | ((addr & 0x0000FFFF) | (3 << 24))); | 
| Zhu, Yi | a8ec42c | 2008-12-05 07:58:41 -0800 | [diff] [blame] | 422 | wmb(); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 423 | _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val); | 
|  | 424 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 425 |  | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 426 | static inline void iwl_write_prph(struct iwl_priv *priv, u32 addr, u32 val) | 
|  | 427 | { | 
|  | 428 | unsigned long reg_flags; | 
|  | 429 |  | 
|  | 430 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 431 | if (!iwl_grab_nic_access(priv)) { | 
|  | 432 | _iwl_write_prph(priv, addr, val); | 
|  | 433 | iwl_release_nic_access(priv); | 
|  | 434 | } | 
|  | 435 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
|  | 436 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 437 |  | 
|  | 438 | #define _iwl_set_bits_prph(priv, reg, mask) \ | 
|  | 439 | _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask)) | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 440 |  | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 441 | static inline void iwl_set_bits_prph(struct iwl_priv *priv, u32 reg, u32 mask) | 
|  | 442 | { | 
|  | 443 | unsigned long reg_flags; | 
|  | 444 |  | 
|  | 445 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 446 | iwl_grab_nic_access(priv); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 447 | _iwl_set_bits_prph(priv, reg, mask); | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 448 | iwl_release_nic_access(priv); | 
|  | 449 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 450 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 451 |  | 
|  | 452 | #define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \ | 
|  | 453 | _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits)) | 
|  | 454 |  | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 455 | static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg, | 
|  | 456 | u32 bits, u32 mask) | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 457 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 458 | unsigned long reg_flags; | 
|  | 459 |  | 
|  | 460 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 461 | iwl_grab_nic_access(priv); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 462 | _iwl_set_bits_mask_prph(priv, reg, bits, mask); | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 463 | iwl_release_nic_access(priv); | 
|  | 464 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 465 | } | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 466 |  | 
|  | 467 | static inline void iwl_clear_bits_prph(struct iwl_priv | 
|  | 468 | *priv, u32 reg, u32 mask) | 
|  | 469 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 470 | unsigned long reg_flags; | 
|  | 471 | u32 val; | 
|  | 472 |  | 
|  | 473 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 474 | iwl_grab_nic_access(priv); | 
|  | 475 | val = _iwl_read_prph(priv, reg); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 476 | _iwl_write_prph(priv, reg, (val & ~mask)); | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 477 | iwl_release_nic_access(priv); | 
|  | 478 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 479 | } | 
|  | 480 |  | 
|  | 481 | static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr) | 
|  | 482 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 483 | unsigned long reg_flags; | 
|  | 484 | u32 value; | 
|  | 485 |  | 
|  | 486 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 487 | iwl_grab_nic_access(priv); | 
|  | 488 |  | 
|  | 489 | _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr); | 
| Zhu, Yi | a8ec42c | 2008-12-05 07:58:41 -0800 | [diff] [blame] | 490 | rmb(); | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 491 | value = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); | 
|  | 492 |  | 
|  | 493 | iwl_release_nic_access(priv); | 
|  | 494 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
|  | 495 | return value; | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
|  | 498 | static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val) | 
|  | 499 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 500 | unsigned long reg_flags; | 
|  | 501 |  | 
|  | 502 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 503 | if (!iwl_grab_nic_access(priv)) { | 
|  | 504 | _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); | 
|  | 505 | wmb(); | 
|  | 506 | _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val); | 
|  | 507 | iwl_release_nic_access(priv); | 
|  | 508 | } | 
|  | 509 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 510 | } | 
|  | 511 |  | 
|  | 512 | static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr, | 
|  | 513 | u32 len, u32 *values) | 
|  | 514 | { | 
| Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 515 | unsigned long reg_flags; | 
|  | 516 |  | 
|  | 517 | spin_lock_irqsave(&priv->reg_lock, reg_flags); | 
|  | 518 | if (!iwl_grab_nic_access(priv)) { | 
|  | 519 | _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); | 
|  | 520 | wmb(); | 
|  | 521 | for (; 0 < len; len -= sizeof(u32), values++) | 
|  | 522 | _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values); | 
|  | 523 |  | 
|  | 524 | iwl_release_nic_access(priv); | 
|  | 525 | } | 
|  | 526 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); | 
| Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 527 | } | 
|  | 528 | #endif |