iwlwifi: improve the reports in TX path
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-io.c
CommitLineData
02a7fa00
JB
1/******************************************************************************
2 *
4e318262 3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
02a7fa00
JB
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 * Intel Linux Wireless <ilw@linux.intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *
27 *****************************************************************************/
83ed9015
EG
28#include <linux/delay.h>
29#include <linux/device.h>
cc5f7e39 30#include <linux/export.h>
02a7fa00
JB
31
32#include "iwl-io.h"
6ac7d115 33#include "iwl-csr.h"
83ed9015 34#include "iwl-debug.h"
02a7fa00
JB
35
36#define IWL_POLL_INTERVAL 10 /* microseconds */
37
7a65d170 38void __iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask)
02a7fa00 39{
1042db2a 40 iwl_write32(trans, reg, iwl_read32(trans, reg) | mask);
02a7fa00
JB
41}
42
7a65d170 43void __iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask)
02a7fa00 44{
1042db2a 45 iwl_write32(trans, reg, iwl_read32(trans, reg) & ~mask);
02a7fa00
JB
46}
47
1042db2a 48void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask)
02a7fa00
JB
49{
50 unsigned long flags;
51
1042db2a
EG
52 spin_lock_irqsave(&trans->reg_lock, flags);
53 __iwl_set_bit(trans, reg, mask);
54 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 55}
cc5f7e39 56EXPORT_SYMBOL_GPL(iwl_set_bit);
02a7fa00 57
1042db2a 58void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask)
02a7fa00
JB
59{
60 unsigned long flags;
61
1042db2a
EG
62 spin_lock_irqsave(&trans->reg_lock, flags);
63 __iwl_clear_bit(trans, reg, mask);
64 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 65}
cc5f7e39 66EXPORT_SYMBOL_GPL(iwl_clear_bit);
02a7fa00 67
2baa2e57
JB
68void iwl_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value)
69{
70 unsigned long flags;
71 u32 v;
72
73#ifdef CONFIG_IWLWIFI_DEBUG
74 WARN_ON_ONCE(value & ~mask);
75#endif
76
77 spin_lock_irqsave(&trans->reg_lock, flags);
78 v = iwl_read32(trans, reg);
79 v &= ~mask;
80 v |= value;
81 iwl_write32(trans, reg, v);
82 spin_unlock_irqrestore(&trans->reg_lock, flags);
83}
84EXPORT_SYMBOL_GPL(iwl_set_bits_mask);
85
1042db2a 86int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
02a7fa00
JB
87 u32 bits, u32 mask, int timeout)
88{
89 int t = 0;
90
91 do {
1042db2a 92 if ((iwl_read32(trans, addr) & mask) == (bits & mask))
02a7fa00
JB
93 return t;
94 udelay(IWL_POLL_INTERVAL);
95 t += IWL_POLL_INTERVAL;
96 } while (t < timeout);
97
98 return -ETIMEDOUT;
99}
cc5f7e39 100EXPORT_SYMBOL_GPL(iwl_poll_bit);
02a7fa00 101
1042db2a 102u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
02a7fa00 103{
abae2386 104 u32 value = 0x5a5a5a5a;
02a7fa00
JB
105 unsigned long flags;
106
1042db2a 107 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386
EG
108 if (iwl_trans_grab_nic_access(trans, false)) {
109 value = iwl_read32(trans, reg);
110 iwl_trans_release_nic_access(trans);
111 }
1042db2a 112 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00
JB
113
114 return value;
115}
cc5f7e39 116EXPORT_SYMBOL_GPL(iwl_read_direct32);
02a7fa00 117
1042db2a 118void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
02a7fa00
JB
119{
120 unsigned long flags;
121
1042db2a 122 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386 123 if (iwl_trans_grab_nic_access(trans, false)) {
1042db2a 124 iwl_write32(trans, reg, value);
7a65d170 125 iwl_trans_release_nic_access(trans);
02a7fa00 126 }
1042db2a 127 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 128}
cc5f7e39 129EXPORT_SYMBOL_GPL(iwl_write_direct32);
02a7fa00 130
1042db2a 131int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
02a7fa00
JB
132 int timeout)
133{
134 int t = 0;
135
136 do {
1042db2a 137 if ((iwl_read_direct32(trans, addr) & mask) == mask)
02a7fa00
JB
138 return t;
139 udelay(IWL_POLL_INTERVAL);
140 t += IWL_POLL_INTERVAL;
141 } while (t < timeout);
142
143 return -ETIMEDOUT;
144}
cc5f7e39 145EXPORT_SYMBOL_GPL(iwl_poll_direct_bit);
02a7fa00 146
6a06b6c1 147static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
02a7fa00 148{
6a06b6c1
EG
149 u32 val = iwl_trans_read_prph(trans, ofs);
150 trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
151 return val;
02a7fa00
JB
152}
153
6a06b6c1 154static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
02a7fa00 155{
6a06b6c1
EG
156 trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
157 iwl_trans_write_prph(trans, ofs, val);
02a7fa00
JB
158}
159
6a06b6c1 160u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
02a7fa00
JB
161{
162 unsigned long flags;
abae2386 163 u32 val = 0x5a5a5a5a;
02a7fa00 164
1042db2a 165 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386
EG
166 if (iwl_trans_grab_nic_access(trans, false)) {
167 val = __iwl_read_prph(trans, ofs);
168 iwl_trans_release_nic_access(trans);
169 }
1042db2a 170 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00
JB
171 return val;
172}
cc5f7e39 173EXPORT_SYMBOL_GPL(iwl_read_prph);
02a7fa00 174
6a06b6c1 175void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
02a7fa00
JB
176{
177 unsigned long flags;
178
1042db2a 179 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386 180 if (iwl_trans_grab_nic_access(trans, false)) {
6a06b6c1 181 __iwl_write_prph(trans, ofs, val);
7a65d170 182 iwl_trans_release_nic_access(trans);
02a7fa00 183 }
1042db2a 184 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 185}
cc5f7e39 186EXPORT_SYMBOL_GPL(iwl_write_prph);
02a7fa00 187
6a06b6c1 188void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
02a7fa00
JB
189{
190 unsigned long flags;
191
1042db2a 192 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386 193 if (iwl_trans_grab_nic_access(trans, false)) {
6a06b6c1
EG
194 __iwl_write_prph(trans, ofs,
195 __iwl_read_prph(trans, ofs) | mask);
7a65d170 196 iwl_trans_release_nic_access(trans);
bfe4b80e 197 }
1042db2a 198 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 199}
cc5f7e39 200EXPORT_SYMBOL_GPL(iwl_set_bits_prph);
02a7fa00 201
6a06b6c1 202void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
02a7fa00
JB
203 u32 bits, u32 mask)
204{
205 unsigned long flags;
206
1042db2a 207 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386 208 if (iwl_trans_grab_nic_access(trans, false)) {
6a06b6c1
EG
209 __iwl_write_prph(trans, ofs,
210 (__iwl_read_prph(trans, ofs) & mask) | bits);
7a65d170 211 iwl_trans_release_nic_access(trans);
bfe4b80e 212 }
1042db2a 213 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 214}
cc5f7e39 215EXPORT_SYMBOL_GPL(iwl_set_bits_mask_prph);
02a7fa00 216
6a06b6c1 217void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
02a7fa00
JB
218{
219 unsigned long flags;
220 u32 val;
221
1042db2a 222 spin_lock_irqsave(&trans->reg_lock, flags);
abae2386 223 if (iwl_trans_grab_nic_access(trans, false)) {
6a06b6c1
EG
224 val = __iwl_read_prph(trans, ofs);
225 __iwl_write_prph(trans, ofs, (val & ~mask));
7a65d170 226 iwl_trans_release_nic_access(trans);
bfe4b80e 227 }
1042db2a 228 spin_unlock_irqrestore(&trans->reg_lock, flags);
02a7fa00 229}
cc5f7e39 230EXPORT_SYMBOL_GPL(iwl_clear_bits_prph);
This page took 0.238205 seconds and 5 git commands to generate.