ar6k.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //------------------------------------------------------------------------------
  2. // <copyright file="ar6k.h" company="Atheros">
  3. // Copyright (c) 2007-2008 Atheros Corporation. All rights reserved.
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License version 2 as
  7. // published by the Free Software Foundation;
  8. //
  9. // Software distributed under the License is distributed on an "AS
  10. // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. // implied. See the License for the specific language governing
  12. // rights and limitations under the License.
  13. //
  14. //
  15. //------------------------------------------------------------------------------
  16. //==============================================================================
  17. // AR6K device layer that handles register level I/O
  18. //
  19. // Author(s): ="Atheros"
  20. //==============================================================================
  21. #ifndef AR6K_H_
  22. #define AR6K_H_
  23. #define AR6K_MAILBOXES 4
  24. /* HTC runs over mailbox 0 */
  25. #define HTC_MAILBOX 0
  26. #define AR6K_TARGET_DEBUG_INTR_MASK 0x01
  27. #define OTHER_INTS_ENABLED (INT_STATUS_ENABLE_ERROR_MASK | \
  28. INT_STATUS_ENABLE_CPU_MASK | \
  29. INT_STATUS_ENABLE_COUNTER_MASK)
  30. //#define MBOXHW_UNIT_TEST 1
  31. #include "athstartpack.h"
  32. typedef PREPACK struct _AR6K_IRQ_PROC_REGISTERS {
  33. A_UINT8 host_int_status;
  34. A_UINT8 cpu_int_status;
  35. A_UINT8 error_int_status;
  36. A_UINT8 counter_int_status;
  37. A_UINT8 mbox_frame;
  38. A_UINT8 rx_lookahead_valid;
  39. A_UINT8 hole[2];
  40. A_UINT32 rx_lookahead[2];
  41. } POSTPACK AR6K_IRQ_PROC_REGISTERS;
  42. #define AR6K_IRQ_PROC_REGS_SIZE sizeof(AR6K_IRQ_PROC_REGISTERS)
  43. typedef PREPACK struct _AR6K_IRQ_ENABLE_REGISTERS {
  44. A_UINT8 int_status_enable;
  45. A_UINT8 cpu_int_status_enable;
  46. A_UINT8 error_status_enable;
  47. A_UINT8 counter_int_status_enable;
  48. } POSTPACK AR6K_IRQ_ENABLE_REGISTERS;
  49. #include "athendpack.h"
  50. #define AR6K_IRQ_ENABLE_REGS_SIZE sizeof(AR6K_IRQ_ENABLE_REGISTERS)
  51. #define AR6K_REG_IO_BUFFER_SIZE 32
  52. #define AR6K_MAX_REG_IO_BUFFERS 8
  53. /* buffers for ASYNC I/O */
  54. typedef struct _AR6K_ASYNC_REG_IO_BUFFER {
  55. HTC_PACKET HtcPacket; /* we use an HTC packet as a wrapper for our async register-based I/O */
  56. A_UINT8 Buffer[AR6K_REG_IO_BUFFER_SIZE];
  57. } AR6K_ASYNC_REG_IO_BUFFER;
  58. typedef enum _AR6K_TARGET_FAILURE_TYPE {
  59. AR6K_TARGET_ASSERT = 1,
  60. AR6K_TARGET_RX_ERROR,
  61. AR6K_TARGET_TX_ERROR
  62. } AR6K_TARGET_FAILURE_TYPE;
  63. typedef struct _AR6K_DEVICE {
  64. A_MUTEX_T Lock;
  65. AR6K_IRQ_PROC_REGISTERS IrqProcRegisters;
  66. AR6K_IRQ_ENABLE_REGISTERS IrqEnableRegisters;
  67. void *HIFDevice;
  68. A_UINT32 BlockSize;
  69. A_UINT32 BlockMask;
  70. A_UINT32 MailboxAddress;
  71. HIF_PENDING_EVENTS_FUNC GetPendingEventsFunc;
  72. void *HTCContext;
  73. HTC_PACKET_QUEUE RegisterIOList;
  74. AR6K_ASYNC_REG_IO_BUFFER RegIOBuffers[AR6K_MAX_REG_IO_BUFFERS];
  75. void (*TargetFailureCallback)(void *Context, AR6K_TARGET_FAILURE_TYPE Type);
  76. A_STATUS (*MessagePendingCallback)(void *Context, A_UINT32 *LookAhead, A_BOOL *pAsyncProc);
  77. HIF_DEVICE_IRQ_PROCESSING_MODE HifIRQProcessingMode;
  78. HIF_MASK_UNMASK_RECV_EVENT HifMaskUmaskRecvEvent;
  79. A_BOOL HifAttached;
  80. } AR6K_DEVICE;
  81. #define IS_DEV_IRQ_PROCESSING_ASYNC_ALLOWED(pDev) ((pDev)->HifIRQProcessingMode != HIF_DEVICE_IRQ_SYNC_ONLY)
  82. A_STATUS DevSetup(AR6K_DEVICE *pDev);
  83. void DevCleanup(AR6K_DEVICE *pDev);
  84. A_STATUS DevUnmaskInterrupts(AR6K_DEVICE *pDev);
  85. A_STATUS DevMaskInterrupts(AR6K_DEVICE *pDev);
  86. A_STATUS DevPollMboxMsgRecv(AR6K_DEVICE *pDev,
  87. A_UINT32 *pLookAhead,
  88. int TimeoutMS);
  89. A_STATUS DevRWCompletionHandler(void *context, A_STATUS status);
  90. A_STATUS DevDsrHandler(void *context);
  91. A_STATUS DevCheckPendingRecvMsgsAsync(void *context);
  92. void DevDumpRegisters(AR6K_IRQ_PROC_REGISTERS *pIrqProcRegs,
  93. AR6K_IRQ_ENABLE_REGISTERS *pIrqEnableRegs);
  94. #define DEV_STOP_RECV_ASYNC TRUE
  95. #define DEV_STOP_RECV_SYNC FALSE
  96. #define DEV_ENABLE_RECV_ASYNC TRUE
  97. #define DEV_ENABLE_RECV_SYNC FALSE
  98. A_STATUS DevStopRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode);
  99. A_STATUS DevEnableRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode);
  100. A_STATUS DevEnableInterrupts(AR6K_DEVICE *pDev);
  101. A_STATUS DevDisableInterrupts(AR6K_DEVICE *pDev);
  102. static INLINE A_STATUS DevSendPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 SendLength) {
  103. A_UINT32 paddedLength;
  104. A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE;
  105. A_STATUS status;
  106. /* adjust the length to be a multiple of block size if appropriate */
  107. paddedLength = (SendLength + (pDev->BlockMask)) &
  108. (~(pDev->BlockMask));
  109. #if 0 // BufferLength may not be set in , fix this...
  110. if (paddedLength > pPacket->BufferLength) {
  111. AR_DEBUG_ASSERT(FALSE);
  112. if (pPacket->Completion != NULL) {
  113. COMPLETE_HTC_PACKET(pPacket,A_EINVAL);
  114. }
  115. return A_EINVAL;
  116. }
  117. #endif
  118. AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
  119. ("DevSendPacket, Padded Length: %d Mbox:0x%X (mode:%s)\n",
  120. paddedLength,
  121. pDev->MailboxAddress,
  122. sync ? "SYNC" : "ASYNC"));
  123. status = HIFReadWrite(pDev->HIFDevice,
  124. pDev->MailboxAddress,
  125. pPacket->pBuffer,
  126. paddedLength, /* the padded length */
  127. sync ? HIF_WR_SYNC_BLOCK_INC : HIF_WR_ASYNC_BLOCK_INC,
  128. sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */
  129. if (sync) {
  130. pPacket->Status = status;
  131. }
  132. return status;
  133. }
  134. static INLINE A_STATUS DevRecvPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 RecvLength) {
  135. A_UINT32 paddedLength;
  136. A_STATUS status;
  137. A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE;
  138. /* adjust the length to be a multiple of block size if appropriate */
  139. paddedLength = (RecvLength + (pDev->BlockMask)) &
  140. (~(pDev->BlockMask));
  141. if (paddedLength > pPacket->BufferLength) {
  142. AR_DEBUG_ASSERT(FALSE);
  143. AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
  144. ("DevRecvPacket, Not enough space for padlen:%d recvlen:%d bufferlen:%d \n",
  145. paddedLength,RecvLength,pPacket->BufferLength));
  146. if (pPacket->Completion != NULL) {
  147. COMPLETE_HTC_PACKET(pPacket,A_EINVAL);
  148. }
  149. return A_EINVAL;
  150. }
  151. AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
  152. ("DevRecvPacket, Padded Length: %d Mbox:0x%X (mode:%s)\n",
  153. paddedLength,
  154. pDev->MailboxAddress,
  155. sync ? "SYNC" : "ASYNC"));
  156. status = HIFReadWrite(pDev->HIFDevice,
  157. pDev->MailboxAddress,
  158. pPacket->pBuffer,
  159. paddedLength,
  160. sync ? HIF_RD_SYNC_BLOCK_INC : HIF_RD_ASYNC_BLOCK_INC,
  161. sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */
  162. if (sync) {
  163. pPacket->Status = status;
  164. }
  165. return status;
  166. }
  167. #ifdef MBOXHW_UNIT_TEST
  168. A_STATUS DoMboxHWTest(AR6K_DEVICE *pDev);
  169. #endif
  170. #endif /*AR6K_H_*/