blob: 3ddb2fbe12f90729808733a175161637599d72d2 [file] [log] [blame]
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Tomas Winkler3395f6e2008-03-25 16:33:37 -07004 *
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, Tomas759ef892008-12-09 11:28:58 -080024 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler3395f6e2008-03-25 16:33:37 -070025 * 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 Heoed391f42010-03-23 15:55:39 +090034#include "iwl-dev.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070035#include "iwl-debug.h"
Johannes Bergbe1a71a2009-10-02 13:44:02 -070036#include "iwl-devtrace.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070037
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 Winkler775ea372008-03-25 16:33:38 -070047 * and the current line number and caller function name are printed in addition
48 * to any other debug output.
Tomas Winkler3395f6e2008-03-25 16:33:37 -070049 *
50 * The non-prefixed name is the #define that maps the caller into a
Tomas Winkler775ea372008-03-25 16:33:38 -070051 * #define that provides the caller's name and __LINE__ to the double
52 * prefix version.
Tomas Winkler3395f6e2008-03-25 16:33:37 -070053 *
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 Winklera96a27f2008-10-23 23:48:56 -070060 * which result in misconfiguration of the hardware I/O. In combination with
Tomas Winkler3395f6e2008-03-25 16:33:37 -070061 * 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 Cahill4e031852009-11-20 12:04:52 -080066static 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
73static 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 Bergbe1a71a2009-10-02 13:44:02 -070086static 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 Winkler3395f6e2008-03-25 16:33:37 -070092#ifdef CONFIG_IWLWIFI_DEBUG
93static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv,
94 u32 ofs, u32 val)
95{
Tomas Winklere1623442009-01-27 14:27:56 -080096 IWL_DEBUG_IO(priv, "write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -070097 _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 Bergbe1a71a2009-10-02 13:44:02 -0700105static 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 Winkler3395f6e2008-03-25 16:33:37 -0700112#ifdef CONFIG_IWLWIFI_DEBUG
113static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs)
114{
Tomas Winklere1623442009-01-27 14:27:56 -0800115 IWL_DEBUG_IO(priv, "read_direct32(0x%08X) - %s %d\n", ofs, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700116 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, Fengguang4087f6f2008-12-17 16:52:32 +0800123#define IWL_POLL_INTERVAL 10 /* microseconds */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700124static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr,
125 u32 bits, u32 mask, int timeout)
126{
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800127 int t = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700128
129 do {
130 if ((_iwl_read32(priv, addr) & mask) == (bits & mask))
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800131 return t;
132 udelay(IWL_POLL_INTERVAL);
133 t += IWL_POLL_INTERVAL;
134 } while (t < timeout);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700135
136 return -ETIMEDOUT;
137}
138#ifdef CONFIG_IWLWIFI_DEBUG
139static 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 Winklere1623442009-01-27 14:27:56 -0800144 IWL_DEBUG_IO(priv, "poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n",
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700145 addr, bits, mask,
Abhijeet Kolekarc3056062008-11-12 13:14:08 -0800146 unlikely(ret == -ETIMEDOUT) ? "timeout" : "", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700147 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
155static 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
160static 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 Winklere1623442009-01-27 14:27:56 -0800164 IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700165 _iwl_write32(priv, reg, val);
166}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700167static 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 Winkler3395f6e2008-03-25 16:33:37 -0700175#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700176static 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 Winkler3395f6e2008-03-25 16:33:37 -0700184#endif
185
186static 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
191static 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 Winklere1623442009-01-27 14:27:56 -0800195 IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700196 _iwl_write32(priv, reg, val);
197}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700198static 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 Winkler3395f6e2008-03-25 16:33:37 -0700206#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700207static 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 Winkler3395f6e2008-03-25 16:33:37 -0700215#endif
216
217static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
218{
219 int ret;
Reinette Chatre18d426c2009-03-11 11:18:00 -0700220 u32 val;
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700221
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700222 /* this bit wakes up the NIC */
223 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Ben Cahilla7e66112009-11-06 14:53:00 -0800224
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 Winkler3395f6e2008-03-25 16:33:37 -0700244 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, Mohamede9414b62009-01-20 21:33:55 -0800247 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700248 if (ret < 0) {
Reinette Chatre18d426c2009-03-11 11:18:00 -0700249 val = _iwl_read32(priv, CSR_GP_CNTRL);
250 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700251 _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700252 return -EIO;
253 }
254
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700255 return 0;
256}
257
258#ifdef CONFIG_IWLWIFI_DEBUG
259static inline int __iwl_grab_nic_access(const char *f, u32 l,
260 struct iwl_priv *priv)
261{
Tomas Winklere1623442009-01-27 14:27:56 -0800262 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700263 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
272static inline void _iwl_release_nic_access(struct iwl_priv *priv)
273{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700274 _iwl_clear_bit(priv, CSR_GP_CNTRL,
275 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700276}
277#ifdef CONFIG_IWLWIFI_DEBUG
278static inline void __iwl_release_nic_access(const char *f, u32 l,
279 struct iwl_priv *priv)
280{
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700281
Tomas Winklere1623442009-01-27 14:27:56 -0800282 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700283 _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
292static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg)
293{
294 return _iwl_read32(priv, reg);
295}
296#ifdef CONFIG_IWLWIFI_DEBUG
297static 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 Pop91dd6c22010-03-24 14:19:58 -0700301 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d\n", reg, value,
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700302 f, l);
303 return value;
304}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700305static 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 Winkler3395f6e2008-03-25 16:33:37 -0700318#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700319static 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 Winkler3395f6e2008-03-25 16:33:37 -0700332#endif
333
334static inline void _iwl_write_direct32(struct iwl_priv *priv,
335 u32 reg, u32 value)
336{
337 _iwl_write32(priv, reg, value);
338}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700339static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700340{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700341 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 Winkler3395f6e2008-03-25 16:33:37 -0700349}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700350
351static 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 Abbasa8b50a02009-05-22 11:01:47 -0700358 iwl_write_direct32(priv, reg, *values);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700359 }
360}
361
Zhu, Yi73d7b5a2008-12-05 07:58:40 -0800362static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
363 u32 mask, int timeout)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700364{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700365 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 Winkler3395f6e2008-03-25 16:33:37 -0700375}
376
377#ifdef CONFIG_IWLWIFI_DEBUG
378static 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 Winklere1623442009-01-27 14:27:56 -0800385 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) - "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700386 "timedout - %s %d\n", addr, mask, f, l);
387 else
Tomas Winklere1623442009-01-27 14:27:56 -0800388 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700389 "- %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
398static 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, Yia8ec42c2008-12-05 07:58:41 -0800401 rmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700402 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
403}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700404static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700405{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700406 unsigned long reg_flags;
407 u32 val;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700408
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700409 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 Winkler3395f6e2008-03-25 16:33:37 -0700416
417static 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, Yia8ec42c2008-12-05 07:58:41 -0800422 wmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700423 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
424}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700425
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700426static 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 Winkler3395f6e2008-03-25 16:33:37 -0700437
438#define _iwl_set_bits_prph(priv, reg, mask) \
439 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700440
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700441static 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 Winkler3395f6e2008-03-25 16:33:37 -0700447 _iwl_set_bits_prph(priv, reg, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700448 iwl_release_nic_access(priv);
449 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700450}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700451
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 Abbasa8b50a02009-05-22 11:01:47 -0700455static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg,
456 u32 bits, u32 mask)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700457{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700458 unsigned long reg_flags;
459
460 spin_lock_irqsave(&priv->reg_lock, reg_flags);
461 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700462 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700463 iwl_release_nic_access(priv);
464 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700465}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700466
467static inline void iwl_clear_bits_prph(struct iwl_priv
468 *priv, u32 reg, u32 mask)
469{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700470 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 Winkler3395f6e2008-03-25 16:33:37 -0700476 _iwl_write_prph(priv, reg, (val & ~mask));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700477 iwl_release_nic_access(priv);
478 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700479}
480
481static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
482{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700483 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, Yia8ec42c2008-12-05 07:58:41 -0800490 rmb();
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700491 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 Winkler3395f6e2008-03-25 16:33:37 -0700496}
497
498static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
499{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700500 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 Winkler3395f6e2008-03-25 16:33:37 -0700510}
511
512static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
513 u32 len, u32 *values)
514{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700515 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 Winkler3395f6e2008-03-25 16:33:37 -0700527}
528#endif