blob: c719baf2585a49583f2cef7a4b02107e044830a5 [file] [log] [blame]
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001/******************************************************************************
2 *
Reinette Chatre1f447802010-01-15 13:43:41 -08003 * Copyright(c) 2003 - 2010 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
34#include "iwl-debug.h"
Johannes Bergbe1a71a2009-10-02 13:44:02 -070035#include "iwl-devtrace.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070036
37/*
38 * IO, register, and NIC memory access functions
39 *
40 * NOTE on naming convention and macro usage for these
41 *
42 * A single _ prefix before a an access function means that no state
43 * check or debug information is printed when that function is called.
44 *
45 * A double __ prefix before an access function means that state is checked
Tomas Winkler775ea372008-03-25 16:33:38 -070046 * and the current line number and caller function name are printed in addition
47 * to any other debug output.
Tomas Winkler3395f6e2008-03-25 16:33:37 -070048 *
49 * The non-prefixed name is the #define that maps the caller into a
Tomas Winkler775ea372008-03-25 16:33:38 -070050 * #define that provides the caller's name and __LINE__ to the double
51 * prefix version.
Tomas Winkler3395f6e2008-03-25 16:33:37 -070052 *
53 * If you wish to call the function without any debug or state checking,
54 * you should use the single _ prefix version (as is used by dependent IO
55 * routines, for example _iwl_read_direct32 calls the non-check version of
56 * _iwl_read32.)
57 *
58 * These declarations are *extremely* useful in quickly isolating code deltas
Tomas Winklera96a27f2008-10-23 23:48:56 -070059 * which result in misconfiguration of the hardware I/O. In combination with
Tomas Winkler3395f6e2008-03-25 16:33:37 -070060 * git-bisect and the IO debug level you can quickly determine the specific
61 * commit which breaks the IO sequence to the hardware.
62 *
63 */
64
Ben Cahill4e031852009-11-20 12:04:52 -080065static inline void _iwl_write8(struct iwl_priv *priv, u32 ofs, u8 val)
66{
67 trace_iwlwifi_dev_iowrite8(priv, ofs, val);
68 iowrite8(val, priv->hw_base + ofs);
69}
70
71#ifdef CONFIG_IWLWIFI_DEBUG
72static inline void __iwl_write8(const char *f, u32 l, struct iwl_priv *priv,
73 u32 ofs, u8 val)
74{
75 IWL_DEBUG_IO(priv, "write8(0x%08X, 0x%02X) - %s %d\n", ofs, val, f, l);
76 _iwl_write8(priv, ofs, val);
77}
78#define iwl_write8(priv, ofs, val) \
79 __iwl_write8(__FILE__, __LINE__, priv, ofs, val)
80#else
81#define iwl_write8(priv, ofs, val) _iwl_write8(priv, ofs, val)
82#endif
83
84
Johannes Bergbe1a71a2009-10-02 13:44:02 -070085static inline void _iwl_write32(struct iwl_priv *priv, u32 ofs, u32 val)
86{
87 trace_iwlwifi_dev_iowrite32(priv, ofs, val);
88 iowrite32(val, priv->hw_base + ofs);
89}
90
Tomas Winkler3395f6e2008-03-25 16:33:37 -070091#ifdef CONFIG_IWLWIFI_DEBUG
92static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv,
93 u32 ofs, u32 val)
94{
Tomas Winklere1623442009-01-27 14:27:56 -080095 IWL_DEBUG_IO(priv, "write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -070096 _iwl_write32(priv, ofs, val);
97}
98#define iwl_write32(priv, ofs, val) \
99 __iwl_write32(__FILE__, __LINE__, priv, ofs, val)
100#else
101#define iwl_write32(priv, ofs, val) _iwl_write32(priv, ofs, val)
102#endif
103
Johannes Bergbe1a71a2009-10-02 13:44:02 -0700104static inline u32 _iwl_read32(struct iwl_priv *priv, u32 ofs)
105{
106 u32 val = ioread32(priv->hw_base + ofs);
107 trace_iwlwifi_dev_ioread32(priv, ofs, val);
108 return val;
109}
110
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700111#ifdef CONFIG_IWLWIFI_DEBUG
112static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs)
113{
Tomas Winklere1623442009-01-27 14:27:56 -0800114 IWL_DEBUG_IO(priv, "read_direct32(0x%08X) - %s %d\n", ofs, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700115 return _iwl_read32(priv, ofs);
116}
117#define iwl_read32(priv, ofs) __iwl_read32(__FILE__, __LINE__, priv, ofs)
118#else
119#define iwl_read32(p, o) _iwl_read32(p, o)
120#endif
121
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800122#define IWL_POLL_INTERVAL 10 /* microseconds */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700123static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr,
124 u32 bits, u32 mask, int timeout)
125{
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800126 int t = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700127
128 do {
129 if ((_iwl_read32(priv, addr) & mask) == (bits & mask))
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800130 return t;
131 udelay(IWL_POLL_INTERVAL);
132 t += IWL_POLL_INTERVAL;
133 } while (t < timeout);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700134
135 return -ETIMEDOUT;
136}
137#ifdef CONFIG_IWLWIFI_DEBUG
138static inline int __iwl_poll_bit(const char *f, u32 l,
139 struct iwl_priv *priv, u32 addr,
140 u32 bits, u32 mask, int timeout)
141{
142 int ret = _iwl_poll_bit(priv, addr, bits, mask, timeout);
Tomas Winklere1623442009-01-27 14:27:56 -0800143 IWL_DEBUG_IO(priv, "poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n",
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700144 addr, bits, mask,
Abhijeet Kolekarc3056062008-11-12 13:14:08 -0800145 unlikely(ret == -ETIMEDOUT) ? "timeout" : "", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700146 return ret;
147}
148#define iwl_poll_bit(priv, addr, bits, mask, timeout) \
149 __iwl_poll_bit(__FILE__, __LINE__, priv, addr, bits, mask, timeout)
150#else
151#define iwl_poll_bit(p, a, b, m, t) _iwl_poll_bit(p, a, b, m, t)
152#endif
153
154static inline void _iwl_set_bit(struct iwl_priv *priv, u32 reg, u32 mask)
155{
156 _iwl_write32(priv, reg, _iwl_read32(priv, reg) | mask);
157}
158#ifdef CONFIG_IWLWIFI_DEBUG
159static inline void __iwl_set_bit(const char *f, u32 l,
160 struct iwl_priv *priv, u32 reg, u32 mask)
161{
162 u32 val = _iwl_read32(priv, reg) | mask;
Tomas Winklere1623442009-01-27 14:27:56 -0800163 IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700164 _iwl_write32(priv, reg, val);
165}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700166static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
167{
168 unsigned long reg_flags;
169
170 spin_lock_irqsave(&p->reg_lock, reg_flags);
171 __iwl_set_bit(__FILE__, __LINE__, p, r, m);
172 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
173}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700174#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700175static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
176{
177 unsigned long reg_flags;
178
179 spin_lock_irqsave(&p->reg_lock, reg_flags);
180 _iwl_set_bit(p, r, m);
181 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
182}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700183#endif
184
185static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask)
186{
187 _iwl_write32(priv, reg, _iwl_read32(priv, reg) & ~mask);
188}
189#ifdef CONFIG_IWLWIFI_DEBUG
190static inline void __iwl_clear_bit(const char *f, u32 l,
191 struct iwl_priv *priv, u32 reg, u32 mask)
192{
193 u32 val = _iwl_read32(priv, reg) & ~mask;
Tomas Winklere1623442009-01-27 14:27:56 -0800194 IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700195 _iwl_write32(priv, reg, val);
196}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700197static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
198{
199 unsigned long reg_flags;
200
201 spin_lock_irqsave(&p->reg_lock, reg_flags);
202 __iwl_clear_bit(__FILE__, __LINE__, p, r, m);
203 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
204}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700205#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700206static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
207{
208 unsigned long reg_flags;
209
210 spin_lock_irqsave(&p->reg_lock, reg_flags);
211 _iwl_clear_bit(p, r, m);
212 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
213}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700214#endif
215
216static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
217{
218 int ret;
Reinette Chatre18d426c2009-03-11 11:18:00 -0700219 u32 val;
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700220
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700221 /* this bit wakes up the NIC */
222 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Ben Cahilla7e66112009-11-06 14:53:00 -0800223
224 /*
225 * These bits say the device is running, and should keep running for
226 * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
227 * but they do not indicate that embedded SRAM is restored yet;
228 * 3945 and 4965 have volatile SRAM, and must save/restore contents
229 * to/from host DRAM when sleeping/waking for power-saving.
230 * Each direction takes approximately 1/4 millisecond; with this
231 * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
232 * series of register accesses are expected (e.g. reading Event Log),
233 * to keep device from sleeping.
234 *
235 * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
236 * SRAM is okay/restored. We don't check that here because this call
237 * is just for hardware register access; but GP1 MAC_SLEEP check is a
238 * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
239 *
240 * 5000 series and later (including 1000 series) have non-volatile SRAM,
241 * and do not save/restore SRAM when power cycling.
242 */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700243 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
244 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
245 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
Abbas, Mohamede9414b62009-01-20 21:33:55 -0800246 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700247 if (ret < 0) {
Reinette Chatre18d426c2009-03-11 11:18:00 -0700248 val = _iwl_read32(priv, CSR_GP_CNTRL);
249 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700250 _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700251 return -EIO;
252 }
253
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700254 return 0;
255}
256
257#ifdef CONFIG_IWLWIFI_DEBUG
258static inline int __iwl_grab_nic_access(const char *f, u32 l,
259 struct iwl_priv *priv)
260{
Tomas Winklere1623442009-01-27 14:27:56 -0800261 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700262 return _iwl_grab_nic_access(priv);
263}
264#define iwl_grab_nic_access(priv) \
265 __iwl_grab_nic_access(__FILE__, __LINE__, priv)
266#else
267#define iwl_grab_nic_access(priv) \
268 _iwl_grab_nic_access(priv)
269#endif
270
271static inline void _iwl_release_nic_access(struct iwl_priv *priv)
272{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700273 _iwl_clear_bit(priv, CSR_GP_CNTRL,
274 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700275}
276#ifdef CONFIG_IWLWIFI_DEBUG
277static inline void __iwl_release_nic_access(const char *f, u32 l,
278 struct iwl_priv *priv)
279{
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700280
Tomas Winklere1623442009-01-27 14:27:56 -0800281 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700282 _iwl_release_nic_access(priv);
283}
284#define iwl_release_nic_access(priv) \
285 __iwl_release_nic_access(__FILE__, __LINE__, priv)
286#else
287#define iwl_release_nic_access(priv) \
288 _iwl_release_nic_access(priv)
289#endif
290
291static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg)
292{
293 return _iwl_read32(priv, reg);
294}
295#ifdef CONFIG_IWLWIFI_DEBUG
296static inline u32 __iwl_read_direct32(const char *f, u32 l,
297 struct iwl_priv *priv, u32 reg)
298{
299 u32 value = _iwl_read_direct32(priv, reg);
Tomas Winklere1623442009-01-27 14:27:56 -0800300 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700301 f, l);
302 return value;
303}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700304static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
305{
306 u32 value;
307 unsigned long reg_flags;
308
309 spin_lock_irqsave(&priv->reg_lock, reg_flags);
310 iwl_grab_nic_access(priv);
311 value = __iwl_read_direct32(__FILE__, __LINE__, priv, reg);
312 iwl_release_nic_access(priv);
313 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
314 return value;
315}
316
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700317#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700318static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
319{
320 u32 value;
321 unsigned long reg_flags;
322
323 spin_lock_irqsave(&priv->reg_lock, reg_flags);
324 iwl_grab_nic_access(priv);
325 value = _iwl_read_direct32(priv, reg);
326 iwl_release_nic_access(priv);
327 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
328 return value;
329
330}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700331#endif
332
333static inline void _iwl_write_direct32(struct iwl_priv *priv,
334 u32 reg, u32 value)
335{
336 _iwl_write32(priv, reg, value);
337}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700338static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700339{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700340 unsigned long reg_flags;
341
342 spin_lock_irqsave(&priv->reg_lock, reg_flags);
343 if (!iwl_grab_nic_access(priv)) {
344 _iwl_write_direct32(priv, reg, value);
345 iwl_release_nic_access(priv);
346 }
347 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700348}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700349
350static inline void iwl_write_reg_buf(struct iwl_priv *priv,
351 u32 reg, u32 len, u32 *values)
352{
353 u32 count = sizeof(u32);
354
355 if ((priv != NULL) && (values != NULL)) {
356 for (; 0 < len; len -= count, reg += count, values++)
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700357 iwl_write_direct32(priv, reg, *values);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700358 }
359}
360
Zhu, Yi73d7b5a2008-12-05 07:58:40 -0800361static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
362 u32 mask, int timeout)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700363{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700364 int t = 0;
365
366 do {
367 if ((iwl_read_direct32(priv, addr) & mask) == mask)
368 return t;
369 udelay(IWL_POLL_INTERVAL);
370 t += IWL_POLL_INTERVAL;
371 } while (t < timeout);
372
373 return -ETIMEDOUT;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700374}
375
376#ifdef CONFIG_IWLWIFI_DEBUG
377static inline int __iwl_poll_direct_bit(const char *f, u32 l,
378 struct iwl_priv *priv,
379 u32 addr, u32 mask, int timeout)
380{
381 int ret = _iwl_poll_direct_bit(priv, addr, mask, timeout);
382
383 if (unlikely(ret == -ETIMEDOUT))
Tomas Winklere1623442009-01-27 14:27:56 -0800384 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) - "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700385 "timedout - %s %d\n", addr, mask, f, l);
386 else
Tomas Winklere1623442009-01-27 14:27:56 -0800387 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700388 "- %s %d\n", addr, mask, ret, f, l);
389 return ret;
390}
391#define iwl_poll_direct_bit(priv, addr, mask, timeout) \
392 __iwl_poll_direct_bit(__FILE__, __LINE__, priv, addr, mask, timeout)
393#else
394#define iwl_poll_direct_bit _iwl_poll_direct_bit
395#endif
396
397static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
398{
399 _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800400 rmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700401 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
402}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700403static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700404{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700405 unsigned long reg_flags;
406 u32 val;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700407
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700408 spin_lock_irqsave(&priv->reg_lock, reg_flags);
409 iwl_grab_nic_access(priv);
410 val = _iwl_read_prph(priv, reg);
411 iwl_release_nic_access(priv);
412 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
413 return val;
414}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700415
416static inline void _iwl_write_prph(struct iwl_priv *priv,
417 u32 addr, u32 val)
418{
419 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
420 ((addr & 0x0000FFFF) | (3 << 24)));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800421 wmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700422 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
423}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700424
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700425static inline void iwl_write_prph(struct iwl_priv *priv, u32 addr, u32 val)
426{
427 unsigned long reg_flags;
428
429 spin_lock_irqsave(&priv->reg_lock, reg_flags);
430 if (!iwl_grab_nic_access(priv)) {
431 _iwl_write_prph(priv, addr, val);
432 iwl_release_nic_access(priv);
433 }
434 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
435}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700436
437#define _iwl_set_bits_prph(priv, reg, mask) \
438 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700439
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700440static inline void iwl_set_bits_prph(struct iwl_priv *priv, u32 reg, u32 mask)
441{
442 unsigned long reg_flags;
443
444 spin_lock_irqsave(&priv->reg_lock, reg_flags);
445 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700446 _iwl_set_bits_prph(priv, reg, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700447 iwl_release_nic_access(priv);
448 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700449}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700450
451#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \
452 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits))
453
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700454static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg,
455 u32 bits, u32 mask)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700456{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700457 unsigned long reg_flags;
458
459 spin_lock_irqsave(&priv->reg_lock, reg_flags);
460 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700461 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700462 iwl_release_nic_access(priv);
463 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700464}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700465
466static inline void iwl_clear_bits_prph(struct iwl_priv
467 *priv, u32 reg, u32 mask)
468{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700469 unsigned long reg_flags;
470 u32 val;
471
472 spin_lock_irqsave(&priv->reg_lock, reg_flags);
473 iwl_grab_nic_access(priv);
474 val = _iwl_read_prph(priv, reg);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700475 _iwl_write_prph(priv, reg, (val & ~mask));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700476 iwl_release_nic_access(priv);
477 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700478}
479
480static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
481{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700482 unsigned long reg_flags;
483 u32 value;
484
485 spin_lock_irqsave(&priv->reg_lock, reg_flags);
486 iwl_grab_nic_access(priv);
487
488 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800489 rmb();
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700490 value = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
491
492 iwl_release_nic_access(priv);
493 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
494 return value;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700495}
496
497static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
498{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700499 unsigned long reg_flags;
500
501 spin_lock_irqsave(&priv->reg_lock, reg_flags);
502 if (!iwl_grab_nic_access(priv)) {
503 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
504 wmb();
505 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
506 iwl_release_nic_access(priv);
507 }
508 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700509}
510
511static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
512 u32 len, u32 *values)
513{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700514 unsigned long reg_flags;
515
516 spin_lock_irqsave(&priv->reg_lock, reg_flags);
517 if (!iwl_grab_nic_access(priv)) {
518 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
519 wmb();
520 for (; 0 < len; len -= sizeof(u32), values++)
521 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
522
523 iwl_release_nic_access(priv);
524 }
525 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700526}
527#endif