1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2004-2011 Atheros Communications Inc.
3*4882a593Smuzhiyun * Copyright (c) 2011 Qualcomm Atheros, Inc.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Permission to use, copy, modify, and/or distribute this software for any
6*4882a593Smuzhiyun * purpose with or without fee is hereby granted, provided that the above
7*4882a593Smuzhiyun * copyright notice and this permission notice appear in all copies.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*4882a593Smuzhiyun * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*4882a593Smuzhiyun * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*4882a593Smuzhiyun * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*4882a593Smuzhiyun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*4882a593Smuzhiyun * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*4882a593Smuzhiyun * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #ifndef HTC_H
19*4882a593Smuzhiyun #define HTC_H
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #include "common.h"
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun /* frame header flags */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /* send direction */
26*4882a593Smuzhiyun #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
27*4882a593Smuzhiyun #define HTC_FLAGS_SEND_BUNDLE (1 << 1)
28*4882a593Smuzhiyun #define HTC_FLAGS_TX_FIXUP_NETBUF (1 << 2)
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /* receive direction */
31*4882a593Smuzhiyun #define HTC_FLG_RX_UNUSED (1 << 0)
32*4882a593Smuzhiyun #define HTC_FLG_RX_TRAILER (1 << 1)
33*4882a593Smuzhiyun /* Bundle count maske and shift */
34*4882a593Smuzhiyun #define HTC_FLG_RX_BNDL_CNT (0xF0)
35*4882a593Smuzhiyun #define HTC_FLG_RX_BNDL_CNT_S 4
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #define HTC_HDR_LENGTH (sizeof(struct htc_frame_hdr))
38*4882a593Smuzhiyun #define HTC_MAX_PAYLOAD_LENGTH (4096 - sizeof(struct htc_frame_hdr))
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun /* HTC control message IDs */
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #define HTC_MSG_READY_ID 1
43*4882a593Smuzhiyun #define HTC_MSG_CONN_SVC_ID 2
44*4882a593Smuzhiyun #define HTC_MSG_CONN_SVC_RESP_ID 3
45*4882a593Smuzhiyun #define HTC_MSG_SETUP_COMPLETE_ID 4
46*4882a593Smuzhiyun #define HTC_MSG_SETUP_COMPLETE_EX_ID 5
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun #define HTC_MAX_CTRL_MSG_LEN 256
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #define HTC_VERSION_2P0 0x00
51*4882a593Smuzhiyun #define HTC_VERSION_2P1 0x01
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #define HTC_CONN_FLGS_THRESH_LVL_QUAT 0x0
56*4882a593Smuzhiyun #define HTC_CONN_FLGS_THRESH_LVL_HALF 0x1
57*4882a593Smuzhiyun #define HTC_CONN_FLGS_THRESH_LVL_THREE_QUAT 0x2
58*4882a593Smuzhiyun #define HTC_CONN_FLGS_REDUCE_CRED_DRIB 0x4
59*4882a593Smuzhiyun #define HTC_CONN_FLGS_THRESH_MASK 0x3
60*4882a593Smuzhiyun /* disable credit flow control on a specific service */
61*4882a593Smuzhiyun #define HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL (1 << 3)
62*4882a593Smuzhiyun #define HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT 8
63*4882a593Smuzhiyun #define HTC_CONN_FLGS_SET_RECV_ALLOC_MASK 0xFF00U
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* connect response status codes */
66*4882a593Smuzhiyun #define HTC_SERVICE_SUCCESS 0
67*4882a593Smuzhiyun #define HTC_SERVICE_NOT_FOUND 1
68*4882a593Smuzhiyun #define HTC_SERVICE_FAILED 2
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun /* no resources (i.e. no more endpoints) */
71*4882a593Smuzhiyun #define HTC_SERVICE_NO_RESOURCES 3
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun /* specific service is not allowing any more endpoints */
74*4882a593Smuzhiyun #define HTC_SERVICE_NO_MORE_EP 4
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /* report record IDs */
77*4882a593Smuzhiyun #define HTC_RECORD_NULL 0
78*4882a593Smuzhiyun #define HTC_RECORD_CREDITS 1
79*4882a593Smuzhiyun #define HTC_RECORD_LOOKAHEAD 2
80*4882a593Smuzhiyun #define HTC_RECORD_LOOKAHEAD_BUNDLE 3
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun #define HTC_SETUP_COMP_FLG_RX_BNDL_EN (1 << 0)
83*4882a593Smuzhiyun #define HTC_SETUP_COMP_FLG_DISABLE_TX_CREDIT_FLOW (1 << 1)
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun #define MAKE_SERVICE_ID(group, index) \
86*4882a593Smuzhiyun (int)(((int)group << 8) | (int)(index))
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /* NOTE: service ID of 0x0000 is reserved and should never be used */
89*4882a593Smuzhiyun #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
90*4882a593Smuzhiyun #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
91*4882a593Smuzhiyun #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
92*4882a593Smuzhiyun #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
93*4882a593Smuzhiyun #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
94*4882a593Smuzhiyun #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
95*4882a593Smuzhiyun #define WMI_MAX_SERVICES 5
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #define WMM_NUM_AC 4
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /* reserved and used to flush ALL packets */
100*4882a593Smuzhiyun #define HTC_TX_PACKET_TAG_ALL 0
101*4882a593Smuzhiyun #define HTC_SERVICE_TX_PACKET_TAG 1
102*4882a593Smuzhiyun #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_SERVICE_TX_PACKET_TAG + 9)
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun /* more packets on this endpoint are being fetched */
105*4882a593Smuzhiyun #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /* TODO.. for BMI */
108*4882a593Smuzhiyun #define ENDPOINT1 0
109*4882a593Smuzhiyun /* TODO -remove me, but we have to fix BMI first */
110*4882a593Smuzhiyun #define HTC_MAILBOX_NUM_MAX 4
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun /* enable send bundle padding for this endpoint */
113*4882a593Smuzhiyun #define HTC_FLGS_TX_BNDL_PAD_EN (1 << 0)
114*4882a593Smuzhiyun #define HTC_EP_ACTIVE ((u32) (1u << 31))
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /* HTC operational parameters */
117*4882a593Smuzhiyun #define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
118*4882a593Smuzhiyun #define HTC_TARGET_RESPONSE_POLL_WAIT 10
119*4882a593Smuzhiyun #define HTC_TARGET_RESPONSE_POLL_COUNT 200
120*4882a593Smuzhiyun #define HTC_TARGET_DEBUG_INTR_MASK 0x01
121*4882a593Smuzhiyun #define HTC_TARGET_CREDIT_INTR_MASK 0xF0
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun #define HTC_HOST_MAX_MSG_PER_BUNDLE 8
124*4882a593Smuzhiyun #define HTC_MIN_HTC_MSGS_TO_BUNDLE 2
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* packet flags */
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define HTC_RX_PKT_IGNORE_LOOKAHEAD (1 << 0)
129*4882a593Smuzhiyun #define HTC_RX_PKT_REFRESH_HDR (1 << 1)
130*4882a593Smuzhiyun #define HTC_RX_PKT_PART_OF_BUNDLE (1 << 2)
131*4882a593Smuzhiyun #define HTC_RX_PKT_NO_RECYCLE (1 << 3)
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun #define NUM_CONTROL_BUFFERS 8
134*4882a593Smuzhiyun #define NUM_CONTROL_TX_BUFFERS 2
135*4882a593Smuzhiyun #define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun #define HTC_RECV_WAIT_BUFFERS (1 << 0)
138*4882a593Smuzhiyun #define HTC_OP_STATE_STOPPING (1 << 0)
139*4882a593Smuzhiyun #define HTC_OP_STATE_SETUP_COMPLETE (1 << 1)
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun /*
142*4882a593Smuzhiyun * The frame header length and message formats defined herein were selected
143*4882a593Smuzhiyun * to accommodate optimal alignment for target processing. This reduces
144*4882a593Smuzhiyun * code size and improves performance. Any changes to the header length may
145*4882a593Smuzhiyun * alter the alignment and cause exceptions on the target. When adding to
146*4882a593Smuzhiyun * the messagestructures insure that fields are properly aligned.
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun /* HTC frame header
150*4882a593Smuzhiyun *
151*4882a593Smuzhiyun * NOTE: do not remove or re-arrange the fields, these are minimally
152*4882a593Smuzhiyun * required to take advantage of 4-byte lookaheads in some hardware
153*4882a593Smuzhiyun * implementations.
154*4882a593Smuzhiyun */
155*4882a593Smuzhiyun struct htc_frame_hdr {
156*4882a593Smuzhiyun u8 eid;
157*4882a593Smuzhiyun u8 flags;
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /* length of data (including trailer) that follows the header */
160*4882a593Smuzhiyun __le16 payld_len;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /* end of 4-byte lookahead */
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun u8 ctrl[2];
165*4882a593Smuzhiyun } __packed;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* HTC ready message */
168*4882a593Smuzhiyun struct htc_ready_msg {
169*4882a593Smuzhiyun __le16 msg_id;
170*4882a593Smuzhiyun __le16 cred_cnt;
171*4882a593Smuzhiyun __le16 cred_sz;
172*4882a593Smuzhiyun u8 max_ep;
173*4882a593Smuzhiyun u8 pad;
174*4882a593Smuzhiyun } __packed;
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun /* extended HTC ready message */
177*4882a593Smuzhiyun struct htc_ready_ext_msg {
178*4882a593Smuzhiyun struct htc_ready_msg ver2_0_info;
179*4882a593Smuzhiyun u8 htc_ver;
180*4882a593Smuzhiyun u8 msg_per_htc_bndl;
181*4882a593Smuzhiyun } __packed;
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun /* connect service */
184*4882a593Smuzhiyun struct htc_conn_service_msg {
185*4882a593Smuzhiyun __le16 msg_id;
186*4882a593Smuzhiyun __le16 svc_id;
187*4882a593Smuzhiyun __le16 conn_flags;
188*4882a593Smuzhiyun u8 svc_meta_len;
189*4882a593Smuzhiyun u8 pad;
190*4882a593Smuzhiyun } __packed;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* connect response */
193*4882a593Smuzhiyun struct htc_conn_service_resp {
194*4882a593Smuzhiyun __le16 msg_id;
195*4882a593Smuzhiyun __le16 svc_id;
196*4882a593Smuzhiyun u8 status;
197*4882a593Smuzhiyun u8 eid;
198*4882a593Smuzhiyun __le16 max_msg_sz;
199*4882a593Smuzhiyun u8 svc_meta_len;
200*4882a593Smuzhiyun u8 pad;
201*4882a593Smuzhiyun } __packed;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun struct htc_setup_comp_msg {
204*4882a593Smuzhiyun __le16 msg_id;
205*4882a593Smuzhiyun } __packed;
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /* extended setup completion message */
208*4882a593Smuzhiyun struct htc_setup_comp_ext_msg {
209*4882a593Smuzhiyun __le16 msg_id;
210*4882a593Smuzhiyun __le32 flags;
211*4882a593Smuzhiyun u8 msg_per_rxbndl;
212*4882a593Smuzhiyun u8 Rsvd[3];
213*4882a593Smuzhiyun } __packed;
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun struct htc_record_hdr {
216*4882a593Smuzhiyun u8 rec_id;
217*4882a593Smuzhiyun u8 len;
218*4882a593Smuzhiyun } __packed;
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun struct htc_credit_report {
221*4882a593Smuzhiyun u8 eid;
222*4882a593Smuzhiyun u8 credits;
223*4882a593Smuzhiyun } __packed;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /*
226*4882a593Smuzhiyun * NOTE: The lk_ahd array is guarded by a pre_valid
227*4882a593Smuzhiyun * and Post Valid guard bytes. The pre_valid bytes must
228*4882a593Smuzhiyun * equal the inverse of the post_valid byte.
229*4882a593Smuzhiyun */
230*4882a593Smuzhiyun struct htc_lookahead_report {
231*4882a593Smuzhiyun u8 pre_valid;
232*4882a593Smuzhiyun u8 lk_ahd[4];
233*4882a593Smuzhiyun u8 post_valid;
234*4882a593Smuzhiyun } __packed;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun struct htc_bundle_lkahd_rpt {
237*4882a593Smuzhiyun u8 lk_ahd[4];
238*4882a593Smuzhiyun } __packed;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /* Current service IDs */
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun enum htc_service_grp_ids {
243*4882a593Smuzhiyun RSVD_SERVICE_GROUP = 0,
244*4882a593Smuzhiyun WMI_SERVICE_GROUP = 1,
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun HTC_TEST_GROUP = 254,
247*4882a593Smuzhiyun HTC_SERVICE_GROUP_LAST = 255
248*4882a593Smuzhiyun };
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun /* ------ endpoint IDS ------ */
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun enum htc_endpoint_id {
253*4882a593Smuzhiyun ENDPOINT_UNUSED = -1,
254*4882a593Smuzhiyun ENDPOINT_0 = 0,
255*4882a593Smuzhiyun ENDPOINT_1 = 1,
256*4882a593Smuzhiyun ENDPOINT_2 = 2,
257*4882a593Smuzhiyun ENDPOINT_3,
258*4882a593Smuzhiyun ENDPOINT_4,
259*4882a593Smuzhiyun ENDPOINT_5,
260*4882a593Smuzhiyun ENDPOINT_6,
261*4882a593Smuzhiyun ENDPOINT_7,
262*4882a593Smuzhiyun ENDPOINT_8,
263*4882a593Smuzhiyun ENDPOINT_MAX,
264*4882a593Smuzhiyun };
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun struct htc_tx_packet_info {
267*4882a593Smuzhiyun u16 tag;
268*4882a593Smuzhiyun int cred_used;
269*4882a593Smuzhiyun u8 flags;
270*4882a593Smuzhiyun int seqno;
271*4882a593Smuzhiyun };
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun struct htc_rx_packet_info {
274*4882a593Smuzhiyun u32 exp_hdr;
275*4882a593Smuzhiyun u32 rx_flags;
276*4882a593Smuzhiyun u32 indicat_flags;
277*4882a593Smuzhiyun };
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun struct htc_target;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* wrapper around endpoint-specific packets */
282*4882a593Smuzhiyun struct htc_packet {
283*4882a593Smuzhiyun struct list_head list;
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /* caller's per packet specific context */
286*4882a593Smuzhiyun void *pkt_cntxt;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /*
289*4882a593Smuzhiyun * the true buffer start , the caller can store the real
290*4882a593Smuzhiyun * buffer start here. In receive callbacks, the HTC layer
291*4882a593Smuzhiyun * sets buf to the start of the payload past the header.
292*4882a593Smuzhiyun * This field allows the caller to reset buf when it recycles
293*4882a593Smuzhiyun * receive packets back to HTC.
294*4882a593Smuzhiyun */
295*4882a593Smuzhiyun u8 *buf_start;
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun /*
298*4882a593Smuzhiyun * Pointer to the start of the buffer. In the transmit
299*4882a593Smuzhiyun * direction this points to the start of the payload. In the
300*4882a593Smuzhiyun * receive direction, however, the buffer when queued up
301*4882a593Smuzhiyun * points to the start of the HTC header but when returned
302*4882a593Smuzhiyun * to the caller points to the start of the payload
303*4882a593Smuzhiyun */
304*4882a593Smuzhiyun u8 *buf;
305*4882a593Smuzhiyun u32 buf_len;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /* actual length of payload */
308*4882a593Smuzhiyun u32 act_len;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun /* endpoint that this packet was sent/recv'd from */
311*4882a593Smuzhiyun enum htc_endpoint_id endpoint;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /* completion status */
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun int status;
316*4882a593Smuzhiyun union {
317*4882a593Smuzhiyun struct htc_tx_packet_info tx;
318*4882a593Smuzhiyun struct htc_rx_packet_info rx;
319*4882a593Smuzhiyun } info;
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun void (*completion) (struct htc_target *, struct htc_packet *);
322*4882a593Smuzhiyun struct htc_target *context;
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /*
325*4882a593Smuzhiyun * optimization for network-oriented data, the HTC packet
326*4882a593Smuzhiyun * can pass the network buffer corresponding to the HTC packet
327*4882a593Smuzhiyun * lower layers may optimized the transfer knowing this is
328*4882a593Smuzhiyun * a network buffer
329*4882a593Smuzhiyun */
330*4882a593Smuzhiyun struct sk_buff *skb;
331*4882a593Smuzhiyun };
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun enum htc_send_full_action {
334*4882a593Smuzhiyun HTC_SEND_FULL_KEEP = 0,
335*4882a593Smuzhiyun HTC_SEND_FULL_DROP = 1,
336*4882a593Smuzhiyun };
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun struct htc_ep_callbacks {
339*4882a593Smuzhiyun void (*tx_complete) (struct htc_target *, struct htc_packet *);
340*4882a593Smuzhiyun void (*rx) (struct htc_target *, struct htc_packet *);
341*4882a593Smuzhiyun void (*rx_refill) (struct htc_target *, enum htc_endpoint_id endpoint);
342*4882a593Smuzhiyun enum htc_send_full_action (*tx_full) (struct htc_target *,
343*4882a593Smuzhiyun struct htc_packet *);
344*4882a593Smuzhiyun struct htc_packet *(*rx_allocthresh) (struct htc_target *,
345*4882a593Smuzhiyun enum htc_endpoint_id, int);
346*4882a593Smuzhiyun void (*tx_comp_multi) (struct htc_target *, struct list_head *);
347*4882a593Smuzhiyun int rx_alloc_thresh;
348*4882a593Smuzhiyun int rx_refill_thresh;
349*4882a593Smuzhiyun };
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun /* service connection information */
352*4882a593Smuzhiyun struct htc_service_connect_req {
353*4882a593Smuzhiyun u16 svc_id;
354*4882a593Smuzhiyun u16 conn_flags;
355*4882a593Smuzhiyun struct htc_ep_callbacks ep_cb;
356*4882a593Smuzhiyun int max_txq_depth;
357*4882a593Smuzhiyun u32 flags;
358*4882a593Smuzhiyun unsigned int max_rxmsg_sz;
359*4882a593Smuzhiyun };
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun /* service connection response information */
362*4882a593Smuzhiyun struct htc_service_connect_resp {
363*4882a593Smuzhiyun u8 buf_len;
364*4882a593Smuzhiyun u8 act_len;
365*4882a593Smuzhiyun enum htc_endpoint_id endpoint;
366*4882a593Smuzhiyun unsigned int len_max;
367*4882a593Smuzhiyun u8 resp_code;
368*4882a593Smuzhiyun };
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun /* endpoint distributionstructure */
371*4882a593Smuzhiyun struct htc_endpoint_credit_dist {
372*4882a593Smuzhiyun struct list_head list;
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun /* Service ID (set by HTC) */
375*4882a593Smuzhiyun u16 svc_id;
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun /* endpoint for this distributionstruct (set by HTC) */
378*4882a593Smuzhiyun enum htc_endpoint_id endpoint;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun u32 dist_flags;
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun /*
383*4882a593Smuzhiyun * credits for normal operation, anything above this
384*4882a593Smuzhiyun * indicates the endpoint is over-subscribed.
385*4882a593Smuzhiyun */
386*4882a593Smuzhiyun int cred_norm;
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun /* floor for credit distribution */
389*4882a593Smuzhiyun int cred_min;
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun int cred_assngd;
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /* current credits available */
394*4882a593Smuzhiyun int credits;
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun /*
397*4882a593Smuzhiyun * pending credits to distribute on this endpoint, this
398*4882a593Smuzhiyun * is set by HTC when credit reports arrive. The credit
399*4882a593Smuzhiyun * distribution functions sets this to zero when it distributes
400*4882a593Smuzhiyun * the credits.
401*4882a593Smuzhiyun */
402*4882a593Smuzhiyun int cred_to_dist;
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun /*
405*4882a593Smuzhiyun * the number of credits that the current pending TX packet needs
406*4882a593Smuzhiyun * to transmit. This is set by HTC when endpoint needs credits in
407*4882a593Smuzhiyun * order to transmit.
408*4882a593Smuzhiyun */
409*4882a593Smuzhiyun int seek_cred;
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun /* size in bytes of each credit */
412*4882a593Smuzhiyun int cred_sz;
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /* credits required for a maximum sized messages */
415*4882a593Smuzhiyun int cred_per_msg;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun /* reserved for HTC use */
418*4882a593Smuzhiyun struct htc_endpoint *htc_ep;
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun /*
421*4882a593Smuzhiyun * current depth of TX queue , i.e. messages waiting for credits
422*4882a593Smuzhiyun * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
423*4882a593Smuzhiyun * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
424*4882a593Smuzhiyun * that has non-zero credits to recover.
425*4882a593Smuzhiyun */
426*4882a593Smuzhiyun int txq_depth;
427*4882a593Smuzhiyun };
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun /*
430*4882a593Smuzhiyun * credit distribution code that is passed into the distribution function,
431*4882a593Smuzhiyun * there are mandatory and optional codes that must be handled
432*4882a593Smuzhiyun */
433*4882a593Smuzhiyun enum htc_credit_dist_reason {
434*4882a593Smuzhiyun HTC_CREDIT_DIST_SEND_COMPLETE = 0,
435*4882a593Smuzhiyun HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
436*4882a593Smuzhiyun HTC_CREDIT_DIST_SEEK_CREDITS,
437*4882a593Smuzhiyun };
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun struct ath6kl_htc_credit_info {
440*4882a593Smuzhiyun int total_avail_credits;
441*4882a593Smuzhiyun int cur_free_credits;
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun /* list of lowest priority endpoints */
444*4882a593Smuzhiyun struct list_head lowestpri_ep_dist;
445*4882a593Smuzhiyun };
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun /* endpoint statistics */
448*4882a593Smuzhiyun struct htc_endpoint_stats {
449*4882a593Smuzhiyun /*
450*4882a593Smuzhiyun * number of times the host set the credit-low flag in a send
451*4882a593Smuzhiyun * message on this endpoint
452*4882a593Smuzhiyun */
453*4882a593Smuzhiyun u32 cred_low_indicate;
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun u32 tx_issued;
456*4882a593Smuzhiyun u32 tx_pkt_bundled;
457*4882a593Smuzhiyun u32 tx_bundles;
458*4882a593Smuzhiyun u32 tx_dropped;
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun /* running count of total credit reports received for this endpoint */
461*4882a593Smuzhiyun u32 tx_cred_rpt;
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun /* credit reports received from this endpoint's RX packets */
464*4882a593Smuzhiyun u32 cred_rpt_from_rx;
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun /* credit reports received from RX packets of other endpoints */
467*4882a593Smuzhiyun u32 cred_rpt_from_other;
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun /* credit reports received from endpoint 0 RX packets */
470*4882a593Smuzhiyun u32 cred_rpt_ep0;
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun /* count of credits received via Rx packets on this endpoint */
473*4882a593Smuzhiyun u32 cred_from_rx;
474*4882a593Smuzhiyun
475*4882a593Smuzhiyun /* count of credits received via another endpoint */
476*4882a593Smuzhiyun u32 cred_from_other;
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun /* count of credits received via another endpoint */
479*4882a593Smuzhiyun u32 cred_from_ep0;
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun /* count of consummed credits */
482*4882a593Smuzhiyun u32 cred_cosumd;
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun /* count of credits returned */
485*4882a593Smuzhiyun u32 cred_retnd;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun u32 rx_pkts;
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun /* count of lookahead records found in Rx msg */
490*4882a593Smuzhiyun u32 rx_lkahds;
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun /* count of recv packets received in a bundle */
493*4882a593Smuzhiyun u32 rx_bundl;
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun /* count of number of bundled lookaheads */
496*4882a593Smuzhiyun u32 rx_bundle_lkahd;
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun /* count of the number of bundle indications from the HTC header */
499*4882a593Smuzhiyun u32 rx_bundle_from_hdr;
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun /* the number of times the recv allocation threshold was hit */
502*4882a593Smuzhiyun u32 rx_alloc_thresh_hit;
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun /* total number of bytes */
505*4882a593Smuzhiyun u32 rxalloc_thresh_byte;
506*4882a593Smuzhiyun };
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun struct htc_endpoint {
509*4882a593Smuzhiyun enum htc_endpoint_id eid;
510*4882a593Smuzhiyun u16 svc_id;
511*4882a593Smuzhiyun struct list_head txq;
512*4882a593Smuzhiyun struct list_head rx_bufq;
513*4882a593Smuzhiyun struct htc_endpoint_credit_dist cred_dist;
514*4882a593Smuzhiyun struct htc_ep_callbacks ep_cb;
515*4882a593Smuzhiyun int max_txq_depth;
516*4882a593Smuzhiyun int len_max;
517*4882a593Smuzhiyun int tx_proc_cnt;
518*4882a593Smuzhiyun int rx_proc_cnt;
519*4882a593Smuzhiyun struct htc_target *target;
520*4882a593Smuzhiyun u8 seqno;
521*4882a593Smuzhiyun u32 conn_flags;
522*4882a593Smuzhiyun struct htc_endpoint_stats ep_st;
523*4882a593Smuzhiyun u16 tx_drop_packet_threshold;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun struct {
526*4882a593Smuzhiyun u8 pipeid_ul;
527*4882a593Smuzhiyun u8 pipeid_dl;
528*4882a593Smuzhiyun struct list_head tx_lookup_queue;
529*4882a593Smuzhiyun bool tx_credit_flow_enabled;
530*4882a593Smuzhiyun } pipe;
531*4882a593Smuzhiyun };
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun struct htc_control_buffer {
534*4882a593Smuzhiyun struct htc_packet packet;
535*4882a593Smuzhiyun u8 *buf;
536*4882a593Smuzhiyun };
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun struct htc_pipe_txcredit_alloc {
539*4882a593Smuzhiyun u16 service_id;
540*4882a593Smuzhiyun u8 credit_alloc;
541*4882a593Smuzhiyun };
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun enum htc_send_queue_result {
544*4882a593Smuzhiyun HTC_SEND_QUEUE_OK = 0, /* packet was queued */
545*4882a593Smuzhiyun HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */
546*4882a593Smuzhiyun };
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun struct ath6kl_htc_ops {
549*4882a593Smuzhiyun void* (*create)(struct ath6kl *ar);
550*4882a593Smuzhiyun int (*wait_target)(struct htc_target *target);
551*4882a593Smuzhiyun int (*start)(struct htc_target *target);
552*4882a593Smuzhiyun int (*conn_service)(struct htc_target *target,
553*4882a593Smuzhiyun struct htc_service_connect_req *req,
554*4882a593Smuzhiyun struct htc_service_connect_resp *resp);
555*4882a593Smuzhiyun int (*tx)(struct htc_target *target, struct htc_packet *packet);
556*4882a593Smuzhiyun void (*stop)(struct htc_target *target);
557*4882a593Smuzhiyun void (*cleanup)(struct htc_target *target);
558*4882a593Smuzhiyun void (*flush_txep)(struct htc_target *target,
559*4882a593Smuzhiyun enum htc_endpoint_id endpoint, u16 tag);
560*4882a593Smuzhiyun void (*flush_rx_buf)(struct htc_target *target);
561*4882a593Smuzhiyun void (*activity_changed)(struct htc_target *target,
562*4882a593Smuzhiyun enum htc_endpoint_id endpoint,
563*4882a593Smuzhiyun bool active);
564*4882a593Smuzhiyun int (*get_rxbuf_num)(struct htc_target *target,
565*4882a593Smuzhiyun enum htc_endpoint_id endpoint);
566*4882a593Smuzhiyun int (*add_rxbuf_multiple)(struct htc_target *target,
567*4882a593Smuzhiyun struct list_head *pktq);
568*4882a593Smuzhiyun int (*credit_setup)(struct htc_target *target,
569*4882a593Smuzhiyun struct ath6kl_htc_credit_info *cred_info);
570*4882a593Smuzhiyun int (*tx_complete)(struct ath6kl *ar, struct sk_buff *skb);
571*4882a593Smuzhiyun int (*rx_complete)(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
572*4882a593Smuzhiyun };
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun struct ath6kl_device;
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun /* our HTC target state */
577*4882a593Smuzhiyun struct htc_target {
578*4882a593Smuzhiyun struct htc_endpoint endpoint[ENDPOINT_MAX];
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun /* contains struct htc_endpoint_credit_dist */
581*4882a593Smuzhiyun struct list_head cred_dist_list;
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun struct list_head free_ctrl_txbuf;
584*4882a593Smuzhiyun struct list_head free_ctrl_rxbuf;
585*4882a593Smuzhiyun struct ath6kl_htc_credit_info *credit_info;
586*4882a593Smuzhiyun int tgt_creds;
587*4882a593Smuzhiyun unsigned int tgt_cred_sz;
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun /* protects free_ctrl_txbuf and free_ctrl_rxbuf */
590*4882a593Smuzhiyun spinlock_t htc_lock;
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun /* FIXME: does this protext rx_bufq and endpoint structures or what? */
593*4882a593Smuzhiyun spinlock_t rx_lock;
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /* protects endpoint->txq */
596*4882a593Smuzhiyun spinlock_t tx_lock;
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun struct ath6kl_device *dev;
599*4882a593Smuzhiyun u32 htc_flags;
600*4882a593Smuzhiyun u32 rx_st_flags;
601*4882a593Smuzhiyun enum htc_endpoint_id ep_waiting;
602*4882a593Smuzhiyun u8 htc_tgt_ver;
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun /* max messages per bundle for HTC */
605*4882a593Smuzhiyun int msg_per_bndl_max;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun u32 tx_bndl_mask;
608*4882a593Smuzhiyun int rx_bndl_enable;
609*4882a593Smuzhiyun int max_rx_bndl_sz;
610*4882a593Smuzhiyun int max_tx_bndl_sz;
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun u32 block_sz;
613*4882a593Smuzhiyun u32 block_mask;
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun int max_scat_entries;
616*4882a593Smuzhiyun int max_xfer_szper_scatreq;
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun int chk_irq_status_cnt;
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /* counts the number of Tx without bundling continously per AC */
621*4882a593Smuzhiyun u32 ac_tx_count[WMM_NUM_AC];
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun struct {
624*4882a593Smuzhiyun struct htc_packet *htc_packet_pool;
625*4882a593Smuzhiyun u8 ctrl_response_buf[HTC_MAX_CTRL_MSG_LEN];
626*4882a593Smuzhiyun int ctrl_response_len;
627*4882a593Smuzhiyun bool ctrl_response_valid;
628*4882a593Smuzhiyun struct htc_pipe_txcredit_alloc txcredit_alloc[ENDPOINT_MAX];
629*4882a593Smuzhiyun } pipe;
630*4882a593Smuzhiyun };
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
633*4882a593Smuzhiyun u32 msg_look_ahead, int *n_pkts);
634*4882a593Smuzhiyun
set_htc_pkt_info(struct htc_packet * packet,void * context,u8 * buf,unsigned int len,enum htc_endpoint_id eid,u16 tag)635*4882a593Smuzhiyun static inline void set_htc_pkt_info(struct htc_packet *packet, void *context,
636*4882a593Smuzhiyun u8 *buf, unsigned int len,
637*4882a593Smuzhiyun enum htc_endpoint_id eid, u16 tag)
638*4882a593Smuzhiyun {
639*4882a593Smuzhiyun packet->pkt_cntxt = context;
640*4882a593Smuzhiyun packet->buf = buf;
641*4882a593Smuzhiyun packet->act_len = len;
642*4882a593Smuzhiyun packet->endpoint = eid;
643*4882a593Smuzhiyun packet->info.tx.tag = tag;
644*4882a593Smuzhiyun }
645*4882a593Smuzhiyun
htc_rxpkt_reset(struct htc_packet * packet)646*4882a593Smuzhiyun static inline void htc_rxpkt_reset(struct htc_packet *packet)
647*4882a593Smuzhiyun {
648*4882a593Smuzhiyun packet->buf = packet->buf_start;
649*4882a593Smuzhiyun packet->act_len = 0;
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun
set_htc_rxpkt_info(struct htc_packet * packet,void * context,u8 * buf,unsigned long len,enum htc_endpoint_id eid)652*4882a593Smuzhiyun static inline void set_htc_rxpkt_info(struct htc_packet *packet, void *context,
653*4882a593Smuzhiyun u8 *buf, unsigned long len,
654*4882a593Smuzhiyun enum htc_endpoint_id eid)
655*4882a593Smuzhiyun {
656*4882a593Smuzhiyun packet->pkt_cntxt = context;
657*4882a593Smuzhiyun packet->buf = buf;
658*4882a593Smuzhiyun packet->buf_start = buf;
659*4882a593Smuzhiyun packet->buf_len = len;
660*4882a593Smuzhiyun packet->endpoint = eid;
661*4882a593Smuzhiyun }
662*4882a593Smuzhiyun
get_queue_depth(struct list_head * queue)663*4882a593Smuzhiyun static inline int get_queue_depth(struct list_head *queue)
664*4882a593Smuzhiyun {
665*4882a593Smuzhiyun struct list_head *tmp_list;
666*4882a593Smuzhiyun int depth = 0;
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun list_for_each(tmp_list, queue)
669*4882a593Smuzhiyun depth++;
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun return depth;
672*4882a593Smuzhiyun }
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun void ath6kl_htc_pipe_attach(struct ath6kl *ar);
675*4882a593Smuzhiyun void ath6kl_htc_mbox_attach(struct ath6kl *ar);
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun #endif
678