xref: /linux/drivers/net/wireless/ralink/rt2x00/rt2800usb.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 	Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
4 	Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
5 	Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
6 	Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
7 	Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
8 	Copyright (C) 2009 Axel Kollhofer <rain_maker@root-forum.org>
9 	<http://rt2x00.serialmonkey.com>
10 
11  */
12 
13 /*
14 	Module: rt2800usb
15 	Abstract: rt2800usb device specific routines.
16 	Supported chipsets: RT2800U.
17  */
18 
19 #include <linux/delay.h>
20 #include <linux/etherdevice.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/usb.h>
24 
25 #include "rt2x00.h"
26 #include "rt2x00usb.h"
27 #include "rt2800lib.h"
28 #include "rt2800.h"
29 #include "rt2800usb.h"
30 
31 /*
32  * Allow hardware encryption to be disabled.
33  */
34 static bool modparam_nohwcrypt;
35 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444);
36 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
37 
rt2800usb_hwcrypt_disabled(struct rt2x00_dev * rt2x00dev)38 static bool rt2800usb_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
39 {
40 	return modparam_nohwcrypt;
41 }
42 
43 /*
44  * Queue handlers.
45  */
rt2800usb_start_queue(struct data_queue * queue)46 static void rt2800usb_start_queue(struct data_queue *queue)
47 {
48 	struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
49 	u32 reg;
50 
51 	switch (queue->qid) {
52 	case QID_RX:
53 		reg = rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL);
54 		rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
55 		rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
56 		break;
57 	case QID_BEACON:
58 		reg = rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG);
59 		rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
60 		rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
61 		rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
62 		rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
63 		break;
64 	default:
65 		break;
66 	}
67 }
68 
rt2800usb_stop_queue(struct data_queue * queue)69 static void rt2800usb_stop_queue(struct data_queue *queue)
70 {
71 	struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
72 	u32 reg;
73 
74 	switch (queue->qid) {
75 	case QID_RX:
76 		reg = rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL);
77 		rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
78 		rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
79 		break;
80 	case QID_BEACON:
81 		reg = rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG);
82 		rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
83 		rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
84 		rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
85 		rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
86 		break;
87 	default:
88 		break;
89 	}
90 }
91 
92 #define TXSTATUS_READ_INTERVAL 1000000
93 
rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev * rt2x00dev,int urb_status,u32 tx_status)94 static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
95 						 int urb_status, u32 tx_status)
96 {
97 	bool valid;
98 
99 	if (urb_status) {
100 		rt2x00_warn(rt2x00dev, "TX status read failed %d\n",
101 			    urb_status);
102 
103 		goto stop_reading;
104 	}
105 
106 	valid = rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID);
107 	if (valid) {
108 		if (!kfifo_put(&rt2x00dev->txstatus_fifo, tx_status))
109 			rt2x00_warn(rt2x00dev, "TX status FIFO overrun\n");
110 
111 		queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
112 
113 		/* Reschedule urb to read TX status again instantly */
114 		return true;
115 	}
116 
117 	/* Check if there is any entry that timedout waiting on TX status */
118 	if (rt2800_txstatus_timeout(rt2x00dev))
119 		queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
120 
121 	if (rt2800_txstatus_pending(rt2x00dev)) {
122 		/* Read register after 1 ms */
123 		hrtimer_start(&rt2x00dev->txstatus_timer,
124 			      TXSTATUS_READ_INTERVAL,
125 			      HRTIMER_MODE_REL);
126 		return false;
127 	}
128 
129 stop_reading:
130 	clear_bit(TX_STATUS_READING, &rt2x00dev->flags);
131 	/*
132 	 * There is small race window above, between txstatus pending check and
133 	 * clear_bit someone could do rt2x00usb_interrupt_txdone, so recheck
134 	 * here again if status reading is needed.
135 	 */
136 	if (rt2800_txstatus_pending(rt2x00dev) &&
137 	    !test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
138 		return true;
139 	else
140 		return false;
141 }
142 
rt2800usb_async_read_tx_status(struct rt2x00_dev * rt2x00dev)143 static void rt2800usb_async_read_tx_status(struct rt2x00_dev *rt2x00dev)
144 {
145 
146 	if (test_and_set_bit(TX_STATUS_READING, &rt2x00dev->flags))
147 		return;
148 
149 	/* Read TX_STA_FIFO register after 2 ms */
150 	hrtimer_start(&rt2x00dev->txstatus_timer,
151 		      2 * TXSTATUS_READ_INTERVAL,
152 		      HRTIMER_MODE_REL);
153 }
154 
rt2800usb_tx_dma_done(struct queue_entry * entry)155 static void rt2800usb_tx_dma_done(struct queue_entry *entry)
156 {
157 	struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
158 
159 	rt2800usb_async_read_tx_status(rt2x00dev);
160 }
161 
rt2800usb_tx_sta_fifo_timeout(struct hrtimer * timer)162 static enum hrtimer_restart rt2800usb_tx_sta_fifo_timeout(struct hrtimer *timer)
163 {
164 	struct rt2x00_dev *rt2x00dev =
165 	    container_of(timer, struct rt2x00_dev, txstatus_timer);
166 
167 	rt2x00usb_register_read_async(rt2x00dev, TX_STA_FIFO,
168 				      rt2800usb_tx_sta_fifo_read_completed);
169 
170 	return HRTIMER_NORESTART;
171 }
172 
173 /*
174  * Firmware functions
175  */
rt2800usb_autorun_detect(struct rt2x00_dev * rt2x00dev)176 static int rt2800usb_autorun_detect(struct rt2x00_dev *rt2x00dev)
177 {
178 	__le32 *reg;
179 	u32 fw_mode;
180 	int ret;
181 
182 	reg = kmalloc(sizeof(*reg), GFP_KERNEL);
183 	if (reg == NULL)
184 		return -ENOMEM;
185 	/* cannot use rt2x00usb_register_read here as it uses different
186 	 * mode (MULTI_READ vs. DEVICE_MODE) and does not pass the
187 	 * magic value USB_MODE_AUTORUN (0x11) to the device, thus the
188 	 * returned value would be invalid.
189 	 */
190 	ret = rt2x00usb_vendor_request(rt2x00dev, USB_DEVICE_MODE,
191 				       USB_VENDOR_REQUEST_IN, 0,
192 				       USB_MODE_AUTORUN, reg, sizeof(*reg),
193 				       REGISTER_TIMEOUT_FIRMWARE);
194 	fw_mode = le32_to_cpu(*reg);
195 	kfree(reg);
196 	if (ret < 0)
197 		return ret;
198 
199 	if ((fw_mode & 0x00000003) == 2)
200 		return 1;
201 
202 	return 0;
203 }
204 
rt2800usb_get_firmware_name(struct rt2x00_dev * rt2x00dev)205 static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
206 {
207 	return FIRMWARE_RT2870;
208 }
209 
rt2800usb_write_firmware(struct rt2x00_dev * rt2x00dev,const u8 * data,const size_t len)210 static int rt2800usb_write_firmware(struct rt2x00_dev *rt2x00dev,
211 				    const u8 *data, const size_t len)
212 {
213 	int status;
214 	u32 offset;
215 	u32 length;
216 	int retval;
217 
218 	/*
219 	 * Check which section of the firmware we need.
220 	 */
221 	if (rt2x00_rt(rt2x00dev, RT2860) ||
222 	    rt2x00_rt(rt2x00dev, RT2872) ||
223 	    rt2x00_rt(rt2x00dev, RT3070)) {
224 		offset = 0;
225 		length = 4096;
226 	} else {
227 		offset = 4096;
228 		length = 4096;
229 	}
230 
231 	/*
232 	 * Write firmware to device.
233 	 */
234 	retval = rt2800usb_autorun_detect(rt2x00dev);
235 	if (retval < 0)
236 		return retval;
237 	if (retval) {
238 		rt2x00_info(rt2x00dev,
239 			    "Firmware loading not required - NIC in AutoRun mode\n");
240 		__clear_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
241 	} else {
242 		rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
243 					      data + offset, length);
244 	}
245 
246 	rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
247 	rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
248 
249 	/*
250 	 * Send firmware request to device to load firmware,
251 	 * we need to specify a long timeout time.
252 	 */
253 	status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
254 					     0, USB_MODE_FIRMWARE,
255 					     REGISTER_TIMEOUT_FIRMWARE);
256 	if (status < 0) {
257 		rt2x00_err(rt2x00dev, "Failed to write Firmware to device\n");
258 		return status;
259 	}
260 
261 	msleep(10);
262 	rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
263 
264 	return 0;
265 }
266 
267 /*
268  * Device state switch handlers.
269  */
rt2800usb_init_registers(struct rt2x00_dev * rt2x00dev)270 static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
271 {
272 	u32 reg;
273 
274 	/*
275 	 * Wait until BBP and RF are ready.
276 	 */
277 	if (rt2800_wait_csr_ready(rt2x00dev))
278 		return -EBUSY;
279 
280 	reg = rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL);
281 	rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
282 
283 	reg = 0;
284 	rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
285 	rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
286 	rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
287 
288 	rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
289 				    USB_MODE_RESET, REGISTER_TIMEOUT);
290 
291 	rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
292 
293 	return 0;
294 }
295 
rt2800usb_enable_radio(struct rt2x00_dev * rt2x00dev)296 static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
297 {
298 	u32 reg = 0;
299 
300 	if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev)))
301 		return -EIO;
302 
303 	rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
304 	rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN, 0);
305 	rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
306 	/*
307 	 * Total room for RX frames in kilobytes, PBF might still exceed
308 	 * this limit so reduce the number to prevent errors.
309 	 */
310 	rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
311 			   ((rt2x00dev->rx->limit * DATA_FRAME_SIZE)
312 			    / 1024) - 3);
313 	rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
314 	rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
315 	rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg);
316 
317 	return rt2800_enable_radio(rt2x00dev);
318 }
319 
rt2800usb_disable_radio(struct rt2x00_dev * rt2x00dev)320 static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
321 {
322 	rt2800_disable_radio(rt2x00dev);
323 }
324 
rt2800usb_set_state(struct rt2x00_dev * rt2x00dev,enum dev_state state)325 static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
326 			       enum dev_state state)
327 {
328 	if (state == STATE_AWAKE)
329 		rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 2);
330 	else
331 		rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0xff, 2);
332 
333 	return 0;
334 }
335 
rt2800usb_set_device_state(struct rt2x00_dev * rt2x00dev,enum dev_state state)336 static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
337 				      enum dev_state state)
338 {
339 	int retval = 0;
340 
341 	switch (state) {
342 	case STATE_RADIO_ON:
343 		/*
344 		 * Before the radio can be enabled, the device first has
345 		 * to be woken up. After that it needs a bit of time
346 		 * to be fully awake and then the radio can be enabled.
347 		 */
348 		rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
349 		msleep(1);
350 		retval = rt2800usb_enable_radio(rt2x00dev);
351 		break;
352 	case STATE_RADIO_OFF:
353 		/*
354 		 * After the radio has been disabled, the device should
355 		 * be put to sleep for powersaving.
356 		 */
357 		rt2800usb_disable_radio(rt2x00dev);
358 		rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
359 		break;
360 	case STATE_RADIO_IRQ_ON:
361 	case STATE_RADIO_IRQ_OFF:
362 		/* No support, but no error either */
363 		break;
364 	case STATE_DEEP_SLEEP:
365 	case STATE_SLEEP:
366 	case STATE_STANDBY:
367 	case STATE_AWAKE:
368 		retval = rt2800usb_set_state(rt2x00dev, state);
369 		break;
370 	default:
371 		retval = -ENOTSUPP;
372 		break;
373 	}
374 
375 	if (unlikely(retval))
376 		rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
377 			   state, retval);
378 
379 	return retval;
380 }
381 
rt2800usb_get_dma_done(struct data_queue * queue)382 static unsigned int rt2800usb_get_dma_done(struct data_queue *queue)
383 {
384 	struct queue_entry *entry;
385 
386 	entry = rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE);
387 	return entry->entry_idx;
388 }
389 
390 /*
391  * TX descriptor initialization
392  */
rt2800usb_get_txwi(struct queue_entry * entry)393 static __le32 *rt2800usb_get_txwi(struct queue_entry *entry)
394 {
395 	if (entry->queue->qid == QID_BEACON)
396 		return (__le32 *) (entry->skb->data);
397 	else
398 		return (__le32 *) (entry->skb->data + TXINFO_DESC_SIZE);
399 }
400 
rt2800usb_write_tx_desc(struct queue_entry * entry,struct txentry_desc * txdesc)401 static void rt2800usb_write_tx_desc(struct queue_entry *entry,
402 				    struct txentry_desc *txdesc)
403 {
404 	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
405 	__le32 *txi = (__le32 *) entry->skb->data;
406 	u32 word;
407 
408 	/*
409 	 * Initialize TXINFO descriptor
410 	 */
411 	word = rt2x00_desc_read(txi, 0);
412 
413 	/*
414 	 * The size of TXINFO_W0_USB_DMA_TX_PKT_LEN is
415 	 * TXWI + 802.11 header + L2 pad + payload + pad,
416 	 * so need to decrease size of TXINFO.
417 	 */
418 	rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
419 			   roundup(entry->skb->len, 4) - TXINFO_DESC_SIZE);
420 	rt2x00_set_field32(&word, TXINFO_W0_WIV,
421 			   !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
422 	rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
423 	rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
424 	rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
425 	rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
426 			   test_bit(ENTRY_TXD_BURST, &txdesc->flags));
427 	rt2x00_desc_write(txi, 0, word);
428 
429 	/*
430 	 * Register descriptor details in skb frame descriptor.
431 	 */
432 	skbdesc->flags |= SKBDESC_DESC_IN_SKB;
433 	skbdesc->desc = txi;
434 	skbdesc->desc_len = TXINFO_DESC_SIZE + entry->queue->winfo_size;
435 }
436 
437 /*
438  * TX data initialization
439  */
rt2800usb_get_tx_data_len(struct queue_entry * entry)440 static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
441 {
442 	/*
443 	 * pad(1~3 bytes) is needed after each 802.11 payload.
444 	 * USB end pad(4 bytes) is needed at each USB bulk out packet end.
445 	 * TX frame format is :
446 	 * | TXINFO | TXWI | 802.11 header | L2 pad | payload | pad | USB end pad |
447 	 *                 |<------------- tx_pkt_len ------------->|
448 	 */
449 
450 	return roundup(entry->skb->len, 4) + 4;
451 }
452 
453 /*
454  * TX control handlers
455  */
rt2800usb_work_txdone(struct work_struct * work)456 static void rt2800usb_work_txdone(struct work_struct *work)
457 {
458 	struct rt2x00_dev *rt2x00dev =
459 	    container_of(work, struct rt2x00_dev, txdone_work);
460 
461 	while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
462 	       rt2800_txstatus_timeout(rt2x00dev)) {
463 
464 		rt2800_txdone(rt2x00dev, UINT_MAX);
465 
466 		rt2800_txdone_nostatus(rt2x00dev);
467 
468 		/*
469 		 * The hw may delay sending the packet after DMA complete
470 		 * if the medium is busy, thus the TX_STA_FIFO entry is
471 		 * also delayed -> use a timer to retrieve it.
472 		 */
473 		if (rt2800_txstatus_pending(rt2x00dev))
474 			rt2800usb_async_read_tx_status(rt2x00dev);
475 	}
476 }
477 
478 /*
479  * RX control handlers
480  */
rt2800usb_fill_rxdone(struct queue_entry * entry,struct rxdone_entry_desc * rxdesc)481 static void rt2800usb_fill_rxdone(struct queue_entry *entry,
482 				  struct rxdone_entry_desc *rxdesc)
483 {
484 	struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
485 	__le32 *rxi = (__le32 *)entry->skb->data;
486 	__le32 *rxd;
487 	u32 word;
488 	int rx_pkt_len;
489 
490 	/*
491 	 * Copy descriptor to the skbdesc->desc buffer, making it safe from
492 	 * moving of frame data in rt2x00usb.
493 	 */
494 	memcpy(skbdesc->desc, rxi, skbdesc->desc_len);
495 
496 	/*
497 	 * RX frame format is :
498 	 * | RXINFO | RXWI | header | L2 pad | payload | pad | RXD | USB pad |
499 	 *          |<------------ rx_pkt_len -------------->|
500 	 */
501 	word = rt2x00_desc_read(rxi, 0);
502 	rx_pkt_len = rt2x00_get_field32(word, RXINFO_W0_USB_DMA_RX_PKT_LEN);
503 
504 	/*
505 	 * Remove the RXINFO structure from the sbk.
506 	 */
507 	skb_pull(entry->skb, RXINFO_DESC_SIZE);
508 
509 	/*
510 	 * Check for rx_pkt_len validity. Return if invalid, leaving
511 	 * rxdesc->size zeroed out by the upper level.
512 	 */
513 	if (unlikely(rx_pkt_len == 0 ||
514 			rx_pkt_len > entry->queue->data_size)) {
515 		rt2x00_err(entry->queue->rt2x00dev,
516 			   "Bad frame size %d, forcing to 0\n", rx_pkt_len);
517 		return;
518 	}
519 
520 	rxd = (__le32 *)(entry->skb->data + rx_pkt_len);
521 
522 	/*
523 	 * It is now safe to read the descriptor on all architectures.
524 	 */
525 	word = rt2x00_desc_read(rxd, 0);
526 
527 	if (rt2x00_get_field32(word, RXD_W0_CRC_ERROR))
528 		rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
529 
530 	rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W0_CIPHER_ERROR);
531 
532 	if (rt2x00_get_field32(word, RXD_W0_DECRYPTED)) {
533 		/*
534 		 * Hardware has stripped IV/EIV data from 802.11 frame during
535 		 * decryption. Unfortunately the descriptor doesn't contain
536 		 * any fields with the EIV/IV data either, so they can't
537 		 * be restored by rt2x00lib.
538 		 */
539 		rxdesc->flags |= RX_FLAG_IV_STRIPPED;
540 
541 		/*
542 		 * The hardware has already checked the Michael Mic and has
543 		 * stripped it from the frame. Signal this to mac80211.
544 		 */
545 		rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
546 
547 		if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS) {
548 			rxdesc->flags |= RX_FLAG_DECRYPTED;
549 		} else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC) {
550 			/*
551 			 * In order to check the Michael Mic, the packet must have
552 			 * been decrypted.  Mac80211 doesnt check the MMIC failure
553 			 * flag to initiate MMIC countermeasures if the decoded flag
554 			 * has not been set.
555 			 */
556 			rxdesc->flags |= RX_FLAG_DECRYPTED;
557 
558 			rxdesc->flags |= RX_FLAG_MMIC_ERROR;
559 		}
560 	}
561 
562 	if (rt2x00_get_field32(word, RXD_W0_MY_BSS))
563 		rxdesc->dev_flags |= RXDONE_MY_BSS;
564 
565 	if (rt2x00_get_field32(word, RXD_W0_L2PAD))
566 		rxdesc->dev_flags |= RXDONE_L2PAD;
567 
568 	/*
569 	 * Remove RXD descriptor from end of buffer.
570 	 */
571 	skb_trim(entry->skb, rx_pkt_len);
572 
573 	/*
574 	 * Process the RXWI structure.
575 	 */
576 	rt2800_process_rxwi(entry, rxdesc);
577 }
578 
579 /*
580  * Device probe functions.
581  */
rt2800usb_efuse_detect(struct rt2x00_dev * rt2x00dev)582 static int rt2800usb_efuse_detect(struct rt2x00_dev *rt2x00dev)
583 {
584 	int retval;
585 
586 	retval = rt2800usb_autorun_detect(rt2x00dev);
587 	if (retval < 0)
588 		return retval;
589 	if (retval)
590 		return 1;
591 	return rt2800_efuse_detect(rt2x00dev);
592 }
593 
rt2800usb_read_eeprom(struct rt2x00_dev * rt2x00dev)594 static int rt2800usb_read_eeprom(struct rt2x00_dev *rt2x00dev)
595 {
596 	int retval;
597 
598 	retval = rt2800usb_efuse_detect(rt2x00dev);
599 	if (retval < 0)
600 		return retval;
601 	if (retval)
602 		retval = rt2800_read_eeprom_efuse(rt2x00dev);
603 	else
604 		retval = rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom,
605 					       EEPROM_SIZE);
606 
607 	return retval;
608 }
609 
rt2800usb_probe_hw(struct rt2x00_dev * rt2x00dev)610 static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
611 {
612 	int retval;
613 
614 	retval = rt2800_probe_hw(rt2x00dev);
615 	if (retval)
616 		return retval;
617 
618 	/*
619 	 * Set txstatus timer function.
620 	 */
621 	rt2x00dev->txstatus_timer.function = rt2800usb_tx_sta_fifo_timeout;
622 
623 	/*
624 	 * Overwrite TX done handler
625 	 */
626 	INIT_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone);
627 
628 	return 0;
629 }
630 
631 static const struct ieee80211_ops rt2800usb_mac80211_ops = {
632 	.add_chanctx = ieee80211_emulate_add_chanctx,
633 	.remove_chanctx = ieee80211_emulate_remove_chanctx,
634 	.change_chanctx = ieee80211_emulate_change_chanctx,
635 	.switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
636 	.tx			= rt2x00mac_tx,
637 	.wake_tx_queue		= ieee80211_handle_wake_tx_queue,
638 	.start			= rt2x00mac_start,
639 	.stop			= rt2x00mac_stop,
640 	.add_interface		= rt2x00mac_add_interface,
641 	.remove_interface	= rt2x00mac_remove_interface,
642 	.config			= rt2x00mac_config,
643 	.configure_filter	= rt2x00mac_configure_filter,
644 	.set_tim		= rt2x00mac_set_tim,
645 	.set_key		= rt2x00mac_set_key,
646 	.sw_scan_start		= rt2x00mac_sw_scan_start,
647 	.sw_scan_complete	= rt2x00mac_sw_scan_complete,
648 	.get_stats		= rt2x00mac_get_stats,
649 	.get_key_seq		= rt2800_get_key_seq,
650 	.set_rts_threshold	= rt2800_set_rts_threshold,
651 	.sta_add		= rt2800_sta_add,
652 	.sta_remove		= rt2800_sta_remove,
653 	.bss_info_changed	= rt2x00mac_bss_info_changed,
654 	.conf_tx		= rt2800_conf_tx,
655 	.get_tsf		= rt2800_get_tsf,
656 	.rfkill_poll		= rt2x00mac_rfkill_poll,
657 	.ampdu_action		= rt2800_ampdu_action,
658 	.flush			= rt2x00mac_flush,
659 	.get_survey		= rt2800_get_survey,
660 	.get_ringparam		= rt2x00mac_get_ringparam,
661 	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
662 	.reconfig_complete	= rt2x00mac_reconfig_complete,
663 };
664 
665 static const struct rt2800_ops rt2800usb_rt2800_ops = {
666 	.register_read		= rt2x00usb_register_read,
667 	.register_read_lock	= rt2x00usb_register_read_lock,
668 	.register_write		= rt2x00usb_register_write,
669 	.register_write_lock	= rt2x00usb_register_write_lock,
670 	.register_multiread	= rt2x00usb_register_multiread,
671 	.register_multiwrite	= rt2x00usb_register_multiwrite,
672 	.regbusy_read		= rt2x00usb_regbusy_read,
673 	.read_eeprom		= rt2800usb_read_eeprom,
674 	.hwcrypt_disabled	= rt2800usb_hwcrypt_disabled,
675 	.drv_write_firmware	= rt2800usb_write_firmware,
676 	.drv_init_registers	= rt2800usb_init_registers,
677 	.drv_get_txwi		= rt2800usb_get_txwi,
678 	.drv_get_dma_done	= rt2800usb_get_dma_done,
679 };
680 
681 static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
682 	.probe_hw		= rt2800usb_probe_hw,
683 	.get_firmware_name	= rt2800usb_get_firmware_name,
684 	.check_firmware		= rt2800_check_firmware,
685 	.load_firmware		= rt2800_load_firmware,
686 	.initialize		= rt2x00usb_initialize,
687 	.uninitialize		= rt2x00usb_uninitialize,
688 	.clear_entry		= rt2x00usb_clear_entry,
689 	.set_device_state	= rt2800usb_set_device_state,
690 	.rfkill_poll		= rt2800_rfkill_poll,
691 	.link_stats		= rt2800_link_stats,
692 	.reset_tuner		= rt2800_reset_tuner,
693 	.link_tuner		= rt2800_link_tuner,
694 	.gain_calibration	= rt2800_gain_calibration,
695 	.vco_calibration	= rt2800_vco_calibration,
696 	.watchdog		= rt2800_watchdog,
697 	.start_queue		= rt2800usb_start_queue,
698 	.kick_queue		= rt2x00usb_kick_queue,
699 	.stop_queue		= rt2800usb_stop_queue,
700 	.flush_queue		= rt2x00usb_flush_queue,
701 	.tx_dma_done		= rt2800usb_tx_dma_done,
702 	.write_tx_desc		= rt2800usb_write_tx_desc,
703 	.write_tx_data		= rt2800_write_tx_data,
704 	.write_beacon		= rt2800_write_beacon,
705 	.clear_beacon		= rt2800_clear_beacon,
706 	.get_tx_data_len	= rt2800usb_get_tx_data_len,
707 	.fill_rxdone		= rt2800usb_fill_rxdone,
708 	.config_shared_key	= rt2800_config_shared_key,
709 	.config_pairwise_key	= rt2800_config_pairwise_key,
710 	.config_filter		= rt2800_config_filter,
711 	.config_intf		= rt2800_config_intf,
712 	.config_erp		= rt2800_config_erp,
713 	.config_ant		= rt2800_config_ant,
714 	.config			= rt2800_config,
715 	.pre_reset_hw		= rt2800_pre_reset_hw,
716 };
717 
rt2800usb_queue_init(struct data_queue * queue)718 static void rt2800usb_queue_init(struct data_queue *queue)
719 {
720 	struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
721 	unsigned short txwi_size, rxwi_size;
722 
723 	rt2800_get_txwi_rxwi_size(rt2x00dev, &txwi_size, &rxwi_size);
724 
725 	switch (queue->qid) {
726 	case QID_RX:
727 		queue->limit = 128;
728 		queue->data_size = AGGREGATION_SIZE;
729 		queue->desc_size = RXINFO_DESC_SIZE;
730 		queue->winfo_size = rxwi_size;
731 		queue->priv_size = sizeof(struct queue_entry_priv_usb);
732 		break;
733 
734 	case QID_AC_VO:
735 	case QID_AC_VI:
736 	case QID_AC_BE:
737 	case QID_AC_BK:
738 		queue->limit = 16;
739 		queue->data_size = AGGREGATION_SIZE;
740 		queue->desc_size = TXINFO_DESC_SIZE;
741 		queue->winfo_size = txwi_size;
742 		queue->priv_size = sizeof(struct queue_entry_priv_usb);
743 		break;
744 
745 	case QID_BEACON:
746 		queue->limit = 8;
747 		queue->data_size = MGMT_FRAME_SIZE;
748 		queue->desc_size = TXINFO_DESC_SIZE;
749 		queue->winfo_size = txwi_size;
750 		queue->priv_size = sizeof(struct queue_entry_priv_usb);
751 		break;
752 
753 	case QID_ATIM:
754 	default:
755 		BUG();
756 		break;
757 	}
758 }
759 
760 static const struct rt2x00_ops rt2800usb_ops = {
761 	.name			= KBUILD_MODNAME,
762 	.drv_data_size		= sizeof(struct rt2800_drv_data),
763 	.max_ap_intf		= 8,
764 	.eeprom_size		= EEPROM_SIZE,
765 	.rf_size		= RF_SIZE,
766 	.tx_queues		= NUM_TX_QUEUES,
767 	.queue_init		= rt2800usb_queue_init,
768 	.lib			= &rt2800usb_rt2x00_ops,
769 	.drv			= &rt2800usb_rt2800_ops,
770 	.hw			= &rt2800usb_mac80211_ops,
771 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
772 	.debugfs		= &rt2800_rt2x00debug,
773 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
774 };
775 
776 /*
777  * rt2800usb module information.
778  */
779 static const struct usb_device_id rt2800usb_device_table[] = {
780 	/* Abocom */
781 	{ USB_DEVICE(0x07b8, 0x2870) },
782 	{ USB_DEVICE(0x07b8, 0x2770) },
783 	{ USB_DEVICE(0x07b8, 0x3070) },
784 	{ USB_DEVICE(0x07b8, 0x3071) },
785 	{ USB_DEVICE(0x07b8, 0x3072) },
786 	{ USB_DEVICE(0x1482, 0x3c09) },
787 	/* AirTies */
788 	{ USB_DEVICE(0x1eda, 0x2012) },
789 	{ USB_DEVICE(0x1eda, 0x2210) },
790 	{ USB_DEVICE(0x1eda, 0x2310) },
791 	/* Allwin */
792 	{ USB_DEVICE(0x8516, 0x2070) },
793 	{ USB_DEVICE(0x8516, 0x2770) },
794 	{ USB_DEVICE(0x8516, 0x2870) },
795 	{ USB_DEVICE(0x8516, 0x3070) },
796 	{ USB_DEVICE(0x8516, 0x3071) },
797 	{ USB_DEVICE(0x8516, 0x3072) },
798 	/* Alpha Networks */
799 	{ USB_DEVICE(0x14b2, 0x3c06) },
800 	{ USB_DEVICE(0x14b2, 0x3c07) },
801 	{ USB_DEVICE(0x14b2, 0x3c09) },
802 	{ USB_DEVICE(0x14b2, 0x3c12) },
803 	{ USB_DEVICE(0x14b2, 0x3c23) },
804 	{ USB_DEVICE(0x14b2, 0x3c25) },
805 	{ USB_DEVICE(0x14b2, 0x3c27) },
806 	{ USB_DEVICE(0x14b2, 0x3c28) },
807 	{ USB_DEVICE(0x14b2, 0x3c2c) },
808 	/* Amit */
809 	{ USB_DEVICE(0x15c5, 0x0008) },
810 	/* Askey */
811 	{ USB_DEVICE(0x1690, 0x0740) },
812 	/* ASUS */
813 	{ USB_DEVICE(0x0b05, 0x1731) },
814 	{ USB_DEVICE(0x0b05, 0x1732) },
815 	{ USB_DEVICE(0x0b05, 0x1742) },
816 	{ USB_DEVICE(0x0b05, 0x1784) },
817 	{ USB_DEVICE(0x1761, 0x0b05) },
818 	/* AzureWave */
819 	{ USB_DEVICE(0x13d3, 0x3247) },
820 	{ USB_DEVICE(0x13d3, 0x3273) },
821 	{ USB_DEVICE(0x13d3, 0x3305) },
822 	{ USB_DEVICE(0x13d3, 0x3307) },
823 	{ USB_DEVICE(0x13d3, 0x3321) },
824 	/* Belkin */
825 	{ USB_DEVICE(0x050d, 0x8053) },
826 	{ USB_DEVICE(0x050d, 0x805c) },
827 	{ USB_DEVICE(0x050d, 0x815c) },
828 	{ USB_DEVICE(0x050d, 0x825a) },
829 	{ USB_DEVICE(0x050d, 0x825b) },
830 	{ USB_DEVICE(0x050d, 0x935a) },
831 	{ USB_DEVICE(0x050d, 0x935b) },
832 	/* Buffalo */
833 	{ USB_DEVICE(0x0411, 0x00e8) },
834 	{ USB_DEVICE(0x0411, 0x0158) },
835 	{ USB_DEVICE(0x0411, 0x015d) },
836 	{ USB_DEVICE(0x0411, 0x016f) },
837 	{ USB_DEVICE(0x0411, 0x01a2) },
838 	{ USB_DEVICE(0x0411, 0x01ee) },
839 	{ USB_DEVICE(0x0411, 0x01a8) },
840 	{ USB_DEVICE(0x0411, 0x01fd) },
841 	/* Corega */
842 	{ USB_DEVICE(0x07aa, 0x002f) },
843 	{ USB_DEVICE(0x07aa, 0x003c) },
844 	{ USB_DEVICE(0x07aa, 0x003f) },
845 	{ USB_DEVICE(0x18c5, 0x0012) },
846 	/* D-Link */
847 	{ USB_DEVICE(0x07d1, 0x3c09) },
848 	{ USB_DEVICE(0x07d1, 0x3c0a) },
849 	{ USB_DEVICE(0x07d1, 0x3c0d) },
850 	{ USB_DEVICE(0x07d1, 0x3c0e) },
851 	{ USB_DEVICE(0x07d1, 0x3c0f) },
852 	{ USB_DEVICE(0x07d1, 0x3c11) },
853 	{ USB_DEVICE(0x07d1, 0x3c13) },
854 	{ USB_DEVICE(0x07d1, 0x3c15) },
855 	{ USB_DEVICE(0x07d1, 0x3c16) },
856 	{ USB_DEVICE(0x07d1, 0x3c17) },
857 	{ USB_DEVICE(0x2001, 0x3317) },
858 	{ USB_DEVICE(0x2001, 0x3c1b) },
859 	{ USB_DEVICE(0x2001, 0x3c25) },
860 	/* Draytek */
861 	{ USB_DEVICE(0x07fa, 0x7712) },
862 	/* DVICO */
863 	{ USB_DEVICE(0x0fe9, 0xb307) },
864 	/* Edimax */
865 	{ USB_DEVICE(0x7392, 0x4085) },
866 	{ USB_DEVICE(0x7392, 0x7711) },
867 	{ USB_DEVICE(0x7392, 0x7717) },
868 	{ USB_DEVICE(0x7392, 0x7718) },
869 	{ USB_DEVICE(0x7392, 0x7722) },
870 	/* Encore */
871 	{ USB_DEVICE(0x203d, 0x1480) },
872 	{ USB_DEVICE(0x203d, 0x14a9) },
873 	/* EnGenius */
874 	{ USB_DEVICE(0x1740, 0x9701) },
875 	{ USB_DEVICE(0x1740, 0x9702) },
876 	{ USB_DEVICE(0x1740, 0x9703) },
877 	{ USB_DEVICE(0x1740, 0x9705) },
878 	{ USB_DEVICE(0x1740, 0x9706) },
879 	{ USB_DEVICE(0x1740, 0x9707) },
880 	{ USB_DEVICE(0x1740, 0x9708) },
881 	{ USB_DEVICE(0x1740, 0x9709) },
882 	/* Gemtek */
883 	{ USB_DEVICE(0x15a9, 0x0012) },
884 	/* Gigabyte */
885 	{ USB_DEVICE(0x1044, 0x800b) },
886 	{ USB_DEVICE(0x1044, 0x800d) },
887 	/* Hawking */
888 	{ USB_DEVICE(0x0e66, 0x0001) },
889 	{ USB_DEVICE(0x0e66, 0x0003) },
890 	{ USB_DEVICE(0x0e66, 0x0009) },
891 	{ USB_DEVICE(0x0e66, 0x000b) },
892 	{ USB_DEVICE(0x0e66, 0x0013) },
893 	{ USB_DEVICE(0x0e66, 0x0017) },
894 	{ USB_DEVICE(0x0e66, 0x0018) },
895 	/* I-O DATA */
896 	{ USB_DEVICE(0x04bb, 0x0945) },
897 	{ USB_DEVICE(0x04bb, 0x0947) },
898 	{ USB_DEVICE(0x04bb, 0x0948) },
899 	/* Linksys */
900 	{ USB_DEVICE(0x13b1, 0x0031) },
901 	{ USB_DEVICE(0x1737, 0x0070) },
902 	{ USB_DEVICE(0x1737, 0x0071) },
903 	{ USB_DEVICE(0x1737, 0x0077) },
904 	{ USB_DEVICE(0x1737, 0x0078) },
905 	/* Logitec */
906 	{ USB_DEVICE(0x0789, 0x0162) },
907 	{ USB_DEVICE(0x0789, 0x0163) },
908 	{ USB_DEVICE(0x0789, 0x0164) },
909 	{ USB_DEVICE(0x0789, 0x0166) },
910 	/* Motorola */
911 	{ USB_DEVICE(0x100d, 0x9031) },
912 	/* MSI */
913 	{ USB_DEVICE(0x0db0, 0x3820) },
914 	{ USB_DEVICE(0x0db0, 0x3821) },
915 	{ USB_DEVICE(0x0db0, 0x3822) },
916 	{ USB_DEVICE(0x0db0, 0x3870) },
917 	{ USB_DEVICE(0x0db0, 0x3871) },
918 	{ USB_DEVICE(0x0db0, 0x6899) },
919 	{ USB_DEVICE(0x0db0, 0x821a) },
920 	{ USB_DEVICE(0x0db0, 0x822a) },
921 	{ USB_DEVICE(0x0db0, 0x822b) },
922 	{ USB_DEVICE(0x0db0, 0x822c) },
923 	{ USB_DEVICE(0x0db0, 0x870a) },
924 	{ USB_DEVICE(0x0db0, 0x871a) },
925 	{ USB_DEVICE(0x0db0, 0x871b) },
926 	{ USB_DEVICE(0x0db0, 0x871c) },
927 	{ USB_DEVICE(0x0db0, 0x899a) },
928 	/* Ovislink */
929 	{ USB_DEVICE(0x1b75, 0x3070) },
930 	{ USB_DEVICE(0x1b75, 0x3071) },
931 	{ USB_DEVICE(0x1b75, 0x3072) },
932 	{ USB_DEVICE(0x1b75, 0xa200) },
933 	/* Para */
934 	{ USB_DEVICE(0x20b8, 0x8888) },
935 	/* Pegatron */
936 	{ USB_DEVICE(0x1d4d, 0x0002) },
937 	{ USB_DEVICE(0x1d4d, 0x000c) },
938 	{ USB_DEVICE(0x1d4d, 0x000e) },
939 	{ USB_DEVICE(0x1d4d, 0x0011) },
940 	/* Philips */
941 	{ USB_DEVICE(0x0471, 0x200f) },
942 	/* Planex */
943 	{ USB_DEVICE(0x2019, 0x5201) },
944 	{ USB_DEVICE(0x2019, 0xab25) },
945 	{ USB_DEVICE(0x2019, 0xed06) },
946 	/* Quanta */
947 	{ USB_DEVICE(0x1a32, 0x0304) },
948 	/* Ralink */
949 	{ USB_DEVICE(0x148f, 0x2070) },
950 	{ USB_DEVICE(0x148f, 0x2770) },
951 	{ USB_DEVICE(0x148f, 0x2870) },
952 	{ USB_DEVICE(0x148f, 0x3070) },
953 	{ USB_DEVICE(0x148f, 0x3071) },
954 	{ USB_DEVICE(0x148f, 0x3072) },
955 	/* Samsung */
956 	{ USB_DEVICE(0x04e8, 0x2018) },
957 	/* Siemens */
958 	{ USB_DEVICE(0x129b, 0x1828) },
959 	/* Sitecom */
960 	{ USB_DEVICE(0x0df6, 0x0017) },
961 	{ USB_DEVICE(0x0df6, 0x002b) },
962 	{ USB_DEVICE(0x0df6, 0x002c) },
963 	{ USB_DEVICE(0x0df6, 0x002d) },
964 	{ USB_DEVICE(0x0df6, 0x0039) },
965 	{ USB_DEVICE(0x0df6, 0x003b) },
966 	{ USB_DEVICE(0x0df6, 0x003d) },
967 	{ USB_DEVICE(0x0df6, 0x003e) },
968 	{ USB_DEVICE(0x0df6, 0x003f) },
969 	{ USB_DEVICE(0x0df6, 0x0040) },
970 	{ USB_DEVICE(0x0df6, 0x0042) },
971 	{ USB_DEVICE(0x0df6, 0x0047) },
972 	{ USB_DEVICE(0x0df6, 0x0048) },
973 	{ USB_DEVICE(0x0df6, 0x0051) },
974 	{ USB_DEVICE(0x0df6, 0x005f) },
975 	{ USB_DEVICE(0x0df6, 0x0060) },
976 	/* SMC */
977 	{ USB_DEVICE(0x083a, 0x6618) },
978 	{ USB_DEVICE(0x083a, 0x7511) },
979 	{ USB_DEVICE(0x083a, 0x7512) },
980 	{ USB_DEVICE(0x083a, 0x7522) },
981 	{ USB_DEVICE(0x083a, 0x8522) },
982 	{ USB_DEVICE(0x083a, 0xa618) },
983 	{ USB_DEVICE(0x083a, 0xa701) },
984 	{ USB_DEVICE(0x083a, 0xa702) },
985 	{ USB_DEVICE(0x083a, 0xa703) },
986 	{ USB_DEVICE(0x083a, 0xb522) },
987 	/* Sparklan */
988 	{ USB_DEVICE(0x15a9, 0x0006) },
989 	/* Sweex */
990 	{ USB_DEVICE(0x177f, 0x0153) },
991 	{ USB_DEVICE(0x177f, 0x0164) },
992 	{ USB_DEVICE(0x177f, 0x0302) },
993 	{ USB_DEVICE(0x177f, 0x0313) },
994 	{ USB_DEVICE(0x177f, 0x0323) },
995 	{ USB_DEVICE(0x177f, 0x0324) },
996 	{ USB_DEVICE(0x177f, 0x1163) },
997 	/* U-Media */
998 	{ USB_DEVICE(0x157e, 0x300e) },
999 	{ USB_DEVICE(0x157e, 0x3013) },
1000 	/* ZCOM */
1001 	{ USB_DEVICE(0x0cde, 0x0022) },
1002 	{ USB_DEVICE(0x0cde, 0x0025) },
1003 	/* Zinwell */
1004 	{ USB_DEVICE(0x5a57, 0x0280) },
1005 	{ USB_DEVICE(0x5a57, 0x0282) },
1006 	{ USB_DEVICE(0x5a57, 0x0283) },
1007 	{ USB_DEVICE(0x5a57, 0x5257) },
1008 	/* Zyxel */
1009 	{ USB_DEVICE(0x0586, 0x3416) },
1010 	{ USB_DEVICE(0x0586, 0x3418) },
1011 	{ USB_DEVICE(0x0586, 0x341a) },
1012 	{ USB_DEVICE(0x0586, 0x341e) },
1013 	{ USB_DEVICE(0x0586, 0x343e) },
1014 #ifdef CONFIG_RT2800USB_RT33XX
1015 	/* Belkin */
1016 	{ USB_DEVICE(0x050d, 0x945b) },
1017 	/* D-Link */
1018 	{ USB_DEVICE(0x2001, 0x3c17) },
1019 	/* Panasonic */
1020 	{ USB_DEVICE(0x083a, 0xb511) },
1021 	/* Accton/Arcadyan/Epson */
1022 	{ USB_DEVICE(0x083a, 0xb512) },
1023 	/* Philips */
1024 	{ USB_DEVICE(0x0471, 0x20dd) },
1025 	/* Ralink */
1026 	{ USB_DEVICE(0x148f, 0x3370) },
1027 	{ USB_DEVICE(0x148f, 0x8070) },
1028 	/* Sitecom */
1029 	{ USB_DEVICE(0x0df6, 0x0050) },
1030 	/* Sweex */
1031 	{ USB_DEVICE(0x177f, 0x0163) },
1032 	{ USB_DEVICE(0x177f, 0x0165) },
1033 #endif
1034 #ifdef CONFIG_RT2800USB_RT35XX
1035 	/* Allwin */
1036 	{ USB_DEVICE(0x8516, 0x3572) },
1037 	/* Askey */
1038 	{ USB_DEVICE(0x1690, 0x0744) },
1039 	{ USB_DEVICE(0x1690, 0x0761) },
1040 	{ USB_DEVICE(0x1690, 0x0764) },
1041 	/* ASUS */
1042 	{ USB_DEVICE(0x0b05, 0x179d) },
1043 	/* Cisco */
1044 	{ USB_DEVICE(0x167b, 0x4001) },
1045 	/* EnGenius */
1046 	{ USB_DEVICE(0x1740, 0x9801) },
1047 	/* I-O DATA */
1048 	{ USB_DEVICE(0x04bb, 0x0944) },
1049 	/* Linksys */
1050 	{ USB_DEVICE(0x13b1, 0x002f) },
1051 	{ USB_DEVICE(0x1737, 0x0079) },
1052 	/* Logitec */
1053 	{ USB_DEVICE(0x0789, 0x0170) },
1054 	/* Ralink */
1055 	{ USB_DEVICE(0x148f, 0x3572) },
1056 	/* Sitecom */
1057 	{ USB_DEVICE(0x0df6, 0x0041) },
1058 	{ USB_DEVICE(0x0df6, 0x0062) },
1059 	{ USB_DEVICE(0x0df6, 0x0065) },
1060 	{ USB_DEVICE(0x0df6, 0x0066) },
1061 	{ USB_DEVICE(0x0df6, 0x0068) },
1062 	/* Toshiba */
1063 	{ USB_DEVICE(0x0930, 0x0a07) },
1064 	/* Zinwell */
1065 	{ USB_DEVICE(0x5a57, 0x0284) },
1066 #endif
1067 #ifdef CONFIG_RT2800USB_RT3573
1068 	/* AirLive */
1069 	{ USB_DEVICE(0x1b75, 0x7733) },
1070 	/* ASUS */
1071 	{ USB_DEVICE(0x0b05, 0x17bc) },
1072 	{ USB_DEVICE(0x0b05, 0x17ad) },
1073 	/* Belkin */
1074 	{ USB_DEVICE(0x050d, 0x1103) },
1075 	/* Cameo */
1076 	{ USB_DEVICE(0x148f, 0xf301) },
1077 	/* D-Link */
1078 	{ USB_DEVICE(0x2001, 0x3c1f) },
1079 	/* Edimax */
1080 	{ USB_DEVICE(0x7392, 0x7733) },
1081 	/* Hawking */
1082 	{ USB_DEVICE(0x0e66, 0x0020) },
1083 	{ USB_DEVICE(0x0e66, 0x0021) },
1084 	/* I-O DATA */
1085 	{ USB_DEVICE(0x04bb, 0x094e) },
1086 	/* Linksys */
1087 	{ USB_DEVICE(0x13b1, 0x003b) },
1088 	/* Logitec */
1089 	{ USB_DEVICE(0x0789, 0x016b) },
1090 	/* NETGEAR */
1091 	{ USB_DEVICE(0x0846, 0x9012) },
1092 	{ USB_DEVICE(0x0846, 0x9013) },
1093 	{ USB_DEVICE(0x0846, 0x9019) },
1094 	/* Planex */
1095 	{ USB_DEVICE(0x2019, 0xed14) },
1096 	{ USB_DEVICE(0x2019, 0xed19) },
1097 	/* Ralink */
1098 	{ USB_DEVICE(0x148f, 0x3573) },
1099 	/* Sitecom */
1100 	{ USB_DEVICE(0x0df6, 0x0067) },
1101 	{ USB_DEVICE(0x0df6, 0x006a) },
1102 	{ USB_DEVICE(0x0df6, 0x006e) },
1103 	/* ZyXEL */
1104 	{ USB_DEVICE(0x0586, 0x3421) },
1105 #endif
1106 #ifdef CONFIG_RT2800USB_RT53XX
1107 	/* Arcadyan */
1108 	{ USB_DEVICE(0x043e, 0x7a12) },
1109 	/* ASUS */
1110 	{ USB_DEVICE(0x0b05, 0x17e8) },
1111 	/* Azurewave */
1112 	{ USB_DEVICE(0x13d3, 0x3329) },
1113 	{ USB_DEVICE(0x13d3, 0x3365) },
1114 	/* D-Link */
1115 	{ USB_DEVICE(0x2001, 0x3c15) },
1116 	{ USB_DEVICE(0x2001, 0x3c19) },
1117 	{ USB_DEVICE(0x2001, 0x3c1c) },
1118 	{ USB_DEVICE(0x2001, 0x3c1d) },
1119 	{ USB_DEVICE(0x2001, 0x3c1e) },
1120 	{ USB_DEVICE(0x2001, 0x3c20) },
1121 	{ USB_DEVICE(0x2001, 0x3c22) },
1122 	{ USB_DEVICE(0x2001, 0x3c23) },
1123 	/* LG innotek */
1124 	{ USB_DEVICE(0x043e, 0x7a22) },
1125 	{ USB_DEVICE(0x043e, 0x7a42) },
1126 	/* Panasonic */
1127 	{ USB_DEVICE(0x04da, 0x1801) },
1128 	{ USB_DEVICE(0x04da, 0x1800) },
1129 	{ USB_DEVICE(0x04da, 0x23f6) },
1130 	/* Philips */
1131 	{ USB_DEVICE(0x0471, 0x2104) },
1132 	{ USB_DEVICE(0x0471, 0x2126) },
1133 	{ USB_DEVICE(0x0471, 0x2180) },
1134 	{ USB_DEVICE(0x0471, 0x2181) },
1135 	{ USB_DEVICE(0x0471, 0x2182) },
1136 	/* Ralink */
1137 	{ USB_DEVICE(0x148f, 0x5370) },
1138 	{ USB_DEVICE(0x148f, 0x5372) },
1139 #endif
1140 #ifdef CONFIG_RT2800USB_RT55XX
1141 	/* Arcadyan */
1142 	{ USB_DEVICE(0x043e, 0x7a32) },
1143 	/* AVM GmbH */
1144 	{ USB_DEVICE(0x057c, 0x8501) },
1145 	/* Buffalo */
1146 	{ USB_DEVICE(0x0411, 0x0241) },
1147 	{ USB_DEVICE(0x0411, 0x0253) },
1148 	/* D-Link */
1149 	{ USB_DEVICE(0x2001, 0x3c1a) },
1150 	{ USB_DEVICE(0x2001, 0x3c21) },
1151 	/* Proware */
1152 	{ USB_DEVICE(0x043e, 0x7a13) },
1153 	/* Ralink */
1154 	{ USB_DEVICE(0x148f, 0x5572) },
1155 	/* TRENDnet */
1156 	{ USB_DEVICE(0x20f4, 0x724a) },
1157 #endif
1158 #ifdef CONFIG_RT2800USB_UNKNOWN
1159 	/*
1160 	 * Unclear what kind of devices these are (they aren't supported by the
1161 	 * vendor linux driver).
1162 	 */
1163 	/* Abocom */
1164 	{ USB_DEVICE(0x07b8, 0x3073) },
1165 	{ USB_DEVICE(0x07b8, 0x3074) },
1166 	/* Alpha Networks */
1167 	{ USB_DEVICE(0x14b2, 0x3c08) },
1168 	{ USB_DEVICE(0x14b2, 0x3c11) },
1169 	/* Amigo */
1170 	{ USB_DEVICE(0x0e0b, 0x9031) },
1171 	{ USB_DEVICE(0x0e0b, 0x9041) },
1172 	/* ASUS */
1173 	{ USB_DEVICE(0x0b05, 0x166a) },
1174 	{ USB_DEVICE(0x0b05, 0x1760) },
1175 	{ USB_DEVICE(0x0b05, 0x1761) },
1176 	{ USB_DEVICE(0x0b05, 0x1790) },
1177 	{ USB_DEVICE(0x0b05, 0x17a7) },
1178 	/* AzureWave */
1179 	{ USB_DEVICE(0x13d3, 0x3262) },
1180 	{ USB_DEVICE(0x13d3, 0x3284) },
1181 	{ USB_DEVICE(0x13d3, 0x3322) },
1182 	{ USB_DEVICE(0x13d3, 0x3340) },
1183 	{ USB_DEVICE(0x13d3, 0x3399) },
1184 	{ USB_DEVICE(0x13d3, 0x3400) },
1185 	{ USB_DEVICE(0x13d3, 0x3401) },
1186 	/* Belkin */
1187 	{ USB_DEVICE(0x050d, 0x1003) },
1188 	/* Buffalo */
1189 	{ USB_DEVICE(0x0411, 0x012e) },
1190 	{ USB_DEVICE(0x0411, 0x0148) },
1191 	{ USB_DEVICE(0x0411, 0x0150) },
1192 	/* Corega */
1193 	{ USB_DEVICE(0x07aa, 0x0041) },
1194 	{ USB_DEVICE(0x07aa, 0x0042) },
1195 	{ USB_DEVICE(0x18c5, 0x0008) },
1196 	/* D-Link */
1197 	{ USB_DEVICE(0x07d1, 0x3c0b) },
1198 	/* Encore */
1199 	{ USB_DEVICE(0x203d, 0x14a1) },
1200 	/* EnGenius */
1201 	{ USB_DEVICE(0x1740, 0x0600) },
1202 	{ USB_DEVICE(0x1740, 0x0602) },
1203 	/* Gemtek */
1204 	{ USB_DEVICE(0x15a9, 0x0010) },
1205 	/* Gigabyte */
1206 	{ USB_DEVICE(0x1044, 0x800c) },
1207 	/* Hercules */
1208 	{ USB_DEVICE(0x06f8, 0xe036) },
1209 	/* Huawei */
1210 	{ USB_DEVICE(0x148f, 0xf101) },
1211 	/* I-O DATA */
1212 	{ USB_DEVICE(0x04bb, 0x094b) },
1213 	/* LevelOne */
1214 	{ USB_DEVICE(0x1740, 0x0605) },
1215 	{ USB_DEVICE(0x1740, 0x0615) },
1216 	/* Logitec */
1217 	{ USB_DEVICE(0x0789, 0x0168) },
1218 	{ USB_DEVICE(0x0789, 0x0169) },
1219 	/* Motorola */
1220 	{ USB_DEVICE(0x100d, 0x9032) },
1221 	/* Pegatron */
1222 	{ USB_DEVICE(0x05a6, 0x0101) },
1223 	{ USB_DEVICE(0x1d4d, 0x0010) },
1224 	/* Planex */
1225 	{ USB_DEVICE(0x2019, 0xab24) },
1226 	{ USB_DEVICE(0x2019, 0xab29) },
1227 	/* Qcom */
1228 	{ USB_DEVICE(0x18e8, 0x6259) },
1229 	/* RadioShack */
1230 	{ USB_DEVICE(0x08b9, 0x1197) },
1231 	/* Sitecom */
1232 	{ USB_DEVICE(0x0df6, 0x003c) },
1233 	{ USB_DEVICE(0x0df6, 0x004a) },
1234 	{ USB_DEVICE(0x0df6, 0x004d) },
1235 	{ USB_DEVICE(0x0df6, 0x0053) },
1236 	{ USB_DEVICE(0x0df6, 0x0069) },
1237 	{ USB_DEVICE(0x0df6, 0x006f) },
1238 	{ USB_DEVICE(0x0df6, 0x0078) },
1239 	/* SMC */
1240 	{ USB_DEVICE(0x083a, 0xa512) },
1241 	{ USB_DEVICE(0x083a, 0xc522) },
1242 	{ USB_DEVICE(0x083a, 0xd522) },
1243 	{ USB_DEVICE(0x083a, 0xf511) },
1244 	/* Sweex */
1245 	{ USB_DEVICE(0x177f, 0x0254) },
1246 	/* TP-LINK */
1247 	{ USB_DEVICE(0xf201, 0x5370) },
1248 #endif
1249 	{ 0, }
1250 };
1251 
1252 MODULE_AUTHOR(DRV_PROJECT);
1253 MODULE_VERSION(DRV_VERSION);
1254 MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
1255 MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
1256 MODULE_FIRMWARE(FIRMWARE_RT2870);
1257 MODULE_LICENSE("GPL");
1258 
rt2800usb_probe(struct usb_interface * usb_intf,const struct usb_device_id * id)1259 static int rt2800usb_probe(struct usb_interface *usb_intf,
1260 			   const struct usb_device_id *id)
1261 {
1262 	return rt2x00usb_probe(usb_intf, &rt2800usb_ops);
1263 }
1264 
1265 static struct usb_driver rt2800usb_driver = {
1266 	.name		= KBUILD_MODNAME,
1267 	.id_table	= rt2800usb_device_table,
1268 	.probe		= rt2800usb_probe,
1269 	.disconnect	= rt2x00usb_disconnect,
1270 	.suspend	= rt2x00usb_suspend,
1271 	.resume		= rt2x00usb_resume,
1272 	.reset_resume	= rt2x00usb_resume,
1273 	.disable_hub_initiated_lpm = 1,
1274 };
1275 
1276 module_usb_driver(rt2800usb_driver);
1277