blob: ecd018798c4721d6d62c8802b53c87d28673a66d [file] [log] [blame]
Sujithfb9987d2010-03-17 14:25:25 +05301/*
2 * Copyright (c) 2010 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef HTC_HST_H
18#define HTC_HST_H
19
20struct ath9k_htc_priv;
21struct htc_target;
22struct ath9k_htc_tx_ctl;
23
24enum ath9k_hif_transports {
25 ATH9K_HIF_USB,
26};
27
28struct ath9k_htc_hif {
29 struct list_head list;
30 const enum ath9k_hif_transports transport;
31 const char *name;
32
33 u8 control_dl_pipe;
34 u8 control_ul_pipe;
35
36 void (*start) (void *hif_handle, u8 pipe);
37 void (*stop) (void *hif_handle, u8 pipe);
38 int (*send) (void *hif_handle, u8 pipe, struct sk_buff *buf,
39 struct ath9k_htc_tx_ctl *tx_ctl);
40};
41
42enum htc_endpoint_id {
43 ENDPOINT_UNUSED = -1,
44 ENDPOINT0 = 0,
45 ENDPOINT1 = 1,
46 ENDPOINT2 = 2,
47 ENDPOINT3 = 3,
48 ENDPOINT4 = 4,
49 ENDPOINT5 = 5,
50 ENDPOINT6 = 6,
51 ENDPOINT7 = 7,
52 ENDPOINT8 = 8,
53 ENDPOINT_MAX = 22
54};
55
56/* Htc frame hdr flags */
57#define HTC_FLAGS_RECV_TRAILER (1 << 1)
58
59struct htc_frame_hdr {
60 u8 endpoint_id;
61 u8 flags;
Sujith7f1f5a02010-04-16 11:54:03 +053062 __be16 payload_len;
Sujithfb9987d2010-03-17 14:25:25 +053063 u8 control[4];
64} __packed;
65
66struct htc_ready_msg {
Sujith7f1f5a02010-04-16 11:54:03 +053067 __be16 message_id;
68 __be16 credits;
69 __be16 credit_size;
Sujithfb9987d2010-03-17 14:25:25 +053070 u8 max_endpoints;
71 u8 pad;
72} __packed;
73
74struct htc_config_pipe_msg {
Sujith7f1f5a02010-04-16 11:54:03 +053075 __be16 message_id;
Sujithfb9987d2010-03-17 14:25:25 +053076 u8 pipe_id;
77 u8 credits;
78} __packed;
79
Sujithfb9987d2010-03-17 14:25:25 +053080struct htc_ep_callbacks {
81 void *priv;
82 void (*tx) (void *, struct sk_buff *, enum htc_endpoint_id, bool txok);
83 void (*rx) (void *, struct sk_buff *, enum htc_endpoint_id);
84};
85
86#define HTC_TX_QUEUE_SIZE 256
87
88struct htc_txq {
89 struct sk_buff *buf[HTC_TX_QUEUE_SIZE];
90 u32 txqdepth;
91 u16 txbuf_cnt;
92 u16 txq_head;
93 u16 txq_tail;
94};
95
96struct htc_endpoint {
97 u16 service_id;
98
99 struct htc_ep_callbacks ep_callbacks;
100 struct htc_txq htc_txq;
101 u32 max_txqdepth;
102 int max_msglen;
103
104 u8 ul_pipeid;
105 u8 dl_pipeid;
106};
107
108#define HTC_MAX_CONTROL_MESSAGE_LENGTH 255
109#define HTC_CONTROL_BUFFER_SIZE \
110 (HTC_MAX_CONTROL_MESSAGE_LENGTH + sizeof(struct htc_frame_hdr))
111
Sujithfb9987d2010-03-17 14:25:25 +0530112#define HTC_OP_START_WAIT BIT(0)
113#define HTC_OP_CONFIG_PIPE_CREDITS BIT(1)
114
115struct htc_target {
116 void *hif_dev;
117 struct ath9k_htc_priv *drv_priv;
118 struct device *dev;
119 struct ath9k_htc_hif *hif;
Sujith.Manoharan@atheros.com8116daf2010-05-11 17:03:36 +0530120 struct htc_endpoint endpoint[ENDPOINT_MAX];
Sujithfb9987d2010-03-17 14:25:25 +0530121 struct completion target_wait;
122 struct completion cmd_wait;
123 struct list_head list;
124 enum htc_endpoint_id conn_rsp_epid;
125 u16 credits;
126 u16 credit_size;
127 u8 htc_flags;
Sujith.Manoharan@atheros.comd8c49ff2010-05-11 16:24:43 +0530128 atomic_t tgt_ready;
Sujithfb9987d2010-03-17 14:25:25 +0530129};
130
131enum htc_msg_id {
132 HTC_MSG_READY_ID = 1,
133 HTC_MSG_CONNECT_SERVICE_ID,
134 HTC_MSG_CONNECT_SERVICE_RESPONSE_ID,
135 HTC_MSG_SETUP_COMPLETE_ID,
136 HTC_MSG_CONFIG_PIPE_ID,
137 HTC_MSG_CONFIG_PIPE_RESPONSE_ID,
138};
139
140struct htc_service_connreq {
141 u16 service_id;
142 u16 con_flags;
143 u32 max_send_qdepth;
144 struct htc_ep_callbacks ep_callbacks;
145};
146
147/* Current service IDs */
148
149enum htc_service_group_ids{
150 RSVD_SERVICE_GROUP = 0,
151 WMI_SERVICE_GROUP = 1,
152
153 HTC_SERVICE_GROUP_LAST = 255
154};
155
156#define MAKE_SERVICE_ID(group, index) \
157 (int)(((int)group << 8) | (int)(index))
158
159/* NOTE: service ID of 0x0000 is reserved and should never be used */
160#define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
161#define HTC_LOOPBACK_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 2)
162
163#define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
164#define WMI_BEACON_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
165#define WMI_CAB_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
166#define WMI_UAPSD_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
167#define WMI_MGMT_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
168#define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 5)
169#define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 6)
170#define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 7)
171#define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 8)
172
173struct htc_conn_svc_msg {
Sujith7f1f5a02010-04-16 11:54:03 +0530174 __be16 msg_id;
175 __be16 service_id;
176 __be16 con_flags;
Sujithfb9987d2010-03-17 14:25:25 +0530177 u8 dl_pipeid;
178 u8 ul_pipeid;
179 u8 svc_meta_len;
180 u8 pad;
181} __packed;
182
183/* connect response status codes */
184#define HTC_SERVICE_SUCCESS 0
185#define HTC_SERVICE_NOT_FOUND 1
186#define HTC_SERVICE_FAILED 2
187#define HTC_SERVICE_NO_RESOURCES 3
188#define HTC_SERVICE_NO_MORE_EP 4
189
190struct htc_conn_svc_rspmsg {
Sujith7f1f5a02010-04-16 11:54:03 +0530191 __be16 msg_id;
192 __be16 service_id;
Sujithfb9987d2010-03-17 14:25:25 +0530193 u8 status;
194 u8 endpoint_id;
Sujith7f1f5a02010-04-16 11:54:03 +0530195 __be16 max_msg_len;
Sujithfb9987d2010-03-17 14:25:25 +0530196 u8 svc_meta_len;
197 u8 pad;
198} __packed;
199
200struct htc_comp_msg {
Sujith7f1f5a02010-04-16 11:54:03 +0530201 __be16 msg_id;
Sujithfb9987d2010-03-17 14:25:25 +0530202} __packed;
203
204int htc_init(struct htc_target *target);
205int htc_connect_service(struct htc_target *target,
206 struct htc_service_connreq *service_connreq,
207 enum htc_endpoint_id *conn_rsp_eid);
208int htc_send(struct htc_target *target, struct sk_buff *skb,
209 enum htc_endpoint_id eid, struct ath9k_htc_tx_ctl *tx_ctl);
210void htc_stop(struct htc_target *target);
211void htc_start(struct htc_target *target);
212
213void ath9k_htc_rx_msg(struct htc_target *htc_handle,
214 struct sk_buff *skb, u32 len, u8 pipe_id);
215void ath9k_htc_txcompletion_cb(struct htc_target *htc_handle,
216 struct sk_buff *skb, bool txok);
217
Sujith.Manoharan@atheros.com47fce022010-05-11 16:24:41 +0530218struct htc_target *ath9k_htc_hw_alloc(void *hif_handle,
219 struct ath9k_htc_hif *hif,
220 struct device *dev);
Sujithfb9987d2010-03-17 14:25:25 +0530221void ath9k_htc_hw_free(struct htc_target *htc);
Sujith.Manoharan@atheros.com47fce022010-05-11 16:24:41 +0530222int ath9k_htc_hw_init(struct htc_target *target,
Rajkumar Manoharanfa6e15e2010-11-19 16:53:22 +0530223 struct device *dev, u16 devid, char *product,
224 u32 drv_info);
Sujithfb9987d2010-03-17 14:25:25 +0530225void ath9k_htc_hw_deinit(struct htc_target *target, bool hot_unplug);
226
227#endif /* HTC_HST_H */