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.
20 #ifndef _HTC_INTERNAL_H_
21 #define _HTC_INTERNAL_H_
23 /* for debugging, uncomment this to capture the last frame header, on frame header
24 * processing errors, the last frame header is dump for comparison */
25 //#define HTC_CAPTURE_LAST_FRAME
27 //#define HTC_EP_STAT_PROFILING
31 #endif /* __cplusplus */
45 /* HTC operational parameters */
46 #define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
47 #define HTC_TARGET_DEBUG_INTR_MASK 0x01
48 #define HTC_TARGET_CREDIT_INTR_MASK 0xF0
50 typedef struct _HTC_ENDPOINT
{
51 HTC_SERVICE_ID ServiceID
; /* service ID this endpoint is bound to
52 non-zero value means this endpoint is in use */
53 HTC_PACKET_QUEUE TxQueue
; /* HTC frame buffer TX queue */
54 HTC_PACKET_QUEUE RxBuffers
; /* HTC frame buffer RX list */
55 HTC_ENDPOINT_CREDIT_DIST CreditDist
; /* credit distribution structure (exposed to driver layer) */
56 HTC_EP_CALLBACKS EpCallBacks
; /* callbacks associated with this endpoint */
57 int MaxTxQueueDepth
; /* max depth of the TX queue before we need to
58 call driver's full handler */
59 int CurrentTxQueueDepth
; /* current TX queue depth */
60 int MaxMsgLength
; /* max length of endpoint message */
61 #ifdef HTC_EP_STAT_PROFILING
62 HTC_ENDPOINT_STATS EndPointStats
; /* endpoint statistics */
66 #ifdef HTC_EP_STAT_PROFILING
67 #define INC_HTC_EP_STAT(p,stat,count) (p)->EndPointStats.stat += (count);
69 #define INC_HTC_EP_STAT(p,stat,count)
72 #define HTC_SERVICE_TX_PACKET_TAG HTC_TX_PACKET_TAG_INTERNAL
74 #define NUM_CONTROL_BUFFERS 8
75 #define NUM_CONTROL_TX_BUFFERS 2
76 #define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)
78 #define HTC_CONTROL_BUFFER_SIZE (HTC_MAX_CONTROL_MESSAGE_LENGTH + HTC_HDR_LENGTH)
80 typedef struct HTC_CONTROL_BUFFER
{
82 A_UINT8 Buffer
[HTC_CONTROL_BUFFER_SIZE
];
85 /* our HTC target state */
86 typedef struct _HTC_TARGET
{
87 HTC_ENDPOINT EndPoint
[ENDPOINT_MAX
];
88 HTC_CONTROL_BUFFER HTCControlBuffers
[NUM_CONTROL_BUFFERS
];
89 HTC_ENDPOINT_CREDIT_DIST
*EpCreditDistributionListHead
;
90 HTC_PACKET_QUEUE ControlBufferTXFreeList
;
91 HTC_PACKET_QUEUE ControlBufferRXFreeList
;
92 HTC_CREDIT_DIST_CALLBACK DistributeCredits
;
93 HTC_CREDIT_INIT_CALLBACK InitCredits
;
94 void *pCredDistContext
;
100 AR6K_DEVICE Device
; /* AR6K - specific state */
101 A_UINT32 HTCStateFlags
;
102 HTC_ENDPOINT_ID EpWaitingForBuffers
;
103 A_BOOL TargetFailure
;
104 void *pInstanceContext
;
105 #define HTC_STATE_WAIT_BUFFERS (1 << 0)
106 #define HTC_STATE_STOPPING (1 << 1)
107 #ifdef HTC_CAPTURE_LAST_FRAME
108 HTC_FRAME_HDR LastFrameHdr
; /* useful for debugging */
109 A_UINT8 LastTrailer
[256];
110 A_UINT8 LastTrailerLength
;
114 #define HTC_STOPPING(t) ((t)->HTCStateFlags & HTC_STATE_STOPPING)
115 #define LOCK_HTC(t) A_MUTEX_LOCK(&(t)->HTCLock);
116 #define UNLOCK_HTC(t) A_MUTEX_UNLOCK(&(t)->HTCLock);
117 #define LOCK_HTC_RX(t) A_MUTEX_LOCK(&(t)->HTCRxLock);
118 #define UNLOCK_HTC_RX(t) A_MUTEX_UNLOCK(&(t)->HTCRxLock);
119 #define LOCK_HTC_TX(t) A_MUTEX_LOCK(&(t)->HTCTxLock);
120 #define UNLOCK_HTC_TX(t) A_MUTEX_UNLOCK(&(t)->HTCTxLock);
122 #define GET_HTC_TARGET_FROM_HANDLE(hnd) ((HTC_TARGET *)(hnd))
123 #define HTC_RECYCLE_RX_PKT(target,p) \
125 HTC_PACKET_RESET_RX(pPacket); \
126 HTCAddReceivePkt((HTC_HANDLE)(target),(p)); \
129 /* internal HTC functions */
130 void HTCControlTxComplete(void *Context
, HTC_PACKET
*pPacket
);
131 void HTCControlRecv(void *Context
, HTC_PACKET
*pPacket
);
132 A_STATUS
HTCWaitforControlMessage(HTC_TARGET
*target
, HTC_PACKET
**ppControlPacket
);
133 HTC_PACKET
*HTCAllocControlBuffer(HTC_TARGET
*target
, HTC_PACKET_QUEUE
*pList
);
134 void HTCFreeControlBuffer(HTC_TARGET
*target
, HTC_PACKET
*pPacket
, HTC_PACKET_QUEUE
*pList
);
135 A_STATUS
HTCIssueSend(HTC_TARGET
*target
, HTC_PACKET
*pPacket
, A_UINT8 Flags
);
136 A_STATUS
HTCIssueRecv(HTC_TARGET
*target
, HTC_PACKET
*pPacket
);
137 void HTCRecvCompleteHandler(void *Context
, HTC_PACKET
*pPacket
);
138 A_STATUS
HTCRecvMessagePendingHandler(void *Context
, A_UINT32 LookAhead
, A_BOOL
*pAsyncProc
);
139 void HTCProcessCreditRpt(HTC_TARGET
*target
, HTC_CREDIT_REPORT
*pRpt
, int NumEntries
, HTC_ENDPOINT_ID FromEndpoint
);
140 A_STATUS
HTCSendSetupComplete(HTC_TARGET
*target
);
141 void HTCFlushRecvBuffers(HTC_TARGET
*target
);
142 void HTCFlushSendPkts(HTC_TARGET
*target
);
143 void DumpCreditDist(HTC_ENDPOINT_CREDIT_DIST
*pEPDist
);
144 void DumpCreditDistStates(HTC_TARGET
*target
);
145 void DebugDumpBytes(A_UCHAR
*buffer
, A_UINT16 length
, char *pDescription
);
147 static INLINE HTC_PACKET
*HTC_ALLOC_CONTROL_TX(HTC_TARGET
*target
) {
148 HTC_PACKET
*pPacket
= HTCAllocControlBuffer(target
,&target
->ControlBufferTXFreeList
);
149 if (pPacket
!= NULL
) {
150 /* set payload pointer area with some headroom */
151 pPacket
->pBuffer
= pPacket
->pBufferStart
+ HTC_HDR_LENGTH
;
156 #define HTC_FREE_CONTROL_TX(t,p) HTCFreeControlBuffer((t),(p),&(t)->ControlBufferTXFreeList)
157 #define HTC_ALLOC_CONTROL_RX(t) HTCAllocControlBuffer((t),&(t)->ControlBufferRXFreeList)
158 #define HTC_FREE_CONTROL_RX(t,p) \
160 HTC_PACKET_RESET_RX(p); \
161 HTCFreeControlBuffer((t),(p),&(t)->ControlBufferRXFreeList); \
168 #endif /* _HTC_INTERNAL_H_ */