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