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: rt2400pci 1062306a36Sopenharmony_ci Abstract: rt2400pci device specific routines. 1162306a36Sopenharmony_ci Supported chipsets: RT2460. 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 "rt2400pci.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 attempt. 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 rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 = rt2400pci_bbp_read, 17862306a36Sopenharmony_ci .write = rt2400pci_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 = rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 rt2400pci_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 = rt2400pci_brightness_set; 24362306a36Sopenharmony_ci led->led_dev.blink_set = rt2400pci_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 rt2400pci_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 * since there is no filter for it at this time. 26062306a36Sopenharmony_ci */ 26162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 26262306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_CRC, 26362306a36Sopenharmony_ci !(filter_flags & FIF_FCSFAIL)); 26462306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_PHYSICAL, 26562306a36Sopenharmony_ci !(filter_flags & FIF_PLCPFAIL)); 26662306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_CONTROL, 26762306a36Sopenharmony_ci !(filter_flags & FIF_CONTROL)); 26862306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_NOT_TO_ME, 26962306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags)); 27062306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_TODS, 27162306a36Sopenharmony_ci !test_bit(CONFIG_MONITORING, &rt2x00dev->flags) && 27262306a36Sopenharmony_ci !rt2x00dev->intf_ap_count); 27362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DROP_VERSION_ERROR, 1); 27462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 27562306a36Sopenharmony_ci} 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_cistatic void rt2400pci_config_intf(struct rt2x00_dev *rt2x00dev, 27862306a36Sopenharmony_ci struct rt2x00_intf *intf, 27962306a36Sopenharmony_ci struct rt2x00intf_conf *conf, 28062306a36Sopenharmony_ci const unsigned int flags) 28162306a36Sopenharmony_ci{ 28262306a36Sopenharmony_ci unsigned int bcn_preload; 28362306a36Sopenharmony_ci u32 reg; 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_TYPE) { 28662306a36Sopenharmony_ci /* 28762306a36Sopenharmony_ci * Enable beacon config 28862306a36Sopenharmony_ci */ 28962306a36Sopenharmony_ci bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20); 29062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, BCNCSR1); 29162306a36Sopenharmony_ci rt2x00_set_field32(®, BCNCSR1_PRELOAD, bcn_preload); 29262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, BCNCSR1, reg); 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci /* 29562306a36Sopenharmony_ci * Enable synchronisation. 29662306a36Sopenharmony_ci */ 29762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 29862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_SYNC, conf->sync); 29962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 30062306a36Sopenharmony_ci } 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_MAC) 30362306a36Sopenharmony_ci rt2x00mmio_register_multiwrite(rt2x00dev, CSR3, 30462306a36Sopenharmony_ci conf->mac, sizeof(conf->mac)); 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci if (flags & CONFIG_UPDATE_BSSID) 30762306a36Sopenharmony_ci rt2x00mmio_register_multiwrite(rt2x00dev, CSR5, 30862306a36Sopenharmony_ci conf->bssid, 30962306a36Sopenharmony_ci sizeof(conf->bssid)); 31062306a36Sopenharmony_ci} 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_cistatic void rt2400pci_config_erp(struct rt2x00_dev *rt2x00dev, 31362306a36Sopenharmony_ci struct rt2x00lib_erp *erp, 31462306a36Sopenharmony_ci u32 changed) 31562306a36Sopenharmony_ci{ 31662306a36Sopenharmony_ci int preamble_mask; 31762306a36Sopenharmony_ci u32 reg; 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci /* 32062306a36Sopenharmony_ci * When short preamble is enabled, we should set bit 0x08 32162306a36Sopenharmony_ci */ 32262306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_PREAMBLE) { 32362306a36Sopenharmony_ci preamble_mask = erp->short_preamble << 3; 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR1); 32662306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_ACK_TIMEOUT, 0x1ff); 32762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_ACK_CONSUME_TIME, 0x13a); 32862306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_TSF_OFFSET, IEEE80211_HEADER); 32962306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR1_AUTORESPONDER, 1); 33062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR1, reg); 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR2); 33362306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_SIGNAL, 0x00); 33462306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_SERVICE, 0x04); 33562306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 33662306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 10)); 33762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR2, reg); 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR3); 34062306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR3_SIGNAL, 0x01 | preamble_mask); 34162306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR3_SERVICE, 0x04); 34262306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 34362306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 20)); 34462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR3, reg); 34562306a36Sopenharmony_ci 34662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR4); 34762306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR4_SIGNAL, 0x02 | preamble_mask); 34862306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR4_SERVICE, 0x04); 34962306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 35062306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 55)); 35162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR4, reg); 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR5); 35462306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR5_SIGNAL, 0x03 | preamble_mask); 35562306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR5_SERVICE, 0x84); 35662306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR2_LENGTH, 35762306a36Sopenharmony_ci GET_DURATION(ACK_SIZE, 110)); 35862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR5, reg); 35962306a36Sopenharmony_ci } 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ci if (changed & BSS_CHANGED_BASIC_RATES) 36262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR1, erp->basic_rates); 36362306a36Sopenharmony_ci 36462306a36Sopenharmony_ci if (changed & BSS_CHANGED_ERP_SLOT) { 36562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 36662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_SLOT_TIME, erp->slot_time); 36762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR18); 37062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR18_SIFS, erp->sifs); 37162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR18_PIFS, erp->pifs); 37262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR18, reg); 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR19); 37562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR19_DIFS, erp->difs); 37662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR19_EIFS, erp->eifs); 37762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR19, reg); 37862306a36Sopenharmony_ci } 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci if (changed & BSS_CHANGED_BEACON_INT) { 38162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR12); 38262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR12_BEACON_INTERVAL, 38362306a36Sopenharmony_ci erp->beacon_int * 16); 38462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR12_CFP_MAX_DURATION, 38562306a36Sopenharmony_ci erp->beacon_int * 16); 38662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR12, reg); 38762306a36Sopenharmony_ci } 38862306a36Sopenharmony_ci} 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_cistatic void rt2400pci_config_ant(struct rt2x00_dev *rt2x00dev, 39162306a36Sopenharmony_ci struct antenna_setup *ant) 39262306a36Sopenharmony_ci{ 39362306a36Sopenharmony_ci u8 r1; 39462306a36Sopenharmony_ci u8 r4; 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci /* 39762306a36Sopenharmony_ci * We should never come here because rt2x00lib is supposed 39862306a36Sopenharmony_ci * to catch this and send us the correct antenna explicitely. 39962306a36Sopenharmony_ci */ 40062306a36Sopenharmony_ci BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY || 40162306a36Sopenharmony_ci ant->tx == ANTENNA_SW_DIVERSITY); 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci r4 = rt2400pci_bbp_read(rt2x00dev, 4); 40462306a36Sopenharmony_ci r1 = rt2400pci_bbp_read(rt2x00dev, 1); 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ci /* 40762306a36Sopenharmony_ci * Configure the TX antenna. 40862306a36Sopenharmony_ci */ 40962306a36Sopenharmony_ci switch (ant->tx) { 41062306a36Sopenharmony_ci case ANTENNA_HW_DIVERSITY: 41162306a36Sopenharmony_ci rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1); 41262306a36Sopenharmony_ci break; 41362306a36Sopenharmony_ci case ANTENNA_A: 41462306a36Sopenharmony_ci rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0); 41562306a36Sopenharmony_ci break; 41662306a36Sopenharmony_ci case ANTENNA_B: 41762306a36Sopenharmony_ci default: 41862306a36Sopenharmony_ci rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 2); 41962306a36Sopenharmony_ci break; 42062306a36Sopenharmony_ci } 42162306a36Sopenharmony_ci 42262306a36Sopenharmony_ci /* 42362306a36Sopenharmony_ci * Configure the RX antenna. 42462306a36Sopenharmony_ci */ 42562306a36Sopenharmony_ci switch (ant->rx) { 42662306a36Sopenharmony_ci case ANTENNA_HW_DIVERSITY: 42762306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1); 42862306a36Sopenharmony_ci break; 42962306a36Sopenharmony_ci case ANTENNA_A: 43062306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 0); 43162306a36Sopenharmony_ci break; 43262306a36Sopenharmony_ci case ANTENNA_B: 43362306a36Sopenharmony_ci default: 43462306a36Sopenharmony_ci rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2); 43562306a36Sopenharmony_ci break; 43662306a36Sopenharmony_ci } 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 4, r4); 43962306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 1, r1); 44062306a36Sopenharmony_ci} 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_cistatic void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev, 44362306a36Sopenharmony_ci struct rf_channel *rf) 44462306a36Sopenharmony_ci{ 44562306a36Sopenharmony_ci /* 44662306a36Sopenharmony_ci * Switch on tuning bits. 44762306a36Sopenharmony_ci */ 44862306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf1, RF1_TUNER, 1); 44962306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TUNER, 1); 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); 45262306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 2, rf->rf2); 45362306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci /* 45662306a36Sopenharmony_ci * RF2420 chipset don't need any additional actions. 45762306a36Sopenharmony_ci */ 45862306a36Sopenharmony_ci if (rt2x00_rf(rt2x00dev, RF2420)) 45962306a36Sopenharmony_ci return; 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_ci /* 46262306a36Sopenharmony_ci * For the RT2421 chipsets we need to write an invalid 46362306a36Sopenharmony_ci * reference clock rate to activate auto_tune. 46462306a36Sopenharmony_ci * After that we set the value back to the correct channel. 46562306a36Sopenharmony_ci */ 46662306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); 46762306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 2, 0x000c2a32); 46862306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci msleep(1); 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); 47362306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 2, rf->rf2); 47462306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_ci msleep(1); 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci /* 47962306a36Sopenharmony_ci * Switch off tuning bits. 48062306a36Sopenharmony_ci */ 48162306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf1, RF1_TUNER, 0); 48262306a36Sopenharmony_ci rt2x00_set_field32(&rf->rf3, RF3_TUNER, 0); 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 1, rf->rf1); 48562306a36Sopenharmony_ci rt2400pci_rf_write(rt2x00dev, 3, rf->rf3); 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci /* 48862306a36Sopenharmony_ci * Clear false CRC during channel switch. 48962306a36Sopenharmony_ci */ 49062306a36Sopenharmony_ci rf->rf1 = rt2x00mmio_register_read(rt2x00dev, CNT0); 49162306a36Sopenharmony_ci} 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_cistatic void rt2400pci_config_txpower(struct rt2x00_dev *rt2x00dev, int txpower) 49462306a36Sopenharmony_ci{ 49562306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower)); 49662306a36Sopenharmony_ci} 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_cistatic void rt2400pci_config_retry_limit(struct rt2x00_dev *rt2x00dev, 49962306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 50062306a36Sopenharmony_ci{ 50162306a36Sopenharmony_ci u32 reg; 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 50462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_LONG_RETRY, 50562306a36Sopenharmony_ci libconf->conf->long_frame_max_tx_count); 50662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_SHORT_RETRY, 50762306a36Sopenharmony_ci libconf->conf->short_frame_max_tx_count); 50862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 50962306a36Sopenharmony_ci} 51062306a36Sopenharmony_ci 51162306a36Sopenharmony_cistatic void rt2400pci_config_ps(struct rt2x00_dev *rt2x00dev, 51262306a36Sopenharmony_ci struct rt2x00lib_conf *libconf) 51362306a36Sopenharmony_ci{ 51462306a36Sopenharmony_ci enum dev_state state = 51562306a36Sopenharmony_ci (libconf->conf->flags & IEEE80211_CONF_PS) ? 51662306a36Sopenharmony_ci STATE_SLEEP : STATE_AWAKE; 51762306a36Sopenharmony_ci u32 reg; 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci if (state == STATE_SLEEP) { 52062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR20); 52162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_DELAY_AFTER_TBCN, 52262306a36Sopenharmony_ci (rt2x00dev->beacon_int - 20) * 16); 52362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_TBCN_BEFORE_WAKEUP, 52462306a36Sopenharmony_ci libconf->conf->listen_interval - 1); 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_ci /* We must first disable autowake before it can be enabled */ 52762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 0); 52862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 1); 53162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 53262306a36Sopenharmony_ci } else { 53362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR20); 53462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR20_AUTOWAKE, 0); 53562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR20, reg); 53662306a36Sopenharmony_ci } 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_ci rt2x00dev->ops->lib->set_device_state(rt2x00dev, state); 53962306a36Sopenharmony_ci} 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_cistatic void rt2400pci_config(struct rt2x00_dev *rt2x00dev, 54262306a36Sopenharmony_ci struct rt2x00lib_conf *libconf, 54362306a36Sopenharmony_ci const unsigned int flags) 54462306a36Sopenharmony_ci{ 54562306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_CHANNEL) 54662306a36Sopenharmony_ci rt2400pci_config_channel(rt2x00dev, &libconf->rf); 54762306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_POWER) 54862306a36Sopenharmony_ci rt2400pci_config_txpower(rt2x00dev, 54962306a36Sopenharmony_ci libconf->conf->power_level); 55062306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS) 55162306a36Sopenharmony_ci rt2400pci_config_retry_limit(rt2x00dev, libconf); 55262306a36Sopenharmony_ci if (flags & IEEE80211_CONF_CHANGE_PS) 55362306a36Sopenharmony_ci rt2400pci_config_ps(rt2x00dev, libconf); 55462306a36Sopenharmony_ci} 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_cistatic void rt2400pci_config_cw(struct rt2x00_dev *rt2x00dev, 55762306a36Sopenharmony_ci const int cw_min, const int cw_max) 55862306a36Sopenharmony_ci{ 55962306a36Sopenharmony_ci u32 reg; 56062306a36Sopenharmony_ci 56162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR11); 56262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_CWMIN, cw_min); 56362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR11_CWMAX, cw_max); 56462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR11, reg); 56562306a36Sopenharmony_ci} 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci/* 56862306a36Sopenharmony_ci * Link tuning 56962306a36Sopenharmony_ci */ 57062306a36Sopenharmony_cistatic void rt2400pci_link_stats(struct rt2x00_dev *rt2x00dev, 57162306a36Sopenharmony_ci struct link_qual *qual) 57262306a36Sopenharmony_ci{ 57362306a36Sopenharmony_ci u32 reg; 57462306a36Sopenharmony_ci u8 bbp; 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci /* 57762306a36Sopenharmony_ci * Update FCS error count from register. 57862306a36Sopenharmony_ci */ 57962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT0); 58062306a36Sopenharmony_ci qual->rx_failed = rt2x00_get_field32(reg, CNT0_FCS_ERROR); 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci /* 58362306a36Sopenharmony_ci * Update False CCA count from register. 58462306a36Sopenharmony_ci */ 58562306a36Sopenharmony_ci bbp = rt2400pci_bbp_read(rt2x00dev, 39); 58662306a36Sopenharmony_ci qual->false_cca = bbp; 58762306a36Sopenharmony_ci} 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_cistatic inline void rt2400pci_set_vgc(struct rt2x00_dev *rt2x00dev, 59062306a36Sopenharmony_ci struct link_qual *qual, u8 vgc_level) 59162306a36Sopenharmony_ci{ 59262306a36Sopenharmony_ci if (qual->vgc_level_reg != vgc_level) { 59362306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 13, vgc_level); 59462306a36Sopenharmony_ci qual->vgc_level = vgc_level; 59562306a36Sopenharmony_ci qual->vgc_level_reg = vgc_level; 59662306a36Sopenharmony_ci } 59762306a36Sopenharmony_ci} 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_cistatic void rt2400pci_reset_tuner(struct rt2x00_dev *rt2x00dev, 60062306a36Sopenharmony_ci struct link_qual *qual) 60162306a36Sopenharmony_ci{ 60262306a36Sopenharmony_ci rt2400pci_set_vgc(rt2x00dev, qual, 0x08); 60362306a36Sopenharmony_ci} 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_cistatic void rt2400pci_link_tuner(struct rt2x00_dev *rt2x00dev, 60662306a36Sopenharmony_ci struct link_qual *qual, const u32 count) 60762306a36Sopenharmony_ci{ 60862306a36Sopenharmony_ci /* 60962306a36Sopenharmony_ci * The link tuner should not run longer then 60 seconds, 61062306a36Sopenharmony_ci * and should run once every 2 seconds. 61162306a36Sopenharmony_ci */ 61262306a36Sopenharmony_ci if (count > 60 || !(count & 1)) 61362306a36Sopenharmony_ci return; 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci /* 61662306a36Sopenharmony_ci * Base r13 link tuning on the false cca count. 61762306a36Sopenharmony_ci */ 61862306a36Sopenharmony_ci if ((qual->false_cca > 512) && (qual->vgc_level < 0x20)) 61962306a36Sopenharmony_ci rt2400pci_set_vgc(rt2x00dev, qual, ++qual->vgc_level); 62062306a36Sopenharmony_ci else if ((qual->false_cca < 100) && (qual->vgc_level > 0x08)) 62162306a36Sopenharmony_ci rt2400pci_set_vgc(rt2x00dev, qual, --qual->vgc_level); 62262306a36Sopenharmony_ci} 62362306a36Sopenharmony_ci 62462306a36Sopenharmony_ci/* 62562306a36Sopenharmony_ci * Queue handlers. 62662306a36Sopenharmony_ci */ 62762306a36Sopenharmony_cistatic void rt2400pci_start_queue(struct data_queue *queue) 62862306a36Sopenharmony_ci{ 62962306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 63062306a36Sopenharmony_ci u32 reg; 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci switch (queue->qid) { 63362306a36Sopenharmony_ci case QID_RX: 63462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 63562306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DISABLE_RX, 0); 63662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 63762306a36Sopenharmony_ci break; 63862306a36Sopenharmony_ci case QID_BEACON: 63962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 64062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 1); 64162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 1); 64262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 1); 64362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 64462306a36Sopenharmony_ci break; 64562306a36Sopenharmony_ci default: 64662306a36Sopenharmony_ci break; 64762306a36Sopenharmony_ci } 64862306a36Sopenharmony_ci} 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_cistatic void rt2400pci_kick_queue(struct data_queue *queue) 65162306a36Sopenharmony_ci{ 65262306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 65362306a36Sopenharmony_ci u32 reg; 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci switch (queue->qid) { 65662306a36Sopenharmony_ci case QID_AC_VO: 65762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 65862306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_PRIO, 1); 65962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 66062306a36Sopenharmony_ci break; 66162306a36Sopenharmony_ci case QID_AC_VI: 66262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 66362306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_TX, 1); 66462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 66562306a36Sopenharmony_ci break; 66662306a36Sopenharmony_ci case QID_ATIM: 66762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 66862306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_KICK_ATIM, 1); 66962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 67062306a36Sopenharmony_ci break; 67162306a36Sopenharmony_ci default: 67262306a36Sopenharmony_ci break; 67362306a36Sopenharmony_ci } 67462306a36Sopenharmony_ci} 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_cistatic void rt2400pci_stop_queue(struct data_queue *queue) 67762306a36Sopenharmony_ci{ 67862306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; 67962306a36Sopenharmony_ci u32 reg; 68062306a36Sopenharmony_ci 68162306a36Sopenharmony_ci switch (queue->qid) { 68262306a36Sopenharmony_ci case QID_AC_VO: 68362306a36Sopenharmony_ci case QID_AC_VI: 68462306a36Sopenharmony_ci case QID_ATIM: 68562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR0); 68662306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR0_ABORT, 1); 68762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR0, reg); 68862306a36Sopenharmony_ci break; 68962306a36Sopenharmony_ci case QID_RX: 69062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR0); 69162306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR0_DISABLE_RX, 1); 69262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR0, reg); 69362306a36Sopenharmony_ci break; 69462306a36Sopenharmony_ci case QID_BEACON: 69562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 69662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 0); 69762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 0); 69862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 69962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci /* 70262306a36Sopenharmony_ci * Wait for possibly running tbtt tasklets. 70362306a36Sopenharmony_ci */ 70462306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->tbtt_tasklet); 70562306a36Sopenharmony_ci break; 70662306a36Sopenharmony_ci default: 70762306a36Sopenharmony_ci break; 70862306a36Sopenharmony_ci } 70962306a36Sopenharmony_ci} 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/* 71262306a36Sopenharmony_ci * Initialization functions. 71362306a36Sopenharmony_ci */ 71462306a36Sopenharmony_cistatic bool rt2400pci_get_entry_state(struct queue_entry *entry) 71562306a36Sopenharmony_ci{ 71662306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 71762306a36Sopenharmony_ci u32 word; 71862306a36Sopenharmony_ci 71962306a36Sopenharmony_ci if (entry->queue->qid == QID_RX) { 72062306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_ci return rt2x00_get_field32(word, RXD_W0_OWNER_NIC); 72362306a36Sopenharmony_ci } else { 72462306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci return (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) || 72762306a36Sopenharmony_ci rt2x00_get_field32(word, TXD_W0_VALID)); 72862306a36Sopenharmony_ci } 72962306a36Sopenharmony_ci} 73062306a36Sopenharmony_ci 73162306a36Sopenharmony_cistatic void rt2400pci_clear_entry(struct queue_entry *entry) 73262306a36Sopenharmony_ci{ 73362306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 73462306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 73562306a36Sopenharmony_ci u32 word; 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci if (entry->queue->qid == QID_RX) { 73862306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 2); 73962306a36Sopenharmony_ci rt2x00_set_field32(&word, RXD_W2_BUFFER_LENGTH, entry->skb->len); 74062306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 2, word); 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 1); 74362306a36Sopenharmony_ci rt2x00_set_field32(&word, RXD_W1_BUFFER_ADDRESS, skbdesc->skb_dma); 74462306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 1, word); 74562306a36Sopenharmony_ci 74662306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 74762306a36Sopenharmony_ci rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1); 74862306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 0, word); 74962306a36Sopenharmony_ci } else { 75062306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 75162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_VALID, 0); 75262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0); 75362306a36Sopenharmony_ci rt2x00_desc_write(entry_priv->desc, 0, word); 75462306a36Sopenharmony_ci } 75562306a36Sopenharmony_ci} 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_cistatic int rt2400pci_init_queues(struct rt2x00_dev *rt2x00dev) 75862306a36Sopenharmony_ci{ 75962306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv; 76062306a36Sopenharmony_ci u32 reg; 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci /* 76362306a36Sopenharmony_ci * Initialize registers. 76462306a36Sopenharmony_ci */ 76562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR2); 76662306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_TXD_SIZE, rt2x00dev->tx[0].desc_size); 76762306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_TXD, rt2x00dev->tx[1].limit); 76862306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_ATIM, rt2x00dev->atim->limit); 76962306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR2_NUM_PRIO, rt2x00dev->tx[0].limit); 77062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR2, reg); 77162306a36Sopenharmony_ci 77262306a36Sopenharmony_ci entry_priv = rt2x00dev->tx[1].entries[0].priv_data; 77362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR3); 77462306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR3_TX_RING_REGISTER, 77562306a36Sopenharmony_ci entry_priv->desc_dma); 77662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR3, reg); 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_ci entry_priv = rt2x00dev->tx[0].entries[0].priv_data; 77962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR5); 78062306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR5_PRIO_RING_REGISTER, 78162306a36Sopenharmony_ci entry_priv->desc_dma); 78262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR5, reg); 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ci entry_priv = rt2x00dev->atim->entries[0].priv_data; 78562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR4); 78662306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR4_ATIM_RING_REGISTER, 78762306a36Sopenharmony_ci entry_priv->desc_dma); 78862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR4, reg); 78962306a36Sopenharmony_ci 79062306a36Sopenharmony_ci entry_priv = rt2x00dev->bcn->entries[0].priv_data; 79162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TXCSR6); 79262306a36Sopenharmony_ci rt2x00_set_field32(®, TXCSR6_BEACON_RING_REGISTER, 79362306a36Sopenharmony_ci entry_priv->desc_dma); 79462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TXCSR6, reg); 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR1); 79762306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR1_RXD_SIZE, rt2x00dev->rx->desc_size); 79862306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR1_NUM_RXD, rt2x00dev->rx->limit); 79962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR1, reg); 80062306a36Sopenharmony_ci 80162306a36Sopenharmony_ci entry_priv = rt2x00dev->rx->entries[0].priv_data; 80262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR2); 80362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR2_RX_RING_REGISTER, 80462306a36Sopenharmony_ci entry_priv->desc_dma); 80562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR2, reg); 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci return 0; 80862306a36Sopenharmony_ci} 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_cistatic int rt2400pci_init_registers(struct rt2x00_dev *rt2x00dev) 81162306a36Sopenharmony_ci{ 81262306a36Sopenharmony_ci u32 reg; 81362306a36Sopenharmony_ci 81462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR0, 0x00020002); 81562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR1, 0x00000002); 81662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR2, 0x00023f20); 81762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PSCSR3, 0x00000002); 81862306a36Sopenharmony_ci 81962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, TIMECSR); 82062306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_US_COUNT, 33); 82162306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_US_64_COUNT, 63); 82262306a36Sopenharmony_ci rt2x00_set_field32(®, TIMECSR_BEACON_EXPECT, 0); 82362306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, TIMECSR, reg); 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR9); 82662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR9_MAX_FRAME_UNIT, 82762306a36Sopenharmony_ci (rt2x00dev->rx->data_size / 128)); 82862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR9, reg); 82962306a36Sopenharmony_ci 83062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 83162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_COUNT, 0); 83262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TSF_SYNC, 0); 83362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCN, 0); 83462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TCFP, 0); 83562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TATIMW, 0); 83662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 83762306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_CFP_COUNT_PRELOAD, 0); 83862306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_TBCM_PRELOAD, 0); 83962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 84062306a36Sopenharmony_ci 84162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CNT3, 0x3f080000); 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, ARCSR0); 84462306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR0_AR_BBP_DATA0, 133); 84562306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR0_AR_BBP_ID0, 134); 84662306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR0_AR_BBP_DATA1, 136); 84762306a36Sopenharmony_ci rt2x00_set_field32(®, ARCSR0_AR_BBP_ID1, 135); 84862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, ARCSR0, reg); 84962306a36Sopenharmony_ci 85062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RXCSR3); 85162306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID0, 3); /* Tx power.*/ 85262306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID0_VALID, 1); 85362306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID1, 32); /* Signal */ 85462306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID1_VALID, 1); 85562306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID2, 36); /* Rssi */ 85662306a36Sopenharmony_ci rt2x00_set_field32(®, RXCSR3_BBP_ID2_VALID, 1); 85762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RXCSR3, reg); 85862306a36Sopenharmony_ci 85962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR0, 0x3f3b3100); 86062306a36Sopenharmony_ci 86162306a36Sopenharmony_ci if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE)) 86262306a36Sopenharmony_ci return -EBUSY; 86362306a36Sopenharmony_ci 86462306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR0, 0x00217223); 86562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR1, 0x00235518); 86662306a36Sopenharmony_ci 86762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, MACCSR2); 86862306a36Sopenharmony_ci rt2x00_set_field32(®, MACCSR2_DELAY, 64); 86962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, MACCSR2, reg); 87062306a36Sopenharmony_ci 87162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, RALINKCSR); 87262306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA0, 17); 87362306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID0, 154); 87462306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA1, 0); 87562306a36Sopenharmony_ci rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID1, 154); 87662306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, RALINKCSR, reg); 87762306a36Sopenharmony_ci 87862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR1); 87962306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_SOFT_RESET, 1); 88062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_BBP_RESET, 0); 88162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_HOST_READY, 0); 88262306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR1, reg); 88362306a36Sopenharmony_ci 88462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR1); 88562306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_SOFT_RESET, 0); 88662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR1_HOST_READY, 1); 88762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR1, reg); 88862306a36Sopenharmony_ci 88962306a36Sopenharmony_ci /* 89062306a36Sopenharmony_ci * We must clear the FCS and FIFO error count. 89162306a36Sopenharmony_ci * These registers are cleared on read, 89262306a36Sopenharmony_ci * so we may pass a useless variable to store the value. 89362306a36Sopenharmony_ci */ 89462306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT0); 89562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CNT4); 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ci return 0; 89862306a36Sopenharmony_ci} 89962306a36Sopenharmony_ci 90062306a36Sopenharmony_cistatic int rt2400pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev) 90162306a36Sopenharmony_ci{ 90262306a36Sopenharmony_ci unsigned int i; 90362306a36Sopenharmony_ci u8 value; 90462306a36Sopenharmony_ci 90562306a36Sopenharmony_ci for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 90662306a36Sopenharmony_ci value = rt2400pci_bbp_read(rt2x00dev, 0); 90762306a36Sopenharmony_ci if ((value != 0xff) && (value != 0x00)) 90862306a36Sopenharmony_ci return 0; 90962306a36Sopenharmony_ci udelay(REGISTER_BUSY_DELAY); 91062306a36Sopenharmony_ci } 91162306a36Sopenharmony_ci 91262306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n"); 91362306a36Sopenharmony_ci return -EACCES; 91462306a36Sopenharmony_ci} 91562306a36Sopenharmony_ci 91662306a36Sopenharmony_cistatic int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev) 91762306a36Sopenharmony_ci{ 91862306a36Sopenharmony_ci unsigned int i; 91962306a36Sopenharmony_ci u16 eeprom; 92062306a36Sopenharmony_ci u8 reg_id; 92162306a36Sopenharmony_ci u8 value; 92262306a36Sopenharmony_ci 92362306a36Sopenharmony_ci if (unlikely(rt2400pci_wait_bbp_ready(rt2x00dev))) 92462306a36Sopenharmony_ci return -EACCES; 92562306a36Sopenharmony_ci 92662306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 1, 0x00); 92762306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 3, 0x27); 92862306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 4, 0x08); 92962306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 10, 0x0f); 93062306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 15, 0x72); 93162306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 16, 0x74); 93262306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 17, 0x20); 93362306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 18, 0x72); 93462306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 19, 0x0b); 93562306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 20, 0x00); 93662306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 28, 0x11); 93762306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 29, 0x04); 93862306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 30, 0x21); 93962306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, 31, 0x00); 94062306a36Sopenharmony_ci 94162306a36Sopenharmony_ci for (i = 0; i < EEPROM_BBP_SIZE; i++) { 94262306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i); 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ci if (eeprom != 0xffff && eeprom != 0x0000) { 94562306a36Sopenharmony_ci reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID); 94662306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE); 94762306a36Sopenharmony_ci rt2400pci_bbp_write(rt2x00dev, reg_id, value); 94862306a36Sopenharmony_ci } 94962306a36Sopenharmony_ci } 95062306a36Sopenharmony_ci 95162306a36Sopenharmony_ci return 0; 95262306a36Sopenharmony_ci} 95362306a36Sopenharmony_ci 95462306a36Sopenharmony_ci/* 95562306a36Sopenharmony_ci * Device state switch handlers. 95662306a36Sopenharmony_ci */ 95762306a36Sopenharmony_cistatic void rt2400pci_toggle_irq(struct rt2x00_dev *rt2x00dev, 95862306a36Sopenharmony_ci enum dev_state state) 95962306a36Sopenharmony_ci{ 96062306a36Sopenharmony_ci int mask = (state == STATE_RADIO_IRQ_OFF); 96162306a36Sopenharmony_ci u32 reg; 96262306a36Sopenharmony_ci unsigned long flags; 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_ci /* 96562306a36Sopenharmony_ci * When interrupts are being enabled, the interrupt registers 96662306a36Sopenharmony_ci * should clear the register to assure a clean state. 96762306a36Sopenharmony_ci */ 96862306a36Sopenharmony_ci if (state == STATE_RADIO_IRQ_ON) { 96962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR7); 97062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR7, reg); 97162306a36Sopenharmony_ci } 97262306a36Sopenharmony_ci 97362306a36Sopenharmony_ci /* 97462306a36Sopenharmony_ci * Only toggle the interrupts bits we are going to use. 97562306a36Sopenharmony_ci * Non-checked interrupt bits are disabled by default. 97662306a36Sopenharmony_ci */ 97762306a36Sopenharmony_ci spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags); 97862306a36Sopenharmony_ci 97962306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 98062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TBCN_EXPIRE, mask); 98162306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_TXRING, mask); 98262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_ATIMRING, mask); 98362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_PRIORING, mask); 98462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_RXDONE, mask); 98562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 98662306a36Sopenharmony_ci 98762306a36Sopenharmony_ci spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags); 98862306a36Sopenharmony_ci 98962306a36Sopenharmony_ci if (state == STATE_RADIO_IRQ_OFF) { 99062306a36Sopenharmony_ci /* 99162306a36Sopenharmony_ci * Ensure that all tasklets are finished before 99262306a36Sopenharmony_ci * disabling the interrupts. 99362306a36Sopenharmony_ci */ 99462306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->txstatus_tasklet); 99562306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->rxdone_tasklet); 99662306a36Sopenharmony_ci tasklet_kill(&rt2x00dev->tbtt_tasklet); 99762306a36Sopenharmony_ci } 99862306a36Sopenharmony_ci} 99962306a36Sopenharmony_ci 100062306a36Sopenharmony_cistatic int rt2400pci_enable_radio(struct rt2x00_dev *rt2x00dev) 100162306a36Sopenharmony_ci{ 100262306a36Sopenharmony_ci /* 100362306a36Sopenharmony_ci * Initialize all registers. 100462306a36Sopenharmony_ci */ 100562306a36Sopenharmony_ci if (unlikely(rt2400pci_init_queues(rt2x00dev) || 100662306a36Sopenharmony_ci rt2400pci_init_registers(rt2x00dev) || 100762306a36Sopenharmony_ci rt2400pci_init_bbp(rt2x00dev))) 100862306a36Sopenharmony_ci return -EIO; 100962306a36Sopenharmony_ci 101062306a36Sopenharmony_ci return 0; 101162306a36Sopenharmony_ci} 101262306a36Sopenharmony_ci 101362306a36Sopenharmony_cistatic void rt2400pci_disable_radio(struct rt2x00_dev *rt2x00dev) 101462306a36Sopenharmony_ci{ 101562306a36Sopenharmony_ci /* 101662306a36Sopenharmony_ci * Disable power 101762306a36Sopenharmony_ci */ 101862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR0, 0); 101962306a36Sopenharmony_ci} 102062306a36Sopenharmony_ci 102162306a36Sopenharmony_cistatic int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev, 102262306a36Sopenharmony_ci enum dev_state state) 102362306a36Sopenharmony_ci{ 102462306a36Sopenharmony_ci u32 reg, reg2; 102562306a36Sopenharmony_ci unsigned int i; 102662306a36Sopenharmony_ci bool put_to_sleep; 102762306a36Sopenharmony_ci u8 bbp_state; 102862306a36Sopenharmony_ci u8 rf_state; 102962306a36Sopenharmony_ci 103062306a36Sopenharmony_ci put_to_sleep = (state != STATE_AWAKE); 103162306a36Sopenharmony_ci 103262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, PWRCSR1); 103362306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_SET_STATE, 1); 103462306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_BBP_DESIRE_STATE, state); 103562306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_RF_DESIRE_STATE, state); 103662306a36Sopenharmony_ci rt2x00_set_field32(®, PWRCSR1_PUT_TO_SLEEP, put_to_sleep); 103762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR1, reg); 103862306a36Sopenharmony_ci 103962306a36Sopenharmony_ci /* 104062306a36Sopenharmony_ci * Device is not guaranteed to be in the requested state yet. 104162306a36Sopenharmony_ci * We must wait until the register indicates that the 104262306a36Sopenharmony_ci * device has entered the correct state. 104362306a36Sopenharmony_ci */ 104462306a36Sopenharmony_ci for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 104562306a36Sopenharmony_ci reg2 = rt2x00mmio_register_read(rt2x00dev, PWRCSR1); 104662306a36Sopenharmony_ci bbp_state = rt2x00_get_field32(reg2, PWRCSR1_BBP_CURR_STATE); 104762306a36Sopenharmony_ci rf_state = rt2x00_get_field32(reg2, PWRCSR1_RF_CURR_STATE); 104862306a36Sopenharmony_ci if (bbp_state == state && rf_state == state) 104962306a36Sopenharmony_ci return 0; 105062306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, PWRCSR1, reg); 105162306a36Sopenharmony_ci msleep(10); 105262306a36Sopenharmony_ci } 105362306a36Sopenharmony_ci 105462306a36Sopenharmony_ci return -EBUSY; 105562306a36Sopenharmony_ci} 105662306a36Sopenharmony_ci 105762306a36Sopenharmony_cistatic int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev, 105862306a36Sopenharmony_ci enum dev_state state) 105962306a36Sopenharmony_ci{ 106062306a36Sopenharmony_ci int retval = 0; 106162306a36Sopenharmony_ci 106262306a36Sopenharmony_ci switch (state) { 106362306a36Sopenharmony_ci case STATE_RADIO_ON: 106462306a36Sopenharmony_ci retval = rt2400pci_enable_radio(rt2x00dev); 106562306a36Sopenharmony_ci break; 106662306a36Sopenharmony_ci case STATE_RADIO_OFF: 106762306a36Sopenharmony_ci rt2400pci_disable_radio(rt2x00dev); 106862306a36Sopenharmony_ci break; 106962306a36Sopenharmony_ci case STATE_RADIO_IRQ_ON: 107062306a36Sopenharmony_ci case STATE_RADIO_IRQ_OFF: 107162306a36Sopenharmony_ci rt2400pci_toggle_irq(rt2x00dev, state); 107262306a36Sopenharmony_ci break; 107362306a36Sopenharmony_ci case STATE_DEEP_SLEEP: 107462306a36Sopenharmony_ci case STATE_SLEEP: 107562306a36Sopenharmony_ci case STATE_STANDBY: 107662306a36Sopenharmony_ci case STATE_AWAKE: 107762306a36Sopenharmony_ci retval = rt2400pci_set_state(rt2x00dev, state); 107862306a36Sopenharmony_ci break; 107962306a36Sopenharmony_ci default: 108062306a36Sopenharmony_ci retval = -ENOTSUPP; 108162306a36Sopenharmony_ci break; 108262306a36Sopenharmony_ci } 108362306a36Sopenharmony_ci 108462306a36Sopenharmony_ci if (unlikely(retval)) 108562306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n", 108662306a36Sopenharmony_ci state, retval); 108762306a36Sopenharmony_ci 108862306a36Sopenharmony_ci return retval; 108962306a36Sopenharmony_ci} 109062306a36Sopenharmony_ci 109162306a36Sopenharmony_ci/* 109262306a36Sopenharmony_ci * TX descriptor initialization 109362306a36Sopenharmony_ci */ 109462306a36Sopenharmony_cistatic void rt2400pci_write_tx_desc(struct queue_entry *entry, 109562306a36Sopenharmony_ci struct txentry_desc *txdesc) 109662306a36Sopenharmony_ci{ 109762306a36Sopenharmony_ci struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); 109862306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 109962306a36Sopenharmony_ci __le32 *txd = entry_priv->desc; 110062306a36Sopenharmony_ci u32 word; 110162306a36Sopenharmony_ci 110262306a36Sopenharmony_ci /* 110362306a36Sopenharmony_ci * Start writing the descriptor words. 110462306a36Sopenharmony_ci */ 110562306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 1); 110662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W1_BUFFER_ADDRESS, skbdesc->skb_dma); 110762306a36Sopenharmony_ci rt2x00_desc_write(txd, 1, word); 110862306a36Sopenharmony_ci 110962306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 2); 111062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_BUFFER_LENGTH, txdesc->length); 111162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W2_DATABYTE_COUNT, txdesc->length); 111262306a36Sopenharmony_ci rt2x00_desc_write(txd, 2, word); 111362306a36Sopenharmony_ci 111462306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 3); 111562306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL, txdesc->u.plcp.signal); 111662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL_REGNUM, 5); 111762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL_BUSY, 1); 111862306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE, txdesc->u.plcp.service); 111962306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE_REGNUM, 6); 112062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE_BUSY, 1); 112162306a36Sopenharmony_ci rt2x00_desc_write(txd, 3, word); 112262306a36Sopenharmony_ci 112362306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 4); 112462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_LOW, 112562306a36Sopenharmony_ci txdesc->u.plcp.length_low); 112662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_LOW_REGNUM, 8); 112762306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_LOW_BUSY, 1); 112862306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_HIGH, 112962306a36Sopenharmony_ci txdesc->u.plcp.length_high); 113062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_HIGH_REGNUM, 7); 113162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W3_PLCP_LENGTH_HIGH_BUSY, 1); 113262306a36Sopenharmony_ci rt2x00_desc_write(txd, 4, word); 113362306a36Sopenharmony_ci 113462306a36Sopenharmony_ci /* 113562306a36Sopenharmony_ci * Writing TXD word 0 must the last to prevent a race condition with 113662306a36Sopenharmony_ci * the device, whereby the device may take hold of the TXD before we 113762306a36Sopenharmony_ci * finished updating it. 113862306a36Sopenharmony_ci */ 113962306a36Sopenharmony_ci word = rt2x00_desc_read(txd, 0); 114062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1); 114162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_VALID, 1); 114262306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_MORE_FRAG, 114362306a36Sopenharmony_ci test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags)); 114462306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_ACK, 114562306a36Sopenharmony_ci test_bit(ENTRY_TXD_ACK, &txdesc->flags)); 114662306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_TIMESTAMP, 114762306a36Sopenharmony_ci test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags)); 114862306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_RTS, 114962306a36Sopenharmony_ci test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags)); 115062306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->u.plcp.ifs); 115162306a36Sopenharmony_ci rt2x00_set_field32(&word, TXD_W0_RETRY_MODE, 115262306a36Sopenharmony_ci test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags)); 115362306a36Sopenharmony_ci rt2x00_desc_write(txd, 0, word); 115462306a36Sopenharmony_ci 115562306a36Sopenharmony_ci /* 115662306a36Sopenharmony_ci * Register descriptor details in skb frame descriptor. 115762306a36Sopenharmony_ci */ 115862306a36Sopenharmony_ci skbdesc->desc = txd; 115962306a36Sopenharmony_ci skbdesc->desc_len = TXD_DESC_SIZE; 116062306a36Sopenharmony_ci} 116162306a36Sopenharmony_ci 116262306a36Sopenharmony_ci/* 116362306a36Sopenharmony_ci * TX data initialization 116462306a36Sopenharmony_ci */ 116562306a36Sopenharmony_cistatic void rt2400pci_write_beacon(struct queue_entry *entry, 116662306a36Sopenharmony_ci struct txentry_desc *txdesc) 116762306a36Sopenharmony_ci{ 116862306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 116962306a36Sopenharmony_ci u32 reg; 117062306a36Sopenharmony_ci 117162306a36Sopenharmony_ci /* 117262306a36Sopenharmony_ci * Disable beaconing while we are reloading the beacon data, 117362306a36Sopenharmony_ci * otherwise we might be sending out invalid data. 117462306a36Sopenharmony_ci */ 117562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR14); 117662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 0); 117762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 117862306a36Sopenharmony_ci 117962306a36Sopenharmony_ci if (rt2x00queue_map_txskb(entry)) { 118062306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Fail to map beacon, aborting\n"); 118162306a36Sopenharmony_ci goto out; 118262306a36Sopenharmony_ci } 118362306a36Sopenharmony_ci /* 118462306a36Sopenharmony_ci * Enable beaconing again. 118562306a36Sopenharmony_ci */ 118662306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 1); 118762306a36Sopenharmony_ci /* 118862306a36Sopenharmony_ci * Write the TX descriptor for the beacon. 118962306a36Sopenharmony_ci */ 119062306a36Sopenharmony_ci rt2400pci_write_tx_desc(entry, txdesc); 119162306a36Sopenharmony_ci 119262306a36Sopenharmony_ci /* 119362306a36Sopenharmony_ci * Dump beacon to userspace through debugfs. 119462306a36Sopenharmony_ci */ 119562306a36Sopenharmony_ci rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry); 119662306a36Sopenharmony_ciout: 119762306a36Sopenharmony_ci /* 119862306a36Sopenharmony_ci * Enable beaconing again. 119962306a36Sopenharmony_ci */ 120062306a36Sopenharmony_ci rt2x00_set_field32(®, CSR14_BEACON_GEN, 1); 120162306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR14, reg); 120262306a36Sopenharmony_ci} 120362306a36Sopenharmony_ci 120462306a36Sopenharmony_ci/* 120562306a36Sopenharmony_ci * RX control handlers 120662306a36Sopenharmony_ci */ 120762306a36Sopenharmony_cistatic void rt2400pci_fill_rxdone(struct queue_entry *entry, 120862306a36Sopenharmony_ci struct rxdone_entry_desc *rxdesc) 120962306a36Sopenharmony_ci{ 121062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; 121162306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv = entry->priv_data; 121262306a36Sopenharmony_ci u32 word0; 121362306a36Sopenharmony_ci u32 word2; 121462306a36Sopenharmony_ci u32 word3; 121562306a36Sopenharmony_ci u32 word4; 121662306a36Sopenharmony_ci u64 tsf; 121762306a36Sopenharmony_ci u32 rx_low; 121862306a36Sopenharmony_ci u32 rx_high; 121962306a36Sopenharmony_ci 122062306a36Sopenharmony_ci word0 = rt2x00_desc_read(entry_priv->desc, 0); 122162306a36Sopenharmony_ci word2 = rt2x00_desc_read(entry_priv->desc, 2); 122262306a36Sopenharmony_ci word3 = rt2x00_desc_read(entry_priv->desc, 3); 122362306a36Sopenharmony_ci word4 = rt2x00_desc_read(entry_priv->desc, 4); 122462306a36Sopenharmony_ci 122562306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR)) 122662306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC; 122762306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR)) 122862306a36Sopenharmony_ci rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC; 122962306a36Sopenharmony_ci 123062306a36Sopenharmony_ci /* 123162306a36Sopenharmony_ci * We only get the lower 32bits from the timestamp, 123262306a36Sopenharmony_ci * to get the full 64bits we must complement it with 123362306a36Sopenharmony_ci * the timestamp from get_tsf(). 123462306a36Sopenharmony_ci * Note that when a wraparound of the lower 32bits 123562306a36Sopenharmony_ci * has occurred between the frame arrival and the get_tsf() 123662306a36Sopenharmony_ci * call, we must decrease the higher 32bits with 1 to get 123762306a36Sopenharmony_ci * to correct value. 123862306a36Sopenharmony_ci */ 123962306a36Sopenharmony_ci tsf = rt2x00dev->ops->hw->get_tsf(rt2x00dev->hw, NULL); 124062306a36Sopenharmony_ci rx_low = rt2x00_get_field32(word4, RXD_W4_RX_END_TIME); 124162306a36Sopenharmony_ci rx_high = upper_32_bits(tsf); 124262306a36Sopenharmony_ci 124362306a36Sopenharmony_ci if ((u32)tsf <= rx_low) 124462306a36Sopenharmony_ci rx_high--; 124562306a36Sopenharmony_ci 124662306a36Sopenharmony_ci /* 124762306a36Sopenharmony_ci * Obtain the status about this packet. 124862306a36Sopenharmony_ci * The signal is the PLCP value, and needs to be stripped 124962306a36Sopenharmony_ci * of the preamble bit (0x08). 125062306a36Sopenharmony_ci */ 125162306a36Sopenharmony_ci rxdesc->timestamp = ((u64)rx_high << 32) | rx_low; 125262306a36Sopenharmony_ci rxdesc->signal = rt2x00_get_field32(word2, RXD_W2_SIGNAL) & ~0x08; 125362306a36Sopenharmony_ci rxdesc->rssi = rt2x00_get_field32(word3, RXD_W3_RSSI) - 125462306a36Sopenharmony_ci entry->queue->rt2x00dev->rssi_offset; 125562306a36Sopenharmony_ci rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT); 125662306a36Sopenharmony_ci 125762306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP; 125862306a36Sopenharmony_ci if (rt2x00_get_field32(word0, RXD_W0_MY_BSS)) 125962306a36Sopenharmony_ci rxdesc->dev_flags |= RXDONE_MY_BSS; 126062306a36Sopenharmony_ci} 126162306a36Sopenharmony_ci 126262306a36Sopenharmony_ci/* 126362306a36Sopenharmony_ci * Interrupt functions. 126462306a36Sopenharmony_ci */ 126562306a36Sopenharmony_cistatic void rt2400pci_txdone(struct rt2x00_dev *rt2x00dev, 126662306a36Sopenharmony_ci const enum data_queue_qid queue_idx) 126762306a36Sopenharmony_ci{ 126862306a36Sopenharmony_ci struct data_queue *queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx); 126962306a36Sopenharmony_ci struct queue_entry_priv_mmio *entry_priv; 127062306a36Sopenharmony_ci struct queue_entry *entry; 127162306a36Sopenharmony_ci struct txdone_entry_desc txdesc; 127262306a36Sopenharmony_ci u32 word; 127362306a36Sopenharmony_ci 127462306a36Sopenharmony_ci while (!rt2x00queue_empty(queue)) { 127562306a36Sopenharmony_ci entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE); 127662306a36Sopenharmony_ci entry_priv = entry->priv_data; 127762306a36Sopenharmony_ci word = rt2x00_desc_read(entry_priv->desc, 0); 127862306a36Sopenharmony_ci 127962306a36Sopenharmony_ci if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) || 128062306a36Sopenharmony_ci !rt2x00_get_field32(word, TXD_W0_VALID)) 128162306a36Sopenharmony_ci break; 128262306a36Sopenharmony_ci 128362306a36Sopenharmony_ci /* 128462306a36Sopenharmony_ci * Obtain the status about this packet. 128562306a36Sopenharmony_ci */ 128662306a36Sopenharmony_ci txdesc.flags = 0; 128762306a36Sopenharmony_ci switch (rt2x00_get_field32(word, TXD_W0_RESULT)) { 128862306a36Sopenharmony_ci case 0: /* Success */ 128962306a36Sopenharmony_ci case 1: /* Success with retry */ 129062306a36Sopenharmony_ci __set_bit(TXDONE_SUCCESS, &txdesc.flags); 129162306a36Sopenharmony_ci break; 129262306a36Sopenharmony_ci case 2: /* Failure, excessive retries */ 129362306a36Sopenharmony_ci __set_bit(TXDONE_EXCESSIVE_RETRY, &txdesc.flags); 129462306a36Sopenharmony_ci fallthrough; /* this is a failed frame! */ 129562306a36Sopenharmony_ci default: /* Failure */ 129662306a36Sopenharmony_ci __set_bit(TXDONE_FAILURE, &txdesc.flags); 129762306a36Sopenharmony_ci } 129862306a36Sopenharmony_ci txdesc.retry = rt2x00_get_field32(word, TXD_W0_RETRY_COUNT); 129962306a36Sopenharmony_ci 130062306a36Sopenharmony_ci rt2x00lib_txdone(entry, &txdesc); 130162306a36Sopenharmony_ci } 130262306a36Sopenharmony_ci} 130362306a36Sopenharmony_ci 130462306a36Sopenharmony_cistatic inline void rt2400pci_enable_interrupt(struct rt2x00_dev *rt2x00dev, 130562306a36Sopenharmony_ci struct rt2x00_field32 irq_field) 130662306a36Sopenharmony_ci{ 130762306a36Sopenharmony_ci u32 reg; 130862306a36Sopenharmony_ci 130962306a36Sopenharmony_ci /* 131062306a36Sopenharmony_ci * Enable a single interrupt. The interrupt mask register 131162306a36Sopenharmony_ci * access needs locking. 131262306a36Sopenharmony_ci */ 131362306a36Sopenharmony_ci spin_lock_irq(&rt2x00dev->irqmask_lock); 131462306a36Sopenharmony_ci 131562306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 131662306a36Sopenharmony_ci rt2x00_set_field32(®, irq_field, 0); 131762306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 131862306a36Sopenharmony_ci 131962306a36Sopenharmony_ci spin_unlock_irq(&rt2x00dev->irqmask_lock); 132062306a36Sopenharmony_ci} 132162306a36Sopenharmony_ci 132262306a36Sopenharmony_cistatic void rt2400pci_txstatus_tasklet(struct tasklet_struct *t) 132362306a36Sopenharmony_ci{ 132462306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, 132562306a36Sopenharmony_ci txstatus_tasklet); 132662306a36Sopenharmony_ci u32 reg; 132762306a36Sopenharmony_ci 132862306a36Sopenharmony_ci /* 132962306a36Sopenharmony_ci * Handle all tx queues. 133062306a36Sopenharmony_ci */ 133162306a36Sopenharmony_ci rt2400pci_txdone(rt2x00dev, QID_ATIM); 133262306a36Sopenharmony_ci rt2400pci_txdone(rt2x00dev, QID_AC_VO); 133362306a36Sopenharmony_ci rt2400pci_txdone(rt2x00dev, QID_AC_VI); 133462306a36Sopenharmony_ci 133562306a36Sopenharmony_ci /* 133662306a36Sopenharmony_ci * Enable all TXDONE interrupts again. 133762306a36Sopenharmony_ci */ 133862306a36Sopenharmony_ci if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) { 133962306a36Sopenharmony_ci spin_lock_irq(&rt2x00dev->irqmask_lock); 134062306a36Sopenharmony_ci 134162306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 134262306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_TXRING, 0); 134362306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_ATIMRING, 0); 134462306a36Sopenharmony_ci rt2x00_set_field32(®, CSR8_TXDONE_PRIORING, 0); 134562306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 134662306a36Sopenharmony_ci 134762306a36Sopenharmony_ci spin_unlock_irq(&rt2x00dev->irqmask_lock); 134862306a36Sopenharmony_ci } 134962306a36Sopenharmony_ci} 135062306a36Sopenharmony_ci 135162306a36Sopenharmony_cistatic void rt2400pci_tbtt_tasklet(struct tasklet_struct *t) 135262306a36Sopenharmony_ci{ 135362306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, tbtt_tasklet); 135462306a36Sopenharmony_ci rt2x00lib_beacondone(rt2x00dev); 135562306a36Sopenharmony_ci if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 135662306a36Sopenharmony_ci rt2400pci_enable_interrupt(rt2x00dev, CSR8_TBCN_EXPIRE); 135762306a36Sopenharmony_ci} 135862306a36Sopenharmony_ci 135962306a36Sopenharmony_cistatic void rt2400pci_rxdone_tasklet(struct tasklet_struct *t) 136062306a36Sopenharmony_ci{ 136162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = from_tasklet(rt2x00dev, t, 136262306a36Sopenharmony_ci rxdone_tasklet); 136362306a36Sopenharmony_ci if (rt2x00mmio_rxdone(rt2x00dev)) 136462306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->rxdone_tasklet); 136562306a36Sopenharmony_ci else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 136662306a36Sopenharmony_ci rt2400pci_enable_interrupt(rt2x00dev, CSR8_RXDONE); 136762306a36Sopenharmony_ci} 136862306a36Sopenharmony_ci 136962306a36Sopenharmony_cistatic irqreturn_t rt2400pci_interrupt(int irq, void *dev_instance) 137062306a36Sopenharmony_ci{ 137162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = dev_instance; 137262306a36Sopenharmony_ci u32 reg, mask; 137362306a36Sopenharmony_ci 137462306a36Sopenharmony_ci /* 137562306a36Sopenharmony_ci * Get the interrupt sources & saved to local variable. 137662306a36Sopenharmony_ci * Write register value back to clear pending interrupts. 137762306a36Sopenharmony_ci */ 137862306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR7); 137962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR7, reg); 138062306a36Sopenharmony_ci 138162306a36Sopenharmony_ci if (!reg) 138262306a36Sopenharmony_ci return IRQ_NONE; 138362306a36Sopenharmony_ci 138462306a36Sopenharmony_ci if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) 138562306a36Sopenharmony_ci return IRQ_HANDLED; 138662306a36Sopenharmony_ci 138762306a36Sopenharmony_ci mask = reg; 138862306a36Sopenharmony_ci 138962306a36Sopenharmony_ci /* 139062306a36Sopenharmony_ci * Schedule tasklets for interrupt handling. 139162306a36Sopenharmony_ci */ 139262306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_TBCN_EXPIRE)) 139362306a36Sopenharmony_ci tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet); 139462306a36Sopenharmony_ci 139562306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_RXDONE)) 139662306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->rxdone_tasklet); 139762306a36Sopenharmony_ci 139862306a36Sopenharmony_ci if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING) || 139962306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING) || 140062306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR7_TXDONE_TXRING)) { 140162306a36Sopenharmony_ci tasklet_schedule(&rt2x00dev->txstatus_tasklet); 140262306a36Sopenharmony_ci /* 140362306a36Sopenharmony_ci * Mask out all txdone interrupts. 140462306a36Sopenharmony_ci */ 140562306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_TXRING, 1); 140662306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_ATIMRING, 1); 140762306a36Sopenharmony_ci rt2x00_set_field32(&mask, CSR8_TXDONE_PRIORING, 1); 140862306a36Sopenharmony_ci } 140962306a36Sopenharmony_ci 141062306a36Sopenharmony_ci /* 141162306a36Sopenharmony_ci * Disable all interrupts for which a tasklet was scheduled right now, 141262306a36Sopenharmony_ci * the tasklet will reenable the appropriate interrupts. 141362306a36Sopenharmony_ci */ 141462306a36Sopenharmony_ci spin_lock(&rt2x00dev->irqmask_lock); 141562306a36Sopenharmony_ci 141662306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR8); 141762306a36Sopenharmony_ci reg |= mask; 141862306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, CSR8, reg); 141962306a36Sopenharmony_ci 142062306a36Sopenharmony_ci spin_unlock(&rt2x00dev->irqmask_lock); 142162306a36Sopenharmony_ci 142262306a36Sopenharmony_ci 142362306a36Sopenharmony_ci 142462306a36Sopenharmony_ci return IRQ_HANDLED; 142562306a36Sopenharmony_ci} 142662306a36Sopenharmony_ci 142762306a36Sopenharmony_ci/* 142862306a36Sopenharmony_ci * Device probe functions. 142962306a36Sopenharmony_ci */ 143062306a36Sopenharmony_cistatic int rt2400pci_validate_eeprom(struct rt2x00_dev *rt2x00dev) 143162306a36Sopenharmony_ci{ 143262306a36Sopenharmony_ci struct eeprom_93cx6 eeprom; 143362306a36Sopenharmony_ci u32 reg; 143462306a36Sopenharmony_ci u16 word; 143562306a36Sopenharmony_ci u8 *mac; 143662306a36Sopenharmony_ci 143762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR21); 143862306a36Sopenharmony_ci 143962306a36Sopenharmony_ci eeprom.data = rt2x00dev; 144062306a36Sopenharmony_ci eeprom.register_read = rt2400pci_eepromregister_read; 144162306a36Sopenharmony_ci eeprom.register_write = rt2400pci_eepromregister_write; 144262306a36Sopenharmony_ci eeprom.width = rt2x00_get_field32(reg, CSR21_TYPE_93C46) ? 144362306a36Sopenharmony_ci PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66; 144462306a36Sopenharmony_ci eeprom.reg_data_in = 0; 144562306a36Sopenharmony_ci eeprom.reg_data_out = 0; 144662306a36Sopenharmony_ci eeprom.reg_data_clock = 0; 144762306a36Sopenharmony_ci eeprom.reg_chip_select = 0; 144862306a36Sopenharmony_ci 144962306a36Sopenharmony_ci eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom, 145062306a36Sopenharmony_ci EEPROM_SIZE / sizeof(u16)); 145162306a36Sopenharmony_ci 145262306a36Sopenharmony_ci /* 145362306a36Sopenharmony_ci * Start validation of the data that has been read. 145462306a36Sopenharmony_ci */ 145562306a36Sopenharmony_ci mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0); 145662306a36Sopenharmony_ci rt2x00lib_set_mac_address(rt2x00dev, mac); 145762306a36Sopenharmony_ci 145862306a36Sopenharmony_ci word = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 145962306a36Sopenharmony_ci if (word == 0xffff) { 146062306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Invalid EEPROM data detected\n"); 146162306a36Sopenharmony_ci return -EINVAL; 146262306a36Sopenharmony_ci } 146362306a36Sopenharmony_ci 146462306a36Sopenharmony_ci return 0; 146562306a36Sopenharmony_ci} 146662306a36Sopenharmony_ci 146762306a36Sopenharmony_cistatic int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev) 146862306a36Sopenharmony_ci{ 146962306a36Sopenharmony_ci u32 reg; 147062306a36Sopenharmony_ci u16 value; 147162306a36Sopenharmony_ci u16 eeprom; 147262306a36Sopenharmony_ci 147362306a36Sopenharmony_ci /* 147462306a36Sopenharmony_ci * Read EEPROM word for configuration. 147562306a36Sopenharmony_ci */ 147662306a36Sopenharmony_ci eeprom = rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA); 147762306a36Sopenharmony_ci 147862306a36Sopenharmony_ci /* 147962306a36Sopenharmony_ci * Identify RF chipset. 148062306a36Sopenharmony_ci */ 148162306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 148262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR0); 148362306a36Sopenharmony_ci rt2x00_set_chip(rt2x00dev, RT2460, value, 148462306a36Sopenharmony_ci rt2x00_get_field32(reg, CSR0_REVISION)); 148562306a36Sopenharmony_ci 148662306a36Sopenharmony_ci if (!rt2x00_rf(rt2x00dev, RF2420) && !rt2x00_rf(rt2x00dev, RF2421)) { 148762306a36Sopenharmony_ci rt2x00_err(rt2x00dev, "Invalid RF chipset detected\n"); 148862306a36Sopenharmony_ci return -ENODEV; 148962306a36Sopenharmony_ci } 149062306a36Sopenharmony_ci 149162306a36Sopenharmony_ci /* 149262306a36Sopenharmony_ci * Identify default antenna configuration. 149362306a36Sopenharmony_ci */ 149462306a36Sopenharmony_ci rt2x00dev->default_ant.tx = 149562306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT); 149662306a36Sopenharmony_ci rt2x00dev->default_ant.rx = 149762306a36Sopenharmony_ci rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT); 149862306a36Sopenharmony_ci 149962306a36Sopenharmony_ci /* 150062306a36Sopenharmony_ci * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead. 150162306a36Sopenharmony_ci * I am not 100% sure about this, but the legacy drivers do not 150262306a36Sopenharmony_ci * indicate antenna swapping in software is required when 150362306a36Sopenharmony_ci * diversity is enabled. 150462306a36Sopenharmony_ci */ 150562306a36Sopenharmony_ci if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY) 150662306a36Sopenharmony_ci rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; 150762306a36Sopenharmony_ci if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY) 150862306a36Sopenharmony_ci rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; 150962306a36Sopenharmony_ci 151062306a36Sopenharmony_ci /* 151162306a36Sopenharmony_ci * Store led mode, for correct led behaviour. 151262306a36Sopenharmony_ci */ 151362306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_LEDS 151462306a36Sopenharmony_ci value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE); 151562306a36Sopenharmony_ci 151662306a36Sopenharmony_ci rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO); 151762306a36Sopenharmony_ci if (value == LED_MODE_TXRX_ACTIVITY || 151862306a36Sopenharmony_ci value == LED_MODE_DEFAULT || 151962306a36Sopenharmony_ci value == LED_MODE_ASUS) 152062306a36Sopenharmony_ci rt2400pci_init_led(rt2x00dev, &rt2x00dev->led_qual, 152162306a36Sopenharmony_ci LED_TYPE_ACTIVITY); 152262306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_LEDS */ 152362306a36Sopenharmony_ci 152462306a36Sopenharmony_ci /* 152562306a36Sopenharmony_ci * Detect if this device has an hardware controlled radio. 152662306a36Sopenharmony_ci */ 152762306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO)) 152862306a36Sopenharmony_ci __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags); 152962306a36Sopenharmony_ci 153062306a36Sopenharmony_ci /* 153162306a36Sopenharmony_ci * Check if the BBP tuning should be enabled. 153262306a36Sopenharmony_ci */ 153362306a36Sopenharmony_ci if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_AGCVGC_TUNING)) 153462306a36Sopenharmony_ci __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags); 153562306a36Sopenharmony_ci 153662306a36Sopenharmony_ci return 0; 153762306a36Sopenharmony_ci} 153862306a36Sopenharmony_ci 153962306a36Sopenharmony_ci/* 154062306a36Sopenharmony_ci * RF value list for RF2420 & RF2421 154162306a36Sopenharmony_ci * Supports: 2.4 GHz 154262306a36Sopenharmony_ci */ 154362306a36Sopenharmony_cistatic const struct rf_channel rf_vals_b[] = { 154462306a36Sopenharmony_ci { 1, 0x00022058, 0x000c1fda, 0x00000101, 0 }, 154562306a36Sopenharmony_ci { 2, 0x00022058, 0x000c1fee, 0x00000101, 0 }, 154662306a36Sopenharmony_ci { 3, 0x00022058, 0x000c2002, 0x00000101, 0 }, 154762306a36Sopenharmony_ci { 4, 0x00022058, 0x000c2016, 0x00000101, 0 }, 154862306a36Sopenharmony_ci { 5, 0x00022058, 0x000c202a, 0x00000101, 0 }, 154962306a36Sopenharmony_ci { 6, 0x00022058, 0x000c203e, 0x00000101, 0 }, 155062306a36Sopenharmony_ci { 7, 0x00022058, 0x000c2052, 0x00000101, 0 }, 155162306a36Sopenharmony_ci { 8, 0x00022058, 0x000c2066, 0x00000101, 0 }, 155262306a36Sopenharmony_ci { 9, 0x00022058, 0x000c207a, 0x00000101, 0 }, 155362306a36Sopenharmony_ci { 10, 0x00022058, 0x000c208e, 0x00000101, 0 }, 155462306a36Sopenharmony_ci { 11, 0x00022058, 0x000c20a2, 0x00000101, 0 }, 155562306a36Sopenharmony_ci { 12, 0x00022058, 0x000c20b6, 0x00000101, 0 }, 155662306a36Sopenharmony_ci { 13, 0x00022058, 0x000c20ca, 0x00000101, 0 }, 155762306a36Sopenharmony_ci { 14, 0x00022058, 0x000c20fa, 0x00000101, 0 }, 155862306a36Sopenharmony_ci}; 155962306a36Sopenharmony_ci 156062306a36Sopenharmony_cistatic int rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev) 156162306a36Sopenharmony_ci{ 156262306a36Sopenharmony_ci struct hw_mode_spec *spec = &rt2x00dev->spec; 156362306a36Sopenharmony_ci struct channel_info *info; 156462306a36Sopenharmony_ci u8 *tx_power; 156562306a36Sopenharmony_ci unsigned int i; 156662306a36Sopenharmony_ci 156762306a36Sopenharmony_ci /* 156862306a36Sopenharmony_ci * Initialize all hw fields. 156962306a36Sopenharmony_ci */ 157062306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, PS_NULLFUNC_STACK); 157162306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SUPPORTS_PS); 157262306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, HOST_BROADCAST_PS_BUFFERING); 157362306a36Sopenharmony_ci ieee80211_hw_set(rt2x00dev->hw, SIGNAL_DBM); 157462306a36Sopenharmony_ci 157562306a36Sopenharmony_ci SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev); 157662306a36Sopenharmony_ci SET_IEEE80211_PERM_ADDR(rt2x00dev->hw, 157762306a36Sopenharmony_ci rt2x00_eeprom_addr(rt2x00dev, 157862306a36Sopenharmony_ci EEPROM_MAC_ADDR_0)); 157962306a36Sopenharmony_ci 158062306a36Sopenharmony_ci /* 158162306a36Sopenharmony_ci * Initialize hw_mode information. 158262306a36Sopenharmony_ci */ 158362306a36Sopenharmony_ci spec->supported_bands = SUPPORT_BAND_2GHZ; 158462306a36Sopenharmony_ci spec->supported_rates = SUPPORT_RATE_CCK; 158562306a36Sopenharmony_ci 158662306a36Sopenharmony_ci spec->num_channels = ARRAY_SIZE(rf_vals_b); 158762306a36Sopenharmony_ci spec->channels = rf_vals_b; 158862306a36Sopenharmony_ci 158962306a36Sopenharmony_ci /* 159062306a36Sopenharmony_ci * Create channel information array 159162306a36Sopenharmony_ci */ 159262306a36Sopenharmony_ci info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL); 159362306a36Sopenharmony_ci if (!info) 159462306a36Sopenharmony_ci return -ENOMEM; 159562306a36Sopenharmony_ci 159662306a36Sopenharmony_ci spec->channels_info = info; 159762306a36Sopenharmony_ci 159862306a36Sopenharmony_ci tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START); 159962306a36Sopenharmony_ci for (i = 0; i < 14; i++) { 160062306a36Sopenharmony_ci info[i].max_power = TXPOWER_FROM_DEV(MAX_TXPOWER); 160162306a36Sopenharmony_ci info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]); 160262306a36Sopenharmony_ci } 160362306a36Sopenharmony_ci 160462306a36Sopenharmony_ci return 0; 160562306a36Sopenharmony_ci} 160662306a36Sopenharmony_ci 160762306a36Sopenharmony_cistatic int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev) 160862306a36Sopenharmony_ci{ 160962306a36Sopenharmony_ci int retval; 161062306a36Sopenharmony_ci u32 reg; 161162306a36Sopenharmony_ci 161262306a36Sopenharmony_ci /* 161362306a36Sopenharmony_ci * Allocate eeprom data. 161462306a36Sopenharmony_ci */ 161562306a36Sopenharmony_ci retval = rt2400pci_validate_eeprom(rt2x00dev); 161662306a36Sopenharmony_ci if (retval) 161762306a36Sopenharmony_ci return retval; 161862306a36Sopenharmony_ci 161962306a36Sopenharmony_ci retval = rt2400pci_init_eeprom(rt2x00dev); 162062306a36Sopenharmony_ci if (retval) 162162306a36Sopenharmony_ci return retval; 162262306a36Sopenharmony_ci 162362306a36Sopenharmony_ci /* 162462306a36Sopenharmony_ci * Enable rfkill polling by setting GPIO direction of the 162562306a36Sopenharmony_ci * rfkill switch GPIO pin correctly. 162662306a36Sopenharmony_ci */ 162762306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, GPIOCSR); 162862306a36Sopenharmony_ci rt2x00_set_field32(®, GPIOCSR_DIR0, 1); 162962306a36Sopenharmony_ci rt2x00mmio_register_write(rt2x00dev, GPIOCSR, reg); 163062306a36Sopenharmony_ci 163162306a36Sopenharmony_ci /* 163262306a36Sopenharmony_ci * Initialize hw specifications. 163362306a36Sopenharmony_ci */ 163462306a36Sopenharmony_ci retval = rt2400pci_probe_hw_mode(rt2x00dev); 163562306a36Sopenharmony_ci if (retval) 163662306a36Sopenharmony_ci return retval; 163762306a36Sopenharmony_ci 163862306a36Sopenharmony_ci /* 163962306a36Sopenharmony_ci * This device requires the atim queue and DMA-mapped skbs. 164062306a36Sopenharmony_ci */ 164162306a36Sopenharmony_ci __set_bit(REQUIRE_ATIM_QUEUE, &rt2x00dev->cap_flags); 164262306a36Sopenharmony_ci __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags); 164362306a36Sopenharmony_ci __set_bit(REQUIRE_SW_SEQNO, &rt2x00dev->cap_flags); 164462306a36Sopenharmony_ci 164562306a36Sopenharmony_ci /* 164662306a36Sopenharmony_ci * Set the rssi offset. 164762306a36Sopenharmony_ci */ 164862306a36Sopenharmony_ci rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET; 164962306a36Sopenharmony_ci 165062306a36Sopenharmony_ci return 0; 165162306a36Sopenharmony_ci} 165262306a36Sopenharmony_ci 165362306a36Sopenharmony_ci/* 165462306a36Sopenharmony_ci * IEEE80211 stack callback functions. 165562306a36Sopenharmony_ci */ 165662306a36Sopenharmony_cistatic int rt2400pci_conf_tx(struct ieee80211_hw *hw, 165762306a36Sopenharmony_ci struct ieee80211_vif *vif, 165862306a36Sopenharmony_ci unsigned int link_id, u16 queue, 165962306a36Sopenharmony_ci const struct ieee80211_tx_queue_params *params) 166062306a36Sopenharmony_ci{ 166162306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 166262306a36Sopenharmony_ci 166362306a36Sopenharmony_ci /* 166462306a36Sopenharmony_ci * We don't support variating cw_min and cw_max variables 166562306a36Sopenharmony_ci * per queue. So by default we only configure the TX queue, 166662306a36Sopenharmony_ci * and ignore all other configurations. 166762306a36Sopenharmony_ci */ 166862306a36Sopenharmony_ci if (queue != 0) 166962306a36Sopenharmony_ci return -EINVAL; 167062306a36Sopenharmony_ci 167162306a36Sopenharmony_ci if (rt2x00mac_conf_tx(hw, vif, link_id, queue, params)) 167262306a36Sopenharmony_ci return -EINVAL; 167362306a36Sopenharmony_ci 167462306a36Sopenharmony_ci /* 167562306a36Sopenharmony_ci * Write configuration to register. 167662306a36Sopenharmony_ci */ 167762306a36Sopenharmony_ci rt2400pci_config_cw(rt2x00dev, 167862306a36Sopenharmony_ci rt2x00dev->tx->cw_min, rt2x00dev->tx->cw_max); 167962306a36Sopenharmony_ci 168062306a36Sopenharmony_ci return 0; 168162306a36Sopenharmony_ci} 168262306a36Sopenharmony_ci 168362306a36Sopenharmony_cistatic u64 rt2400pci_get_tsf(struct ieee80211_hw *hw, 168462306a36Sopenharmony_ci struct ieee80211_vif *vif) 168562306a36Sopenharmony_ci{ 168662306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 168762306a36Sopenharmony_ci u64 tsf; 168862306a36Sopenharmony_ci u32 reg; 168962306a36Sopenharmony_ci 169062306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR17); 169162306a36Sopenharmony_ci tsf = (u64) rt2x00_get_field32(reg, CSR17_HIGH_TSFTIMER) << 32; 169262306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR16); 169362306a36Sopenharmony_ci tsf |= rt2x00_get_field32(reg, CSR16_LOW_TSFTIMER); 169462306a36Sopenharmony_ci 169562306a36Sopenharmony_ci return tsf; 169662306a36Sopenharmony_ci} 169762306a36Sopenharmony_ci 169862306a36Sopenharmony_cistatic int rt2400pci_tx_last_beacon(struct ieee80211_hw *hw) 169962306a36Sopenharmony_ci{ 170062306a36Sopenharmony_ci struct rt2x00_dev *rt2x00dev = hw->priv; 170162306a36Sopenharmony_ci u32 reg; 170262306a36Sopenharmony_ci 170362306a36Sopenharmony_ci reg = rt2x00mmio_register_read(rt2x00dev, CSR15); 170462306a36Sopenharmony_ci return rt2x00_get_field32(reg, CSR15_BEACON_SENT); 170562306a36Sopenharmony_ci} 170662306a36Sopenharmony_ci 170762306a36Sopenharmony_cistatic const struct ieee80211_ops rt2400pci_mac80211_ops = { 170862306a36Sopenharmony_ci .tx = rt2x00mac_tx, 170962306a36Sopenharmony_ci .wake_tx_queue = ieee80211_handle_wake_tx_queue, 171062306a36Sopenharmony_ci .start = rt2x00mac_start, 171162306a36Sopenharmony_ci .stop = rt2x00mac_stop, 171262306a36Sopenharmony_ci .add_interface = rt2x00mac_add_interface, 171362306a36Sopenharmony_ci .remove_interface = rt2x00mac_remove_interface, 171462306a36Sopenharmony_ci .config = rt2x00mac_config, 171562306a36Sopenharmony_ci .configure_filter = rt2x00mac_configure_filter, 171662306a36Sopenharmony_ci .sw_scan_start = rt2x00mac_sw_scan_start, 171762306a36Sopenharmony_ci .sw_scan_complete = rt2x00mac_sw_scan_complete, 171862306a36Sopenharmony_ci .get_stats = rt2x00mac_get_stats, 171962306a36Sopenharmony_ci .bss_info_changed = rt2x00mac_bss_info_changed, 172062306a36Sopenharmony_ci .conf_tx = rt2400pci_conf_tx, 172162306a36Sopenharmony_ci .get_tsf = rt2400pci_get_tsf, 172262306a36Sopenharmony_ci .tx_last_beacon = rt2400pci_tx_last_beacon, 172362306a36Sopenharmony_ci .rfkill_poll = rt2x00mac_rfkill_poll, 172462306a36Sopenharmony_ci .flush = rt2x00mac_flush, 172562306a36Sopenharmony_ci .set_antenna = rt2x00mac_set_antenna, 172662306a36Sopenharmony_ci .get_antenna = rt2x00mac_get_antenna, 172762306a36Sopenharmony_ci .get_ringparam = rt2x00mac_get_ringparam, 172862306a36Sopenharmony_ci .tx_frames_pending = rt2x00mac_tx_frames_pending, 172962306a36Sopenharmony_ci}; 173062306a36Sopenharmony_ci 173162306a36Sopenharmony_cistatic const struct rt2x00lib_ops rt2400pci_rt2x00_ops = { 173262306a36Sopenharmony_ci .irq_handler = rt2400pci_interrupt, 173362306a36Sopenharmony_ci .txstatus_tasklet = rt2400pci_txstatus_tasklet, 173462306a36Sopenharmony_ci .tbtt_tasklet = rt2400pci_tbtt_tasklet, 173562306a36Sopenharmony_ci .rxdone_tasklet = rt2400pci_rxdone_tasklet, 173662306a36Sopenharmony_ci .probe_hw = rt2400pci_probe_hw, 173762306a36Sopenharmony_ci .initialize = rt2x00mmio_initialize, 173862306a36Sopenharmony_ci .uninitialize = rt2x00mmio_uninitialize, 173962306a36Sopenharmony_ci .get_entry_state = rt2400pci_get_entry_state, 174062306a36Sopenharmony_ci .clear_entry = rt2400pci_clear_entry, 174162306a36Sopenharmony_ci .set_device_state = rt2400pci_set_device_state, 174262306a36Sopenharmony_ci .rfkill_poll = rt2400pci_rfkill_poll, 174362306a36Sopenharmony_ci .link_stats = rt2400pci_link_stats, 174462306a36Sopenharmony_ci .reset_tuner = rt2400pci_reset_tuner, 174562306a36Sopenharmony_ci .link_tuner = rt2400pci_link_tuner, 174662306a36Sopenharmony_ci .start_queue = rt2400pci_start_queue, 174762306a36Sopenharmony_ci .kick_queue = rt2400pci_kick_queue, 174862306a36Sopenharmony_ci .stop_queue = rt2400pci_stop_queue, 174962306a36Sopenharmony_ci .flush_queue = rt2x00mmio_flush_queue, 175062306a36Sopenharmony_ci .write_tx_desc = rt2400pci_write_tx_desc, 175162306a36Sopenharmony_ci .write_beacon = rt2400pci_write_beacon, 175262306a36Sopenharmony_ci .fill_rxdone = rt2400pci_fill_rxdone, 175362306a36Sopenharmony_ci .config_filter = rt2400pci_config_filter, 175462306a36Sopenharmony_ci .config_intf = rt2400pci_config_intf, 175562306a36Sopenharmony_ci .config_erp = rt2400pci_config_erp, 175662306a36Sopenharmony_ci .config_ant = rt2400pci_config_ant, 175762306a36Sopenharmony_ci .config = rt2400pci_config, 175862306a36Sopenharmony_ci}; 175962306a36Sopenharmony_ci 176062306a36Sopenharmony_cistatic void rt2400pci_queue_init(struct data_queue *queue) 176162306a36Sopenharmony_ci{ 176262306a36Sopenharmony_ci switch (queue->qid) { 176362306a36Sopenharmony_ci case QID_RX: 176462306a36Sopenharmony_ci queue->limit = 24; 176562306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 176662306a36Sopenharmony_ci queue->desc_size = RXD_DESC_SIZE; 176762306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 176862306a36Sopenharmony_ci break; 176962306a36Sopenharmony_ci 177062306a36Sopenharmony_ci case QID_AC_VO: 177162306a36Sopenharmony_ci case QID_AC_VI: 177262306a36Sopenharmony_ci case QID_AC_BE: 177362306a36Sopenharmony_ci case QID_AC_BK: 177462306a36Sopenharmony_ci queue->limit = 24; 177562306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 177662306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 177762306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 177862306a36Sopenharmony_ci break; 177962306a36Sopenharmony_ci 178062306a36Sopenharmony_ci case QID_BEACON: 178162306a36Sopenharmony_ci queue->limit = 1; 178262306a36Sopenharmony_ci queue->data_size = MGMT_FRAME_SIZE; 178362306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 178462306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 178562306a36Sopenharmony_ci break; 178662306a36Sopenharmony_ci 178762306a36Sopenharmony_ci case QID_ATIM: 178862306a36Sopenharmony_ci queue->limit = 8; 178962306a36Sopenharmony_ci queue->data_size = DATA_FRAME_SIZE; 179062306a36Sopenharmony_ci queue->desc_size = TXD_DESC_SIZE; 179162306a36Sopenharmony_ci queue->priv_size = sizeof(struct queue_entry_priv_mmio); 179262306a36Sopenharmony_ci break; 179362306a36Sopenharmony_ci 179462306a36Sopenharmony_ci default: 179562306a36Sopenharmony_ci BUG(); 179662306a36Sopenharmony_ci break; 179762306a36Sopenharmony_ci } 179862306a36Sopenharmony_ci} 179962306a36Sopenharmony_ci 180062306a36Sopenharmony_cistatic const struct rt2x00_ops rt2400pci_ops = { 180162306a36Sopenharmony_ci .name = KBUILD_MODNAME, 180262306a36Sopenharmony_ci .max_ap_intf = 1, 180362306a36Sopenharmony_ci .eeprom_size = EEPROM_SIZE, 180462306a36Sopenharmony_ci .rf_size = RF_SIZE, 180562306a36Sopenharmony_ci .tx_queues = NUM_TX_QUEUES, 180662306a36Sopenharmony_ci .queue_init = rt2400pci_queue_init, 180762306a36Sopenharmony_ci .lib = &rt2400pci_rt2x00_ops, 180862306a36Sopenharmony_ci .hw = &rt2400pci_mac80211_ops, 180962306a36Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS 181062306a36Sopenharmony_ci .debugfs = &rt2400pci_rt2x00debug, 181162306a36Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */ 181262306a36Sopenharmony_ci}; 181362306a36Sopenharmony_ci 181462306a36Sopenharmony_ci/* 181562306a36Sopenharmony_ci * RT2400pci module information. 181662306a36Sopenharmony_ci */ 181762306a36Sopenharmony_cistatic const struct pci_device_id rt2400pci_device_table[] = { 181862306a36Sopenharmony_ci { PCI_DEVICE(0x1814, 0x0101) }, 181962306a36Sopenharmony_ci { 0, } 182062306a36Sopenharmony_ci}; 182162306a36Sopenharmony_ci 182262306a36Sopenharmony_ci 182362306a36Sopenharmony_ciMODULE_AUTHOR(DRV_PROJECT); 182462306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION); 182562306a36Sopenharmony_ciMODULE_DESCRIPTION("Ralink RT2400 PCI & PCMCIA Wireless LAN driver."); 182662306a36Sopenharmony_ciMODULE_DEVICE_TABLE(pci, rt2400pci_device_table); 182762306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 182862306a36Sopenharmony_ci 182962306a36Sopenharmony_cistatic int rt2400pci_probe(struct pci_dev *pci_dev, 183062306a36Sopenharmony_ci const struct pci_device_id *id) 183162306a36Sopenharmony_ci{ 183262306a36Sopenharmony_ci return rt2x00pci_probe(pci_dev, &rt2400pci_ops); 183362306a36Sopenharmony_ci} 183462306a36Sopenharmony_ci 183562306a36Sopenharmony_cistatic struct pci_driver rt2400pci_driver = { 183662306a36Sopenharmony_ci .name = KBUILD_MODNAME, 183762306a36Sopenharmony_ci .id_table = rt2400pci_device_table, 183862306a36Sopenharmony_ci .probe = rt2400pci_probe, 183962306a36Sopenharmony_ci .remove = rt2x00pci_remove, 184062306a36Sopenharmony_ci .driver.pm = &rt2x00pci_pm_ops, 184162306a36Sopenharmony_ci}; 184262306a36Sopenharmony_ci 184362306a36Sopenharmony_cimodule_pci_driver(rt2400pci_driver); 1844