/drivers/net/wireless/rt2x00/rt2800usb.c
C | 1152 lines | 777 code | 112 blank | 263 comment | 48 complexity | 39245f7a79914b23e72d6bbf0774e1bd MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
- Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
- Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
- Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
- Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
- Copyright (C) 2009 Axel Kollhofer <rain_maker@root-forum.org>
- <http://rt2x00.serialmonkey.com>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the
- Free Software Foundation, Inc.,
- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /*
- Module: rt2800usb
- Abstract: rt2800usb device specific routines.
- Supported chipsets: RT2800U.
- */
- #include <linux/delay.h>
- #include <linux/etherdevice.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/usb.h>
- #include "rt2x00.h"
- #include "rt2x00usb.h"
- #include "rt2800lib.h"
- #include "rt2800.h"
- #include "rt2800usb.h"
- /*
- * Allow hardware encryption to be disabled.
- */
- static int modparam_nohwcrypt;
- module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
- MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
- /*
- * Queue handlers.
- */
- static void rt2800usb_start_queue(struct data_queue *queue)
- {
- struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
- u32 reg;
- switch (queue->qid) {
- case QID_RX:
- rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
- rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
- rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
- break;
- case QID_BEACON:
- rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
- rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1);
- rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1);
- rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
- rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
- break;
- default:
- break;
- }
- }
- static void rt2800usb_stop_queue(struct data_queue *queue)
- {
- struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
- u32 reg;
- switch (queue->qid) {
- case QID_RX:
- rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
- rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 0);
- rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
- break;
- case QID_BEACON:
- rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
- rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
- rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
- rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
- rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
- break;
- default:
- break;
- }
- }
- /*
- * test if there is an entry in any TX queue for which DMA is done
- * but the TX status has not been returned yet
- */
- static bool rt2800usb_txstatus_pending(struct rt2x00_dev *rt2x00dev)
- {
- struct data_queue *queue;
- tx_queue_for_each(rt2x00dev, queue) {
- if (rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE) !=
- rt2x00queue_get_entry(queue, Q_INDEX_DONE))
- return true;
- }
- return false;
- }
- static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
- int urb_status, u32 tx_status)
- {
- if (urb_status) {
- WARNING(rt2x00dev, "rt2x00usb_register_read_async failed: %d\n", urb_status);
- return false;
- }
- /* try to read all TX_STA_FIFO entries before scheduling txdone_work */
- if (rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID)) {
- if (!kfifo_put(&rt2x00dev->txstatus_fifo, &tx_status)) {
- WARNING(rt2x00dev, "TX status FIFO overrun, "
- "drop tx status report.\n");
- queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
- } else
- return true;
- } else if (!kfifo_is_empty(&rt2x00dev->txstatus_fifo)) {
- queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
- } else if (rt2800usb_txstatus_pending(rt2x00dev)) {
- mod_timer(&rt2x00dev->txstatus_timer, jiffies + msecs_to_jiffies(2));
- }
- return false;
- }
- static void rt2800usb_tx_dma_done(struct queue_entry *entry)
- {
- struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
- rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO,
- rt2800usb_tx_sta_fifo_read_completed);
- }
- static void rt2800usb_tx_sta_fifo_timeout(unsigned long data)
- {
- struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
- rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO,
- rt2800usb_tx_sta_fifo_read_completed);
- }
- /*
- * Firmware functions
- */
- static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
- {
- return FIRMWARE_RT2870;
- }
- static int rt2800usb_write_firmware(struct rt2x00_dev *rt2x00dev,
- const u8 *data, const size_t len)
- {
- int status;
- u32 offset;
- u32 length;
- /*
- * Check which section of the firmware we need.
- */
- if (rt2x00_rt(rt2x00dev, RT2860) ||
- rt2x00_rt(rt2x00dev, RT2872) ||
- rt2x00_rt(rt2x00dev, RT3070)) {
- offset = 0;
- length = 4096;
- } else {
- offset = 4096;
- length = 4096;
- }
- /*
- * Write firmware to device.
- */
- rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
- data + offset, length);
- rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
- rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
- /*
- * Send firmware request to device to load firmware,
- * we need to specify a long timeout time.
- */
- status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
- 0, USB_MODE_FIRMWARE,
- REGISTER_TIMEOUT_FIRMWARE);
- if (status < 0) {
- ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
- return status;
- }
- msleep(10);
- rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
- return 0;
- }
- /*
- * Device state switch handlers.
- */
- static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
- {
- u32 reg;
- /*
- * Wait until BBP and RF are ready.
- */
- if (rt2800_wait_csr_ready(rt2x00dev))
- return -EBUSY;
- rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
- rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
- rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
- rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
- rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_CSR, 1);
- rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_BBP, 1);
- rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
- rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
- rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
- USB_MODE_RESET, REGISTER_TIMEOUT);
- rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
- return 0;
- }
- static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
- {
-