iwlwifi: cleanup usage of inline functions
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-4965-io.h
CommitLineData
b481de9c
ZY
1/******************************************************************************
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
bb8c093b
CH
29#ifndef __iwl4965_io_h__
30#define __iwl4965_io_h__
b481de9c
ZY
31
32#include <linux/io.h>
33
5d08cd1d 34#include "iwl-4965-debug.h"
b481de9c
ZY
35
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
ac17a947 45 * and the current line number is printed in addition to any other debug output.
b481de9c
ZY
46 *
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
bb8c093b
CH
52 * routines, for example _iwl4965_read_direct32 calls the non-check version of
53 * _iwl4965_read32.)
b481de9c
ZY
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
bb8c093b 62#define _iwl4965_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs))
c8b0e6e1 63#ifdef CONFIG_IWL4965_DEBUG
bb8c093b 64static inline void __iwl4965_write32(const char *f, u32 l, struct iwl4965_priv *iwl,
b481de9c
ZY
65 u32 ofs, u32 val)
66{
ac17a947 67 IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l);
bb8c093b 68 _iwl4965_write32(iwl, ofs, val);
b481de9c 69}
bb8c093b
CH
70#define iwl4965_write32(iwl, ofs, val) \
71 __iwl4965_write32(__FILE__, __LINE__, iwl, ofs, val)
b481de9c 72#else
bb8c093b 73#define iwl4965_write32(iwl, ofs, val) _iwl4965_write32(iwl, ofs, val)
b481de9c
ZY
74#endif
75
bb8c093b 76#define _iwl4965_read32(iwl, ofs) readl((iwl)->hw_base + (ofs))
c8b0e6e1 77#ifdef CONFIG_IWL4965_DEBUG
bb8c093b 78static inline u32 __iwl4965_read32(char *f, u32 l, struct iwl4965_priv *iwl, u32 ofs)
b481de9c
ZY
79{
80 IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l);
bb8c093b 81 return _iwl4965_read32(iwl, ofs);
b481de9c 82}
bb8c093b 83#define iwl4965_read32(iwl, ofs) __iwl4965_read32(__FILE__, __LINE__, iwl, ofs)
b481de9c 84#else
bb8c093b 85#define iwl4965_read32(p, o) _iwl4965_read32(p, o)
b481de9c
ZY
86#endif
87
bb8c093b 88static inline int _iwl4965_poll_bit(struct iwl4965_priv *priv, u32 addr,
b481de9c
ZY
89 u32 bits, u32 mask, int timeout)
90{
91 int i = 0;
92
93 do {
bb8c093b 94 if ((_iwl4965_read32(priv, addr) & mask) == (bits & mask))
b481de9c
ZY
95 return i;
96 mdelay(10);
97 i += 10;
98 } while (i < timeout);
99
100 return -ETIMEDOUT;
101}
c8b0e6e1 102#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
103static inline int __iwl4965_poll_bit(const char *f, u32 l,
104 struct iwl4965_priv *priv, u32 addr,
b481de9c
ZY
105 u32 bits, u32 mask, int timeout)
106{
bb8c093b 107 int ret = _iwl4965_poll_bit(priv, addr, bits, mask, timeout);
ac17a947 108 if (unlikely(ret == -ETIMEDOUT))
b481de9c
ZY
109 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",
ac17a947
TW
115 addr, bits, mask, ret, f, l);
116 return ret;
b481de9c 117}
bb8c093b
CH
118#define iwl4965_poll_bit(iwl, addr, bits, mask, timeout) \
119 __iwl4965_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout)
b481de9c 120#else
bb8c093b 121#define iwl4965_poll_bit(p, a, b, m, t) _iwl4965_poll_bit(p, a, b, m, t)
b481de9c
ZY
122#endif
123
bb8c093b 124static inline void _iwl4965_set_bit(struct iwl4965_priv *priv, u32 reg, u32 mask)
b481de9c 125{
bb8c093b 126 _iwl4965_write32(priv, reg, _iwl4965_read32(priv, reg) | mask);
b481de9c 127}
c8b0e6e1 128#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
129static inline void __iwl4965_set_bit(const char *f, u32 l,
130 struct iwl4965_priv *priv, u32 reg, u32 mask)
b481de9c 131{
bb8c093b 132 u32 val = _iwl4965_read32(priv, reg) | mask;
b481de9c 133 IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
bb8c093b 134 _iwl4965_write32(priv, reg, val);
b481de9c 135}
bb8c093b 136#define iwl4965_set_bit(p, r, m) __iwl4965_set_bit(__FILE__, __LINE__, p, r, m)
b481de9c 137#else
bb8c093b 138#define iwl4965_set_bit(p, r, m) _iwl4965_set_bit(p, r, m)
b481de9c
ZY
139#endif
140
bb8c093b 141static inline void _iwl4965_clear_bit(struct iwl4965_priv *priv, u32 reg, u32 mask)
b481de9c 142{
bb8c093b 143 _iwl4965_write32(priv, reg, _iwl4965_read32(priv, reg) & ~mask);
b481de9c 144}
c8b0e6e1 145#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
146static inline void __iwl4965_clear_bit(const char *f, u32 l,
147 struct iwl4965_priv *priv, u32 reg, u32 mask)
b481de9c 148{
bb8c093b 149 u32 val = _iwl4965_read32(priv, reg) & ~mask;
b481de9c 150 IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val);
bb8c093b 151 _iwl4965_write32(priv, reg, val);
b481de9c 152}
bb8c093b 153#define iwl4965_clear_bit(p, r, m) __iwl4965_clear_bit(__FILE__, __LINE__, p, r, m)
b481de9c 154#else
bb8c093b 155#define iwl4965_clear_bit(p, r, m) _iwl4965_clear_bit(p, r, m)
b481de9c
ZY
156#endif
157
bb8c093b 158static inline int _iwl4965_grab_nic_access(struct iwl4965_priv *priv)
b481de9c 159{
ac17a947 160 int ret;
b481de9c
ZY
161 u32 gp_ctl;
162
c8b0e6e1 163#ifdef CONFIG_IWL4965_DEBUG
b481de9c
ZY
164 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 */
bb8c093b 173 gp_ctl = _iwl4965_read32(priv, CSR_GP_CNTRL);
b481de9c
ZY
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 */
bb8c093b
CH
184 _iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
185 ret = _iwl4965_poll_bit(priv, CSR_GP_CNTRL,
b481de9c
ZY
186 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);
ac17a947 189 if (ret < 0) {
b481de9c
ZY
190 IWL_ERROR("MAC is in deep sleep!\n");
191 return -EIO;
192 }
193
c8b0e6e1 194#ifdef CONFIG_IWL4965_DEBUG
b481de9c
ZY
195 atomic_inc(&priv->restrict_refcnt);
196#endif
197 return 0;
198}
199
c8b0e6e1 200#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
201static inline int __iwl4965_grab_nic_access(const char *f, u32 l,
202 struct iwl4965_priv *priv)
b481de9c
ZY
203{
204 if (atomic_read(&priv->restrict_refcnt))
205 IWL_DEBUG_INFO("Grabbing access while already held at "
206 "line %d.\n", l);
207
ac17a947 208 IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l);
bb8c093b 209 return _iwl4965_grab_nic_access(priv);
b481de9c 210}
bb8c093b
CH
211#define iwl4965_grab_nic_access(priv) \
212 __iwl4965_grab_nic_access(__FILE__, __LINE__, priv)
b481de9c 213#else
bb8c093b
CH
214#define iwl4965_grab_nic_access(priv) \
215 _iwl4965_grab_nic_access(priv)
b481de9c
ZY
216#endif
217
bb8c093b 218static inline void _iwl4965_release_nic_access(struct iwl4965_priv *priv)
b481de9c 219{
c8b0e6e1 220#ifdef CONFIG_IWL4965_DEBUG
b481de9c
ZY
221 if (atomic_dec_and_test(&priv->restrict_refcnt))
222#endif
bb8c093b 223 _iwl4965_clear_bit(priv, CSR_GP_CNTRL,
b481de9c
ZY
224 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
225}
c8b0e6e1 226#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
227static inline void __iwl4965_release_nic_access(const char *f, u32 l,
228 struct iwl4965_priv *priv)
b481de9c
ZY
229{
230 if (atomic_read(&priv->restrict_refcnt) <= 0)
ac17a947 231 IWL_ERROR("Release unheld nic access at line %d.\n", l);
b481de9c 232
ac17a947 233 IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l);
bb8c093b 234 _iwl4965_release_nic_access(priv);
b481de9c 235}
bb8c093b
CH
236#define iwl4965_release_nic_access(priv) \
237 __iwl4965_release_nic_access(__FILE__, __LINE__, priv)
b481de9c 238#else
bb8c093b
CH
239#define iwl4965_release_nic_access(priv) \
240 _iwl4965_release_nic_access(priv)
b481de9c
ZY
241#endif
242
bb8c093b 243static inline u32 _iwl4965_read_direct32(struct iwl4965_priv *priv, u32 reg)
b481de9c 244{
bb8c093b 245 return _iwl4965_read32(priv, reg);
b481de9c 246}
c8b0e6e1 247#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
248static inline u32 __iwl4965_read_direct32(const char *f, u32 l,
249 struct iwl4965_priv *priv, u32 reg)
b481de9c 250{
bb8c093b 251 u32 value = _iwl4965_read_direct32(priv, reg);
b481de9c 252 if (!atomic_read(&priv->restrict_refcnt))
ac17a947
TW
253 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,
b481de9c
ZY
255 f, l);
256 return value;
257}
bb8c093b
CH
258#define iwl4965_read_direct32(priv, reg) \
259 __iwl4965_read_direct32(__FILE__, __LINE__, priv, reg)
b481de9c 260#else
bb8c093b 261#define iwl4965_read_direct32 _iwl4965_read_direct32
b481de9c
ZY
262#endif
263
bb8c093b 264static inline void _iwl4965_write_direct32(struct iwl4965_priv *priv,
b481de9c
ZY
265 u32 reg, u32 value)
266{
bb8c093b 267 _iwl4965_write32(priv, reg, value);
b481de9c 268}
c8b0e6e1 269#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
270static void __iwl4965_write_direct32(u32 line,
271 struct iwl4965_priv *priv, u32 reg, u32 value)
b481de9c
ZY
272{
273 if (!atomic_read(&priv->restrict_refcnt))
ac17a947 274 IWL_ERROR("Nic access not held from line %d\n", line);
bb8c093b 275 _iwl4965_write_direct32(priv, reg, value);
b481de9c 276}
bb8c093b
CH
277#define iwl4965_write_direct32(priv, reg, value) \
278 __iwl4965_write_direct32(__LINE__, priv, reg, value)
b481de9c 279#else
bb8c093b 280#define iwl4965_write_direct32 _iwl4965_write_direct32
b481de9c
ZY
281#endif
282
bb8c093b 283static inline void iwl4965_write_reg_buf(struct iwl4965_priv *priv,
b481de9c
ZY
284 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++)
bb8c093b 290 _iwl4965_write_direct32(priv, reg, *values);
b481de9c
ZY
291 }
292}
293
bb8c093b 294static inline int _iwl4965_poll_direct_bit(struct iwl4965_priv *priv,
b481de9c
ZY
295 u32 addr, u32 mask, int timeout)
296{
297 int i = 0;
298
299 do {
bb8c093b 300 if ((_iwl4965_read_direct32(priv, addr) & mask) == mask)
b481de9c
ZY
301 return i;
302 mdelay(10);
303 i += 10;
304 } while (i < timeout);
305
306 return -ETIMEDOUT;
307}
308
c8b0e6e1 309#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
310static inline int __iwl4965_poll_direct_bit(const char *f, u32 l,
311 struct iwl4965_priv *priv,
b481de9c
ZY
312 u32 addr, u32 mask, int timeout)
313{
bb8c093b 314 int ret = _iwl4965_poll_direct_bit(priv, addr, mask, timeout);
b481de9c 315
ac17a947
TW
316 if (unlikely(ret == -ETIMEDOUT))
317 IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - "
b481de9c
ZY
318 "timedout - %s %d\n", addr, mask, f, l);
319 else
ac17a947
TW
320 IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X "
321 "- %s %d\n", addr, mask, ret, f, l);
322 return ret;
b481de9c 323}
bb8c093b
CH
324#define iwl4965_poll_direct_bit(iwl, addr, mask, timeout) \
325 __iwl4965_poll_direct_bit(__FILE__, __LINE__, iwl, addr, mask, timeout)
b481de9c 326#else
bb8c093b 327#define iwl4965_poll_direct_bit _iwl4965_poll_direct_bit
b481de9c
ZY
328#endif
329
bb8c093b 330static inline u32 _iwl4965_read_prph(struct iwl4965_priv *priv, u32 reg)
b481de9c 331{
bb8c093b
CH
332 _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
333 return _iwl4965_read_direct32(priv, HBUS_TARG_PRPH_RDAT);
b481de9c 334}
c8b0e6e1 335#ifdef CONFIG_IWL4965_DEBUG
bb8c093b 336static inline u32 __iwl4965_read_prph(u32 line, struct iwl4965_priv *priv, u32 reg)
b481de9c
ZY
337{
338 if (!atomic_read(&priv->restrict_refcnt))
ac17a947 339 IWL_ERROR("Nic access not held from line %d\n", line);
bb8c093b 340 return _iwl4965_read_prph(priv, reg);
b481de9c
ZY
341}
342
bb8c093b
CH
343#define iwl4965_read_prph(priv, reg) \
344 __iwl4965_read_prph(__LINE__, priv, reg)
b481de9c 345#else
bb8c093b 346#define iwl4965_read_prph _iwl4965_read_prph
b481de9c
ZY
347#endif
348
bb8c093b 349static inline void _iwl4965_write_prph(struct iwl4965_priv *priv,
b481de9c
ZY
350 u32 addr, u32 val)
351{
bb8c093b 352 _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_WADDR,
b481de9c 353 ((addr & 0x0000FFFF) | (3 << 24)));
bb8c093b 354 _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val);
b481de9c 355}
c8b0e6e1 356#ifdef CONFIG_IWL4965_DEBUG
bb8c093b 357static inline void __iwl4965_write_prph(u32 line, struct iwl4965_priv *priv,
b481de9c
ZY
358 u32 addr, u32 val)
359{
360 if (!atomic_read(&priv->restrict_refcnt))
ac17a947 361 IWL_ERROR("Nic access from line %d\n", line);
bb8c093b 362 _iwl4965_write_prph(priv, addr, val);
b481de9c
ZY
363}
364
bb8c093b
CH
365#define iwl4965_write_prph(priv, addr, val) \
366 __iwl4965_write_prph(__LINE__, priv, addr, val);
b481de9c 367#else
bb8c093b 368#define iwl4965_write_prph _iwl4965_write_prph
b481de9c
ZY
369#endif
370
bb8c093b
CH
371#define _iwl4965_set_bits_prph(priv, reg, mask) \
372 _iwl4965_write_prph(priv, reg, (_iwl4965_read_prph(priv, reg) | mask))
c8b0e6e1 373#ifdef CONFIG_IWL4965_DEBUG
bb8c093b 374static inline void __iwl4965_set_bits_prph(u32 line, struct iwl4965_priv *priv,
d8609652 375 u32 reg, u32 mask)
b481de9c
ZY
376{
377 if (!atomic_read(&priv->restrict_refcnt))
ac17a947
TW
378 IWL_ERROR("Nic access not held from line %d\n", line);
379
bb8c093b 380 _iwl4965_set_bits_prph(priv, reg, mask);
b481de9c 381}
bb8c093b
CH
382#define iwl4965_set_bits_prph(priv, reg, mask) \
383 __iwl4965_set_bits_prph(__LINE__, priv, reg, mask)
b481de9c 384#else
bb8c093b 385#define iwl4965_set_bits_prph _iwl4965_set_bits_prph
b481de9c
ZY
386#endif
387
bb8c093b
CH
388#define _iwl4965_set_bits_mask_prph(priv, reg, bits, mask) \
389 _iwl4965_write_prph(priv, reg, ((_iwl4965_read_prph(priv, reg) & mask) | bits))
d8609652 390
c8b0e6e1 391#ifdef CONFIG_IWL4965_DEBUG
bb8c093b
CH
392static inline void __iwl4965_set_bits_mask_prph(u32 line,
393 struct iwl4965_priv *priv, u32 reg, u32 bits, u32 mask)
b481de9c
ZY
394{
395 if (!atomic_read(&priv->restrict_refcnt))
ac17a947 396 IWL_ERROR("Nic access not held from line %d\n", line);
bb8c093b 397 _iwl4965_set_bits_mask_prph(priv, reg, bits, mask);
b481de9c 398}
bb8c093b
CH
399#define iwl4965_set_bits_mask_prph(priv, reg, bits, mask) \
400 __iwl4965_set_bits_mask_prph(__LINE__, priv, reg, bits, mask)
b481de9c 401#else
bb8c093b 402#define iwl4965_set_bits_mask_prph _iwl4965_set_bits_mask_prph
b481de9c
ZY
403#endif
404
bb8c093b 405static inline void iwl4965_clear_bits_prph(struct iwl4965_priv
b481de9c
ZY
406 *priv, u32 reg, u32 mask)
407{
bb8c093b
CH
408 u32 val = _iwl4965_read_prph(priv, reg);
409 _iwl4965_write_prph(priv, reg, (val & ~mask));
b481de9c
ZY
410}
411
bb8c093b 412static inline u32 iwl4965_read_targ_mem(struct iwl4965_priv *priv, u32 addr)
b481de9c 413{
bb8c093b
CH
414 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr);
415 return iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
b481de9c
ZY
416}
417
bb8c093b 418static inline void iwl4965_write_targ_mem(struct iwl4965_priv *priv, u32 addr, u32 val)
b481de9c 419{
bb8c093b
CH
420 iwl4965_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
421 iwl4965_write_direct32(priv, HBUS_TARG_MEM_WDAT, val);
b481de9c
ZY
422}
423
bb8c093b 424static inline void iwl4965_write_targ_mem_buf(struct iwl4965_priv *priv, u32 addr,
af7cca2a 425 u32 len, u32 *values)
b481de9c 426{
bb8c093b 427 iwl4965_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr);
b481de9c 428 for (; 0 < len; len -= sizeof(u32), values++)
bb8c093b 429 iwl4965_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values);
b481de9c 430}
b481de9c 431#endif
This page took 0.12938 seconds and 5 git commands to generate.