rt2800pci.c 36 KB

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