rt2800pci.c 34 KB

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