rt2800pci.c 39 KB

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