1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2002,2003 Oliver Kurth
4  *	     (c) 2003,2004 Joerg Albert <joerg.albert@gmx.de>
5  *	     (c) 2007 Guido Guenther <agx@sigxcpu.org>
6  *
7  * This driver was based on information from the Sourceforge driver
8  * released and maintained by Atmel:
9  *
10  *  http://sourceforge.net/projects/atmelwlandriver/
11  *
12  * Although the code was completely re-written,
13  * it would have been impossible without Atmel's decision to
14  * release an Open Source driver (unfortunately the firmware was
15  * kept binary only). Thanks for that decision to Atmel!
16  */
17 
18 #ifndef _AT76_USB_H
19 #define _AT76_USB_H
20 
21 /* Board types */
22 enum board_type {
23 	BOARD_503_ISL3861 = 1,
24 	BOARD_503_ISL3863 = 2,
25 	BOARD_503 = 3,
26 	BOARD_503_ACC = 4,
27 	BOARD_505 = 5,
28 	BOARD_505_2958 = 6,
29 	BOARD_505A = 7,
30 	BOARD_505AMX = 8
31 };
32 
33 #define CMD_STATUS_IDLE				0x00
34 #define CMD_STATUS_COMPLETE			0x01
35 #define CMD_STATUS_UNKNOWN			0x02
36 #define CMD_STATUS_INVALID_PARAMETER		0x03
37 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED	0x04
38 #define CMD_STATUS_TIME_OUT			0x07
39 #define CMD_STATUS_IN_PROGRESS			0x08
40 #define CMD_STATUS_HOST_FAILURE			0xff
41 #define CMD_STATUS_SCAN_FAILED			0xf0
42 
43 /* answers to get op mode */
44 #define OPMODE_NONE				0x00
45 #define OPMODE_NORMAL_NIC_WITH_FLASH		0x01
46 #define OPMODE_HW_CONFIG_MODE			0x02
47 #define OPMODE_DFU_MODE_WITH_FLASH		0x03
48 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH		0x04
49 
50 #define CMD_SET_MIB		0x01
51 #define CMD_GET_MIB		0x02
52 #define CMD_SCAN		0x03
53 #define CMD_JOIN		0x04
54 #define CMD_START_IBSS		0x05
55 #define CMD_RADIO_ON		0x06
56 #define CMD_RADIO_OFF		0x07
57 #define CMD_STARTUP		0x0B
58 
59 #define MIB_LOCAL		0x01
60 #define MIB_MAC_ADDR		0x02
61 #define MIB_MAC			0x03
62 #define MIB_MAC_MGMT		0x05
63 #define MIB_MAC_WEP		0x06
64 #define MIB_PHY			0x07
65 #define MIB_FW_VERSION		0x08
66 #define MIB_MDOMAIN		0x09
67 
68 #define ADHOC_MODE		1
69 #define INFRASTRUCTURE_MODE	2
70 
71 /* values for struct mib_local, field preamble_type */
72 #define PREAMBLE_TYPE_LONG	0
73 #define PREAMBLE_TYPE_SHORT	1
74 #define PREAMBLE_TYPE_AUTO	2
75 
76 /* values for tx_rate */
77 #define TX_RATE_1MBIT		0
78 #define TX_RATE_2MBIT		1
79 #define TX_RATE_5_5MBIT 	2
80 #define TX_RATE_11MBIT		3
81 #define TX_RATE_AUTO		4
82 
83 /* power management modes */
84 #define AT76_PM_OFF		1
85 #define AT76_PM_ON		2
86 #define AT76_PM_SMART		3
87 
88 struct hwcfg_r505 {
89 	u8 cr39_values[14];
90 	u8 reserved1[14];
91 	u8 bb_cr[14];
92 	u8 pidvid[4];
93 	u8 mac_addr[ETH_ALEN];
94 	u8 regulatory_domain;
95 	u8 reserved2[14];
96 	u8 cr15_values[14];
97 	u8 reserved3[3];
98 } __packed;
99 
100 struct hwcfg_rfmd {
101 	u8 cr20_values[14];
102 	u8 cr21_values[14];
103 	u8 bb_cr[14];
104 	u8 pidvid[4];
105 	u8 mac_addr[ETH_ALEN];
106 	u8 regulatory_domain;
107 	u8 low_power_values[14];
108 	u8 normal_power_values[14];
109 	u8 reserved1[3];
110 } __packed;
111 
112 struct hwcfg_intersil {
113 	u8 mac_addr[ETH_ALEN];
114 	u8 cr31_values[14];
115 	u8 cr58_values[14];
116 	u8 pidvid[4];
117 	u8 regulatory_domain;
118 	u8 reserved[1];
119 } __packed;
120 
121 union at76_hwcfg {
122 	struct hwcfg_intersil i;
123 	struct hwcfg_rfmd r3;
124 	struct hwcfg_r505 r5;
125 };
126 
127 #define WEP_SMALL_KEY_LEN	(40 / 8)
128 #define WEP_LARGE_KEY_LEN	(104 / 8)
129 #define WEP_KEYS		(4)
130 
131 struct at76_card_config {
132 	u8 exclude_unencrypted;
133 	u8 promiscuous_mode;
134 	u8 short_retry_limit;
135 	u8 encryption_type;
136 	__le16 rts_threshold;
137 	__le16 fragmentation_threshold;	/* 256..2346 */
138 	u8 basic_rate_set[4];
139 	u8 auto_rate_fallback;	/* 0,1 */
140 	u8 channel;
141 	u8 privacy_invoked;
142 	u8 wep_default_key_id;	/* 0..3 */
143 	u8 current_ssid[32];
144 	u8 wep_default_key_value[4][WEP_LARGE_KEY_LEN];
145 	u8 ssid_len;
146 	u8 short_preamble;
147 	__le16 beacon_period;
148 } __packed;
149 
150 struct at76_command {
151 	u8 cmd;
152 	u8 reserved;
153 	__le16 size;
154 	u8 data[0];
155 } __packed;
156 
157 /* Length of Atmel-specific Rx header before 802.11 frame */
158 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
159 
160 struct at76_rx_buffer {
161 	__le16 wlength;
162 	u8 rx_rate;
163 	u8 newbss;
164 	u8 fragmentation;
165 	u8 rssi;
166 	u8 link_quality;
167 	u8 noise_level;
168 	__le32 rx_time;
169 	u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
170 } __packed;
171 
172 /* Length of Atmel-specific Tx header before 802.11 frame */
173 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
174 
175 struct at76_tx_buffer {
176 	__le16 wlength;
177 	u8 tx_rate;
178 	u8 padding;
179 	u8 reserved[4];
180 	u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
181 } __packed;
182 
183 /* defines for scan_type below */
184 #define SCAN_TYPE_ACTIVE	0
185 #define SCAN_TYPE_PASSIVE	1
186 
187 struct at76_req_scan {
188 	u8 bssid[ETH_ALEN];
189 	u8 essid[32];
190 	u8 scan_type;
191 	u8 channel;
192 	__le16 probe_delay;
193 	__le16 min_channel_time;
194 	__le16 max_channel_time;
195 	u8 essid_size;
196 	u8 international_scan;
197 } __packed;
198 
199 struct at76_req_ibss {
200 	u8 bssid[ETH_ALEN];
201 	u8 essid[32];
202 	u8 bss_type;
203 	u8 channel;
204 	u8 essid_size;
205 	u8 reserved[3];
206 } __packed;
207 
208 struct at76_req_join {
209 	u8 bssid[ETH_ALEN];
210 	u8 essid[32];
211 	u8 bss_type;
212 	u8 channel;
213 	__le16 timeout;
214 	u8 essid_size;
215 	u8 reserved;
216 } __packed;
217 
218 struct mib_local {
219 	u16 reserved0;
220 	u8 beacon_enable;
221 	u8 txautorate_fallback;
222 	u8 reserved1;
223 	u8 ssid_size;
224 	u8 promiscuous_mode;
225 	u16 reserved2;
226 	u8 preamble_type;
227 	u16 reserved3;
228 } __packed;
229 
230 struct mib_mac_addr {
231 	u8 mac_addr[ETH_ALEN];
232 	u8 res[2];		/* ??? */
233 	u8 group_addr[4][ETH_ALEN];
234 	u8 group_addr_status[4];
235 } __packed;
236 
237 struct mib_mac {
238 	__le32 max_tx_msdu_lifetime;
239 	__le32 max_rx_lifetime;
240 	__le16 frag_threshold;
241 	__le16 rts_threshold;
242 	__le16 cwmin;
243 	__le16 cwmax;
244 	u8 short_retry_time;
245 	u8 long_retry_time;
246 	u8 scan_type;		/* active or passive */
247 	u8 scan_channel;
248 	__le16 probe_delay;	/* delay before ProbeReq in active scan, RO */
249 	__le16 min_channel_time;
250 	__le16 max_channel_time;
251 	__le16 listen_interval;
252 	u8 desired_ssid[32];
253 	u8 desired_bssid[ETH_ALEN];
254 	u8 desired_bsstype;	/* ad-hoc or infrastructure */
255 	u8 reserved2;
256 } __packed;
257 
258 struct mib_mac_mgmt {
259 	__le16 beacon_period;
260 	__le16 CFP_max_duration;
261 	__le16 medium_occupancy_limit;
262 	__le16 station_id;	/* assoc id */
263 	__le16 ATIM_window;
264 	u8 CFP_mode;
265 	u8 privacy_option_implemented;
266 	u8 DTIM_period;
267 	u8 CFP_period;
268 	u8 current_bssid[ETH_ALEN];
269 	u8 current_essid[32];
270 	u8 current_bss_type;
271 	u8 power_mgmt_mode;
272 	/* rfmd and 505 */
273 	u8 ibss_change;
274 	u8 res;
275 	u8 multi_domain_capability_implemented;
276 	u8 multi_domain_capability_enabled;
277 	u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
278 	u8 reserved[3];
279 } __packed;
280 
281 struct mib_mac_wep {
282 	u8 privacy_invoked;	/* 0 disable encr., 1 enable encr */
283 	u8 wep_default_key_id;
284 	u8 wep_key_mapping_len;
285 	u8 exclude_unencrypted;
286 	__le32 wep_icv_error_count;
287 	__le32 wep_excluded_count;
288 	u8 wep_default_keyvalue[WEP_KEYS][WEP_LARGE_KEY_LEN];
289 	u8 encryption_level;	/* 1 for 40bit, 2 for 104bit encryption */
290 } __packed;
291 
292 struct mib_phy {
293 	__le32 ed_threshold;
294 
295 	__le16 slot_time;
296 	__le16 sifs_time;
297 	__le16 preamble_length;
298 	__le16 plcp_header_length;
299 	__le16 mpdu_max_length;
300 	__le16 cca_mode_supported;
301 
302 	u8 operation_rate_set[4];
303 	u8 channel_id;
304 	u8 current_cca_mode;
305 	u8 phy_type;
306 	u8 current_reg_domain;
307 } __packed;
308 
309 struct mib_fw_version {
310 	u8 major;
311 	u8 minor;
312 	u8 patch;
313 	u8 build;
314 } __packed;
315 
316 struct mib_mdomain {
317 	u8 tx_powerlevel[14];
318 	u8 channel_list[14];	/* 0 for invalid channels */
319 } __packed;
320 
321 struct set_mib_buffer {
322 	u8 type;
323 	u8 size;
324 	u8 index;
325 	u8 reserved;
326 	union {
327 		u8 byte;
328 		__le16 word;
329 		u8 addr[ETH_ALEN];
330 		struct mib_mac_wep wep_mib;
331 	} data;
332 } __packed;
333 
334 struct at76_fw_header {
335 	__le32 crc;		/* CRC32 of the whole image */
336 	__le32 board_type;	/* firmware compatibility code */
337 	u8 build;		/* firmware build number */
338 	u8 patch;		/* firmware patch level */
339 	u8 minor;		/* firmware minor version */
340 	u8 major;		/* firmware major version */
341 	__le32 str_offset;	/* offset of the copyright string */
342 	__le32 int_fw_offset;	/* internal firmware image offset */
343 	__le32 int_fw_len;	/* internal firmware image length */
344 	__le32 ext_fw_offset;	/* external firmware image offset */
345 	__le32 ext_fw_len;	/* external firmware image length */
346 } __packed;
347 
348 /* a description of a regulatory domain and the allowed channels */
349 struct reg_domain {
350 	u16 code;
351 	char const *name;
352 	u32 channel_map;	/* if bit N is set, channel (N+1) is allowed */
353 };
354 
355 /* Data for one loaded firmware file */
356 struct fwentry {
357 	const char *const fwname;
358 	const struct firmware *fw;
359 	int extfw_size;
360 	int intfw_size;
361 	/* pointer to loaded firmware, no need to free */
362 	u8 *extfw;		/* external firmware, extfw_size bytes long */
363 	u8 *intfw;		/* internal firmware, intfw_size bytes long */
364 	enum board_type board_type;	/* board type */
365 	struct mib_fw_version fw_version;
366 	int loaded;		/* Loaded and parsed successfully */
367 };
368 
369 struct at76_priv {
370 	struct usb_device *udev;	/* USB device pointer */
371 
372 	struct sk_buff *rx_skb;	/* skbuff for receiving data */
373 	struct sk_buff *tx_skb;	/* skbuff for transmitting data */
374 	void *bulk_out_buffer;	/* buffer for sending data */
375 
376 	struct urb *tx_urb;	/* URB for sending data */
377 	struct urb *rx_urb;	/* URB for receiving data */
378 
379 	unsigned int tx_pipe;	/* bulk out pipe */
380 	unsigned int rx_pipe;	/* bulk in pipe */
381 
382 	struct mutex mtx;	/* locks this structure */
383 
384 	/* work queues */
385 	struct work_struct work_set_promisc;
386 	struct work_struct work_submit_rx;
387 	struct work_struct work_join_bssid;
388 	struct delayed_work dwork_hw_scan;
389 
390 	struct tasklet_struct rx_tasklet;
391 
392 	/* the WEP stuff */
393 	int wep_enabled;	/* 1 if WEP is enabled */
394 	int wep_key_id;		/* key id to be used */
395 	u8 wep_keys[WEP_KEYS][WEP_LARGE_KEY_LEN];	/* WEP keys */
396 	u8 wep_keys_len[WEP_KEYS];	/* length of WEP keys */
397 
398 	int channel;
399 	int iw_mode;
400 	u8 bssid[ETH_ALEN];
401 	u8 essid[IW_ESSID_MAX_SIZE];
402 	int essid_size;
403 	int radio_on;
404 	int promisc;
405 
406 	int preamble_type;	/* 0 - long, 1 - short, 2 - auto */
407 	int auth_mode;		/* authentication type: 0 open, 1 shared key */
408 	int txrate;		/* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
409 	int frag_threshold;	/* threshold for fragmentation of tx packets */
410 	int rts_threshold;	/* threshold for RTS mechanism */
411 	int short_retry_limit;
412 
413 	int scan_min_time;	/* scan min channel time */
414 	int scan_max_time;	/* scan max channel time */
415 	int scan_mode;		/* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
416 	int scan_need_any;	/* if set, need to scan for any ESSID */
417 	bool scanning;		/* if set, the scan is running */
418 
419 	u16 assoc_id;		/* current association ID, if associated */
420 
421 	u8 pm_mode;		/* power management mode */
422 	u32 pm_period;		/* power management period in microseconds */
423 
424 	struct reg_domain const *domain;	/* reg domain description */
425 
426 	/* These fields contain HW config provided by the device (not all of
427 	 * these fields are used by all board types) */
428 	u8 mac_addr[ETH_ALEN];
429 	u8 regulatory_domain;
430 
431 	struct at76_card_config card_config;
432 
433 	enum board_type board_type;
434 	struct mib_fw_version fw_version;
435 
436 	unsigned int device_unplugged:1;
437 	unsigned int netdev_registered:1;
438 	struct set_mib_buffer mib_buf;	/* global buffer for set_mib calls */
439 
440 	int beacon_period;	/* period of mgmt beacons, Kus */
441 
442 	struct ieee80211_hw *hw;
443 	int mac80211_registered;
444 };
445 
446 #define AT76_SUPPORTED_FILTERS 0
447 
448 #define SCAN_POLL_INTERVAL	(HZ / 4)
449 
450 #define CMD_COMPLETION_TIMEOUT	(5 * HZ)
451 
452 #define DEF_RTS_THRESHOLD	1536
453 #define DEF_FRAG_THRESHOLD	1536
454 #define DEF_SHORT_RETRY_LIMIT	8
455 #define DEF_CHANNEL		10
456 #define DEF_SCAN_MIN_TIME	10
457 #define DEF_SCAN_MAX_TIME	120
458 
459 /* the max padding size for tx in bytes (see calc_padding) */
460 #define MAX_PADDING_SIZE	53
461 
462 #endif				/* _AT76_USB_H */
463