device.h 9.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * File: device.h
 *
 * Purpose: MAC Data structure
 *
 * Author: Tevin Chen
 *
 * Date: Mar 17, 1997
 *
 */

#ifndef __DEVICE_H__
#define __DEVICE_H__

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
35 36 37 38
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/firmware.h>
#include <linux/suspend.h>
39
#include <linux/if_arp.h>
40 41
#include <linux/wireless.h>
#include <linux/timer.h>
42
#include <linux/usb.h>
43
#include <linux/crc32.h>
44
#include <net/mac80211.h>
45

46 47 48 49 50 51 52
#ifdef SIOCETHTOOL
#define DEVICE_ETHTOOL_IOCTL_SUPPORT
#include <linux/ethtool.h>
#else
#undef DEVICE_ETHTOOL_IOCTL_SUPPORT
#endif

53 54 55 56 57 58 59 60 61 62 63 64 65 66
#define RATE_1M		0
#define RATE_2M		1
#define RATE_5M		2
#define RATE_11M	3
#define RATE_6M		4
#define RATE_9M		5
#define RATE_12M	6
#define RATE_18M	7
#define RATE_24M	8
#define RATE_36M	9
#define RATE_48M	10
#define RATE_54M	11
#define RATE_AUTO	12

67 68
#define MAX_RATE			12

69 70 71
/*
 * device specific
 */
72 73 74 75 76 77

#include "wcmd.h"
#include "desc.h"
#include "key.h"
#include "card.h"

78
#define VNT_USB_VENDOR_ID                     0x160a
79 80
#define VNT_USB_PRODUCT_ID                    0x3184

81 82 83 84 85 86 87 88 89 90
#define DEVICE_NAME			"vt6656"
#define DEVICE_FULL_DRV_NAM		"VIA Networking Wireless LAN USB Driver"

#define DEVICE_VERSION			"1.19_12"

#define CONFIG_PATH			"/etc/vntconfiguration.dat"

#define MAX_UINTS			8
#define OPTION_DEFAULT			{ [0 ... MAX_UINTS-1] = -1}

91 92 93 94 95 96 97 98 99
#define DUPLICATE_RX_CACHE_LENGTH       5

#define AUTO_FB_NONE            0
#define AUTO_FB_0               1
#define AUTO_FB_1               2

#define FB_RATE0                0
#define FB_RATE1                1

100
/* Antenna Mode */
101 102 103 104 105 106 107 108 109 110 111 112 113 114
#define ANT_A                   0
#define ANT_B                   1
#define ANT_DIVERSITY           2
#define ANT_RXD_TXA             3
#define ANT_RXD_TXB             4
#define ANT_UNKNOWN             0xFF
#define ANT_TXA                 0
#define ANT_TXB                 1
#define ANT_RXA                 2
#define ANT_RXB                 3

#define BB_VGA_LEVEL            4
#define BB_VGA_CHANGE_THRESHOLD 3

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
#define EEP_MAX_CONTEXT_SIZE    256

/* Contents in the EEPROM */
#define EEP_OFS_PAR		0x0
#define EEP_OFS_ANTENNA		0x17
#define EEP_OFS_RADIOCTL	0x18
#define EEP_OFS_RFTYPE		0x1b
#define EEP_OFS_MINCHANNEL	0x1c
#define EEP_OFS_MAXCHANNEL	0x1d
#define EEP_OFS_SIGNATURE	0x1e
#define EEP_OFS_ZONETYPE	0x1f
#define EEP_OFS_RFTABLE		0x20
#define EEP_OFS_PWR_CCK		0x20
#define EEP_OFS_SETPT_CCK	0x21
#define EEP_OFS_PWR_OFDMG	0x23

#define EEP_OFS_CALIB_TX_IQ	0x24
#define EEP_OFS_CALIB_TX_DC	0x25
#define EEP_OFS_CALIB_RX_IQ	0x26

#define EEP_OFS_MAJOR_VER	0x2e
#define EEP_OFS_MINOR_VER	0x2f

#define EEP_OFS_CCK_PWR_TBL	0x30
#define EEP_OFS_OFDM_PWR_TBL	0x40
#define EEP_OFS_OFDMA_PWR_TBL	0x50

/* Bits in EEP_OFS_ANTENNA */
#define EEP_ANTENNA_MAIN	0x1
#define EEP_ANTENNA_AUX		0x2
#define EEP_ANTINV		0x4

