/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. #include "iwl-drv.h"
  32. #include "iwl-io.h"
  33. #include "iwl-csr.h"
  34. #include "iwl-debug.h"
  35. #include "iwl-fh.h"
  36. #include "iwl-csr.h"
  37. #define IWL_POLL_INTERVAL 10 /* microseconds */
  38. int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
  39. u32 bits, u32 mask, int timeout)
  40. {
  41. int t = 0;
  42. do {
  43. if ((iwl_read32(trans, addr) & mask) == (bits & mask))
  44. return t;
  45. udelay(IWL_POLL_INTERVAL);
  46. t += IWL_POLL_INTERVAL;
  47. } while (t < timeout);
  48. return -ETIMEDOUT;
  49. }
  50. IWL_EXPORT_SYMBOL(iwl_poll_bit);
  51. u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
  52. {
  53. u32 value = 0x5a5a5a5a;
  54. unsigned long flags;
  55. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  56. value = iwl_read32(trans, reg);
  57. iwl_trans_release_nic_access(trans, &flags);
  58. }
  59. return value;
  60. }
  61. IWL_EXPORT_SYMBOL(iwl_read_direct32);
  62. void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
  63. {
  64. unsigned long flags;
  65. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  66. iwl_write32(trans, reg, value);
  67. iwl_trans_release_nic_access(trans, &flags);
  68. }
  69. }
  70. IWL_EXPORT_SYMBOL(iwl_write_direct32);
  71. int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
  72. int timeout)
  73. {
  74. int t = 0;
  75. do {
  76. if ((iwl_read_direct32(trans, addr) & mask) == mask)
  77. return t;
  78. udelay(IWL_POLL_INTERVAL);
  79. t += IWL_POLL_INTERVAL;
  80. } while (t < timeout);
  81. return -ETIMEDOUT;
  82. }
  83. IWL_EXPORT_SYMBOL(iwl_poll_direct_bit);
  84. static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  85. {
  86. u32 val = iwl_trans_read_prph(trans, ofs);
  87. trace_iwlwifi_dev_ioread_prph32(trans->dev, ofs, val);
  88. return val;
  89. }
  90. static inline void __iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  91. {
  92. trace_iwlwifi_dev_iowrite_prph32(trans->dev, ofs, val);
  93. iwl_trans_write_prph(trans, ofs, val);
  94. }
  95. u32 iwl_read_prph(struct iwl_trans *trans, u32 ofs)
  96. {
  97. unsigned long flags;
  98. u32 val = 0x5a5a5a5a;
  99. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  100. val = __iwl_read_prph(trans, ofs);
  101. iwl_trans_release_nic_access(trans, &flags);
  102. }
  103. return val;
  104. }
  105. IWL_EXPORT_SYMBOL(iwl_read_prph);
  106. void iwl_write_prph(struct iwl_trans *trans, u32 ofs, u32 val)
  107. {
  108. unsigned long flags;
  109. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  110. __iwl_write_prph(trans, ofs, val);
  111. iwl_trans_release_nic_access(trans, &flags);
  112. }
  113. }
  114. IWL_EXPORT_SYMBOL(iwl_write_prph);
  115. void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  116. {
  117. unsigned long flags;
  118. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  119. __iwl_write_prph(trans, ofs,
  120. __iwl_read_prph(trans, ofs) | mask);
  121. iwl_trans_release_nic_access(trans, &flags);
  122. }
  123. }
  124. IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
  125. void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
  126. u32 bits, u32 mask)
  127. {
  128. unsigned long flags;
  129. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  130. __iwl_write_prph(trans, ofs,
  131. (__iwl_read_prph(trans, ofs) & mask) | bits);
  132. iwl_trans_release_nic_access(trans, &flags);
  133. }
  134. }
  135. IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
  136. void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  137. {
  138. unsigned long flags;
  139. u32 val;
  140. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  141. val = __iwl_read_prph(trans, ofs);
  142. __iwl_write_prph(trans, ofs, (val & ~mask));
  143. iwl_trans_release_nic_access(trans, &flags);
  144. }
  145. }
  146. IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
  147. static const char *get_fh_string(int cmd)
  148. {
  149. #define IWL_CMD(x) case x: return #x
  150. switch (cmd) {
  151. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  152. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  153. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  154. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  155. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  156. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  157. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  158. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  159. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  160. default:
  161. return "UNKNOWN";
  162. }
  163. #undef IWL_CMD
  164. }
  165. int iwl_dump_fh(struct iwl_trans *trans, char **buf)
  166. {
  167. int i;
  168. static const u32 fh_tbl[] = {
  169. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  170. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  171. FH_RSCSR_CHNL0_WPTR,
  172. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  173. FH_MEM_RSSR_SHARED_CTRL_REG,
  174. FH_MEM_RSSR_RX_STATUS_REG,
  175. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  176. FH_TSSR_TX_STATUS_REG,
  177. FH_TSSR_TX_ERROR_REG
  178. };
  179. #ifdef CONFIG_IWLWIFI_DEBUGFS
  180. if (buf) {
  181. int pos = 0;
  182. size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  183. *buf = kmalloc(bufsz, GFP_KERNEL);
  184. if (!*buf)
  185. return -ENOMEM;
  186. pos += scnprintf(*buf + pos, bufsz - pos,
  187. "FH register values:\n");
  188. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  189. pos += scnprintf(*buf + pos, bufsz - pos,
  190. " %34s: 0X%08x\n",
  191. get_fh_string(fh_tbl[i]),
  192. iwl_read_direct32(trans, fh_tbl[i]));
  193. return pos;
  194. }
  195. #endif
  196. IWL_ERR(trans, "FH register values:\n");
  197. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  198. IWL_ERR(trans, " %34s: 0X%08x\n",
  199. get_fh_string(fh_tbl[i]),
  200. iwl_read_direct32(trans, fh_tbl[i]));
  201. return 0;
  202. }