1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef HTC_H
19#define HTC_H
20
21#include "common.h"
22
23
24
25
26#define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
27#define HTC_FLAGS_SEND_BUNDLE (1 << 1)
28#define HTC_FLAGS_TX_FIXUP_NETBUF (1 << 2)
29
30
31#define HTC_FLG_RX_UNUSED (1 << 0)
32#define HTC_FLG_RX_TRAILER (1 << 1)
33
34#define HTC_FLG_RX_BNDL_CNT (0xF0)
35#define HTC_FLG_RX_BNDL_CNT_S 4
36
37#define HTC_HDR_LENGTH (sizeof(struct htc_frame_hdr))
38#define HTC_MAX_PAYLOAD_LENGTH (4096 - sizeof(struct htc_frame_hdr))
39
40
41
42#define HTC_MSG_READY_ID 1
43#define HTC_MSG_CONN_SVC_ID 2
44#define HTC_MSG_CONN_SVC_RESP_ID 3
45#define HTC_MSG_SETUP_COMPLETE_ID 4
46#define HTC_MSG_SETUP_COMPLETE_EX_ID 5
47
48#define HTC_MAX_CTRL_MSG_LEN 256
49
50#define HTC_VERSION_2P0 0x00
51#define HTC_VERSION_2P1 0x01
52
53#define HTC_SERVICE_META_DATA_MAX_LENGTH 128
54
55#define HTC_CONN_FLGS_THRESH_LVL_QUAT 0x0
56#define HTC_CONN_FLGS_THRESH_LVL_HALF 0x1
57#define HTC_CONN_FLGS_THRESH_LVL_THREE_QUAT 0x2
58#define HTC_CONN_FLGS_REDUCE_CRED_DRIB 0x4
59#define HTC_CONN_FLGS_THRESH_MASK 0x3
60
61#define HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL (1 << 3)
62#define HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT 8
63#define HTC_CONN_FLGS_SET_RECV_ALLOC_MASK 0xFF00U
64
65
66#define HTC_SERVICE_SUCCESS 0
67#define HTC_SERVICE_NOT_FOUND 1
68#define HTC_SERVICE_FAILED 2
69
70
71#define HTC_SERVICE_NO_RESOURCES 3
72
73
74#define HTC_SERVICE_NO_MORE_EP 4
75
76
77#define HTC_RECORD_NULL 0
78#define HTC_RECORD_CREDITS 1
79#define HTC_RECORD_LOOKAHEAD 2
80#define HTC_RECORD_LOOKAHEAD_BUNDLE 3
81
82#define HTC_SETUP_COMP_FLG_RX_BNDL_EN (1 << 0)
83#define HTC_SETUP_COMP_FLG_DISABLE_TX_CREDIT_FLOW (1 << 1)
84
85#define MAKE_SERVICE_ID(group, index) \
86 (int)(((int)group << 8) | (int)(index))
87
88
89#define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
90#define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
91#define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
92#define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
93#define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
94#define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
95#define WMI_MAX_SERVICES 5
96
97#define WMM_NUM_AC 4
98
99
100#define HTC_TX_PACKET_TAG_ALL 0
101#define HTC_SERVICE_TX_PACKET_TAG 1
102#define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_SERVICE_TX_PACKET_TAG + 9)
103
104
105#define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
106
107
108#define ENDPOINT1 0
109
110#define HTC_MAILBOX_NUM_MAX 4
111
112
113#define HTC_FLGS_TX_BNDL_PAD_EN (1 << 0)
114#define HTC_EP_ACTIVE ((u32) (1u << 31))
115
116
117#define HTC_TARGET_RESPONSE_TIMEOUT 2000
118#define HTC_TARGET_RESPONSE_POLL_WAIT 10
119#define HTC_TARGET_RESPONSE_POLL_COUNT 200
120#define HTC_TARGET_DEBUG_INTR_MASK 0x01
121#define HTC_TARGET_CREDIT_INTR_MASK 0xF0
122
123#define HTC_HOST_MAX_MSG_PER_BUNDLE 8
124#define HTC_MIN_HTC_MSGS_TO_BUNDLE 2
125
126
127
128#define HTC_RX_PKT_IGNORE_LOOKAHEAD (1 << 0)
129#define HTC_RX_PKT_REFRESH_HDR (1 << 1)
130#define HTC_RX_PKT_PART_OF_BUNDLE (1 << 2)
131#define HTC_RX_PKT_NO_RECYCLE (1 << 3)
132
133#define NUM_CONTROL_BUFFERS 8
134#define NUM_CONTROL_TX_BUFFERS 2
135#define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)
136
137#define HTC_RECV_WAIT_BUFFERS (1 << 0)
138#define HTC_OP_STATE_STOPPING (1 << 0)
139#define HTC_OP_STATE_SETUP_COMPLETE (1 << 1)
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155struct htc_frame_hdr {
156 u8 eid;
157 u8 flags;
158
159
160 __le16 payld_len;
161
162
163
164 u8 ctrl[2];
165} __packed;
166
167
168struct htc_ready_msg {
169 __le16 msg_id;
170 __le16 cred_cnt;
171 __le16 cred_sz;
172 u8 max_ep;
173 u8 pad;
174} __packed;
175
176
177struct htc_ready_ext_msg {
178 struct htc_ready_msg ver2_0_info;
179 u8 htc_ver;
180 u8 msg_per_htc_bndl;
181} __packed;
182
183
184struct htc_conn_service_msg {
185 __le16 msg_id;
186 __le16 svc_id;
187 __le16 conn_flags;
188 u8 svc_meta_len;
189 u8 pad;
190} __packed;
191
192
193struct htc_conn_service_resp {
194 __le16 msg_id;
195 __le16 svc_id;
196 u8 status;
197 u8 eid;
198 __le16 max_msg_sz;
199 u8 svc_meta_len;
200 u8 pad;
201} __packed;
202
203struct htc_setup_comp_msg {
204 __le16 msg_id;
205} __packed;
206
207
208struct htc_setup_comp_ext_msg {
209 __le16 msg_id;
210 __le32 flags;
211 u8 msg_per_rxbndl;
212 u8 Rsvd[3];
213} __packed;
214
215struct htc_record_hdr {
216 u8 rec_id;
217 u8 len;
218} __packed;
219
220struct htc_credit_report {
221 u8 eid;
222 u8 credits;
223} __packed;
224
225
226
227
228
229
230struct htc_lookahead_report {
231 u8 pre_valid;
232 u8 lk_ahd[4];
233 u8 post_valid;
234} __packed;
235
236struct htc_bundle_lkahd_rpt {
237 u8 lk_ahd[4];
238} __packed;
239
240
241
242enum htc_service_grp_ids {
243 RSVD_SERVICE_GROUP = 0,
244 WMI_SERVICE_GROUP = 1,
245
246 HTC_TEST_GROUP = 254,
247 HTC_SERVICE_GROUP_LAST = 255
248};
249
250
251
252enum htc_endpoint_id {
253 ENDPOINT_UNUSED = -1,
254 ENDPOINT_0 = 0,
255 ENDPOINT_1 = 1,
256 ENDPOINT_2 = 2,
257 ENDPOINT_3,
258 ENDPOINT_4,
259 ENDPOINT_5,
260 ENDPOINT_6,
261 ENDPOINT_7,
262 ENDPOINT_8,
263 ENDPOINT_MAX,
264};
265
266struct htc_tx_packet_info {
267 u16 tag;
268 int cred_used;
269 u8 flags;
270 int seqno;
271};
272
273struct htc_rx_packet_info {
274 u32 exp_hdr;
275 u32 rx_flags;
276 u32 indicat_flags;
277};
278
279struct htc_target;
280
281
282struct htc_packet {
283 struct list_head list;
284
285
286 void *pkt_cntxt;
287
288
289
290
291
292
293
294
295 u8 *buf_start;
296
297
298
299
300
301
302
303
304 u8 *buf;
305 u32 buf_len;
306
307
308 u32 act_len;
309
310
311 enum htc_endpoint_id endpoint;
312
313
314
315 int status;
316 union {
317 struct htc_tx_packet_info tx;
318 struct htc_rx_packet_info rx;
319 } info;
320
321 void (*completion) (struct htc_target *, struct htc_packet *);
322 struct htc_target *context;
323
324
325
326
327
328
329
330 struct sk_buff *skb;
331};
332
333enum htc_send_full_action {
334 HTC_SEND_FULL_KEEP = 0,
335 HTC_SEND_FULL_DROP = 1,
336};
337
338struct htc_ep_callbacks {
339 void (*tx_complete) (struct htc_target *, struct htc_packet *);
340 void (*rx) (struct htc_target *, struct htc_packet *);
341 void (*rx_refill) (struct htc_target *, enum htc_endpoint_id endpoint);
342 enum htc_send_full_action (*tx_full) (struct htc_target *,
343 struct htc_packet *);
344 struct htc_packet *(*rx_allocthresh) (struct htc_target *,
345 enum htc_endpoint_id, int);
346 void (*tx_comp_multi) (struct htc_target *, struct list_head *);
347 int rx_alloc_thresh;
348 int rx_refill_thresh;
349};
350
351
352struct htc_service_connect_req {
353 u16 svc_id;
354 u16 conn_flags;
355 struct htc_ep_callbacks ep_cb;
356 int max_txq_depth;
357 u32 flags;
358 unsigned int max_rxmsg_sz;
359};
360
361
362struct htc_service_connect_resp {
363 u8 buf_len;
364 u8 act_len;
365 enum htc_endpoint_id endpoint;
366 unsigned int len_max;
367 u8 resp_code;
368};
369
370
371struct htc_endpoint_credit_dist {
372 struct list_head list;
373
374
375 u16 svc_id;
376
377
378 enum htc_endpoint_id endpoint;
379
380 u32 dist_flags;
381
382
383
384
385
386 int cred_norm;
387
388
389 int cred_min;
390
391 int cred_assngd;
392
393
394 int credits;
395
396
397
398
399
400
401
402 int cred_to_dist;
403
404
405
406
407
408
409 int seek_cred;
410
411
412 int cred_sz;
413
414
415 int cred_per_msg;
416
417
418 struct htc_endpoint *htc_ep;
419
420
421
422
423
424
425
426 int txq_depth;
427};
428
429
430
431
432
433enum htc_credit_dist_reason {
434 HTC_CREDIT_DIST_SEND_COMPLETE = 0,
435 HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
436 HTC_CREDIT_DIST_SEEK_CREDITS,
437};
438
439struct ath6kl_htc_credit_info {
440 int total_avail_credits;
441 int cur_free_credits;
442
443
444 struct list_head lowestpri_ep_dist;
445};
446
447
448struct htc_endpoint_stats {
449
450
451
452
453 u32 cred_low_indicate;
454
455 u32 tx_issued;
456 u32 tx_pkt_bundled;
457 u32 tx_bundles;
458 u32 tx_dropped;
459
460
461 u32 tx_cred_rpt;
462
463
464 u32 cred_rpt_from_rx;
465
466
467 u32 cred_rpt_from_other;
468
469
470 u32 cred_rpt_ep0;
471
472
473 u32 cred_from_rx;
474
475
476 u32 cred_from_other;
477
478
479 u32 cred_from_ep0;
480
481
482 u32 cred_cosumd;
483
484
485 u32 cred_retnd;
486
487 u32 rx_pkts;
488
489
490 u32 rx_lkahds;
491
492
493 u32 rx_bundl;
494
495
496 u32 rx_bundle_lkahd;
497
498
499 u32 rx_bundle_from_hdr;
500
501
502 u32 rx_alloc_thresh_hit;
503
504
505 u32 rxalloc_thresh_byte;
506};
507
508struct htc_endpoint {
509 enum htc_endpoint_id eid;
510 u16 svc_id;
511 struct list_head txq;
512 struct list_head rx_bufq;
513 struct htc_endpoint_credit_dist cred_dist;
514 struct htc_ep_callbacks ep_cb;
515 int max_txq_depth;
516 int len_max;
517 int tx_proc_cnt;
518 int rx_proc_cnt;
519 struct htc_target *target;
520 u8 seqno;
521 u32 conn_flags;
522 struct htc_endpoint_stats ep_st;
523 u16 tx_drop_packet_threshold;
524
525 struct {
526 u8 pipeid_ul;
527 u8 pipeid_dl;
528 struct list_head tx_lookup_queue;
529 bool tx_credit_flow_enabled;
530 } pipe;
531};
532
533struct htc_control_buffer {
534 struct htc_packet packet;
535 u8 *buf;
536};
537
538struct htc_pipe_txcredit_alloc {
539 u16 service_id;
540 u8 credit_alloc;
541};
542
543enum htc_send_queue_result {
544 HTC_SEND_QUEUE_OK = 0,
545 HTC_SEND_QUEUE_DROP = 1,
546};
547
548struct ath6kl_htc_ops {
549 void* (*create)(struct ath6kl *ar);
550 int (*wait_target)(struct htc_target *target);
551 int (*start)(struct htc_target *target);
552 int (*conn_service)(struct htc_target *target,
553 struct htc_service_connect_req *req,
554 struct htc_service_connect_resp *resp);
555 int (*tx)(struct htc_target *target, struct htc_packet *packet);
556 void (*stop)(struct htc_target *target);
557 void (*cleanup)(struct htc_target *target);
558 void (*flush_txep)(struct htc_target *target,
559 enum htc_endpoint_id endpoint, u16 tag);
560 void (*flush_rx_buf)(struct htc_target *target);
561 void (*activity_changed)(struct htc_target *target,
562 enum htc_endpoint_id endpoint,
563 bool active);
564 int (*get_rxbuf_num)(struct htc_target *target,
565 enum htc_endpoint_id endpoint);
566 int (*add_rxbuf_multiple)(struct htc_target *target,
567 struct list_head *pktq);
568 int (*credit_setup)(struct htc_target *target,
569 struct ath6kl_htc_credit_info *cred_info);
570 int (*tx_complete)(struct ath6kl *ar, struct sk_buff *skb);
571 int (*rx_complete)(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
572};
573
574struct ath6kl_device;
575
576
577struct htc_target {
578 struct htc_endpoint endpoint[ENDPOINT_MAX];
579
580
581 struct list_head cred_dist_list;
582
583 struct list_head free_ctrl_txbuf;
584 struct list_head free_ctrl_rxbuf;
585 struct ath6kl_htc_credit_info *credit_info;
586 int tgt_creds;
587 unsigned int tgt_cred_sz;
588
589
590 spinlock_t htc_lock;
591
592
593 spinlock_t rx_lock;
594
595
596 spinlock_t tx_lock;
597
598 struct ath6kl_device *dev;
599 u32 htc_flags;
600 u32 rx_st_flags;
601 enum htc_endpoint_id ep_waiting;
602 u8 htc_tgt_ver;
603
604
605 int msg_per_bndl_max;
606
607 u32 tx_bndl_mask;
608 int rx_bndl_enable;
609 int max_rx_bndl_sz;
610 int max_tx_bndl_sz;
611
612 u32 block_sz;
613 u32 block_mask;
614
615 int max_scat_entries;
616 int max_xfer_szper_scatreq;
617
618 int chk_irq_status_cnt;
619
620
621 u32 ac_tx_count[WMM_NUM_AC];
622
623 struct {
624 struct htc_packet *htc_packet_pool;
625 u8 ctrl_response_buf[HTC_MAX_CTRL_MSG_LEN];
626 int ctrl_response_len;
627 bool ctrl_response_valid;
628 struct htc_pipe_txcredit_alloc txcredit_alloc[ENDPOINT_MAX];
629 } pipe;
630};
631
632int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
633 u32 msg_look_ahead, int *n_pkts);
634
635static inline void set_htc_pkt_info(struct htc_packet *packet, void *context,
636 u8 *buf, unsigned int len,
637 enum htc_endpoint_id eid, u16 tag)
638{
639 packet->pkt_cntxt = context;
640 packet->buf = buf;
641 packet->act_len = len;
642 packet->endpoint = eid;
643 packet->info.tx.tag = tag;
644}
645
646static inline void htc_rxpkt_reset(struct htc_packet *packet)
647{
648 packet->buf = packet->buf_start;
649 packet->act_len = 0;
650}
651
652static inline void set_htc_rxpkt_info(struct htc_packet *packet, void *context,
653 u8 *buf, unsigned long len,
654 enum htc_endpoint_id eid)
655{
656 packet->pkt_cntxt = context;
657 packet->buf = buf;
658 packet->buf_start = buf;
659 packet->buf_len = len;
660 packet->endpoint = eid;
661}
662
663static inline int get_queue_depth(struct list_head *queue)
664{
665 struct list_head *tmp_list;
666 int depth = 0;
667
668 list_for_each(tmp_list, queue)
669 depth++;
670
671 return depth;
672}
673
674void ath6kl_htc_pipe_attach(struct ath6kl *ar);
675void ath6kl_htc_mbox_attach(struct ath6kl *ar);
676
677#endif
678