/* Bits in EEP_OFS_RADIOCTL */
#define EEP_RADIOCTL_ENABLE	0x80

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/* control commands */
#define MESSAGE_TYPE_READ		0x1
#define MESSAGE_TYPE_WRITE		0x0
#define MESSAGE_TYPE_LOCK_OR		0x2
#define MESSAGE_TYPE_LOCK_AND		0x3
#define MESSAGE_TYPE_WRITE_MASK		0x4
#define MESSAGE_TYPE_CARDINIT		0x5
#define MESSAGE_TYPE_INIT_RSP		0x6
#define MESSAGE_TYPE_MACSHUTDOWN	0x7
#define MESSAGE_TYPE_SETKEY		0x8
#define MESSAGE_TYPE_CLRKEYENTRY	0x9
#define MESSAGE_TYPE_WRITE_MISCFF	0xa
#define MESSAGE_TYPE_SET_ANTMD		0xb
#define MESSAGE_TYPE_SELECT_CHANNLE	0xc
#define MESSAGE_TYPE_SET_TSFTBTT	0xd
#define MESSAGE_TYPE_SET_SSTIFS		0xe
#define MESSAGE_TYPE_CHANGE_BBTYPE	0xf
#define MESSAGE_TYPE_DISABLE_PS		0x10
#define MESSAGE_TYPE_WRITE_IFRF		0x11

/* command read/write(index) */
#define MESSAGE_REQUEST_MEM		0x1
#define MESSAGE_REQUEST_BBREG		0x2
#define MESSAGE_REQUEST_MACREG		0x3
#define MESSAGE_REQUEST_EEPROM		0x4
#define MESSAGE_REQUEST_TSF		0x5
#define MESSAGE_REQUEST_TBTT		0x6
#define MESSAGE_REQUEST_BBAGC		0x7
#define MESSAGE_REQUEST_VERSION		0x8
#define MESSAGE_REQUEST_RF_INIT		0x9
#define MESSAGE_REQUEST_RF_INIT2	0xa
#define MESSAGE_REQUEST_RF_CH0		0xb
#define MESSAGE_REQUEST_RF_CH1		0xc
#define MESSAGE_REQUEST_RF_CH2		0xd

/* USB registers */
#define USB_REG4			0x604

188 189 190
#define DEVICE_INIT_COLD	0x0 /* cold init */
#define DEVICE_INIT_RESET	0x1 /* reset init or Dx to D0 power remain */
#define DEVICE_INIT_DXPL	0x2 /* Dx to D0 power lost init */
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
/* Device init */
struct vnt_cmd_card_init {
	u8 init_class;
	u8 exist_sw_net_addr;
	u8 sw_net_addr[6];
	u8 short_retry_limit;
	u8 long_retry_limit;
};

struct vnt_rsp_card_init {
	u8 status;
	u8 net_addr[6];
	u8 rf_type;
	u8 min_channel;
	u8 max_channel;
};

209
/* USB */
210

211 212 213
/*
 * Enum of context types for SendPacket
 */
214 215
enum {
	CONTEXT_DATA_PACKET = 1,
216 217
	CONTEXT_MGMT_PACKET,
	CONTEXT_BEACON_PACKET
218
};
219

220
/* RCB (Receive Control Block) */
221
struct vnt_rcb {
222 223
	void *priv;
	struct urb *urb;
224
	struct sk_buff *skb;
225
	int in_use;
226
};
227

228
/* used to track bulk out irps */
229
struct vnt_usb_send_context {
230 231 232
	void *priv;
	struct sk_buff *skb;
	struct urb *urb;
233
	struct ieee80211_hdr *hdr;
234
	unsigned int buf_len;
235
	u16 tx_hdr_size;
236
	u8 type;
237
	u8 pkt_no;
238
	u8 pkt_type;
239
	u8 need_ack;
240
	u8 fb_option;
241 242
	bool in_use;
	unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
243
};
244

245 246 247
/*
 * Structure to keep track of USB interrupt packets
 */
248 249 250 251
struct vnt_interrupt_buffer {
	u8 *data_buf;
	bool in_use;
};
252

253
/*++ NDIS related */
254

255 256 257 258 259 260
enum {
	STATUS_SUCCESS = 0,
	STATUS_FAILURE,
	STATUS_RESOURCES,
	STATUS_PENDING,
};
261

262
/* flags for options */
263 264
#define     DEVICE_FLAGS_UNPLUG          0x00000001UL

265
/* flags for driver status */
266 267
#define     DEVICE_FLAGS_OPENED          0x00010000UL

