Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
htc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2011 Atheros Communications Inc.
3  * Copyright (c) 2011 Qualcomm Atheros, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef HTC_H
19 #define HTC_H
20 
21 #include "common.h"
22 
23 /* frame header flags */
24 
25 /* send direction */
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 /* receive direction */
31 #define HTC_FLG_RX_UNUSED (1 << 0)
32 #define HTC_FLG_RX_TRAILER (1 << 1)
33 /* Bundle count maske and shift */
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 /* HTC control message IDs */
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 /* disable credit flow control on a specific service */
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 0xFF00
64 
65 /* connect response status codes */
66 #define HTC_SERVICE_SUCCESS 0
67 #define HTC_SERVICE_NOT_FOUND 1
68 #define HTC_SERVICE_FAILED 2
69 
70 /* no resources (i.e. no more endpoints) */
71 #define HTC_SERVICE_NO_RESOURCES 3
72 
73 /* specific service is not allowing any more endpoints */
74 #define HTC_SERVICE_NO_MORE_EP 4
75 
76 /* report record IDs */
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 /* NOTE: service ID of 0x0000 is reserved and should never be used */
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 /* reserved and used to flush ALL packets */
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 /* more packets on this endpoint are being fetched */
105 #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
106 
107 /* TODO.. for BMI */
108 #define ENDPOINT1 0
109 /* TODO -remove me, but we have to fix BMI first */
110 #define HTC_MAILBOX_NUM_MAX 4
111 
112 /* enable send bundle padding for this endpoint */
113 #define HTC_FLGS_TX_BNDL_PAD_EN (1 << 0)
114 #define HTC_EP_ACTIVE ((u32) (1u << 31))
115 
116 /* HTC operational parameters */
117 #define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
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 /* packet flags */
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  * The frame header length and message formats defined herein were selected
143  * to accommodate optimal alignment for target processing. This reduces
144  * code size and improves performance. Any changes to the header length may
145  * alter the alignment and cause exceptions on the target. When adding to
146  * the messagestructures insure that fields are properly aligned.
147  */
148 
149 /* HTC frame header
150  *
151  * NOTE: do not remove or re-arrange the fields, these are minimally
152  * required to take advantage of 4-byte lookaheads in some hardware
153  * implementations.
154  */
158 
159  /* length of data (including trailer) that follows the header */
161 
162  /* end of 4-byte lookahead */
163 
164  u8 ctrl[2];
165 } __packed;
166 
167 /* HTC ready message */
174 } __packed;
175 
176 /* extended HTC ready message */
181 } __packed;
182 
183 /* connect service */
190 } __packed;
191 
192 /* connect response */
201 } __packed;
202 
205 } __packed;
206 
207 /* extended setup completion message */
212  u8 Rsvd[3];
213 } __packed;
214 
218 } __packed;
219 
223 } __packed;
224 
225 /*
226  * NOTE: The lk_ahd array is guarded by a pre_valid
227  * and Post Valid guard bytes. The pre_valid bytes must
228  * equal the inverse of the post_valid byte.
229  */
232  u8 lk_ahd[4];
234 } __packed;
235 
237  u8 lk_ahd[4];
238 } __packed;
239 
240 /* Current service IDs */
241 
245 
248 };
249 
250 /* ------ endpoint IDS ------ */
251 
264 };
265 
270  int seqno;
271 };
272 
277 };
278 
279 struct htc_target;
280 
281 /* wrapper around endpoint-specific packets */
282 struct htc_packet {
283  struct list_head list;
284 
285  /* caller's per packet specific context */
286  void *pkt_cntxt;
287 
288  /*
289  * the true buffer start , the caller can store the real
290  * buffer start here. In receive callbacks, the HTC layer
291  * sets buf to the start of the payload past the header.
292  * This field allows the caller to reset buf when it recycles
293  * receive packets back to HTC.
294  */
296 
297  /*
298  * Pointer to the start of the buffer. In the transmit
299  * direction this points to the start of the payload. In the
300  * receive direction, however, the buffer when queued up
301  * points to the start of the HTC header but when returned
302  * to the caller points to the start of the payload
303  */
304  u8 *buf;
306 
307  /* actual length of payload */
309 
310  /* endpoint that this packet was sent/recv'd from */
312 
313  /* completion status */
314 
315  int status;
316  union {
319  } info;
320 
321  void (*completion) (struct htc_target *, struct htc_packet *);
323 
324  /*
325  * optimization for network-oriented data, the HTC packet
326  * can pass the network buffer corresponding to the HTC packet
327  * lower layers may optimized the transfer knowing this is
328  * a network buffer
329  */
330  struct sk_buff *skb;
331 };
332 
336 };
337 
339  void (*tx_complete) (struct htc_target *, struct htc_packet *);
340  void (*rx) (struct htc_target *, struct htc_packet *);
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 *);
349 };
350 
351 /* service connection information */
358  unsigned int max_rxmsg_sz;
359 };
360 
361 /* service connection response information */
366  unsigned int len_max;
368 };
369 
370 /* endpoint distributionstructure */
372  struct list_head list;
373 
374  /* Service ID (set by HTC) */
376 
377  /* endpoint for this distributionstruct (set by HTC) */
379 
381 
382  /*
383  * credits for normal operation, anything above this
384  * indicates the endpoint is over-subscribed.
385  */
387 
388  /* floor for credit distribution */
389  int cred_min;
390 
392 
393  /* current credits available */
394  int credits;
395 
396  /*
397  * pending credits to distribute on this endpoint, this
398  * is set by HTC when credit reports arrive. The credit
399  * distribution functions sets this to zero when it distributes
400  * the credits.
401  */
403 
404  /*
405  * the number of credits that the current pending TX packet needs
406  * to transmit. This is set by HTC when endpoint needs credits in
407  * order to transmit.
408  */
410 
411  /* size in bytes of each credit */
412  int cred_sz;
413 
414  /* credits required for a maximum sized messages */
416 
417  /* reserved for HTC use */
419 
420  /*
421  * current depth of TX queue , i.e. messages waiting for credits
422  * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
423  * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
424  * that has non-zero credits to recover.
425  */
427 };
428 
429 /*
430  * credit distibution code that is passed into the distrbution function,
431  * there are mandatory and optional codes that must be handled
432  */
437 };
438 
442 
443  /* list of lowest priority endpoints */
445 };
446 
447 /* endpoint statistics */
449  /*
450  * number of times the host set the credit-low flag in a send
451  * message on this endpoint
452  */
454 
459 
460  /* running count of total credit reports received for this endpoint */
462 
463  /* credit reports received from this endpoint's RX packets */
465 
466  /* credit reports received from RX packets of other endpoints */
468 
469  /* credit reports received from endpoint 0 RX packets */
471 
472  /* count of credits received via Rx packets on this endpoint */
474 
475  /* count of credits received via another endpoint */
477 
478  /* count of credits received via another endpoint */
480 
481  /* count of consummed credits */
483 
484  /* count of credits returned */
486 
488 
489  /* count of lookahead records found in Rx msg */
491 
492  /* count of recv packets received in a bundle */
494 
495  /* count of number of bundled lookaheads */
497 
498  /* count of the number of bundle indications from the HTC header */
500 
501  /* the number of times the recv allocation threshold was hit */
503 
504  /* total number of bytes */
506 };
507 
508 struct htc_endpoint {
511  struct list_head txq;
516  int len_max;
524 
525  struct {
530  } pipe;
531 };
532 
535  u8 *buf;
536 };
537 
541 };
542 
544  HTC_SEND_QUEUE_OK = 0, /* packet was queued */
545  HTC_SEND_QUEUE_DROP = 1, /* this packet should be dropped */
546 };
547 
549  void* (*create)(struct ath6kl *ar);
551  int (*start)(struct htc_target *target);
555  int (*tx)(struct htc_target *target, struct htc_packet *packet);
556  void (*stop)(struct htc_target *target);
563  bool active);
567  struct list_head *pktq);
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 
574 struct ath6kl_device;
575 
576 /* our HTC target state */
577 struct htc_target {
579 
580  /* contains struct htc_endpoint_credit_dist */
582 
587  unsigned int tgt_cred_sz;
588 
589  /* protects free_ctrl_txbuf and free_ctrl_rxbuf */
591 
592  /* FIXME: does this protext rx_bufq and endpoint structures or what? */
594 
595  /* protects endpoint->txq */
597 
603 
604  /* max messages per bundle for HTC */
606 
611 
614 
617 
619 
620  /* counts the number of Tx without bundling continously per AC */
622 
623  struct {
629  } pipe;
630 };
631 
633  u32 msg_look_ahead, int *n_pkts);
634 
635 static 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 
646 static inline void htc_rxpkt_reset(struct htc_packet *packet)
647 {
648  packet->buf = packet->buf_start;
649  packet->act_len = 0;
650 }
651 
652 static 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 
663 static 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 
676 
677 #endif