📄 rt2500pci.c
字号:
rt2x00pci_register_write(rt2x00dev, BBPCSR1, reg); rt2500pci_bbp_write(rt2x00dev, 14, r14); rt2500pci_bbp_write(rt2x00dev, 2, r2);}static void rt2500pci_config_duration(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_conf *libconf){ u32 reg; rt2x00pci_register_read(rt2x00dev, CSR11, ®); rt2x00_set_field32(®, CSR11_SLOT_TIME, libconf->slot_time); rt2x00pci_register_write(rt2x00dev, CSR11, reg); rt2x00pci_register_read(rt2x00dev, CSR18, ®); rt2x00_set_field32(®, CSR18_SIFS, libconf->sifs); rt2x00_set_field32(®, CSR18_PIFS, libconf->pifs); rt2x00pci_register_write(rt2x00dev, CSR18, reg); rt2x00pci_register_read(rt2x00dev, CSR19, ®); rt2x00_set_field32(®, CSR19_DIFS, libconf->difs); rt2x00_set_field32(®, CSR19_EIFS, libconf->eifs); rt2x00pci_register_write(rt2x00dev, CSR19, reg); rt2x00pci_register_read(rt2x00dev, TXCSR1, ®); rt2x00_set_field32(®, TXCSR1_TSF_OFFSET, IEEE80211_HEADER); rt2x00_set_field32(®, TXCSR1_AUTORESPONDER, 1); rt2x00pci_register_write(rt2x00dev, TXCSR1, reg); rt2x00pci_register_read(rt2x00dev, CSR12, ®); rt2x00_set_field32(®, CSR12_BEACON_INTERVAL, libconf->conf->beacon_int * 16); rt2x00_set_field32(®, CSR12_CFP_MAX_DURATION, libconf->conf->beacon_int * 16); rt2x00pci_register_write(rt2x00dev, CSR12, reg);}static void rt2500pci_config(struct rt2x00_dev *rt2x00dev, const unsigned int flags, struct rt2x00lib_conf *libconf){ if (flags & CONFIG_UPDATE_PHYMODE) rt2500pci_config_phymode(rt2x00dev, libconf->basic_rates); if (flags & CONFIG_UPDATE_CHANNEL) rt2500pci_config_channel(rt2x00dev, &libconf->rf, libconf->conf->power_level); if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL)) rt2500pci_config_txpower(rt2x00dev, libconf->conf->power_level); if (flags & CONFIG_UPDATE_ANTENNA) rt2500pci_config_antenna(rt2x00dev, libconf->conf->antenna_sel_tx, libconf->conf->antenna_sel_rx); if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT)) rt2500pci_config_duration(rt2x00dev, libconf);}/* * LED functions. */static void rt2500pci_enable_led(struct rt2x00_dev *rt2x00dev){ u32 reg; rt2x00pci_register_read(rt2x00dev, LEDCSR, ®); rt2x00_set_field32(®, LEDCSR_ON_PERIOD, 70); rt2x00_set_field32(®, LEDCSR_OFF_PERIOD, 30); if (rt2x00dev->led_mode == LED_MODE_TXRX_ACTIVITY) { rt2x00_set_field32(®, LEDCSR_LINK, 1); rt2x00_set_field32(®, LEDCSR_ACTIVITY, 0); } else if (rt2x00dev->led_mode == LED_MODE_ASUS) { rt2x00_set_field32(®, LEDCSR_LINK, 0); rt2x00_set_field32(®, LEDCSR_ACTIVITY, 1); } else { rt2x00_set_field32(®, LEDCSR_LINK, 1); rt2x00_set_field32(®, LEDCSR_ACTIVITY, 1); } rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);}static void rt2500pci_disable_led(struct rt2x00_dev *rt2x00dev){ u32 reg; rt2x00pci_register_read(rt2x00dev, LEDCSR, ®); rt2x00_set_field32(®, LEDCSR_LINK, 0); rt2x00_set_field32(®, LEDCSR_ACTIVITY, 0); rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);}/* * Link tuning */static void rt2500pci_link_stats(struct rt2x00_dev *rt2x00dev){ u32 reg; /* * Update FCS error count from register. */ rt2x00pci_register_read(rt2x00dev, CNT0, ®); rt2x00dev->link.rx_failed = rt2x00_get_field32(reg, CNT0_FCS_ERROR); /* * Update False CCA count from register. */ rt2x00pci_register_read(rt2x00dev, CNT3, ®); rt2x00dev->link.false_cca = rt2x00_get_field32(reg, CNT3_FALSE_CCA);}static void rt2500pci_reset_tuner(struct rt2x00_dev *rt2x00dev){ rt2500pci_bbp_write(rt2x00dev, 17, 0x48); rt2x00dev->link.vgc_level = 0x48;}static void rt2500pci_link_tuner(struct rt2x00_dev *rt2x00dev){ int rssi = rt2x00_get_link_rssi(&rt2x00dev->link); u8 r17; /* * To prevent collisions with MAC ASIC on chipsets * up to version C the link tuning should halt after 20 * seconds. */ if (rt2x00_rev(&rt2x00dev->chip) < RT2560_VERSION_D && rt2x00dev->link.count > 20) return; rt2500pci_bbp_read(rt2x00dev, 17, &r17); /* * Chipset versions C and lower should directly continue * to the dynamic CCA tuning. */ if (rt2x00_rev(&rt2x00dev->chip) < RT2560_VERSION_D) goto dynamic_cca_tune; /* * A too low RSSI will cause too much false CCA which will * then corrupt the R17 tuning. To remidy this the tuning should * be stopped (While making sure the R17 value will not exceed limits) */ if (rssi < -80 && rt2x00dev->link.count > 20) { if (r17 >= 0x41) { r17 = rt2x00dev->link.vgc_level; rt2500pci_bbp_write(rt2x00dev, 17, r17); } return; } /* * Special big-R17 for short distance */ if (rssi >= -58) { if (r17 != 0x50) rt2500pci_bbp_write(rt2x00dev, 17, 0x50); return; } /* * Special mid-R17 for middle distance */ if (rssi >= -74) { if (r17 != 0x41) rt2500pci_bbp_write(rt2x00dev, 17, 0x41); return; } /* * Leave short or middle distance condition, restore r17 * to the dynamic tuning range. */ if (r17 >= 0x41) { rt2500pci_bbp_write(rt2x00dev, 17, rt2x00dev->link.vgc_level); return; }dynamic_cca_tune: /* * R17 is inside the dynamic tuning range, * start tuning the link based on the false cca counter. */ if (rt2x00dev->link.false_cca > 512 && r17 < 0x40) { rt2500pci_bbp_write(rt2x00dev, 17, ++r17); rt2x00dev->link.vgc_level = r17; } else if (rt2x00dev->link.false_cca < 100 && r17 > 0x32) { rt2500pci_bbp_write(rt2x00dev, 17, --r17); rt2x00dev->link.vgc_level = r17; }}/* * Initialization functions. */static void rt2500pci_init_rxring(struct rt2x00_dev *rt2x00dev){ struct data_ring *ring = rt2x00dev->rx; struct data_desc *rxd; unsigned int i; u32 word; memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring)); for (i = 0; i < ring->stats.limit; i++) { rxd = ring->entry[i].priv; rt2x00_desc_read(rxd, 1, &word); rt2x00_set_field32(&word, RXD_W1_BUFFER_ADDRESS, ring->entry[i].data_dma); rt2x00_desc_write(rxd, 1, word); rt2x00_desc_read(rxd, 0, &word); rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1); rt2x00_desc_write(rxd, 0, word); } rt2x00_ring_index_clear(rt2x00dev->rx);}static void rt2500pci_init_txring(struct rt2x00_dev *rt2x00dev, const int queue){ struct data_ring *ring = rt2x00lib_get_ring(rt2x00dev, queue); struct data_desc *txd; unsigned int i; u32 word; memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring)); for (i = 0; i < ring->stats.limit; i++) { txd = ring->entry[i].priv; rt2x00_desc_read(txd, 1, &word); rt2x00_set_field32(&word, TXD_W1_BUFFER_ADDRESS, ring->entry[i].data_dma); rt2x00_desc_write(txd, 1, word); rt2x00_desc_read(txd, 0, &word); rt2x00_set_field32(&word, TXD_W0_VALID, 0); rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0); rt2x00_desc_write(txd, 0, word); } rt2x00_ring_index_clear(ring);}static int rt2500pci_init_rings(struct rt2x00_dev *rt2x00dev){ u32 reg; /* * Initialize rings. */ rt2500pci_init_rxring(rt2x00dev); rt2500pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA0); rt2500pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA1); rt2500pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_AFTER_BEACON); rt2500pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON); /* * Initialize registers. */ rt2x00pci_register_read(rt2x00dev, TXCSR2, ®); rt2x00_set_field32(®, TXCSR2_TXD_SIZE, rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].desc_size); rt2x00_set_field32(®, TXCSR2_NUM_TXD, rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].stats.limit); rt2x00_set_field32(®, TXCSR2_NUM_ATIM, rt2x00dev->bcn[1].stats.limit); rt2x00_set_field32(®, TXCSR2_NUM_PRIO, rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].stats.limit); rt2x00pci_register_write(rt2x00dev, TXCSR2, reg); rt2x00pci_register_read(rt2x00dev, TXCSR3, ®); rt2x00_set_field32(®, TXCSR3_TX_RING_REGISTER, rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].data_dma); rt2x00pci_register_write(rt2x00dev, TXCSR3, reg); rt2x00pci_register_read(rt2x00dev, TXCSR5, ®); rt2x00_set_field32(®, TXCSR5_PRIO_RING_REGISTER, rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].data_dma); rt2x00pci_register_write(rt2x00dev, TXCSR5, reg); rt2x00pci_register_read(rt2x00dev, TXCSR4, ®); rt2x00_set_field32(®, TXCSR4_ATIM_RING_REGISTER, rt2x00dev->bcn[1].data_dma); rt2x00pci_register_write(rt2x00dev, TXCSR4, reg); rt2x00pci_register_read(rt2x00dev, TXCSR6, ®); rt2x00_set_field32(®, TXCSR6_BEACON_RING_REGISTER, rt2x00dev->bcn[0].data_dma); rt2x00pci_register_write(rt2x00dev, TXCSR6, reg); rt2x00pci_register_read(rt2x00dev, RXCSR1, ®); rt2x00_set_field32(®, RXCSR1_RXD_SIZE, rt2x00dev->rx->desc_size); rt2x00_set_field32(®, RXCSR1_NUM_RXD, rt2x00dev->rx->stats.limit); rt2x00pci_register_write(rt2x00dev, RXCSR1, reg); rt2x00pci_register_read(rt2x00dev, RXCSR2, ®); rt2x00_set_field32(®, RXCSR2_RX_RING_REGISTER, rt2x00dev->rx->data_dma); rt2x00pci_register_write(rt2x00dev, RXCSR2, reg); return 0;}static int rt2500pci_init_registers(struct rt2x00_dev *rt2x00dev){ u32 reg; rt2x00pci_register_write(rt2x00dev, PSCSR0, 0x00020002); rt2x00pci_register_write(rt2x00dev, PSCSR1, 0x00000002); rt2x00pci_register_write(rt2x00dev, PSCSR2, 0x00020002); rt2x00pci_register_write(rt2x00dev, PSCSR3, 0x00000002); rt2x00pci_register_read(rt2x00dev, TIMECSR, ®); rt2x00_set_field32(®, TIMECSR_US_COUNT, 33); rt2x00_set_field32(®, TIMECSR_US_64_COUNT, 63); rt2x00_set_field32(®, TIMECSR_BEACON_EXPECT, 0); rt2x00pci_register_write(rt2x00dev, TIMECSR, reg); rt2x00pci_register_read(rt2x00dev, CSR9, ®); rt2x00_set_field32(®, CSR9_MAX_FRAME_UNIT, rt2x00dev->rx->data_size / 128); rt2x00pci_register_write(rt2x00dev, CSR9, reg); /* * Always use CWmin and CWmax set in descriptor. */ rt2x00pci_register_read(rt2x00dev, CSR11, ®); rt2x00_set_field32(®, CSR11_CW_SELECT, 0); rt2x00pci_register_write(rt2x00dev, CSR11, reg); rt2x00pci_register_write(rt2x00dev, CNT3, 0); rt2x00pci_register_read(rt2x00dev, TXCSR8, ®); rt2x00_set_field32(®, TXCSR8_BBP_ID0, 10); rt2x00_set_field32(®, TXCSR8_BBP_ID0_VALID, 1); rt2x00_set_field32(®, TXCSR8_BBP_ID1, 11); rt2x00_set_field32(®, TXCSR8_BBP_ID1_VALID, 1); rt2x00_set_field32(®, TXCSR8_BBP_ID2, 13); rt2x00_set_field32(®, TXCSR8_BBP_ID2_VALID, 1); rt2x00_set_field32(®, TXCSR8_BBP_ID3, 12); rt2x00_set_field32(®, TXCSR8_BBP_ID3_VALID, 1); rt2x00pci_register_write(rt2x00dev, TXCSR8, reg); rt2x00pci_register_read(rt2x00dev, ARTCSR0, ®); rt2x00_set_field32(®, ARTCSR0_ACK_CTS_1MBS, 112); rt2x00_set_field32(®, ARTCSR0_ACK_CTS_2MBS, 56); rt2x00_set_field32(®, ARTCSR0_ACK_CTS_5_5MBS, 20); rt2x00_set_field32(®, ARTCSR0_ACK_CTS_11MBS, 10); rt2x00pci_register_write(rt2x00dev, ARTCSR0, reg); rt2x00pci_register_read(rt2x00dev, ARTCSR1, ®); rt2x00_set_field32(®, ARTCSR1_ACK_CTS_6MBS, 45); rt2x00_set_field32(®, ARTCSR1_ACK_CTS_9MBS, 37); rt2x00_set_field32(®, ARTCSR1_ACK_CTS_12MBS, 33); rt2x00_set_field32(®, ARTCSR1_ACK_CTS_18MBS, 29); rt2x00pci_register_write(rt2x00dev, ARTCSR1, reg); rt2x00pci_register_read(rt2x00dev, ARTCSR2, ®); rt2x00_set_field32(®, ARTCSR2_ACK_CTS_24MBS, 29); rt2x00_set_field32(®, ARTCSR2_ACK_CTS_36MBS, 25); rt2x00_set_field32(®, ARTCSR2_ACK_CTS_48MBS, 25); rt2x00_set_field32(®, ARTCSR2_ACK_CTS_54MBS, 25); rt2x00pci_register_write(rt2x00dev, ARTCSR2, reg); rt2x00pci_register_read(rt2x00dev, RXCSR3, ®); rt2x00_set_field32(®, RXCSR3_BBP_ID0, 47); /* CCK Signal */ rt2x00_set_field32(®, RXCSR3_BBP_ID0_VALID, 1); rt2x00_set_field32(®, RXCSR3_BBP_ID1, 51); /* Rssi */ rt2x00_set_field32(®, RXCSR3_BBP_ID1_VALID, 1); rt2x00_set_field32(®, RXCSR3_BBP_ID2, 42); /* OFDM Rate */ rt2x00_set_field32(®, RXCSR3_BBP_ID2_VALID, 1); rt2x00_set_field32(®, RXCSR3_BBP_ID3, 51); /* RSSI */ rt2x00_set_field32(®, RXCSR3_BBP_ID3_VALID, 1); rt2x00pci_register_write(rt2x00dev, RXCSR3, reg); rt2x00pci_register_read(rt2x00dev, PCICSR, ®); rt2x00_set_field32(®, PCICSR_BIG_ENDIAN, 0); rt2x00_set_field32(®, PCICSR_RX_TRESHOLD, 0); rt2x00_set_field32(®, PCICSR_TX_TRESHOLD, 3); rt2x00_set_field32(®, PCICSR_BURST_LENTH, 1); rt2x00_set_field32(®, PCICSR_ENABLE_CLK, 1); rt2x00_set_field32(®, PCICSR_READ_MULTIPLE, 1); rt2x00_set_field32(®, PCICSR_WRITE_INVALID, 1); rt2x00pci_register_write(rt2x00dev, PCICSR, reg); rt2x00pci_register_write(rt2x00dev, PWRCSR0, 0x3f3b3100); rt2x00pci_register_write(rt2x00dev, GPIOCSR, 0x0000ff00); rt2x00pci_register_write(rt2x00dev, TESTCSR, 0x000000f0); if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE)) return -EBUSY; rt2x00pci_register_write(rt2x00dev, MACCSR0, 0x00213223); rt2x00pci_register_write(rt2x00dev, MACCSR1, 0x00235518); rt2x00pci_register_read(rt2x00dev, MACCSR2, ®); rt2x00_set_field32(®, MACCSR2_DELAY, 64); rt2x00pci_register_write(rt2x00dev, MACCSR2, reg); rt2x00pci_register_read(rt2x00dev, RALINKCSR, ®); rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA0, 17); rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID0, 26); rt2x00_set_field32(®, RALINKCSR_AR_BBP_VALID0, 1); rt2x00_set_field32(®, RALINKCSR_AR_BBP_DATA1, 0); rt2x00_set_field32(®, RALINKCSR_AR_BBP_ID1, 26); rt2x00_set_field32(®, RALINKCSR_AR_BBP_VALID1, 1); rt2x00pci_register_write(rt2x00dev, RALINKCSR, reg); rt2x00pci_register_write(rt2x00dev, BBPCSR1, 0x82188200); rt2x00pci_register_write(rt2x00dev, TXACKCSR0, 0x00000020); rt2x00pci_register_read(rt2x00dev, CSR1, ®); rt2x00_set_field32(®, CSR1_SOFT_RESET, 1); rt2x00_set_field32(®, CSR1_BBP_RESET, 0); rt2x00_set_field32(®, CSR1_HOST_READY, 0); rt2x00pci_register_write(rt2x00dev, CSR1, reg); rt2x00pci_register_read(rt2x00dev, CSR1, ®); rt2x00_set_field32(®, CSR1_SOFT_RESET, 0); rt2x00_set_field32(®, CSR1_HOST_READY, 1); rt2x00pci_register_write(rt2x00dev, CSR1, reg); /* * We must clear the FCS and FIFO error count. * These registers are cleared on read, * so we may pass a useless variable to store the value. */ rt2x00pci_register_read(rt2x00dev, CNT0, ®); rt2x00pci_register_read(rt2x00dev, CNT4, ®); return 0;}static int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev){ unsigned int i; u16 eeprom; u8 reg_id; u8 value; for (i = 0; i < REGISTER_BUSY_COUNT; i++) { rt2500pci_bbp_read(rt2x00dev, 0, &value); if ((value != 0xff) && (value != 0x00)) goto continue_csr_init; NOTICE(rt2x00dev, "Waiting for BBP register.\n"); udelay(REGISTER_BUSY_DELAY); } ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); return -EACCES;continue_csr_init: rt2500pci_bbp_write(rt2x00dev, 3, 0x02); rt2500pci_bbp_write(rt2x00dev, 4, 0x19); rt2500pci_bbp_write(rt2x00dev, 14, 0x1c); rt2500pci_bbp_write(rt2x00dev, 15, 0x30); rt2500pci_bbp_write(rt2x00dev, 16, 0xac); rt2500pci_bbp_write(rt2x00dev, 18, 0x18); rt2500pci_bbp_write(rt2x00dev, 19, 0xff); rt2500pci_bbp_write(rt2x00dev, 20, 0x1e); rt2500pci_bbp_write(rt2x00dev, 21, 0x08); rt2500pci_bbp_write(rt2x00dev, 22, 0x08); rt2500pci_bbp_write(rt2x00dev, 23, 0x08); rt2500pci_bbp_write(rt2x00dev, 24, 0x70); rt2500pci_bbp_write(rt2x00dev, 25, 0x40); rt2500pci_bbp_write(rt2x00dev, 26, 0x08); rt2500pci_bbp_write(rt2x00dev, 27, 0x23); rt2500pci_bbp_write(rt2x00dev, 30, 0x10); rt2500pci_bbp_write(rt2x00dev, 31, 0x2b); rt2500pci_bbp_write(rt2x00dev, 32, 0xb9); rt2500pci_bbp_write(rt2x00dev, 34, 0x12); rt2500pci_bbp_write(rt2x00dev, 35, 0x50); rt2500pci_bbp_write(rt2x00dev, 39, 0xc4); rt2500pci_bbp_write(rt2x00dev, 40, 0x02); rt2500pci_bbp_write(rt2x00dev, 41, 0x60); rt2500pci_bbp_write(rt2x00dev, 53, 0x10); rt2500pci_bbp_write(rt2x00dev, 54, 0x18); rt2500pci_bbp_write(rt2x00dev, 56, 0x08); rt2500pci_bbp_write(rt2x00dev, 57, 0x10); rt2500pci_bbp_write(rt2x00dev, 58, 0x08); rt2500pci_bbp_write(rt2x00dev, 61, 0x6d); rt2500pci_bbp_write(rt2x00dev, 62, 0x10);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -