pre-merge coding style cleanup and code review
[helenos.git] / uspace / drv / nic / ar9271 / htc.h
blob91a368ac682730877671fc137e3d9e9939c4f2af
1 /*
2 * Copyright (c) 2014 Jan Kolarik
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @file htc.h
31 * Definitions of the Atheros HTC (Host Target Communication) technology
32 * for communication between host (PC) and target (device firmware).
36 #ifndef ATHEROS_HTC_H
37 #define ATHEROS_HTC_H
39 #include <ieee80211.h>
40 #include <usb/dev/driver.h>
41 #include <sys/types.h>
42 #include <nic.h>
43 #include "ath.h"
45 #define HTC_RTS_THRESHOLD 2304
46 #define HTC_RATES_MAX_LENGTH 30
48 /** HTC message IDs.
51 typedef enum {
52 HTC_MESSAGE_READY = 1,
53 HTC_MESSAGE_CONNECT_SERVICE,
54 HTC_MESSAGE_CONNECT_SERVICE_RESPONSE,
55 HTC_MESSAGE_SETUP_COMPLETE,
56 HTC_MESSAGE_CONFIG
57 } htc_message_id_t;
59 /** HTC response message status codes.
62 typedef enum {
63 HTC_SERVICE_SUCCESS = 0,
64 HTC_SERVICE_NOT_FOUND,
65 HTC_SERVICE_FAILED,
66 HTC_SERVICE_NO_RESOURCES,
67 HTC_SERVICE_NO_MORE_EP
68 } htc_response_status_code_t;
70 /** HTC operating mode definition.
73 typedef enum {
74 HTC_OPMODE_ADHOC = 0,
75 HTC_OPMODE_STATION = 1,
76 HTC_OPMODE_MESH = 2,
77 HTC_OPMODE_AP = 6
78 } htc_operating_mode_t;
80 /** HTC data type indicator.
83 typedef enum {
84 HTC_DATA_AMPDU = 1,
85 HTC_DATA_NORMAL = 2,
86 HTC_DATA_BEACON = 3,
87 HTC_DATA_MGMT = 4
88 } htc_data_type_t;
90 /** HTC endpoint numbers.
93 typedef struct {
94 int ctrl_endpoint;
95 int wmi_endpoint;
96 int beacon_endpoint;
97 int cab_endpoint;
98 int uapsd_endpoint;
99 int mgmt_endpoint;
100 int data_be_endpoint;
101 int data_bk_endpoint;
102 int data_video_endpoint;
103 int data_voice_endpoint;
104 } htc_pipes_t;
106 /** HTC device data.
109 typedef struct {
110 /** WMI message sequence number */
111 uint16_t sequence_number;
113 /** HTC endpoints numbers */
114 htc_pipes_t endpoints;
116 /** Lock for receiver */
117 fibril_mutex_t rx_lock;
119 /** Lock for transmitter */
120 fibril_mutex_t tx_lock;
122 /** Pointer to related IEEE 802.11 device */
123 ieee80211_dev_t *ieee80211_dev;
125 /** Pointer to Atheros WiFi device structure */
126 ath_t *ath_device;
127 } htc_device_t;
129 /** HTC frame header structure.
132 typedef struct {
133 uint8_t endpoint_id;
134 uint8_t flags;
135 uint16_t payload_length; /**< Big Endian value! */
136 uint8_t control_bytes[4];
137 } __attribute__((packed)) htc_frame_header_t;
139 /** HTC management TX frame header structure.
142 typedef struct {
143 uint8_t node_idx;
144 uint8_t vif_idx;
145 uint8_t tidno;
146 uint8_t flags;
147 uint8_t key_type;
148 uint8_t keyix;
149 uint8_t cookie;
150 uint8_t pad;
151 } __attribute__((packed)) htc_tx_management_header_t;
153 /** HTC data TX frame header structure.
156 typedef struct {
157 uint8_t data_type;
158 uint8_t node_idx;
159 uint8_t vif_idx;
160 uint8_t tidno;
161 uint32_t flags; /**< Big Endian value! */
162 uint8_t key_type;
163 uint8_t keyix;
164 uint8_t cookie;
165 uint8_t pad;
166 } __attribute__((packed)) htc_tx_data_header_t;
168 /** HTC ready message structure.
171 typedef struct {
172 uint16_t message_id; /**< Big Endian value! */
173 uint16_t credits; /**< Big Endian value! */
174 uint16_t credit_size; /**< Big Endian value! */
176 uint8_t max_endpoints;
177 uint8_t pad;
178 } __attribute__((packed)) htc_ready_msg_t;
180 /** HTC service message structure.
183 typedef struct {
184 uint16_t message_id; /**< Big Endian value! */
185 uint16_t service_id; /**< Big Endian value! */
186 uint16_t connection_flags; /**< Big Endian value! */
188 uint8_t download_pipe_id;
189 uint8_t upload_pipe_id;
190 uint8_t service_meta_length;
191 uint8_t pad;
192 } __attribute__((packed)) htc_service_msg_t;
194 /** HTC service response message structure.
197 typedef struct {
198 uint16_t message_id; /**< Big Endian value! */
199 uint16_t service_id; /**< Big Endian value! */
200 uint8_t status;
201 uint8_t endpoint_id;
202 uint16_t max_message_length; /**< Big Endian value! */
203 uint8_t service_meta_length;
204 uint8_t pad;
205 } __attribute__((packed)) htc_service_resp_msg_t;
207 /** HTC credits config message structure.
210 typedef struct {
211 uint16_t message_id; /**< Big Endian value! */
212 uint8_t pipe_id;
213 uint8_t credits;
214 } __attribute__((packed)) htc_config_msg_t;
216 /** HTC new virtual interface message.
219 typedef struct {
220 uint8_t index;
221 uint8_t op_mode;
222 uint8_t addr[ETH_ADDR];
223 uint8_t ath_cap;
224 uint16_t rts_thres; /**< Big Endian value! */
225 uint8_t pad;
226 } __attribute__((packed)) htc_vif_msg_t;
228 /** HTC new station message.
231 typedef struct {
232 uint8_t addr[ETH_ADDR];
233 uint8_t bssid[ETH_ADDR];
234 uint8_t sta_index;
235 uint8_t vif_index;
236 uint8_t is_vif_sta;
238 uint16_t flags; /**< Big Endian value! */
239 uint16_t ht_cap; /**< Big Endian value! */
240 uint16_t max_ampdu; /**< Big Endian value! */
242 uint8_t pad;
243 } __attribute__((packed)) htc_sta_msg_t;
245 /** HTC message to inform target about available capabilities.
248 typedef struct {
249 uint32_t ampdu_limit; /**< Big Endian value! */
250 uint8_t ampdu_subframes;
251 uint8_t enable_coex;
252 uint8_t tx_chainmask;
253 uint8_t pad;
254 } __attribute__((packed)) htc_cap_msg_t;
256 typedef struct {
257 uint8_t sta_index;
258 uint8_t is_new;
259 uint32_t cap_flags; /**< Big Endian value! */
260 uint8_t legacy_rates_count;
261 uint8_t legacy_rates[HTC_RATES_MAX_LENGTH];
262 uint16_t pad;
263 } htc_rate_msg_t;
265 /** HTC RX status structure used in incoming HTC data messages.
268 typedef struct {
269 uint64_t timestamp; /**< Big Endian value! */
270 uint16_t data_length; /**< Big Endian value! */
271 uint8_t status;
272 uint8_t phy_err;
273 int8_t rssi;
274 int8_t rssi_ctl[3];
275 int8_t rssi_ext[3];
276 uint8_t keyix;
277 uint8_t rate;
278 uint8_t antenna;
279 uint8_t more;
280 uint8_t is_aggr;
281 uint8_t more_aggr;
282 uint8_t num_delims;
283 uint8_t flags;
284 uint8_t dummy;
285 uint32_t evm0; /**< Big Endian value! */
286 uint32_t evm1; /**< Big Endian value! */
287 uint32_t evm2; /**< Big Endian value! */
288 } htc_rx_status_t;
290 /** HTC setup complete message structure
293 typedef struct {
294 uint16_t message_id; /**< Big Endian value! */
295 } __attribute__((packed)) htc_setup_complete_msg_t;
297 extern int htc_device_init(ath_t *, ieee80211_dev_t *, htc_device_t *);
298 extern int htc_init(htc_device_t *);
299 extern int htc_init_new_vif(htc_device_t *);
300 extern int htc_read_control_message(htc_device_t *, void *, size_t, size_t *);
301 extern int htc_read_data_message(htc_device_t *, void *, size_t, size_t *);
302 extern int htc_send_control_message(htc_device_t *, void *, size_t, uint8_t);
303 extern int htc_send_data_message(htc_device_t *, void *, size_t, uint8_t);
305 #endif /* ATHEROS_HTC_H */