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