iwl-io.c 7.2 KB

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