blob: 74a51798c232f5fa2bacfa660b208d1e011c9596 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
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:
24 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
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
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080034#include "iwl-3945-debug.h"
Zhu Yib481de92007-09-25 17:54:57 -070035
36/*
37 * IO, register, and NIC memory access functions
38 *
39 * NOTE on naming convention and macro usage for these
40 *
41 * A single _ prefix before a an access function means that no state
42 * check or debug information is printed when that function is called.
43 *
44 * A double __ prefix before an access function means that state is checked
Tomas Winklerac17a942007-10-25 17:15:37 +080045 * and the current line number is printed in addition to any other debug output.
Zhu Yib481de92007-09-25 17:54:57 -070046 *
47 * The non-prefixed name is the #define that maps the caller into a
48 * #define that provides the caller's __LINE__ to the double prefix version.
49 *
50 * If you wish to call the function without any debug or state checking,
51 * you should use the single _ prefix version (as is used by dependent IO
Tomas Winklerac17a942007-10-25 17:15:37 +080052 * routines, for example _iwl_read_direct32 calls the non-check version of
Zhu Yib481de92007-09-25 17:54:57 -070053 * _iwl_read32.)
54 *
55 * These declarations are *extremely* useful in quickly isolating code deltas
56 * which result in misconfiguring of the hardware I/O. In combination with
57 * git-bisect and the IO debug level you can quickly determine the specific
58 * commit which breaks the IO sequence to the hardware.
59 *
60 */
61
62#define _iwl_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs))
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080063#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070064static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *iwl,
65 u32 ofs, u32 val)
66{
Tomas Winklerac17a942007-10-25 17:15:37 +080067 IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
Zhu Yib481de92007-09-25 17:54:57 -070068 _iwl_write32(iwl, ofs, val);
69}
70#define iwl_write32(iwl, ofs, val) \
71 __iwl_write32(__FILE__, __LINE__, iwl, ofs, val)
72#else
73#define iwl_write32(iwl, ofs, val) _iwl_write32(iwl, ofs, val)
74#endif
75
76#define _iwl_read32(iwl, ofs) readl((iwl)->hw_base + (ofs))
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080077#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070078static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *iwl, u32 ofs)
79{
80 IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l);
81 return _iwl_read32(iwl, ofs);
82}
83#define iwl_read32(iwl, ofs) __iwl_read32(__FILE__, __LINE__, iwl, ofs)
84#else
85#define iwl_read32(p, o) _iwl_read32(p, o)
86#endif
87
88static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr,
89 u32 bits, u32 mask, int timeout)
90{
91 int i = 0;
92
93 do {
94 if ((_iwl_read32(priv, addr) & mask) == (bits & mask))
95 return i;
96 mdelay(10);
97 i += 10;
98 } while (i < timeout);
99
100 return -ETIMEDOUT;
101}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800102#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700103static inline int __iwl_poll_bit(const char *f, u32 l,
104 struct iwl_priv *priv, u32 addr,
105 u32 bits, u32 mask, int timeout)
106{
Tomas Winklerac17a942007-10-25 17:15:37 +0800107 int ret = _iwl_poll_bit(priv, addr, bits, mask, timeout);
108 if (unlikely(ret == -ETIMEDOUT))
Zhu Yib481de92007-09-25 17:54:57 -0700109 IWL_DEBUG_IO
110 ("poll_bit(0x%08X, 0x%08X, 0x%08X) - timedout - %s %d\n",
111 addr, bits, mask, f, l);
112 else
113 IWL_DEBUG_IO
114 ("poll_bit(0x%08X, 0x%08X, 0x%08X) = 0x%08X - %s %d\n",
Tomas Winklerac17a942007-10-25 17:15:37 +0800115 addr, bits, mask, ret, f, l);
116 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700117}
118#define iwl_poll_bit(iwl, addr, bits, mask, timeout) \
119 __iwl_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout)
120#else
121#define iwl_poll_bit(p, a, b, m, t) _iwl_poll_bit(p, a, b, m, t)
122#endif
123
124static inline void _iwl_set_bit(struct iwl_priv *priv, u32 reg, u32 mask)
125{
126 _iwl_write32(priv, reg, _iwl_read32(priv, reg) | mask);
127}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800128#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700129static inline void __iwl_set_bit(const char *f, u32 l,
130 struct iwl_priv *priv, u32 reg, u32 mask)
131{
132 u32 val = _iwl_read32(priv, reg) | mask;
133 IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
134 _iwl_write32(priv, reg, val);
135}
136#define iwl_set_bit(p, r, m) __iwl_set_bit(__FILE__, __LINE__, p, r, m)
137#else
138#define iwl_set_bit(p, r, m) _iwl_set_bit(p, r, m)
139#endif
140
141static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask)
142{
143 _iwl_write32(priv, reg, _iwl_read32(priv, reg) & ~mask);
144}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800145#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700146static inline void __iwl_clear_bit(const char *f, u32 l,
147 struct iwl_priv *priv, u32 reg, u32 mask)
148{
149 u32 val = _iwl_read32(priv, reg) & ~mask;
150 IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
151 _iwl_write32(priv, reg, val);
152}
153#define iwl_clear_bit(p, r, m) __iwl_clear_bit(__FILE__, __LINE__, p, r, m)
154#else
155#define iwl_clear_bit(p, r, m) _iwl_clear_bit(p, r, m)
156#endif
157
Tomas Winklerac17a942007-10-25 17:15:37 +0800158static inline int _iwl_grab_nic_access(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700159{
Tomas Winklerac17a942007-10-25 17:15:37 +0800160 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700161 u32 gp_ctl;
162
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800163#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700164 if (atomic_read(&priv->restrict_refcnt))
165 return 0;
166#endif
167 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
168 test_bit(STATUS_RF_KILL_SW, &priv->status)) {
169 IWL_WARNING("WARNING: Requesting MAC access during RFKILL "
170 "wakes up NIC\n");
171
172 /* 10 msec allows time for NIC to complete its data save */
173 gp_ctl = _iwl_read32(priv, CSR_GP_CNTRL);
174 if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) {
175 IWL_DEBUG_RF_KILL("Wait for complete power-down, "
176 "gpctl = 0x%08x\n", gp_ctl);
177 mdelay(10);
178 } else
179 IWL_DEBUG_RF_KILL("power-down complete, "
180 "gpctl = 0x%08x\n", gp_ctl);
181 }
182
183 /* this bit wakes up the NIC */
184 _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Tomas Winklerac17a942007-10-25 17:15:37 +0800185 ret = _iwl_poll_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -0700186 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
187 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
188 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50);
Tomas Winklerac17a942007-10-25 17:15:37 +0800189 if (ret < 0) {
Zhu Yib481de92007-09-25 17:54:57 -0700190 IWL_ERROR("MAC is in deep sleep!\n");
191 return -EIO;
192 }
193
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800194#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700195 atomic_inc(&priv->restrict_refcnt);
196#endif
197 return 0;
198}
199
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800200#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerac17a942007-10-25 17:15:37 +0800201static inline int __iwl_grab_nic_access(const char *f, u32 l,
Zhu Yib481de92007-09-25 17:54:57 -0700202 struct iwl_priv *priv)
203{
204 if (atomic_read(&priv->restrict_refcnt))
205 IWL_DEBUG_INFO("Grabbing access while already held at "
206 "line %d.\n", l);
207
Tomas Winklerac17a942007-10-25 17:15:37 +0800208 IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l);
209 return _iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700210}
Tomas Winklerac17a942007-10-25 17:15:37 +0800211#define iwl_grab_nic_access(priv) \
212 __iwl_grab_nic_access(__FILE__, __LINE__, priv)
Zhu Yib481de92007-09-25 17:54:57 -0700213#else
Tomas Winklerac17a942007-10-25 17:15:37 +0800214#define iwl_grab_nic_access(priv) \
215 _iwl_grab_nic_access(priv)
Zhu Yib481de92007-09-25 17:54:57 -0700216#endif
217
Tomas Winklerac17a942007-10-25 17:15:37 +0800218static inline void _iwl_release_nic_access(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700219{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800220#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700221 if (atomic_dec_and_test(&priv->restrict_refcnt))
222#endif
223 _iwl_clear_bit(priv, CSR_GP_CNTRL,
224 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
225}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800226#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerac17a942007-10-25 17:15:37 +0800227static inline void __iwl_release_nic_access(const char *f, u32 l,
228 struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700229{
230 if (atomic_read(&priv->restrict_refcnt) <= 0)
Tomas Winklerac17a942007-10-25 17:15:37 +0800231 IWL_ERROR("Release unheld nic access at line %d.\n", l);
Zhu Yib481de92007-09-25 17:54:57 -0700232
Tomas Winklerac17a942007-10-25 17:15:37 +0800233 IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l);
234 _iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700235}
Tomas Winklerac17a942007-10-25 17:15:37 +0800236#define iwl_release_nic_access(priv) \
237 __iwl_release_nic_access(__FILE__, __LINE__, priv)
Zhu Yib481de92007-09-25 17:54:57 -0700238#else
Tomas Winklerac17a942007-10-25 17:15:37 +0800239#define iwl_release_nic_access(priv) \
240 _iwl_release_nic_access(priv)
Zhu Yib481de92007-09-25 17:54:57 -0700241#endif
242
Tomas Winklerac17a942007-10-25 17:15:37 +0800243static inline u32 _iwl_read_direct32(struct iwl_priv *priv, u32 reg)
Zhu Yib481de92007-09-25 17:54:57 -0700244{
245 return _iwl_read32(priv, reg);
246}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800247#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerac17a942007-10-25 17:15:37 +0800248static inline u32 __iwl_read_direct32(const char *f, u32 l,
Zhu Yib481de92007-09-25 17:54:57 -0700249 struct iwl_priv *priv, u32 reg)
250{
Tomas Winklerac17a942007-10-25 17:15:37 +0800251 u32 value = _iwl_read_direct32(priv, reg);
Zhu Yib481de92007-09-25 17:54:57 -0700252 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800253 IWL_ERROR("Nic access not held from %s %d\n", f, l);
254 IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value,
Zhu Yib481de92007-09-25 17:54:57 -0700255 f, l);
256 return value;
257}
Tomas Winklerac17a942007-10-25 17:15:37 +0800258#define iwl_read_direct32(priv, reg) \
259 __iwl_read_direct32(__FILE__, __LINE__, priv, reg)
Zhu Yib481de92007-09-25 17:54:57 -0700260#else
Tomas Winklerac17a942007-10-25 17:15:37 +0800261#define iwl_read_direct32 _iwl_read_direct32
Zhu Yib481de92007-09-25 17:54:57 -0700262#endif
263
Tomas Winklerac17a942007-10-25 17:15:37 +0800264static inline void _iwl_write_direct32(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700265 u32 reg, u32 value)
266{
267 _iwl_write32(priv, reg, value);
268}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800269#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerac17a942007-10-25 17:15:37 +0800270static void __iwl_write_direct32(u32 line,
Zhu Yib481de92007-09-25 17:54:57 -0700271 struct iwl_priv *priv, u32 reg, u32 value)
272{
273 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800274 IWL_ERROR("Nic access not held from line %d\n", line);
275 _iwl_write_direct32(priv, reg, value);
Zhu Yib481de92007-09-25 17:54:57 -0700276}
Tomas Winklerac17a942007-10-25 17:15:37 +0800277#define iwl_write_direct32(priv, reg, value) \
278 __iwl_write_direct32(__LINE__, priv, reg, value)
Zhu Yib481de92007-09-25 17:54:57 -0700279#else
Tomas Winklerac17a942007-10-25 17:15:37 +0800280#define iwl_write_direct32 _iwl_write_direct32
Zhu Yib481de92007-09-25 17:54:57 -0700281#endif
282
Tomas Winklerac17a942007-10-25 17:15:37 +0800283static inline void iwl_write_reg_buf(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700284 u32 reg, u32 len, u32 *values)
285{
286 u32 count = sizeof(u32);
287
288 if ((priv != NULL) && (values != NULL)) {
289 for (; 0 < len; len -= count, reg += count, values++)
Tomas Winklerac17a942007-10-25 17:15:37 +0800290 _iwl_write_direct32(priv, reg, *values);
Zhu Yib481de92007-09-25 17:54:57 -0700291 }
292}
293
Tomas Winklerac17a942007-10-25 17:15:37 +0800294static inline int _iwl_poll_direct_bit(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700295 u32 addr, u32 mask, int timeout)
296{
297 int i = 0;
298
299 do {
Tomas Winklerac17a942007-10-25 17:15:37 +0800300 if ((_iwl_read_direct32(priv, addr) & mask) == mask)
Zhu Yib481de92007-09-25 17:54:57 -0700301 return i;
302 mdelay(10);
303 i += 10;
304 } while (i < timeout);
305
306 return -ETIMEDOUT;
307}
308
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800309#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerac17a942007-10-25 17:15:37 +0800310static inline int __iwl_poll_direct_bit(const char *f, u32 l,
Zhu Yib481de92007-09-25 17:54:57 -0700311 struct iwl_priv *priv,
312 u32 addr, u32 mask, int timeout)
313{
Tomas Winklerac17a942007-10-25 17:15:37 +0800314 int ret = _iwl_poll_direct_bit(priv, addr, mask, timeout);
Zhu Yib481de92007-09-25 17:54:57 -0700315
Tomas Winklerac17a942007-10-25 17:15:37 +0800316 if (unlikely(ret == -ETIMEDOUT))
317 IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - "
Zhu Yib481de92007-09-25 17:54:57 -0700318 "timedout - %s %d\n", addr, mask, f, l);
319 else
Tomas Winklerac17a942007-10-25 17:15:37 +0800320 IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
321 "- %s %d\n", addr, mask, ret, f, l);
322 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700323}
Tomas Winklerac17a942007-10-25 17:15:37 +0800324#define iwl_poll_direct_bit(iwl, addr, mask, timeout) \
325 __iwl_poll_direct_bit(__FILE__, __LINE__, iwl, addr, mask, timeout)
Zhu Yib481de92007-09-25 17:54:57 -0700326#else
Tomas Winklerac17a942007-10-25 17:15:37 +0800327#define iwl_poll_direct_bit _iwl_poll_direct_bit
Zhu Yib481de92007-09-25 17:54:57 -0700328#endif
329
Tomas Winklerd8609652007-10-25 17:15:35 +0800330static inline u32 _iwl_read_prph(struct iwl_priv *priv, u32 reg)
Zhu Yib481de92007-09-25 17:54:57 -0700331{
Tomas Winklerac17a942007-10-25 17:15:37 +0800332 _iwl_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
333 return _iwl_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -0700334}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800335#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerd8609652007-10-25 17:15:35 +0800336static inline u32 __iwl_read_prph(u32 line, struct iwl_priv *priv, u32 reg)
Zhu Yib481de92007-09-25 17:54:57 -0700337{
338 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800339 IWL_ERROR("Nic access not held from line %d\n", line);
Tomas Winklerd8609652007-10-25 17:15:35 +0800340 return _iwl_read_prph(priv, reg);
Zhu Yib481de92007-09-25 17:54:57 -0700341}
342
Tomas Winklerd8609652007-10-25 17:15:35 +0800343#define iwl_read_prph(priv, reg) \
344 __iwl_read_prph(__LINE__, priv, reg)
Zhu Yib481de92007-09-25 17:54:57 -0700345#else
Tomas Winklerd8609652007-10-25 17:15:35 +0800346#define iwl_read_prph _iwl_read_prph
Zhu Yib481de92007-09-25 17:54:57 -0700347#endif
348
Tomas Winklerd8609652007-10-25 17:15:35 +0800349static inline void _iwl_write_prph(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700350 u32 addr, u32 val)
351{
Tomas Winklerac17a942007-10-25 17:15:37 +0800352 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
Zhu Yib481de92007-09-25 17:54:57 -0700353 ((addr & 0x0000FFFF) | (3 << 24)));
Tomas Winklerac17a942007-10-25 17:15:37 +0800354 _iwl_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
Zhu Yib481de92007-09-25 17:54:57 -0700355}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800356#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerd8609652007-10-25 17:15:35 +0800357static inline void __iwl_write_prph(u32 line, struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700358 u32 addr, u32 val)
359{
360 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800361 IWL_ERROR("Nic access from line %d\n", line);
Tomas Winklerd8609652007-10-25 17:15:35 +0800362 _iwl_write_prph(priv, addr, val);
Zhu Yib481de92007-09-25 17:54:57 -0700363}
364
Tomas Winklerd8609652007-10-25 17:15:35 +0800365#define iwl_write_prph(priv, addr, val) \
366 __iwl_write_prph(__LINE__, priv, addr, val);
Zhu Yib481de92007-09-25 17:54:57 -0700367#else
Tomas Winklerd8609652007-10-25 17:15:35 +0800368#define iwl_write_prph _iwl_write_prph
Zhu Yib481de92007-09-25 17:54:57 -0700369#endif
370
Tomas Winklerd8609652007-10-25 17:15:35 +0800371#define _iwl_set_bits_prph(priv, reg, mask) \
372 _iwl_write_prph(priv, reg, (_iwl_read_prph(priv, reg) | mask))
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800373#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerd8609652007-10-25 17:15:35 +0800374static inline void __iwl_set_bits_prph(u32 line, struct iwl_priv *priv,
375 u32 reg, u32 mask)
Zhu Yib481de92007-09-25 17:54:57 -0700376{
377 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800378 IWL_ERROR("Nic access not held from line %d\n", line);
379
Tomas Winklerd8609652007-10-25 17:15:35 +0800380 _iwl_set_bits_prph(priv, reg, mask);
Zhu Yib481de92007-09-25 17:54:57 -0700381}
Tomas Winklerd8609652007-10-25 17:15:35 +0800382#define iwl_set_bits_prph(priv, reg, mask) \
383 __iwl_set_bits_prph(__LINE__, priv, reg, mask)
Zhu Yib481de92007-09-25 17:54:57 -0700384#else
Tomas Winklerd8609652007-10-25 17:15:35 +0800385#define iwl_set_bits_prph _iwl_set_bits_prph
Zhu Yib481de92007-09-25 17:54:57 -0700386#endif
387
Tomas Winklerd8609652007-10-25 17:15:35 +0800388#define _iwl_set_bits_mask_prph(priv, reg, bits, mask) \
389 _iwl_write_prph(priv, reg, ((_iwl_read_prph(priv, reg) & mask) | bits))
390
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800391#ifdef CONFIG_IWL3945_DEBUG
Tomas Winklerd8609652007-10-25 17:15:35 +0800392static inline void __iwl_set_bits_mask_prph(u32 line,
Zhu Yib481de92007-09-25 17:54:57 -0700393 struct iwl_priv *priv, u32 reg, u32 bits, u32 mask)
394{
395 if (!atomic_read(&priv->restrict_refcnt))
Tomas Winklerac17a942007-10-25 17:15:37 +0800396 IWL_ERROR("Nic access not held from line %d\n", line);
Tomas Winklerd8609652007-10-25 17:15:35 +0800397 _iwl_set_bits_mask_prph(priv, reg, bits, mask);
Zhu Yib481de92007-09-25 17:54:57 -0700398}
Tomas Winklerd8609652007-10-25 17:15:35 +0800399#define iwl_set_bits_mask_prph(priv, reg, bits, mask) \
400 __iwl_set_bits_mask_prph(__LINE__, priv, reg, bits, mask)
Zhu Yib481de92007-09-25 17:54:57 -0700401#else
Tomas Winklerd8609652007-10-25 17:15:35 +0800402#define iwl_set_bits_mask_prph _iwl_set_bits_mask_prph
Zhu Yib481de92007-09-25 17:54:57 -0700403#endif
404
Tomas Winklerd8609652007-10-25 17:15:35 +0800405static inline void iwl_clear_bits_prph(struct iwl_priv
Zhu Yib481de92007-09-25 17:54:57 -0700406 *priv, u32 reg, u32 mask)
407{
Tomas Winklerd8609652007-10-25 17:15:35 +0800408 u32 val = _iwl_read_prph(priv, reg);
409 _iwl_write_prph(priv, reg, (val & ~mask));
Zhu Yib481de92007-09-25 17:54:57 -0700410}
411
Tomas Winkleraf7cca22007-10-25 17:15:36 +0800412static inline u32 iwl_read_targ_mem(struct iwl_priv *priv, u32 addr)
Zhu Yib481de92007-09-25 17:54:57 -0700413{
Tomas Winklerac17a942007-10-25 17:15:37 +0800414 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
415 return iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -0700416}
417
Tomas Winkleraf7cca22007-10-25 17:15:36 +0800418static inline void iwl_write_targ_mem(struct iwl_priv *priv, u32 addr, u32 val)
Zhu Yib481de92007-09-25 17:54:57 -0700419{
Tomas Winklerac17a942007-10-25 17:15:37 +0800420 iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
421 iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
Zhu Yib481de92007-09-25 17:54:57 -0700422}
423
Tomas Winkleraf7cca22007-10-25 17:15:36 +0800424static inline void iwl_write_targ_mem_buf(struct iwl_priv *priv, u32 addr,
425 u32 len, u32 *values)
Zhu Yib481de92007-09-25 17:54:57 -0700426{
Tomas Winklerac17a942007-10-25 17:15:37 +0800427 iwl_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
Zhu Yib481de92007-09-25 17:54:57 -0700428 for (; 0 < len; len -= sizeof(u32), values++)
Tomas Winklerac17a942007-10-25 17:15:37 +0800429 iwl_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
Zhu Yib481de92007-09-25 17:54:57 -0700430}
Zhu Yib481de92007-09-25 17:54:57 -0700431#endif