blob: d0a358c9d96b48f5ba5620e23160b23a9e83ac73 [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);
Ben Cahilla7e66112009-11-06 14:53:00 -0800203
204 /*
205 * These bits say the device is running, and should keep running for
206 * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
207 * but they do not indicate that embedded SRAM is restored yet;
208 * 3945 and 4965 have volatile SRAM, and must save/restore contents
209 * to/from host DRAM when sleeping/waking for power-saving.
210 * Each direction takes approximately 1/4 millisecond; with this
211 * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
212 * series of register accesses are expected (e.g. reading Event Log),
213 * to keep device from sleeping.
214 *
215 * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
216 * SRAM is okay/restored. We don't check that here because this call
217 * is just for hardware register access; but GP1 MAC_SLEEP check is a
218 * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
219 *
220 * 5000 series and later (including 1000 series) have non-volatile SRAM,
221 * and do not save/restore SRAM when power cycling.
222 */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700223 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
224 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
225 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
Abbas, Mohamede9414b62009-01-20 21:33:55 -0800226 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700227 if (ret < 0) {
Reinette Chatre18d426c2009-03-11 11:18:00 -0700228 val = _iwl_read32(priv, CSR_GP_CNTRL);
229 IWL_ERR(priv, "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700230 _iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_FORCE_NMI);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700231 return -EIO;
232 }
233
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700234 return 0;
235}
236
237#ifdef CONFIG_IWLWIFI_DEBUG
238static inline int __iwl_grab_nic_access(const char *f, u32 l,
239 struct iwl_priv *priv)
240{
Tomas Winklere1623442009-01-27 14:27:56 -0800241 IWL_DEBUG_IO(priv, "grabbing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700242 return _iwl_grab_nic_access(priv);
243}
244#define iwl_grab_nic_access(priv) \
245 __iwl_grab_nic_access(__FILE__, __LINE__, priv)
246#else
247#define iwl_grab_nic_access(priv) \
248 _iwl_grab_nic_access(priv)
249#endif
250
251static inline void _iwl_release_nic_access(struct iwl_priv *priv)
252{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700253 _iwl_clear_bit(priv, CSR_GP_CNTRL,
254 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700255}
256#ifdef CONFIG_IWLWIFI_DEBUG
257static inline void __iwl_release_nic_access(const char *f, u32 l,
258 struct iwl_priv *priv)
259{
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700260
Tomas Winklere1623442009-01-27 14:27:56 -0800261 IWL_DEBUG_IO(priv, "releasing nic access - %s %d\n", f, l);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700262 _iwl_release_nic_access(priv);
263}
264#define iwl_release_nic_access(priv) \
265 __iwl_release_nic_access(__FILE__, __LINE__, priv)
266#else
267#define iwl_release_nic_access(priv) \
268 _iwl_release_nic_access(priv)
269#endif
270
271static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg)
272{
273 return _iwl_read32(priv, reg);
274}
275#ifdef CONFIG_IWLWIFI_DEBUG
276static inline u32 __iwl_read_direct32(const char *f, u32 l,
277 struct iwl_priv *priv, u32 reg)
278{
279 u32 value = _iwl_read_direct32(priv, reg);
Tomas Winklere1623442009-01-27 14:27:56 -0800280 IWL_DEBUG_IO(priv, "read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700281 f, l);
282 return value;
283}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700284static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
285{
286 u32 value;
287 unsigned long reg_flags;
288
289 spin_lock_irqsave(&priv->reg_lock, reg_flags);
290 iwl_grab_nic_access(priv);
291 value = __iwl_read_direct32(__FILE__, __LINE__, priv, reg);
292 iwl_release_nic_access(priv);
293 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
294 return value;
295}
296
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700297#else
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700298static inline u32 iwl_read_direct32(struct iwl_priv *priv, u32 reg)
299{
300 u32 value;
301 unsigned long reg_flags;
302
303 spin_lock_irqsave(&priv->reg_lock, reg_flags);
304 iwl_grab_nic_access(priv);
305 value = _iwl_read_direct32(priv, reg);
306 iwl_release_nic_access(priv);
307 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
308 return value;
309
310}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700311#endif
312
313static inline void _iwl_write_direct32(struct iwl_priv *priv,
314 u32 reg, u32 value)
315{
316 _iwl_write32(priv, reg, value);
317}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700318static inline void iwl_write_direct32(struct iwl_priv *priv, u32 reg, u32 value)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700319{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700320 unsigned long reg_flags;
321
322 spin_lock_irqsave(&priv->reg_lock, reg_flags);
323 if (!iwl_grab_nic_access(priv)) {
324 _iwl_write_direct32(priv, reg, value);
325 iwl_release_nic_access(priv);
326 }
327 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700328}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700329
330static inline void iwl_write_reg_buf(struct iwl_priv *priv,
331 u32 reg, u32 len, u32 *values)
332{
333 u32 count = sizeof(u32);
334
335 if ((priv != NULL) && (values != NULL)) {
336 for (; 0 < len; len -= count, reg += count, values++)
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700337 iwl_write_direct32(priv, reg, *values);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700338 }
339}
340
Zhu, Yi73d7b5a2008-12-05 07:58:40 -0800341static inline int _iwl_poll_direct_bit(struct iwl_priv *priv, u32 addr,
342 u32 mask, int timeout)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700343{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700344 int t = 0;
345
346 do {
347 if ((iwl_read_direct32(priv, addr) & mask) == mask)
348 return t;
349 udelay(IWL_POLL_INTERVAL);
350 t += IWL_POLL_INTERVAL;
351 } while (t < timeout);
352
353 return -ETIMEDOUT;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700354}
355
356#ifdef CONFIG_IWLWIFI_DEBUG
357static inline int __iwl_poll_direct_bit(const char *f, u32 l,
358 struct iwl_priv *priv,
359 u32 addr, u32 mask, int timeout)
360{
361 int ret = _iwl_poll_direct_bit(priv, addr, mask, timeout);
362
363 if (unlikely(ret == -ETIMEDOUT))
Tomas Winklere1623442009-01-27 14:27:56 -0800364 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) - "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700365 "timedout - %s %d\n", addr, mask, f, l);
366 else
Tomas Winklere1623442009-01-27 14:27:56 -0800367 IWL_DEBUG_IO(priv, "poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700368 "- %s %d\n", addr, mask, ret, f, l);
369 return ret;
370}
371#define iwl_poll_direct_bit(priv, addr, mask, timeout) \
372 __iwl_poll_direct_bit(__FILE__, __LINE__, priv, addr, mask, timeout)
373#else
374#define iwl_poll_direct_bit _iwl_poll_direct_bit
375#endif
376
377static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
378{
379 _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800380 rmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700381 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
382}
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700383static inline u32 iwl_read_prph(struct iwl_priv *priv, u32 reg)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700384{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700385 unsigned long reg_flags;
386 u32 val;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700387
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700388 spin_lock_irqsave(&priv->reg_lock, reg_flags);
389 iwl_grab_nic_access(priv);
390 val = _iwl_read_prph(priv, reg);
391 iwl_release_nic_access(priv);
392 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
393 return val;
394}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700395
396static inline void _iwl_write_prph(struct iwl_priv *priv,
397 u32 addr, u32 val)
398{
399 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
400 ((addr & 0x0000FFFF) | (3 << 24)));
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800401 wmb();
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700402 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
403}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700404
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700405static inline void iwl_write_prph(struct iwl_priv *priv, u32 addr, u32 val)
406{
407 unsigned long reg_flags;
408
409 spin_lock_irqsave(&priv->reg_lock, reg_flags);
410 if (!iwl_grab_nic_access(priv)) {
411 _iwl_write_prph(priv, addr, val);
412 iwl_release_nic_access(priv);
413 }
414 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
415}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700416
417#define _iwl_set_bits_prph(priv, reg, mask) \
418 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700419
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700420static inline void iwl_set_bits_prph(struct iwl_priv *priv, u32 reg, u32 mask)
421{
422 unsigned long reg_flags;
423
424 spin_lock_irqsave(&priv->reg_lock, reg_flags);
425 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700426 _iwl_set_bits_prph(priv, reg, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700427 iwl_release_nic_access(priv);
428 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700429}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700430
431#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \
432 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits))
433
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700434static inline void iwl_set_bits_mask_prph(struct iwl_priv *priv, u32 reg,
435 u32 bits, u32 mask)
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700436{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700437 unsigned long reg_flags;
438
439 spin_lock_irqsave(&priv->reg_lock, reg_flags);
440 iwl_grab_nic_access(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700441 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700442 iwl_release_nic_access(priv);
443 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700444}
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700445
446static inline void iwl_clear_bits_prph(struct iwl_priv
447 *priv, u32 reg, u32 mask)
448{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700449 unsigned long reg_flags;
450 u32 val;
451
452 spin_lock_irqsave(&priv->reg_lock, reg_flags);
453 iwl_grab_nic_access(priv);
454 val = _iwl_read_prph(priv, reg);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700455 _iwl_write_prph(priv, reg, (val & ~mask));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700456 iwl_release_nic_access(priv);
457 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700458}
459
460static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
461{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700462 unsigned long reg_flags;
463 u32 value;
464
465 spin_lock_irqsave(&priv->reg_lock, reg_flags);
466 iwl_grab_nic_access(priv);
467
468 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
Zhu, Yia8ec42c2008-12-05 07:58:41 -0800469 rmb();
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700470 value = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
471
472 iwl_release_nic_access(priv);
473 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
474 return value;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700475}
476
477static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
478{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700479 unsigned long reg_flags;
480
481 spin_lock_irqsave(&priv->reg_lock, reg_flags);
482 if (!iwl_grab_nic_access(priv)) {
483 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
484 wmb();
485 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
486 iwl_release_nic_access(priv);
487 }
488 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700489}
490
491static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
492 u32 len, u32 *values)
493{
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700494 unsigned long reg_flags;
495
496 spin_lock_irqsave(&priv->reg_lock, reg_flags);
497 if (!iwl_grab_nic_access(priv)) {
498 _iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
499 wmb();
500 for (; 0 < len; len -= sizeof(u32), values++)
501 _iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
502
503 iwl_release_nic_access(priv);
504 }
505 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700506}
507#endif