rt2800pci.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. /*
  2. Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
  3. Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
  4. Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
  5. Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
  6. Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
  7. Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
  8. Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
  9. Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com>
  10. <http://rt2x00.serialmonkey.com>
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the
  21. Free Software Foundation, Inc.,
  22. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. */
  24. /*
  25. Module: rt2800pci
  26. Abstract: rt2800pci device specific routines.
  27. Supported chipsets: RT2800E & RT2800ED.
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/init.h>
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/pci.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/eeprom_93cx6.h>
  37. #include "rt2x00.h"
  38. #include "rt2x00pci.h"
  39. #include "rt2x00soc.h"
  40. #include "rt2800lib.h"
  41. #include "rt2800.h"
  42. #include "rt2800pci.h"
  43. /*
  44. * Allow hardware encryption to be disabled.
  45. */
  46. static bool modparam_nohwcrypt = false;
  47. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  48. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  49. static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
  50. {
  51. unsigned int i;
  52. u32 reg;
  53. /*
  54. * SOC devices don't support MCU requests.
  55. */
  56. if (rt2x00_is_soc(rt2x00dev))
  57. return;
  58. for (i = 0; i < 200; i++) {
  59. rt2x00pci_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
  60. if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
  61. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
  62. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
  63. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
  64. break;
  65. udelay(REGISTER_BUSY_DELAY);
  66. }
  67. if (i == 200)
  68. ERROR(rt2x00dev, "MCU request failed, no response from hardware\n");
  69. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  70. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  71. }
  72. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  73. static void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
  74. {
  75. void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
  76. memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
  77. iounmap(base_addr);
  78. }
  79. #else
  80. static inline void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
  81. {
  82. }
  83. #endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */
  84. #ifdef CONFIG_PCI
  85. static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  86. {
  87. struct rt2x00_dev *rt2x00dev = eeprom->data;
  88. u32 reg;
  89. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  90. eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
  91. eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
  92. eeprom->reg_data_clock =
  93. !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
  94. eeprom->reg_chip_select =
  95. !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
  96. }
  97. static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  98. {
  99. struct rt2x00_dev *rt2x00dev = eeprom->data;
  100. u32 reg = 0;
  101. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
  102. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
  103. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
  104. !!eeprom->reg_data_clock);
  105. rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
  106. !!eeprom->reg_chip_select);
  107. rt2x00pci_register_write(rt2x00dev, E2PROM_CSR, reg);
  108. }
  109. static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
  110. {
  111. struct eeprom_93cx6 eeprom;
  112. u32 reg;
  113. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  114. eeprom.data = rt2x00dev;
  115. eeprom.register_read = rt2800pci_eepromregister_read;
  116. eeprom.register_write = rt2800pci_eepromregister_write;
  117. switch (rt2x00_get_field32(reg, E2PROM_CSR_TYPE))
  118. {
  119. case 0:
  120. eeprom.width = PCI_EEPROM_WIDTH_93C46;
  121. break;
  122. case 1:
  123. eeprom.width = PCI_EEPROM_WIDTH_93C66;
  124. break;
  125. default:
  126. eeprom.width = PCI_EEPROM_WIDTH_93C86;
  127. break;
  128. }
  129. eeprom.reg_data_in = 0;
  130. eeprom.reg_data_out = 0;
  131. eeprom.reg_data_clock = 0;
  132. eeprom.reg_chip_select = 0;
  133. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  134. EEPROM_SIZE / sizeof(u16));
  135. }
  136. static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
  137. {
  138. return rt2800_efuse_detect(rt2x00dev);
  139. }
  140. static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  141. {
  142. rt2800_read_eeprom_efuse(rt2x00dev);
  143. }
  144. #else
  145. static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
  146. {
  147. }
  148. static inline int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
  149. {
  150. return 0;
  151. }
  152. static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  153. {
  154. }
  155. #endif /* CONFIG_PCI */
  156. /*
  157. * Queue handlers.
  158. */
  159. static void rt2800pci_start_queue(struct data_queue *queue)
  160. {
  161. struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
  162. u32 reg;
  163. switch (queue->qid) {
  164. case QID_RX:
  165. rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  166. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  167. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  168. break;
  169. case QID_BEACON:
  170. rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  171. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  172. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  173. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  174. rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  175. rt2x00pci_register_read(rt2x00dev, INT_TIMER_EN, &reg);
  176. rt2x00_set_field32(&reg, INT_TIMER_EN_PRE_TBTT_TIMER, 1);
  177. rt2x00pci_register_write(rt2x00dev, INT_TIMER_EN, reg);
  178. break;
  179. default:
  180. break;
  181. }
  182. }
  183. static void rt2800pci_kick_queue(struct data_queue *queue)
  184. {
  185. struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
  186. struct queue_entry *entry;
  187. switch (queue->qid) {
  188. case QID_AC_VO:
  189. case QID_AC_VI:
  190. case QID_AC_BE:
  191. case QID_AC_BK:
  192. entry = rt2x00queue_get_entry(queue, Q_INDEX);
  193. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX(queue->qid),
  194. entry->entry_idx);
  195. break;
  196. case QID_MGMT:
  197. entry = rt2x00queue_get_entry(queue, Q_INDEX);
  198. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX(5),
  199. entry->entry_idx);
  200. break;
  201. default:
  202. break;
  203. }
  204. }
  205. static void rt2800pci_stop_queue(struct data_queue *queue)
  206. {
  207. struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
  208. u32 reg;
  209. switch (queue->qid) {
  210. case QID_RX:
  211. rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  212. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
  213. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  214. break;
  215. case QID_BEACON:
  216. rt2x00pci_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  217. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  218. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  219. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  220. rt2x00pci_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  221. rt2x00pci_register_read(rt2x00dev, INT_TIMER_EN, &reg);
  222. rt2x00_set_field32(&reg, INT_TIMER_EN_PRE_TBTT_TIMER, 0);
  223. rt2x00pci_register_write(rt2x00dev, INT_TIMER_EN, reg);
  224. /*
  225. * Wait for current invocation to finish. The tasklet
  226. * won't be scheduled anymore afterwards since we disabled
  227. * the TBTT and PRE TBTT timer.
  228. */
  229. tasklet_kill(&rt2x00dev->tbtt_tasklet);
  230. tasklet_kill(&rt2x00dev->pretbtt_tasklet);
  231. break;
  232. default:
  233. break;
  234. }
  235. }
  236. /*
  237. * Firmware functions
  238. */
  239. static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  240. {
  241. return FIRMWARE_RT2860;
  242. }
  243. static int rt2800pci_write_firmware(struct rt2x00_dev *rt2x00dev,
  244. const u8 *data, const size_t len)
  245. {
  246. u32 reg;
  247. /*
  248. * enable Host program ram write selection
  249. */
  250. reg = 0;
  251. rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
  252. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
  253. /*
  254. * Write firmware to device.
  255. */
  256. rt2x00pci_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  257. data, len);
  258. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
  259. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
  260. rt2x00pci_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  261. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  262. return 0;
  263. }
  264. /*
  265. * Initialization functions.
  266. */
  267. static bool rt2800pci_get_entry_state(struct queue_entry *entry)
  268. {
  269. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  270. u32 word;
  271. if (entry->queue->qid == QID_RX) {
  272. rt2x00_desc_read(entry_priv->desc, 1, &word);
  273. return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE));
  274. } else {
  275. rt2x00_desc_read(entry_priv->desc, 1, &word);
  276. return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE));
  277. }
  278. }
  279. static void rt2800pci_clear_entry(struct queue_entry *entry)
  280. {
  281. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  282. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  283. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  284. u32 word;
  285. if (entry->queue->qid == QID_RX) {
  286. rt2x00_desc_read(entry_priv->desc, 0, &word);
  287. rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma);
  288. rt2x00_desc_write(entry_priv->desc, 0, word);
  289. rt2x00_desc_read(entry_priv->desc, 1, &word);
  290. rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0);
  291. rt2x00_desc_write(entry_priv->desc, 1, word);
  292. /*
  293. * Set RX IDX in register to inform hardware that we have
  294. * handled this entry and it is available for reuse again.
  295. */
  296. rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX,
  297. entry->entry_idx);
  298. } else {
  299. rt2x00_desc_read(entry_priv->desc, 1, &word);
  300. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
  301. rt2x00_desc_write(entry_priv->desc, 1, word);
  302. }
  303. }
  304. static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
  305. {
  306. struct queue_entry_priv_pci *entry_priv;
  307. u32 reg;
  308. /*
  309. * Initialize registers.
  310. */
  311. entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
  312. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma);
  313. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT0,
  314. rt2x00dev->tx[0].limit);
  315. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX0, 0);
  316. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX0, 0);
  317. entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
  318. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma);
  319. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT1,
  320. rt2x00dev->tx[1].limit);
  321. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX1, 0);
  322. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX1, 0);
  323. entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
  324. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma);
  325. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT2,
  326. rt2x00dev->tx[2].limit);
  327. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX2, 0);
  328. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX2, 0);
  329. entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
  330. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma);
  331. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT3,
  332. rt2x00dev->tx[3].limit);
  333. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX3, 0);
  334. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX3, 0);
  335. entry_priv = rt2x00dev->rx->entries[0].priv_data;
  336. rt2x00pci_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
  337. rt2x00pci_register_write(rt2x00dev, RX_MAX_CNT,
  338. rt2x00dev->rx[0].limit);
  339. rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX,
  340. rt2x00dev->rx[0].limit - 1);
  341. rt2x00pci_register_write(rt2x00dev, RX_DRX_IDX, 0);
  342. /*
  343. * Enable global DMA configuration
  344. */
  345. rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  346. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  347. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  348. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  349. rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  350. rt2x00pci_register_write(rt2x00dev, DELAY_INT_CFG, 0);
  351. return 0;
  352. }
  353. /*
  354. * Device state switch handlers.
  355. */
  356. static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  357. enum dev_state state)
  358. {
  359. u32 reg;
  360. unsigned long flags;
  361. /*
  362. * When interrupts are being enabled, the interrupt registers
  363. * should clear the register to assure a clean state.
  364. */
  365. if (state == STATE_RADIO_IRQ_ON) {
  366. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  367. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  368. }
  369. spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags);
  370. reg = 0;
  371. if (state == STATE_RADIO_IRQ_ON) {
  372. rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, 1);
  373. rt2x00_set_field32(&reg, INT_MASK_CSR_TBTT, 1);
  374. rt2x00_set_field32(&reg, INT_MASK_CSR_PRE_TBTT, 1);
  375. rt2x00_set_field32(&reg, INT_MASK_CSR_TX_FIFO_STATUS, 1);
  376. rt2x00_set_field32(&reg, INT_MASK_CSR_AUTO_WAKEUP, 1);
  377. }
  378. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  379. spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags);
  380. if (state == STATE_RADIO_IRQ_OFF) {
  381. /*
  382. * Wait for possibly running tasklets to finish.
  383. */
  384. tasklet_kill(&rt2x00dev->txstatus_tasklet);
  385. tasklet_kill(&rt2x00dev->rxdone_tasklet);
  386. tasklet_kill(&rt2x00dev->autowake_tasklet);
  387. tasklet_kill(&rt2x00dev->tbtt_tasklet);
  388. tasklet_kill(&rt2x00dev->pretbtt_tasklet);
  389. }
  390. }
  391. static int rt2800pci_init_registers(struct rt2x00_dev *rt2x00dev)
  392. {
  393. u32 reg;
  394. /*
  395. * Reset DMA indexes
  396. */
  397. rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
  398. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
  399. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
  400. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
  401. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
  402. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
  403. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
  404. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
  405. rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
  406. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
  407. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
  408. if (rt2x00_is_pcie(rt2x00dev) &&
  409. (rt2x00_rt(rt2x00dev, RT3572) ||
  410. rt2x00_rt(rt2x00dev, RT5390))) {
  411. rt2x00pci_register_read(rt2x00dev, AUX_CTRL, &reg);
  412. rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
  413. rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
  414. rt2x00pci_register_write(rt2x00dev, AUX_CTRL, reg);
  415. }
  416. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  417. rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  418. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  419. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  420. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  421. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  422. return 0;
  423. }
  424. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  425. {
  426. if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
  427. rt2800pci_init_queues(rt2x00dev)))
  428. return -EIO;
  429. return rt2800_enable_radio(rt2x00dev);
  430. }
  431. static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  432. {
  433. if (rt2x00_is_soc(rt2x00dev)) {
  434. rt2800_disable_radio(rt2x00dev);
  435. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  436. rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, 0);
  437. }
  438. }
  439. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  440. enum dev_state state)
  441. {
  442. if (state == STATE_AWAKE) {
  443. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0x02);
  444. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
  445. } else if (state == STATE_SLEEP) {
  446. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
  447. 0xffffffff);
  448. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID,
  449. 0xffffffff);
  450. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0x01, 0xff, 0x01);
  451. }
  452. return 0;
  453. }
  454. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  455. enum dev_state state)
  456. {
  457. int retval = 0;
  458. switch (state) {
  459. case STATE_RADIO_ON:
  460. /*
  461. * Before the radio can be enabled, the device first has
  462. * to be woken up. After that it needs a bit of time
  463. * to be fully awake and then the radio can be enabled.
  464. */
  465. rt2800pci_set_state(rt2x00dev, STATE_AWAKE);
  466. msleep(1);
  467. retval = rt2800pci_enable_radio(rt2x00dev);
  468. break;
  469. case STATE_RADIO_OFF:
  470. /*
  471. * After the radio has been disabled, the device should
  472. * be put to sleep for powersaving.
  473. */
  474. rt2800pci_disable_radio(rt2x00dev);
  475. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  476. break;
  477. case STATE_RADIO_IRQ_ON:
  478. case STATE_RADIO_IRQ_OFF:
  479. rt2800pci_toggle_irq(rt2x00dev, state);
  480. break;
  481. case STATE_DEEP_SLEEP:
  482. case STATE_SLEEP:
  483. case STATE_STANDBY:
  484. case STATE_AWAKE:
  485. retval = rt2800pci_set_state(rt2x00dev, state);
  486. break;
  487. default:
  488. retval = -ENOTSUPP;
  489. break;
  490. }
  491. if (unlikely(retval))
  492. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  493. state, retval);
  494. return retval;
  495. }
  496. /*
  497. * TX descriptor initialization
  498. */
  499. static __le32 *rt2800pci_get_txwi(struct queue_entry *entry)
  500. {
  501. return (__le32 *) entry->skb->data;
  502. }
  503. static void rt2800pci_write_tx_desc(struct queue_entry *entry,
  504. struct txentry_desc *txdesc)
  505. {
  506. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  507. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  508. __le32 *txd = entry_priv->desc;
  509. u32 word;
  510. /*
  511. * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
  512. * must contains a TXWI structure + 802.11 header + padding + 802.11
  513. * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
  514. * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
  515. * data. It means that LAST_SEC0 is always 0.
  516. */
  517. /*
  518. * Initialize TX descriptor
  519. */
  520. word = 0;
  521. rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
  522. rt2x00_desc_write(txd, 0, word);
  523. word = 0;
  524. rt2x00_set_field32(&word, TXD_W1_SD_LEN1, entry->skb->len);
  525. rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
  526. !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  527. rt2x00_set_field32(&word, TXD_W1_BURST,
  528. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  529. rt2x00_set_field32(&word, TXD_W1_SD_LEN0, TXWI_DESC_SIZE);
  530. rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
  531. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
  532. rt2x00_desc_write(txd, 1, word);
  533. word = 0;
  534. rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
  535. skbdesc->skb_dma + TXWI_DESC_SIZE);
  536. rt2x00_desc_write(txd, 2, word);
  537. word = 0;
  538. rt2x00_set_field32(&word, TXD_W3_WIV,
  539. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  540. rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
  541. rt2x00_desc_write(txd, 3, word);
  542. /*
  543. * Register descriptor details in skb frame descriptor.
  544. */
  545. skbdesc->desc = txd;
  546. skbdesc->desc_len = TXD_DESC_SIZE;
  547. }
  548. /*
  549. * RX control handlers
  550. */
  551. static void rt2800pci_fill_rxdone(struct queue_entry *entry,
  552. struct rxdone_entry_desc *rxdesc)
  553. {
  554. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  555. __le32 *rxd = entry_priv->desc;
  556. u32 word;
  557. rt2x00_desc_read(rxd, 3, &word);
  558. if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
  559. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  560. /*
  561. * Unfortunately we don't know the cipher type used during
  562. * decryption. This prevents us from correct providing
  563. * correct statistics through debugfs.
  564. */
  565. rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
  566. if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
  567. /*
  568. * Hardware has stripped IV/EIV data from 802.11 frame during
  569. * decryption. Unfortunately the descriptor doesn't contain
  570. * any fields with the EIV/IV data either, so they can't
  571. * be restored by rt2x00lib.
  572. */
  573. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  574. /*
  575. * The hardware has already checked the Michael Mic and has
  576. * stripped it from the frame. Signal this to mac80211.
  577. */
  578. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  579. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  580. rxdesc->flags |= RX_FLAG_DECRYPTED;
  581. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  582. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  583. }
  584. if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
  585. rxdesc->dev_flags |= RXDONE_MY_BSS;
  586. if (rt2x00_get_field32(word, RXD_W3_L2PAD))
  587. rxdesc->dev_flags |= RXDONE_L2PAD;
  588. /*
  589. * Process the RXWI structure that is at the start of the buffer.
  590. */
  591. rt2800_process_rxwi(entry, rxdesc);
  592. }
  593. /*
  594. * Interrupt functions.
  595. */
  596. static void rt2800pci_wakeup(struct rt2x00_dev *rt2x00dev)
  597. {
  598. struct ieee80211_conf conf = { .flags = 0 };
  599. struct rt2x00lib_conf libconf = { .conf = &conf };
  600. rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
  601. }
  602. static bool rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
  603. {
  604. struct data_queue *queue;
  605. struct queue_entry *entry;
  606. u32 status;
  607. u8 qid;
  608. int max_tx_done = 16;
  609. while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
  610. qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
  611. if (unlikely(qid >= QID_RX)) {
  612. /*
  613. * Unknown queue, this shouldn't happen. Just drop
  614. * this tx status.
  615. */
  616. WARNING(rt2x00dev, "Got TX status report with "
  617. "unexpected pid %u, dropping\n", qid);
  618. break;
  619. }
  620. queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
  621. if (unlikely(queue == NULL)) {
  622. /*
  623. * The queue is NULL, this shouldn't happen. Stop
  624. * processing here and drop the tx status
  625. */
  626. WARNING(rt2x00dev, "Got TX status for an unavailable "
  627. "queue %u, dropping\n", qid);
  628. break;
  629. }
  630. if (unlikely(rt2x00queue_empty(queue))) {
  631. /*
  632. * The queue is empty. Stop processing here
  633. * and drop the tx status.
  634. */
  635. WARNING(rt2x00dev, "Got TX status for an empty "
  636. "queue %u, dropping\n", qid);
  637. break;
  638. }
  639. entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  640. rt2800_txdone_entry(entry, status, rt2800pci_get_txwi(entry));
  641. if (--max_tx_done == 0)
  642. break;
  643. }
  644. return !max_tx_done;
  645. }
  646. static inline void rt2800pci_enable_interrupt(struct rt2x00_dev *rt2x00dev,
  647. struct rt2x00_field32 irq_field)
  648. {
  649. u32 reg;
  650. /*
  651. * Enable a single interrupt. The interrupt mask register
  652. * access needs locking.
  653. */
  654. spin_lock_irq(&rt2x00dev->irqmask_lock);
  655. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  656. rt2x00_set_field32(&reg, irq_field, 1);
  657. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  658. spin_unlock_irq(&rt2x00dev->irqmask_lock);
  659. }
  660. static void rt2800pci_txstatus_tasklet(unsigned long data)
  661. {
  662. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  663. if (rt2800pci_txdone(rt2x00dev))
  664. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  665. /*
  666. * No need to enable the tx status interrupt here as we always
  667. * leave it enabled to minimize the possibility of a tx status
  668. * register overflow. See comment in interrupt handler.
  669. */
  670. }
  671. static void rt2800pci_pretbtt_tasklet(unsigned long data)
  672. {
  673. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  674. rt2x00lib_pretbtt(rt2x00dev);
  675. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  676. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_PRE_TBTT);
  677. }
  678. static void rt2800pci_tbtt_tasklet(unsigned long data)
  679. {
  680. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  681. rt2x00lib_beacondone(rt2x00dev);
  682. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  683. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_TBTT);
  684. }
  685. static void rt2800pci_rxdone_tasklet(unsigned long data)
  686. {
  687. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  688. if (rt2x00pci_rxdone(rt2x00dev))
  689. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  690. else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  691. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_RX_DONE);
  692. }
  693. static void rt2800pci_autowake_tasklet(unsigned long data)
  694. {
  695. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  696. rt2800pci_wakeup(rt2x00dev);
  697. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  698. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_AUTO_WAKEUP);
  699. }
  700. static void rt2800pci_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
  701. {
  702. u32 status;
  703. int i;
  704. /*
  705. * The TX_FIFO_STATUS interrupt needs special care. We should
  706. * read TX_STA_FIFO but we should do it immediately as otherwise
  707. * the register can overflow and we would lose status reports.
  708. *
  709. * Hence, read the TX_STA_FIFO register and copy all tx status
  710. * reports into a kernel FIFO which is handled in the txstatus
  711. * tasklet. We use a tasklet to process the tx status reports
  712. * because we can schedule the tasklet multiple times (when the
  713. * interrupt fires again during tx status processing).
  714. *
  715. * Furthermore we don't disable the TX_FIFO_STATUS
  716. * interrupt here but leave it enabled so that the TX_STA_FIFO
  717. * can also be read while the tx status tasklet gets executed.
  718. *
  719. * Since we have only one producer and one consumer we don't
  720. * need to lock the kfifo.
  721. */
  722. for (i = 0; i < rt2x00dev->ops->tx->entry_num; i++) {
  723. rt2x00pci_register_read(rt2x00dev, TX_STA_FIFO, &status);
  724. if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
  725. break;
  726. if (!kfifo_put(&rt2x00dev->txstatus_fifo, &status)) {
  727. WARNING(rt2x00dev, "TX status FIFO overrun,"
  728. "drop tx status report.\n");
  729. break;
  730. }
  731. }
  732. /* Schedule the tasklet for processing the tx status. */
  733. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  734. }
  735. static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
  736. {
  737. struct rt2x00_dev *rt2x00dev = dev_instance;
  738. u32 reg, mask;
  739. /* Read status and ACK all interrupts */
  740. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  741. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  742. if (!reg)
  743. return IRQ_NONE;
  744. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  745. return IRQ_HANDLED;
  746. /*
  747. * Since INT_MASK_CSR and INT_SOURCE_CSR use the same bits
  748. * for interrupts and interrupt masks we can just use the value of
  749. * INT_SOURCE_CSR to create the interrupt mask.
  750. */
  751. mask = ~reg;
  752. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
  753. rt2800pci_txstatus_interrupt(rt2x00dev);
  754. /*
  755. * Never disable the TX_FIFO_STATUS interrupt.
  756. */
  757. rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
  758. }
  759. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
  760. tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
  761. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TBTT))
  762. tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet);
  763. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
  764. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  765. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
  766. tasklet_schedule(&rt2x00dev->autowake_tasklet);
  767. /*
  768. * Disable all interrupts for which a tasklet was scheduled right now,
  769. * the tasklet will reenable the appropriate interrupts.
  770. */
  771. spin_lock(&rt2x00dev->irqmask_lock);
  772. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  773. reg &= mask;
  774. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  775. spin_unlock(&rt2x00dev->irqmask_lock);
  776. return IRQ_HANDLED;
  777. }
  778. /*
  779. * Device probe functions.
  780. */
  781. static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  782. {
  783. /*
  784. * Read EEPROM into buffer
  785. */
  786. if (rt2x00_is_soc(rt2x00dev))
  787. rt2800pci_read_eeprom_soc(rt2x00dev);
  788. else if (rt2800pci_efuse_detect(rt2x00dev))
  789. rt2800pci_read_eeprom_efuse(rt2x00dev);
  790. else
  791. rt2800pci_read_eeprom_pci(rt2x00dev);
  792. return rt2800_validate_eeprom(rt2x00dev);
  793. }
  794. static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  795. {
  796. int retval;
  797. /*
  798. * Allocate eeprom data.
  799. */
  800. retval = rt2800pci_validate_eeprom(rt2x00dev);
  801. if (retval)
  802. return retval;
  803. retval = rt2800_init_eeprom(rt2x00dev);
  804. if (retval)
  805. return retval;
  806. /*
  807. * Initialize hw specifications.
  808. */
  809. retval = rt2800_probe_hw_mode(rt2x00dev);
  810. if (retval)
  811. return retval;
  812. /*
  813. * This device has multiple filters for control frames
  814. * and has a separate filter for PS Poll frames.
  815. */
  816. __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
  817. __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
  818. /*
  819. * This device has a pre tbtt interrupt and thus fetches
  820. * a new beacon directly prior to transmission.
  821. */
  822. __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
  823. /*
  824. * This device requires firmware.
  825. */
  826. if (!rt2x00_is_soc(rt2x00dev))
  827. __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
  828. __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
  829. __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
  830. __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
  831. __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
  832. if (!modparam_nohwcrypt)
  833. __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
  834. __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
  835. __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
  836. /*
  837. * Set the rssi offset.
  838. */
  839. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  840. return 0;
  841. }
  842. static const struct ieee80211_ops rt2800pci_mac80211_ops = {
  843. .tx = rt2x00mac_tx,
  844. .start = rt2x00mac_start,
  845. .stop = rt2x00mac_stop,
  846. .add_interface = rt2x00mac_add_interface,
  847. .remove_interface = rt2x00mac_remove_interface,
  848. .config = rt2x00mac_config,
  849. .configure_filter = rt2x00mac_configure_filter,
  850. .set_key = rt2x00mac_set_key,
  851. .sw_scan_start = rt2x00mac_sw_scan_start,
  852. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  853. .get_stats = rt2x00mac_get_stats,
  854. .get_tkip_seq = rt2800_get_tkip_seq,
  855. .set_rts_threshold = rt2800_set_rts_threshold,
  856. .sta_add = rt2x00mac_sta_add,
  857. .sta_remove = rt2x00mac_sta_remove,
  858. .bss_info_changed = rt2x00mac_bss_info_changed,
  859. .conf_tx = rt2800_conf_tx,
  860. .get_tsf = rt2800_get_tsf,
  861. .rfkill_poll = rt2x00mac_rfkill_poll,
  862. .ampdu_action = rt2800_ampdu_action,
  863. .flush = rt2x00mac_flush,
  864. .get_survey = rt2800_get_survey,
  865. .get_ringparam = rt2x00mac_get_ringparam,
  866. .tx_frames_pending = rt2x00mac_tx_frames_pending,
  867. };
  868. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  869. .register_read = rt2x00pci_register_read,
  870. .register_read_lock = rt2x00pci_register_read, /* same for PCI */
  871. .register_write = rt2x00pci_register_write,
  872. .register_write_lock = rt2x00pci_register_write, /* same for PCI */
  873. .register_multiread = rt2x00pci_register_multiread,
  874. .register_multiwrite = rt2x00pci_register_multiwrite,
  875. .regbusy_read = rt2x00pci_regbusy_read,
  876. .drv_write_firmware = rt2800pci_write_firmware,
  877. .drv_init_registers = rt2800pci_init_registers,
  878. .drv_get_txwi = rt2800pci_get_txwi,
  879. };
  880. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  881. .irq_handler = rt2800pci_interrupt,
  882. .txstatus_tasklet = rt2800pci_txstatus_tasklet,
  883. .pretbtt_tasklet = rt2800pci_pretbtt_tasklet,
  884. .tbtt_tasklet = rt2800pci_tbtt_tasklet,
  885. .rxdone_tasklet = rt2800pci_rxdone_tasklet,
  886. .autowake_tasklet = rt2800pci_autowake_tasklet,
  887. .probe_hw = rt2800pci_probe_hw,
  888. .get_firmware_name = rt2800pci_get_firmware_name,
  889. .check_firmware = rt2800_check_firmware,
  890. .load_firmware = rt2800_load_firmware,
  891. .initialize = rt2x00pci_initialize,
  892. .uninitialize = rt2x00pci_uninitialize,
  893. .get_entry_state = rt2800pci_get_entry_state,
  894. .clear_entry = rt2800pci_clear_entry,
  895. .set_device_state = rt2800pci_set_device_state,
  896. .rfkill_poll = rt2800_rfkill_poll,
  897. .link_stats = rt2800_link_stats,
  898. .reset_tuner = rt2800_reset_tuner,
  899. .link_tuner = rt2800_link_tuner,
  900. .gain_calibration = rt2800_gain_calibration,
  901. .start_queue = rt2800pci_start_queue,
  902. .kick_queue = rt2800pci_kick_queue,
  903. .stop_queue = rt2800pci_stop_queue,
  904. .flush_queue = rt2x00pci_flush_queue,
  905. .write_tx_desc = rt2800pci_write_tx_desc,
  906. .write_tx_data = rt2800_write_tx_data,
  907. .write_beacon = rt2800_write_beacon,
  908. .clear_beacon = rt2800_clear_beacon,
  909. .fill_rxdone = rt2800pci_fill_rxdone,
  910. .config_shared_key = rt2800_config_shared_key,
  911. .config_pairwise_key = rt2800_config_pairwise_key,
  912. .config_filter = rt2800_config_filter,
  913. .config_intf = rt2800_config_intf,
  914. .config_erp = rt2800_config_erp,
  915. .config_ant = rt2800_config_ant,
  916. .config = rt2800_config,
  917. .sta_add = rt2800_sta_add,
  918. .sta_remove = rt2800_sta_remove,
  919. };
  920. static const struct data_queue_desc rt2800pci_queue_rx = {
  921. .entry_num = 128,
  922. .data_size = AGGREGATION_SIZE,
  923. .desc_size = RXD_DESC_SIZE,
  924. .priv_size = sizeof(struct queue_entry_priv_pci),
  925. };
  926. static const struct data_queue_desc rt2800pci_queue_tx = {
  927. .entry_num = 64,
  928. .data_size = AGGREGATION_SIZE,
  929. .desc_size = TXD_DESC_SIZE,
  930. .priv_size = sizeof(struct queue_entry_priv_pci),
  931. };
  932. static const struct data_queue_desc rt2800pci_queue_bcn = {
  933. .entry_num = 8,
  934. .data_size = 0, /* No DMA required for beacons */
  935. .desc_size = TXWI_DESC_SIZE,
  936. .priv_size = sizeof(struct queue_entry_priv_pci),
  937. };
  938. static const struct rt2x00_ops rt2800pci_ops = {
  939. .name = KBUILD_MODNAME,
  940. .max_sta_intf = 1,
  941. .max_ap_intf = 8,
  942. .eeprom_size = EEPROM_SIZE,
  943. .rf_size = RF_SIZE,
  944. .tx_queues = NUM_TX_QUEUES,
  945. .extra_tx_headroom = TXWI_DESC_SIZE,
  946. .rx = &rt2800pci_queue_rx,
  947. .tx = &rt2800pci_queue_tx,
  948. .bcn = &rt2800pci_queue_bcn,
  949. .lib = &rt2800pci_rt2x00_ops,
  950. .drv = &rt2800pci_rt2800_ops,
  951. .hw = &rt2800pci_mac80211_ops,
  952. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  953. .debugfs = &rt2800_rt2x00debug,
  954. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  955. };
  956. /*
  957. * RT2800pci module information.
  958. */
  959. #ifdef CONFIG_PCI
  960. static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
  961. { PCI_DEVICE(0x1814, 0x0601) },
  962. { PCI_DEVICE(0x1814, 0x0681) },
  963. { PCI_DEVICE(0x1814, 0x0701) },
  964. { PCI_DEVICE(0x1814, 0x0781) },
  965. { PCI_DEVICE(0x1814, 0x3090) },
  966. { PCI_DEVICE(0x1814, 0x3091) },
  967. { PCI_DEVICE(0x1814, 0x3092) },
  968. { PCI_DEVICE(0x1432, 0x7708) },
  969. { PCI_DEVICE(0x1432, 0x7727) },
  970. { PCI_DEVICE(0x1432, 0x7728) },
  971. { PCI_DEVICE(0x1432, 0x7738) },
  972. { PCI_DEVICE(0x1432, 0x7748) },
  973. { PCI_DEVICE(0x1432, 0x7758) },
  974. { PCI_DEVICE(0x1432, 0x7768) },
  975. { PCI_DEVICE(0x1462, 0x891a) },
  976. { PCI_DEVICE(0x1a3b, 0x1059) },
  977. #ifdef CONFIG_RT2800PCI_RT33XX
  978. { PCI_DEVICE(0x1814, 0x3390) },
  979. #endif
  980. #ifdef CONFIG_RT2800PCI_RT35XX
  981. { PCI_DEVICE(0x1432, 0x7711) },
  982. { PCI_DEVICE(0x1432, 0x7722) },
  983. { PCI_DEVICE(0x1814, 0x3060) },
  984. { PCI_DEVICE(0x1814, 0x3062) },
  985. { PCI_DEVICE(0x1814, 0x3562) },
  986. { PCI_DEVICE(0x1814, 0x3592) },
  987. { PCI_DEVICE(0x1814, 0x3593) },
  988. #endif
  989. #ifdef CONFIG_RT2800PCI_RT53XX
  990. { PCI_DEVICE(0x1814, 0x5390) },
  991. { PCI_DEVICE(0x1814, 0x539a) },
  992. { PCI_DEVICE(0x1814, 0x539f) },
  993. #endif
  994. { 0, }
  995. };
  996. #endif /* CONFIG_PCI */
  997. MODULE_AUTHOR(DRV_PROJECT);
  998. MODULE_VERSION(DRV_VERSION);
  999. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  1000. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  1001. #ifdef CONFIG_PCI
  1002. MODULE_FIRMWARE(FIRMWARE_RT2860);
  1003. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  1004. #endif /* CONFIG_PCI */
  1005. MODULE_LICENSE("GPL");
  1006. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1007. static int rt2800soc_probe(struct platform_device *pdev)
  1008. {
  1009. return rt2x00soc_probe(pdev, &rt2800pci_ops);
  1010. }
  1011. static struct platform_driver rt2800soc_driver = {
  1012. .driver = {
  1013. .name = "rt2800_wmac",
  1014. .owner = THIS_MODULE,
  1015. .mod_name = KBUILD_MODNAME,
  1016. },
  1017. .probe = rt2800soc_probe,
  1018. .remove = __devexit_p(rt2x00soc_remove),
  1019. .suspend = rt2x00soc_suspend,
  1020. .resume = rt2x00soc_resume,
  1021. };
  1022. #endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */
  1023. #ifdef CONFIG_PCI
  1024. static int rt2800pci_probe(struct pci_dev *pci_dev,
  1025. const struct pci_device_id *id)
  1026. {
  1027. return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
  1028. }
  1029. static struct pci_driver rt2800pci_driver = {
  1030. .name = KBUILD_MODNAME,
  1031. .id_table = rt2800pci_device_table,
  1032. .probe = rt2800pci_probe,
  1033. .remove = __devexit_p(rt2x00pci_remove),
  1034. .suspend = rt2x00pci_suspend,
  1035. .resume = rt2x00pci_resume,
  1036. };
  1037. #endif /* CONFIG_PCI */
  1038. static int __init rt2800pci_init(void)
  1039. {
  1040. int ret = 0;
  1041. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1042. ret = platform_driver_register(&rt2800soc_driver);
  1043. if (ret)
  1044. return ret;
  1045. #endif
  1046. #ifdef CONFIG_PCI
  1047. ret = pci_register_driver(&rt2800pci_driver);
  1048. if (ret) {
  1049. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1050. platform_driver_unregister(&rt2800soc_driver);
  1051. #endif
  1052. return ret;
  1053. }
  1054. #endif
  1055. return ret;
  1056. }
  1057. static void __exit rt2800pci_exit(void)
  1058. {
  1059. #ifdef CONFIG_PCI
  1060. pci_unregister_driver(&rt2800pci_driver);
  1061. #endif
  1062. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1063. platform_driver_unregister(&rt2800soc_driver);
  1064. #endif
  1065. }
  1066. module_init(rt2800pci_init);
  1067. module_exit(rt2800pci_exit);