Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | struct ath9k_htc_priv; |
| 21 | struct htc_target; |
| 22 | struct ath9k_htc_tx_ctl; |
| 23 | |
| 24 | enum ath9k_hif_transports { |
| 25 | ATH9K_HIF_USB, |
| 26 | }; |
| 27 | |
| 28 | struct 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); |
Sujith Manoharan | 40dc9e4 | 2011-04-13 11:24:31 +0530 | [diff] [blame] | 38 | int (*send) (void *hif_handle, u8 pipe, struct sk_buff *buf); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | enum htc_endpoint_id { |
| 42 | ENDPOINT_UNUSED = -1, |
| 43 | ENDPOINT0 = 0, |
| 44 | ENDPOINT1 = 1, |
| 45 | ENDPOINT2 = 2, |
| 46 | ENDPOINT3 = 3, |
| 47 | ENDPOINT4 = 4, |
| 48 | ENDPOINT5 = 5, |
| 49 | ENDPOINT6 = 6, |
| 50 | ENDPOINT7 = 7, |
| 51 | ENDPOINT8 = 8, |
| 52 | ENDPOINT_MAX = 22 |
| 53 | }; |
| 54 | |
| 55 | /* Htc frame hdr flags */ |
| 56 | #define HTC_FLAGS_RECV_TRAILER (1 << 1) |
| 57 | |
| 58 | struct htc_frame_hdr { |
| 59 | u8 endpoint_id; |
| 60 | u8 flags; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 61 | __be16 payload_len; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 62 | u8 control[4]; |
| 63 | } __packed; |
| 64 | |
| 65 | struct htc_ready_msg { |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 66 | __be16 message_id; |
| 67 | __be16 credits; |
| 68 | __be16 credit_size; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 69 | u8 max_endpoints; |
| 70 | u8 pad; |
| 71 | } __packed; |
| 72 | |
| 73 | struct htc_config_pipe_msg { |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 74 | __be16 message_id; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 75 | u8 pipe_id; |
| 76 | u8 credits; |
| 77 | } __packed; |
| 78 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 79 | struct htc_ep_callbacks { |
| 80 | void *priv; |
| 81 | void (*tx) (void *, struct sk_buff *, enum htc_endpoint_id, bool txok); |
| 82 | void (*rx) (void *, struct sk_buff *, enum htc_endpoint_id); |
| 83 | }; |
| 84 | |
| 85 | #define HTC_TX_QUEUE_SIZE 256 |
| 86 | |
| 87 | struct htc_txq { |
| 88 | struct sk_buff *buf[HTC_TX_QUEUE_SIZE]; |
| 89 | u32 txqdepth; |
| 90 | u16 txbuf_cnt; |
| 91 | u16 txq_head; |
| 92 | u16 txq_tail; |
| 93 | }; |
| 94 | |
| 95 | struct htc_endpoint { |
| 96 | u16 service_id; |
| 97 | |
| 98 | struct htc_ep_callbacks ep_callbacks; |
| 99 | struct htc_txq htc_txq; |
| 100 | u32 max_txqdepth; |
| 101 | int max_msglen; |
| 102 | |
| 103 | u8 ul_pipeid; |
| 104 | u8 dl_pipeid; |
| 105 | }; |
| 106 | |
| 107 | #define HTC_MAX_CONTROL_MESSAGE_LENGTH 255 |
| 108 | #define HTC_CONTROL_BUFFER_SIZE \ |
| 109 | (HTC_MAX_CONTROL_MESSAGE_LENGTH + sizeof(struct htc_frame_hdr)) |
| 110 | |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 111 | #define HTC_OP_START_WAIT BIT(0) |
| 112 | #define HTC_OP_CONFIG_PIPE_CREDITS BIT(1) |
| 113 | |
| 114 | struct htc_target { |
| 115 | void *hif_dev; |
| 116 | struct ath9k_htc_priv *drv_priv; |
| 117 | struct device *dev; |
| 118 | struct ath9k_htc_hif *hif; |
Sujith.Manoharan@atheros.com | 8116daf | 2010-05-11 17:03:36 +0530 | [diff] [blame] | 119 | struct htc_endpoint endpoint[ENDPOINT_MAX]; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 120 | struct completion target_wait; |
| 121 | struct completion cmd_wait; |
| 122 | struct list_head list; |
| 123 | enum htc_endpoint_id conn_rsp_epid; |
| 124 | u16 credits; |
| 125 | u16 credit_size; |
| 126 | u8 htc_flags; |
Sujith.Manoharan@atheros.com | d8c49ff | 2010-05-11 16:24:43 +0530 | [diff] [blame] | 127 | atomic_t tgt_ready; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | enum htc_msg_id { |
| 131 | HTC_MSG_READY_ID = 1, |
| 132 | HTC_MSG_CONNECT_SERVICE_ID, |
| 133 | HTC_MSG_CONNECT_SERVICE_RESPONSE_ID, |
| 134 | HTC_MSG_SETUP_COMPLETE_ID, |
| 135 | HTC_MSG_CONFIG_PIPE_ID, |
| 136 | HTC_MSG_CONFIG_PIPE_RESPONSE_ID, |
| 137 | }; |
| 138 | |
| 139 | struct htc_service_connreq { |
| 140 | u16 service_id; |
| 141 | u16 con_flags; |
| 142 | u32 max_send_qdepth; |
| 143 | struct htc_ep_callbacks ep_callbacks; |
| 144 | }; |
| 145 | |
| 146 | /* Current service IDs */ |
| 147 | |
| 148 | enum htc_service_group_ids{ |
| 149 | RSVD_SERVICE_GROUP = 0, |
| 150 | WMI_SERVICE_GROUP = 1, |
| 151 | |
| 152 | HTC_SERVICE_GROUP_LAST = 255 |
| 153 | }; |
| 154 | |
| 155 | #define MAKE_SERVICE_ID(group, index) \ |
| 156 | (int)(((int)group << 8) | (int)(index)) |
| 157 | |
| 158 | /* NOTE: service ID of 0x0000 is reserved and should never be used */ |
| 159 | #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1) |
| 160 | #define HTC_LOOPBACK_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 2) |
| 161 | |
| 162 | #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0) |
| 163 | #define WMI_BEACON_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1) |
| 164 | #define WMI_CAB_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2) |
| 165 | #define WMI_UAPSD_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3) |
| 166 | #define WMI_MGMT_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4) |
| 167 | #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 5) |
| 168 | #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 6) |
| 169 | #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 7) |
| 170 | #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 8) |
| 171 | |
| 172 | struct htc_conn_svc_msg { |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 173 | __be16 msg_id; |
| 174 | __be16 service_id; |
| 175 | __be16 con_flags; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 176 | u8 dl_pipeid; |
| 177 | u8 ul_pipeid; |
| 178 | u8 svc_meta_len; |
| 179 | u8 pad; |
| 180 | } __packed; |
| 181 | |
| 182 | /* connect response status codes */ |
| 183 | #define HTC_SERVICE_SUCCESS 0 |
| 184 | #define HTC_SERVICE_NOT_FOUND 1 |
| 185 | #define HTC_SERVICE_FAILED 2 |
| 186 | #define HTC_SERVICE_NO_RESOURCES 3 |
| 187 | #define HTC_SERVICE_NO_MORE_EP 4 |
| 188 | |
| 189 | struct htc_conn_svc_rspmsg { |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 190 | __be16 msg_id; |
| 191 | __be16 service_id; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 192 | u8 status; |
| 193 | u8 endpoint_id; |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 194 | __be16 max_msg_len; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 195 | u8 svc_meta_len; |
| 196 | u8 pad; |
| 197 | } __packed; |
| 198 | |
| 199 | struct htc_comp_msg { |
Sujith | 7f1f5a0 | 2010-04-16 11:54:03 +0530 | [diff] [blame] | 200 | __be16 msg_id; |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 201 | } __packed; |
| 202 | |
| 203 | int htc_init(struct htc_target *target); |
| 204 | int htc_connect_service(struct htc_target *target, |
| 205 | struct htc_service_connreq *service_connreq, |
| 206 | enum htc_endpoint_id *conn_rsp_eid); |
Sujith Manoharan | d67ee53 | 2011-04-13 11:25:35 +0530 | [diff] [blame] | 207 | int htc_send(struct htc_target *target, struct sk_buff *skb); |
| 208 | int htc_send_epid(struct htc_target *target, struct sk_buff *skb, |
| 209 | enum htc_endpoint_id epid); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 210 | void htc_stop(struct htc_target *target); |
| 211 | void htc_start(struct htc_target *target); |
| 212 | |
| 213 | void ath9k_htc_rx_msg(struct htc_target *htc_handle, |
| 214 | struct sk_buff *skb, u32 len, u8 pipe_id); |
| 215 | void ath9k_htc_txcompletion_cb(struct htc_target *htc_handle, |
| 216 | struct sk_buff *skb, bool txok); |
| 217 | |
Sujith.Manoharan@atheros.com | 47fce02 | 2010-05-11 16:24:41 +0530 | [diff] [blame] | 218 | struct htc_target *ath9k_htc_hw_alloc(void *hif_handle, |
| 219 | struct ath9k_htc_hif *hif, |
| 220 | struct device *dev); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 221 | void ath9k_htc_hw_free(struct htc_target *htc); |
Sujith.Manoharan@atheros.com | 47fce02 | 2010-05-11 16:24:41 +0530 | [diff] [blame] | 222 | int ath9k_htc_hw_init(struct htc_target *target, |
Rajkumar Manoharan | fa6e15e | 2010-11-19 16:53:22 +0530 | [diff] [blame] | 223 | struct device *dev, u16 devid, char *product, |
| 224 | u32 drv_info); |
Sujith | fb9987d | 2010-03-17 14:25:25 +0530 | [diff] [blame] | 225 | void ath9k_htc_hw_deinit(struct htc_target *target, bool hot_unplug); |
| 226 | |
| 227 | #endif /* HTC_HST_H */ |