blob: 0a078b082833ebad4d3a77009555411d6affcb7c [file] [log] [blame]
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 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
Johannes Bergbe1a71a2009-10-02 13:44:02 -070065static inline void _iwl_write32(struct iwl_priv *priv, u32 ofs, u32 val)
66{
67 trace_iwlwifi_dev_iowrite32(priv, ofs, val);
68 iowrite32(val, priv->hw_base + ofs);
69}
70
Tomas Winkler3395f6e2008-03-25 16:33:37 -070071#ifdef CONFIG_IWLWIFI_DEBUG
72static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *priv,
73 u32 ofs, u32 val)
74{
Tomas Winklere1623442009-01-27 14:27:56 -080075 IWL_DEBUG_IO(priv, "write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -070076 _iwl_write32(priv, ofs, val);
77}
78#define iwl_write32(priv, ofs, val) \
79 __iwl_write32(__FILE__, __LINE__, priv, ofs, val)
80#else
81#define iwl_write32(priv, ofs, val) _iwl_write32(priv, ofs, val)
82#endif
83
Johannes Bergbe1a71a2009-10-02 13:44:02 -070084static inline u32 _iwl_read32(struct iwl_priv *priv, u32 ofs)
85{
86 u32 val = ioread32(priv->hw_base + ofs);
87 trace_iwlwifi_dev_ioread32(priv, ofs, val);
88 return val;
89}
90
Tomas Winkler3395f6e2008-03-25 16:33:37 -070091#ifdef CONFIG_IWLWIFI_DEBUG
92static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *priv, u32 ofs)
93{
Tomas Winklere1623442009-01-27 14:27:56 -080094 IWL_DEBUG_IO(priv, "read_direct32(0x%08X) - %s %d\n", ofs, f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -070095 return _iwl_read32(priv, ofs);
96}
97#define iwl_read32(priv, ofs) __iwl_read32(__FILE__, __LINE__, priv, ofs)
98#else
99#define iwl_read32(p, o) _iwl_read32(p, o)
100#endif
101
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800102#define IWL_POLL_INTERVAL 10 /* microseconds */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700103static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr,
104 u32 bits, u32 mask, int timeout)
105{
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800106 int t = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700107
108 do {
109 if ((_iwl_read32(priv, addr) & mask) == (bits & mask))
Wu, Fengguang4087f6f2008-12-17 16:52:32 +0800110 return t;
111 udelay(IWL_POLL_INTERVAL);
112 t += IWL_POLL_INTERVAL;
113 } while (t < timeout);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700114
115 return -ETIMEDOUT;
116}
117#ifdef CONFIG_IWLWIFI_DEBUG
118static inline int __iwl_poll_bit(const char *f, u32 l,
119 struct iwl_priv *priv, u32 addr,
120 u32 bits, u32 mask, int timeout)
121{
122 int ret = _iwl_poll_bit(priv, addr, bits, mask, timeout);
Tomas Winklere1623442009-01-27 14:27:56 -0800123 IWL_DEBUG_IO(priv, "poll_bit(0x%08X, 0x%08X, 0x%08X) - %s- %s %d\n",
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700124 addr, bits, mask,
Abhijeet Kolekarc3056062008-11-12 13:14:08 -0800125 unlikely(ret == -ETIMEDOUT) ? "timeout" : "", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700126 return ret;
127}
128#define iwl_poll_bit(priv, addr, bits, mask, timeout) \
129 __iwl_poll_bit(__FILE__, __LINE__, priv, addr, bits, mask, timeout)
130#else
131#define iwl_poll_bit(p, a, b, m, t) _iwl_poll_bit(p, a, b, m, t)
132#endif
133
134static inline void _iwl_set_bit(struct iwl_priv *priv, u32 reg, u32 mask)
135{
136 _iwl_write32(priv, reg, _iwl_read32(priv, reg) | mask);
137}
138#ifdef CONFIG_IWLWIFI_DEBUG
139static inline void __iwl_set_bit(const char *f, u32 l,
140 struct iwl_priv *priv, u32 reg, u32 mask)
141{
142 u32 val = _iwl_read32(priv, reg) | mask;
Tomas Winklere1623442009-01-27 14:27:56 -0800143 IWL_DEBUG_IO(priv, "set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700144 _iwl_write32(priv, reg, val);
145}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700146static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
147{
148 unsigned long reg_flags;
149
150 spin_lock_irqsave(&p->reg_lock, reg_flags);
151 __iwl_set_bit(__FILE__, __LINE__, p, r, m);
152 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
153}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700154#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700155static inline void iwl_set_bit(struct iwl_priv *p, u32 r, u32 m)
156{
157 unsigned long reg_flags;
158
159 spin_lock_irqsave(&p->reg_lock, reg_flags);
160 _iwl_set_bit(p, r, m);
161 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
162}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700163#endif
164
165static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask)
166{
167 _iwl_write32(priv, reg, _iwl_read32(priv, reg) & ~mask);
168}
169#ifdef CONFIG_IWLWIFI_DEBUG
170static inline void __iwl_clear_bit(const char *f, u32 l,
171 struct iwl_priv *priv, u32 reg, u32 mask)
172{
173 u32 val = _iwl_read32(priv, reg) & ~mask;
Tomas Winklere1623442009-01-27 14:27:56 -0800174 IWL_DEBUG_IO(priv, "clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700175 _iwl_write32(priv, reg, val);
176}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700177static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
178{
179 unsigned long reg_flags;
180
181 spin_lock_irqsave(&p->reg_lock, reg_flags);
182 __iwl_clear_bit(__FILE__, __LINE__, p, r, m);
183 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
184}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700185#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700186static inline void iwl_clear_bit(struct iwl_priv *p, u32 r, u32 m)
187{
188 unsigned long reg_flags;
189
190 spin_lock_irqsave(&p->reg_lock, reg_flags);
191 _iwl_clear_bit(p, r, m);
192 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
193}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700194#endif
195
196static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
197{
198 int ret;
Reinette Chatre18d426c2009-03-11 11:18:00 -0700199 u32 val;
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700200
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700201 /* this bit wakes up the NIC */
202 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
203 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
204 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
205 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
Abbas, Mohamede9414b62009-01-20 21:33:55 -0800206 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700207 if (ret < 0) {
Reinette Chatre18d426c2009-03-11 11:18:00 -0700208 val = _iwl_read32(priv, CSR_GP_CNTRL);
209 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700210 _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700211 return -EIO;
212 }
213
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700214 return 0;
215}
216
217#ifdef CONFIG_IWLWIFI_DEBUG
218static inline int __iwl_grab_nic_access(const char *f, u32 l,
219 struct iwl_priv *priv)
220{
Tomas Winklere1623442009-01-27 14:27:56 -0800221 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700222 return _iwl_grab_nic_access(priv);
223}
224#define iwl_grab_nic_access(priv) \
225 __iwl_grab_nic_access(__FILE__, __LINE__, priv)
226#else
227#define iwl_grab_nic_access(priv) \
228 _iwl_grab_nic_access(priv)
229#endif
230
231static inline void _iwl_release_nic_access(struct iwl_priv *priv)
232{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700233 _iwl_clear_bit(priv, CSR_GP_CNTRL,
234 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700235}
236#ifdef CONFIG_IWLWIFI_DEBUG
237static inline void __iwl_release_nic_access(const char *f, u32 l,
238 struct iwl_priv *priv)
239{
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700240
Tomas Winklere1623442009-01-27 14:27:56 -0800241 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700242 _iwl_release_nic_access(priv);
243}
244#define iwl_release_nic_access(priv) \
245 __iwl_release_nic_access(__FILE__, __LINE__, priv)
246#else
247#define iwl_release_nic_access(priv) \
248 _iwl_release_nic_access(priv)
249#endif
250
251static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg)
252{
253 return _iwl_read32(priv, reg);
254}
255#ifdef CONFIG_IWLWIFI_DEBUG
256static inline u32 __iwl_read_direct32(const char *f, u32 l,
257 struct iwl_priv *priv, u32 reg)
258{
259 u32 value = _iwl_read_direct32(priv, reg);
Tomas Winklere1623442009-01-27 14:27:56 -0800260 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700261 f, l);
262 return value;
263}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700264static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
265{
266 u32 value;
267 unsigned long reg_flags;
268
269 spin_lock_irqsave(&priv->reg_lock, reg_flags);
270 iwl_grab_nic_access(priv);
271 value = __iwl_read_direct32(__FILE__, __LINE__, priv, reg);
272 iwl_release_nic_access(priv);
273 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
274 return value;
275}
276
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700277#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700278static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
279{
280 u32 value;
281 unsigned long reg_flags;
282
283 spin_lock_irqsave(&priv->reg_lock, reg_flags);
284 iwl_grab_nic_access(priv);
285 value = _iwl_read_direct32(priv, reg);
286 iwl_release_nic_access(priv);
287 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
288 return value;
289
290}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700291#endif
292
293static inline void _iwl_write_direct32(struct iwl_priv *priv,
294 u32 reg, u32 value)
295{
296 _iwl_write32(priv, reg, value);
297}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700298static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700299{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700300 unsigned long reg_flags;
301
302 spin_lock_irqsave(&priv->reg_lock, reg_flags);
303 if (!iwl_grab_nic_access(priv)) {
304 _iwl_write_direct32(priv, reg, value);
305 iwl_release_nic_access(priv);
306 }
307 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700308}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700309
310static inline void iwl_write_reg_buf(struct iwl_priv *priv,
311 u32 reg, u32 len, u32 *values)
312{
313 u32 count = sizeof(u32);
314
315 if ((priv != NULL) && (values != NULL)) {
316 for (; 0 < len; len -= count, reg += count, values++)
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700317 iwl_write_direct32(priv, reg, *values);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700318 }
319}
320
Zhu, Yi73d7b5a2008-12-05 07:58:40 -0800321static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
322 u32 mask, int timeout)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700323{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700324 int t = 0;
325
326 do {
327 if ((iwl_read_direct32(priv, addr) & mask) == mask)
328 return t;
329 udelay(IWL_POLL_INTERVAL);
330 t += IWL_POLL_INTERVAL;
331 } while (t < timeout);
332
333 return -ETIMEDOUT;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700334}
335
336#ifdef CONFIG_IWLWIFI_DEBUG
337static inline int __iwl_poll_direct_bit(const char *f, u32 l,
338 struct iwl_priv *priv,
339 u32 addr, u32 mask, int timeout)
340{
341 int ret = _iwl_poll_direct_bit(priv, addr, mask, timeout);
342
343 if (unlikely(ret == -ETIMEDOUT))
Tomas Winklere1623442009-01-27 14:27:56 -0800344 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) - "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700345 "timedout - %s %d\n", addr, mask, f, l);
346 else
Tomas Winklere1623442009-01-27 14:27:56 -0800347 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700348 "- %s %d\n", addr, mask, ret, f, l);
349 return ret;
350}
351#define iwl_poll_direct_bit(priv, addr, mask, timeout) \
352 __iwl_poll_direct_bit(__FILE__, __LINE__, priv, addr, mask, timeout)
353#else
354#define iwl_poll_direct_bit _iwl_poll_direct_bit
355#endif
356
357static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
358{
359 _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800360 rmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700361 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
362}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700363static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700364{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700365 unsigned long reg_flags;
366 u32 val;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700367
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700368 spin_lock_irqsave(&priv->reg_lock, reg_flags);
369 iwl_grab_nic_access(priv);
370 val = _iwl_read_prph(priv, reg);
371 iwl_release_nic_access(priv);
372 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
373 return val;
374}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700375
376static inline void _iwl_write_prph(struct iwl_priv *priv,
377 u32 addr, u32 val)
378{
379 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
380 ((addr & 0x0000FFFF) | (3 << 24)));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800381 wmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700382 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
383}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700384
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700385static inline void iwl_write_prph(struct iwl_priv *priv, u32 addr, u32 val)
386{
387 unsigned long reg_flags;
388
389 spin_lock_irqsave(&priv->reg_lock, reg_flags);
390 if (!iwl_grab_nic_access(priv)) {
391 _iwl_write_prph(priv, addr, val);
392 iwl_release_nic_access(priv);
393 }
394 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
395}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700396
397#define _iwl_set_bits_prph(priv, reg, mask) \
398 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700399
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700400static inline void iwl_set_bits_prph(struct iwl_priv *priv, u32 reg, u32 mask)
401{
402 unsigned long reg_flags;
403
404 spin_lock_irqsave(&priv->reg_lock, reg_flags);
405 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700406 _iwl_set_bits_prph(priv, reg, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700407 iwl_release_nic_access(priv);
408 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700409}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700410
411#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \
412 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits))
413
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700414static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg,
415 u32 bits, u32 mask)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700416{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700417 unsigned long reg_flags;
418
419 spin_lock_irqsave(&priv->reg_lock, reg_flags);
420 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700421 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700422 iwl_release_nic_access(priv);
423 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700424}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700425
426static inline void iwl_clear_bits_prph(struct iwl_priv
427 *priv, u32 reg, u32 mask)
428{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700429 unsigned long reg_flags;
430 u32 val;
431
432 spin_lock_irqsave(&priv->reg_lock, reg_flags);
433 iwl_grab_nic_access(priv);
434 val = _iwl_read_prph(priv, reg);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700435 _iwl_write_prph(priv, reg, (val & ~mask));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700436 iwl_release_nic_access(priv);
437 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700438}
439
440static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
441{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700442 unsigned long reg_flags;
443 u32 value;
444
445 spin_lock_irqsave(&priv->reg_lock, reg_flags);
446 iwl_grab_nic_access(priv);
447
448 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800449 rmb();
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700450 value = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
451
452 iwl_release_nic_access(priv);
453 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
454 return value;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700455}
456
457static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
458{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700459 unsigned long reg_flags;
460
461 spin_lock_irqsave(&priv->reg_lock, reg_flags);
462 if (!iwl_grab_nic_access(priv)) {
463 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
464 wmb();
465 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
466 iwl_release_nic_access(priv);
467 }
468 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700469}
470
471static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
472 u32 len, u32 *values)
473{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700474 unsigned long reg_flags;
475
476 spin_lock_irqsave(&priv->reg_lock, reg_flags);
477 if (!iwl_grab_nic_access(priv)) {
478 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
479 wmb();
480 for (; 0 < len; len -= sizeof(u32), values++)
481 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
482
483 iwl_release_nic_access(priv);
484 }
485 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700486}
487#endif