iwl-io.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2014 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-prph.h"
  36. #include "iwl-fh.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. 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. 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. int iwl_poll_prph_bit(struct iwl_trans *trans, u32 addr,
  116. u32 bits, u32 mask, int timeout)
  117. {
  118. int t = 0;
  119. do {
  120. if ((iwl_read_prph(trans, addr) & mask) == (bits & mask))
  121. return t;
  122. udelay(IWL_POLL_INTERVAL);
  123. t += IWL_POLL_INTERVAL;
  124. } while (t < timeout);
  125. return -ETIMEDOUT;
  126. }
  127. void iwl_set_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  128. {
  129. unsigned long flags;
  130. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  131. __iwl_write_prph(trans, ofs,
  132. __iwl_read_prph(trans, ofs) | mask);
  133. iwl_trans_release_nic_access(trans, &flags);
  134. }
  135. }
  136. IWL_EXPORT_SYMBOL(iwl_set_bits_prph);
  137. void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 ofs,
  138. u32 bits, u32 mask)
  139. {
  140. unsigned long flags;
  141. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  142. __iwl_write_prph(trans, ofs,
  143. (__iwl_read_prph(trans, ofs) & mask) | bits);
  144. iwl_trans_release_nic_access(trans, &flags);
  145. }
  146. }
  147. IWL_EXPORT_SYMBOL(iwl_set_bits_mask_prph);
  148. void iwl_clear_bits_prph(struct iwl_trans *trans, u32 ofs, u32 mask)
  149. {
  150. unsigned long flags;
  151. u32 val;
  152. if (iwl_trans_grab_nic_access(trans, false, &flags)) {
  153. val = __iwl_read_prph(trans, ofs);
  154. __iwl_write_prph(trans, ofs, (val & ~mask));
  155. iwl_trans_release_nic_access(trans, &flags);
  156. }
  157. }
  158. IWL_EXPORT_SYMBOL(iwl_clear_bits_prph);
  159. void iwl_force_nmi(struct iwl_trans *trans)
  160. {
  161. if (trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  162. iwl_write_prph(trans, DEVICE_SET_NMI_REG,
  163. DEVICE_SET_NMI_VAL_DRV);
  164. iwl_write_prph(trans, DEVICE_SET_NMI_REG,
  165. DEVICE_SET_NMI_VAL_HW);
  166. } else {
  167. iwl_write_prph(trans, DEVICE_SET_NMI_8000_REG,
  168. DEVICE_SET_NMI_8000_VAL);
  169. iwl_write_prph(trans, DEVICE_SET_NMI_REG,
  170. DEVICE_SET_NMI_VAL_DRV);
  171. }
  172. }
  173. IWL_EXPORT_SYMBOL(iwl_force_nmi);
  174. static const char *get_fh_string(int cmd)
  175. {
  176. #define IWL_CMD(x) case x: return #x
  177. switch (cmd) {
  178. IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  179. IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  180. IWL_CMD(FH_RSCSR_CHNL0_WPTR);
  181. IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  182. IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  183. IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  184. IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  185. IWL_CMD(FH_TSSR_TX_STATUS_REG);
  186. IWL_CMD(FH_TSSR_TX_ERROR_REG);
  187. default:
  188. return "UNKNOWN";
  189. }
  190. #undef IWL_CMD
  191. }
  192. int iwl_dump_fh(struct iwl_trans *trans, char **buf)
  193. {
  194. int i;
  195. static const u32 fh_tbl[] = {
  196. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  197. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  198. FH_RSCSR_CHNL0_WPTR,
  199. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  200. FH_MEM_RSSR_SHARED_CTRL_REG,
  201. FH_MEM_RSSR_RX_STATUS_REG,
  202. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  203. FH_TSSR_TX_STATUS_REG,
  204. FH_TSSR_TX_ERROR_REG
  205. };
  206. #ifdef CONFIG_IWLWIFI_DEBUGFS
  207. if (buf) {
  208. int pos = 0;
  209. size_t bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  210. *buf = kmalloc(bufsz, GFP_KERNEL);
  211. if (!*buf)
  212. return -ENOMEM;
  213. pos += scnprintf(*buf + pos, bufsz - pos,
  214. "FH register values:\n");
  215. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  216. pos += scnprintf(*buf + pos, bufsz - pos,
  217. " %34s: 0X%08x\n",
  218. get_fh_string(fh_tbl[i]),
  219. iwl_read_direct32(trans, fh_tbl[i]));
  220. return pos;
  221. }
  222. #endif
  223. IWL_ERR(trans, "FH register values:\n");
  224. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++)
  225. IWL_ERR(trans, " %34s: 0X%08x\n",
  226. get_fh_string(fh_tbl[i]),
  227. iwl_read_direct32(trans, fh_tbl[i]));
  228. return 0;
  229. }