PageRenderTime 35ms CodeModel.GetById 9ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/iwlwifi/iwl-io.c

http://github.com/mirrors/linux
C | 235 lines | 175 code | 33 blank | 27 comment | 18 complexity | 8baa8188751e80d73f1f23f32b33e4a0 MD5 | raw file
  1/******************************************************************************
  2 *
  3 * Copyright(c) 2003 - 2013 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 *  Intel Linux Wireless <ilw@linux.intel.com>
 25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 26 *
 27 *****************************************************************************/
 28#include <linux/delay.h>
 29#include <linux/device.h>
 30#include <linux/export.h>
 31
 32#include "iwl-drv.h"
 33#include "iwl-io.h"
 34#include "iwl-csr.h"
 35#include "iwl-debug.h"
 36#include "iwl-fh.h"
 37#include "iwl-csr.h"
 38
 39#define IWL_POLL_INTERVAL 10	/* microseconds */
 40
 41int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
 42		 u32 bits, u32 mask, int timeout)
 43{
 44	int t = 0;
 45
 46	do {
 47		if ((iwl_read32(trans, addr) & mask) == (bits & mask))
 48			return t;
 49		udelay(IWL_POLL_INTERVAL);
 50		t += IWL_POLL_INTERVAL;
 51	} while (t < timeout);
 52
 53	return -ETIMEDOUT;
 54}
 55IWL_EXPORT_SYMBOL(iwl_poll_bit);
 56
 57u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
 58{
 59	u32 value = 0x5a5a5a5a;
 60	unsigned long flags;
 61	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
 62		value = iwl_read32(trans, reg);
 63		iwl_trans_release_nic_access(trans, &flags);
 64	}
 65
 66	return value;
 67}
 68IWL_EXPORT_SYMBOL(iwl_read_direct32);
 69
 70void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
 71{
 72	unsigned long flags;
 73
 74	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
 75		iwl_write32(trans, reg, value);
 76		iwl_trans_release_nic_access(trans, &flags);
 77	}
 78}
 79IWL_EXPORT_SYMBOL(iwl_write_direct32);
 80
 81int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
 82			int timeout)
 83{
 84	int t = 0;
 85
 86	do {
 87		if ((iwl_read_direct32(trans, addr) & mask) == mask)
 88			return t;
 89		udelay(IWL_POLL_INTERVAL);
 90		t += IWL_POLL_INTERVAL;
 91	} while (t < timeout);
 92
 93	return -ETIMEDOUT;
 94}
 95IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
 96
 97static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
 98{
 99	u32 val = iwl_trans_read_prph(trans, ofs);
100	trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
101	return val;
102}
103
104static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
105{
106	trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
107	iwl_trans_write_prph(trans, ofs, val);
108}
109
110u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
111{
112	unsigned long flags;
113	u32 val = 0x5a5a5a5a;
114
115	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
116		val = __iwl_read_prph(trans, ofs);
117		iwl_trans_release_nic_access(trans, &flags);
118	}
119	return val;
120}
121IWL_EXPORT_SYMBOL(iwl_read_prph);
122
123void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
124{
125	unsigned long flags;
126
127	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
128		__iwl_write_prph(trans, ofs, val);
129		iwl_trans_release_nic_access(trans, &flags);
130	}
131}
132IWL_EXPORT_SYMBOL(iwl_write_prph);
133
134void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
135{
136	unsigned long flags;
137
138	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
139		__iwl_write_prph(trans, ofs,
140				 __iwl_read_prph(trans, ofs) | mask);
141		iwl_trans_release_nic_access(trans, &flags);
142	}
143}
144IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
145
146void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
147			    u32 bits, u32 mask)
148{
149	unsigned long flags;
150
151	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
152		__iwl_write_prph(trans, ofs,
153				 (__iwl_read_prph(trans, ofs) & mask) | bits);
154		iwl_trans_release_nic_access(trans, &flags);
155	}
156}
157IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
158
159void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
160{
161	unsigned long flags;
162	u32 val;
163
164	if (iwl_trans_grab_nic_access(trans, false, &flags)) {
165		val = __iwl_read_prph(trans, ofs);
166		__iwl_write_prph(trans, ofs, (val & ~mask));
167		iwl_trans_release_nic_access(trans, &flags);
168	}
169}
170IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
171
172static const char *get_fh_string(int cmd)
173{
174#define IWL_CMD(x) case x: return #x
175	switch (cmd) {
176	IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
177	IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
178	IWL_CMD(FH_RSCSR_CHNL0_WPTR);
179	IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
180	IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
181	IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
182	IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
183	IWL_CMD(FH_TSSR_TX_STATUS_REG);
184	IWL_CMD(FH_TSSR_TX_ERROR_REG);
185	default:
186		return "UNKNOWN";
187	}
188#undef IWL_CMD
189}
190
191int iwl_dump_fh(struct iwl_trans *trans, char **buf)
192{
193	int i;
194	static const u32 fh_tbl[] = {
195		FH_RSCSR_CHNL0_STTS_WPTR_REG,
196		FH_RSCSR_CHNL0_RBDCB_BASE_REG,
197		FH_RSCSR_CHNL0_WPTR,
198		FH_MEM_RCSR_CHNL0_CONFIG_REG,
199		FH_MEM_RSSR_SHARED_CTRL_REG,
200		FH_MEM_RSSR_RX_STATUS_REG,
201		FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
202		FH_TSSR_TX_STATUS_REG,
203		FH_TSSR_TX_ERROR_REG
204	};
205
206#ifdef CONFIG_IWLWIFI_DEBUGFS
207	if (buf) {
208		int pos = 0;
209		size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
210
211		*buf = kmalloc(bufsz, GFP_KERNEL);
212		if (!*buf)
213			return -ENOMEM;
214
215		pos += scnprintf(*buf + pos, bufsz - pos,
216				"FH register values:\n");
217
218		for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
219			pos += scnprintf(*buf + pos, bufsz - pos,
220				"  %34s: 0X%08x\n",
221				get_fh_string(fh_tbl[i]),
222				iwl_read_direct32(trans, fh_tbl[i]));
223
224		return pos;
225	}
226#endif
227
228	IWL_ERR(trans, "FH register values:\n");
229	for (i = 0; i <  ARRAY_SIZE(fh_tbl); i++)
230		IWL_ERR(trans, "  %34s: 0X%08x\n",
231			get_fh_string(fh_tbl[i]),
232			iwl_read_direct32(trans, fh_tbl[i]));
233
234	return 0;
235}