162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> 462306a36Sopenharmony_ci <http://rt2x00.serialmonkey.com> 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci/* 962306a36Sopenharmony_ci Module: rt73usb 1062306a36Sopenharmony_ci Abstract: rt73usb device specific routines. 1162306a36Sopenharmony_ci Supported chipsets: rt2571W & rt2671. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/crc-itu-t.h> 1562306a36Sopenharmony_ci#include <linux/delay.h> 1662306a36Sopenharmony_ci#include <linux/etherdevice.h> 1762306a36Sopenharmony_ci#include <linux/kernel.h> 1862306a36Sopenharmony_ci#include <linux/module.h> 1962306a36Sopenharmony_ci#include <linux/slab.h> 2062306a36Sopenharmony_ci#include <linux/usb.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#include "rt2x00.h" 2362306a36Sopenharmony_ci#include "rt2x00usb.h" 2462306a36Sopenharmony_ci#include "rt73usb.h" 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * Allow hardware encryption to be disabled. 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_cistatic bool modparam_nohwcrypt; 3062306a36Sopenharmony_cimodule_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444); 3162306a36Sopenharmony_ciMODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* 3462306a36Sopenharmony_ci * Register access. 3562306a36Sopenharmony_ci * All access to the CSR registers will go through the methods 3662306a36Sopenharmony_ci * rt2x00usb_register_read and rt2x00usb_register_write. 3762306a36Sopenharmony_ci * BBP and RF register require indirect register access, 3862306a36Sopenharmony_ci * and use the CSR registers BBPCSR and RFCSR to achieve this. 3962306a36Sopenharmony_ci * These indirect registers work with busy bits, 4062306a36Sopenharmony_ci * and we will try maximal REGISTER_BUSY_COUNT times to access 4162306a36Sopenharmony_ci * the register while taking a REGISTER_BUSY_DELAY us delay 4262306a36Sopenharmony_ci * between each attampt. When the busy bit is still set at that time, 4362306a36Sopenharmony_ci * the access attempt is considered to have failed, 4462306a36Sopenharmony_ci * and we will print an error. 4562306a36Sopenharmony_ci * The _lock versions must be used if you already hold the csr_mutex 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_ci#define WAIT_FOR_BBP(__dev, __reg) \ 4862306a36Sopenharmony_ci rt2x00usb_regbusy_read((__dev), PHY_CSR3, PHY_CSR3_BUSY, (__reg)) 4962306a36Sopenharmony_ci#define WAIT_FOR_RF(__dev, __reg) \ 5062306a36Sopenharmony_ci rt2x00usb_regbusy_read((__dev), PHY_CSR4, PHY_CSR4_BUSY, (__reg)) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_cistatic void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev, 5362306a36Sopenharmony_ci const unsigned int word, const u8 value) 5462306a36Sopenharmony_ci{ 5562306a36Sopenharmony_ci u32 reg; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci /* 6062306a36Sopenharmony_ci * Wait until the BBP becomes available, afterwards we 6162306a36Sopenharmony_ci * can safely write the new data into the register. 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_ci if (WAIT_FOR_BBP(rt2x00dev, ®)) { 6462306a36Sopenharmony_ci reg = 0; 6562306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_VALUE, value); 6662306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_REGNUM, word); 6762306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_BUSY, 1); 6862306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_READ_CONTROL, 0); 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); 7162306a36Sopenharmony_ci } 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 7462306a36Sopenharmony_ci} 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistatic u8 rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, 7762306a36Sopenharmony_ci const unsigned int word) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci u32 reg; 8062306a36Sopenharmony_ci u8 value; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci /* 8562306a36Sopenharmony_ci * Wait until the BBP becomes available, afterwards we 8662306a36Sopenharmony_ci * can safely write the read request into the register. 8762306a36Sopenharmony_ci * After the data has been written, we wait until hardware 8862306a36Sopenharmony_ci * returns the correct value, if at any time the register 8962306a36Sopenharmony_ci * doesn't become available in time, reg will be 0xffffffff 9062306a36Sopenharmony_ci * which means we return 0xff to the caller. 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ci if (WAIT_FOR_BBP(rt2x00dev, ®)) { 9362306a36Sopenharmony_ci reg = 0; 9462306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_REGNUM, word); 9562306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_BUSY, 1); 9662306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR3_READ_CONTROL, 1); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR3, reg); 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci WAIT_FOR_BBP(rt2x00dev, ®); 10162306a36Sopenharmony_ci } 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci value = rt2x00_get_field32(reg, PHY_CSR3_VALUE); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci return value; 10862306a36Sopenharmony_ci} 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistatic void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev, 11162306a36Sopenharmony_ci const unsigned int word, const u32 value) 11262306a36Sopenharmony_ci{ 11362306a36Sopenharmony_ci u32 reg; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci /* 11862306a36Sopenharmony_ci * Wait until the RF becomes available, afterwards we 11962306a36Sopenharmony_ci * can safely write the new data into the register. 12062306a36Sopenharmony_ci */ 12162306a36Sopenharmony_ci if (WAIT_FOR_RF(rt2x00dev, ®)) { 12262306a36Sopenharmony_ci reg = 0; 12362306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR4_VALUE, value); 12462306a36Sopenharmony_ci /* 12562306a36Sopenharmony_ci * RF5225 and RF2527 contain 21 bits per RF register value, 12662306a36Sopenharmony_ci * all others contain 20 bits. 12762306a36Sopenharmony_ci */ 12862306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR4_NUMBER_OF_BITS, 12962306a36Sopenharmony_ci 20 + (rt2x00_rf(rt2x00dev, RF5225) || 13062306a36Sopenharmony_ci rt2x00_rf(rt2x00dev, RF2527))); 13162306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR4_IF_SELECT, 0); 13262306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR4_BUSY, 1); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR4, reg); 13562306a36Sopenharmony_ci rt2x00_rf_write(rt2x00dev, word, value); 13662306a36Sopenharmony_ci } 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 13962306a36Sopenharmony_ci} 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS 14262306a36Sopenharmony_cistatic const struct rt2x00debug rt73usb_rt2x00debug = { 14362306a36Sopenharmony_ci .owner = THIS_MODULE, 14462306a36Sopenharmony_ci .csr = { 14562306a36Sopenharmony_ci .read = rt2x00usb_register_read, 14662306a36Sopenharmony_ci .write = rt2x00usb_register_write, 14762306a36Sopenharmony_ci .flags = RT2X00DEBUGFS_OFFSET, 14862306a36Sopenharmony_ci .word_base = CSR_REG_BASE, 14962306a36Sopenharmony_ci .word_size = sizeof(u32), 15062306a36Sopenharmony_ci .word_count = CSR_REG_SIZE / sizeof(u32), 15162306a36Sopenharmony_ci }, 15262306a36Sopenharmony_ci .eeprom = { 15362306a36Sopenharmony_ci .read = rt2x00_eeprom_read, 15462306a36Sopenharmony_ci .write = rt2x00_eeprom_write, 15562306a36Sopenharmony_ci .word_base = EEPROM_BASE, 15662306a36Sopenharmony_ci .word_size = sizeof(u16), 15762306a36Sopenharmony_ci .word_count = EEPROM_SIZE / sizeof(u16), 15862306a36Sopenharmony_ci }, 15962306a36Sopenharmony_ci .bbp = { 16062306a36Sopenharmony_ci .read = rt73usb_bbp_read, 16162306a36Sopenharmony_ci .write = rt73usb_bbp_write, 16262306a36Sopenharmony_ci .word_base = BBP_BASE, 16362306a36Sopenharmony_ci .word_size = sizeof(u8), 16462306a36Sopenharmony_ci .word_count = BBP_SIZE / sizeof(u8), 16562306a36Sopenharmony_ci }, 16662306a36Sopenharmony_ci .rf = { 16762306a36Sopenharmony_ci .read = rt2x00_rf_read, 16862306a36Sopenharmony_ci .write = rt73usb_rf_write, 16962306a36Sopenharmony_ci .word_base = RF_BASE, 17062306a36Sopenharmony_ci .word_size = sizeof(u32), 17162306a36Sopenharmony_ci .word_count = RF_SIZE / sizeof(u32), 17262306a36Sopenharmony_ci }, 17362306a36Sopenharmony_ci}; 17462306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_cistatic int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev) 17762306a36Sopenharmony_ci{ 17862306a36Sopenharmony_ci u32 reg; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR13); 18162306a36Sopenharmony_ci return rt2x00_get_field32(reg, MAC_CSR13_VAL7); 18262306a36Sopenharmony_ci} 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_LEDS 18562306a36Sopenharmony_cistatic void rt73usb_brightness_set(struct led_classdev *led_cdev, 18662306a36Sopenharmony_ci enum led_brightness brightness) 18762306a36Sopenharmony_ci{ 18862306a36Sopenharmony_ci struct rt2x00_led *led = 18962306a36Sopenharmony_ci container_of(led_cdev, struct rt2x00_led, led_dev); 19062306a36Sopenharmony_ci unsigned int enabled = brightness != LED_OFF; 19162306a36Sopenharmony_ci unsigned int a_mode = 19262306a36Sopenharmony_ci (enabled && led->rt2x00dev->curr_band == NL80211_BAND_5GHZ); 19362306a36Sopenharmony_ci unsigned int bg_mode = 19462306a36Sopenharmony_ci (enabled && led->rt2x00dev->curr_band == NL80211_BAND_2GHZ); 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci if (led->type == LED_TYPE_RADIO) { 19762306a36Sopenharmony_ci rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, 19862306a36Sopenharmony_ci MCU_LEDCS_RADIO_STATUS, enabled); 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, 20162306a36Sopenharmony_ci 0, led->rt2x00dev->led_mcu_reg, 20262306a36Sopenharmony_ci REGISTER_TIMEOUT); 20362306a36Sopenharmony_ci } else if (led->type == LED_TYPE_ASSOC) { 20462306a36Sopenharmony_ci rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, 20562306a36Sopenharmony_ci MCU_LEDCS_LINK_BG_STATUS, bg_mode); 20662306a36Sopenharmony_ci rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg, 20762306a36Sopenharmony_ci MCU_LEDCS_LINK_A_STATUS, a_mode); 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ci rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, 21062306a36Sopenharmony_ci 0, led->rt2x00dev->led_mcu_reg, 21162306a36Sopenharmony_ci REGISTER_TIMEOUT); 21262306a36Sopenharmony_ci } else if (led->type == LED_TYPE_QUALITY) { 21362306a36Sopenharmony_ci /* 21462306a36Sopenharmony_ci * The brightness is divided into 6 levels (0 - 5), 21562306a36Sopenharmony_ci * this means we need to convert the brightness 21662306a36Sopenharmony_ci * argument into the matching level within that range. 21762306a36Sopenharmony_ci */ 21862306a36Sopenharmony_ci rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL, 21962306a36Sopenharmony_ci brightness / (LED_FULL / 6), 22062306a36Sopenharmony_ci led->rt2x00dev->led_mcu_reg, 22162306a36Sopenharmony_ci REGISTER_TIMEOUT); 22262306a36Sopenharmony_ci } 22362306a36Sopenharmony_ci} 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_cistatic int rt73usb_blink_set(struct led_classdev *led_cdev, 22662306a36Sopenharmony_ci unsigned long *delay_on, 22762306a36Sopenharmony_ci unsigned long *delay_off) 22862306a36Sopenharmony_ci{ 22962306a36Sopenharmony_ci struct rt2x00_led *led = 23062306a36Sopenharmony_ci container_of(led_cdev, struct rt2x00_led, led_dev); 23162306a36Sopenharmony_ci u32 reg; 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci reg = rt2x00usb_register_read(led->rt2x00dev, MAC_CSR14); 23462306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR14_ON_PERIOD, *delay_on); 23562306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR14_OFF_PERIOD, *delay_off); 23662306a36Sopenharmony_ci rt2x00usb_register_write(led->rt2x00dev, MAC_CSR14, reg); 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci return 0; 23962306a36Sopenharmony_ci} 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_cistatic void rt73usb_init_led(struct rt2x00_dev *rt2x00dev, 24262306a36Sopenharmony_ci struct rt2x00_led *led, 24362306a36Sopenharmony_ci enum led_type type) 24462306a36Sopenharmony_ci{ 24562306a36Sopenharmony_ci led->rt2x00dev = rt2x00dev; 24662306a36Sopenharmony_ci led->type = type; 24762306a36Sopenharmony_ci led->led_dev.brightness_set = rt73usb_brightness_set; 24862306a36Sopenharmony_ci led->led_dev.blink_set = rt73usb_blink_set; 24962306a36Sopenharmony_ci led->flags = LED_INITIALIZED; 25062306a36Sopenharmony_ci} 25162306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_LEDS */ 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci/* 25462306a36Sopenharmony_ci * Configuration handlers. 25562306a36Sopenharmony_ci */ 25662306a36Sopenharmony_cistatic int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev, 25762306a36Sopenharmony_ci struct rt2x00lib_crypto *crypto, 25862306a36Sopenharmony_ci struct ieee80211_key_conf *key) 25962306a36Sopenharmony_ci{ 26062306a36Sopenharmony_ci struct hw_key_entry key_entry; 26162306a36Sopenharmony_ci struct rt2x00_field32 field; 26262306a36Sopenharmony_ci u32 mask; 26362306a36Sopenharmony_ci u32 reg; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci if (crypto->cmd == SET_KEY) { 26662306a36Sopenharmony_ci /* 26762306a36Sopenharmony_ci * rt2x00lib can't determine the correct free 26862306a36Sopenharmony_ci * key_idx for shared keys. We have 1 register 26962306a36Sopenharmony_ci * with key valid bits. The goal is simple, read 27062306a36Sopenharmony_ci * the register, if that is full we have no slots 27162306a36Sopenharmony_ci * left. 27262306a36Sopenharmony_ci * Note that each BSS is allowed to have up to 4 27362306a36Sopenharmony_ci * shared keys, so put a mask over the allowed 27462306a36Sopenharmony_ci * entries. 27562306a36Sopenharmony_ci */ 27662306a36Sopenharmony_ci mask = (0xf << crypto->bssidx); 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR0); 27962306a36Sopenharmony_ci reg &= mask; 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_ci if (reg && reg == mask) 28262306a36Sopenharmony_ci return -ENOSPC; 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci key->hw_key_idx += reg ? ffz(reg) : 0; 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci /* 28762306a36Sopenharmony_ci * Upload key to hardware 28862306a36Sopenharmony_ci */ 28962306a36Sopenharmony_ci memcpy(key_entry.key, crypto->key, 29062306a36Sopenharmony_ci sizeof(key_entry.key)); 29162306a36Sopenharmony_ci memcpy(key_entry.tx_mic, crypto->tx_mic, 29262306a36Sopenharmony_ci sizeof(key_entry.tx_mic)); 29362306a36Sopenharmony_ci memcpy(key_entry.rx_mic, crypto->rx_mic, 29462306a36Sopenharmony_ci sizeof(key_entry.rx_mic)); 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci reg = SHARED_KEY_ENTRY(key->hw_key_idx); 29762306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, reg, 29862306a36Sopenharmony_ci &key_entry, sizeof(key_entry)); 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci /* 30162306a36Sopenharmony_ci * The cipher types are stored over 2 registers. 30262306a36Sopenharmony_ci * bssidx 0 and 1 keys are stored in SEC_CSR1 and 30362306a36Sopenharmony_ci * bssidx 1 and 2 keys are stored in SEC_CSR5. 30462306a36Sopenharmony_ci * Using the correct defines correctly will cause overhead, 30562306a36Sopenharmony_ci * so just calculate the correct offset. 30662306a36Sopenharmony_ci */ 30762306a36Sopenharmony_ci if (key->hw_key_idx < 8) { 30862306a36Sopenharmony_ci field.bit_offset = (3 * key->hw_key_idx); 30962306a36Sopenharmony_ci field.bit_mask = 0x7 << field.bit_offset; 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR1); 31262306a36Sopenharmony_ci rt2x00_set_field32(®, field, crypto->cipher); 31362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR1, reg); 31462306a36Sopenharmony_ci } else { 31562306a36Sopenharmony_ci field.bit_offset = (3 * (key->hw_key_idx - 8)); 31662306a36Sopenharmony_ci field.bit_mask = 0x7 << field.bit_offset; 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR5); 31962306a36Sopenharmony_ci rt2x00_set_field32(®, field, crypto->cipher); 32062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR5, reg); 32162306a36Sopenharmony_ci } 32262306a36Sopenharmony_ci 32362306a36Sopenharmony_ci /* 32462306a36Sopenharmony_ci * The driver does not support the IV/EIV generation 32562306a36Sopenharmony_ci * in hardware. However it doesn't support the IV/EIV 32662306a36Sopenharmony_ci * inside the ieee80211 frame either, but requires it 32762306a36Sopenharmony_ci * to be provided separately for the descriptor. 32862306a36Sopenharmony_ci * rt2x00lib will cut the IV/EIV data out of all frames 32962306a36Sopenharmony_ci * given to us by mac80211, but we must tell mac80211 33062306a36Sopenharmony_ci * to generate the IV/EIV data. 33162306a36Sopenharmony_ci */ 33262306a36Sopenharmony_ci key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 33362306a36Sopenharmony_ci } 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci /* 33662306a36Sopenharmony_ci * SEC_CSR0 contains only single-bit fields to indicate 33762306a36Sopenharmony_ci * a particular key is valid. Because using the FIELD32() 33862306a36Sopenharmony_ci * defines directly will cause a lot of overhead we use 33962306a36Sopenharmony_ci * a calculation to determine the correct bit directly. 34062306a36Sopenharmony_ci */ 34162306a36Sopenharmony_ci mask = 1 << key->hw_key_idx; 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR0); 34462306a36Sopenharmony_ci if (crypto->cmd == SET_KEY) 34562306a36Sopenharmony_ci reg |= mask; 34662306a36Sopenharmony_ci else if (crypto->cmd == DISABLE_KEY) 34762306a36Sopenharmony_ci reg &= ~mask; 34862306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR0, reg); 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci return 0; 35162306a36Sopenharmony_ci} 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_cistatic int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev, 35462306a36Sopenharmony_ci struct rt2x00lib_crypto *crypto, 35562306a36Sopenharmony_ci struct ieee80211_key_conf *key) 35662306a36Sopenharmony_ci{ 35762306a36Sopenharmony_ci struct hw_pairwise_ta_entry addr_entry; 35862306a36Sopenharmony_ci struct hw_key_entry key_entry; 35962306a36Sopenharmony_ci u32 mask; 36062306a36Sopenharmony_ci u32 reg; 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci if (crypto->cmd == SET_KEY) { 36362306a36Sopenharmony_ci /* 36462306a36Sopenharmony_ci * rt2x00lib can't determine the correct free 36562306a36Sopenharmony_ci * key_idx for pairwise keys. We have 2 registers 36662306a36Sopenharmony_ci * with key valid bits. The goal is simple, read 36762306a36Sopenharmony_ci * the first register, if that is full move to 36862306a36Sopenharmony_ci * the next register. 36962306a36Sopenharmony_ci * When both registers are full, we drop the key, 37062306a36Sopenharmony_ci * otherwise we use the first invalid entry. 37162306a36Sopenharmony_ci */ 37262306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR2); 37362306a36Sopenharmony_ci if (reg && reg == ~0) { 37462306a36Sopenharmony_ci key->hw_key_idx = 32; 37562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR3); 37662306a36Sopenharmony_ci if (reg && reg == ~0) 37762306a36Sopenharmony_ci return -ENOSPC; 37862306a36Sopenharmony_ci } 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci key->hw_key_idx += reg ? ffz(reg) : 0; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci /* 38362306a36Sopenharmony_ci * Upload key to hardware 38462306a36Sopenharmony_ci */ 38562306a36Sopenharmony_ci memcpy(key_entry.key, crypto->key, 38662306a36Sopenharmony_ci sizeof(key_entry.key)); 38762306a36Sopenharmony_ci memcpy(key_entry.tx_mic, crypto->tx_mic, 38862306a36Sopenharmony_ci sizeof(key_entry.tx_mic)); 38962306a36Sopenharmony_ci memcpy(key_entry.rx_mic, crypto->rx_mic, 39062306a36Sopenharmony_ci sizeof(key_entry.rx_mic)); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx); 39362306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, reg, 39462306a36Sopenharmony_ci &key_entry, sizeof(key_entry)); 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci /* 39762306a36Sopenharmony_ci * Send the address and cipher type to the hardware register. 39862306a36Sopenharmony_ci */ 39962306a36Sopenharmony_ci memset(&addr_entry, 0, sizeof(addr_entry)); 40062306a36Sopenharmony_ci memcpy(&addr_entry, crypto->address, ETH_ALEN); 40162306a36Sopenharmony_ci addr_entry.cipher = crypto->cipher; 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci reg = PAIRWISE_TA_ENTRY(key->hw_key_idx); 40462306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, reg, 40562306a36Sopenharmony_ci &addr_entry, sizeof(addr_entry)); 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci /* 40862306a36Sopenharmony_ci * Enable pairwise lookup table for given BSS idx, 40962306a36Sopenharmony_ci * without this received frames will not be decrypted 41062306a36Sopenharmony_ci * by the hardware. 41162306a36Sopenharmony_ci */ 41262306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR4); 41362306a36Sopenharmony_ci reg |= (1 << crypto->bssidx); 41462306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR4, reg); 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_ci /* 41762306a36Sopenharmony_ci * The driver does not support the IV/EIV generation 41862306a36Sopenharmony_ci * in hardware. However it doesn't support the IV/EIV 41962306a36Sopenharmony_ci * inside the ieee80211 frame either, but requires it 42062306a36Sopenharmony_ci * to be provided separately for the descriptor. 42162306a36Sopenharmony_ci * rt2x00lib will cut the IV/EIV data out of all frames 42262306a36Sopenharmony_ci * given to us by mac80211, but we must tell mac80211 42362306a36Sopenharmony_ci * to generate the IV/EIV data. 42462306a36Sopenharmony_ci */ 42562306a36Sopenharmony_ci key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 42662306a36Sopenharmony_ci } 42762306a36Sopenharmony_ci 42862306a36Sopenharmony_ci /* 42962306a36Sopenharmony_ci * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate 43062306a36Sopenharmony_ci * a particular key is valid. Because using the FIELD32() 43162306a36Sopenharmony_ci * defines directly will cause a lot of overhead we use 43262306a36Sopenharmony_ci * a calculation to determine the correct bit directly. 43362306a36Sopenharmony_ci */ 43462306a36Sopenharmony_ci if (key->hw_key_idx < 32) { 43562306a36Sopenharmony_ci mask = 1 << key->hw_key_idx; 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR2); 43862306a36Sopenharmony_ci if (crypto->cmd == SET_KEY) 43962306a36Sopenharmony_ci reg |= mask; 44062306a36Sopenharmony_ci else if (crypto->cmd == DISABLE_KEY) 44162306a36Sopenharmony_ci reg &= ~mask; 44262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR2, reg); 44362306a36Sopenharmony_ci } else { 44462306a36Sopenharmony_ci mask = 1 << (key->hw_key_idx - 32); 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, SEC_CSR3); 44762306a36Sopenharmony_ci if (crypto->cmd == SET_KEY) 44862306a36Sopenharmony_ci reg |= mask; 44962306a36Sopenharmony_ci else if (crypto->cmd == DISABLE_KEY) 45062306a36Sopenharmony_ci reg &= ~mask; 45162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR3, reg); 45262306a36Sopenharmony_ci } 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_ci return 0; 45562306a36Sopenharmony_ci} 45662306a36Sopenharmony_ci 45762306a36Sopenharmony_cistatic void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev, 45862306a36Sopenharmony_ci const unsigned int filter_flags) 45962306a36Sopenharmony_ci{ 46062306a36Sopenharmony_ci u32 reg; 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci /* 46362306a36Sopenharmony_ci * Start configuration steps. 46462306a36Sopenharmony_ci * Note that the version error will always be dropped 46562306a36Sopenharmony_ci * and broadcast frames will always be accepted since 46662306a36Sopenharmony_ci * there is no filter for it at this time. 46762306a36Sopenharmony_ci */ 46862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR0); 46962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_CRC, 47062306a36Sopenharmony_ci !(filter_flags & FIF_FCSFAIL)); 47162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_PHYSICAL, 47262306a36Sopenharmony_ci !(filter_flags & FIF_PLCPFAIL)); 47362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_CONTROL, 47462306a36Sopenharmony_ci !(filter_flags & (FIF_CONTROL | FIF_PSPOLL))); 47562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_NOT_TO_ME, 47662306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags)); 47762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_TO_DS, 47862306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags) && 47962306a36Sopenharmony_ci !rt2x00dev->intf_ap_count); 48062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_VERSION_ERROR, 1); 48162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_MULTICAST, 48262306a36Sopenharmony_ci !(filter_flags & FIF_ALLMULTI)); 48362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_BROADCAST, 0); 48462306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DROP_ACK_CTS, 48562306a36Sopenharmony_ci !(filter_flags & FIF_CONTROL)); 48662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg); 48762306a36Sopenharmony_ci} 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_cistatic void rt73usb_config_intf(struct rt2x00_dev *rt2x00dev, 49062306a36Sopenharmony_ci struct rt2x00_intf *intf, 49162306a36Sopenharmony_ci struct rt2x00intf_conf *conf, 49262306a36Sopenharmony_ci const unsigned int flags) 49362306a36Sopenharmony_ci{ 49462306a36Sopenharmony_ci u32 reg; 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_TYPE) { 49762306a36Sopenharmony_ci /* 49862306a36Sopenharmony_ci * Enable synchronisation. 49962306a36Sopenharmony_ci */ 50062306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 50162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TSF_SYNC, conf->sync); 50262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 50362306a36Sopenharmony_ci } 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_MAC) { 50662306a36Sopenharmony_ci reg = le32_to_cpu(conf->mac[1]); 50762306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff); 50862306a36Sopenharmony_ci conf->mac[1] = cpu_to_le32(reg); 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR2, 51162306a36Sopenharmony_ci conf->mac, sizeof(conf->mac)); 51262306a36Sopenharmony_ci } 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_BSSID) { 51562306a36Sopenharmony_ci reg = le32_to_cpu(conf->bssid[1]); 51662306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR5_BSS_ID_MASK, 3); 51762306a36Sopenharmony_ci conf->bssid[1] = cpu_to_le32(reg); 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR4, 52062306a36Sopenharmony_ci conf->bssid, sizeof(conf->bssid)); 52162306a36Sopenharmony_ci } 52262306a36Sopenharmony_ci} 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_cistatic void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev, 52562306a36Sopenharmony_ci struct rt2x00lib_erp *erp, 52662306a36Sopenharmony_ci u32 changed) 52762306a36Sopenharmony_ci{ 52862306a36Sopenharmony_ci u32 reg; 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR0); 53162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_RX_ACK_TIMEOUT, 0x32); 53262306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER); 53362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg); 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_PREAMBLE) { 53662306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR4); 53762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_AUTORESPOND_ENABLE, 1); 53862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_AUTORESPOND_PREAMBLE, 53962306a36Sopenharmony_ci !!erp->short_preamble); 54062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg); 54162306a36Sopenharmony_ci } 54262306a36Sopenharmony_ci 54362306a36Sopenharmony_ci if (changed & BSS_CHANGED_BASIC_RATES) 54462306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR5, 54562306a36Sopenharmony_ci erp->basic_rates); 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci if (changed & BSS_CHANGED_BEACON_INT) { 54862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 54962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_INTERVAL, 55062306a36Sopenharmony_ci erp->beacon_int * 16); 55162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 55262306a36Sopenharmony_ci } 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_SLOT) { 55562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR9); 55662306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR9_SLOT_TIME, erp->slot_time); 55762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg); 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR8); 56062306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR8_SIFS, erp->sifs); 56162306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3); 56262306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR8_EIFS, erp->eifs); 56362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR8, reg); 56462306a36Sopenharmony_ci } 56562306a36Sopenharmony_ci} 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_cistatic void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev, 56862306a36Sopenharmony_ci struct antenna_setup *ant) 56962306a36Sopenharmony_ci{ 57062306a36Sopenharmony_ci u8 r3; 57162306a36Sopenharmony_ci u8 r4; 57262306a36Sopenharmony_ci u8 r77; 57362306a36Sopenharmony_ci u8 temp; 57462306a36Sopenharmony_ci 57562306a36Sopenharmony_ci r3 = rt73usb_bbp_read(rt2x00dev, 3); 57662306a36Sopenharmony_ci r4 = rt73usb_bbp_read(rt2x00dev, 4); 57762306a36Sopenharmony_ci r77 = rt73usb_bbp_read(rt2x00dev, 77); 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_ci rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0); 58062306a36Sopenharmony_ci 58162306a36Sopenharmony_ci /* 58262306a36Sopenharmony_ci * Configure the RX antenna. 58362306a36Sopenharmony_ci */ 58462306a36Sopenharmony_ci switch (ant->rx) { 58562306a36Sopenharmony_ci case ANTENNA_HW_DIVERSITY: 58662306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); 58762306a36Sopenharmony_ci temp = !rt2x00_has_cap_frame_type(rt2x00dev) && 58862306a36Sopenharmony_ci (rt2x00dev->curr_band != NL80211_BAND_5GHZ); 58962306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp); 59062306a36Sopenharmony_ci break; 59162306a36Sopenharmony_ci case ANTENNA_A: 59262306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 59362306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 59462306a36Sopenharmony_ci if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) 59562306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 59662306a36Sopenharmony_ci else 59762306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 59862306a36Sopenharmony_ci break; 59962306a36Sopenharmony_ci case ANTENNA_B: 60062306a36Sopenharmony_ci default: 60162306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 60262306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0); 60362306a36Sopenharmony_ci if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) 60462306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 60562306a36Sopenharmony_ci else 60662306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 60762306a36Sopenharmony_ci break; 60862306a36Sopenharmony_ci } 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 77, r77); 61162306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 3, r3); 61262306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 4, r4); 61362306a36Sopenharmony_ci} 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_cistatic void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev, 61662306a36Sopenharmony_ci struct antenna_setup *ant) 61762306a36Sopenharmony_ci{ 61862306a36Sopenharmony_ci u8 r3; 61962306a36Sopenharmony_ci u8 r4; 62062306a36Sopenharmony_ci u8 r77; 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_ci r3 = rt73usb_bbp_read(rt2x00dev, 3); 62362306a36Sopenharmony_ci r4 = rt73usb_bbp_read(rt2x00dev, 4); 62462306a36Sopenharmony_ci r77 = rt73usb_bbp_read(rt2x00dev, 77); 62562306a36Sopenharmony_ci 62662306a36Sopenharmony_ci rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0); 62762306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 62862306a36Sopenharmony_ci !rt2x00_has_cap_frame_type(rt2x00dev)); 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci /* 63162306a36Sopenharmony_ci * Configure the RX antenna. 63262306a36Sopenharmony_ci */ 63362306a36Sopenharmony_ci switch (ant->rx) { 63462306a36Sopenharmony_ci case ANTENNA_HW_DIVERSITY: 63562306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2); 63662306a36Sopenharmony_ci break; 63762306a36Sopenharmony_ci case ANTENNA_A: 63862306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3); 63962306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 64062306a36Sopenharmony_ci break; 64162306a36Sopenharmony_ci case ANTENNA_B: 64262306a36Sopenharmony_ci default: 64362306a36Sopenharmony_ci rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0); 64462306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1); 64562306a36Sopenharmony_ci break; 64662306a36Sopenharmony_ci } 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 77, r77); 64962306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 3, r3); 65062306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 4, r4); 65162306a36Sopenharmony_ci} 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_cistruct antenna_sel { 65462306a36Sopenharmony_ci u8 word; 65562306a36Sopenharmony_ci /* 65662306a36Sopenharmony_ci * value[0] -> non-LNA 65762306a36Sopenharmony_ci * value[1] -> LNA 65862306a36Sopenharmony_ci */ 65962306a36Sopenharmony_ci u8 value[2]; 66062306a36Sopenharmony_ci}; 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_cistatic const struct antenna_sel antenna_sel_a[] = { 66362306a36Sopenharmony_ci { 96, { 0x58, 0x78 } }, 66462306a36Sopenharmony_ci { 104, { 0x38, 0x48 } }, 66562306a36Sopenharmony_ci { 75, { 0xfe, 0x80 } }, 66662306a36Sopenharmony_ci { 86, { 0xfe, 0x80 } }, 66762306a36Sopenharmony_ci { 88, { 0xfe, 0x80 } }, 66862306a36Sopenharmony_ci { 35, { 0x60, 0x60 } }, 66962306a36Sopenharmony_ci { 97, { 0x58, 0x58 } }, 67062306a36Sopenharmony_ci { 98, { 0x58, 0x58 } }, 67162306a36Sopenharmony_ci}; 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_cistatic const struct antenna_sel antenna_sel_bg[] = { 67462306a36Sopenharmony_ci { 96, { 0x48, 0x68 } }, 67562306a36Sopenharmony_ci { 104, { 0x2c, 0x3c } }, 67662306a36Sopenharmony_ci { 75, { 0xfe, 0x80 } }, 67762306a36Sopenharmony_ci { 86, { 0xfe, 0x80 } }, 67862306a36Sopenharmony_ci { 88, { 0xfe, 0x80 } }, 67962306a36Sopenharmony_ci { 35, { 0x50, 0x50 } }, 68062306a36Sopenharmony_ci { 97, { 0x48, 0x48 } }, 68162306a36Sopenharmony_ci { 98, { 0x48, 0x48 } }, 68262306a36Sopenharmony_ci}; 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_cistatic void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev, 68562306a36Sopenharmony_ci struct antenna_setup *ant) 68662306a36Sopenharmony_ci{ 68762306a36Sopenharmony_ci const struct antenna_sel *sel; 68862306a36Sopenharmony_ci unsigned int lna; 68962306a36Sopenharmony_ci unsigned int i; 69062306a36Sopenharmony_ci u32 reg; 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ci /* 69362306a36Sopenharmony_ci * We should never come here because rt2x00lib is supposed 69462306a36Sopenharmony_ci * to catch this and send us the correct antenna explicitely. 69562306a36Sopenharmony_ci */ 69662306a36Sopenharmony_ci BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY || 69762306a36Sopenharmony_ci ant->tx == ANTENNA_SW_DIVERSITY); 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_ci if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) { 70062306a36Sopenharmony_ci sel = antenna_sel_a; 70162306a36Sopenharmony_ci lna = rt2x00_has_cap_external_lna_a(rt2x00dev); 70262306a36Sopenharmony_ci } else { 70362306a36Sopenharmony_ci sel = antenna_sel_bg; 70462306a36Sopenharmony_ci lna = rt2x00_has_cap_external_lna_bg(rt2x00dev); 70562306a36Sopenharmony_ci } 70662306a36Sopenharmony_ci 70762306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++) 70862306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]); 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, PHY_CSR0); 71162306a36Sopenharmony_ci 71262306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR0_PA_PE_BG, 71362306a36Sopenharmony_ci (rt2x00dev->curr_band == NL80211_BAND_2GHZ)); 71462306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR0_PA_PE_A, 71562306a36Sopenharmony_ci (rt2x00dev->curr_band == NL80211_BAND_5GHZ)); 71662306a36Sopenharmony_ci 71762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, PHY_CSR0, reg); 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF5226) || rt2x00_rf(rt2x00dev, RF5225)) 72062306a36Sopenharmony_ci rt73usb_config_antenna_5x(rt2x00dev, ant); 72162306a36Sopenharmony_ci else if (rt2x00_rf(rt2x00dev, RF2528) || rt2x00_rf(rt2x00dev, RF2527)) 72262306a36Sopenharmony_ci rt73usb_config_antenna_2x(rt2x00dev, ant); 72362306a36Sopenharmony_ci} 72462306a36Sopenharmony_ci 72562306a36Sopenharmony_cistatic void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev, 72662306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 72762306a36Sopenharmony_ci{ 72862306a36Sopenharmony_ci u16 eeprom; 72962306a36Sopenharmony_ci short lna_gain = 0; 73062306a36Sopenharmony_ci 73162306a36Sopenharmony_ci if (libconf->conf->chandef.chan->band == NL80211_BAND_2GHZ) { 73262306a36Sopenharmony_ci if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) 73362306a36Sopenharmony_ci lna_gain += 14; 73462306a36Sopenharmony_ci 73562306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG); 73662306a36Sopenharmony_ci lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1); 73762306a36Sopenharmony_ci } else { 73862306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A); 73962306a36Sopenharmony_ci lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1); 74062306a36Sopenharmony_ci } 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci rt2x00dev->lna_gain = lna_gain; 74362306a36Sopenharmony_ci} 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_cistatic void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev, 74662306a36Sopenharmony_ci struct rf_channel *rf, const int txpower) 74762306a36Sopenharmony_ci{ 74862306a36Sopenharmony_ci u8 r3; 74962306a36Sopenharmony_ci u8 r94; 75062306a36Sopenharmony_ci u8 smart; 75162306a36Sopenharmony_ci 75262306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); 75362306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset); 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_ci smart = !(rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527)); 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci r3 = rt73usb_bbp_read(rt2x00dev, 3); 75862306a36Sopenharmony_ci rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart); 75962306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 3, r3); 76062306a36Sopenharmony_ci 76162306a36Sopenharmony_ci r94 = 6; 76262306a36Sopenharmony_ci if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94)) 76362306a36Sopenharmony_ci r94 += txpower - MAX_TXPOWER; 76462306a36Sopenharmony_ci else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94)) 76562306a36Sopenharmony_ci r94 += txpower; 76662306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 94, r94); 76762306a36Sopenharmony_ci 76862306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 1, rf->rf1); 76962306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 2, rf->rf2); 77062306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); 77162306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 4, rf->rf4); 77262306a36Sopenharmony_ci 77362306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 1, rf->rf1); 77462306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 2, rf->rf2); 77562306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004); 77662306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 4, rf->rf4); 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 1, rf->rf1); 77962306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 2, rf->rf2); 78062306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004); 78162306a36Sopenharmony_ci rt73usb_rf_write(rt2x00dev, 4, rf->rf4); 78262306a36Sopenharmony_ci 78362306a36Sopenharmony_ci udelay(10); 78462306a36Sopenharmony_ci} 78562306a36Sopenharmony_ci 78662306a36Sopenharmony_cistatic void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev, 78762306a36Sopenharmony_ci const int txpower) 78862306a36Sopenharmony_ci{ 78962306a36Sopenharmony_ci struct rf_channel rf; 79062306a36Sopenharmony_ci 79162306a36Sopenharmony_ci rf.rf1 = rt2x00_rf_read(rt2x00dev, 1); 79262306a36Sopenharmony_ci rf.rf2 = rt2x00_rf_read(rt2x00dev, 2); 79362306a36Sopenharmony_ci rf.rf3 = rt2x00_rf_read(rt2x00dev, 3); 79462306a36Sopenharmony_ci rf.rf4 = rt2x00_rf_read(rt2x00dev, 4); 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_ci rt73usb_config_channel(rt2x00dev, &rf, txpower); 79762306a36Sopenharmony_ci} 79862306a36Sopenharmony_ci 79962306a36Sopenharmony_cistatic void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev, 80062306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 80162306a36Sopenharmony_ci{ 80262306a36Sopenharmony_ci u32 reg; 80362306a36Sopenharmony_ci 80462306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR4); 80562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_OFDM_TX_RATE_DOWN, 1); 80662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_OFDM_TX_RATE_STEP, 0); 80762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_OFDM_TX_FALLBACK_CCK, 0); 80862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_LONG_RETRY_LIMIT, 80962306a36Sopenharmony_ci libconf->conf->long_frame_max_tx_count); 81062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR4_SHORT_RETRY_LIMIT, 81162306a36Sopenharmony_ci libconf->conf->short_frame_max_tx_count); 81262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg); 81362306a36Sopenharmony_ci} 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_cistatic void rt73usb_config_ps(struct rt2x00_dev *rt2x00dev, 81662306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 81762306a36Sopenharmony_ci{ 81862306a36Sopenharmony_ci enum dev_state state = 81962306a36Sopenharmony_ci (libconf->conf->flags & IEEE80211_CONF_PS) ? 82062306a36Sopenharmony_ci STATE_SLEEP : STATE_AWAKE; 82162306a36Sopenharmony_ci u32 reg; 82262306a36Sopenharmony_ci 82362306a36Sopenharmony_ci if (state == STATE_SLEEP) { 82462306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR11); 82562306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_DELAY_AFTER_TBCN, 82662306a36Sopenharmony_ci rt2x00dev->beacon_int - 10); 82762306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_TBCN_BEFORE_WAKEUP, 82862306a36Sopenharmony_ci libconf->conf->listen_interval - 1); 82962306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_WAKEUP_LATENCY, 5); 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci /* We must first disable autowake before it can be enabled */ 83262306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_AUTOWAKE, 0); 83362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg); 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_AUTOWAKE, 1); 83662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg); 83762306a36Sopenharmony_ci 83862306a36Sopenharmony_ci rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0, 83962306a36Sopenharmony_ci USB_MODE_SLEEP, REGISTER_TIMEOUT); 84062306a36Sopenharmony_ci } else { 84162306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR11); 84262306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_DELAY_AFTER_TBCN, 0); 84362306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_TBCN_BEFORE_WAKEUP, 0); 84462306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_AUTOWAKE, 0); 84562306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR11_WAKEUP_LATENCY, 0); 84662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg); 84762306a36Sopenharmony_ci 84862306a36Sopenharmony_ci rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0, 84962306a36Sopenharmony_ci USB_MODE_WAKEUP, REGISTER_TIMEOUT); 85062306a36Sopenharmony_ci } 85162306a36Sopenharmony_ci} 85262306a36Sopenharmony_ci 85362306a36Sopenharmony_cistatic void rt73usb_config(struct rt2x00_dev *rt2x00dev, 85462306a36Sopenharmony_ci struct rt2x00lib_conf *libconf, 85562306a36Sopenharmony_ci const unsigned int flags) 85662306a36Sopenharmony_ci{ 85762306a36Sopenharmony_ci /* Always recalculate LNA gain before changing configuration */ 85862306a36Sopenharmony_ci rt73usb_config_lna_gain(rt2x00dev, libconf); 85962306a36Sopenharmony_ci 86062306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_CHANNEL) 86162306a36Sopenharmony_ci rt73usb_config_channel(rt2x00dev, &libconf->rf, 86262306a36Sopenharmony_ci libconf->conf->power_level); 86362306a36Sopenharmony_ci if ((flags & IEEE80211_CONF_CHANGE_POWER) && 86462306a36Sopenharmony_ci !(flags & IEEE80211_CONF_CHANGE_CHANNEL)) 86562306a36Sopenharmony_ci rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level); 86662306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) 86762306a36Sopenharmony_ci rt73usb_config_retry_limit(rt2x00dev, libconf); 86862306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_PS) 86962306a36Sopenharmony_ci rt73usb_config_ps(rt2x00dev, libconf); 87062306a36Sopenharmony_ci} 87162306a36Sopenharmony_ci 87262306a36Sopenharmony_ci/* 87362306a36Sopenharmony_ci * Link tuning 87462306a36Sopenharmony_ci */ 87562306a36Sopenharmony_cistatic void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev, 87662306a36Sopenharmony_ci struct link_qual *qual) 87762306a36Sopenharmony_ci{ 87862306a36Sopenharmony_ci u32 reg; 87962306a36Sopenharmony_ci 88062306a36Sopenharmony_ci /* 88162306a36Sopenharmony_ci * Update FCS error count from register. 88262306a36Sopenharmony_ci */ 88362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, STA_CSR0); 88462306a36Sopenharmony_ci qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR); 88562306a36Sopenharmony_ci 88662306a36Sopenharmony_ci /* 88762306a36Sopenharmony_ci * Update False CCA count from register. 88862306a36Sopenharmony_ci */ 88962306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, STA_CSR1); 89062306a36Sopenharmony_ci qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR); 89162306a36Sopenharmony_ci} 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_cistatic inline void rt73usb_set_vgc(struct rt2x00_dev *rt2x00dev, 89462306a36Sopenharmony_ci struct link_qual *qual, u8 vgc_level) 89562306a36Sopenharmony_ci{ 89662306a36Sopenharmony_ci if (qual->vgc_level != vgc_level) { 89762306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 17, vgc_level); 89862306a36Sopenharmony_ci qual->vgc_level = vgc_level; 89962306a36Sopenharmony_ci qual->vgc_level_reg = vgc_level; 90062306a36Sopenharmony_ci } 90162306a36Sopenharmony_ci} 90262306a36Sopenharmony_ci 90362306a36Sopenharmony_cistatic void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev, 90462306a36Sopenharmony_ci struct link_qual *qual) 90562306a36Sopenharmony_ci{ 90662306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, 0x20); 90762306a36Sopenharmony_ci} 90862306a36Sopenharmony_ci 90962306a36Sopenharmony_cistatic void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev, 91062306a36Sopenharmony_ci struct link_qual *qual, const u32 count) 91162306a36Sopenharmony_ci{ 91262306a36Sopenharmony_ci u8 up_bound; 91362306a36Sopenharmony_ci u8 low_bound; 91462306a36Sopenharmony_ci 91562306a36Sopenharmony_ci /* 91662306a36Sopenharmony_ci * Determine r17 bounds. 91762306a36Sopenharmony_ci */ 91862306a36Sopenharmony_ci if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) { 91962306a36Sopenharmony_ci low_bound = 0x28; 92062306a36Sopenharmony_ci up_bound = 0x48; 92162306a36Sopenharmony_ci 92262306a36Sopenharmony_ci if (rt2x00_has_cap_external_lna_a(rt2x00dev)) { 92362306a36Sopenharmony_ci low_bound += 0x10; 92462306a36Sopenharmony_ci up_bound += 0x10; 92562306a36Sopenharmony_ci } 92662306a36Sopenharmony_ci } else { 92762306a36Sopenharmony_ci if (qual->rssi > -82) { 92862306a36Sopenharmony_ci low_bound = 0x1c; 92962306a36Sopenharmony_ci up_bound = 0x40; 93062306a36Sopenharmony_ci } else if (qual->rssi > -84) { 93162306a36Sopenharmony_ci low_bound = 0x1c; 93262306a36Sopenharmony_ci up_bound = 0x20; 93362306a36Sopenharmony_ci } else { 93462306a36Sopenharmony_ci low_bound = 0x1c; 93562306a36Sopenharmony_ci up_bound = 0x1c; 93662306a36Sopenharmony_ci } 93762306a36Sopenharmony_ci 93862306a36Sopenharmony_ci if (rt2x00_has_cap_external_lna_bg(rt2x00dev)) { 93962306a36Sopenharmony_ci low_bound += 0x14; 94062306a36Sopenharmony_ci up_bound += 0x10; 94162306a36Sopenharmony_ci } 94262306a36Sopenharmony_ci } 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ci /* 94562306a36Sopenharmony_ci * If we are not associated, we should go straight to the 94662306a36Sopenharmony_ci * dynamic CCA tuning. 94762306a36Sopenharmony_ci */ 94862306a36Sopenharmony_ci if (!rt2x00dev->intf_associated) 94962306a36Sopenharmony_ci goto dynamic_cca_tune; 95062306a36Sopenharmony_ci 95162306a36Sopenharmony_ci /* 95262306a36Sopenharmony_ci * Special big-R17 for very short distance 95362306a36Sopenharmony_ci */ 95462306a36Sopenharmony_ci if (qual->rssi > -35) { 95562306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, 0x60); 95662306a36Sopenharmony_ci return; 95762306a36Sopenharmony_ci } 95862306a36Sopenharmony_ci 95962306a36Sopenharmony_ci /* 96062306a36Sopenharmony_ci * Special big-R17 for short distance 96162306a36Sopenharmony_ci */ 96262306a36Sopenharmony_ci if (qual->rssi >= -58) { 96362306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, up_bound); 96462306a36Sopenharmony_ci return; 96562306a36Sopenharmony_ci } 96662306a36Sopenharmony_ci 96762306a36Sopenharmony_ci /* 96862306a36Sopenharmony_ci * Special big-R17 for middle-short distance 96962306a36Sopenharmony_ci */ 97062306a36Sopenharmony_ci if (qual->rssi >= -66) { 97162306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x10); 97262306a36Sopenharmony_ci return; 97362306a36Sopenharmony_ci } 97462306a36Sopenharmony_ci 97562306a36Sopenharmony_ci /* 97662306a36Sopenharmony_ci * Special mid-R17 for middle distance 97762306a36Sopenharmony_ci */ 97862306a36Sopenharmony_ci if (qual->rssi >= -74) { 97962306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x08); 98062306a36Sopenharmony_ci return; 98162306a36Sopenharmony_ci } 98262306a36Sopenharmony_ci 98362306a36Sopenharmony_ci /* 98462306a36Sopenharmony_ci * Special case: Change up_bound based on the rssi. 98562306a36Sopenharmony_ci * Lower up_bound when rssi is weaker then -74 dBm. 98662306a36Sopenharmony_ci */ 98762306a36Sopenharmony_ci up_bound -= 2 * (-74 - qual->rssi); 98862306a36Sopenharmony_ci if (low_bound > up_bound) 98962306a36Sopenharmony_ci up_bound = low_bound; 99062306a36Sopenharmony_ci 99162306a36Sopenharmony_ci if (qual->vgc_level > up_bound) { 99262306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, up_bound); 99362306a36Sopenharmony_ci return; 99462306a36Sopenharmony_ci } 99562306a36Sopenharmony_ci 99662306a36Sopenharmony_cidynamic_cca_tune: 99762306a36Sopenharmony_ci 99862306a36Sopenharmony_ci /* 99962306a36Sopenharmony_ci * r17 does not yet exceed upper limit, continue and base 100062306a36Sopenharmony_ci * the r17 tuning on the false CCA count. 100162306a36Sopenharmony_ci */ 100262306a36Sopenharmony_ci if ((qual->false_cca > 512) && (qual->vgc_level < up_bound)) 100362306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, 100462306a36Sopenharmony_ci min_t(u8, qual->vgc_level + 4, up_bound)); 100562306a36Sopenharmony_ci else if ((qual->false_cca < 100) && (qual->vgc_level > low_bound)) 100662306a36Sopenharmony_ci rt73usb_set_vgc(rt2x00dev, qual, 100762306a36Sopenharmony_ci max_t(u8, qual->vgc_level - 4, low_bound)); 100862306a36Sopenharmony_ci} 100962306a36Sopenharmony_ci 101062306a36Sopenharmony_ci/* 101162306a36Sopenharmony_ci * Queue handlers. 101262306a36Sopenharmony_ci */ 101362306a36Sopenharmony_cistatic void rt73usb_start_queue(struct data_queue *queue) 101462306a36Sopenharmony_ci{ 101562306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 101662306a36Sopenharmony_ci u32 reg; 101762306a36Sopenharmony_ci 101862306a36Sopenharmony_ci switch (queue->qid) { 101962306a36Sopenharmony_ci case QID_RX: 102062306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR0); 102162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, 0); 102262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg); 102362306a36Sopenharmony_ci break; 102462306a36Sopenharmony_ci case QID_BEACON: 102562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 102662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 1); 102762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 1); 102862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 1); 102962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 103062306a36Sopenharmony_ci break; 103162306a36Sopenharmony_ci default: 103262306a36Sopenharmony_ci break; 103362306a36Sopenharmony_ci } 103462306a36Sopenharmony_ci} 103562306a36Sopenharmony_ci 103662306a36Sopenharmony_cistatic void rt73usb_stop_queue(struct data_queue *queue) 103762306a36Sopenharmony_ci{ 103862306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 103962306a36Sopenharmony_ci u32 reg; 104062306a36Sopenharmony_ci 104162306a36Sopenharmony_ci switch (queue->qid) { 104262306a36Sopenharmony_ci case QID_RX: 104362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR0); 104462306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, 1); 104562306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg); 104662306a36Sopenharmony_ci break; 104762306a36Sopenharmony_ci case QID_BEACON: 104862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 104962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 0); 105062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 0); 105162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); 105262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 105362306a36Sopenharmony_ci break; 105462306a36Sopenharmony_ci default: 105562306a36Sopenharmony_ci break; 105662306a36Sopenharmony_ci } 105762306a36Sopenharmony_ci} 105862306a36Sopenharmony_ci 105962306a36Sopenharmony_ci/* 106062306a36Sopenharmony_ci * Firmware functions 106162306a36Sopenharmony_ci */ 106262306a36Sopenharmony_cistatic char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev) 106362306a36Sopenharmony_ci{ 106462306a36Sopenharmony_ci return FIRMWARE_RT2571; 106562306a36Sopenharmony_ci} 106662306a36Sopenharmony_ci 106762306a36Sopenharmony_cistatic int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev, 106862306a36Sopenharmony_ci const u8 *data, const size_t len) 106962306a36Sopenharmony_ci{ 107062306a36Sopenharmony_ci u16 fw_crc; 107162306a36Sopenharmony_ci u16 crc; 107262306a36Sopenharmony_ci 107362306a36Sopenharmony_ci /* 107462306a36Sopenharmony_ci * Only support 2kb firmware files. 107562306a36Sopenharmony_ci */ 107662306a36Sopenharmony_ci if (len != 2048) 107762306a36Sopenharmony_ci return FW_BAD_LENGTH; 107862306a36Sopenharmony_ci 107962306a36Sopenharmony_ci /* 108062306a36Sopenharmony_ci * The last 2 bytes in the firmware array are the crc checksum itself, 108162306a36Sopenharmony_ci * this means that we should never pass those 2 bytes to the crc 108262306a36Sopenharmony_ci * algorithm. 108362306a36Sopenharmony_ci */ 108462306a36Sopenharmony_ci fw_crc = (data[len - 2] << 8 | data[len - 1]); 108562306a36Sopenharmony_ci 108662306a36Sopenharmony_ci /* 108762306a36Sopenharmony_ci * Use the crc itu-t algorithm. 108862306a36Sopenharmony_ci */ 108962306a36Sopenharmony_ci crc = crc_itu_t(0, data, len - 2); 109062306a36Sopenharmony_ci crc = crc_itu_t_byte(crc, 0); 109162306a36Sopenharmony_ci crc = crc_itu_t_byte(crc, 0); 109262306a36Sopenharmony_ci 109362306a36Sopenharmony_ci return (fw_crc == crc) ? FW_OK : FW_BAD_CRC; 109462306a36Sopenharmony_ci} 109562306a36Sopenharmony_ci 109662306a36Sopenharmony_cistatic int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, 109762306a36Sopenharmony_ci const u8 *data, const size_t len) 109862306a36Sopenharmony_ci{ 109962306a36Sopenharmony_ci unsigned int i; 110062306a36Sopenharmony_ci int status; 110162306a36Sopenharmony_ci u32 reg; 110262306a36Sopenharmony_ci 110362306a36Sopenharmony_ci /* 110462306a36Sopenharmony_ci * Wait for stable hardware. 110562306a36Sopenharmony_ci */ 110662306a36Sopenharmony_ci for (i = 0; i < 100; i++) { 110762306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR0); 110862306a36Sopenharmony_ci if (reg) 110962306a36Sopenharmony_ci break; 111062306a36Sopenharmony_ci msleep(1); 111162306a36Sopenharmony_ci } 111262306a36Sopenharmony_ci 111362306a36Sopenharmony_ci if (!reg) { 111462306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Unstable hardware\n"); 111562306a36Sopenharmony_ci return -EBUSY; 111662306a36Sopenharmony_ci } 111762306a36Sopenharmony_ci 111862306a36Sopenharmony_ci /* 111962306a36Sopenharmony_ci * Write firmware to device. 112062306a36Sopenharmony_ci */ 112162306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, data, len); 112262306a36Sopenharmony_ci 112362306a36Sopenharmony_ci /* 112462306a36Sopenharmony_ci * Send firmware request to device to load firmware, 112562306a36Sopenharmony_ci * we need to specify a long timeout time. 112662306a36Sopenharmony_ci */ 112762306a36Sopenharmony_ci status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 112862306a36Sopenharmony_ci 0, USB_MODE_FIRMWARE, 112962306a36Sopenharmony_ci REGISTER_TIMEOUT_FIRMWARE); 113062306a36Sopenharmony_ci if (status < 0) { 113162306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Failed to write Firmware to device\n"); 113262306a36Sopenharmony_ci return status; 113362306a36Sopenharmony_ci } 113462306a36Sopenharmony_ci 113562306a36Sopenharmony_ci return 0; 113662306a36Sopenharmony_ci} 113762306a36Sopenharmony_ci 113862306a36Sopenharmony_ci/* 113962306a36Sopenharmony_ci * Initialization functions. 114062306a36Sopenharmony_ci */ 114162306a36Sopenharmony_cistatic int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev) 114262306a36Sopenharmony_ci{ 114362306a36Sopenharmony_ci u32 reg; 114462306a36Sopenharmony_ci 114562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR0); 114662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_AUTO_TX_SEQ, 1); 114762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX, 0); 114862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR0_TX_WITHOUT_WAITING, 0); 114962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg); 115062306a36Sopenharmony_ci 115162306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR1); 115262306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */ 115362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID0_VALID, 1); 115462306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID1, 30); /* Rssi */ 115562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID1_VALID, 1); 115662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */ 115762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID2_VALID, 1); 115862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID3, 30); /* Rssi */ 115962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR1_BBP_ID3_VALID, 1); 116062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR1, reg); 116162306a36Sopenharmony_ci 116262306a36Sopenharmony_ci /* 116362306a36Sopenharmony_ci * CCK TXD BBP registers 116462306a36Sopenharmony_ci */ 116562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR2); 116662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID0, 13); 116762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID0_VALID, 1); 116862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID1, 12); 116962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID1_VALID, 1); 117062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID2, 11); 117162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID2_VALID, 1); 117262306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID3, 10); 117362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR2_BBP_ID3_VALID, 1); 117462306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR2, reg); 117562306a36Sopenharmony_ci 117662306a36Sopenharmony_ci /* 117762306a36Sopenharmony_ci * OFDM TXD BBP registers 117862306a36Sopenharmony_ci */ 117962306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR3); 118062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID0, 7); 118162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID0_VALID, 1); 118262306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID1, 6); 118362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID1_VALID, 1); 118462306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID2, 5); 118562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR3_BBP_ID2_VALID, 1); 118662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR3, reg); 118762306a36Sopenharmony_ci 118862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR7); 118962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_6MBS, 59); 119062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_9MBS, 53); 119162306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_12MBS, 49); 119262306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR7_ACK_CTS_18MBS, 46); 119362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR7, reg); 119462306a36Sopenharmony_ci 119562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR8); 119662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_24MBS, 44); 119762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_36MBS, 42); 119862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_48MBS, 42); 119962306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR8_ACK_CTS_54MBS, 42); 120062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR8, reg); 120162306a36Sopenharmony_ci 120262306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 120362306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_INTERVAL, 0); 120462306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TSF_TICKING, 0); 120562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TSF_SYNC, 0); 120662306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TBTT_ENABLE, 0); 120762306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); 120862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0); 120962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 121062306a36Sopenharmony_ci 121162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f); 121262306a36Sopenharmony_ci 121362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR6); 121462306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR6_MAX_FRAME_UNIT, 0xfff); 121562306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR6, reg); 121662306a36Sopenharmony_ci 121762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718); 121862306a36Sopenharmony_ci 121962306a36Sopenharmony_ci if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE)) 122062306a36Sopenharmony_ci return -EBUSY; 122162306a36Sopenharmony_ci 122262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00); 122362306a36Sopenharmony_ci 122462306a36Sopenharmony_ci /* 122562306a36Sopenharmony_ci * Invalidate all Shared Keys (SEC_CSR0), 122662306a36Sopenharmony_ci * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5) 122762306a36Sopenharmony_ci */ 122862306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000); 122962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000); 123062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000); 123162306a36Sopenharmony_ci 123262306a36Sopenharmony_ci reg = 0x000023b0; 123362306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527)) 123462306a36Sopenharmony_ci rt2x00_set_field32(®, PHY_CSR1_RF_RPI, 1); 123562306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, PHY_CSR1, reg); 123662306a36Sopenharmony_ci 123762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06); 123862306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606); 123962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408); 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR9); 124262306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR9_CW_SELECT, 0); 124362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg); 124462306a36Sopenharmony_ci 124562306a36Sopenharmony_ci /* 124662306a36Sopenharmony_ci * Clear all beacons 124762306a36Sopenharmony_ci * For the Beacon base registers we only need to clear 124862306a36Sopenharmony_ci * the first byte since that byte contains the VALID and OWNER 124962306a36Sopenharmony_ci * bits which (when set to 0) will invalidate the entire beacon. 125062306a36Sopenharmony_ci */ 125162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0); 125262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0); 125362306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0); 125462306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0); 125562306a36Sopenharmony_ci 125662306a36Sopenharmony_ci /* 125762306a36Sopenharmony_ci * We must clear the error counters. 125862306a36Sopenharmony_ci * These registers are cleared on read, 125962306a36Sopenharmony_ci * so we may pass a useless variable to store the value. 126062306a36Sopenharmony_ci */ 126162306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, STA_CSR0); 126262306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, STA_CSR1); 126362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, STA_CSR2); 126462306a36Sopenharmony_ci 126562306a36Sopenharmony_ci /* 126662306a36Sopenharmony_ci * Reset MAC and BBP registers. 126762306a36Sopenharmony_ci */ 126862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR1); 126962306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR1_SOFT_RESET, 1); 127062306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR1_BBP_RESET, 1); 127162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg); 127262306a36Sopenharmony_ci 127362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR1); 127462306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR1_SOFT_RESET, 0); 127562306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR1_BBP_RESET, 0); 127662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg); 127762306a36Sopenharmony_ci 127862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR1); 127962306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR1_HOST_READY, 1); 128062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg); 128162306a36Sopenharmony_ci 128262306a36Sopenharmony_ci return 0; 128362306a36Sopenharmony_ci} 128462306a36Sopenharmony_ci 128562306a36Sopenharmony_cistatic int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) 128662306a36Sopenharmony_ci{ 128762306a36Sopenharmony_ci unsigned int i; 128862306a36Sopenharmony_ci u8 value; 128962306a36Sopenharmony_ci 129062306a36Sopenharmony_ci for (i = 0; i < REGISTER_USB_BUSY_COUNT; i++) { 129162306a36Sopenharmony_ci value = rt73usb_bbp_read(rt2x00dev, 0); 129262306a36Sopenharmony_ci if ((value != 0xff) && (value != 0x00)) 129362306a36Sopenharmony_ci return 0; 129462306a36Sopenharmony_ci udelay(REGISTER_BUSY_DELAY); 129562306a36Sopenharmony_ci } 129662306a36Sopenharmony_ci 129762306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n"); 129862306a36Sopenharmony_ci return -EACCES; 129962306a36Sopenharmony_ci} 130062306a36Sopenharmony_ci 130162306a36Sopenharmony_cistatic int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev) 130262306a36Sopenharmony_ci{ 130362306a36Sopenharmony_ci unsigned int i; 130462306a36Sopenharmony_ci u16 eeprom; 130562306a36Sopenharmony_ci u8 reg_id; 130662306a36Sopenharmony_ci u8 value; 130762306a36Sopenharmony_ci 130862306a36Sopenharmony_ci if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev))) 130962306a36Sopenharmony_ci return -EACCES; 131062306a36Sopenharmony_ci 131162306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 3, 0x80); 131262306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 15, 0x30); 131362306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 21, 0xc8); 131462306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 22, 0x38); 131562306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 23, 0x06); 131662306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 24, 0xfe); 131762306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 25, 0x0a); 131862306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 26, 0x0d); 131962306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 32, 0x0b); 132062306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 34, 0x12); 132162306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 37, 0x07); 132262306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 39, 0xf8); 132362306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 41, 0x60); 132462306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 53, 0x10); 132562306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 54, 0x18); 132662306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 60, 0x10); 132762306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 61, 0x04); 132862306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 62, 0x04); 132962306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 75, 0xfe); 133062306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 86, 0xfe); 133162306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 88, 0xfe); 133262306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 90, 0x0f); 133362306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 99, 0x00); 133462306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 102, 0x16); 133562306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, 107, 0x04); 133662306a36Sopenharmony_ci 133762306a36Sopenharmony_ci for (i = 0; i < EEPROM_BBP_SIZE; i++) { 133862306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i); 133962306a36Sopenharmony_ci 134062306a36Sopenharmony_ci if (eeprom != 0xffff && eeprom != 0x0000) { 134162306a36Sopenharmony_ci reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); 134262306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); 134362306a36Sopenharmony_ci rt73usb_bbp_write(rt2x00dev, reg_id, value); 134462306a36Sopenharmony_ci } 134562306a36Sopenharmony_ci } 134662306a36Sopenharmony_ci 134762306a36Sopenharmony_ci return 0; 134862306a36Sopenharmony_ci} 134962306a36Sopenharmony_ci 135062306a36Sopenharmony_ci/* 135162306a36Sopenharmony_ci * Device state switch handlers. 135262306a36Sopenharmony_ci */ 135362306a36Sopenharmony_cistatic int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev) 135462306a36Sopenharmony_ci{ 135562306a36Sopenharmony_ci /* 135662306a36Sopenharmony_ci * Initialize all registers. 135762306a36Sopenharmony_ci */ 135862306a36Sopenharmony_ci if (unlikely(rt73usb_init_registers(rt2x00dev) || 135962306a36Sopenharmony_ci rt73usb_init_bbp(rt2x00dev))) 136062306a36Sopenharmony_ci return -EIO; 136162306a36Sopenharmony_ci 136262306a36Sopenharmony_ci return 0; 136362306a36Sopenharmony_ci} 136462306a36Sopenharmony_ci 136562306a36Sopenharmony_cistatic void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev) 136662306a36Sopenharmony_ci{ 136762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818); 136862306a36Sopenharmony_ci 136962306a36Sopenharmony_ci /* 137062306a36Sopenharmony_ci * Disable synchronisation. 137162306a36Sopenharmony_ci */ 137262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, 0); 137362306a36Sopenharmony_ci 137462306a36Sopenharmony_ci rt2x00usb_disable_radio(rt2x00dev); 137562306a36Sopenharmony_ci} 137662306a36Sopenharmony_ci 137762306a36Sopenharmony_cistatic int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state) 137862306a36Sopenharmony_ci{ 137962306a36Sopenharmony_ci u32 reg, reg2; 138062306a36Sopenharmony_ci unsigned int i; 138162306a36Sopenharmony_ci bool put_to_sleep; 138262306a36Sopenharmony_ci 138362306a36Sopenharmony_ci put_to_sleep = (state != STATE_AWAKE); 138462306a36Sopenharmony_ci 138562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR12); 138662306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep); 138762306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep); 138862306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg); 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_ci /* 139162306a36Sopenharmony_ci * Device is not guaranteed to be in the requested state yet. 139262306a36Sopenharmony_ci * We must wait until the register indicates that the 139362306a36Sopenharmony_ci * device has entered the correct state. 139462306a36Sopenharmony_ci */ 139562306a36Sopenharmony_ci for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 139662306a36Sopenharmony_ci reg2 = rt2x00usb_register_read(rt2x00dev, MAC_CSR12); 139762306a36Sopenharmony_ci state = rt2x00_get_field32(reg2, MAC_CSR12_BBP_CURRENT_STATE); 139862306a36Sopenharmony_ci if (state == !put_to_sleep) 139962306a36Sopenharmony_ci return 0; 140062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg); 140162306a36Sopenharmony_ci msleep(10); 140262306a36Sopenharmony_ci } 140362306a36Sopenharmony_ci 140462306a36Sopenharmony_ci return -EBUSY; 140562306a36Sopenharmony_ci} 140662306a36Sopenharmony_ci 140762306a36Sopenharmony_cistatic int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev, 140862306a36Sopenharmony_ci enum dev_state state) 140962306a36Sopenharmony_ci{ 141062306a36Sopenharmony_ci int retval = 0; 141162306a36Sopenharmony_ci 141262306a36Sopenharmony_ci switch (state) { 141362306a36Sopenharmony_ci case STATE_RADIO_ON: 141462306a36Sopenharmony_ci retval = rt73usb_enable_radio(rt2x00dev); 141562306a36Sopenharmony_ci break; 141662306a36Sopenharmony_ci case STATE_RADIO_OFF: 141762306a36Sopenharmony_ci rt73usb_disable_radio(rt2x00dev); 141862306a36Sopenharmony_ci break; 141962306a36Sopenharmony_ci case STATE_RADIO_IRQ_ON: 142062306a36Sopenharmony_ci case STATE_RADIO_IRQ_OFF: 142162306a36Sopenharmony_ci /* No support, but no error either */ 142262306a36Sopenharmony_ci break; 142362306a36Sopenharmony_ci case STATE_DEEP_SLEEP: 142462306a36Sopenharmony_ci case STATE_SLEEP: 142562306a36Sopenharmony_ci case STATE_STANDBY: 142662306a36Sopenharmony_ci case STATE_AWAKE: 142762306a36Sopenharmony_ci retval = rt73usb_set_state(rt2x00dev, state); 142862306a36Sopenharmony_ci break; 142962306a36Sopenharmony_ci default: 143062306a36Sopenharmony_ci retval = -ENOTSUPP; 143162306a36Sopenharmony_ci break; 143262306a36Sopenharmony_ci } 143362306a36Sopenharmony_ci 143462306a36Sopenharmony_ci if (unlikely(retval)) 143562306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n", 143662306a36Sopenharmony_ci state, retval); 143762306a36Sopenharmony_ci 143862306a36Sopenharmony_ci return retval; 143962306a36Sopenharmony_ci} 144062306a36Sopenharmony_ci 144162306a36Sopenharmony_ci/* 144262306a36Sopenharmony_ci * TX descriptor initialization 144362306a36Sopenharmony_ci */ 144462306a36Sopenharmony_cistatic void rt73usb_write_tx_desc(struct queue_entry *entry, 144562306a36Sopenharmony_ci struct txentry_desc *txdesc) 144662306a36Sopenharmony_ci{ 144762306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 144862306a36Sopenharmony_ci __le32 *txd = (__le32 *) entry->skb->data; 144962306a36Sopenharmony_ci u32 word; 145062306a36Sopenharmony_ci 145162306a36Sopenharmony_ci /* 145262306a36Sopenharmony_ci * Start writing the descriptor words. 145362306a36Sopenharmony_ci */ 145462306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 0); 145562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_BURST, 145662306a36Sopenharmony_ci test_bit(ENTRY_TXD_BURST, &txdesc->flags)); 145762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_VALID, 1); 145862306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_MORE_FRAG, 145962306a36Sopenharmony_ci test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); 146062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_ACK, 146162306a36Sopenharmony_ci test_bit(ENTRY_TXD_ACK, &txdesc->flags)); 146262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_TIMESTAMP, 146362306a36Sopenharmony_ci test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); 146462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OFDM, 146562306a36Sopenharmony_ci (txdesc->rate_mode == RATE_MODE_OFDM)); 146662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->u.plcp.ifs); 146762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, 146862306a36Sopenharmony_ci test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); 146962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, 147062306a36Sopenharmony_ci test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags)); 147162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_KEY_TABLE, 147262306a36Sopenharmony_ci test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags)); 147362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx); 147462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length); 147562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_BURST2, 147662306a36Sopenharmony_ci test_bit(ENTRY_TXD_BURST, &txdesc->flags)); 147762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher); 147862306a36Sopenharmony_ci rt2x00_desc_write(txd, 0, word); 147962306a36Sopenharmony_ci 148062306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 1); 148162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, entry->queue->qid); 148262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_AIFSN, entry->queue->aifs); 148362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_CWMIN, entry->queue->cw_min); 148462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_CWMAX, entry->queue->cw_max); 148562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset); 148662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE, 148762306a36Sopenharmony_ci test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags)); 148862306a36Sopenharmony_ci rt2x00_desc_write(txd, 1, word); 148962306a36Sopenharmony_ci 149062306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 2); 149162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->u.plcp.signal); 149262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->u.plcp.service); 149362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, 149462306a36Sopenharmony_ci txdesc->u.plcp.length_low); 149562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, 149662306a36Sopenharmony_ci txdesc->u.plcp.length_high); 149762306a36Sopenharmony_ci rt2x00_desc_write(txd, 2, word); 149862306a36Sopenharmony_ci 149962306a36Sopenharmony_ci if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { 150062306a36Sopenharmony_ci _rt2x00_desc_write(txd, 3, skbdesc->iv[0]); 150162306a36Sopenharmony_ci _rt2x00_desc_write(txd, 4, skbdesc->iv[1]); 150262306a36Sopenharmony_ci } 150362306a36Sopenharmony_ci 150462306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 5); 150562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W5_TX_POWER, 150662306a36Sopenharmony_ci TXPOWER_TO_DEV(entry->queue->rt2x00dev->tx_power)); 150762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1); 150862306a36Sopenharmony_ci rt2x00_desc_write(txd, 5, word); 150962306a36Sopenharmony_ci 151062306a36Sopenharmony_ci /* 151162306a36Sopenharmony_ci * Register descriptor details in skb frame descriptor. 151262306a36Sopenharmony_ci */ 151362306a36Sopenharmony_ci skbdesc->flags |= SKBDESC_DESC_IN_SKB; 151462306a36Sopenharmony_ci skbdesc->desc = txd; 151562306a36Sopenharmony_ci skbdesc->desc_len = TXD_DESC_SIZE; 151662306a36Sopenharmony_ci} 151762306a36Sopenharmony_ci 151862306a36Sopenharmony_ci/* 151962306a36Sopenharmony_ci * TX data initialization 152062306a36Sopenharmony_ci */ 152162306a36Sopenharmony_cistatic void rt73usb_write_beacon(struct queue_entry *entry, 152262306a36Sopenharmony_ci struct txentry_desc *txdesc) 152362306a36Sopenharmony_ci{ 152462306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 152562306a36Sopenharmony_ci unsigned int beacon_base; 152662306a36Sopenharmony_ci unsigned int padding_len; 152762306a36Sopenharmony_ci u32 orig_reg, reg; 152862306a36Sopenharmony_ci 152962306a36Sopenharmony_ci /* 153062306a36Sopenharmony_ci * Disable beaconing while we are reloading the beacon data, 153162306a36Sopenharmony_ci * otherwise we might be sending out invalid data. 153262306a36Sopenharmony_ci */ 153362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 153462306a36Sopenharmony_ci orig_reg = reg; 153562306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); 153662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 153762306a36Sopenharmony_ci 153862306a36Sopenharmony_ci /* 153962306a36Sopenharmony_ci * Add space for the descriptor in front of the skb. 154062306a36Sopenharmony_ci */ 154162306a36Sopenharmony_ci skb_push(entry->skb, TXD_DESC_SIZE); 154262306a36Sopenharmony_ci memset(entry->skb->data, 0, TXD_DESC_SIZE); 154362306a36Sopenharmony_ci 154462306a36Sopenharmony_ci /* 154562306a36Sopenharmony_ci * Write the TX descriptor for the beacon. 154662306a36Sopenharmony_ci */ 154762306a36Sopenharmony_ci rt73usb_write_tx_desc(entry, txdesc); 154862306a36Sopenharmony_ci 154962306a36Sopenharmony_ci /* 155062306a36Sopenharmony_ci * Dump beacon to userspace through debugfs. 155162306a36Sopenharmony_ci */ 155262306a36Sopenharmony_ci rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry); 155362306a36Sopenharmony_ci 155462306a36Sopenharmony_ci /* 155562306a36Sopenharmony_ci * Write entire beacon with descriptor and padding to register. 155662306a36Sopenharmony_ci */ 155762306a36Sopenharmony_ci padding_len = roundup(entry->skb->len, 4) - entry->skb->len; 155862306a36Sopenharmony_ci if (padding_len && skb_pad(entry->skb, padding_len)) { 155962306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n"); 156062306a36Sopenharmony_ci /* skb freed by skb_pad() on failure */ 156162306a36Sopenharmony_ci entry->skb = NULL; 156262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, orig_reg); 156362306a36Sopenharmony_ci return; 156462306a36Sopenharmony_ci } 156562306a36Sopenharmony_ci 156662306a36Sopenharmony_ci beacon_base = HW_BEACON_OFFSET(entry->entry_idx); 156762306a36Sopenharmony_ci rt2x00usb_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data, 156862306a36Sopenharmony_ci entry->skb->len + padding_len); 156962306a36Sopenharmony_ci 157062306a36Sopenharmony_ci /* 157162306a36Sopenharmony_ci * Enable beaconing again. 157262306a36Sopenharmony_ci * 157362306a36Sopenharmony_ci * For Wi-Fi faily generated beacons between participating stations. 157462306a36Sopenharmony_ci * Set TBTT phase adaptive adjustment step to 8us (default 16us) 157562306a36Sopenharmony_ci */ 157662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008); 157762306a36Sopenharmony_ci 157862306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 1); 157962306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 158062306a36Sopenharmony_ci 158162306a36Sopenharmony_ci /* 158262306a36Sopenharmony_ci * Clean up the beacon skb. 158362306a36Sopenharmony_ci */ 158462306a36Sopenharmony_ci dev_kfree_skb(entry->skb); 158562306a36Sopenharmony_ci entry->skb = NULL; 158662306a36Sopenharmony_ci} 158762306a36Sopenharmony_ci 158862306a36Sopenharmony_cistatic void rt73usb_clear_beacon(struct queue_entry *entry) 158962306a36Sopenharmony_ci{ 159062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 159162306a36Sopenharmony_ci unsigned int beacon_base; 159262306a36Sopenharmony_ci u32 orig_reg, reg; 159362306a36Sopenharmony_ci 159462306a36Sopenharmony_ci /* 159562306a36Sopenharmony_ci * Disable beaconing while we are reloading the beacon data, 159662306a36Sopenharmony_ci * otherwise we might be sending out invalid data. 159762306a36Sopenharmony_ci */ 159862306a36Sopenharmony_ci orig_reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR9); 159962306a36Sopenharmony_ci reg = orig_reg; 160062306a36Sopenharmony_ci rt2x00_set_field32(®, TXRX_CSR9_BEACON_GEN, 0); 160162306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg); 160262306a36Sopenharmony_ci 160362306a36Sopenharmony_ci /* 160462306a36Sopenharmony_ci * Clear beacon. 160562306a36Sopenharmony_ci */ 160662306a36Sopenharmony_ci beacon_base = HW_BEACON_OFFSET(entry->entry_idx); 160762306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, beacon_base, 0); 160862306a36Sopenharmony_ci 160962306a36Sopenharmony_ci /* 161062306a36Sopenharmony_ci * Restore beaconing state. 161162306a36Sopenharmony_ci */ 161262306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, orig_reg); 161362306a36Sopenharmony_ci} 161462306a36Sopenharmony_ci 161562306a36Sopenharmony_cistatic int rt73usb_get_tx_data_len(struct queue_entry *entry) 161662306a36Sopenharmony_ci{ 161762306a36Sopenharmony_ci int length; 161862306a36Sopenharmony_ci 161962306a36Sopenharmony_ci /* 162062306a36Sopenharmony_ci * The length _must_ be a multiple of 4, 162162306a36Sopenharmony_ci * but it must _not_ be a multiple of the USB packet size. 162262306a36Sopenharmony_ci */ 162362306a36Sopenharmony_ci length = roundup(entry->skb->len, 4); 162462306a36Sopenharmony_ci length += (4 * !(length % entry->queue->usb_maxpacket)); 162562306a36Sopenharmony_ci 162662306a36Sopenharmony_ci return length; 162762306a36Sopenharmony_ci} 162862306a36Sopenharmony_ci 162962306a36Sopenharmony_ci/* 163062306a36Sopenharmony_ci * RX control handlers 163162306a36Sopenharmony_ci */ 163262306a36Sopenharmony_cistatic int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1) 163362306a36Sopenharmony_ci{ 163462306a36Sopenharmony_ci u8 offset = rt2x00dev->lna_gain; 163562306a36Sopenharmony_ci u8 lna; 163662306a36Sopenharmony_ci 163762306a36Sopenharmony_ci lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA); 163862306a36Sopenharmony_ci switch (lna) { 163962306a36Sopenharmony_ci case 3: 164062306a36Sopenharmony_ci offset += 90; 164162306a36Sopenharmony_ci break; 164262306a36Sopenharmony_ci case 2: 164362306a36Sopenharmony_ci offset += 74; 164462306a36Sopenharmony_ci break; 164562306a36Sopenharmony_ci case 1: 164662306a36Sopenharmony_ci offset += 64; 164762306a36Sopenharmony_ci break; 164862306a36Sopenharmony_ci default: 164962306a36Sopenharmony_ci return 0; 165062306a36Sopenharmony_ci } 165162306a36Sopenharmony_ci 165262306a36Sopenharmony_ci if (rt2x00dev->curr_band == NL80211_BAND_5GHZ) { 165362306a36Sopenharmony_ci if (rt2x00_has_cap_external_lna_a(rt2x00dev)) { 165462306a36Sopenharmony_ci if (lna == 3 || lna == 2) 165562306a36Sopenharmony_ci offset += 10; 165662306a36Sopenharmony_ci } else { 165762306a36Sopenharmony_ci if (lna == 3) 165862306a36Sopenharmony_ci offset += 6; 165962306a36Sopenharmony_ci else if (lna == 2) 166062306a36Sopenharmony_ci offset += 8; 166162306a36Sopenharmony_ci } 166262306a36Sopenharmony_ci } 166362306a36Sopenharmony_ci 166462306a36Sopenharmony_ci return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset; 166562306a36Sopenharmony_ci} 166662306a36Sopenharmony_ci 166762306a36Sopenharmony_cistatic void rt73usb_fill_rxdone(struct queue_entry *entry, 166862306a36Sopenharmony_ci struct rxdone_entry_desc *rxdesc) 166962306a36Sopenharmony_ci{ 167062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 167162306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 167262306a36Sopenharmony_ci __le32 *rxd = (__le32 *)entry->skb->data; 167362306a36Sopenharmony_ci u32 word0; 167462306a36Sopenharmony_ci u32 word1; 167562306a36Sopenharmony_ci 167662306a36Sopenharmony_ci /* 167762306a36Sopenharmony_ci * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of 167862306a36Sopenharmony_ci * frame data in rt2x00usb. 167962306a36Sopenharmony_ci */ 168062306a36Sopenharmony_ci memcpy(skbdesc->desc, rxd, skbdesc->desc_len); 168162306a36Sopenharmony_ci rxd = (__le32 *)skbdesc->desc; 168262306a36Sopenharmony_ci 168362306a36Sopenharmony_ci /* 168462306a36Sopenharmony_ci * It is now safe to read the descriptor on all architectures. 168562306a36Sopenharmony_ci */ 168662306a36Sopenharmony_ci word0 = rt2x00_desc_read(rxd, 0); 168762306a36Sopenharmony_ci word1 = rt2x00_desc_read(rxd, 1); 168862306a36Sopenharmony_ci 168962306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) 169062306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; 169162306a36Sopenharmony_ci 169262306a36Sopenharmony_ci rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG); 169362306a36Sopenharmony_ci rxdesc->cipher_status = rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR); 169462306a36Sopenharmony_ci 169562306a36Sopenharmony_ci if (rxdesc->cipher != CIPHER_NONE) { 169662306a36Sopenharmony_ci rxdesc->iv[0] = _rt2x00_desc_read(rxd, 2); 169762306a36Sopenharmony_ci rxdesc->iv[1] = _rt2x00_desc_read(rxd, 3); 169862306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_CRYPTO_IV; 169962306a36Sopenharmony_ci 170062306a36Sopenharmony_ci rxdesc->icv = _rt2x00_desc_read(rxd, 4); 170162306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_CRYPTO_ICV; 170262306a36Sopenharmony_ci 170362306a36Sopenharmony_ci /* 170462306a36Sopenharmony_ci * Hardware has stripped IV/EIV data from 802.11 frame during 170562306a36Sopenharmony_ci * decryption. It has provided the data separately but rt2x00lib 170662306a36Sopenharmony_ci * should decide if it should be reinserted. 170762306a36Sopenharmony_ci */ 170862306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_IV_STRIPPED; 170962306a36Sopenharmony_ci 171062306a36Sopenharmony_ci /* 171162306a36Sopenharmony_ci * The hardware has already checked the Michael Mic and has 171262306a36Sopenharmony_ci * stripped it from the frame. Signal this to mac80211. 171362306a36Sopenharmony_ci */ 171462306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_MMIC_STRIPPED; 171562306a36Sopenharmony_ci 171662306a36Sopenharmony_ci if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) 171762306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_DECRYPTED; 171862306a36Sopenharmony_ci else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) 171962306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_MMIC_ERROR; 172062306a36Sopenharmony_ci } 172162306a36Sopenharmony_ci 172262306a36Sopenharmony_ci /* 172362306a36Sopenharmony_ci * Obtain the status about this packet. 172462306a36Sopenharmony_ci * When frame was received with an OFDM bitrate, 172562306a36Sopenharmony_ci * the signal is the PLCP value. If it was received with 172662306a36Sopenharmony_ci * a CCK bitrate the signal is the rate in 100kbit/s. 172762306a36Sopenharmony_ci */ 172862306a36Sopenharmony_ci rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL); 172962306a36Sopenharmony_ci rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1); 173062306a36Sopenharmony_ci rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); 173162306a36Sopenharmony_ci 173262306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 173362306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 173462306a36Sopenharmony_ci else 173562306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE; 173662306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 173762306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_MY_BSS; 173862306a36Sopenharmony_ci 173962306a36Sopenharmony_ci /* 174062306a36Sopenharmony_ci * Set skb pointers, and update frame information. 174162306a36Sopenharmony_ci */ 174262306a36Sopenharmony_ci skb_pull(entry->skb, entry->queue->desc_size); 174362306a36Sopenharmony_ci skb_trim(entry->skb, rxdesc->size); 174462306a36Sopenharmony_ci} 174562306a36Sopenharmony_ci 174662306a36Sopenharmony_ci/* 174762306a36Sopenharmony_ci * Device probe functions. 174862306a36Sopenharmony_ci */ 174962306a36Sopenharmony_cistatic int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev) 175062306a36Sopenharmony_ci{ 175162306a36Sopenharmony_ci u16 word; 175262306a36Sopenharmony_ci u8 *mac; 175362306a36Sopenharmony_ci s8 value; 175462306a36Sopenharmony_ci 175562306a36Sopenharmony_ci rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE); 175662306a36Sopenharmony_ci 175762306a36Sopenharmony_ci /* 175862306a36Sopenharmony_ci * Start validation of the data that has been read. 175962306a36Sopenharmony_ci */ 176062306a36Sopenharmony_ci mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); 176162306a36Sopenharmony_ci rt2x00lib_set_mac_address(rt2x00dev, mac); 176262306a36Sopenharmony_ci 176362306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 176462306a36Sopenharmony_ci if (word == 0xffff) { 176562306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2); 176662306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT, 176762306a36Sopenharmony_ci ANTENNA_B); 176862306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT, 176962306a36Sopenharmony_ci ANTENNA_B); 177062306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0); 177162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0); 177262306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0); 177362306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226); 177462306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word); 177562306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word); 177662306a36Sopenharmony_ci } 177762306a36Sopenharmony_ci 177862306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC); 177962306a36Sopenharmony_ci if (word == 0xffff) { 178062306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0); 178162306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word); 178262306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word); 178362306a36Sopenharmony_ci } 178462306a36Sopenharmony_ci 178562306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_LED); 178662306a36Sopenharmony_ci if (word == 0xffff) { 178762306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0); 178862306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0); 178962306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0); 179062306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0); 179162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0); 179262306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0); 179362306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0); 179462306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0); 179562306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_LED_LED_MODE, 179662306a36Sopenharmony_ci LED_MODE_DEFAULT); 179762306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word); 179862306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "Led: 0x%04x\n", word); 179962306a36Sopenharmony_ci } 180062306a36Sopenharmony_ci 180162306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ); 180262306a36Sopenharmony_ci if (word == 0xffff) { 180362306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0); 180462306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0); 180562306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word); 180662306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word); 180762306a36Sopenharmony_ci } 180862306a36Sopenharmony_ci 180962306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG); 181062306a36Sopenharmony_ci if (word == 0xffff) { 181162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0); 181262306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0); 181362306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word); 181462306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word); 181562306a36Sopenharmony_ci } else { 181662306a36Sopenharmony_ci value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1); 181762306a36Sopenharmony_ci if (value < -10 || value > 10) 181862306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0); 181962306a36Sopenharmony_ci value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2); 182062306a36Sopenharmony_ci if (value < -10 || value > 10) 182162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0); 182262306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word); 182362306a36Sopenharmony_ci } 182462306a36Sopenharmony_ci 182562306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A); 182662306a36Sopenharmony_ci if (word == 0xffff) { 182762306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0); 182862306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0); 182962306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word); 183062306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word); 183162306a36Sopenharmony_ci } else { 183262306a36Sopenharmony_ci value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1); 183362306a36Sopenharmony_ci if (value < -10 || value > 10) 183462306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0); 183562306a36Sopenharmony_ci value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2); 183662306a36Sopenharmony_ci if (value < -10 || value > 10) 183762306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0); 183862306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word); 183962306a36Sopenharmony_ci } 184062306a36Sopenharmony_ci 184162306a36Sopenharmony_ci return 0; 184262306a36Sopenharmony_ci} 184362306a36Sopenharmony_ci 184462306a36Sopenharmony_cistatic int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev) 184562306a36Sopenharmony_ci{ 184662306a36Sopenharmony_ci u32 reg; 184762306a36Sopenharmony_ci u16 value; 184862306a36Sopenharmony_ci u16 eeprom; 184962306a36Sopenharmony_ci 185062306a36Sopenharmony_ci /* 185162306a36Sopenharmony_ci * Read EEPROM word for configuration. 185262306a36Sopenharmony_ci */ 185362306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 185462306a36Sopenharmony_ci 185562306a36Sopenharmony_ci /* 185662306a36Sopenharmony_ci * Identify RF chipset. 185762306a36Sopenharmony_ci */ 185862306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 185962306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR0); 186062306a36Sopenharmony_ci rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET), 186162306a36Sopenharmony_ci value, rt2x00_get_field32(reg, MAC_CSR0_REVISION)); 186262306a36Sopenharmony_ci 186362306a36Sopenharmony_ci if (!rt2x00_rt(rt2x00dev, RT2573) || (rt2x00_rev(rt2x00dev) == 0)) { 186462306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Invalid RT chipset detected\n"); 186562306a36Sopenharmony_ci return -ENODEV; 186662306a36Sopenharmony_ci } 186762306a36Sopenharmony_ci 186862306a36Sopenharmony_ci if (!rt2x00_rf(rt2x00dev, RF5226) && 186962306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2528) && 187062306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF5225) && 187162306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2527)) { 187262306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Invalid RF chipset detected\n"); 187362306a36Sopenharmony_ci return -ENODEV; 187462306a36Sopenharmony_ci } 187562306a36Sopenharmony_ci 187662306a36Sopenharmony_ci /* 187762306a36Sopenharmony_ci * Identify default antenna configuration. 187862306a36Sopenharmony_ci */ 187962306a36Sopenharmony_ci rt2x00dev->default_ant.tx = 188062306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT); 188162306a36Sopenharmony_ci rt2x00dev->default_ant.rx = 188262306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT); 188362306a36Sopenharmony_ci 188462306a36Sopenharmony_ci /* 188562306a36Sopenharmony_ci * Read the Frame type. 188662306a36Sopenharmony_ci */ 188762306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE)) 188862306a36Sopenharmony_ci __set_bit(CAPABILITY_FRAME_TYPE, &rt2x00dev->cap_flags); 188962306a36Sopenharmony_ci 189062306a36Sopenharmony_ci /* 189162306a36Sopenharmony_ci * Detect if this device has an hardware controlled radio. 189262306a36Sopenharmony_ci */ 189362306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 189462306a36Sopenharmony_ci __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags); 189562306a36Sopenharmony_ci 189662306a36Sopenharmony_ci /* 189762306a36Sopenharmony_ci * Read frequency offset. 189862306a36Sopenharmony_ci */ 189962306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ); 190062306a36Sopenharmony_ci rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET); 190162306a36Sopenharmony_ci 190262306a36Sopenharmony_ci /* 190362306a36Sopenharmony_ci * Read external LNA informations. 190462306a36Sopenharmony_ci */ 190562306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC); 190662306a36Sopenharmony_ci 190762306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) { 190862306a36Sopenharmony_ci __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags); 190962306a36Sopenharmony_ci __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags); 191062306a36Sopenharmony_ci } 191162306a36Sopenharmony_ci 191262306a36Sopenharmony_ci /* 191362306a36Sopenharmony_ci * Store led settings, for correct led behaviour. 191462306a36Sopenharmony_ci */ 191562306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_LEDS 191662306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_LED); 191762306a36Sopenharmony_ci 191862306a36Sopenharmony_ci rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 191962306a36Sopenharmony_ci rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC); 192062306a36Sopenharmony_ci if (value == LED_MODE_SIGNAL_STRENGTH) 192162306a36Sopenharmony_ci rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual, 192262306a36Sopenharmony_ci LED_TYPE_QUALITY); 192362306a36Sopenharmony_ci 192462306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value); 192562306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0, 192662306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 192762306a36Sopenharmony_ci EEPROM_LED_POLARITY_GPIO_0)); 192862306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1, 192962306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 193062306a36Sopenharmony_ci EEPROM_LED_POLARITY_GPIO_1)); 193162306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2, 193262306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 193362306a36Sopenharmony_ci EEPROM_LED_POLARITY_GPIO_2)); 193462306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3, 193562306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 193662306a36Sopenharmony_ci EEPROM_LED_POLARITY_GPIO_3)); 193762306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4, 193862306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 193962306a36Sopenharmony_ci EEPROM_LED_POLARITY_GPIO_4)); 194062306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT, 194162306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT)); 194262306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG, 194362306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 194462306a36Sopenharmony_ci EEPROM_LED_POLARITY_RDY_G)); 194562306a36Sopenharmony_ci rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A, 194662306a36Sopenharmony_ci rt2x00_get_field16(eeprom, 194762306a36Sopenharmony_ci EEPROM_LED_POLARITY_RDY_A)); 194862306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_LEDS */ 194962306a36Sopenharmony_ci 195062306a36Sopenharmony_ci return 0; 195162306a36Sopenharmony_ci} 195262306a36Sopenharmony_ci 195362306a36Sopenharmony_ci/* 195462306a36Sopenharmony_ci * RF value list for RF2528 195562306a36Sopenharmony_ci * Supports: 2.4 GHz 195662306a36Sopenharmony_ci */ 195762306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2528[] = { 195862306a36Sopenharmony_ci { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b }, 195962306a36Sopenharmony_ci { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f }, 196062306a36Sopenharmony_ci { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b }, 196162306a36Sopenharmony_ci { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f }, 196262306a36Sopenharmony_ci { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b }, 196362306a36Sopenharmony_ci { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f }, 196462306a36Sopenharmony_ci { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b }, 196562306a36Sopenharmony_ci { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f }, 196662306a36Sopenharmony_ci { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b }, 196762306a36Sopenharmony_ci { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f }, 196862306a36Sopenharmony_ci { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b }, 196962306a36Sopenharmony_ci { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f }, 197062306a36Sopenharmony_ci { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b }, 197162306a36Sopenharmony_ci { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 }, 197262306a36Sopenharmony_ci}; 197362306a36Sopenharmony_ci 197462306a36Sopenharmony_ci/* 197562306a36Sopenharmony_ci * RF value list for RF5226 197662306a36Sopenharmony_ci * Supports: 2.4 GHz & 5.2 GHz 197762306a36Sopenharmony_ci */ 197862306a36Sopenharmony_cistatic const struct rf_channel rf_vals_5226[] = { 197962306a36Sopenharmony_ci { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b }, 198062306a36Sopenharmony_ci { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f }, 198162306a36Sopenharmony_ci { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b }, 198262306a36Sopenharmony_ci { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f }, 198362306a36Sopenharmony_ci { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b }, 198462306a36Sopenharmony_ci { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f }, 198562306a36Sopenharmony_ci { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b }, 198662306a36Sopenharmony_ci { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f }, 198762306a36Sopenharmony_ci { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b }, 198862306a36Sopenharmony_ci { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f }, 198962306a36Sopenharmony_ci { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b }, 199062306a36Sopenharmony_ci { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f }, 199162306a36Sopenharmony_ci { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b }, 199262306a36Sopenharmony_ci { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 }, 199362306a36Sopenharmony_ci 199462306a36Sopenharmony_ci /* 802.11 UNI / HyperLan 2 */ 199562306a36Sopenharmony_ci { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 }, 199662306a36Sopenharmony_ci { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 }, 199762306a36Sopenharmony_ci { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b }, 199862306a36Sopenharmony_ci { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 }, 199962306a36Sopenharmony_ci { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b }, 200062306a36Sopenharmony_ci { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 }, 200162306a36Sopenharmony_ci { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 }, 200262306a36Sopenharmony_ci { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b }, 200362306a36Sopenharmony_ci 200462306a36Sopenharmony_ci /* 802.11 HyperLan 2 */ 200562306a36Sopenharmony_ci { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 }, 200662306a36Sopenharmony_ci { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b }, 200762306a36Sopenharmony_ci { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 }, 200862306a36Sopenharmony_ci { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b }, 200962306a36Sopenharmony_ci { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 }, 201062306a36Sopenharmony_ci { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 }, 201162306a36Sopenharmony_ci { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b }, 201262306a36Sopenharmony_ci { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 }, 201362306a36Sopenharmony_ci { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b }, 201462306a36Sopenharmony_ci { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 }, 201562306a36Sopenharmony_ci 201662306a36Sopenharmony_ci /* 802.11 UNII */ 201762306a36Sopenharmony_ci { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 }, 201862306a36Sopenharmony_ci { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f }, 201962306a36Sopenharmony_ci { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 }, 202062306a36Sopenharmony_ci { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 }, 202162306a36Sopenharmony_ci { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f }, 202262306a36Sopenharmony_ci { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 }, 202362306a36Sopenharmony_ci 202462306a36Sopenharmony_ci /* MMAC(Japan)J52 ch 34,38,42,46 */ 202562306a36Sopenharmony_ci { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b }, 202662306a36Sopenharmony_ci { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 }, 202762306a36Sopenharmony_ci { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b }, 202862306a36Sopenharmony_ci { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 }, 202962306a36Sopenharmony_ci}; 203062306a36Sopenharmony_ci 203162306a36Sopenharmony_ci/* 203262306a36Sopenharmony_ci * RF value list for RF5225 & RF2527 203362306a36Sopenharmony_ci * Supports: 2.4 GHz & 5.2 GHz 203462306a36Sopenharmony_ci */ 203562306a36Sopenharmony_cistatic const struct rf_channel rf_vals_5225_2527[] = { 203662306a36Sopenharmony_ci { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b }, 203762306a36Sopenharmony_ci { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f }, 203862306a36Sopenharmony_ci { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b }, 203962306a36Sopenharmony_ci { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f }, 204062306a36Sopenharmony_ci { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b }, 204162306a36Sopenharmony_ci { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f }, 204262306a36Sopenharmony_ci { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b }, 204362306a36Sopenharmony_ci { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f }, 204462306a36Sopenharmony_ci { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b }, 204562306a36Sopenharmony_ci { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f }, 204662306a36Sopenharmony_ci { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b }, 204762306a36Sopenharmony_ci { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f }, 204862306a36Sopenharmony_ci { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b }, 204962306a36Sopenharmony_ci { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 }, 205062306a36Sopenharmony_ci 205162306a36Sopenharmony_ci /* 802.11 UNI / HyperLan 2 */ 205262306a36Sopenharmony_ci { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 }, 205362306a36Sopenharmony_ci { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 }, 205462306a36Sopenharmony_ci { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b }, 205562306a36Sopenharmony_ci { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 }, 205662306a36Sopenharmony_ci { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b }, 205762306a36Sopenharmony_ci { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 }, 205862306a36Sopenharmony_ci { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 }, 205962306a36Sopenharmony_ci { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b }, 206062306a36Sopenharmony_ci 206162306a36Sopenharmony_ci /* 802.11 HyperLan 2 */ 206262306a36Sopenharmony_ci { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 }, 206362306a36Sopenharmony_ci { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b }, 206462306a36Sopenharmony_ci { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 }, 206562306a36Sopenharmony_ci { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b }, 206662306a36Sopenharmony_ci { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 }, 206762306a36Sopenharmony_ci { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 }, 206862306a36Sopenharmony_ci { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b }, 206962306a36Sopenharmony_ci { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 }, 207062306a36Sopenharmony_ci { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b }, 207162306a36Sopenharmony_ci { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 }, 207262306a36Sopenharmony_ci 207362306a36Sopenharmony_ci /* 802.11 UNII */ 207462306a36Sopenharmony_ci { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 }, 207562306a36Sopenharmony_ci { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f }, 207662306a36Sopenharmony_ci { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 }, 207762306a36Sopenharmony_ci { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 }, 207862306a36Sopenharmony_ci { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f }, 207962306a36Sopenharmony_ci { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 }, 208062306a36Sopenharmony_ci 208162306a36Sopenharmony_ci /* MMAC(Japan)J52 ch 34,38,42,46 */ 208262306a36Sopenharmony_ci { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b }, 208362306a36Sopenharmony_ci { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 }, 208462306a36Sopenharmony_ci { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b }, 208562306a36Sopenharmony_ci { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 }, 208662306a36Sopenharmony_ci}; 208762306a36Sopenharmony_ci 208862306a36Sopenharmony_ci 208962306a36Sopenharmony_cistatic int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 209062306a36Sopenharmony_ci{ 209162306a36Sopenharmony_ci struct hw_mode_spec *spec = &rt2x00dev->spec; 209262306a36Sopenharmony_ci struct channel_info *info; 209362306a36Sopenharmony_ci u8 *tx_power; 209462306a36Sopenharmony_ci unsigned int i; 209562306a36Sopenharmony_ci 209662306a36Sopenharmony_ci /* 209762306a36Sopenharmony_ci * Initialize all hw fields. 209862306a36Sopenharmony_ci * 209962306a36Sopenharmony_ci * Don't set IEEE80211_HOST_BROADCAST_PS_BUFFERING unless we are 210062306a36Sopenharmony_ci * capable of sending the buffered frames out after the DTIM 210162306a36Sopenharmony_ci * transmission using rt2x00lib_beacondone. This will send out 210262306a36Sopenharmony_ci * multicast and broadcast traffic immediately instead of buffering it 210362306a36Sopenharmony_ci * infinitly and thus dropping it after some time. 210462306a36Sopenharmony_ci */ 210562306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, PS_NULLFUNC_STACK); 210662306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SIGNAL_DBM); 210762306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SUPPORTS_PS); 210862306a36Sopenharmony_ci 210962306a36Sopenharmony_ci SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); 211062306a36Sopenharmony_ci SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, 211162306a36Sopenharmony_ci rt2x00_eeprom_addr(rt2x00dev, 211262306a36Sopenharmony_ci EEPROM_MAC_ADDR_0)); 211362306a36Sopenharmony_ci 211462306a36Sopenharmony_ci /* 211562306a36Sopenharmony_ci * Initialize hw_mode information. 211662306a36Sopenharmony_ci */ 211762306a36Sopenharmony_ci spec->supported_bands = SUPPORT_BAND_2GHZ; 211862306a36Sopenharmony_ci spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 211962306a36Sopenharmony_ci 212062306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2528)) { 212162306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528); 212262306a36Sopenharmony_ci spec->channels = rf_vals_bg_2528; 212362306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF5226)) { 212462306a36Sopenharmony_ci spec->supported_bands |= SUPPORT_BAND_5GHZ; 212562306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_5226); 212662306a36Sopenharmony_ci spec->channels = rf_vals_5226; 212762306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF2527)) { 212862306a36Sopenharmony_ci spec->num_channels = 14; 212962306a36Sopenharmony_ci spec->channels = rf_vals_5225_2527; 213062306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF5225)) { 213162306a36Sopenharmony_ci spec->supported_bands |= SUPPORT_BAND_5GHZ; 213262306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527); 213362306a36Sopenharmony_ci spec->channels = rf_vals_5225_2527; 213462306a36Sopenharmony_ci } 213562306a36Sopenharmony_ci 213662306a36Sopenharmony_ci /* 213762306a36Sopenharmony_ci * Create channel information array 213862306a36Sopenharmony_ci */ 213962306a36Sopenharmony_ci info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); 214062306a36Sopenharmony_ci if (!info) 214162306a36Sopenharmony_ci return -ENOMEM; 214262306a36Sopenharmony_ci 214362306a36Sopenharmony_ci spec->channels_info = info; 214462306a36Sopenharmony_ci 214562306a36Sopenharmony_ci tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START); 214662306a36Sopenharmony_ci for (i = 0; i < 14; i++) { 214762306a36Sopenharmony_ci info[i].max_power = MAX_TXPOWER; 214862306a36Sopenharmony_ci info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]); 214962306a36Sopenharmony_ci } 215062306a36Sopenharmony_ci 215162306a36Sopenharmony_ci if (spec->num_channels > 14) { 215262306a36Sopenharmony_ci tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START); 215362306a36Sopenharmony_ci for (i = 14; i < spec->num_channels; i++) { 215462306a36Sopenharmony_ci info[i].max_power = MAX_TXPOWER; 215562306a36Sopenharmony_ci info[i].default_power1 = 215662306a36Sopenharmony_ci TXPOWER_FROM_DEV(tx_power[i - 14]); 215762306a36Sopenharmony_ci } 215862306a36Sopenharmony_ci } 215962306a36Sopenharmony_ci 216062306a36Sopenharmony_ci return 0; 216162306a36Sopenharmony_ci} 216262306a36Sopenharmony_ci 216362306a36Sopenharmony_cistatic int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev) 216462306a36Sopenharmony_ci{ 216562306a36Sopenharmony_ci int retval; 216662306a36Sopenharmony_ci u32 reg; 216762306a36Sopenharmony_ci 216862306a36Sopenharmony_ci /* 216962306a36Sopenharmony_ci * Allocate eeprom data. 217062306a36Sopenharmony_ci */ 217162306a36Sopenharmony_ci retval = rt73usb_validate_eeprom(rt2x00dev); 217262306a36Sopenharmony_ci if (retval) 217362306a36Sopenharmony_ci return retval; 217462306a36Sopenharmony_ci 217562306a36Sopenharmony_ci retval = rt73usb_init_eeprom(rt2x00dev); 217662306a36Sopenharmony_ci if (retval) 217762306a36Sopenharmony_ci return retval; 217862306a36Sopenharmony_ci 217962306a36Sopenharmony_ci /* 218062306a36Sopenharmony_ci * Enable rfkill polling by setting GPIO direction of the 218162306a36Sopenharmony_ci * rfkill switch GPIO pin correctly. 218262306a36Sopenharmony_ci */ 218362306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, MAC_CSR13); 218462306a36Sopenharmony_ci rt2x00_set_field32(®, MAC_CSR13_DIR7, 0); 218562306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, MAC_CSR13, reg); 218662306a36Sopenharmony_ci 218762306a36Sopenharmony_ci /* 218862306a36Sopenharmony_ci * Initialize hw specifications. 218962306a36Sopenharmony_ci */ 219062306a36Sopenharmony_ci retval = rt73usb_probe_hw_mode(rt2x00dev); 219162306a36Sopenharmony_ci if (retval) 219262306a36Sopenharmony_ci return retval; 219362306a36Sopenharmony_ci 219462306a36Sopenharmony_ci /* 219562306a36Sopenharmony_ci * This device has multiple filters for control frames, 219662306a36Sopenharmony_ci * but has no a separate filter for PS Poll frames. 219762306a36Sopenharmony_ci */ 219862306a36Sopenharmony_ci __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags); 219962306a36Sopenharmony_ci 220062306a36Sopenharmony_ci /* 220162306a36Sopenharmony_ci * This device requires firmware. 220262306a36Sopenharmony_ci */ 220362306a36Sopenharmony_ci __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags); 220462306a36Sopenharmony_ci if (!modparam_nohwcrypt) 220562306a36Sopenharmony_ci __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags); 220662306a36Sopenharmony_ci __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); 220762306a36Sopenharmony_ci __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags); 220862306a36Sopenharmony_ci 220962306a36Sopenharmony_ci /* 221062306a36Sopenharmony_ci * Set the rssi offset. 221162306a36Sopenharmony_ci */ 221262306a36Sopenharmony_ci rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; 221362306a36Sopenharmony_ci 221462306a36Sopenharmony_ci return 0; 221562306a36Sopenharmony_ci} 221662306a36Sopenharmony_ci 221762306a36Sopenharmony_ci/* 221862306a36Sopenharmony_ci * IEEE80211 stack callback functions. 221962306a36Sopenharmony_ci */ 222062306a36Sopenharmony_cistatic int rt73usb_conf_tx(struct ieee80211_hw *hw, 222162306a36Sopenharmony_ci struct ieee80211_vif *vif, 222262306a36Sopenharmony_ci unsigned int link_id, u16 queue_idx, 222362306a36Sopenharmony_ci const struct ieee80211_tx_queue_params *params) 222462306a36Sopenharmony_ci{ 222562306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 222662306a36Sopenharmony_ci struct data_queue *queue; 222762306a36Sopenharmony_ci struct rt2x00_field32 field; 222862306a36Sopenharmony_ci int retval; 222962306a36Sopenharmony_ci u32 reg; 223062306a36Sopenharmony_ci u32 offset; 223162306a36Sopenharmony_ci 223262306a36Sopenharmony_ci /* 223362306a36Sopenharmony_ci * First pass the configuration through rt2x00lib, that will 223462306a36Sopenharmony_ci * update the queue settings and validate the input. After that 223562306a36Sopenharmony_ci * we are free to update the registers based on the value 223662306a36Sopenharmony_ci * in the queue parameter. 223762306a36Sopenharmony_ci */ 223862306a36Sopenharmony_ci retval = rt2x00mac_conf_tx(hw, vif, link_id, queue_idx, params); 223962306a36Sopenharmony_ci if (retval) 224062306a36Sopenharmony_ci return retval; 224162306a36Sopenharmony_ci 224262306a36Sopenharmony_ci /* 224362306a36Sopenharmony_ci * We only need to perform additional register initialization 224462306a36Sopenharmony_ci * for WMM queues/ 224562306a36Sopenharmony_ci */ 224662306a36Sopenharmony_ci if (queue_idx >= 4) 224762306a36Sopenharmony_ci return 0; 224862306a36Sopenharmony_ci 224962306a36Sopenharmony_ci queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); 225062306a36Sopenharmony_ci 225162306a36Sopenharmony_ci /* Update WMM TXOP register */ 225262306a36Sopenharmony_ci offset = AC_TXOP_CSR0 + (sizeof(u32) * (!!(queue_idx & 2))); 225362306a36Sopenharmony_ci field.bit_offset = (queue_idx & 1) * 16; 225462306a36Sopenharmony_ci field.bit_mask = 0xffff << field.bit_offset; 225562306a36Sopenharmony_ci 225662306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, offset); 225762306a36Sopenharmony_ci rt2x00_set_field32(®, field, queue->txop); 225862306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, offset, reg); 225962306a36Sopenharmony_ci 226062306a36Sopenharmony_ci /* Update WMM registers */ 226162306a36Sopenharmony_ci field.bit_offset = queue_idx * 4; 226262306a36Sopenharmony_ci field.bit_mask = 0xf << field.bit_offset; 226362306a36Sopenharmony_ci 226462306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, AIFSN_CSR); 226562306a36Sopenharmony_ci rt2x00_set_field32(®, field, queue->aifs); 226662306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, AIFSN_CSR, reg); 226762306a36Sopenharmony_ci 226862306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, CWMIN_CSR); 226962306a36Sopenharmony_ci rt2x00_set_field32(®, field, queue->cw_min); 227062306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, CWMIN_CSR, reg); 227162306a36Sopenharmony_ci 227262306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, CWMAX_CSR); 227362306a36Sopenharmony_ci rt2x00_set_field32(®, field, queue->cw_max); 227462306a36Sopenharmony_ci rt2x00usb_register_write(rt2x00dev, CWMAX_CSR, reg); 227562306a36Sopenharmony_ci 227662306a36Sopenharmony_ci return 0; 227762306a36Sopenharmony_ci} 227862306a36Sopenharmony_ci 227962306a36Sopenharmony_cistatic u64 rt73usb_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 228062306a36Sopenharmony_ci{ 228162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 228262306a36Sopenharmony_ci u64 tsf; 228362306a36Sopenharmony_ci u32 reg; 228462306a36Sopenharmony_ci 228562306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR13); 228662306a36Sopenharmony_ci tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32; 228762306a36Sopenharmony_ci reg = rt2x00usb_register_read(rt2x00dev, TXRX_CSR12); 228862306a36Sopenharmony_ci tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER); 228962306a36Sopenharmony_ci 229062306a36Sopenharmony_ci return tsf; 229162306a36Sopenharmony_ci} 229262306a36Sopenharmony_ci 229362306a36Sopenharmony_cistatic const struct ieee80211_ops rt73usb_mac80211_ops = { 229462306a36Sopenharmony_ci .tx = rt2x00mac_tx, 229562306a36Sopenharmony_ci .wake_tx_queue = ieee80211_handle_wake_tx_queue, 229662306a36Sopenharmony_ci .start = rt2x00mac_start, 229762306a36Sopenharmony_ci .stop = rt2x00mac_stop, 229862306a36Sopenharmony_ci .add_interface = rt2x00mac_add_interface, 229962306a36Sopenharmony_ci .remove_interface = rt2x00mac_remove_interface, 230062306a36Sopenharmony_ci .config = rt2x00mac_config, 230162306a36Sopenharmony_ci .configure_filter = rt2x00mac_configure_filter, 230262306a36Sopenharmony_ci .set_tim = rt2x00mac_set_tim, 230362306a36Sopenharmony_ci .set_key = rt2x00mac_set_key, 230462306a36Sopenharmony_ci .sw_scan_start = rt2x00mac_sw_scan_start, 230562306a36Sopenharmony_ci .sw_scan_complete = rt2x00mac_sw_scan_complete, 230662306a36Sopenharmony_ci .get_stats = rt2x00mac_get_stats, 230762306a36Sopenharmony_ci .bss_info_changed = rt2x00mac_bss_info_changed, 230862306a36Sopenharmony_ci .conf_tx = rt73usb_conf_tx, 230962306a36Sopenharmony_ci .get_tsf = rt73usb_get_tsf, 231062306a36Sopenharmony_ci .rfkill_poll = rt2x00mac_rfkill_poll, 231162306a36Sopenharmony_ci .flush = rt2x00mac_flush, 231262306a36Sopenharmony_ci .set_antenna = rt2x00mac_set_antenna, 231362306a36Sopenharmony_ci .get_antenna = rt2x00mac_get_antenna, 231462306a36Sopenharmony_ci .get_ringparam = rt2x00mac_get_ringparam, 231562306a36Sopenharmony_ci .tx_frames_pending = rt2x00mac_tx_frames_pending, 231662306a36Sopenharmony_ci}; 231762306a36Sopenharmony_ci 231862306a36Sopenharmony_cistatic const struct rt2x00lib_ops rt73usb_rt2x00_ops = { 231962306a36Sopenharmony_ci .probe_hw = rt73usb_probe_hw, 232062306a36Sopenharmony_ci .get_firmware_name = rt73usb_get_firmware_name, 232162306a36Sopenharmony_ci .check_firmware = rt73usb_check_firmware, 232262306a36Sopenharmony_ci .load_firmware = rt73usb_load_firmware, 232362306a36Sopenharmony_ci .initialize = rt2x00usb_initialize, 232462306a36Sopenharmony_ci .uninitialize = rt2x00usb_uninitialize, 232562306a36Sopenharmony_ci .clear_entry = rt2x00usb_clear_entry, 232662306a36Sopenharmony_ci .set_device_state = rt73usb_set_device_state, 232762306a36Sopenharmony_ci .rfkill_poll = rt73usb_rfkill_poll, 232862306a36Sopenharmony_ci .link_stats = rt73usb_link_stats, 232962306a36Sopenharmony_ci .reset_tuner = rt73usb_reset_tuner, 233062306a36Sopenharmony_ci .link_tuner = rt73usb_link_tuner, 233162306a36Sopenharmony_ci .watchdog = rt2x00usb_watchdog, 233262306a36Sopenharmony_ci .start_queue = rt73usb_start_queue, 233362306a36Sopenharmony_ci .kick_queue = rt2x00usb_kick_queue, 233462306a36Sopenharmony_ci .stop_queue = rt73usb_stop_queue, 233562306a36Sopenharmony_ci .flush_queue = rt2x00usb_flush_queue, 233662306a36Sopenharmony_ci .write_tx_desc = rt73usb_write_tx_desc, 233762306a36Sopenharmony_ci .write_beacon = rt73usb_write_beacon, 233862306a36Sopenharmony_ci .clear_beacon = rt73usb_clear_beacon, 233962306a36Sopenharmony_ci .get_tx_data_len = rt73usb_get_tx_data_len, 234062306a36Sopenharmony_ci .fill_rxdone = rt73usb_fill_rxdone, 234162306a36Sopenharmony_ci .config_shared_key = rt73usb_config_shared_key, 234262306a36Sopenharmony_ci .config_pairwise_key = rt73usb_config_pairwise_key, 234362306a36Sopenharmony_ci .config_filter = rt73usb_config_filter, 234462306a36Sopenharmony_ci .config_intf = rt73usb_config_intf, 234562306a36Sopenharmony_ci .config_erp = rt73usb_config_erp, 234662306a36Sopenharmony_ci .config_ant = rt73usb_config_ant, 234762306a36Sopenharmony_ci .config = rt73usb_config, 234862306a36Sopenharmony_ci}; 234962306a36Sopenharmony_ci 235062306a36Sopenharmony_cistatic void rt73usb_queue_init(struct data_queue *queue) 235162306a36Sopenharmony_ci{ 235262306a36Sopenharmony_ci switch (queue->qid) { 235362306a36Sopenharmony_ci case QID_RX: 235462306a36Sopenharmony_ci queue->limit = 32; 235562306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 235662306a36Sopenharmony_ci queue->desc_size = RXD_DESC_SIZE; 235762306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_usb); 235862306a36Sopenharmony_ci break; 235962306a36Sopenharmony_ci 236062306a36Sopenharmony_ci case QID_AC_VO: 236162306a36Sopenharmony_ci case QID_AC_VI: 236262306a36Sopenharmony_ci case QID_AC_BE: 236362306a36Sopenharmony_ci case QID_AC_BK: 236462306a36Sopenharmony_ci queue->limit = 32; 236562306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 236662306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 236762306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_usb); 236862306a36Sopenharmony_ci break; 236962306a36Sopenharmony_ci 237062306a36Sopenharmony_ci case QID_BEACON: 237162306a36Sopenharmony_ci queue->limit = 4; 237262306a36Sopenharmony_ci queue->data_size = MGMT_FRAME_SIZE; 237362306a36Sopenharmony_ci queue->desc_size = TXINFO_SIZE; 237462306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_usb); 237562306a36Sopenharmony_ci break; 237662306a36Sopenharmony_ci 237762306a36Sopenharmony_ci case QID_ATIM: 237862306a36Sopenharmony_ci default: 237962306a36Sopenharmony_ci BUG(); 238062306a36Sopenharmony_ci break; 238162306a36Sopenharmony_ci } 238262306a36Sopenharmony_ci} 238362306a36Sopenharmony_ci 238462306a36Sopenharmony_cistatic const struct rt2x00_ops rt73usb_ops = { 238562306a36Sopenharmony_ci .name = KBUILD_MODNAME, 238662306a36Sopenharmony_ci .max_ap_intf = 4, 238762306a36Sopenharmony_ci .eeprom_size = EEPROM_SIZE, 238862306a36Sopenharmony_ci .rf_size = RF_SIZE, 238962306a36Sopenharmony_ci .tx_queues = NUM_TX_QUEUES, 239062306a36Sopenharmony_ci .queue_init = rt73usb_queue_init, 239162306a36Sopenharmony_ci .lib = &rt73usb_rt2x00_ops, 239262306a36Sopenharmony_ci .hw = &rt73usb_mac80211_ops, 239362306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS 239462306a36Sopenharmony_ci .debugfs = &rt73usb_rt2x00debug, 239562306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 239662306a36Sopenharmony_ci}; 239762306a36Sopenharmony_ci 239862306a36Sopenharmony_ci/* 239962306a36Sopenharmony_ci * rt73usb module information. 240062306a36Sopenharmony_ci */ 240162306a36Sopenharmony_cistatic const struct usb_device_id rt73usb_device_table[] = { 240262306a36Sopenharmony_ci /* AboCom */ 240362306a36Sopenharmony_ci { USB_DEVICE(0x07b8, 0xb21b) }, 240462306a36Sopenharmony_ci { USB_DEVICE(0x07b8, 0xb21c) }, 240562306a36Sopenharmony_ci { USB_DEVICE(0x07b8, 0xb21d) }, 240662306a36Sopenharmony_ci { USB_DEVICE(0x07b8, 0xb21e) }, 240762306a36Sopenharmony_ci { USB_DEVICE(0x07b8, 0xb21f) }, 240862306a36Sopenharmony_ci /* AL */ 240962306a36Sopenharmony_ci { USB_DEVICE(0x14b2, 0x3c10) }, 241062306a36Sopenharmony_ci /* Amigo */ 241162306a36Sopenharmony_ci { USB_DEVICE(0x148f, 0x9021) }, 241262306a36Sopenharmony_ci { USB_DEVICE(0x0eb0, 0x9021) }, 241362306a36Sopenharmony_ci /* AMIT */ 241462306a36Sopenharmony_ci { USB_DEVICE(0x18c5, 0x0002) }, 241562306a36Sopenharmony_ci /* Askey */ 241662306a36Sopenharmony_ci { USB_DEVICE(0x1690, 0x0722) }, 241762306a36Sopenharmony_ci /* ASUS */ 241862306a36Sopenharmony_ci { USB_DEVICE(0x0b05, 0x1723) }, 241962306a36Sopenharmony_ci { USB_DEVICE(0x0b05, 0x1724) }, 242062306a36Sopenharmony_ci /* Belkin */ 242162306a36Sopenharmony_ci { USB_DEVICE(0x050d, 0x7050) }, /* FCC ID: K7SF5D7050B ver. 3.x */ 242262306a36Sopenharmony_ci { USB_DEVICE(0x050d, 0x705a) }, 242362306a36Sopenharmony_ci { USB_DEVICE(0x050d, 0x905b) }, 242462306a36Sopenharmony_ci { USB_DEVICE(0x050d, 0x905c) }, 242562306a36Sopenharmony_ci /* Billionton */ 242662306a36Sopenharmony_ci { USB_DEVICE(0x1631, 0xc019) }, 242762306a36Sopenharmony_ci { USB_DEVICE(0x08dd, 0x0120) }, 242862306a36Sopenharmony_ci /* Buffalo */ 242962306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x00d8) }, 243062306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x00d9) }, 243162306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x00e6) }, 243262306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x00f4) }, 243362306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x0116) }, 243462306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x0119) }, 243562306a36Sopenharmony_ci { USB_DEVICE(0x0411, 0x0137) }, 243662306a36Sopenharmony_ci /* CEIVA */ 243762306a36Sopenharmony_ci { USB_DEVICE(0x178d, 0x02be) }, 243862306a36Sopenharmony_ci /* CNet */ 243962306a36Sopenharmony_ci { USB_DEVICE(0x1371, 0x9022) }, 244062306a36Sopenharmony_ci { USB_DEVICE(0x1371, 0x9032) }, 244162306a36Sopenharmony_ci /* Conceptronic */ 244262306a36Sopenharmony_ci { USB_DEVICE(0x14b2, 0x3c22) }, 244362306a36Sopenharmony_ci /* Corega */ 244462306a36Sopenharmony_ci { USB_DEVICE(0x07aa, 0x002e) }, 244562306a36Sopenharmony_ci /* D-Link */ 244662306a36Sopenharmony_ci { USB_DEVICE(0x07d1, 0x3c03) }, 244762306a36Sopenharmony_ci { USB_DEVICE(0x07d1, 0x3c04) }, 244862306a36Sopenharmony_ci { USB_DEVICE(0x07d1, 0x3c06) }, 244962306a36Sopenharmony_ci { USB_DEVICE(0x07d1, 0x3c07) }, 245062306a36Sopenharmony_ci /* Edimax */ 245162306a36Sopenharmony_ci { USB_DEVICE(0x7392, 0x7318) }, 245262306a36Sopenharmony_ci { USB_DEVICE(0x7392, 0x7618) }, 245362306a36Sopenharmony_ci /* EnGenius */ 245462306a36Sopenharmony_ci { USB_DEVICE(0x1740, 0x3701) }, 245562306a36Sopenharmony_ci /* Gemtek */ 245662306a36Sopenharmony_ci { USB_DEVICE(0x15a9, 0x0004) }, 245762306a36Sopenharmony_ci /* Gigabyte */ 245862306a36Sopenharmony_ci { USB_DEVICE(0x1044, 0x8008) }, 245962306a36Sopenharmony_ci { USB_DEVICE(0x1044, 0x800a) }, 246062306a36Sopenharmony_ci /* Huawei-3Com */ 246162306a36Sopenharmony_ci { USB_DEVICE(0x1472, 0x0009) }, 246262306a36Sopenharmony_ci /* Hercules */ 246362306a36Sopenharmony_ci { USB_DEVICE(0x06f8, 0xe002) }, 246462306a36Sopenharmony_ci { USB_DEVICE(0x06f8, 0xe010) }, 246562306a36Sopenharmony_ci { USB_DEVICE(0x06f8, 0xe020) }, 246662306a36Sopenharmony_ci /* Linksys */ 246762306a36Sopenharmony_ci { USB_DEVICE(0x13b1, 0x0020) }, 246862306a36Sopenharmony_ci { USB_DEVICE(0x13b1, 0x0023) }, 246962306a36Sopenharmony_ci { USB_DEVICE(0x13b1, 0x0028) }, 247062306a36Sopenharmony_ci /* MSI */ 247162306a36Sopenharmony_ci { USB_DEVICE(0x0db0, 0x4600) }, 247262306a36Sopenharmony_ci { USB_DEVICE(0x0db0, 0x6877) }, 247362306a36Sopenharmony_ci { USB_DEVICE(0x0db0, 0x6874) }, 247462306a36Sopenharmony_ci { USB_DEVICE(0x0db0, 0xa861) }, 247562306a36Sopenharmony_ci { USB_DEVICE(0x0db0, 0xa874) }, 247662306a36Sopenharmony_ci /* Ovislink */ 247762306a36Sopenharmony_ci { USB_DEVICE(0x1b75, 0x7318) }, 247862306a36Sopenharmony_ci /* Ralink */ 247962306a36Sopenharmony_ci { USB_DEVICE(0x04bb, 0x093d) }, 248062306a36Sopenharmony_ci { USB_DEVICE(0x148f, 0x2573) }, 248162306a36Sopenharmony_ci { USB_DEVICE(0x148f, 0x2671) }, 248262306a36Sopenharmony_ci { USB_DEVICE(0x0812, 0x3101) }, 248362306a36Sopenharmony_ci /* Qcom */ 248462306a36Sopenharmony_ci { USB_DEVICE(0x18e8, 0x6196) }, 248562306a36Sopenharmony_ci { USB_DEVICE(0x18e8, 0x6229) }, 248662306a36Sopenharmony_ci { USB_DEVICE(0x18e8, 0x6238) }, 248762306a36Sopenharmony_ci /* Samsung */ 248862306a36Sopenharmony_ci { USB_DEVICE(0x04e8, 0x4471) }, 248962306a36Sopenharmony_ci /* Senao */ 249062306a36Sopenharmony_ci { USB_DEVICE(0x1740, 0x7100) }, 249162306a36Sopenharmony_ci /* Sitecom */ 249262306a36Sopenharmony_ci { USB_DEVICE(0x0df6, 0x0024) }, 249362306a36Sopenharmony_ci { USB_DEVICE(0x0df6, 0x0027) }, 249462306a36Sopenharmony_ci { USB_DEVICE(0x0df6, 0x002f) }, 249562306a36Sopenharmony_ci { USB_DEVICE(0x0df6, 0x90ac) }, 249662306a36Sopenharmony_ci { USB_DEVICE(0x0df6, 0x9712) }, 249762306a36Sopenharmony_ci /* Surecom */ 249862306a36Sopenharmony_ci { USB_DEVICE(0x0769, 0x31f3) }, 249962306a36Sopenharmony_ci /* Tilgin */ 250062306a36Sopenharmony_ci { USB_DEVICE(0x6933, 0x5001) }, 250162306a36Sopenharmony_ci /* Philips */ 250262306a36Sopenharmony_ci { USB_DEVICE(0x0471, 0x200a) }, 250362306a36Sopenharmony_ci /* Planex */ 250462306a36Sopenharmony_ci { USB_DEVICE(0x2019, 0xab01) }, 250562306a36Sopenharmony_ci { USB_DEVICE(0x2019, 0xab50) }, 250662306a36Sopenharmony_ci /* WideTell */ 250762306a36Sopenharmony_ci { USB_DEVICE(0x7167, 0x3840) }, 250862306a36Sopenharmony_ci /* Zcom */ 250962306a36Sopenharmony_ci { USB_DEVICE(0x0cde, 0x001c) }, 251062306a36Sopenharmony_ci /* ZyXEL */ 251162306a36Sopenharmony_ci { USB_DEVICE(0x0586, 0x3415) }, 251262306a36Sopenharmony_ci { 0, } 251362306a36Sopenharmony_ci}; 251462306a36Sopenharmony_ci 251562306a36Sopenharmony_ciMODULE_AUTHOR(DRV_PROJECT); 251662306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 251762306a36Sopenharmony_ciMODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver."); 251862306a36Sopenharmony_ciMODULE_DEVICE_TABLE(usb, rt73usb_device_table); 251962306a36Sopenharmony_ciMODULE_FIRMWARE(FIRMWARE_RT2571); 252062306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 252162306a36Sopenharmony_ci 252262306a36Sopenharmony_cistatic int rt73usb_probe(struct usb_interface *usb_intf, 252362306a36Sopenharmony_ci const struct usb_device_id *id) 252462306a36Sopenharmony_ci{ 252562306a36Sopenharmony_ci return rt2x00usb_probe(usb_intf, &rt73usb_ops); 252662306a36Sopenharmony_ci} 252762306a36Sopenharmony_ci 252862306a36Sopenharmony_cistatic struct usb_driver rt73usb_driver = { 252962306a36Sopenharmony_ci .name = KBUILD_MODNAME, 253062306a36Sopenharmony_ci .id_table = rt73usb_device_table, 253162306a36Sopenharmony_ci .probe = rt73usb_probe, 253262306a36Sopenharmony_ci .disconnect = rt2x00usb_disconnect, 253362306a36Sopenharmony_ci .suspend = rt2x00usb_suspend, 253462306a36Sopenharmony_ci .resume = rt2x00usb_resume, 253562306a36Sopenharmony_ci .reset_resume = rt2x00usb_resume, 253662306a36Sopenharmony_ci .disable_hub_initiated_lpm = 1, 253762306a36Sopenharmony_ci}; 253862306a36Sopenharmony_ci 253962306a36Sopenharmony_cimodule_usb_driver(rt73usb_driver); 2540