aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/ath6kl/htc2/htc_internal.h
blob: cac97351769aea439f80321187705c45154499d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//------------------------------------------------------------------------------
// <copyright file="htc_internal.h" company="Atheros">
//    Copyright (c) 2007-2010 Atheros Corporation.  All rights reserved.
// 
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
//
//------------------------------------------------------------------------------
//==============================================================================
// Author(s): ="Atheros"
//==============================================================================
#ifndef _HTC_INTERNAL_H_
#define _HTC_INTERNAL_H_

/* for debugging, uncomment this to capture the last frame header, on frame header
 * processing errors, the last frame header is dump for comparison */
//#define HTC_CAPTURE_LAST_FRAME


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Header files */

#include "a_config.h"
#include "athdefs.h"
#include "a_osapi.h"
#include "htc_debug.h"
#include "htc.h"
#include "htc_api.h"
#include "bmi_msg.h"
#include "hif.h"
#include "AR6000/ar6k.h"

/* HTC operational parameters */
#define HTC_TARGET_RESPONSE_TIMEOUT        2000 /* in ms */
#define HTC_TARGET_DEBUG_INTR_MASK         0x01
#define HTC_TARGET_CREDIT_INTR_MASK        0xF0

#define HTC_HOST_MAX_MSG_PER_BUNDLE        8
#define HTC_MIN_HTC_MSGS_TO_BUNDLE         2

/* packet flags */

#define HTC_RX_PKT_IGNORE_LOOKAHEAD      (1 << 0)
#define HTC_RX_PKT_REFRESH_HDR           (1 << 1)
#define HTC_RX_PKT_PART_OF_BUNDLE        (1 << 2)
#define HTC_RX_PKT_NO_RECYCLE            (1 << 3)

/* scatter request flags */

#define HTC_SCATTER_REQ_FLAGS_PARTIAL_BUNDLE  (1 << 0)

struct htc_endpoint {
    HTC_ENDPOINT_ID             Id;
    HTC_SERVICE_ID              ServiceID;      /* service ID this endpoint is bound to
                                                   non-zero value means this endpoint is in use */
    struct htc_packet_queue            TxQueue;        /* HTC frame buffer TX queue */
    struct htc_packet_queue            RxBuffers;      /* HTC frame buffer RX list */
    struct htc_endpoint_credit_dist    CreditDist;     /* credit distribution structure (exposed to driver layer) */
    struct htc_ep_callbacks            EpCallBacks;    /* callbacks associated with this endpoint */
    int                         MaxTxQueueDepth;   /* max depth of the TX queue before we need to
                                                      call driver's full handler */
    int                         MaxMsgLength;        /* max length of endpoint message */
    int                         TxProcessCount;  /* reference count to continue tx processing */
    struct htc_packet_queue            RecvIndicationQueue;    /* recv packets ready to be indicated */
    int                         RxProcessCount;         /* reference count to allow single processing context */
    struct htc_target           *target;                /* back pointer to target */
    u8 SeqNo;                  /* TX seq no (helpful) for debugging */
    u32 LocalConnectionFlags;   /* local connection flags */
    struct htc_endpoint_stats          EndPointStats;          /* endpoint statistics */
};

#define INC_HTC_EP_STAT(p,stat,count) (p)->EndPointStats.stat += (count);
#define HTC_SERVICE_TX_PACKET_TAG  HTC_TX_PACKET_TAG_INTERNAL

#define NUM_CONTROL_BUFFERS     8
#define NUM_CONTROL_TX_BUFFERS  2
#define NUM_CONTROL_RX_BUFFERS  (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)

struct htc_control_buffer {
    struct htc_packet    HtcPacket;
    u8 *Buffer;
};

#define HTC_RECV_WAIT_BUFFERS        (1 << 0)
#define HTC_OP_STATE_STOPPING        (1 << 0)

/* our HTC target state */
struct htc_target {
    struct htc_endpoint                EndPoint[ENDPOINT_MAX];
    struct htc_control_buffer          HTCControlBuffers[NUM_CONTROL_BUFFERS];
    struct htc_endpoint_credit_dist   *EpCreditDistributionListHead;
    struct htc_packet_queue            ControlBufferTXFreeList;
    struct htc_packet_queue            ControlBufferRXFreeList;
    HTC_CREDIT_DIST_CALLBACK    DistributeCredits;
    HTC_CREDIT_INIT_CALLBACK    InitCredits;
    void                       *pCredDistContext;
    int                         TargetCredits;
    unsigned int                TargetCreditSize;
    A_MUTEX_T                   HTCLock;
    A_MUTEX_T                   HTCRxLock;
    A_MUTEX_T                   HTCTxLock;
    struct ar6k_device                 Device;         /* AR6K - specific state */
    u32 OpStateFlags;
    u32 RecvStateFlags;
    HTC_ENDPOINT_ID             EpWaitingForBuffers;
    bool                      TargetFailure;
#ifdef HTC_CAPTURE_LAST_FRAME
    struct htc_frame_hdr               LastFrameHdr;  /* useful for debugging */
    u8 LastTrailer[256];
    u8 LastTrailerLength;
#endif
    struct htc_init_info               HTCInitInfo;
    u8 HTCTargetVersion;
    int                         MaxMsgPerBundle;       /* max messages per bundle for HTC */
    bool                      SendBundlingEnabled;   /* run time enable for send bundling (dynamic) */
    int                         RecvBundlingEnabled;   /* run time enable for recv bundling (dynamic) */
};

