3 * Copyright (c) 2007 Atheros Communications Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation;
11 * Software distributed under the License is distributed on an "AS
12 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * rights and limitations under the License.
23 #define AR6K_MAILBOXES 4
25 /* HTC runs over mailbox 0 */
28 #define AR6K_TARGET_DEBUG_INTR_MASK 0x01
30 #define OTHER_INTS_ENABLED (INT_STATUS_ENABLE_ERROR_MASK | \
31 INT_STATUS_ENABLE_CPU_MASK | \
32 INT_STATUS_ENABLE_COUNTER_MASK)
34 //#define MBOXHW_UNIT_TEST 1
36 #include "athstartpack.h"
37 typedef PREPACK struct _AR6K_IRQ_PROC_REGISTERS {
38 A_UINT8 host_int_status;
39 A_UINT8 cpu_int_status;
40 A_UINT8 error_int_status;
41 A_UINT8 counter_int_status;
43 A_UINT8 rx_lookahead_valid;
45 A_UINT32 rx_lookahead[2];
46 } POSTPACK AR6K_IRQ_PROC_REGISTERS;
48 #define AR6K_IRQ_PROC_REGS_SIZE sizeof(AR6K_IRQ_PROC_REGISTERS)
52 typedef PREPACK struct _AR6K_IRQ_ENABLE_REGISTERS {
53 A_UINT8 int_status_enable;
54 A_UINT8 cpu_int_status_enable;
55 A_UINT8 error_status_enable;
56 A_UINT8 counter_int_status_enable;
57 } POSTPACK AR6K_IRQ_ENABLE_REGISTERS;
59 #include "athendpack.h"
61 #define AR6K_IRQ_ENABLE_REGS_SIZE sizeof(AR6K_IRQ_ENABLE_REGISTERS)
63 #define AR6K_REG_IO_BUFFER_SIZE 32
64 #define AR6K_MAX_REG_IO_BUFFERS 8
66 /* buffers for ASYNC I/O */
67 typedef struct AR6K_ASYNC_REG_IO_BUFFER {
68 HTC_PACKET HtcPacket; /* we use an HTC packet as a wrapper for our async register-based I/O */
69 A_UINT8 Buffer[AR6K_REG_IO_BUFFER_SIZE];
70 } AR6K_ASYNC_REG_IO_BUFFER;
72 typedef struct _AR6K_DEVICE {
74 AR6K_IRQ_PROC_REGISTERS IrqProcRegisters;
75 AR6K_IRQ_ENABLE_REGISTERS IrqEnableRegisters;
79 A_UINT32 MailboxAddress;
80 HIF_PENDING_EVENTS_FUNC GetPendingEventsFunc;
82 HTC_PACKET_QUEUE RegisterIOList;
83 AR6K_ASYNC_REG_IO_BUFFER RegIOBuffers[AR6K_MAX_REG_IO_BUFFERS];
84 void (*TargetFailureCallback)(void *Context);
85 A_STATUS (*MessagePendingCallback)(void *Context, A_UINT32 LookAhead, A_BOOL *pAsyncProc);
86 HIF_DEVICE_IRQ_PROCESSING_MODE HifIRQProcessingMode;
87 HIF_MASK_UNMASK_RECV_EVENT HifMaskUmaskRecvEvent;
90 #define IS_DEV_IRQ_PROCESSING_ASYNC_ALLOWED(pDev) ((pDev)->HifIRQProcessingMode != HIF_DEVICE_IRQ_SYNC_ONLY)
92 A_STATUS DevSetup(AR6K_DEVICE *pDev);
93 A_STATUS DevUnmaskInterrupts(AR6K_DEVICE *pDev);
94 A_STATUS DevMaskInterrupts(AR6K_DEVICE *pDev);
95 A_STATUS DevPollMboxMsgRecv(AR6K_DEVICE *pDev,
98 A_STATUS DevRWCompletionHandler(void *context, A_STATUS status);
99 A_STATUS DevDsrHandler(void *context);
100 A_STATUS DevCheckPendingRecvMsgsAsync(void *context);
101 void DevDumpRegisters(AR6K_IRQ_PROC_REGISTERS *pIrqProcRegs,
102 AR6K_IRQ_ENABLE_REGISTERS *pIrqEnableRegs);
104 #define DEV_STOP_RECV_ASYNC TRUE
105 #define DEV_STOP_RECV_SYNC FALSE
106 #define DEV_ENABLE_RECV_ASYNC TRUE
107 #define DEV_ENABLE_RECV_SYNC FALSE
108 A_STATUS DevStopRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode);
109 A_STATUS DevEnableRecv(AR6K_DEVICE *pDev, A_BOOL ASyncMode);
111 static INLINE A_STATUS DevSendPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 SendLength) {
112 A_UINT32 paddedLength;
113 A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE;
116 /* adjust the length to be a multiple of block size if appropriate */
117 paddedLength = (SendLength + (pDev->BlockMask)) &
118 (~(pDev->BlockMask));
119 #if 0 // BufferLength may not be set in , fix this...
120 if (paddedLength > pPacket->BufferLength) {
121 AR_DEBUG_ASSERT(FALSE);
122 if (pPacket->Completion != NULL) {
123 COMPLETE_HTC_PACKET(pPacket,A_EINVAL);
128 AR_DEBUG_PRINTF(ATH_DEBUG_SEND,
129 ("DevSendPacket, Padded Length: %d Mbox:0x%X (mode:%s)\n",
131 pDev->MailboxAddress,
132 sync ? "SYNC" : "ASYNC"));
134 status = HIFReadWrite(pDev->HIFDevice,
135 pDev->MailboxAddress,
137 paddedLength, /* the padded length */
138 sync ? HIF_WR_SYNC_BLOCK_INC : HIF_WR_ASYNC_BLOCK_INC,
139 sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */
142 pPacket->Status = status;
148 static INLINE A_STATUS DevRecvPacket(AR6K_DEVICE *pDev, HTC_PACKET *pPacket, A_UINT32 RecvLength) {
149 A_UINT32 paddedLength;
151 A_BOOL sync = (pPacket->Completion == NULL) ? TRUE : FALSE;
153 /* adjust the length to be a multiple of block size if appropriate */
154 paddedLength = (RecvLength + (pDev->BlockMask)) &
155 (~(pDev->BlockMask));
156 if (paddedLength > pPacket->BufferLength) {
157 AR_DEBUG_ASSERT(FALSE);
158 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
159 ("DevRecvPacket, Not enough space for padlen:%d recvlen:%d bufferlen:%d \n",
160 paddedLength,RecvLength,pPacket->BufferLength));
161 if (pPacket->Completion != NULL) {
162 COMPLETE_HTC_PACKET(pPacket,A_EINVAL);
167 AR_DEBUG_PRINTF(ATH_DEBUG_RECV,
168 ("DevRecvPacket, Padded Length: %d Mbox:0x%X (mode:%s)\n",
170 pDev->MailboxAddress,
171 sync ? "SYNC" : "ASYNC"));
173 status = HIFReadWrite(pDev->HIFDevice,
174 pDev->MailboxAddress,
177 sync ? HIF_RD_SYNC_BLOCK_INC : HIF_RD_ASYNC_BLOCK_INC,
178 sync ? NULL : pPacket); /* pass the packet as the context to the HIF request */
181 pPacket->Status = status;
187 #ifdef MBOXHW_UNIT_TEST
188 A_STATUS DoMboxHWTest(AR6K_DEVICE *pDev);