iwl-io.c 6.0 KB

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