268
struct vnt_private {
269 270
	/* mac80211 */
	struct ieee80211_hw *hw;
271
	struct ieee80211_vif *vif;
272
	u8 mac_hw;
273 274
	/* netdev */
	struct usb_device *usb;
275

276 277 278
	u64 tsf_time;
	u8 rx_rate;

279
	u32 rx_buf_sz;
280
	int mc_list_count;
281

282
	spinlock_t lock;
283
	struct mutex usb_lock;
284

285 286
	u32 flags;
	unsigned long Flags;
287

288
	/* USB */
289
	struct urb *interrupt_urb;
290
	u32 int_interval;
291

292
	/* Variables to track resources for the BULK In Pipe */
293
	struct vnt_rcb *rcb[CB_MAX_RX_DESC];
294
	u32 num_rcb;
295

296
	/* Variables to track resources for the BULK Out Pipe */
297
	struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
298
	u32 num_tx_context;
299

300
	/* Variables to track resources for the Interrupt In Pipe */
301
	struct vnt_interrupt_buffer int_buf;
302

303
	/* Version control */
304
	u16 firmware_version;
305
	u8 local_id;
306
	u8 rf_type;
307
	u8 bb_rx_conf;
308

309 310
	struct vnt_cmd_card_init init_command;
	struct vnt_rsp_card_init init_response;
311
	u8 current_net_addr[ETH_ALEN];
312
	u8 permanent_net_addr[ETH_ALEN];
313

314
	u8 exist_sw_net_addr;
315

316
	u64 current_tsf;
317 318

	/* 802.11 MAC specific */
319
	u32 current_rssi;
320 321

	/* Antenna Diversity */
322 323 324 325 326
	int tx_rx_ant_inv;
	u32 rx_antenna_sel;
	u8 rx_antenna_mode;
	u8 tx_antenna_mode;
	u8 radio_ctl;
327

328
	/* IFS & Cw */
329 330 331 332
	u32 sifs;  /* Current SIFS */
	u32 difs;  /* Current DIFS */
	u32 eifs;  /* Current EIFS */
	u32 slot;  /* Current SlotTime */
333 334

	/* Rate */
335
	u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
336
	u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
337
	u32 basic_rates;
338
	u8 top_ofdm_basic_rate;
339
	u8 top_cck_basic_rate;
340

341
	u8 eeprom[EEP_MAX_CONTEXT_SIZE];  /*u32 alignment */
342

343
	u8 preamble_type;
344 345

	/* For RF Power table */
346 347 348 349 350 351 352
	u8 cck_pwr;
	u8 ofdm_pwr_g;
	u8 ofdm_pwr_a;
	u8 power;
	u8 cck_pwr_tbl[14];
	u8 ofdm_pwr_tbl[14];
	u8 ofdm_a_pwr_tbl[42];
353

354
	u16 current_rate;
355 356 357
	u16 tx_rate_fb0;
	u16 tx_rate_fb1;

358 359
	u8 short_retry_limit;
	u8 long_retry_limit;
360 361 362

	enum nl80211_iftype op_mode;

363
	int short_slot_time;
364 365

	/* Power save */
366
	u16 current_aid;
367 368

	/* Beacon releated */
369
	u16 seq_counter;
370

371
	enum vnt_cmd_state command_state;
372

373
	enum vnt_cmd command;
374 375 376

	/* 802.11 counter */

377
	enum vnt_cmd cmd_queue[CMD_Q_SIZE];
378 379 380 381
	u32 cmd_dequeue_idx;
	u32 cmd_enqueue_idx;
	u32 free_cmd_queue;
	int cmd_running;
382

383
	unsigned long key_entry_inuse;
384

385
	u8 auto_fb_ctrl;
386 387

	/* For Update BaseBand VGA Gain Offset */
388
	u8 bb_vga[BB_VGA_LEVEL];
389

390
	u8 bb_pre_ed_rssi;
391
	u8 bb_pre_ed_index;
392 393

	/* command timer */
394
	struct delayed_work run_command_work;
395

396
	struct ieee80211_low_level_stats low_stats;
397
};
398

399 400 401 402 403
#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {	\
	if ((uVar) >= ((uModulo) - 1))			\
		(uVar) = 0;				\
	else						\
		(uVar)++;				\
404 405 406 407 408 409 410 411 412 413
}

#define fMP_DISCONNECTED                    0x00000002
#define fMP_POST_READS                      0x00000100
#define fMP_POST_WRITES                     0x00000200

#define MP_SET_FLAG(_M, _F)             ((_M)->Flags |= (_F))
#define MP_CLEAR_FLAG(_M, _F)            ((_M)->Flags &= ~(_F))
#define MP_TEST_FLAGS(_M, _F)            (((_M)->Flags & (_F)) == (_F))

414
#define MP_IS_READY(_M)        (((_M)->Flags & fMP_DISCONNECTED) == 0)
415

416
int vnt_init(struct vnt_private *priv);
417 418

#endif