cmd.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Atheros CARL9170 driver
  3. *
  4. * Basic HW register/memory/command access functions
  5. *
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2010, Christian Lamparter <chunkeey@googlemail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; see the file COPYING. If not, see
  21. * http://www.gnu.org/licenses/.
  22. *
  23. * This file incorporates work covered by the following copyright and
  24. * permission notice:
  25. * Copyright (c) 2007-2008 Atheros Communications, Inc.
  26. *
  27. * Permission to use, copy, modify, and/or distribute this software for any
  28. * purpose with or without fee is hereby granted, provided that the above
  29. * copyright notice and this permission notice appear in all copies.
  30. *
  31. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  32. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  34. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  35. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  36. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  37. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. */
  39. #ifndef __CMD_H
  40. #define __CMD_H
  41. #include "carl9170.h"
  42. /* basic HW access */
  43. int carl9170_write_reg(struct ar9170 *ar, const u32 reg, const u32 val);
  44. int carl9170_read_reg(struct ar9170 *ar, const u32 reg, u32 *val);
  45. int carl9170_read_mreg(struct ar9170 *ar, const int nregs,
  46. const u32 *regs, u32 *out);
  47. int carl9170_echo_test(struct ar9170 *ar, u32 v);
  48. int carl9170_reboot(struct ar9170 *ar);
  49. int carl9170_mac_reset(struct ar9170 *ar);
  50. int carl9170_powersave(struct ar9170 *ar, const bool power_on);
  51. int carl9170_collect_tally(struct ar9170 *ar);
  52. int carl9170_bcn_ctrl(struct ar9170 *ar, const unsigned int vif_id,
  53. const u32 mode, const u32 addr, const u32 len);
  54. static inline int carl9170_flush_cab(struct ar9170 *ar,
  55. const unsigned int vif_id)
  56. {
  57. return carl9170_bcn_ctrl(ar, vif_id, CARL9170_BCN_CTRL_DRAIN, 0, 0);
  58. }
  59. static inline int carl9170_rx_filter(struct ar9170 *ar,
  60. const unsigned int _rx_filter)
  61. {
  62. __le32 rx_filter = cpu_to_le32(_rx_filter);
  63. return carl9170_exec_cmd(ar, CARL9170_CMD_RX_FILTER,
  64. sizeof(rx_filter), (u8 *)&rx_filter,
  65. 0, NULL);
  66. }
  67. struct carl9170_cmd *carl9170_cmd_buf(struct ar9170 *ar,
  68. const enum carl9170_cmd_oids cmd, const unsigned int len);
  69. /*
  70. * Macros to facilitate writing multiple registers in a single
  71. * write-combining USB command. Note that when the first group
  72. * fails the whole thing will fail without any others attempted,
  73. * but you won't know which write in the group failed.
  74. */
  75. #define carl9170_regwrite_begin(ar) \
  76. do { \
  77. int __nreg = 0, __err = 0; \
  78. struct ar9170 *__ar = ar;
  79. #define carl9170_regwrite(r, v) do { \
  80. __ar->cmd_buf[2 * __nreg + 1] = cpu_to_le32(r); \
  81. __ar->cmd_buf[2 * __nreg + 2] = cpu_to_le32(v); \
  82. __nreg++; \
  83. if ((__nreg >= PAYLOAD_MAX / 2)) { \
  84. if (IS_ACCEPTING_CMD(__ar)) \
  85. __err = carl9170_exec_cmd(__ar, \
  86. CARL9170_CMD_WREG, 8 * __nreg, \
  87. (u8 *) &__ar->cmd_buf[1], 0, NULL); \
  88. else \
  89. goto __regwrite_out; \
  90. \
  91. __nreg = 0; \
  92. if (__err) \
  93. goto __regwrite_out; \
  94. } \
  95. } while (0)
  96. #define carl9170_regwrite_finish() \
  97. __regwrite_out : \
  98. if (__err == 0 && __nreg) { \
  99. if (IS_ACCEPTING_CMD(__ar)) \
  100. __err = carl9170_exec_cmd(__ar, \
  101. CARL9170_CMD_WREG, 8 * __nreg, \
  102. (u8 *) &__ar->cmd_buf[1], 0, NULL); \
  103. __nreg = 0; \
  104. }
  105. #define carl9170_regwrite_result() \
  106. __err; \
  107. } while (0)
  108. #define carl9170_async_regwrite_get_buf() \
  109. do { \
  110. __nreg = 0; \
  111. __cmd = carl9170_cmd_buf(__carl, CARL9170_CMD_WREG_ASYNC, \
  112. CARL9170_MAX_CMD_PAYLOAD_LEN); \
  113. if (__cmd == NULL) { \
  114. __err = -ENOMEM; \
  115. goto __async_regwrite_out; \
  116. } \
  117. } while (0)
  118. #define carl9170_async_regwrite_begin(carl) \
  119. do { \
  120. struct ar9170 *__carl = carl; \
  121. struct carl9170_cmd *__cmd; \
  122. unsigned int __nreg; \
  123. int __err = 0; \
  124. carl9170_async_regwrite_get_buf(); \
  125. #define carl9170_async_regwrite_flush() \
  126. do { \
  127. if (__cmd == NULL || __nreg == 0) \
  128. break; \
  129. \
  130. if (IS_ACCEPTING_CMD(__carl) && __nreg) { \
  131. __cmd->hdr.len = 8 * __nreg; \
  132. __err = __carl9170_exec_cmd(__carl, __cmd, true); \
  133. __cmd = NULL; \
  134. break; \
  135. } \
  136. goto __async_regwrite_out; \
  137. } while (0)
  138. #define carl9170_async_regwrite(r, v) do { \
  139. if (__cmd == NULL) \
  140. carl9170_async_regwrite_get_buf(); \
  141. __cmd->wreg.regs[__nreg].addr = cpu_to_le32(r); \
  142. __cmd->wreg.regs[__nreg].val = cpu_to_le32(v); \
  143. __nreg++; \
  144. if ((__nreg >= PAYLOAD_MAX / 2)) \
  145. carl9170_async_regwrite_flush(); \
  146. } while (0)
  147. #define carl9170_async_regwrite_finish() do { \
  148. __async_regwrite_out: \
  149. if (__cmd != NULL && __err == 0) \
  150. carl9170_async_regwrite_flush(); \
  151. kfree(__cmd); \
  152. } while (0) \
  153. #define carl9170_async_regwrite_result() \
  154. __err; \
  155. } while (0)
  156. #endif /* __CMD_H */