#define HTC_STOPPING(t) ((t)->OpStateFlags & HTC_OP_STATE_STOPPING)
#define LOCK_HTC(t)      A_MUTEX_LOCK(&(t)->HTCLock);
#define UNLOCK_HTC(t)    A_MUTEX_UNLOCK(&(t)->HTCLock);
#define LOCK_HTC_RX(t)   A_MUTEX_LOCK(&(t)->HTCRxLock);
#define UNLOCK_HTC_RX(t) A_MUTEX_UNLOCK(&(t)->HTCRxLock);
#define LOCK_HTC_TX(t)   A_MUTEX_LOCK(&(t)->HTCTxLock);
#define UNLOCK_HTC_TX(t) A_MUTEX_UNLOCK(&(t)->HTCTxLock);

#define GET_HTC_TARGET_FROM_HANDLE(hnd) ((struct htc_target *)(hnd))
#define HTC_RECYCLE_RX_PKT(target,p,e)                           \
{                                                                \
    if ((p)->PktInfo.AsRx.HTCRxFlags & HTC_RX_PKT_NO_RECYCLE) {  \
         HTC_PACKET_RESET_RX(pPacket);                           \
         pPacket->Status = A_ECANCELED;                          \
         (e)->EpCallBacks.EpRecv((e)->EpCallBacks.pContext,      \
                                 (p));                           \
    } else {                                                     \
        HTC_PACKET_RESET_RX(pPacket);                            \
        HTCAddReceivePkt((HTC_HANDLE)(target),(p));              \
    }                                                            \
}

/* internal HTC functions */
void        HTCControlTxComplete(void *Context, struct htc_packet *pPacket);
void        HTCControlRecv(void *Context, struct htc_packet *pPacket);
int    HTCWaitforControlMessage(struct htc_target *target, struct htc_packet **ppControlPacket);
struct htc_packet *HTCAllocControlBuffer(struct htc_target *target, struct htc_packet_queue *pList);
void        HTCFreeControlBuffer(struct htc_target *target, struct htc_packet *pPacket, struct htc_packet_queue *pList);
int    HTCIssueSend(struct htc_target *target, struct htc_packet *pPacket);
void        HTCRecvCompleteHandler(void *Context, struct htc_packet *pPacket);
int    HTCRecvMessagePendingHandler(void *Context, u32 MsgLookAheads[], int NumLookAheads, bool *pAsyncProc, int *pNumPktsFetched);
void        HTCProcessCreditRpt(struct htc_target *target, HTC_CREDIT_REPORT *pRpt, int NumEntries, HTC_ENDPOINT_ID FromEndpoint);
int    HTCSendSetupComplete(struct htc_target *target);
void        HTCFlushRecvBuffers(struct htc_target *target);
void        HTCFlushSendPkts(struct htc_target *target);

#ifdef ATH_DEBUG_MODULE
void        DumpCreditDist(struct htc_endpoint_credit_dist *pEPDist);
void        DumpCreditDistStates(struct htc_target *target);
void 		DebugDumpBytes(u8 *buffer, u16 length, char *pDescription);
#endif

static INLINE struct htc_packet *HTC_ALLOC_CONTROL_TX(struct htc_target *target) {
    struct htc_packet *pPacket = HTCAllocControlBuffer(target,&target->ControlBufferTXFreeList);
    if (pPacket != NULL) {
            /* set payload pointer area with some headroom */
        pPacket->pBuffer = pPacket->pBufferStart + HTC_HDR_LENGTH;
    }
    return pPacket;
}

#define HTC_FREE_CONTROL_TX(t,p) HTCFreeControlBuffer((t),(p),&(t)->ControlBufferTXFreeList)
#define HTC_ALLOC_CONTROL_RX(t)  HTCAllocControlBuffer((t),&(t)->ControlBufferRXFreeList)
#define HTC_FREE_CONTROL_RX(t,p) \
{                                                                \
    HTC_PACKET_RESET_RX(p);                                      \
    HTCFreeControlBuffer((t),(p),&(t)->ControlBufferRXFreeList); \
}

#define HTC_PREPARE_SEND_PKT(pP,sendflags,ctrl0,ctrl1)       \
{                                                   \
    u8 *pHdrBuf;                               \
    (pP)->pBuffer -= HTC_HDR_LENGTH;                \
    pHdrBuf = (pP)->pBuffer;                        \
    A_SET_UINT16_FIELD(pHdrBuf,struct htc_frame_hdr,PayloadLen,(u16)(pP)->ActualLength);  \
    A_SET_UINT8_FIELD(pHdrBuf,struct htc_frame_hdr,Flags,(sendflags));                         \
    A_SET_UINT8_FIELD(pHdrBuf,struct htc_frame_hdr,EndpointID, (u8)(pP)->Endpoint); \
    A_SET_UINT8_FIELD(pHdrBuf,struct htc_frame_hdr,ControlBytes[0], (u8)(ctrl0));   \
    A_SET_UINT8_FIELD(pHdrBuf,struct htc_frame_hdr,ControlBytes[1], (u8)(ctrl1));   \
}

#define HTC_UNPREPARE_SEND_PKT(pP)     \
    (pP)->pBuffer += HTC_HDR_LENGTH;   \
    
#ifdef __cplusplus
}
#endif

#endif /* _HTC_INTERNAL_H_ */