staging: vt6656: move need_ack into into vnt_usb_send_context
[linux-block.git] / drivers / staging / vt6656 / device.h
CommitLineData
92b96797
FB
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
92b96797 32#include <linux/module.h>
92b96797 33#include <linux/kernel.h>
92b96797 34#include <linux/slab.h>
11d404cb
MP
35#include <linux/delay.h>
36#include <linux/device.h>
37#include <linux/firmware.h>
11d404cb 38#include <linux/suspend.h>
92b96797 39#include <linux/if_arp.h>
11d404cb 40#include <linux/wireless.h>
11d404cb 41#include <linux/timer.h>
92b96797 42#include <linux/usb.h>
f0fde117 43#include <linux/crc32.h>
63b9907f 44#include <net/mac80211.h>
11d404cb 45
92b96797
FB
46#ifdef SIOCETHTOOL
47#define DEVICE_ETHTOOL_IOCTL_SUPPORT
48#include <linux/ethtool.h>
49#else
50#undef DEVICE_ETHTOOL_IOCTL_SUPPORT
51#endif
92b96797 52
f07e9fb2
MP
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
4aeaf153
MP
67#define MAX_RATE 12
68
d3e23951
AM
69/*
70 * device specific
71 */
92b96797 72
92b96797 73#include "wcmd.h"
92b96797 74#include "desc.h"
92b96797 75#include "key.h"
92b96797 76#include "card.h"
92b96797 77
5008c456 78#define VNT_USB_VENDOR_ID 0x160a
92b96797
FB
79#define VNT_USB_PRODUCT_ID 0x3184
80
4aeaf153
MP
81#define DEVICE_NAME "vt6656"
82#define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
83
84#define DEVICE_VERSION "1.19_12"
85
86#define CONFIG_PATH "/etc/vntconfiguration.dat"
87
88#define MAX_UINTS 8
89#define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1}
90
92b96797
FB
91#define DUPLICATE_RX_CACHE_LENGTH 5
92
92b96797
FB
93#define AUTO_FB_NONE 0
94#define AUTO_FB_0 1
95#define AUTO_FB_1 2
96
97#define FB_RATE0 0
98#define FB_RATE1 1
99
d3e23951 100/* Antenna Mode */
92b96797
FB
101#define ANT_A 0
102#define ANT_B 1
103#define ANT_DIVERSITY 2
104#define ANT_RXD_TXA 3
105#define ANT_RXD_TXB 4
106#define ANT_UNKNOWN 0xFF
107#define ANT_TXA 0
108#define ANT_TXB 1
109#define ANT_RXA 2
110#define ANT_RXB 3
111
92b96797
FB
112#define BB_VGA_LEVEL 4
113#define BB_VGA_CHANGE_THRESHOLD 3
114
15baf4ff
MP
115#define EEP_MAX_CONTEXT_SIZE 256
116
117/* Contents in the EEPROM */
118#define EEP_OFS_PAR 0x0
119#define EEP_OFS_ANTENNA 0x17
120#define EEP_OFS_RADIOCTL 0x18
121#define EEP_OFS_RFTYPE 0x1b
122#define EEP_OFS_MINCHANNEL 0x1c
123#define EEP_OFS_MAXCHANNEL 0x1d
124#define EEP_OFS_SIGNATURE 0x1e
125#define EEP_OFS_ZONETYPE 0x1f
126#define EEP_OFS_RFTABLE 0x20
127#define EEP_OFS_PWR_CCK 0x20
128#define EEP_OFS_SETPT_CCK 0x21
129#define EEP_OFS_PWR_OFDMG 0x23
130
131#define EEP_OFS_CALIB_TX_IQ 0x24
132#define EEP_OFS_CALIB_TX_DC 0x25
133#define EEP_OFS_CALIB_RX_IQ 0x26
134
135#define EEP_OFS_MAJOR_VER 0x2e
136#define EEP_OFS_MINOR_VER 0x2f
137
138#define EEP_OFS_CCK_PWR_TBL 0x30
139#define EEP_OFS_OFDM_PWR_TBL 0x40
140#define EEP_OFS_OFDMA_PWR_TBL 0x50
141
142/* Bits in EEP_OFS_ANTENNA */
143#define EEP_ANTENNA_MAIN 0x1
144#define EEP_ANTENNA_AUX 0x2
145#define EEP_ANTINV 0x4
146
147/* Bits in EEP_OFS_RADIOCTL */
148#define EEP_RADIOCTL_ENABLE 0x80
149
60f8ce8d
MP
150/* control commands */
151#define MESSAGE_TYPE_READ 0x1
152#define MESSAGE_TYPE_WRITE 0x0
153#define MESSAGE_TYPE_LOCK_OR 0x2
154#define MESSAGE_TYPE_LOCK_AND 0x3
155#define MESSAGE_TYPE_WRITE_MASK 0x4
156#define MESSAGE_TYPE_CARDINIT 0x5
157#define MESSAGE_TYPE_INIT_RSP 0x6
158#define MESSAGE_TYPE_MACSHUTDOWN 0x7
159#define MESSAGE_TYPE_SETKEY 0x8
160#define MESSAGE_TYPE_CLRKEYENTRY 0x9
161#define MESSAGE_TYPE_WRITE_MISCFF 0xa
162#define MESSAGE_TYPE_SET_ANTMD 0xb
163#define MESSAGE_TYPE_SELECT_CHANNLE 0xc
164#define MESSAGE_TYPE_SET_TSFTBTT 0xd
165#define MESSAGE_TYPE_SET_SSTIFS 0xe
166#define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
167#define MESSAGE_TYPE_DISABLE_PS 0x10
168#define MESSAGE_TYPE_WRITE_IFRF 0x11
169
170/* command read/write(index) */
171#define MESSAGE_REQUEST_MEM 0x1
172#define MESSAGE_REQUEST_BBREG 0x2
173#define MESSAGE_REQUEST_MACREG 0x3
174#define MESSAGE_REQUEST_EEPROM 0x4
175#define MESSAGE_REQUEST_TSF 0x5
176#define MESSAGE_REQUEST_TBTT 0x6
177#define MESSAGE_REQUEST_BBAGC 0x7
178#define MESSAGE_REQUEST_VERSION 0x8
179#define MESSAGE_REQUEST_RF_INIT 0x9
180#define MESSAGE_REQUEST_RF_INIT2 0xa
181#define MESSAGE_REQUEST_RF_CH0 0xb
182#define MESSAGE_REQUEST_RF_CH1 0xc
183#define MESSAGE_REQUEST_RF_CH2 0xd
184
185/* USB registers */
186#define USB_REG4 0x604
187
302433da
MP
188#define DEVICE_INIT_COLD 0x0 /* cold init */
189#define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
190#define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
92b96797 191
60f8ce8d
MP
192/* Device init */
193struct vnt_cmd_card_init {
194 u8 init_class;
195 u8 exist_sw_net_addr;
196 u8 sw_net_addr[6];
197 u8 short_retry_limit;
198 u8 long_retry_limit;
199};
200
201struct vnt_rsp_card_init {
202 u8 status;
203 u8 net_addr[6];
204 u8 rf_type;
205 u8 min_channel;
206 u8 max_channel;
207};
208
d3e23951 209/* USB */
92b96797 210
d3e23951
AM
211/*
212 * Enum of context types for SendPacket
213 */
1450ba62
MP
214enum {
215 CONTEXT_DATA_PACKET = 1,
d38b13aa
MP
216 CONTEXT_MGMT_PACKET,
217 CONTEXT_BEACON_PACKET
1450ba62 218};
92b96797 219
d3e23951 220/* RCB (Receive Control Block) */
115cac2e 221struct vnt_rcb {
325de984
MP
222 void *priv;
223 struct urb *urb;
dd0a774f 224 struct sk_buff *skb;
325de984 225 int in_use;
115cac2e 226};
92b96797 227
d3e23951 228/* used to track bulk out irps */
dcdf1d03 229struct vnt_usb_send_context {
30a05b39
MP
230 void *priv;
231 struct sk_buff *skb;
232 struct urb *urb;
1622c8fc 233 struct ieee80211_hdr *hdr;
30a05b39 234 unsigned int buf_len;
1622c8fc 235 u16 tx_hdr_size;
1450ba62 236 u8 type;
71d764ae 237 u8 pkt_no;
e8c9875c 238 u8 pkt_type;
2eca8dbb 239 u8 need_ack;
71d764ae 240 u8 fb_option;
30a05b39
MP
241 bool in_use;
242 unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
dcdf1d03 243};
92b96797 244
d3e23951
AM
245/*
246 * Structure to keep track of USB interrupt packets
247 */
f764e00d
MP
248struct vnt_interrupt_buffer {
249 u8 *data_buf;
250 bool in_use;
251};
92b96797 252
d3e23951 253/*++ NDIS related */
92b96797 254
879be45a
PST
255enum {
256 STATUS_SUCCESS = 0,
257 STATUS_FAILURE,
258 STATUS_RESOURCES,
259 STATUS_PENDING,
260};
92b96797 261
d3e23951 262/* flags for options */
92b96797 263#define DEVICE_FLAGS_UNPLUG 0x00000001UL
92b96797 264
d3e23951 265/* flags for driver status */
92b96797 266#define DEVICE_FLAGS_OPENED 0x00010000UL
92b96797 267
14c5ef57 268struct vnt_private {
63b9907f
MP
269 /* mac80211 */
270 struct ieee80211_hw *hw;
db8f37fa 271 struct ieee80211_vif *vif;
30816f83 272 u8 mac_hw;
61462ab3
MP
273 /* netdev */
274 struct usb_device *usb;
92b96797 275
63b9907f
MP
276 u64 tsf_time;
277 u8 rx_rate;
278
61462ab3 279 u32 rx_buf_sz;
db8f37fa 280 int mc_list_count;
92b96797 281
61462ab3 282 spinlock_t lock;
c91b1869 283 struct mutex usb_lock;
92b96797 284
61462ab3
MP
285 u32 flags;
286 unsigned long Flags;
92b96797 287
61462ab3 288 /* USB */
3d582487 289 struct urb *interrupt_urb;
61462ab3 290 u32 int_interval;
92b96797 291
61462ab3 292 /* Variables to track resources for the BULK In Pipe */
8577011c 293 struct vnt_rcb *rcb[CB_MAX_RX_DESC];
6da4738f 294 u32 num_rcb;
92b96797 295
61462ab3 296 /* Variables to track resources for the BULK Out Pipe */
f7e4a8f4 297 struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
03b7e354 298 u32 num_tx_context;
92b96797 299
61462ab3 300 /* Variables to track resources for the Interrupt In Pipe */
f764e00d 301 struct vnt_interrupt_buffer int_buf;
92b96797 302
61462ab3 303 /* Version control */
8a73f9da 304 u16 firmware_version;
f1945a15 305 u8 local_id;
6242ecae 306 u8 rf_type;
cd5856ae 307 u8 bb_rx_conf;
92b96797 308
748bf69c
MP
309 struct vnt_cmd_card_init init_command;
310 struct vnt_rsp_card_init init_response;
ebf9b312 311 u8 current_net_addr[ETH_ALEN];
41e8321a 312 u8 permanent_net_addr[ETH_ALEN];
92b96797 313
35cc8f94 314 u8 exist_sw_net_addr;
92b96797 315
113f0b91 316 u64 current_tsf;
61462ab3
MP
317
318 /* 802.11 MAC specific */
125cfc63 319 u32 current_rssi;
61462ab3
MP
320
321 /* Antenna Diversity */
2044dbdb
MP
322 int tx_rx_ant_inv;
323 u32 rx_antenna_sel;
324 u8 rx_antenna_mode;
325 u8 tx_antenna_mode;
326 u8 radio_ctl;
61462ab3 327
cc856e61 328 /* IFS & Cw */
ff5fee22
MP
329 u32 sifs; /* Current SIFS */
330 u32 difs; /* Current DIFS */
331 u32 eifs; /* Current EIFS */
332 u32 slot; /* Current SlotTime */
61462ab3 333
61462ab3 334 /* Rate */
65df77e2 335 u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
e12471db 336 u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
93a73558 337 u32 basic_rates;
3c8a5b25 338 u8 top_ofdm_basic_rate;
d80bf43c 339 u8 top_cck_basic_rate;
61462ab3 340
bbb11263 341 u8 eeprom[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
61462ab3 342
98e93fe5 343 u8 preamble_type;
61462ab3
MP
344
345 /* For RF Power table */
5a97491c
MP
346 u8 cck_pwr;
347 u8 ofdm_pwr_g;
348 u8 ofdm_pwr_a;
349 u8 power;
350 u8 cck_pwr_tbl[14];
351 u8 ofdm_pwr_tbl[14];
352 u8 ofdm_a_pwr_tbl[42];
61462ab3 353
8b84c1da 354 u16 current_rate;
f84cdf65
MP
355 u16 tx_rate_fb0;
356 u16 tx_rate_fb1;
357
388e5cb8
MP
358 u8 short_retry_limit;
359 u8 long_retry_limit;
a0ad2776
MP
360
361 enum nl80211_iftype op_mode;
362
a641c9ec 363 int short_slot_time;
61462ab3 364
61462ab3 365 /* Power save */
db8f37fa 366 u16 current_aid;
61462ab3
MP
367
368 /* Beacon releated */
1b2bc0aa 369 u16 seq_counter;
61462ab3 370
ad74e91d 371 enum vnt_cmd_state command_state;
61462ab3 372
80f0d092 373 enum vnt_cmd command;
61462ab3 374
61462ab3
MP
375 /* 802.11 counter */
376
b595f9b8 377 enum vnt_cmd cmd_queue[CMD_Q_SIZE];
33a60b87
MP
378 u32 cmd_dequeue_idx;
379 u32 cmd_enqueue_idx;
380 u32 free_cmd_queue;
381 int cmd_running;
61462ab3 382
d1eb5003 383 unsigned long key_entry_inuse;
61462ab3 384
a6177aef 385 u8 auto_fb_ctrl;
61462ab3 386
61462ab3 387 /* For Update BaseBand VGA Gain Offset */
c37cbd37 388 u8 bb_vga[BB_VGA_LEVEL];
61462ab3 389
12687222 390 u8 bb_pre_ed_rssi;
43fd1924 391 u8 bb_pre_ed_index;
61462ab3 392
61462ab3 393 /* command timer */
94488a7e 394 struct delayed_work run_command_work;
92b96797 395
1786384e 396 struct ieee80211_low_level_stats low_stats;
14c5ef57 397};
92b96797 398
dbf0a03b
PST
399#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
400 if ((uVar) >= ((uModulo) - 1)) \
401 (uVar) = 0; \
402 else \
403 (uVar)++; \
92b96797
FB
404}
405
92b96797 406#define fMP_DISCONNECTED 0x00000002
92b96797
FB
407#define fMP_POST_READS 0x00000100
408#define fMP_POST_WRITES 0x00000200
92b96797 409
92b96797
FB
410#define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
411#define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
92b96797
FB
412#define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
413
d4f376dd 414#define MP_IS_READY(_M) (((_M)->Flags & fMP_DISCONNECTED) == 0)
92b96797 415
30816f83 416int vnt_init(struct vnt_private *priv);
92b96797
FB
417
418#endif