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