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: rt2500pci 1062306a36Sopenharmony_ci Abstract: rt2500pci device specific routines. 1162306a36Sopenharmony_ci Supported chipsets: RT2560. 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <linux/delay.h> 1562306a36Sopenharmony_ci#include <linux/etherdevice.h> 1662306a36Sopenharmony_ci#include <linux/kernel.h> 1762306a36Sopenharmony_ci#include <linux/module.h> 1862306a36Sopenharmony_ci#include <linux/pci.h> 1962306a36Sopenharmony_ci#include <linux/eeprom_93cx6.h> 2062306a36Sopenharmony_ci#include <linux/slab.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#include "rt2x00.h" 2362306a36Sopenharmony_ci#include "rt2x00mmio.h" 2462306a36Sopenharmony_ci#include "rt2x00pci.h" 2562306a36Sopenharmony_ci#include "rt2500pci.h" 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* 2862306a36Sopenharmony_ci * Register access. 2962306a36Sopenharmony_ci * All access to the CSR registers will go through the methods 3062306a36Sopenharmony_ci * rt2x00mmio_register_read and rt2x00mmio_register_write. 3162306a36Sopenharmony_ci * BBP and RF register require indirect register access, 3262306a36Sopenharmony_ci * and use the CSR registers BBPCSR and RFCSR to achieve this. 3362306a36Sopenharmony_ci * These indirect registers work with busy bits, 3462306a36Sopenharmony_ci * and we will try maximal REGISTER_BUSY_COUNT times to access 3562306a36Sopenharmony_ci * the register while taking a REGISTER_BUSY_DELAY us delay 3662306a36Sopenharmony_ci * between each attampt. When the busy bit is still set at that time, 3762306a36Sopenharmony_ci * the access attempt is considered to have failed, 3862306a36Sopenharmony_ci * and we will print an error. 3962306a36Sopenharmony_ci */ 4062306a36Sopenharmony_ci#define WAIT_FOR_BBP(__dev, __reg) \ 4162306a36Sopenharmony_ci rt2x00mmio_regbusy_read((__dev), BBPCSR, BBPCSR_BUSY, (__reg)) 4262306a36Sopenharmony_ci#define WAIT_FOR_RF(__dev, __reg) \ 4362306a36Sopenharmony_ci rt2x00mmio_regbusy_read((__dev), RFCSR, RFCSR_BUSY, (__reg)) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistatic void rt2500pci_bbp_write(struct rt2x00_dev *rt2x00dev, 4662306a36Sopenharmony_ci const unsigned int word, const u8 value) 4762306a36Sopenharmony_ci{ 4862306a36Sopenharmony_ci u32 reg; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci /* 5362306a36Sopenharmony_ci * Wait until the BBP becomes available, afterwards we 5462306a36Sopenharmony_ci * can safely write the new data into the register. 5562306a36Sopenharmony_ci */ 5662306a36Sopenharmony_ci if (WAIT_FOR_BBP(rt2x00dev, ®)) { 5762306a36Sopenharmony_ci reg = 0; 5862306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_VALUE, value); 5962306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_REGNUM, word); 6062306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_BUSY, 1); 6162306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_WRITE_CONTROL, 1); 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BBPCSR, reg); 6462306a36Sopenharmony_ci } 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic u8 rt2500pci_bbp_read(struct rt2x00_dev *rt2x00dev, 7062306a36Sopenharmony_ci const unsigned int word) 7162306a36Sopenharmony_ci{ 7262306a36Sopenharmony_ci u32 reg; 7362306a36Sopenharmony_ci u8 value; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci /* 7862306a36Sopenharmony_ci * Wait until the BBP becomes available, afterwards we 7962306a36Sopenharmony_ci * can safely write the read request into the register. 8062306a36Sopenharmony_ci * After the data has been written, we wait until hardware 8162306a36Sopenharmony_ci * returns the correct value, if at any time the register 8262306a36Sopenharmony_ci * doesn't become available in time, reg will be 0xffffffff 8362306a36Sopenharmony_ci * which means we return 0xff to the caller. 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci if (WAIT_FOR_BBP(rt2x00dev, ®)) { 8662306a36Sopenharmony_ci reg = 0; 8762306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_REGNUM, word); 8862306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_BUSY, 1); 8962306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR_WRITE_CONTROL, 0); 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BBPCSR, reg); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci WAIT_FOR_BBP(rt2x00dev, ®); 9462306a36Sopenharmony_ci } 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci value = rt2x00_get_field32(reg, BBPCSR_VALUE); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci return value; 10162306a36Sopenharmony_ci} 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistatic void rt2500pci_rf_write(struct rt2x00_dev *rt2x00dev, 10462306a36Sopenharmony_ci const unsigned int word, const u32 value) 10562306a36Sopenharmony_ci{ 10662306a36Sopenharmony_ci u32 reg; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci mutex_lock(&rt2x00dev->csr_mutex); 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci /* 11162306a36Sopenharmony_ci * Wait until the RF becomes available, afterwards we 11262306a36Sopenharmony_ci * can safely write the new data into the register. 11362306a36Sopenharmony_ci */ 11462306a36Sopenharmony_ci if (WAIT_FOR_RF(rt2x00dev, ®)) { 11562306a36Sopenharmony_ci reg = 0; 11662306a36Sopenharmony_ci rt2x00_set_field32(®, RFCSR_VALUE, value); 11762306a36Sopenharmony_ci rt2x00_set_field32(®, RFCSR_NUMBER_OF_BITS, 20); 11862306a36Sopenharmony_ci rt2x00_set_field32(®, RFCSR_IF_SELECT, 0); 11962306a36Sopenharmony_ci rt2x00_set_field32(®, RFCSR_BUSY, 1); 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RFCSR, reg); 12262306a36Sopenharmony_ci rt2x00_rf_write(rt2x00dev, word, value); 12362306a36Sopenharmony_ci } 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci mutex_unlock(&rt2x00dev->csr_mutex); 12662306a36Sopenharmony_ci} 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_cistatic void rt2500pci_eepromregister_read(struct eeprom_93cx6 *eeprom) 12962306a36Sopenharmony_ci{ 13062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = eeprom->data; 13162306a36Sopenharmony_ci u32 reg; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR21); 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci eeprom->reg_data_in = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_IN); 13662306a36Sopenharmony_ci eeprom->reg_data_out = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_OUT); 13762306a36Sopenharmony_ci eeprom->reg_data_clock = 13862306a36Sopenharmony_ci !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_CLOCK); 13962306a36Sopenharmony_ci eeprom->reg_chip_select = 14062306a36Sopenharmony_ci !!rt2x00_get_field32(reg, CSR21_EEPROM_CHIP_SELECT); 14162306a36Sopenharmony_ci} 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_cistatic void rt2500pci_eepromregister_write(struct eeprom_93cx6 *eeprom) 14462306a36Sopenharmony_ci{ 14562306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = eeprom->data; 14662306a36Sopenharmony_ci u32 reg = 0; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR21_EEPROM_DATA_IN, !!eeprom->reg_data_in); 14962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR21_EEPROM_DATA_OUT, !!eeprom->reg_data_out); 15062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR21_EEPROM_DATA_CLOCK, 15162306a36Sopenharmony_ci !!eeprom->reg_data_clock); 15262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR21_EEPROM_CHIP_SELECT, 15362306a36Sopenharmony_ci !!eeprom->reg_chip_select); 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR21, reg); 15662306a36Sopenharmony_ci} 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS 15962306a36Sopenharmony_cistatic const struct rt2x00debug rt2500pci_rt2x00debug = { 16062306a36Sopenharmony_ci .owner = THIS_MODULE, 16162306a36Sopenharmony_ci .csr = { 16262306a36Sopenharmony_ci .read = rt2x00mmio_register_read, 16362306a36Sopenharmony_ci .write = rt2x00mmio_register_write, 16462306a36Sopenharmony_ci .flags = RT2X00DEBUGFS_OFFSET, 16562306a36Sopenharmony_ci .word_base = CSR_REG_BASE, 16662306a36Sopenharmony_ci .word_size = sizeof(u32), 16762306a36Sopenharmony_ci .word_count = CSR_REG_SIZE / sizeof(u32), 16862306a36Sopenharmony_ci }, 16962306a36Sopenharmony_ci .eeprom = { 17062306a36Sopenharmony_ci .read = rt2x00_eeprom_read, 17162306a36Sopenharmony_ci .write = rt2x00_eeprom_write, 17262306a36Sopenharmony_ci .word_base = EEPROM_BASE, 17362306a36Sopenharmony_ci .word_size = sizeof(u16), 17462306a36Sopenharmony_ci .word_count = EEPROM_SIZE / sizeof(u16), 17562306a36Sopenharmony_ci }, 17662306a36Sopenharmony_ci .bbp = { 17762306a36Sopenharmony_ci .read = rt2500pci_bbp_read, 17862306a36Sopenharmony_ci .write = rt2500pci_bbp_write, 17962306a36Sopenharmony_ci .word_base = BBP_BASE, 18062306a36Sopenharmony_ci .word_size = sizeof(u8), 18162306a36Sopenharmony_ci .word_count = BBP_SIZE / sizeof(u8), 18262306a36Sopenharmony_ci }, 18362306a36Sopenharmony_ci .rf = { 18462306a36Sopenharmony_ci .read = rt2x00_rf_read, 18562306a36Sopenharmony_ci .write = rt2500pci_rf_write, 18662306a36Sopenharmony_ci .word_base = RF_BASE, 18762306a36Sopenharmony_ci .word_size = sizeof(u32), 18862306a36Sopenharmony_ci .word_count = RF_SIZE / sizeof(u32), 18962306a36Sopenharmony_ci }, 19062306a36Sopenharmony_ci}; 19162306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_cistatic int rt2500pci_rfkill_poll(struct rt2x00_dev *rt2x00dev) 19462306a36Sopenharmony_ci{ 19562306a36Sopenharmony_ci u32 reg; 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, GPIOCSR); 19862306a36Sopenharmony_ci return rt2x00_get_field32(reg, GPIOCSR_VAL0); 19962306a36Sopenharmony_ci} 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_LEDS 20262306a36Sopenharmony_cistatic void rt2500pci_brightness_set(struct led_classdev *led_cdev, 20362306a36Sopenharmony_ci enum led_brightness brightness) 20462306a36Sopenharmony_ci{ 20562306a36Sopenharmony_ci struct rt2x00_led *led = 20662306a36Sopenharmony_ci container_of(led_cdev, struct rt2x00_led, led_dev); 20762306a36Sopenharmony_ci unsigned int enabled = brightness != LED_OFF; 20862306a36Sopenharmony_ci u32 reg; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(led->rt2x00dev, LEDCSR); 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC) 21362306a36Sopenharmony_ci rt2x00_set_field32(®, LEDCSR_LINK, enabled); 21462306a36Sopenharmony_ci else if (led->type == LED_TYPE_ACTIVITY) 21562306a36Sopenharmony_ci rt2x00_set_field32(®, LEDCSR_ACTIVITY, enabled); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci rt2x00mmio_register_write(led->rt2x00dev, LEDCSR, reg); 21862306a36Sopenharmony_ci} 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_cistatic int rt2500pci_blink_set(struct led_classdev *led_cdev, 22162306a36Sopenharmony_ci unsigned long *delay_on, 22262306a36Sopenharmony_ci unsigned long *delay_off) 22362306a36Sopenharmony_ci{ 22462306a36Sopenharmony_ci struct rt2x00_led *led = 22562306a36Sopenharmony_ci container_of(led_cdev, struct rt2x00_led, led_dev); 22662306a36Sopenharmony_ci u32 reg; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(led->rt2x00dev, LEDCSR); 22962306a36Sopenharmony_ci rt2x00_set_field32(®, LEDCSR_ON_PERIOD, *delay_on); 23062306a36Sopenharmony_ci rt2x00_set_field32(®, LEDCSR_OFF_PERIOD, *delay_off); 23162306a36Sopenharmony_ci rt2x00mmio_register_write(led->rt2x00dev, LEDCSR, reg); 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci return 0; 23462306a36Sopenharmony_ci} 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_cistatic void rt2500pci_init_led(struct rt2x00_dev *rt2x00dev, 23762306a36Sopenharmony_ci struct rt2x00_led *led, 23862306a36Sopenharmony_ci enum led_type type) 23962306a36Sopenharmony_ci{ 24062306a36Sopenharmony_ci led->rt2x00dev = rt2x00dev; 24162306a36Sopenharmony_ci led->type = type; 24262306a36Sopenharmony_ci led->led_dev.brightness_set = rt2500pci_brightness_set; 24362306a36Sopenharmony_ci led->led_dev.blink_set = rt2500pci_blink_set; 24462306a36Sopenharmony_ci led->flags = LED_INITIALIZED; 24562306a36Sopenharmony_ci} 24662306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_LEDS */ 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci/* 24962306a36Sopenharmony_ci * Configuration handlers. 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_cistatic void rt2500pci_config_filter(struct rt2x00_dev *rt2x00dev, 25262306a36Sopenharmony_ci const unsigned int filter_flags) 25362306a36Sopenharmony_ci{ 25462306a36Sopenharmony_ci u32 reg; 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci /* 25762306a36Sopenharmony_ci * Start configuration steps. 25862306a36Sopenharmony_ci * Note that the version error will always be dropped 25962306a36Sopenharmony_ci * and broadcast frames will always be accepted since 26062306a36Sopenharmony_ci * there is no filter for it at this time. 26162306a36Sopenharmony_ci */ 26262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 26362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_CRC, 26462306a36Sopenharmony_ci !(filter_flags & FIF_FCSFAIL)); 26562306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_PHYSICAL, 26662306a36Sopenharmony_ci !(filter_flags & FIF_PLCPFAIL)); 26762306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_CONTROL, 26862306a36Sopenharmony_ci !(filter_flags & FIF_CONTROL)); 26962306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_NOT_TO_ME, 27062306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags)); 27162306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_TODS, 27262306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags) && 27362306a36Sopenharmony_ci !rt2x00dev->intf_ap_count); 27462306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_VERSION_ERROR, 1); 27562306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_MCAST, 27662306a36Sopenharmony_ci !(filter_flags & FIF_ALLMULTI)); 27762306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_BCAST, 0); 27862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 27962306a36Sopenharmony_ci} 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_cistatic void rt2500pci_config_intf(struct rt2x00_dev *rt2x00dev, 28262306a36Sopenharmony_ci struct rt2x00_intf *intf, 28362306a36Sopenharmony_ci struct rt2x00intf_conf *conf, 28462306a36Sopenharmony_ci const unsigned int flags) 28562306a36Sopenharmony_ci{ 28662306a36Sopenharmony_ci struct data_queue *queue = rt2x00dev->bcn; 28762306a36Sopenharmony_ci unsigned int bcn_preload; 28862306a36Sopenharmony_ci u32 reg; 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_TYPE) { 29162306a36Sopenharmony_ci /* 29262306a36Sopenharmony_ci * Enable beacon config 29362306a36Sopenharmony_ci */ 29462306a36Sopenharmony_ci bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20); 29562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, BCNCSR1); 29662306a36Sopenharmony_ci rt2x00_set_field32(®, BCNCSR1_PRELOAD, bcn_preload); 29762306a36Sopenharmony_ci rt2x00_set_field32(®, BCNCSR1_BEACON_CWMIN, queue->cw_min); 29862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BCNCSR1, reg); 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci /* 30162306a36Sopenharmony_ci * Enable synchronisation. 30262306a36Sopenharmony_ci */ 30362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 30462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_SYNC, conf->sync); 30562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 30662306a36Sopenharmony_ci } 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_MAC) 30962306a36Sopenharmony_ci rt2x00mmio_register_multiwrite(rt2x00dev, CSR3, 31062306a36Sopenharmony_ci conf->mac, sizeof(conf->mac)); 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_BSSID) 31362306a36Sopenharmony_ci rt2x00mmio_register_multiwrite(rt2x00dev, CSR5, 31462306a36Sopenharmony_ci conf->bssid, sizeof(conf->bssid)); 31562306a36Sopenharmony_ci} 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_cistatic void rt2500pci_config_erp(struct rt2x00_dev *rt2x00dev, 31862306a36Sopenharmony_ci struct rt2x00lib_erp *erp, 31962306a36Sopenharmony_ci u32 changed) 32062306a36Sopenharmony_ci{ 32162306a36Sopenharmony_ci int preamble_mask; 32262306a36Sopenharmony_ci u32 reg; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci /* 32562306a36Sopenharmony_ci * When short preamble is enabled, we should set bit 0x08 32662306a36Sopenharmony_ci */ 32762306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_PREAMBLE) { 32862306a36Sopenharmony_ci preamble_mask = erp->short_preamble << 3; 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR1); 33162306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_ACK_TIMEOUT, 0x162); 33262306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_ACK_CONSUME_TIME, 0xa2); 33362306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_TSF_OFFSET, IEEE80211_HEADER); 33462306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_AUTORESPONDER, 1); 33562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR1, reg); 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR2); 33862306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_SIGNAL, 0x00); 33962306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_SERVICE, 0x04); 34062306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 34162306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 10)); 34262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR2, reg); 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR3); 34562306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR3_SIGNAL, 0x01 | preamble_mask); 34662306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR3_SERVICE, 0x04); 34762306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 34862306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 20)); 34962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR3, reg); 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR4); 35262306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR4_SIGNAL, 0x02 | preamble_mask); 35362306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR4_SERVICE, 0x04); 35462306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 35562306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 55)); 35662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR4, reg); 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR5); 35962306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR5_SIGNAL, 0x03 | preamble_mask); 36062306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR5_SERVICE, 0x84); 36162306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 36262306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 110)); 36362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR5, reg); 36462306a36Sopenharmony_ci } 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ci if (changed & BSS_CHANGED_BASIC_RATES) 36762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR1, erp->basic_rates); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_SLOT) { 37062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 37162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_SLOT_TIME, erp->slot_time); 37262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR18); 37562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR18_SIFS, erp->sifs); 37662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR18_PIFS, erp->pifs); 37762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR18, reg); 37862306a36Sopenharmony_ci 37962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR19); 38062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR19_DIFS, erp->difs); 38162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR19_EIFS, erp->eifs); 38262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR19, reg); 38362306a36Sopenharmony_ci } 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci if (changed & BSS_CHANGED_BEACON_INT) { 38662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR12); 38762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR12_BEACON_INTERVAL, 38862306a36Sopenharmony_ci erp->beacon_int * 16); 38962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR12_CFP_MAX_DURATION, 39062306a36Sopenharmony_ci erp->beacon_int * 16); 39162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR12, reg); 39262306a36Sopenharmony_ci } 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci} 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_cistatic void rt2500pci_config_ant(struct rt2x00_dev *rt2x00dev, 39762306a36Sopenharmony_ci struct antenna_setup *ant) 39862306a36Sopenharmony_ci{ 39962306a36Sopenharmony_ci u32 reg; 40062306a36Sopenharmony_ci u8 r14; 40162306a36Sopenharmony_ci u8 r2; 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci /* 40462306a36Sopenharmony_ci * We should never come here because rt2x00lib is supposed 40562306a36Sopenharmony_ci * to catch this and send us the correct antenna explicitely. 40662306a36Sopenharmony_ci */ 40762306a36Sopenharmony_ci BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY || 40862306a36Sopenharmony_ci ant->tx == ANTENNA_SW_DIVERSITY); 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, BBPCSR1); 41162306a36Sopenharmony_ci r14 = rt2500pci_bbp_read(rt2x00dev, 14); 41262306a36Sopenharmony_ci r2 = rt2500pci_bbp_read(rt2x00dev, 2); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci /* 41562306a36Sopenharmony_ci * Configure the TX antenna. 41662306a36Sopenharmony_ci */ 41762306a36Sopenharmony_ci switch (ant->tx) { 41862306a36Sopenharmony_ci case ANTENNA_A: 41962306a36Sopenharmony_ci rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0); 42062306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_CCK, 0); 42162306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_OFDM, 0); 42262306a36Sopenharmony_ci break; 42362306a36Sopenharmony_ci case ANTENNA_B: 42462306a36Sopenharmony_ci default: 42562306a36Sopenharmony_ci rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2); 42662306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_CCK, 2); 42762306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_OFDM, 2); 42862306a36Sopenharmony_ci break; 42962306a36Sopenharmony_ci } 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci /* 43262306a36Sopenharmony_ci * Configure the RX antenna. 43362306a36Sopenharmony_ci */ 43462306a36Sopenharmony_ci switch (ant->rx) { 43562306a36Sopenharmony_ci case ANTENNA_A: 43662306a36Sopenharmony_ci rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0); 43762306a36Sopenharmony_ci break; 43862306a36Sopenharmony_ci case ANTENNA_B: 43962306a36Sopenharmony_ci default: 44062306a36Sopenharmony_ci rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2); 44162306a36Sopenharmony_ci break; 44262306a36Sopenharmony_ci } 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci /* 44562306a36Sopenharmony_ci * RT2525E and RT5222 need to flip TX I/Q 44662306a36Sopenharmony_ci */ 44762306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2525E) || rt2x00_rf(rt2x00dev, RF5222)) { 44862306a36Sopenharmony_ci rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1); 44962306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_CCK_FLIP, 1); 45062306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_OFDM_FLIP, 1); 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_ci /* 45362306a36Sopenharmony_ci * RT2525E does not need RX I/Q Flip. 45462306a36Sopenharmony_ci */ 45562306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2525E)) 45662306a36Sopenharmony_ci rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0); 45762306a36Sopenharmony_ci } else { 45862306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_CCK_FLIP, 0); 45962306a36Sopenharmony_ci rt2x00_set_field32(®, BBPCSR1_OFDM_FLIP, 0); 46062306a36Sopenharmony_ci } 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BBPCSR1, reg); 46362306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 14, r14); 46462306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 2, r2); 46562306a36Sopenharmony_ci} 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_cistatic void rt2500pci_config_channel(struct rt2x00_dev *rt2x00dev, 46862306a36Sopenharmony_ci struct rf_channel *rf, const int txpower) 46962306a36Sopenharmony_ci{ 47062306a36Sopenharmony_ci u8 r70; 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_ci /* 47362306a36Sopenharmony_ci * Set TXpower. 47462306a36Sopenharmony_ci */ 47562306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_ci /* 47862306a36Sopenharmony_ci * Switch on tuning bits. 47962306a36Sopenharmony_ci * For RT2523 devices we do not need to update the R1 register. 48062306a36Sopenharmony_ci */ 48162306a36Sopenharmony_ci if (!rt2x00_rf(rt2x00dev, RF2523)) 48262306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf1, RF1_TUNER, 1); 48362306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TUNER, 1); 48462306a36Sopenharmony_ci 48562306a36Sopenharmony_ci /* 48662306a36Sopenharmony_ci * For RT2525 we should first set the channel to half band higher. 48762306a36Sopenharmony_ci */ 48862306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2525)) { 48962306a36Sopenharmony_ci static const u32 vals[] = { 49062306a36Sopenharmony_ci 0x00080cbe, 0x00080d02, 0x00080d06, 0x00080d0a, 49162306a36Sopenharmony_ci 0x00080d0e, 0x00080d12, 0x00080d16, 0x00080d1a, 49262306a36Sopenharmony_ci 0x00080d1e, 0x00080d22, 0x00080d26, 0x00080d2a, 49362306a36Sopenharmony_ci 0x00080d2e, 0x00080d3a 49462306a36Sopenharmony_ci }; 49562306a36Sopenharmony_ci 49662306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); 49762306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 2, vals[rf->channel - 1]); 49862306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); 49962306a36Sopenharmony_ci if (rf->rf4) 50062306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 4, rf->rf4); 50162306a36Sopenharmony_ci } 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); 50462306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 2, rf->rf2); 50562306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); 50662306a36Sopenharmony_ci if (rf->rf4) 50762306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 4, rf->rf4); 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci /* 51062306a36Sopenharmony_ci * Channel 14 requires the Japan filter bit to be set. 51162306a36Sopenharmony_ci */ 51262306a36Sopenharmony_ci r70 = 0x46; 51362306a36Sopenharmony_ci rt2x00_set_field8(&r70, BBP_R70_JAPAN_FILTER, rf->channel == 14); 51462306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 70, r70); 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_ci msleep(1); 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci /* 51962306a36Sopenharmony_ci * Switch off tuning bits. 52062306a36Sopenharmony_ci * For RT2523 devices we do not need to update the R1 register. 52162306a36Sopenharmony_ci */ 52262306a36Sopenharmony_ci if (!rt2x00_rf(rt2x00dev, RF2523)) { 52362306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf1, RF1_TUNER, 0); 52462306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 1, rf->rf1); 52562306a36Sopenharmony_ci } 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TUNER, 0); 52862306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 3, rf->rf3); 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ci /* 53162306a36Sopenharmony_ci * Clear false CRC during channel switch. 53262306a36Sopenharmony_ci */ 53362306a36Sopenharmony_ci rf->rf1 = rt2x00mmio_register_read(rt2x00dev, CNT0); 53462306a36Sopenharmony_ci} 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_cistatic void rt2500pci_config_txpower(struct rt2x00_dev *rt2x00dev, 53762306a36Sopenharmony_ci const int txpower) 53862306a36Sopenharmony_ci{ 53962306a36Sopenharmony_ci u32 rf3; 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ci rf3 = rt2x00_rf_read(rt2x00dev, 3); 54262306a36Sopenharmony_ci rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower)); 54362306a36Sopenharmony_ci rt2500pci_rf_write(rt2x00dev, 3, rf3); 54462306a36Sopenharmony_ci} 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_cistatic void rt2500pci_config_retry_limit(struct rt2x00_dev *rt2x00dev, 54762306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 54862306a36Sopenharmony_ci{ 54962306a36Sopenharmony_ci u32 reg; 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 55262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_LONG_RETRY, 55362306a36Sopenharmony_ci libconf->conf->long_frame_max_tx_count); 55462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_SHORT_RETRY, 55562306a36Sopenharmony_ci libconf->conf->short_frame_max_tx_count); 55662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 55762306a36Sopenharmony_ci} 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_cistatic void rt2500pci_config_ps(struct rt2x00_dev *rt2x00dev, 56062306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 56162306a36Sopenharmony_ci{ 56262306a36Sopenharmony_ci enum dev_state state = 56362306a36Sopenharmony_ci (libconf->conf->flags & IEEE80211_CONF_PS) ? 56462306a36Sopenharmony_ci STATE_SLEEP : STATE_AWAKE; 56562306a36Sopenharmony_ci u32 reg; 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci if (state == STATE_SLEEP) { 56862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR20); 56962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_DELAY_AFTER_TBCN, 57062306a36Sopenharmony_ci (rt2x00dev->beacon_int - 20) * 16); 57162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_TBCN_BEFORE_WAKEUP, 57262306a36Sopenharmony_ci libconf->conf->listen_interval - 1); 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ci /* We must first disable autowake before it can be enabled */ 57562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 0); 57662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 1); 57962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 58062306a36Sopenharmony_ci } else { 58162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR20); 58262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 0); 58362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 58462306a36Sopenharmony_ci } 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); 58762306a36Sopenharmony_ci} 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_cistatic void rt2500pci_config(struct rt2x00_dev *rt2x00dev, 59062306a36Sopenharmony_ci struct rt2x00lib_conf *libconf, 59162306a36Sopenharmony_ci const unsigned int flags) 59262306a36Sopenharmony_ci{ 59362306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_CHANNEL) 59462306a36Sopenharmony_ci rt2500pci_config_channel(rt2x00dev, &libconf->rf, 59562306a36Sopenharmony_ci libconf->conf->power_level); 59662306a36Sopenharmony_ci if ((flags & IEEE80211_CONF_CHANGE_POWER) && 59762306a36Sopenharmony_ci !(flags & IEEE80211_CONF_CHANGE_CHANNEL)) 59862306a36Sopenharmony_ci rt2500pci_config_txpower(rt2x00dev, 59962306a36Sopenharmony_ci libconf->conf->power_level); 60062306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) 60162306a36Sopenharmony_ci rt2500pci_config_retry_limit(rt2x00dev, libconf); 60262306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_PS) 60362306a36Sopenharmony_ci rt2500pci_config_ps(rt2x00dev, libconf); 60462306a36Sopenharmony_ci} 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci/* 60762306a36Sopenharmony_ci * Link tuning 60862306a36Sopenharmony_ci */ 60962306a36Sopenharmony_cistatic void rt2500pci_link_stats(struct rt2x00_dev *rt2x00dev, 61062306a36Sopenharmony_ci struct link_qual *qual) 61162306a36Sopenharmony_ci{ 61262306a36Sopenharmony_ci u32 reg; 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci /* 61562306a36Sopenharmony_ci * Update FCS error count from register. 61662306a36Sopenharmony_ci */ 61762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT0); 61862306a36Sopenharmony_ci qual->rx_failed = rt2x00_get_field32(reg, CNT0_FCS_ERROR); 61962306a36Sopenharmony_ci 62062306a36Sopenharmony_ci /* 62162306a36Sopenharmony_ci * Update False CCA count from register. 62262306a36Sopenharmony_ci */ 62362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT3); 62462306a36Sopenharmony_ci qual->false_cca = rt2x00_get_field32(reg, CNT3_FALSE_CCA); 62562306a36Sopenharmony_ci} 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_cistatic inline void rt2500pci_set_vgc(struct rt2x00_dev *rt2x00dev, 62862306a36Sopenharmony_ci struct link_qual *qual, u8 vgc_level) 62962306a36Sopenharmony_ci{ 63062306a36Sopenharmony_ci if (qual->vgc_level_reg != vgc_level) { 63162306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 17, vgc_level); 63262306a36Sopenharmony_ci qual->vgc_level = vgc_level; 63362306a36Sopenharmony_ci qual->vgc_level_reg = vgc_level; 63462306a36Sopenharmony_ci } 63562306a36Sopenharmony_ci} 63662306a36Sopenharmony_ci 63762306a36Sopenharmony_cistatic void rt2500pci_reset_tuner(struct rt2x00_dev *rt2x00dev, 63862306a36Sopenharmony_ci struct link_qual *qual) 63962306a36Sopenharmony_ci{ 64062306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, 0x48); 64162306a36Sopenharmony_ci} 64262306a36Sopenharmony_ci 64362306a36Sopenharmony_cistatic void rt2500pci_link_tuner(struct rt2x00_dev *rt2x00dev, 64462306a36Sopenharmony_ci struct link_qual *qual, const u32 count) 64562306a36Sopenharmony_ci{ 64662306a36Sopenharmony_ci /* 64762306a36Sopenharmony_ci * To prevent collisions with MAC ASIC on chipsets 64862306a36Sopenharmony_ci * up to version C the link tuning should halt after 20 64962306a36Sopenharmony_ci * seconds while being associated. 65062306a36Sopenharmony_ci */ 65162306a36Sopenharmony_ci if (rt2x00_rev(rt2x00dev) < RT2560_VERSION_D && 65262306a36Sopenharmony_ci rt2x00dev->intf_associated && count > 20) 65362306a36Sopenharmony_ci return; 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci /* 65662306a36Sopenharmony_ci * Chipset versions C and lower should directly continue 65762306a36Sopenharmony_ci * to the dynamic CCA tuning. Chipset version D and higher 65862306a36Sopenharmony_ci * should go straight to dynamic CCA tuning when they 65962306a36Sopenharmony_ci * are not associated. 66062306a36Sopenharmony_ci */ 66162306a36Sopenharmony_ci if (rt2x00_rev(rt2x00dev) < RT2560_VERSION_D || 66262306a36Sopenharmony_ci !rt2x00dev->intf_associated) 66362306a36Sopenharmony_ci goto dynamic_cca_tune; 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ci /* 66662306a36Sopenharmony_ci * A too low RSSI will cause too much false CCA which will 66762306a36Sopenharmony_ci * then corrupt the R17 tuning. To remidy this the tuning should 66862306a36Sopenharmony_ci * be stopped (While making sure the R17 value will not exceed limits) 66962306a36Sopenharmony_ci */ 67062306a36Sopenharmony_ci if (qual->rssi < -80 && count > 20) { 67162306a36Sopenharmony_ci if (qual->vgc_level_reg >= 0x41) 67262306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, qual->vgc_level); 67362306a36Sopenharmony_ci return; 67462306a36Sopenharmony_ci } 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ci /* 67762306a36Sopenharmony_ci * Special big-R17 for short distance 67862306a36Sopenharmony_ci */ 67962306a36Sopenharmony_ci if (qual->rssi >= -58) { 68062306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, 0x50); 68162306a36Sopenharmony_ci return; 68262306a36Sopenharmony_ci } 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci /* 68562306a36Sopenharmony_ci * Special mid-R17 for middle distance 68662306a36Sopenharmony_ci */ 68762306a36Sopenharmony_ci if (qual->rssi >= -74) { 68862306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, 0x41); 68962306a36Sopenharmony_ci return; 69062306a36Sopenharmony_ci } 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ci /* 69362306a36Sopenharmony_ci * Leave short or middle distance condition, restore r17 69462306a36Sopenharmony_ci * to the dynamic tuning range. 69562306a36Sopenharmony_ci */ 69662306a36Sopenharmony_ci if (qual->vgc_level_reg >= 0x41) { 69762306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, qual->vgc_level); 69862306a36Sopenharmony_ci return; 69962306a36Sopenharmony_ci } 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_cidynamic_cca_tune: 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci /* 70462306a36Sopenharmony_ci * R17 is inside the dynamic tuning range, 70562306a36Sopenharmony_ci * start tuning the link based on the false cca counter. 70662306a36Sopenharmony_ci */ 70762306a36Sopenharmony_ci if (qual->false_cca > 512 && qual->vgc_level_reg < 0x40) 70862306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, ++qual->vgc_level_reg); 70962306a36Sopenharmony_ci else if (qual->false_cca < 100 && qual->vgc_level_reg > 0x32) 71062306a36Sopenharmony_ci rt2500pci_set_vgc(rt2x00dev, qual, --qual->vgc_level_reg); 71162306a36Sopenharmony_ci} 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_ci/* 71462306a36Sopenharmony_ci * Queue handlers. 71562306a36Sopenharmony_ci */ 71662306a36Sopenharmony_cistatic void rt2500pci_start_queue(struct data_queue *queue) 71762306a36Sopenharmony_ci{ 71862306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 71962306a36Sopenharmony_ci u32 reg; 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ci switch (queue->qid) { 72262306a36Sopenharmony_ci case QID_RX: 72362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 72462306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DISABLE_RX, 0); 72562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 72662306a36Sopenharmony_ci break; 72762306a36Sopenharmony_ci case QID_BEACON: 72862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 72962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 1); 73062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 1); 73162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 1); 73262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 73362306a36Sopenharmony_ci break; 73462306a36Sopenharmony_ci default: 73562306a36Sopenharmony_ci break; 73662306a36Sopenharmony_ci } 73762306a36Sopenharmony_ci} 73862306a36Sopenharmony_ci 73962306a36Sopenharmony_cistatic void rt2500pci_kick_queue(struct data_queue *queue) 74062306a36Sopenharmony_ci{ 74162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 74262306a36Sopenharmony_ci u32 reg; 74362306a36Sopenharmony_ci 74462306a36Sopenharmony_ci switch (queue->qid) { 74562306a36Sopenharmony_ci case QID_AC_VO: 74662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 74762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_PRIO, 1); 74862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 74962306a36Sopenharmony_ci break; 75062306a36Sopenharmony_ci case QID_AC_VI: 75162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 75262306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_TX, 1); 75362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 75462306a36Sopenharmony_ci break; 75562306a36Sopenharmony_ci case QID_ATIM: 75662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 75762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_ATIM, 1); 75862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 75962306a36Sopenharmony_ci break; 76062306a36Sopenharmony_ci default: 76162306a36Sopenharmony_ci break; 76262306a36Sopenharmony_ci } 76362306a36Sopenharmony_ci} 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_cistatic void rt2500pci_stop_queue(struct data_queue *queue) 76662306a36Sopenharmony_ci{ 76762306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 76862306a36Sopenharmony_ci u32 reg; 76962306a36Sopenharmony_ci 77062306a36Sopenharmony_ci switch (queue->qid) { 77162306a36Sopenharmony_ci case QID_AC_VO: 77262306a36Sopenharmony_ci case QID_AC_VI: 77362306a36Sopenharmony_ci case QID_ATIM: 77462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 77562306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_ABORT, 1); 77662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 77762306a36Sopenharmony_ci break; 77862306a36Sopenharmony_ci case QID_RX: 77962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 78062306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DISABLE_RX, 1); 78162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 78262306a36Sopenharmony_ci break; 78362306a36Sopenharmony_ci case QID_BEACON: 78462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 78562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 0); 78662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 0); 78762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 78862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 78962306a36Sopenharmony_ci 79062306a36Sopenharmony_ci /* 79162306a36Sopenharmony_ci * Wait for possibly running tbtt tasklets. 79262306a36Sopenharmony_ci */ 79362306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->tbtt_tasklet); 79462306a36Sopenharmony_ci break; 79562306a36Sopenharmony_ci default: 79662306a36Sopenharmony_ci break; 79762306a36Sopenharmony_ci } 79862306a36Sopenharmony_ci} 79962306a36Sopenharmony_ci 80062306a36Sopenharmony_ci/* 80162306a36Sopenharmony_ci * Initialization functions. 80262306a36Sopenharmony_ci */ 80362306a36Sopenharmony_cistatic bool rt2500pci_get_entry_state(struct queue_entry *entry) 80462306a36Sopenharmony_ci{ 80562306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 80662306a36Sopenharmony_ci u32 word; 80762306a36Sopenharmony_ci 80862306a36Sopenharmony_ci if (entry->queue->qid == QID_RX) { 80962306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_ci return rt2x00_get_field32(word, RXD_W0_OWNER_NIC); 81262306a36Sopenharmony_ci } else { 81362306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_ci return (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) || 81662306a36Sopenharmony_ci rt2x00_get_field32(word, TXD_W0_VALID)); 81762306a36Sopenharmony_ci } 81862306a36Sopenharmony_ci} 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_cistatic void rt2500pci_clear_entry(struct queue_entry *entry) 82162306a36Sopenharmony_ci{ 82262306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 82362306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 82462306a36Sopenharmony_ci u32 word; 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_ci if (entry->queue->qid == QID_RX) { 82762306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 1); 82862306a36Sopenharmony_ci rt2x00_set_field32(&word, RXD_W1_BUFFER_ADDRESS, skbdesc->skb_dma); 82962306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 1, word); 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 83262306a36Sopenharmony_ci rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1); 83362306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 0, word); 83462306a36Sopenharmony_ci } else { 83562306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 83662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_VALID, 0); 83762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0); 83862306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 0, word); 83962306a36Sopenharmony_ci } 84062306a36Sopenharmony_ci} 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_cistatic int rt2500pci_init_queues(struct rt2x00_dev *rt2x00dev) 84362306a36Sopenharmony_ci{ 84462306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv; 84562306a36Sopenharmony_ci u32 reg; 84662306a36Sopenharmony_ci 84762306a36Sopenharmony_ci /* 84862306a36Sopenharmony_ci * Initialize registers. 84962306a36Sopenharmony_ci */ 85062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR2); 85162306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_TXD_SIZE, rt2x00dev->tx[0].desc_size); 85262306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_TXD, rt2x00dev->tx[1].limit); 85362306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_ATIM, rt2x00dev->atim->limit); 85462306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_PRIO, rt2x00dev->tx[0].limit); 85562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR2, reg); 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci entry_priv = rt2x00dev->tx[1].entries[0].priv_data; 85862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR3); 85962306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR3_TX_RING_REGISTER, 86062306a36Sopenharmony_ci entry_priv->desc_dma); 86162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR3, reg); 86262306a36Sopenharmony_ci 86362306a36Sopenharmony_ci entry_priv = rt2x00dev->tx[0].entries[0].priv_data; 86462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR5); 86562306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR5_PRIO_RING_REGISTER, 86662306a36Sopenharmony_ci entry_priv->desc_dma); 86762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR5, reg); 86862306a36Sopenharmony_ci 86962306a36Sopenharmony_ci entry_priv = rt2x00dev->atim->entries[0].priv_data; 87062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR4); 87162306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR4_ATIM_RING_REGISTER, 87262306a36Sopenharmony_ci entry_priv->desc_dma); 87362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR4, reg); 87462306a36Sopenharmony_ci 87562306a36Sopenharmony_ci entry_priv = rt2x00dev->bcn->entries[0].priv_data; 87662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR6); 87762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR6_BEACON_RING_REGISTER, 87862306a36Sopenharmony_ci entry_priv->desc_dma); 87962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR6, reg); 88062306a36Sopenharmony_ci 88162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR1); 88262306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR1_RXD_SIZE, rt2x00dev->rx->desc_size); 88362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR1_NUM_RXD, rt2x00dev->rx->limit); 88462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR1, reg); 88562306a36Sopenharmony_ci 88662306a36Sopenharmony_ci entry_priv = rt2x00dev->rx->entries[0].priv_data; 88762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR2); 88862306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR2_RX_RING_REGISTER, 88962306a36Sopenharmony_ci entry_priv->desc_dma); 89062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR2, reg); 89162306a36Sopenharmony_ci 89262306a36Sopenharmony_ci return 0; 89362306a36Sopenharmony_ci} 89462306a36Sopenharmony_ci 89562306a36Sopenharmony_cistatic int rt2500pci_init_registers(struct rt2x00_dev *rt2x00dev) 89662306a36Sopenharmony_ci{ 89762306a36Sopenharmony_ci u32 reg; 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR0, 0x00020002); 90062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR1, 0x00000002); 90162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR2, 0x00020002); 90262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR3, 0x00000002); 90362306a36Sopenharmony_ci 90462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TIMECSR); 90562306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_US_COUNT, 33); 90662306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_US_64_COUNT, 63); 90762306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_BEACON_EXPECT, 0); 90862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TIMECSR, reg); 90962306a36Sopenharmony_ci 91062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR9); 91162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR9_MAX_FRAME_UNIT, 91262306a36Sopenharmony_ci rt2x00dev->rx->data_size / 128); 91362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR9, reg); 91462306a36Sopenharmony_ci 91562306a36Sopenharmony_ci /* 91662306a36Sopenharmony_ci * Always use CWmin and CWmax set in descriptor. 91762306a36Sopenharmony_ci */ 91862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 91962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_CW_SELECT, 0); 92062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 92162306a36Sopenharmony_ci 92262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 92362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 0); 92462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_SYNC, 0); 92562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 0); 92662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TCFP, 0); 92762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TATIMW, 0); 92862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 92962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_CFP_COUNT_PRELOAD, 0); 93062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCM_PRELOAD, 0); 93162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 93262306a36Sopenharmony_ci 93362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CNT3, 0); 93462306a36Sopenharmony_ci 93562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR8); 93662306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID0, 10); 93762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID0_VALID, 1); 93862306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID1, 11); 93962306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID1_VALID, 1); 94062306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID2, 13); 94162306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID2_VALID, 1); 94262306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID3, 12); 94362306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR8_BBP_ID3_VALID, 1); 94462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR8, reg); 94562306a36Sopenharmony_ci 94662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARTCSR0); 94762306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR0_ACK_CTS_1MBS, 112); 94862306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR0_ACK_CTS_2MBS, 56); 94962306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR0_ACK_CTS_5_5MBS, 20); 95062306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR0_ACK_CTS_11MBS, 10); 95162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARTCSR0, reg); 95262306a36Sopenharmony_ci 95362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARTCSR1); 95462306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR1_ACK_CTS_6MBS, 45); 95562306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR1_ACK_CTS_9MBS, 37); 95662306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR1_ACK_CTS_12MBS, 33); 95762306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR1_ACK_CTS_18MBS, 29); 95862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARTCSR1, reg); 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARTCSR2); 96162306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR2_ACK_CTS_24MBS, 29); 96262306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR2_ACK_CTS_36MBS, 25); 96362306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR2_ACK_CTS_48MBS, 25); 96462306a36Sopenharmony_ci rt2x00_set_field32(®, ARTCSR2_ACK_CTS_54MBS, 25); 96562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARTCSR2, reg); 96662306a36Sopenharmony_ci 96762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR3); 96862306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID0, 47); /* CCK Signal */ 96962306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID0_VALID, 1); 97062306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID1, 51); /* Rssi */ 97162306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID1_VALID, 1); 97262306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID2, 42); /* OFDM Rate */ 97362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID2_VALID, 1); 97462306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID3, 51); /* RSSI */ 97562306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID3_VALID, 1); 97662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR3, reg); 97762306a36Sopenharmony_ci 97862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, PCICSR); 97962306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_BIG_ENDIAN, 0); 98062306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_RX_TRESHOLD, 0); 98162306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_TX_TRESHOLD, 3); 98262306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_BURST_LENTH, 1); 98362306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_ENABLE_CLK, 1); 98462306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_READ_MULTIPLE, 1); 98562306a36Sopenharmony_ci rt2x00_set_field32(®, PCICSR_WRITE_INVALID, 1); 98662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PCICSR, reg); 98762306a36Sopenharmony_ci 98862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR0, 0x3f3b3100); 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, GPIOCSR, 0x0000ff00); 99162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TESTCSR, 0x000000f0); 99262306a36Sopenharmony_ci 99362306a36Sopenharmony_ci if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE)) 99462306a36Sopenharmony_ci return -EBUSY; 99562306a36Sopenharmony_ci 99662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR0, 0x00213223); 99762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR1, 0x00235518); 99862306a36Sopenharmony_ci 99962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, MACCSR2); 100062306a36Sopenharmony_ci rt2x00_set_field32(®, MACCSR2_DELAY, 64); 100162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR2, reg); 100262306a36Sopenharmony_ci 100362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RALINKCSR); 100462306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA0, 17); 100562306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID0, 26); 100662306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_VALID0, 1); 100762306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA1, 0); 100862306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID1, 26); 100962306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_VALID1, 1); 101062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RALINKCSR, reg); 101162306a36Sopenharmony_ci 101262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BBPCSR1, 0x82188200); 101362306a36Sopenharmony_ci 101462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXACKCSR0, 0x00000020); 101562306a36Sopenharmony_ci 101662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR1); 101762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_SOFT_RESET, 1); 101862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_BBP_RESET, 0); 101962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_HOST_READY, 0); 102062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR1, reg); 102162306a36Sopenharmony_ci 102262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR1); 102362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_SOFT_RESET, 0); 102462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_HOST_READY, 1); 102562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR1, reg); 102662306a36Sopenharmony_ci 102762306a36Sopenharmony_ci /* 102862306a36Sopenharmony_ci * We must clear the FCS and FIFO error count. 102962306a36Sopenharmony_ci * These registers are cleared on read, 103062306a36Sopenharmony_ci * so we may pass a useless variable to store the value. 103162306a36Sopenharmony_ci */ 103262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT0); 103362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT4); 103462306a36Sopenharmony_ci 103562306a36Sopenharmony_ci return 0; 103662306a36Sopenharmony_ci} 103762306a36Sopenharmony_ci 103862306a36Sopenharmony_cistatic int rt2500pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) 103962306a36Sopenharmony_ci{ 104062306a36Sopenharmony_ci unsigned int i; 104162306a36Sopenharmony_ci u8 value; 104262306a36Sopenharmony_ci 104362306a36Sopenharmony_ci for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 104462306a36Sopenharmony_ci value = rt2500pci_bbp_read(rt2x00dev, 0); 104562306a36Sopenharmony_ci if ((value != 0xff) && (value != 0x00)) 104662306a36Sopenharmony_ci return 0; 104762306a36Sopenharmony_ci udelay(REGISTER_BUSY_DELAY); 104862306a36Sopenharmony_ci } 104962306a36Sopenharmony_ci 105062306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n"); 105162306a36Sopenharmony_ci return -EACCES; 105262306a36Sopenharmony_ci} 105362306a36Sopenharmony_ci 105462306a36Sopenharmony_cistatic int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev) 105562306a36Sopenharmony_ci{ 105662306a36Sopenharmony_ci unsigned int i; 105762306a36Sopenharmony_ci u16 eeprom; 105862306a36Sopenharmony_ci u8 reg_id; 105962306a36Sopenharmony_ci u8 value; 106062306a36Sopenharmony_ci 106162306a36Sopenharmony_ci if (unlikely(rt2500pci_wait_bbp_ready(rt2x00dev))) 106262306a36Sopenharmony_ci return -EACCES; 106362306a36Sopenharmony_ci 106462306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 3, 0x02); 106562306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 4, 0x19); 106662306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 14, 0x1c); 106762306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 15, 0x30); 106862306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 16, 0xac); 106962306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 18, 0x18); 107062306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 19, 0xff); 107162306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 20, 0x1e); 107262306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 21, 0x08); 107362306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 22, 0x08); 107462306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 23, 0x08); 107562306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 24, 0x70); 107662306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 25, 0x40); 107762306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 26, 0x08); 107862306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 27, 0x23); 107962306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 30, 0x10); 108062306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 31, 0x2b); 108162306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 32, 0xb9); 108262306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 34, 0x12); 108362306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 35, 0x50); 108462306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 39, 0xc4); 108562306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 40, 0x02); 108662306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 41, 0x60); 108762306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 53, 0x10); 108862306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 54, 0x18); 108962306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 56, 0x08); 109062306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 57, 0x10); 109162306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 58, 0x08); 109262306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 61, 0x6d); 109362306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, 62, 0x10); 109462306a36Sopenharmony_ci 109562306a36Sopenharmony_ci for (i = 0; i < EEPROM_BBP_SIZE; i++) { 109662306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i); 109762306a36Sopenharmony_ci 109862306a36Sopenharmony_ci if (eeprom != 0xffff && eeprom != 0x0000) { 109962306a36Sopenharmony_ci reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); 110062306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); 110162306a36Sopenharmony_ci rt2500pci_bbp_write(rt2x00dev, reg_id, value); 110262306a36Sopenharmony_ci } 110362306a36Sopenharmony_ci } 110462306a36Sopenharmony_ci 110562306a36Sopenharmony_ci return 0; 110662306a36Sopenharmony_ci} 110762306a36Sopenharmony_ci 110862306a36Sopenharmony_ci/* 110962306a36Sopenharmony_ci * Device state switch handlers. 111062306a36Sopenharmony_ci */ 111162306a36Sopenharmony_cistatic void rt2500pci_toggle_irq(struct rt2x00_dev *rt2x00dev, 111262306a36Sopenharmony_ci enum dev_state state) 111362306a36Sopenharmony_ci{ 111462306a36Sopenharmony_ci int mask = (state == STATE_RADIO_IRQ_OFF); 111562306a36Sopenharmony_ci u32 reg; 111662306a36Sopenharmony_ci unsigned long flags; 111762306a36Sopenharmony_ci 111862306a36Sopenharmony_ci /* 111962306a36Sopenharmony_ci * When interrupts are being enabled, the interrupt registers 112062306a36Sopenharmony_ci * should clear the register to assure a clean state. 112162306a36Sopenharmony_ci */ 112262306a36Sopenharmony_ci if (state == STATE_RADIO_IRQ_ON) { 112362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR7); 112462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR7, reg); 112562306a36Sopenharmony_ci } 112662306a36Sopenharmony_ci 112762306a36Sopenharmony_ci /* 112862306a36Sopenharmony_ci * Only toggle the interrupts bits we are going to use. 112962306a36Sopenharmony_ci * Non-checked interrupt bits are disabled by default. 113062306a36Sopenharmony_ci */ 113162306a36Sopenharmony_ci spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags); 113262306a36Sopenharmony_ci 113362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 113462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TBCN_EXPIRE, mask); 113562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_TXRING, mask); 113662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_ATIMRING, mask); 113762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_PRIORING, mask); 113862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_RXDONE, mask); 113962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 114062306a36Sopenharmony_ci 114162306a36Sopenharmony_ci spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags); 114262306a36Sopenharmony_ci 114362306a36Sopenharmony_ci if (state == STATE_RADIO_IRQ_OFF) { 114462306a36Sopenharmony_ci /* 114562306a36Sopenharmony_ci * Ensure that all tasklets are finished. 114662306a36Sopenharmony_ci */ 114762306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->txstatus_tasklet); 114862306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->rxdone_tasklet); 114962306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->tbtt_tasklet); 115062306a36Sopenharmony_ci } 115162306a36Sopenharmony_ci} 115262306a36Sopenharmony_ci 115362306a36Sopenharmony_cistatic int rt2500pci_enable_radio(struct rt2x00_dev *rt2x00dev) 115462306a36Sopenharmony_ci{ 115562306a36Sopenharmony_ci /* 115662306a36Sopenharmony_ci * Initialize all registers. 115762306a36Sopenharmony_ci */ 115862306a36Sopenharmony_ci if (unlikely(rt2500pci_init_queues(rt2x00dev) || 115962306a36Sopenharmony_ci rt2500pci_init_registers(rt2x00dev) || 116062306a36Sopenharmony_ci rt2500pci_init_bbp(rt2x00dev))) 116162306a36Sopenharmony_ci return -EIO; 116262306a36Sopenharmony_ci 116362306a36Sopenharmony_ci return 0; 116462306a36Sopenharmony_ci} 116562306a36Sopenharmony_ci 116662306a36Sopenharmony_cistatic void rt2500pci_disable_radio(struct rt2x00_dev *rt2x00dev) 116762306a36Sopenharmony_ci{ 116862306a36Sopenharmony_ci /* 116962306a36Sopenharmony_ci * Disable power 117062306a36Sopenharmony_ci */ 117162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR0, 0); 117262306a36Sopenharmony_ci} 117362306a36Sopenharmony_ci 117462306a36Sopenharmony_cistatic int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev, 117562306a36Sopenharmony_ci enum dev_state state) 117662306a36Sopenharmony_ci{ 117762306a36Sopenharmony_ci u32 reg, reg2; 117862306a36Sopenharmony_ci unsigned int i; 117962306a36Sopenharmony_ci bool put_to_sleep; 118062306a36Sopenharmony_ci u8 bbp_state; 118162306a36Sopenharmony_ci u8 rf_state; 118262306a36Sopenharmony_ci 118362306a36Sopenharmony_ci put_to_sleep = (state != STATE_AWAKE); 118462306a36Sopenharmony_ci 118562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, PWRCSR1); 118662306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_SET_STATE, 1); 118762306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_BBP_DESIRE_STATE, state); 118862306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_RF_DESIRE_STATE, state); 118962306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_PUT_TO_SLEEP, put_to_sleep); 119062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR1, reg); 119162306a36Sopenharmony_ci 119262306a36Sopenharmony_ci /* 119362306a36Sopenharmony_ci * Device is not guaranteed to be in the requested state yet. 119462306a36Sopenharmony_ci * We must wait until the register indicates that the 119562306a36Sopenharmony_ci * device has entered the correct state. 119662306a36Sopenharmony_ci */ 119762306a36Sopenharmony_ci for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 119862306a36Sopenharmony_ci reg2 = rt2x00mmio_register_read(rt2x00dev, PWRCSR1); 119962306a36Sopenharmony_ci bbp_state = rt2x00_get_field32(reg2, PWRCSR1_BBP_CURR_STATE); 120062306a36Sopenharmony_ci rf_state = rt2x00_get_field32(reg2, PWRCSR1_RF_CURR_STATE); 120162306a36Sopenharmony_ci if (bbp_state == state && rf_state == state) 120262306a36Sopenharmony_ci return 0; 120362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR1, reg); 120462306a36Sopenharmony_ci msleep(10); 120562306a36Sopenharmony_ci } 120662306a36Sopenharmony_ci 120762306a36Sopenharmony_ci return -EBUSY; 120862306a36Sopenharmony_ci} 120962306a36Sopenharmony_ci 121062306a36Sopenharmony_cistatic int rt2500pci_set_device_state(struct rt2x00_dev *rt2x00dev, 121162306a36Sopenharmony_ci enum dev_state state) 121262306a36Sopenharmony_ci{ 121362306a36Sopenharmony_ci int retval = 0; 121462306a36Sopenharmony_ci 121562306a36Sopenharmony_ci switch (state) { 121662306a36Sopenharmony_ci case STATE_RADIO_ON: 121762306a36Sopenharmony_ci retval = rt2500pci_enable_radio(rt2x00dev); 121862306a36Sopenharmony_ci break; 121962306a36Sopenharmony_ci case STATE_RADIO_OFF: 122062306a36Sopenharmony_ci rt2500pci_disable_radio(rt2x00dev); 122162306a36Sopenharmony_ci break; 122262306a36Sopenharmony_ci case STATE_RADIO_IRQ_ON: 122362306a36Sopenharmony_ci case STATE_RADIO_IRQ_OFF: 122462306a36Sopenharmony_ci rt2500pci_toggle_irq(rt2x00dev, state); 122562306a36Sopenharmony_ci break; 122662306a36Sopenharmony_ci case STATE_DEEP_SLEEP: 122762306a36Sopenharmony_ci case STATE_SLEEP: 122862306a36Sopenharmony_ci case STATE_STANDBY: 122962306a36Sopenharmony_ci case STATE_AWAKE: 123062306a36Sopenharmony_ci retval = rt2500pci_set_state(rt2x00dev, state); 123162306a36Sopenharmony_ci break; 123262306a36Sopenharmony_ci default: 123362306a36Sopenharmony_ci retval = -ENOTSUPP; 123462306a36Sopenharmony_ci break; 123562306a36Sopenharmony_ci } 123662306a36Sopenharmony_ci 123762306a36Sopenharmony_ci if (unlikely(retval)) 123862306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n", 123962306a36Sopenharmony_ci state, retval); 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_ci return retval; 124262306a36Sopenharmony_ci} 124362306a36Sopenharmony_ci 124462306a36Sopenharmony_ci/* 124562306a36Sopenharmony_ci * TX descriptor initialization 124662306a36Sopenharmony_ci */ 124762306a36Sopenharmony_cistatic void rt2500pci_write_tx_desc(struct queue_entry *entry, 124862306a36Sopenharmony_ci struct txentry_desc *txdesc) 124962306a36Sopenharmony_ci{ 125062306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 125162306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 125262306a36Sopenharmony_ci __le32 *txd = entry_priv->desc; 125362306a36Sopenharmony_ci u32 word; 125462306a36Sopenharmony_ci 125562306a36Sopenharmony_ci /* 125662306a36Sopenharmony_ci * Start writing the descriptor words. 125762306a36Sopenharmony_ci */ 125862306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 1); 125962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_BUFFER_ADDRESS, skbdesc->skb_dma); 126062306a36Sopenharmony_ci rt2x00_desc_write(txd, 1, word); 126162306a36Sopenharmony_ci 126262306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 2); 126362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_IV_OFFSET, IEEE80211_HEADER); 126462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_AIFS, entry->queue->aifs); 126562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_CWMIN, entry->queue->cw_min); 126662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_CWMAX, entry->queue->cw_max); 126762306a36Sopenharmony_ci rt2x00_desc_write(txd, 2, word); 126862306a36Sopenharmony_ci 126962306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 3); 127062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL, txdesc->u.plcp.signal); 127162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE, txdesc->u.plcp.service); 127262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_LOW, 127362306a36Sopenharmony_ci txdesc->u.plcp.length_low); 127462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_HIGH, 127562306a36Sopenharmony_ci txdesc->u.plcp.length_high); 127662306a36Sopenharmony_ci rt2x00_desc_write(txd, 3, word); 127762306a36Sopenharmony_ci 127862306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 10); 127962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W10_RTS, 128062306a36Sopenharmony_ci test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags)); 128162306a36Sopenharmony_ci rt2x00_desc_write(txd, 10, word); 128262306a36Sopenharmony_ci 128362306a36Sopenharmony_ci /* 128462306a36Sopenharmony_ci * Writing TXD word 0 must the last to prevent a race condition with 128562306a36Sopenharmony_ci * the device, whereby the device may take hold of the TXD before we 128662306a36Sopenharmony_ci * finished updating it. 128762306a36Sopenharmony_ci */ 128862306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 0); 128962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1); 129062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_VALID, 1); 129162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_MORE_FRAG, 129262306a36Sopenharmony_ci test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); 129362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_ACK, 129462306a36Sopenharmony_ci test_bit(ENTRY_TXD_ACK, &txdesc->flags)); 129562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_TIMESTAMP, 129662306a36Sopenharmony_ci test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); 129762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OFDM, 129862306a36Sopenharmony_ci (txdesc->rate_mode == RATE_MODE_OFDM)); 129962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_CIPHER_OWNER, 1); 130062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->u.plcp.ifs); 130162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, 130262306a36Sopenharmony_ci test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); 130362306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length); 130462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, CIPHER_NONE); 130562306a36Sopenharmony_ci rt2x00_desc_write(txd, 0, word); 130662306a36Sopenharmony_ci 130762306a36Sopenharmony_ci /* 130862306a36Sopenharmony_ci * Register descriptor details in skb frame descriptor. 130962306a36Sopenharmony_ci */ 131062306a36Sopenharmony_ci skbdesc->desc = txd; 131162306a36Sopenharmony_ci skbdesc->desc_len = TXD_DESC_SIZE; 131262306a36Sopenharmony_ci} 131362306a36Sopenharmony_ci 131462306a36Sopenharmony_ci/* 131562306a36Sopenharmony_ci * TX data initialization 131662306a36Sopenharmony_ci */ 131762306a36Sopenharmony_cistatic void rt2500pci_write_beacon(struct queue_entry *entry, 131862306a36Sopenharmony_ci struct txentry_desc *txdesc) 131962306a36Sopenharmony_ci{ 132062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 132162306a36Sopenharmony_ci u32 reg; 132262306a36Sopenharmony_ci 132362306a36Sopenharmony_ci /* 132462306a36Sopenharmony_ci * Disable beaconing while we are reloading the beacon data, 132562306a36Sopenharmony_ci * otherwise we might be sending out invalid data. 132662306a36Sopenharmony_ci */ 132762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 132862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 132962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 133062306a36Sopenharmony_ci 133162306a36Sopenharmony_ci if (rt2x00queue_map_txskb(entry)) { 133262306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Fail to map beacon, aborting\n"); 133362306a36Sopenharmony_ci goto out; 133462306a36Sopenharmony_ci } 133562306a36Sopenharmony_ci 133662306a36Sopenharmony_ci /* 133762306a36Sopenharmony_ci * Write the TX descriptor for the beacon. 133862306a36Sopenharmony_ci */ 133962306a36Sopenharmony_ci rt2500pci_write_tx_desc(entry, txdesc); 134062306a36Sopenharmony_ci 134162306a36Sopenharmony_ci /* 134262306a36Sopenharmony_ci * Dump beacon to userspace through debugfs. 134362306a36Sopenharmony_ci */ 134462306a36Sopenharmony_ci rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry); 134562306a36Sopenharmony_ciout: 134662306a36Sopenharmony_ci /* 134762306a36Sopenharmony_ci * Enable beaconing again. 134862306a36Sopenharmony_ci */ 134962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 1); 135062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 135162306a36Sopenharmony_ci} 135262306a36Sopenharmony_ci 135362306a36Sopenharmony_ci/* 135462306a36Sopenharmony_ci * RX control handlers 135562306a36Sopenharmony_ci */ 135662306a36Sopenharmony_cistatic void rt2500pci_fill_rxdone(struct queue_entry *entry, 135762306a36Sopenharmony_ci struct rxdone_entry_desc *rxdesc) 135862306a36Sopenharmony_ci{ 135962306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 136062306a36Sopenharmony_ci u32 word0; 136162306a36Sopenharmony_ci u32 word2; 136262306a36Sopenharmony_ci 136362306a36Sopenharmony_ci word0 = rt2x00_desc_read(entry_priv->desc, 0); 136462306a36Sopenharmony_ci word2 = rt2x00_desc_read(entry_priv->desc, 2); 136562306a36Sopenharmony_ci 136662306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) 136762306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; 136862306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR)) 136962306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC; 137062306a36Sopenharmony_ci 137162306a36Sopenharmony_ci /* 137262306a36Sopenharmony_ci * Obtain the status about this packet. 137362306a36Sopenharmony_ci * When frame was received with an OFDM bitrate, 137462306a36Sopenharmony_ci * the signal is the PLCP value. If it was received with 137562306a36Sopenharmony_ci * a CCK bitrate the signal is the rate in 100kbit/s. 137662306a36Sopenharmony_ci */ 137762306a36Sopenharmony_ci rxdesc->signal = rt2x00_get_field32(word2, RXD_W2_SIGNAL); 137862306a36Sopenharmony_ci rxdesc->rssi = rt2x00_get_field32(word2, RXD_W2_RSSI) - 137962306a36Sopenharmony_ci entry->queue->rt2x00dev->rssi_offset; 138062306a36Sopenharmony_ci rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); 138162306a36Sopenharmony_ci 138262306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_OFDM)) 138362306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 138462306a36Sopenharmony_ci else 138562306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE; 138662306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 138762306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_MY_BSS; 138862306a36Sopenharmony_ci} 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_ci/* 139162306a36Sopenharmony_ci * Interrupt functions. 139262306a36Sopenharmony_ci */ 139362306a36Sopenharmony_cistatic void rt2500pci_txdone(struct rt2x00_dev *rt2x00dev, 139462306a36Sopenharmony_ci const enum data_queue_qid queue_idx) 139562306a36Sopenharmony_ci{ 139662306a36Sopenharmony_ci struct data_queue *queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); 139762306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv; 139862306a36Sopenharmony_ci struct queue_entry *entry; 139962306a36Sopenharmony_ci struct txdone_entry_desc txdesc; 140062306a36Sopenharmony_ci u32 word; 140162306a36Sopenharmony_ci 140262306a36Sopenharmony_ci while (!rt2x00queue_empty(queue)) { 140362306a36Sopenharmony_ci entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE); 140462306a36Sopenharmony_ci entry_priv = entry->priv_data; 140562306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 140662306a36Sopenharmony_ci 140762306a36Sopenharmony_ci if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) || 140862306a36Sopenharmony_ci !rt2x00_get_field32(word, TXD_W0_VALID)) 140962306a36Sopenharmony_ci break; 141062306a36Sopenharmony_ci 141162306a36Sopenharmony_ci /* 141262306a36Sopenharmony_ci * Obtain the status about this packet. 141362306a36Sopenharmony_ci */ 141462306a36Sopenharmony_ci txdesc.flags = 0; 141562306a36Sopenharmony_ci switch (rt2x00_get_field32(word, TXD_W0_RESULT)) { 141662306a36Sopenharmony_ci case 0: /* Success */ 141762306a36Sopenharmony_ci case 1: /* Success with retry */ 141862306a36Sopenharmony_ci __set_bit(TXDONE_SUCCESS, &txdesc.flags); 141962306a36Sopenharmony_ci break; 142062306a36Sopenharmony_ci case 2: /* Failure, excessive retries */ 142162306a36Sopenharmony_ci __set_bit(TXDONE_EXCESSIVE_RETRY, &txdesc.flags); 142262306a36Sopenharmony_ci fallthrough; /* this is a failed frame! */ 142362306a36Sopenharmony_ci default: /* Failure */ 142462306a36Sopenharmony_ci __set_bit(TXDONE_FAILURE, &txdesc.flags); 142562306a36Sopenharmony_ci } 142662306a36Sopenharmony_ci txdesc.retry = rt2x00_get_field32(word, TXD_W0_RETRY_COUNT); 142762306a36Sopenharmony_ci 142862306a36Sopenharmony_ci rt2x00lib_txdone(entry, &txdesc); 142962306a36Sopenharmony_ci } 143062306a36Sopenharmony_ci} 143162306a36Sopenharmony_ci 143262306a36Sopenharmony_cistatic inline void rt2500pci_enable_interrupt(struct rt2x00_dev *rt2x00dev, 143362306a36Sopenharmony_ci struct rt2x00_field32 irq_field) 143462306a36Sopenharmony_ci{ 143562306a36Sopenharmony_ci u32 reg; 143662306a36Sopenharmony_ci 143762306a36Sopenharmony_ci /* 143862306a36Sopenharmony_ci * Enable a single interrupt. The interrupt mask register 143962306a36Sopenharmony_ci * access needs locking. 144062306a36Sopenharmony_ci */ 144162306a36Sopenharmony_ci spin_lock_irq(&rt2x00dev->irqmask_lock); 144262306a36Sopenharmony_ci 144362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 144462306a36Sopenharmony_ci rt2x00_set_field32(®, irq_field, 0); 144562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 144662306a36Sopenharmony_ci 144762306a36Sopenharmony_ci spin_unlock_irq(&rt2x00dev->irqmask_lock); 144862306a36Sopenharmony_ci} 144962306a36Sopenharmony_ci 145062306a36Sopenharmony_cistatic void rt2500pci_txstatus_tasklet(struct tasklet_struct *t) 145162306a36Sopenharmony_ci{ 145262306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, 145362306a36Sopenharmony_ci txstatus_tasklet); 145462306a36Sopenharmony_ci u32 reg; 145562306a36Sopenharmony_ci 145662306a36Sopenharmony_ci /* 145762306a36Sopenharmony_ci * Handle all tx queues. 145862306a36Sopenharmony_ci */ 145962306a36Sopenharmony_ci rt2500pci_txdone(rt2x00dev, QID_ATIM); 146062306a36Sopenharmony_ci rt2500pci_txdone(rt2x00dev, QID_AC_VO); 146162306a36Sopenharmony_ci rt2500pci_txdone(rt2x00dev, QID_AC_VI); 146262306a36Sopenharmony_ci 146362306a36Sopenharmony_ci /* 146462306a36Sopenharmony_ci * Enable all TXDONE interrupts again. 146562306a36Sopenharmony_ci */ 146662306a36Sopenharmony_ci if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) { 146762306a36Sopenharmony_ci spin_lock_irq(&rt2x00dev->irqmask_lock); 146862306a36Sopenharmony_ci 146962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 147062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_TXRING, 0); 147162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_ATIMRING, 0); 147262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_PRIORING, 0); 147362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 147462306a36Sopenharmony_ci 147562306a36Sopenharmony_ci spin_unlock_irq(&rt2x00dev->irqmask_lock); 147662306a36Sopenharmony_ci } 147762306a36Sopenharmony_ci} 147862306a36Sopenharmony_ci 147962306a36Sopenharmony_cistatic void rt2500pci_tbtt_tasklet(struct tasklet_struct *t) 148062306a36Sopenharmony_ci{ 148162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, tbtt_tasklet); 148262306a36Sopenharmony_ci rt2x00lib_beacondone(rt2x00dev); 148362306a36Sopenharmony_ci if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 148462306a36Sopenharmony_ci rt2500pci_enable_interrupt(rt2x00dev, CSR8_TBCN_EXPIRE); 148562306a36Sopenharmony_ci} 148662306a36Sopenharmony_ci 148762306a36Sopenharmony_cistatic void rt2500pci_rxdone_tasklet(struct tasklet_struct *t) 148862306a36Sopenharmony_ci{ 148962306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, 149062306a36Sopenharmony_ci rxdone_tasklet); 149162306a36Sopenharmony_ci if (rt2x00mmio_rxdone(rt2x00dev)) 149262306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->rxdone_tasklet); 149362306a36Sopenharmony_ci else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 149462306a36Sopenharmony_ci rt2500pci_enable_interrupt(rt2x00dev, CSR8_RXDONE); 149562306a36Sopenharmony_ci} 149662306a36Sopenharmony_ci 149762306a36Sopenharmony_cistatic irqreturn_t rt2500pci_interrupt(int irq, void *dev_instance) 149862306a36Sopenharmony_ci{ 149962306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = dev_instance; 150062306a36Sopenharmony_ci u32 reg, mask; 150162306a36Sopenharmony_ci 150262306a36Sopenharmony_ci /* 150362306a36Sopenharmony_ci * Get the interrupt sources & saved to local variable. 150462306a36Sopenharmony_ci * Write register value back to clear pending interrupts. 150562306a36Sopenharmony_ci */ 150662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR7); 150762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR7, reg); 150862306a36Sopenharmony_ci 150962306a36Sopenharmony_ci if (!reg) 151062306a36Sopenharmony_ci return IRQ_NONE; 151162306a36Sopenharmony_ci 151262306a36Sopenharmony_ci if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 151362306a36Sopenharmony_ci return IRQ_HANDLED; 151462306a36Sopenharmony_ci 151562306a36Sopenharmony_ci mask = reg; 151662306a36Sopenharmony_ci 151762306a36Sopenharmony_ci /* 151862306a36Sopenharmony_ci * Schedule tasklets for interrupt handling. 151962306a36Sopenharmony_ci */ 152062306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_TBCN_EXPIRE)) 152162306a36Sopenharmony_ci tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet); 152262306a36Sopenharmony_ci 152362306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_RXDONE)) 152462306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->rxdone_tasklet); 152562306a36Sopenharmony_ci 152662306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING) || 152762306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING) || 152862306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR7_TXDONE_TXRING)) { 152962306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->txstatus_tasklet); 153062306a36Sopenharmony_ci /* 153162306a36Sopenharmony_ci * Mask out all txdone interrupts. 153262306a36Sopenharmony_ci */ 153362306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_TXRING, 1); 153462306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_ATIMRING, 1); 153562306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_PRIORING, 1); 153662306a36Sopenharmony_ci } 153762306a36Sopenharmony_ci 153862306a36Sopenharmony_ci /* 153962306a36Sopenharmony_ci * Disable all interrupts for which a tasklet was scheduled right now, 154062306a36Sopenharmony_ci * the tasklet will reenable the appropriate interrupts. 154162306a36Sopenharmony_ci */ 154262306a36Sopenharmony_ci spin_lock(&rt2x00dev->irqmask_lock); 154362306a36Sopenharmony_ci 154462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 154562306a36Sopenharmony_ci reg |= mask; 154662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 154762306a36Sopenharmony_ci 154862306a36Sopenharmony_ci spin_unlock(&rt2x00dev->irqmask_lock); 154962306a36Sopenharmony_ci 155062306a36Sopenharmony_ci return IRQ_HANDLED; 155162306a36Sopenharmony_ci} 155262306a36Sopenharmony_ci 155362306a36Sopenharmony_ci/* 155462306a36Sopenharmony_ci * Device probe functions. 155562306a36Sopenharmony_ci */ 155662306a36Sopenharmony_cistatic int rt2500pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) 155762306a36Sopenharmony_ci{ 155862306a36Sopenharmony_ci struct eeprom_93cx6 eeprom; 155962306a36Sopenharmony_ci u32 reg; 156062306a36Sopenharmony_ci u16 word; 156162306a36Sopenharmony_ci u8 *mac; 156262306a36Sopenharmony_ci 156362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR21); 156462306a36Sopenharmony_ci 156562306a36Sopenharmony_ci eeprom.data = rt2x00dev; 156662306a36Sopenharmony_ci eeprom.register_read = rt2500pci_eepromregister_read; 156762306a36Sopenharmony_ci eeprom.register_write = rt2500pci_eepromregister_write; 156862306a36Sopenharmony_ci eeprom.width = rt2x00_get_field32(reg, CSR21_TYPE_93C46) ? 156962306a36Sopenharmony_ci PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66; 157062306a36Sopenharmony_ci eeprom.reg_data_in = 0; 157162306a36Sopenharmony_ci eeprom.reg_data_out = 0; 157262306a36Sopenharmony_ci eeprom.reg_data_clock = 0; 157362306a36Sopenharmony_ci eeprom.reg_chip_select = 0; 157462306a36Sopenharmony_ci 157562306a36Sopenharmony_ci eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom, 157662306a36Sopenharmony_ci EEPROM_SIZE / sizeof(u16)); 157762306a36Sopenharmony_ci 157862306a36Sopenharmony_ci /* 157962306a36Sopenharmony_ci * Start validation of the data that has been read. 158062306a36Sopenharmony_ci */ 158162306a36Sopenharmony_ci mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); 158262306a36Sopenharmony_ci rt2x00lib_set_mac_address(rt2x00dev, mac); 158362306a36Sopenharmony_ci 158462306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 158562306a36Sopenharmony_ci if (word == 0xffff) { 158662306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2); 158762306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT, 158862306a36Sopenharmony_ci ANTENNA_SW_DIVERSITY); 158962306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT, 159062306a36Sopenharmony_ci ANTENNA_SW_DIVERSITY); 159162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE, 159262306a36Sopenharmony_ci LED_MODE_DEFAULT); 159362306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0); 159462306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0); 159562306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522); 159662306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word); 159762306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word); 159862306a36Sopenharmony_ci } 159962306a36Sopenharmony_ci 160062306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC); 160162306a36Sopenharmony_ci if (word == 0xffff) { 160262306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0); 160362306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0); 160462306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0); 160562306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word); 160662306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word); 160762306a36Sopenharmony_ci } 160862306a36Sopenharmony_ci 160962306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET); 161062306a36Sopenharmony_ci if (word == 0xffff) { 161162306a36Sopenharmony_ci rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI, 161262306a36Sopenharmony_ci DEFAULT_RSSI_OFFSET); 161362306a36Sopenharmony_ci rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word); 161462306a36Sopenharmony_ci rt2x00_eeprom_dbg(rt2x00dev, "Calibrate offset: 0x%04x\n", 161562306a36Sopenharmony_ci word); 161662306a36Sopenharmony_ci } 161762306a36Sopenharmony_ci 161862306a36Sopenharmony_ci return 0; 161962306a36Sopenharmony_ci} 162062306a36Sopenharmony_ci 162162306a36Sopenharmony_cistatic int rt2500pci_init_eeprom(struct rt2x00_dev *rt2x00dev) 162262306a36Sopenharmony_ci{ 162362306a36Sopenharmony_ci u32 reg; 162462306a36Sopenharmony_ci u16 value; 162562306a36Sopenharmony_ci u16 eeprom; 162662306a36Sopenharmony_ci 162762306a36Sopenharmony_ci /* 162862306a36Sopenharmony_ci * Read EEPROM word for configuration. 162962306a36Sopenharmony_ci */ 163062306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 163162306a36Sopenharmony_ci 163262306a36Sopenharmony_ci /* 163362306a36Sopenharmony_ci * Identify RF chipset. 163462306a36Sopenharmony_ci */ 163562306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 163662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR0); 163762306a36Sopenharmony_ci rt2x00_set_chip(rt2x00dev, RT2560, value, 163862306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR0_REVISION)); 163962306a36Sopenharmony_ci 164062306a36Sopenharmony_ci if (!rt2x00_rf(rt2x00dev, RF2522) && 164162306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2523) && 164262306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2524) && 164362306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2525) && 164462306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF2525E) && 164562306a36Sopenharmony_ci !rt2x00_rf(rt2x00dev, RF5222)) { 164662306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Invalid RF chipset detected\n"); 164762306a36Sopenharmony_ci return -ENODEV; 164862306a36Sopenharmony_ci } 164962306a36Sopenharmony_ci 165062306a36Sopenharmony_ci /* 165162306a36Sopenharmony_ci * Identify default antenna configuration. 165262306a36Sopenharmony_ci */ 165362306a36Sopenharmony_ci rt2x00dev->default_ant.tx = 165462306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT); 165562306a36Sopenharmony_ci rt2x00dev->default_ant.rx = 165662306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT); 165762306a36Sopenharmony_ci 165862306a36Sopenharmony_ci /* 165962306a36Sopenharmony_ci * Store led mode, for correct led behaviour. 166062306a36Sopenharmony_ci */ 166162306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_LEDS 166262306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE); 166362306a36Sopenharmony_ci 166462306a36Sopenharmony_ci rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 166562306a36Sopenharmony_ci if (value == LED_MODE_TXRX_ACTIVITY || 166662306a36Sopenharmony_ci value == LED_MODE_DEFAULT || 166762306a36Sopenharmony_ci value == LED_MODE_ASUS) 166862306a36Sopenharmony_ci rt2500pci_init_led(rt2x00dev, &rt2x00dev->led_qual, 166962306a36Sopenharmony_ci LED_TYPE_ACTIVITY); 167062306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_LEDS */ 167162306a36Sopenharmony_ci 167262306a36Sopenharmony_ci /* 167362306a36Sopenharmony_ci * Detect if this device has an hardware controlled radio. 167462306a36Sopenharmony_ci */ 167562306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) { 167662306a36Sopenharmony_ci __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags); 167762306a36Sopenharmony_ci /* 167862306a36Sopenharmony_ci * On this device RFKILL initialized during probe does not work. 167962306a36Sopenharmony_ci */ 168062306a36Sopenharmony_ci __set_bit(REQUIRE_DELAYED_RFKILL, &rt2x00dev->cap_flags); 168162306a36Sopenharmony_ci } 168262306a36Sopenharmony_ci 168362306a36Sopenharmony_ci /* 168462306a36Sopenharmony_ci * Check if the BBP tuning should be enabled. 168562306a36Sopenharmony_ci */ 168662306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC); 168762306a36Sopenharmony_ci if (!rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE)) 168862306a36Sopenharmony_ci __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); 168962306a36Sopenharmony_ci 169062306a36Sopenharmony_ci /* 169162306a36Sopenharmony_ci * Read the RSSI <-> dBm offset information. 169262306a36Sopenharmony_ci */ 169362306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET); 169462306a36Sopenharmony_ci rt2x00dev->rssi_offset = 169562306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI); 169662306a36Sopenharmony_ci 169762306a36Sopenharmony_ci return 0; 169862306a36Sopenharmony_ci} 169962306a36Sopenharmony_ci 170062306a36Sopenharmony_ci/* 170162306a36Sopenharmony_ci * RF value list for RF2522 170262306a36Sopenharmony_ci * Supports: 2.4 GHz 170362306a36Sopenharmony_ci */ 170462306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2522[] = { 170562306a36Sopenharmony_ci { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 }, 170662306a36Sopenharmony_ci { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 }, 170762306a36Sopenharmony_ci { 3, 0x00002050, 0x000c2002, 0x00000101, 0 }, 170862306a36Sopenharmony_ci { 4, 0x00002050, 0x000c2016, 0x00000101, 0 }, 170962306a36Sopenharmony_ci { 5, 0x00002050, 0x000c202a, 0x00000101, 0 }, 171062306a36Sopenharmony_ci { 6, 0x00002050, 0x000c203e, 0x00000101, 0 }, 171162306a36Sopenharmony_ci { 7, 0x00002050, 0x000c2052, 0x00000101, 0 }, 171262306a36Sopenharmony_ci { 8, 0x00002050, 0x000c2066, 0x00000101, 0 }, 171362306a36Sopenharmony_ci { 9, 0x00002050, 0x000c207a, 0x00000101, 0 }, 171462306a36Sopenharmony_ci { 10, 0x00002050, 0x000c208e, 0x00000101, 0 }, 171562306a36Sopenharmony_ci { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 }, 171662306a36Sopenharmony_ci { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 }, 171762306a36Sopenharmony_ci { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 }, 171862306a36Sopenharmony_ci { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 }, 171962306a36Sopenharmony_ci}; 172062306a36Sopenharmony_ci 172162306a36Sopenharmony_ci/* 172262306a36Sopenharmony_ci * RF value list for RF2523 172362306a36Sopenharmony_ci * Supports: 2.4 GHz 172462306a36Sopenharmony_ci */ 172562306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2523[] = { 172662306a36Sopenharmony_ci { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b }, 172762306a36Sopenharmony_ci { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b }, 172862306a36Sopenharmony_ci { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b }, 172962306a36Sopenharmony_ci { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b }, 173062306a36Sopenharmony_ci { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b }, 173162306a36Sopenharmony_ci { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b }, 173262306a36Sopenharmony_ci { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b }, 173362306a36Sopenharmony_ci { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b }, 173462306a36Sopenharmony_ci { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b }, 173562306a36Sopenharmony_ci { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b }, 173662306a36Sopenharmony_ci { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b }, 173762306a36Sopenharmony_ci { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b }, 173862306a36Sopenharmony_ci { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b }, 173962306a36Sopenharmony_ci { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 }, 174062306a36Sopenharmony_ci}; 174162306a36Sopenharmony_ci 174262306a36Sopenharmony_ci/* 174362306a36Sopenharmony_ci * RF value list for RF2524 174462306a36Sopenharmony_ci * Supports: 2.4 GHz 174562306a36Sopenharmony_ci */ 174662306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2524[] = { 174762306a36Sopenharmony_ci { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b }, 174862306a36Sopenharmony_ci { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b }, 174962306a36Sopenharmony_ci { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b }, 175062306a36Sopenharmony_ci { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b }, 175162306a36Sopenharmony_ci { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b }, 175262306a36Sopenharmony_ci { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b }, 175362306a36Sopenharmony_ci { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b }, 175462306a36Sopenharmony_ci { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b }, 175562306a36Sopenharmony_ci { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b }, 175662306a36Sopenharmony_ci { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b }, 175762306a36Sopenharmony_ci { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b }, 175862306a36Sopenharmony_ci { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b }, 175962306a36Sopenharmony_ci { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b }, 176062306a36Sopenharmony_ci { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 }, 176162306a36Sopenharmony_ci}; 176262306a36Sopenharmony_ci 176362306a36Sopenharmony_ci/* 176462306a36Sopenharmony_ci * RF value list for RF2525 176562306a36Sopenharmony_ci * Supports: 2.4 GHz 176662306a36Sopenharmony_ci */ 176762306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2525[] = { 176862306a36Sopenharmony_ci { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b }, 176962306a36Sopenharmony_ci { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b }, 177062306a36Sopenharmony_ci { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b }, 177162306a36Sopenharmony_ci { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b }, 177262306a36Sopenharmony_ci { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b }, 177362306a36Sopenharmony_ci { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b }, 177462306a36Sopenharmony_ci { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b }, 177562306a36Sopenharmony_ci { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b }, 177662306a36Sopenharmony_ci { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b }, 177762306a36Sopenharmony_ci { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b }, 177862306a36Sopenharmony_ci { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b }, 177962306a36Sopenharmony_ci { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b }, 178062306a36Sopenharmony_ci { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b }, 178162306a36Sopenharmony_ci { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 }, 178262306a36Sopenharmony_ci}; 178362306a36Sopenharmony_ci 178462306a36Sopenharmony_ci/* 178562306a36Sopenharmony_ci * RF value list for RF2525e 178662306a36Sopenharmony_ci * Supports: 2.4 GHz 178762306a36Sopenharmony_ci */ 178862306a36Sopenharmony_cistatic const struct rf_channel rf_vals_bg_2525e[] = { 178962306a36Sopenharmony_ci { 1, 0x00022020, 0x00081136, 0x00060111, 0x00000a0b }, 179062306a36Sopenharmony_ci { 2, 0x00022020, 0x0008113a, 0x00060111, 0x00000a0b }, 179162306a36Sopenharmony_ci { 3, 0x00022020, 0x0008113e, 0x00060111, 0x00000a0b }, 179262306a36Sopenharmony_ci { 4, 0x00022020, 0x00081182, 0x00060111, 0x00000a0b }, 179362306a36Sopenharmony_ci { 5, 0x00022020, 0x00081186, 0x00060111, 0x00000a0b }, 179462306a36Sopenharmony_ci { 6, 0x00022020, 0x0008118a, 0x00060111, 0x00000a0b }, 179562306a36Sopenharmony_ci { 7, 0x00022020, 0x0008118e, 0x00060111, 0x00000a0b }, 179662306a36Sopenharmony_ci { 8, 0x00022020, 0x00081192, 0x00060111, 0x00000a0b }, 179762306a36Sopenharmony_ci { 9, 0x00022020, 0x00081196, 0x00060111, 0x00000a0b }, 179862306a36Sopenharmony_ci { 10, 0x00022020, 0x0008119a, 0x00060111, 0x00000a0b }, 179962306a36Sopenharmony_ci { 11, 0x00022020, 0x0008119e, 0x00060111, 0x00000a0b }, 180062306a36Sopenharmony_ci { 12, 0x00022020, 0x000811a2, 0x00060111, 0x00000a0b }, 180162306a36Sopenharmony_ci { 13, 0x00022020, 0x000811a6, 0x00060111, 0x00000a0b }, 180262306a36Sopenharmony_ci { 14, 0x00022020, 0x000811ae, 0x00060111, 0x00000a1b }, 180362306a36Sopenharmony_ci}; 180462306a36Sopenharmony_ci 180562306a36Sopenharmony_ci/* 180662306a36Sopenharmony_ci * RF value list for RF5222 180762306a36Sopenharmony_ci * Supports: 2.4 GHz & 5.2 GHz 180862306a36Sopenharmony_ci */ 180962306a36Sopenharmony_cistatic const struct rf_channel rf_vals_5222[] = { 181062306a36Sopenharmony_ci { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b }, 181162306a36Sopenharmony_ci { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b }, 181262306a36Sopenharmony_ci { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b }, 181362306a36Sopenharmony_ci { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b }, 181462306a36Sopenharmony_ci { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b }, 181562306a36Sopenharmony_ci { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b }, 181662306a36Sopenharmony_ci { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b }, 181762306a36Sopenharmony_ci { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b }, 181862306a36Sopenharmony_ci { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b }, 181962306a36Sopenharmony_ci { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b }, 182062306a36Sopenharmony_ci { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b }, 182162306a36Sopenharmony_ci { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b }, 182262306a36Sopenharmony_ci { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b }, 182362306a36Sopenharmony_ci { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b }, 182462306a36Sopenharmony_ci 182562306a36Sopenharmony_ci /* 802.11 UNI / HyperLan 2 */ 182662306a36Sopenharmony_ci { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f }, 182762306a36Sopenharmony_ci { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f }, 182862306a36Sopenharmony_ci { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f }, 182962306a36Sopenharmony_ci { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f }, 183062306a36Sopenharmony_ci { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f }, 183162306a36Sopenharmony_ci { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f }, 183262306a36Sopenharmony_ci { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f }, 183362306a36Sopenharmony_ci { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f }, 183462306a36Sopenharmony_ci 183562306a36Sopenharmony_ci /* 802.11 HyperLan 2 */ 183662306a36Sopenharmony_ci { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f }, 183762306a36Sopenharmony_ci { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f }, 183862306a36Sopenharmony_ci { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f }, 183962306a36Sopenharmony_ci { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f }, 184062306a36Sopenharmony_ci { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f }, 184162306a36Sopenharmony_ci { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f }, 184262306a36Sopenharmony_ci { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f }, 184362306a36Sopenharmony_ci { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f }, 184462306a36Sopenharmony_ci { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f }, 184562306a36Sopenharmony_ci { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f }, 184662306a36Sopenharmony_ci 184762306a36Sopenharmony_ci /* 802.11 UNII */ 184862306a36Sopenharmony_ci { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f }, 184962306a36Sopenharmony_ci { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 }, 185062306a36Sopenharmony_ci { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 }, 185162306a36Sopenharmony_ci { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 }, 185262306a36Sopenharmony_ci { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 }, 185362306a36Sopenharmony_ci}; 185462306a36Sopenharmony_ci 185562306a36Sopenharmony_cistatic int rt2500pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 185662306a36Sopenharmony_ci{ 185762306a36Sopenharmony_ci struct hw_mode_spec *spec = &rt2x00dev->spec; 185862306a36Sopenharmony_ci struct channel_info *info; 185962306a36Sopenharmony_ci u8 *tx_power; 186062306a36Sopenharmony_ci unsigned int i; 186162306a36Sopenharmony_ci 186262306a36Sopenharmony_ci /* 186362306a36Sopenharmony_ci * Initialize all hw fields. 186462306a36Sopenharmony_ci */ 186562306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, PS_NULLFUNC_STACK); 186662306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SUPPORTS_PS); 186762306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, HOST_BROADCAST_PS_BUFFERING); 186862306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SIGNAL_DBM); 186962306a36Sopenharmony_ci 187062306a36Sopenharmony_ci SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); 187162306a36Sopenharmony_ci SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, 187262306a36Sopenharmony_ci rt2x00_eeprom_addr(rt2x00dev, 187362306a36Sopenharmony_ci EEPROM_MAC_ADDR_0)); 187462306a36Sopenharmony_ci 187562306a36Sopenharmony_ci /* 187662306a36Sopenharmony_ci * Disable powersaving as default. 187762306a36Sopenharmony_ci */ 187862306a36Sopenharmony_ci rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 187962306a36Sopenharmony_ci 188062306a36Sopenharmony_ci /* 188162306a36Sopenharmony_ci * Initialize hw_mode information. 188262306a36Sopenharmony_ci */ 188362306a36Sopenharmony_ci spec->supported_bands = SUPPORT_BAND_2GHZ; 188462306a36Sopenharmony_ci spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM; 188562306a36Sopenharmony_ci 188662306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2522)) { 188762306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522); 188862306a36Sopenharmony_ci spec->channels = rf_vals_bg_2522; 188962306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF2523)) { 189062306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523); 189162306a36Sopenharmony_ci spec->channels = rf_vals_bg_2523; 189262306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF2524)) { 189362306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524); 189462306a36Sopenharmony_ci spec->channels = rf_vals_bg_2524; 189562306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF2525)) { 189662306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525); 189762306a36Sopenharmony_ci spec->channels = rf_vals_bg_2525; 189862306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF2525E)) { 189962306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e); 190062306a36Sopenharmony_ci spec->channels = rf_vals_bg_2525e; 190162306a36Sopenharmony_ci } else if (rt2x00_rf(rt2x00dev, RF5222)) { 190262306a36Sopenharmony_ci spec->supported_bands |= SUPPORT_BAND_5GHZ; 190362306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_5222); 190462306a36Sopenharmony_ci spec->channels = rf_vals_5222; 190562306a36Sopenharmony_ci } 190662306a36Sopenharmony_ci 190762306a36Sopenharmony_ci /* 190862306a36Sopenharmony_ci * Create channel information array 190962306a36Sopenharmony_ci */ 191062306a36Sopenharmony_ci info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); 191162306a36Sopenharmony_ci if (!info) 191262306a36Sopenharmony_ci return -ENOMEM; 191362306a36Sopenharmony_ci 191462306a36Sopenharmony_ci spec->channels_info = info; 191562306a36Sopenharmony_ci 191662306a36Sopenharmony_ci tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START); 191762306a36Sopenharmony_ci for (i = 0; i < 14; i++) { 191862306a36Sopenharmony_ci info[i].max_power = MAX_TXPOWER; 191962306a36Sopenharmony_ci info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]); 192062306a36Sopenharmony_ci } 192162306a36Sopenharmony_ci 192262306a36Sopenharmony_ci if (spec->num_channels > 14) { 192362306a36Sopenharmony_ci for (i = 14; i < spec->num_channels; i++) { 192462306a36Sopenharmony_ci info[i].max_power = MAX_TXPOWER; 192562306a36Sopenharmony_ci info[i].default_power1 = DEFAULT_TXPOWER; 192662306a36Sopenharmony_ci } 192762306a36Sopenharmony_ci } 192862306a36Sopenharmony_ci 192962306a36Sopenharmony_ci return 0; 193062306a36Sopenharmony_ci} 193162306a36Sopenharmony_ci 193262306a36Sopenharmony_cistatic int rt2500pci_probe_hw(struct rt2x00_dev *rt2x00dev) 193362306a36Sopenharmony_ci{ 193462306a36Sopenharmony_ci int retval; 193562306a36Sopenharmony_ci u32 reg; 193662306a36Sopenharmony_ci 193762306a36Sopenharmony_ci /* 193862306a36Sopenharmony_ci * Allocate eeprom data. 193962306a36Sopenharmony_ci */ 194062306a36Sopenharmony_ci retval = rt2500pci_validate_eeprom(rt2x00dev); 194162306a36Sopenharmony_ci if (retval) 194262306a36Sopenharmony_ci return retval; 194362306a36Sopenharmony_ci 194462306a36Sopenharmony_ci retval = rt2500pci_init_eeprom(rt2x00dev); 194562306a36Sopenharmony_ci if (retval) 194662306a36Sopenharmony_ci return retval; 194762306a36Sopenharmony_ci 194862306a36Sopenharmony_ci /* 194962306a36Sopenharmony_ci * Enable rfkill polling by setting GPIO direction of the 195062306a36Sopenharmony_ci * rfkill switch GPIO pin correctly. 195162306a36Sopenharmony_ci */ 195262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, GPIOCSR); 195362306a36Sopenharmony_ci rt2x00_set_field32(®, GPIOCSR_DIR0, 1); 195462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, GPIOCSR, reg); 195562306a36Sopenharmony_ci 195662306a36Sopenharmony_ci /* 195762306a36Sopenharmony_ci * Initialize hw specifications. 195862306a36Sopenharmony_ci */ 195962306a36Sopenharmony_ci retval = rt2500pci_probe_hw_mode(rt2x00dev); 196062306a36Sopenharmony_ci if (retval) 196162306a36Sopenharmony_ci return retval; 196262306a36Sopenharmony_ci 196362306a36Sopenharmony_ci /* 196462306a36Sopenharmony_ci * This device requires the atim queue and DMA-mapped skbs. 196562306a36Sopenharmony_ci */ 196662306a36Sopenharmony_ci __set_bit(REQUIRE_ATIM_QUEUE, &rt2x00dev->cap_flags); 196762306a36Sopenharmony_ci __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags); 196862306a36Sopenharmony_ci __set_bit(REQUIRE_SW_SEQNO, &rt2x00dev->cap_flags); 196962306a36Sopenharmony_ci 197062306a36Sopenharmony_ci /* 197162306a36Sopenharmony_ci * Set the rssi offset. 197262306a36Sopenharmony_ci */ 197362306a36Sopenharmony_ci rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; 197462306a36Sopenharmony_ci 197562306a36Sopenharmony_ci return 0; 197662306a36Sopenharmony_ci} 197762306a36Sopenharmony_ci 197862306a36Sopenharmony_ci/* 197962306a36Sopenharmony_ci * IEEE80211 stack callback functions. 198062306a36Sopenharmony_ci */ 198162306a36Sopenharmony_cistatic u64 rt2500pci_get_tsf(struct ieee80211_hw *hw, 198262306a36Sopenharmony_ci struct ieee80211_vif *vif) 198362306a36Sopenharmony_ci{ 198462306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 198562306a36Sopenharmony_ci u64 tsf; 198662306a36Sopenharmony_ci u32 reg; 198762306a36Sopenharmony_ci 198862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR17); 198962306a36Sopenharmony_ci tsf = (u64) rt2x00_get_field32(reg, CSR17_HIGH_TSFTIMER) << 32; 199062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR16); 199162306a36Sopenharmony_ci tsf |= rt2x00_get_field32(reg, CSR16_LOW_TSFTIMER); 199262306a36Sopenharmony_ci 199362306a36Sopenharmony_ci return tsf; 199462306a36Sopenharmony_ci} 199562306a36Sopenharmony_ci 199662306a36Sopenharmony_cistatic int rt2500pci_tx_last_beacon(struct ieee80211_hw *hw) 199762306a36Sopenharmony_ci{ 199862306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 199962306a36Sopenharmony_ci u32 reg; 200062306a36Sopenharmony_ci 200162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR15); 200262306a36Sopenharmony_ci return rt2x00_get_field32(reg, CSR15_BEACON_SENT); 200362306a36Sopenharmony_ci} 200462306a36Sopenharmony_ci 200562306a36Sopenharmony_cistatic const struct ieee80211_ops rt2500pci_mac80211_ops = { 200662306a36Sopenharmony_ci .tx = rt2x00mac_tx, 200762306a36Sopenharmony_ci .wake_tx_queue = ieee80211_handle_wake_tx_queue, 200862306a36Sopenharmony_ci .start = rt2x00mac_start, 200962306a36Sopenharmony_ci .stop = rt2x00mac_stop, 201062306a36Sopenharmony_ci .add_interface = rt2x00mac_add_interface, 201162306a36Sopenharmony_ci .remove_interface = rt2x00mac_remove_interface, 201262306a36Sopenharmony_ci .config = rt2x00mac_config, 201362306a36Sopenharmony_ci .configure_filter = rt2x00mac_configure_filter, 201462306a36Sopenharmony_ci .sw_scan_start = rt2x00mac_sw_scan_start, 201562306a36Sopenharmony_ci .sw_scan_complete = rt2x00mac_sw_scan_complete, 201662306a36Sopenharmony_ci .get_stats = rt2x00mac_get_stats, 201762306a36Sopenharmony_ci .bss_info_changed = rt2x00mac_bss_info_changed, 201862306a36Sopenharmony_ci .conf_tx = rt2x00mac_conf_tx, 201962306a36Sopenharmony_ci .get_tsf = rt2500pci_get_tsf, 202062306a36Sopenharmony_ci .tx_last_beacon = rt2500pci_tx_last_beacon, 202162306a36Sopenharmony_ci .rfkill_poll = rt2x00mac_rfkill_poll, 202262306a36Sopenharmony_ci .flush = rt2x00mac_flush, 202362306a36Sopenharmony_ci .set_antenna = rt2x00mac_set_antenna, 202462306a36Sopenharmony_ci .get_antenna = rt2x00mac_get_antenna, 202562306a36Sopenharmony_ci .get_ringparam = rt2x00mac_get_ringparam, 202662306a36Sopenharmony_ci .tx_frames_pending = rt2x00mac_tx_frames_pending, 202762306a36Sopenharmony_ci}; 202862306a36Sopenharmony_ci 202962306a36Sopenharmony_cistatic const struct rt2x00lib_ops rt2500pci_rt2x00_ops = { 203062306a36Sopenharmony_ci .irq_handler = rt2500pci_interrupt, 203162306a36Sopenharmony_ci .txstatus_tasklet = rt2500pci_txstatus_tasklet, 203262306a36Sopenharmony_ci .tbtt_tasklet = rt2500pci_tbtt_tasklet, 203362306a36Sopenharmony_ci .rxdone_tasklet = rt2500pci_rxdone_tasklet, 203462306a36Sopenharmony_ci .probe_hw = rt2500pci_probe_hw, 203562306a36Sopenharmony_ci .initialize = rt2x00mmio_initialize, 203662306a36Sopenharmony_ci .uninitialize = rt2x00mmio_uninitialize, 203762306a36Sopenharmony_ci .get_entry_state = rt2500pci_get_entry_state, 203862306a36Sopenharmony_ci .clear_entry = rt2500pci_clear_entry, 203962306a36Sopenharmony_ci .set_device_state = rt2500pci_set_device_state, 204062306a36Sopenharmony_ci .rfkill_poll = rt2500pci_rfkill_poll, 204162306a36Sopenharmony_ci .link_stats = rt2500pci_link_stats, 204262306a36Sopenharmony_ci .reset_tuner = rt2500pci_reset_tuner, 204362306a36Sopenharmony_ci .link_tuner = rt2500pci_link_tuner, 204462306a36Sopenharmony_ci .start_queue = rt2500pci_start_queue, 204562306a36Sopenharmony_ci .kick_queue = rt2500pci_kick_queue, 204662306a36Sopenharmony_ci .stop_queue = rt2500pci_stop_queue, 204762306a36Sopenharmony_ci .flush_queue = rt2x00mmio_flush_queue, 204862306a36Sopenharmony_ci .write_tx_desc = rt2500pci_write_tx_desc, 204962306a36Sopenharmony_ci .write_beacon = rt2500pci_write_beacon, 205062306a36Sopenharmony_ci .fill_rxdone = rt2500pci_fill_rxdone, 205162306a36Sopenharmony_ci .config_filter = rt2500pci_config_filter, 205262306a36Sopenharmony_ci .config_intf = rt2500pci_config_intf, 205362306a36Sopenharmony_ci .config_erp = rt2500pci_config_erp, 205462306a36Sopenharmony_ci .config_ant = rt2500pci_config_ant, 205562306a36Sopenharmony_ci .config = rt2500pci_config, 205662306a36Sopenharmony_ci}; 205762306a36Sopenharmony_ci 205862306a36Sopenharmony_cistatic void rt2500pci_queue_init(struct data_queue *queue) 205962306a36Sopenharmony_ci{ 206062306a36Sopenharmony_ci switch (queue->qid) { 206162306a36Sopenharmony_ci case QID_RX: 206262306a36Sopenharmony_ci queue->limit = 32; 206362306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 206462306a36Sopenharmony_ci queue->desc_size = RXD_DESC_SIZE; 206562306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 206662306a36Sopenharmony_ci break; 206762306a36Sopenharmony_ci 206862306a36Sopenharmony_ci case QID_AC_VO: 206962306a36Sopenharmony_ci case QID_AC_VI: 207062306a36Sopenharmony_ci case QID_AC_BE: 207162306a36Sopenharmony_ci case QID_AC_BK: 207262306a36Sopenharmony_ci queue->limit = 32; 207362306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 207462306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 207562306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 207662306a36Sopenharmony_ci break; 207762306a36Sopenharmony_ci 207862306a36Sopenharmony_ci case QID_BEACON: 207962306a36Sopenharmony_ci queue->limit = 1; 208062306a36Sopenharmony_ci queue->data_size = MGMT_FRAME_SIZE; 208162306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 208262306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 208362306a36Sopenharmony_ci break; 208462306a36Sopenharmony_ci 208562306a36Sopenharmony_ci case QID_ATIM: 208662306a36Sopenharmony_ci queue->limit = 8; 208762306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 208862306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 208962306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 209062306a36Sopenharmony_ci break; 209162306a36Sopenharmony_ci 209262306a36Sopenharmony_ci default: 209362306a36Sopenharmony_ci BUG(); 209462306a36Sopenharmony_ci break; 209562306a36Sopenharmony_ci } 209662306a36Sopenharmony_ci} 209762306a36Sopenharmony_ci 209862306a36Sopenharmony_cistatic const struct rt2x00_ops rt2500pci_ops = { 209962306a36Sopenharmony_ci .name = KBUILD_MODNAME, 210062306a36Sopenharmony_ci .max_ap_intf = 1, 210162306a36Sopenharmony_ci .eeprom_size = EEPROM_SIZE, 210262306a36Sopenharmony_ci .rf_size = RF_SIZE, 210362306a36Sopenharmony_ci .tx_queues = NUM_TX_QUEUES, 210462306a36Sopenharmony_ci .queue_init = rt2500pci_queue_init, 210562306a36Sopenharmony_ci .lib = &rt2500pci_rt2x00_ops, 210662306a36Sopenharmony_ci .hw = &rt2500pci_mac80211_ops, 210762306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS 210862306a36Sopenharmony_ci .debugfs = &rt2500pci_rt2x00debug, 210962306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 211062306a36Sopenharmony_ci}; 211162306a36Sopenharmony_ci 211262306a36Sopenharmony_ci/* 211362306a36Sopenharmony_ci * RT2500pci module information. 211462306a36Sopenharmony_ci */ 211562306a36Sopenharmony_cistatic const struct pci_device_id rt2500pci_device_table[] = { 211662306a36Sopenharmony_ci { PCI_DEVICE(0x1814, 0x0201) }, 211762306a36Sopenharmony_ci { 0, } 211862306a36Sopenharmony_ci}; 211962306a36Sopenharmony_ci 212062306a36Sopenharmony_ciMODULE_AUTHOR(DRV_PROJECT); 212162306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 212262306a36Sopenharmony_ciMODULE_DESCRIPTION("Ralink RT2500 PCI & PCMCIA Wireless LAN driver."); 212362306a36Sopenharmony_ciMODULE_DEVICE_TABLE(pci, rt2500pci_device_table); 212462306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 212562306a36Sopenharmony_ci 212662306a36Sopenharmony_cistatic int rt2500pci_probe(struct pci_dev *pci_dev, 212762306a36Sopenharmony_ci const struct pci_device_id *id) 212862306a36Sopenharmony_ci{ 212962306a36Sopenharmony_ci return rt2x00pci_probe(pci_dev, &rt2500pci_ops); 213062306a36Sopenharmony_ci} 213162306a36Sopenharmony_ci 213262306a36Sopenharmony_cistatic struct pci_driver rt2500pci_driver = { 213362306a36Sopenharmony_ci .name = KBUILD_MODNAME, 213462306a36Sopenharmony_ci .id_table = rt2500pci_device_table, 213562306a36Sopenharmony_ci .probe = rt2500pci_probe, 213662306a36Sopenharmony_ci .remove = rt2x00pci_remove, 213762306a36Sopenharmony_ci .driver.pm = &rt2x00pci_pm_ops, 213862306a36Sopenharmony_ci}; 213962306a36Sopenharmony_ci 214062306a36Sopenharmony_cimodule_pci_driver(rt2500pci_driver); 2141