• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
4  * All rights reserved.
5  *
6  * Purpose: MAC Data structure
7  *
8  * Author: Tevin Chen
9  *
10  * Date: Mar 17, 1997
11  *
12  */
13 
14 #ifndef __DEVICE_H__
15 #define __DEVICE_H__
16 
17 #include <linux/bits.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
22 #include <linux/device.h>
23 #include <linux/firmware.h>
24 #include <linux/suspend.h>
25 #include <linux/if_arp.h>
26 #include <linux/wireless.h>
27 #include <linux/timer.h>
28 #include <linux/usb.h>
29 #include <linux/crc32.h>
30 #include <net/mac80211.h>
31 
32 #ifdef SIOCETHTOOL
33 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
34 #include <linux/ethtool.h>
35 #else
36 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
37 #endif
38 
39 #define RATE_1M		0
40 #define RATE_2M		1
41 #define RATE_5M		2
42 #define RATE_11M	3
43 #define RATE_6M		4
44 #define RATE_9M		5
45 #define RATE_12M	6
46 #define RATE_18M	7
47 #define RATE_24M	8
48 #define RATE_36M	9
49 #define RATE_48M	10
50 #define RATE_54M	11
51 #define RATE_AUTO	12
52 
53 #define MAX_RATE			12
54 #define VNT_B_RATES	(BIT(RATE_1M) | BIT(RATE_2M) |\
55 			BIT(RATE_5M) | BIT(RATE_11M))
56 
57 /*
58  * device specific
59  */
60 
61 #include "wcmd.h"
62 #include "desc.h"
63 #include "key.h"
64 #include "card.h"
65 
66 #define VNT_USB_VENDOR_ID                     0x160a
67 #define VNT_USB_PRODUCT_ID                    0x3184
68 
69 #define DEVICE_NAME			"vt6656"
70 #define DEVICE_FULL_DRV_NAM		"VIA Networking Wireless LAN USB Driver"
71 
72 #define DEVICE_VERSION			"mac80211"
73 
74 #define FIRMWARE_VERSION		0x133		/* version 1.51 */
75 #define FIRMWARE_NAME			"vntwusb.fw"
76 #define FIRMWARE_CHUNK_SIZE		0x400
77 
78 #define MAX_UINTS			8
79 #define OPTION_DEFAULT			{ [0 ... MAX_UINTS - 1] = -1}
80 
81 #define DUPLICATE_RX_CACHE_LENGTH       5
82 
83 #define AUTO_FB_NONE            0
84 #define AUTO_FB_0               1
85 #define AUTO_FB_1               2
86 
87 #define FB_RATE0                0
88 #define FB_RATE1                1
89 
90 /* Antenna Mode */
91 #define ANT_A                   0
92 #define ANT_B                   1
93 #define ANT_DIVERSITY           2
94 #define ANT_RXD_TXA             3
95 #define ANT_RXD_TXB             4
96 #define ANT_UNKNOWN             0xFF
97 #define ANT_TXA                 0
98 #define ANT_TXB                 1
99 #define ANT_RXA                 2
100 #define ANT_RXB                 3
101 
102 #define BB_VGA_LEVEL            4
103 #define BB_VGA_CHANGE_THRESHOLD 3
104 
105 #define EEP_MAX_CONTEXT_SIZE    256
106 
107 /* Contents in the EEPROM */
108 #define EEP_OFS_PAR		0x0
109 #define EEP_OFS_ANTENNA		0x17
110 #define EEP_OFS_RADIOCTL	0x18
111 #define EEP_OFS_RFTYPE		0x1b
112 #define EEP_OFS_MINCHANNEL	0x1c
113 #define EEP_OFS_MAXCHANNEL	0x1d
114 #define EEP_OFS_SIGNATURE	0x1e
115 #define EEP_OFS_ZONETYPE	0x1f
116 #define EEP_OFS_RFTABLE		0x20
117 #define EEP_OFS_PWR_CCK		0x20
118 #define EEP_OFS_SETPT_CCK	0x21
119 #define EEP_OFS_PWR_OFDMG	0x23
120 
121 #define EEP_OFS_CALIB_TX_IQ	0x24
122 #define EEP_OFS_CALIB_TX_DC	0x25
123 #define EEP_OFS_CALIB_RX_IQ	0x26
124 
125 #define EEP_OFS_MAJOR_VER	0x2e
126 #define EEP_OFS_MINOR_VER	0x2f
127 
128 #define EEP_OFS_CCK_PWR_TBL	0x30
129 #define EEP_OFS_OFDM_PWR_TBL	0x40
130 #define EEP_OFS_OFDMA_PWR_TBL	0x50
131 
132 /* Bits in EEP_OFS_ANTENNA */
133 #define EEP_ANTENNA_MAIN	BIT(0)
134 #define EEP_ANTENNA_AUX		BIT(1)
135 #define EEP_ANTINV		BIT(2)
136 
137 /* Bits in EEP_OFS_RADIOCTL */
138 #define EEP_RADIOCTL_ENABLE	BIT(7)
139 
140 /* control commands */
141 #define MESSAGE_TYPE_READ		0x1
142 #define MESSAGE_TYPE_WRITE		0x0
143 #define MESSAGE_TYPE_LOCK_OR		0x2
144 #define MESSAGE_TYPE_LOCK_AND		0x3
145 #define MESSAGE_TYPE_WRITE_MASK		0x4
146 #define MESSAGE_TYPE_CARDINIT		0x5
147 #define MESSAGE_TYPE_INIT_RSP		0x6
148 #define MESSAGE_TYPE_MACSHUTDOWN	0x7
149 #define MESSAGE_TYPE_SETKEY		0x8
150 #define MESSAGE_TYPE_CLRKEYENTRY	0x9
151 #define MESSAGE_TYPE_WRITE_MISCFF	0xa
152 #define MESSAGE_TYPE_SET_ANTMD		0xb
153 #define MESSAGE_TYPE_SELECT_CHANNEL	0xc
154 #define MESSAGE_TYPE_SET_TSFTBTT	0xd
155 #define MESSAGE_TYPE_SET_SSTIFS		0xe
156 #define MESSAGE_TYPE_CHANGE_BBTYPE	0xf
157 #define MESSAGE_TYPE_DISABLE_PS		0x10
158 #define MESSAGE_TYPE_WRITE_IFRF		0x11
159 
160 /* command read/write(index) */
161 #define MESSAGE_REQUEST_MEM		0x1
162 #define MESSAGE_REQUEST_BBREG		0x2
163 #define MESSAGE_REQUEST_MACREG		0x3
164 #define MESSAGE_REQUEST_EEPROM		0x4
165 #define MESSAGE_REQUEST_TSF		0x5
166 #define MESSAGE_REQUEST_TBTT		0x6
167 #define MESSAGE_REQUEST_BBAGC		0x7
168 #define MESSAGE_REQUEST_VERSION		0x8
169 #define MESSAGE_REQUEST_RF_INIT		0x9
170 #define MESSAGE_REQUEST_RF_INIT2	0xa
171 #define MESSAGE_REQUEST_RF_CH0		0xb
172 #define MESSAGE_REQUEST_RF_CH1		0xc
173 #define MESSAGE_REQUEST_RF_CH2		0xd
174 
175 /* USB registers */
176 #define USB_REG4			0x604
177 
178 #define DEVICE_INIT_COLD	0x0 /* cold init */
179 #define DEVICE_INIT_RESET	0x1 /* reset init or Dx to D0 power remain */
180 #define DEVICE_INIT_DXPL	0x2 /* Dx to D0 power lost init */
181 
182 /* Device init */
183 struct vnt_cmd_card_init {
184 	u8 init_class;
185 	u8 exist_sw_net_addr;
186 	u8 sw_net_addr[6];
187 	u8 short_retry_limit;
188 	u8 long_retry_limit;
189 };
190 
191 struct vnt_rsp_card_init {
192 	u8 status;
193 	u8 net_addr[6];
194 	u8 rf_type;
195 	u8 min_channel;
196 	u8 max_channel;
197 };
198 
199 /* USB */
200 
201 /*
202  * Enum of context types for SendPacket
203  */
204 enum {
205 	CONTEXT_DATA_PACKET = 0,
206 	CONTEXT_BEACON_PACKET
207 };
208 
209 struct vnt_rx_header {
210 	u32 wbk_status;
211 	u8 rx_sts;
212 	u8 rx_rate;
213 	u16 pay_load_len;
214 } __packed;
215 
216 struct vnt_rx_tail {
217 	__le64 tsf_time;
218 	u8 sq;
219 	u8 new_rsr;
220 	u8 rssi;
221 	u8 rsr;
222 	u8 sq_3;
223 } __packed;
224 
225 /* RCB (Receive Control Block) */
226 struct vnt_rcb {
227 	void *priv;
228 	struct urb *urb;
229 	struct sk_buff *skb;
230 };
231 
232 /* used to track bulk out irps */
233 struct vnt_usb_send_context {
234 	void *priv;
235 	struct sk_buff *skb;
236 	void *tx_buffer;
237 	u32 frame_len;
238 	u16 tx_hdr_size;
239 	u16 tx_rate;
240 	u8 type;
241 	u8 pkt_no;
242 	u8 pkt_type;
243 	bool in_use;
244 };
245 
246 /*
247  * Structure to keep track of USB interrupt packets
248  */
249 struct vnt_interrupt_buffer {
250 	u8 *data_buf;
251 };
252 
253 /* flags for options */
254 #define DEVICE_FLAGS_UNPLUG		0
255 #define DEVICE_FLAGS_DISCONNECTED	1
256 
257 struct vnt_private {
258 	/* mac80211 */
259 	struct ieee80211_hw *hw;
260 	struct ieee80211_vif *vif;
261 	u8 mac_hw;
262 	/* netdev */
263 	struct usb_device *usb;
264 	struct usb_interface *intf;
265 
266 	u64 tsf_time;
267 
268 	u32 rx_buf_sz;
269 	int mc_list_count;
270 
271 	spinlock_t lock;		/* prepare tx USB URB */
272 	struct mutex usb_lock;		/* USB control messages */
273 
274 	unsigned long flags;
275 
276 	/* USB */
277 	struct urb *interrupt_urb;
278 	u32 int_interval;
279 
280 	/* Variables to track resources for the BULK In Pipe */
281 	struct vnt_rcb *rcb[CB_MAX_RX_DESC];
282 	u32 num_rcb;
283 
284 	/* Variables to track resources for the BULK Out Pipe */
285 	struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
286 	struct usb_anchor tx_submitted;
287 	u32 num_tx_context;
288 
289 	/* Variables to track resources for the Interrupt In Pipe */
290 	struct vnt_interrupt_buffer int_buf;
291 
292 	/* Version control */
293 	u16 firmware_version;
294 	u8 local_id;
295 	u8 rf_type;
296 	u8 bb_rx_conf;
297 
298 	struct vnt_cmd_card_init init_command;
299 	struct vnt_rsp_card_init init_response;
300 	u8 current_net_addr[ETH_ALEN] __aligned(2);
301 	u8 permanent_net_addr[ETH_ALEN] __aligned(2);
302 
303 	u8 exist_sw_net_addr;
304 
305 	u64 current_tsf;
306 
307 	/* 802.11 MAC specific */
308 	u32 current_rssi;
309 
310 	/* Antenna Diversity */
311 	int tx_rx_ant_inv;
312 	u32 rx_antenna_sel;
313 	u8 rx_antenna_mode;
314 	u8 tx_antenna_mode;
315 	u8 radio_ctl;
316 
317 	/* IFS & Cw */
318 	u32 sifs;  /* Current SIFS */
319 	u32 difs;  /* Current DIFS */
320 	u32 eifs;  /* Current EIFS */
321 	u32 slot;  /* Current SlotTime */
322 
323 	/* Rate */
324 	u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
325 	u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
326 	u32 basic_rates;
327 	u8 top_ofdm_basic_rate;
328 	u8 top_cck_basic_rate;
329 
330 	u8 eeprom[EEP_MAX_CONTEXT_SIZE];  /*u32 alignment */
331 
332 	u8 preamble_type;
333 
334 	/* For RF Power table */
335 	u8 cck_pwr;
336 	u8 ofdm_pwr_g;
337 	u8 ofdm_pwr_a;
338 	u8 power;
339 	u8 cck_pwr_tbl[14];
340 	u8 ofdm_pwr_tbl[14];
341 	u8 ofdm_a_pwr_tbl[42];
342 
343 	u16 tx_rate_fb0;
344 	u16 tx_rate_fb1;
345 
346 	enum nl80211_iftype op_mode;
347 
348 	int short_slot_time;
349 
350 	/* Power save */
351 	u16 current_aid;
352 
353 	/* Beacon related */
354 	u16 seq_counter;
355 
356 	enum vnt_cmd_state command_state;
357 
358 	enum vnt_cmd command;
359 
360 	/* 802.11 counter */
361 
362 	enum vnt_cmd cmd_queue[CMD_Q_SIZE];
363 	u32 cmd_dequeue_idx;
364 	u32 cmd_enqueue_idx;
365 	u32 free_cmd_queue;
366 	int cmd_running;
367 
368 	unsigned long key_entry_inuse;
369 
370 	u8 auto_fb_ctrl;
371 
372 	/* For Update BaseBand VGA Gain Offset */
373 	u8 bb_vga[BB_VGA_LEVEL];
374 
375 	u8 bb_pre_ed_rssi;
376 	u8 bb_pre_ed_index;
377 
378 	/* command timer */
379 	struct delayed_work run_command_work;
380 
381 	struct ieee80211_low_level_stats low_stats;
382 };
383 
384 int vnt_init(struct vnt_private *priv);
385 
386 #endif
387