Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
0004  * All rights reserved.
0005  *
0006  * Purpose: MAC Data structure
0007  *
0008  * Author: Tevin Chen
0009  *
0010  * Date: Mar 17, 1997
0011  *
0012  */
0013 
0014 #ifndef __DEVICE_H__
0015 #define __DEVICE_H__
0016 
0017 #include <linux/bits.h>
0018 #include <linux/module.h>
0019 #include <linux/kernel.h>
0020 #include <linux/slab.h>
0021 #include <linux/delay.h>
0022 #include <linux/device.h>
0023 #include <linux/firmware.h>
0024 #include <linux/suspend.h>
0025 #include <linux/if_arp.h>
0026 #include <linux/wireless.h>
0027 #include <linux/timer.h>
0028 #include <linux/usb.h>
0029 #include <linux/crc32.h>
0030 #include <net/mac80211.h>
0031 
0032 #ifdef SIOCETHTOOL
0033 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
0034 #include <linux/ethtool.h>
0035 #else
0036 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
0037 #endif
0038 
0039 #define RATE_1M     0
0040 #define RATE_2M     1
0041 #define RATE_5M     2
0042 #define RATE_11M    3
0043 #define RATE_6M     4
0044 #define RATE_9M     5
0045 #define RATE_12M    6
0046 #define RATE_18M    7
0047 #define RATE_24M    8
0048 #define RATE_36M    9
0049 #define RATE_48M    10
0050 #define RATE_54M    11
0051 #define RATE_AUTO   12
0052 
0053 #define MAX_RATE            12
0054 #define VNT_B_RATES (BIT(RATE_1M) | BIT(RATE_2M) |\
0055             BIT(RATE_5M) | BIT(RATE_11M))
0056 
0057 /*
0058  * device specific
0059  */
0060 
0061 #include "wcmd.h"
0062 #include "desc.h"
0063 #include "key.h"
0064 #include "card.h"
0065 
0066 #define VNT_USB_VENDOR_ID                     0x160a
0067 #define VNT_USB_PRODUCT_ID                    0x3184
0068 
0069 #define DEVICE_NAME         "vt6656"
0070 #define DEVICE_FULL_DRV_NAM     "VIA Networking Wireless LAN USB Driver"
0071 
0072 #define DEVICE_VERSION          "mac80211"
0073 
0074 #define FIRMWARE_VERSION        0x133       /* version 1.51 */
0075 #define FIRMWARE_NAME           "vntwusb.fw"
0076 #define FIRMWARE_CHUNK_SIZE     0x400
0077 
0078 #define MAX_UINTS           8
0079 #define OPTION_DEFAULT          { [0 ... MAX_UINTS - 1] = -1}
0080 
0081 #define DUPLICATE_RX_CACHE_LENGTH       5
0082 
0083 #define AUTO_FB_NONE            0
0084 #define AUTO_FB_0               1
0085 #define AUTO_FB_1               2
0086 
0087 #define FB_RATE0                0
0088 #define FB_RATE1                1
0089 
0090 /* Antenna Mode */
0091 #define ANT_A                   0
0092 #define ANT_B                   1
0093 #define ANT_DIVERSITY           2
0094 #define ANT_RXD_TXA             3
0095 #define ANT_RXD_TXB             4
0096 #define ANT_UNKNOWN             0xFF
0097 #define ANT_TXA                 0
0098 #define ANT_TXB                 1
0099 #define ANT_RXA                 2
0100 #define ANT_RXB                 3
0101 
0102 #define BB_VGA_LEVEL            4
0103 #define BB_VGA_CHANGE_THRESHOLD 3
0104 
0105 #define EEP_MAX_CONTEXT_SIZE    256
0106 
0107 /* Contents in the EEPROM */
0108 #define EEP_OFS_PAR     0x0
0109 #define EEP_OFS_ANTENNA     0x17
0110 #define EEP_OFS_RADIOCTL    0x18
0111 #define EEP_OFS_RFTYPE      0x1b
0112 #define EEP_OFS_MINCHANNEL  0x1c
0113 #define EEP_OFS_MAXCHANNEL  0x1d
0114 #define EEP_OFS_SIGNATURE   0x1e
0115 #define EEP_OFS_ZONETYPE    0x1f
0116 #define EEP_OFS_RFTABLE     0x20
0117 #define EEP_OFS_PWR_CCK     0x20
0118 #define EEP_OFS_SETPT_CCK   0x21
0119 #define EEP_OFS_PWR_OFDMG   0x23
0120 
0121 #define EEP_OFS_CALIB_TX_IQ 0x24
0122 #define EEP_OFS_CALIB_TX_DC 0x25
0123 #define EEP_OFS_CALIB_RX_IQ 0x26
0124 
0125 #define EEP_OFS_MAJOR_VER   0x2e
0126 #define EEP_OFS_MINOR_VER   0x2f
0127 
0128 #define EEP_OFS_CCK_PWR_TBL 0x30
0129 #define EEP_OFS_OFDM_PWR_TBL    0x40
0130 #define EEP_OFS_OFDMA_PWR_TBL   0x50
0131 
0132 /* Bits in EEP_OFS_ANTENNA */
0133 #define EEP_ANTENNA_MAIN    BIT(0)
0134 #define EEP_ANTENNA_AUX     BIT(1)
0135 #define EEP_ANTINV      BIT(2)
0136 
0137 /* Bits in EEP_OFS_RADIOCTL */
0138 #define EEP_RADIOCTL_ENABLE BIT(7)
0139 
0140 /* control commands */
0141 #define MESSAGE_TYPE_READ       0x1
0142 #define MESSAGE_TYPE_WRITE      0x0
0143 #define MESSAGE_TYPE_LOCK_OR        0x2
0144 #define MESSAGE_TYPE_LOCK_AND       0x3
0145 #define MESSAGE_TYPE_WRITE_MASK     0x4
0146 #define MESSAGE_TYPE_CARDINIT       0x5
0147 #define MESSAGE_TYPE_INIT_RSP       0x6
0148 #define MESSAGE_TYPE_MACSHUTDOWN    0x7
0149 #define MESSAGE_TYPE_SETKEY     0x8
0150 #define MESSAGE_TYPE_CLRKEYENTRY    0x9
0151 #define MESSAGE_TYPE_WRITE_MISCFF   0xa
0152 #define MESSAGE_TYPE_SET_ANTMD      0xb
0153 #define MESSAGE_TYPE_SELECT_CHANNEL 0xc
0154 #define MESSAGE_TYPE_SET_TSFTBTT    0xd
0155 #define MESSAGE_TYPE_SET_SSTIFS     0xe
0156 #define MESSAGE_TYPE_CHANGE_BBTYPE  0xf
0157 #define MESSAGE_TYPE_DISABLE_PS     0x10
0158 #define MESSAGE_TYPE_WRITE_IFRF     0x11
0159 
0160 /* command read/write(index) */
0161 #define MESSAGE_REQUEST_MEM     0x1
0162 #define MESSAGE_REQUEST_BBREG       0x2
0163 #define MESSAGE_REQUEST_MACREG      0x3
0164 #define MESSAGE_REQUEST_EEPROM      0x4
0165 #define MESSAGE_REQUEST_TSF     0x5
0166 #define MESSAGE_REQUEST_TBTT        0x6
0167 #define MESSAGE_REQUEST_BBAGC       0x7
0168 #define MESSAGE_REQUEST_VERSION     0x8
0169 #define MESSAGE_REQUEST_RF_INIT     0x9
0170 #define MESSAGE_REQUEST_RF_INIT2    0xa
0171 #define MESSAGE_REQUEST_RF_CH0      0xb
0172 #define MESSAGE_REQUEST_RF_CH1      0xc
0173 #define MESSAGE_REQUEST_RF_CH2      0xd
0174 
0175 /* USB registers */
0176 #define USB_REG4            0x604
0177 
0178 #define DEVICE_INIT_COLD    0x0 /* cold init */
0179 #define DEVICE_INIT_RESET   0x1 /* reset init or Dx to D0 power remain */
0180 #define DEVICE_INIT_DXPL    0x2 /* Dx to D0 power lost init */
0181 
0182 /* Device init */
0183 struct vnt_cmd_card_init {
0184     u8 init_class;
0185     u8 exist_sw_net_addr;
0186     u8 sw_net_addr[6];
0187     u8 short_retry_limit;
0188     u8 long_retry_limit;
0189 };
0190 
0191 struct vnt_rsp_card_init {
0192     u8 status;
0193     u8 net_addr[6];
0194     u8 rf_type;
0195     u8 min_channel;
0196     u8 max_channel;
0197 };
0198 
0199 /* USB */
0200 
0201 /*
0202  * Enum of context types for SendPacket
0203  */
0204 enum {
0205     CONTEXT_DATA_PACKET = 0,
0206     CONTEXT_BEACON_PACKET
0207 };
0208 
0209 struct vnt_rx_header {
0210     u32 wbk_status;
0211     u8 rx_sts;
0212     u8 rx_rate;
0213     u16 pay_load_len;
0214 } __packed;
0215 
0216 struct vnt_rx_tail {
0217     __le64 tsf_time;
0218     u8 sq;
0219     u8 new_rsr;
0220     u8 rssi;
0221     u8 rsr;
0222     u8 sq_3;
0223 } __packed;
0224 
0225 /* RCB (Receive Control Block) */
0226 struct vnt_rcb {
0227     void *priv;
0228     struct urb *urb;
0229     struct sk_buff *skb;
0230 };
0231 
0232 /* used to track bulk out irps */
0233 struct vnt_usb_send_context {
0234     void *priv;
0235     struct sk_buff *skb;
0236     void *tx_buffer;
0237     u32 frame_len;
0238     u16 tx_hdr_size;
0239     u16 tx_rate;
0240     u8 type;
0241     u8 pkt_no;
0242     u8 pkt_type;
0243     bool in_use;
0244 };
0245 
0246 /*
0247  * Structure to keep track of USB interrupt packets
0248  */
0249 struct vnt_interrupt_buffer {
0250     u8 *data_buf;
0251 };
0252 
0253 /* flags for options */
0254 #define DEVICE_FLAGS_UNPLUG     0
0255 #define DEVICE_FLAGS_DISCONNECTED   1
0256 
0257 struct vnt_private {
0258     /* mac80211 */
0259     struct ieee80211_hw *hw;
0260     struct ieee80211_vif *vif;
0261     u8 mac_hw;
0262     /* netdev */
0263     struct usb_device *usb;
0264     struct usb_interface *intf;
0265 
0266     u64 tsf_time;
0267 
0268     u32 rx_buf_sz;
0269     int mc_list_count;
0270 
0271     spinlock_t lock;        /* prepare tx USB URB */
0272     struct mutex usb_lock;      /* USB control messages */
0273 
0274     unsigned long flags;
0275 
0276     /* USB */
0277     struct urb *interrupt_urb;
0278     u32 int_interval;
0279 
0280     /* Variables to track resources for the BULK In Pipe */
0281     struct vnt_rcb *rcb[CB_MAX_RX_DESC];
0282     u32 num_rcb;
0283 
0284     /* Variables to track resources for the BULK Out Pipe */
0285     struct vnt_usb_send_context *tx_context[CB_MAX_TX_DESC];
0286     struct usb_anchor tx_submitted;
0287     u32 num_tx_context;
0288 
0289     /* Variables to track resources for the Interrupt In Pipe */
0290     struct vnt_interrupt_buffer int_buf;
0291 
0292     /* Version control */
0293     u16 firmware_version;
0294     u8 local_id;
0295     u8 rf_type;
0296     u8 bb_rx_conf;
0297 
0298     struct vnt_cmd_card_init init_command;
0299     struct vnt_rsp_card_init init_response;
0300     u8 current_net_addr[ETH_ALEN] __aligned(2);
0301     u8 permanent_net_addr[ETH_ALEN] __aligned(2);
0302 
0303     u8 exist_sw_net_addr;
0304 
0305     u64 current_tsf;
0306 
0307     /* 802.11 MAC specific */
0308     u32 current_rssi;
0309 
0310     /* Antenna Diversity */
0311     int tx_rx_ant_inv;
0312     u32 rx_antenna_sel;
0313     u8 rx_antenna_mode;
0314     u8 tx_antenna_mode;
0315     u8 radio_ctl;
0316 
0317     /* IFS & Cw */
0318     u32 sifs;  /* Current SIFS */
0319     u32 difs;  /* Current DIFS */
0320     u32 eifs;  /* Current EIFS */
0321     u32 slot;  /* Current SlotTime */
0322 
0323     /* Rate */
0324     u8 bb_type; /* 0: 11A, 1:11B, 2:11G */
0325     u8 packet_type; /* 0:11a 1:11b 2:11gb 3:11ga */
0326     u32 basic_rates;
0327     u8 top_ofdm_basic_rate;
0328     u8 top_cck_basic_rate;
0329 
0330     u8 eeprom[EEP_MAX_CONTEXT_SIZE];  /*u32 alignment */
0331 
0332     u8 preamble_type;
0333 
0334     /* For RF Power table */
0335     u8 cck_pwr;
0336     u8 ofdm_pwr_g;
0337     u8 ofdm_pwr_a;
0338     u8 power;
0339     u8 cck_pwr_tbl[14];
0340     u8 ofdm_pwr_tbl[14];
0341     u8 ofdm_a_pwr_tbl[42];
0342 
0343     u16 tx_rate_fb0;
0344     u16 tx_rate_fb1;
0345 
0346     enum nl80211_iftype op_mode;
0347 
0348     int short_slot_time;
0349 
0350     /* Power save */
0351     u16 current_aid;
0352 
0353     /* Beacon related */
0354     u16 seq_counter;
0355 
0356     enum vnt_cmd_state command_state;
0357 
0358     enum vnt_cmd command;
0359 
0360     /* 802.11 counter */
0361 
0362     enum vnt_cmd cmd_queue[CMD_Q_SIZE];
0363     u32 cmd_dequeue_idx;
0364     u32 cmd_enqueue_idx;
0365     u32 free_cmd_queue;
0366     int cmd_running;
0367 
0368     unsigned long key_entry_inuse;
0369 
0370     u8 auto_fb_ctrl;
0371 
0372     /* For Update BaseBand VGA Gain Offset */
0373     u8 bb_vga[BB_VGA_LEVEL];
0374 
0375     u8 bb_pre_ed_rssi;
0376     u8 bb_pre_ed_index;
0377 
0378     /* command timer */
0379     struct delayed_work run_command_work;
0380 
0381     struct ieee80211_low_level_stats low_stats;
0382 };
0383 
0384 int vnt_init(struct vnt_private *priv);
0385 
0386 #endif