rt2800pci.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. rt2800_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_rt(rt2x00dev, RT5390)) {
  431. rt2x00pci_register_read(rt2x00dev, AUX_CTRL, &reg);
  432. rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
  433. rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
  434. rt2x00pci_register_write(rt2x00dev, AUX_CTRL, reg);
  435. }
  436. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  437. rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  438. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  439. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  440. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  441. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  442. return 0;
  443. }
  444. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  445. {
  446. if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
  447. rt2800pci_init_queues(rt2x00dev)))
  448. return -EIO;
  449. return rt2800_enable_radio(rt2x00dev);
  450. }
  451. static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  452. {
  453. if (rt2x00_is_soc(rt2x00dev)) {
  454. rt2800_disable_radio(rt2x00dev);
  455. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  456. rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, 0);
  457. }
  458. }
  459. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  460. enum dev_state state)
  461. {
  462. if (state == STATE_AWAKE) {
  463. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0x02);
  464. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
  465. } else if (state == STATE_SLEEP) {
  466. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
  467. 0xffffffff);
  468. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID,
  469. 0xffffffff);
  470. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0x01, 0xff, 0x01);
  471. }
  472. return 0;
  473. }
  474. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  475. enum dev_state state)
  476. {
  477. int retval = 0;
  478. switch (state) {
  479. case STATE_RADIO_ON:
  480. /*
  481. * Before the radio can be enabled, the device first has
  482. * to be woken up. After that it needs a bit of time
  483. * to be fully awake and then the radio can be enabled.
  484. */
  485. rt2800pci_set_state(rt2x00dev, STATE_AWAKE);
  486. msleep(1);
  487. retval = rt2800pci_enable_radio(rt2x00dev);
  488. break;
  489. case STATE_RADIO_OFF:
  490. /*
  491. * After the radio has been disabled, the device should
  492. * be put to sleep for powersaving.
  493. */
  494. rt2800pci_disable_radio(rt2x00dev);
  495. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  496. break;
  497. case STATE_RADIO_IRQ_ON:
  498. case STATE_RADIO_IRQ_OFF:
  499. rt2800pci_toggle_irq(rt2x00dev, state);
  500. break;
  501. case STATE_DEEP_SLEEP:
  502. case STATE_SLEEP:
  503. case STATE_STANDBY:
  504. case STATE_AWAKE:
  505. retval = rt2800pci_set_state(rt2x00dev, state);
  506. break;
  507. default:
  508. retval = -ENOTSUPP;
  509. break;
  510. }
  511. if (unlikely(retval))
  512. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  513. state, retval);
  514. return retval;
  515. }
  516. /*
  517. * TX descriptor initialization
  518. */
  519. static __le32 *rt2800pci_get_txwi(struct queue_entry *entry)
  520. {
  521. return (__le32 *) entry->skb->data;
  522. }
  523. static void rt2800pci_write_tx_desc(struct queue_entry *entry,
  524. struct txentry_desc *txdesc)
  525. {
  526. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  527. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  528. __le32 *txd = entry_priv->desc;
  529. u32 word;
  530. /*
  531. * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
  532. * must contains a TXWI structure + 802.11 header + padding + 802.11
  533. * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
  534. * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
  535. * data. It means that LAST_SEC0 is always 0.
  536. */
  537. /*
  538. * Initialize TX descriptor
  539. */
  540. rt2x00_desc_read(txd, 0, &word);
  541. rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
  542. rt2x00_desc_write(txd, 0, word);
  543. rt2x00_desc_read(txd, 1, &word);
  544. rt2x00_set_field32(&word, TXD_W1_SD_LEN1, entry->skb->len);
  545. rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
  546. !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  547. rt2x00_set_field32(&word, TXD_W1_BURST,
  548. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  549. rt2x00_set_field32(&word, TXD_W1_SD_LEN0, TXWI_DESC_SIZE);
  550. rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
  551. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
  552. rt2x00_desc_write(txd, 1, word);
  553. rt2x00_desc_read(txd, 2, &word);
  554. rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
  555. skbdesc->skb_dma + TXWI_DESC_SIZE);
  556. rt2x00_desc_write(txd, 2, word);
  557. rt2x00_desc_read(txd, 3, &word);
  558. rt2x00_set_field32(&word, TXD_W3_WIV,
  559. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  560. rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
  561. rt2x00_desc_write(txd, 3, word);
  562. /*
  563. * Register descriptor details in skb frame descriptor.
  564. */
  565. skbdesc->desc = txd;
  566. skbdesc->desc_len = TXD_DESC_SIZE;
  567. }
  568. /*
  569. * RX control handlers
  570. */
  571. static void rt2800pci_fill_rxdone(struct queue_entry *entry,
  572. struct rxdone_entry_desc *rxdesc)
  573. {
  574. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  575. __le32 *rxd = entry_priv->desc;
  576. u32 word;
  577. rt2x00_desc_read(rxd, 3, &word);
  578. if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
  579. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  580. /*
  581. * Unfortunately we don't know the cipher type used during
  582. * decryption. This prevents us from correct providing
  583. * correct statistics through debugfs.
  584. */
  585. rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
  586. if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
  587. /*
  588. * Hardware has stripped IV/EIV data from 802.11 frame during
  589. * decryption. Unfortunately the descriptor doesn't contain
  590. * any fields with the EIV/IV data either, so they can't
  591. * be restored by rt2x00lib.
  592. */
  593. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  594. /*
  595. * The hardware has already checked the Michael Mic and has
  596. * stripped it from the frame. Signal this to mac80211.
  597. */
  598. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  599. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  600. rxdesc->flags |= RX_FLAG_DECRYPTED;
  601. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  602. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  603. }
  604. if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
  605. rxdesc->dev_flags |= RXDONE_MY_BSS;
  606. if (rt2x00_get_field32(word, RXD_W3_L2PAD))
  607. rxdesc->dev_flags |= RXDONE_L2PAD;
  608. /*
  609. * Process the RXWI structure that is at the start of the buffer.
  610. */
  611. rt2800_process_rxwi(entry, rxdesc);
  612. }
  613. /*
  614. * Interrupt functions.
  615. */
  616. static void rt2800pci_wakeup(struct rt2x00_dev *rt2x00dev)
  617. {
  618. struct ieee80211_conf conf = { .flags = 0 };
  619. struct rt2x00lib_conf libconf = { .conf = &conf };
  620. rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
  621. }
  622. static bool rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
  623. {
  624. struct data_queue *queue;
  625. struct queue_entry *entry;
  626. u32 status;
  627. u8 qid;
  628. int max_tx_done = 16;
  629. while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
  630. qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
  631. if (unlikely(qid >= QID_RX)) {
  632. /*
  633. * Unknown queue, this shouldn't happen. Just drop
  634. * this tx status.
  635. */
  636. WARNING(rt2x00dev, "Got TX status report with "
  637. "unexpected pid %u, dropping\n", qid);
  638. break;
  639. }
  640. queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
  641. if (unlikely(queue == NULL)) {
  642. /*
  643. * The queue is NULL, this shouldn't happen. Stop
  644. * processing here and drop the tx status
  645. */
  646. WARNING(rt2x00dev, "Got TX status for an unavailable "
  647. "queue %u, dropping\n", qid);
  648. break;
  649. }
  650. if (unlikely(rt2x00queue_empty(queue))) {
  651. /*
  652. * The queue is empty. Stop processing here
  653. * and drop the tx status.
  654. */
  655. WARNING(rt2x00dev, "Got TX status for an empty "
  656. "queue %u, dropping\n", qid);
  657. break;
  658. }
  659. entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  660. rt2800_txdone_entry(entry, status);
  661. if (--max_tx_done == 0)
  662. break;
  663. }
  664. return !max_tx_done;
  665. }
  666. static inline void rt2800pci_enable_interrupt(struct rt2x00_dev *rt2x00dev,
  667. struct rt2x00_field32 irq_field)
  668. {
  669. u32 reg;
  670. /*
  671. * Enable a single interrupt. The interrupt mask register
  672. * access needs locking.
  673. */
  674. spin_lock_irq(&rt2x00dev->irqmask_lock);
  675. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  676. rt2x00_set_field32(&reg, irq_field, 1);
  677. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  678. spin_unlock_irq(&rt2x00dev->irqmask_lock);
  679. }
  680. static void rt2800pci_txstatus_tasklet(unsigned long data)
  681. {
  682. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  683. if (rt2800pci_txdone(rt2x00dev))
  684. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  685. /*
  686. * No need to enable the tx status interrupt here as we always
  687. * leave it enabled to minimize the possibility of a tx status
  688. * register overflow. See comment in interrupt handler.
  689. */
  690. }
  691. static void rt2800pci_pretbtt_tasklet(unsigned long data)
  692. {
  693. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  694. rt2x00lib_pretbtt(rt2x00dev);
  695. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_PRE_TBTT);
  696. }
  697. static void rt2800pci_tbtt_tasklet(unsigned long data)
  698. {
  699. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  700. rt2x00lib_beacondone(rt2x00dev);
  701. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_TBTT);
  702. }
  703. static void rt2800pci_rxdone_tasklet(unsigned long data)
  704. {
  705. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  706. if (rt2x00pci_rxdone(rt2x00dev))
  707. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  708. else
  709. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_RX_DONE);
  710. }
  711. static void rt2800pci_autowake_tasklet(unsigned long data)
  712. {
  713. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  714. rt2800pci_wakeup(rt2x00dev);
  715. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_AUTO_WAKEUP);
  716. }
  717. static void rt2800pci_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
  718. {
  719. u32 status;
  720. int i;
  721. /*
  722. * The TX_FIFO_STATUS interrupt needs special care. We should
  723. * read TX_STA_FIFO but we should do it immediately as otherwise
  724. * the register can overflow and we would lose status reports.
  725. *
  726. * Hence, read the TX_STA_FIFO register and copy all tx status
  727. * reports into a kernel FIFO which is handled in the txstatus
  728. * tasklet. We use a tasklet to process the tx status reports
  729. * because we can schedule the tasklet multiple times (when the
  730. * interrupt fires again during tx status processing).
  731. *
  732. * Furthermore we don't disable the TX_FIFO_STATUS
  733. * interrupt here but leave it enabled so that the TX_STA_FIFO
  734. * can also be read while the tx status tasklet gets executed.
  735. *
  736. * Since we have only one producer and one consumer we don't
  737. * need to lock the kfifo.
  738. */
  739. for (i = 0; i < rt2x00dev->ops->tx->entry_num; i++) {
  740. rt2x00pci_register_read(rt2x00dev, TX_STA_FIFO, &status);
  741. if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
  742. break;
  743. if (!kfifo_put(&rt2x00dev->txstatus_fifo, &status)) {
  744. WARNING(rt2x00dev, "TX status FIFO overrun,"
  745. "drop tx status report.\n");
  746. break;
  747. }
  748. }
  749. /* Schedule the tasklet for processing the tx status. */
  750. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  751. }
  752. static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
  753. {
  754. struct rt2x00_dev *rt2x00dev = dev_instance;
  755. u32 reg, mask;
  756. /* Read status and ACK all interrupts */
  757. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  758. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  759. if (!reg)
  760. return IRQ_NONE;
  761. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  762. return IRQ_HANDLED;
  763. /*
  764. * Since INT_MASK_CSR and INT_SOURCE_CSR use the same bits
  765. * for interrupts and interrupt masks we can just use the value of
  766. * INT_SOURCE_CSR to create the interrupt mask.
  767. */
  768. mask = ~reg;
  769. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
  770. rt2800pci_txstatus_interrupt(rt2x00dev);
  771. /*
  772. * Never disable the TX_FIFO_STATUS interrupt.
  773. */
  774. rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
  775. }
  776. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
  777. tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
  778. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TBTT))
  779. tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet);
  780. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
  781. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  782. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
  783. tasklet_schedule(&rt2x00dev->autowake_tasklet);
  784. /*
  785. * Disable all interrupts for which a tasklet was scheduled right now,
  786. * the tasklet will reenable the appropriate interrupts.
  787. */
  788. spin_lock(&rt2x00dev->irqmask_lock);
  789. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  790. reg &= mask;
  791. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  792. spin_unlock(&rt2x00dev->irqmask_lock);
  793. return IRQ_HANDLED;
  794. }
  795. /*
  796. * Device probe functions.
  797. */
  798. static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  799. {
  800. /*
  801. * Read EEPROM into buffer
  802. */
  803. if (rt2x00_is_soc(rt2x00dev))
  804. rt2800pci_read_eeprom_soc(rt2x00dev);
  805. else if (rt2800pci_efuse_detect(rt2x00dev))
  806. rt2800pci_read_eeprom_efuse(rt2x00dev);
  807. else
  808. rt2800pci_read_eeprom_pci(rt2x00dev);
  809. return rt2800_validate_eeprom(rt2x00dev);
  810. }
  811. static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  812. {
  813. int retval;
  814. /*
  815. * Allocate eeprom data.
  816. */
  817. retval = rt2800pci_validate_eeprom(rt2x00dev);
  818. if (retval)
  819. return retval;
  820. retval = rt2800_init_eeprom(rt2x00dev);
  821. if (retval)
  822. return retval;
  823. /*
  824. * Initialize hw specifications.
  825. */
  826. retval = rt2800_probe_hw_mode(rt2x00dev);
  827. if (retval)
  828. return retval;
  829. /*
  830. * This device has multiple filters for control frames
  831. * and has a separate filter for PS Poll frames.
  832. */
  833. __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
  834. __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
  835. /*
  836. * This device has a pre tbtt interrupt and thus fetches
  837. * a new beacon directly prior to transmission.
  838. */
  839. __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
  840. /*
  841. * This device requires firmware.
  842. */
  843. if (!rt2x00_is_soc(rt2x00dev))
  844. __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
  845. __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
  846. __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
  847. __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
  848. __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
  849. if (!modparam_nohwcrypt)
  850. __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
  851. __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
  852. __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
  853. /*
  854. * Set the rssi offset.
  855. */
  856. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  857. return 0;
  858. }
  859. static const struct ieee80211_ops rt2800pci_mac80211_ops = {
  860. .tx = rt2x00mac_tx,
  861. .start = rt2x00mac_start,
  862. .stop = rt2x00mac_stop,
  863. .add_interface = rt2x00mac_add_interface,
  864. .remove_interface = rt2x00mac_remove_interface,
  865. .config = rt2x00mac_config,
  866. .configure_filter = rt2x00mac_configure_filter,
  867. .set_key = rt2x00mac_set_key,
  868. .sw_scan_start = rt2x00mac_sw_scan_start,
  869. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  870. .get_stats = rt2x00mac_get_stats,
  871. .get_tkip_seq = rt2800_get_tkip_seq,
  872. .set_rts_threshold = rt2800_set_rts_threshold,
  873. .bss_info_changed = rt2x00mac_bss_info_changed,
  874. .conf_tx = rt2800_conf_tx,
  875. .get_tsf = rt2800_get_tsf,
  876. .rfkill_poll = rt2x00mac_rfkill_poll,
  877. .ampdu_action = rt2800_ampdu_action,
  878. .flush = rt2x00mac_flush,
  879. .get_survey = rt2800_get_survey,
  880. .get_ringparam = rt2x00mac_get_ringparam,
  881. };
  882. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  883. .register_read = rt2x00pci_register_read,
  884. .register_read_lock = rt2x00pci_register_read, /* same for PCI */
  885. .register_write = rt2x00pci_register_write,
  886. .register_write_lock = rt2x00pci_register_write, /* same for PCI */
  887. .register_multiread = rt2x00pci_register_multiread,
  888. .register_multiwrite = rt2x00pci_register_multiwrite,
  889. .regbusy_read = rt2x00pci_regbusy_read,
  890. .drv_write_firmware = rt2800pci_write_firmware,
  891. .drv_init_registers = rt2800pci_init_registers,
  892. .drv_get_txwi = rt2800pci_get_txwi,
  893. };
  894. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  895. .irq_handler = rt2800pci_interrupt,
  896. .txstatus_tasklet = rt2800pci_txstatus_tasklet,
  897. .pretbtt_tasklet = rt2800pci_pretbtt_tasklet,
  898. .tbtt_tasklet = rt2800pci_tbtt_tasklet,
  899. .rxdone_tasklet = rt2800pci_rxdone_tasklet,
  900. .autowake_tasklet = rt2800pci_autowake_tasklet,
  901. .probe_hw = rt2800pci_probe_hw,
  902. .get_firmware_name = rt2800pci_get_firmware_name,
  903. .check_firmware = rt2800_check_firmware,
  904. .load_firmware = rt2800_load_firmware,
  905. .initialize = rt2x00pci_initialize,
  906. .uninitialize = rt2x00pci_uninitialize,
  907. .get_entry_state = rt2800pci_get_entry_state,
  908. .clear_entry = rt2800pci_clear_entry,
  909. .set_device_state = rt2800pci_set_device_state,
  910. .rfkill_poll = rt2800_rfkill_poll,
  911. .link_stats = rt2800_link_stats,
  912. .reset_tuner = rt2800_reset_tuner,
  913. .link_tuner = rt2800_link_tuner,
  914. .gain_calibration = rt2800_gain_calibration,
  915. .start_queue = rt2800pci_start_queue,
  916. .kick_queue = rt2800pci_kick_queue,
  917. .stop_queue = rt2800pci_stop_queue,
  918. .flush_queue = rt2x00pci_flush_queue,
  919. .write_tx_desc = rt2800pci_write_tx_desc,
  920. .write_tx_data = rt2800_write_tx_data,
  921. .write_beacon = rt2800_write_beacon,
  922. .clear_beacon = rt2800_clear_beacon,
  923. .fill_rxdone = rt2800pci_fill_rxdone,
  924. .config_shared_key = rt2800_config_shared_key,
  925. .config_pairwise_key = rt2800_config_pairwise_key,
  926. .config_filter = rt2800_config_filter,
  927. .config_intf = rt2800_config_intf,
  928. .config_erp = rt2800_config_erp,
  929. .config_ant = rt2800_config_ant,
  930. .config = rt2800_config,
  931. };
  932. static const struct data_queue_desc rt2800pci_queue_rx = {
  933. .entry_num = 128,
  934. .data_size = AGGREGATION_SIZE,
  935. .desc_size = RXD_DESC_SIZE,
  936. .priv_size = sizeof(struct queue_entry_priv_pci),
  937. };
  938. static const struct data_queue_desc rt2800pci_queue_tx = {
  939. .entry_num = 64,
  940. .data_size = AGGREGATION_SIZE,
  941. .desc_size = TXD_DESC_SIZE,
  942. .priv_size = sizeof(struct queue_entry_priv_pci),
  943. };
  944. static const struct data_queue_desc rt2800pci_queue_bcn = {
  945. .entry_num = 8,
  946. .data_size = 0, /* No DMA required for beacons */
  947. .desc_size = TXWI_DESC_SIZE,
  948. .priv_size = sizeof(struct queue_entry_priv_pci),
  949. };
  950. static const struct rt2x00_ops rt2800pci_ops = {
  951. .name = KBUILD_MODNAME,
  952. .max_sta_intf = 1,
  953. .max_ap_intf = 8,
  954. .eeprom_size = EEPROM_SIZE,
  955. .rf_size = RF_SIZE,
  956. .tx_queues = NUM_TX_QUEUES,
  957. .extra_tx_headroom = TXWI_DESC_SIZE,
  958. .rx = &rt2800pci_queue_rx,
  959. .tx = &rt2800pci_queue_tx,
  960. .bcn = &rt2800pci_queue_bcn,
  961. .lib = &rt2800pci_rt2x00_ops,
  962. .drv = &rt2800pci_rt2800_ops,
  963. .hw = &rt2800pci_mac80211_ops,
  964. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  965. .debugfs = &rt2800_rt2x00debug,
  966. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  967. };
  968. /*
  969. * RT2800pci module information.
  970. */
  971. #ifdef CONFIG_PCI
  972. static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
  973. { PCI_DEVICE(0x1814, 0x0601) },
  974. { PCI_DEVICE(0x1814, 0x0681) },
  975. { PCI_DEVICE(0x1814, 0x0701) },
  976. { PCI_DEVICE(0x1814, 0x0781) },
  977. { PCI_DEVICE(0x1814, 0x3090) },
  978. { PCI_DEVICE(0x1814, 0x3091) },
  979. { PCI_DEVICE(0x1814, 0x3092) },
  980. { PCI_DEVICE(0x1432, 0x7708) },
  981. { PCI_DEVICE(0x1432, 0x7727) },
  982. { PCI_DEVICE(0x1432, 0x7728) },
  983. { PCI_DEVICE(0x1432, 0x7738) },
  984. { PCI_DEVICE(0x1432, 0x7748) },
  985. { PCI_DEVICE(0x1432, 0x7758) },
  986. { PCI_DEVICE(0x1432, 0x7768) },
  987. { PCI_DEVICE(0x1462, 0x891a) },
  988. { PCI_DEVICE(0x1a3b, 0x1059) },
  989. #ifdef CONFIG_RT2800PCI_RT33XX
  990. { PCI_DEVICE(0x1814, 0x3390) },
  991. #endif
  992. #ifdef CONFIG_RT2800PCI_RT35XX
  993. { PCI_DEVICE(0x1432, 0x7711) },
  994. { PCI_DEVICE(0x1432, 0x7722) },
  995. { PCI_DEVICE(0x1814, 0x3060) },
  996. { PCI_DEVICE(0x1814, 0x3062) },
  997. { PCI_DEVICE(0x1814, 0x3562) },
  998. { PCI_DEVICE(0x1814, 0x3592) },
  999. { PCI_DEVICE(0x1814, 0x3593) },
  1000. #endif
  1001. #ifdef CONFIG_RT2800PCI_RT53XX
  1002. { PCI_DEVICE(0x1814, 0x5390) },
  1003. #endif
  1004. { 0, }
  1005. };
  1006. #endif /* CONFIG_PCI */
  1007. MODULE_AUTHOR(DRV_PROJECT);
  1008. MODULE_VERSION(DRV_VERSION);
  1009. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  1010. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  1011. #ifdef CONFIG_PCI
  1012. MODULE_FIRMWARE(FIRMWARE_RT2860);
  1013. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  1014. #endif /* CONFIG_PCI */
  1015. MODULE_LICENSE("GPL");
  1016. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1017. static int rt2800soc_probe(struct platform_device *pdev)
  1018. {
  1019. return rt2x00soc_probe(pdev, &rt2800pci_ops);
  1020. }
  1021. static struct platform_driver rt2800soc_driver = {
  1022. .driver = {
  1023. .name = "rt2800_wmac",
  1024. .owner = THIS_MODULE,
  1025. .mod_name = KBUILD_MODNAME,
  1026. },
  1027. .probe = rt2800soc_probe,
  1028. .remove = __devexit_p(rt2x00soc_remove),
  1029. .suspend = rt2x00soc_suspend,
  1030. .resume = rt2x00soc_resume,
  1031. };
  1032. #endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */
  1033. #ifdef CONFIG_PCI
  1034. static int rt2800pci_probe(struct pci_dev *pci_dev,
  1035. const struct pci_device_id *id)
  1036. {
  1037. return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
  1038. }
  1039. static struct pci_driver rt2800pci_driver = {
  1040. .name = KBUILD_MODNAME,
  1041. .id_table = rt2800pci_device_table,
  1042. .probe = rt2800pci_probe,
  1043. .remove = __devexit_p(rt2x00pci_remove),
  1044. .suspend = rt2x00pci_suspend,
  1045. .resume = rt2x00pci_resume,
  1046. };
  1047. #endif /* CONFIG_PCI */
  1048. static int __init rt2800pci_init(void)
  1049. {
  1050. int ret = 0;
  1051. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1052. ret = platform_driver_register(&rt2800soc_driver);
  1053. if (ret)
  1054. return ret;
  1055. #endif
  1056. #ifdef CONFIG_PCI
  1057. ret = pci_register_driver(&rt2800pci_driver);
  1058. if (ret) {
  1059. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1060. platform_driver_unregister(&rt2800soc_driver);
  1061. #endif
  1062. return ret;
  1063. }
  1064. #endif
  1065. return ret;
  1066. }
  1067. static void __exit rt2800pci_exit(void)
  1068. {
  1069. #ifdef CONFIG_PCI
  1070. pci_unregister_driver(&rt2800pci_driver);
  1071. #endif
  1072. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1073. platform_driver_unregister(&rt2800soc_driver);
  1074. #endif
  1075. }
  1076. module_init(rt2800pci_init);
  1077. module_exit(rt2800pci_exit);