rt2800pci.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. Copyright (C) 2009 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/crc-ccitt.h>
  30. #include <linux/delay.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/init.h>
  33. #include <linux/kernel.h>
  34. #include <linux/module.h>
  35. #include <linux/pci.h>
  36. #include <linux/platform_device.h>
  37. #include <linux/eeprom_93cx6.h>
  38. #include "rt2x00.h"
  39. #include "rt2x00pci.h"
  40. #include "rt2x00soc.h"
  41. #include "rt2800lib.h"
  42. #include "rt2800.h"
  43. #include "rt2800pci.h"
  44. /*
  45. * Allow hardware encryption to be disabled.
  46. */
  47. static int modparam_nohwcrypt = 1;
  48. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  49. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  50. static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
  51. {
  52. unsigned int i;
  53. u32 reg;
  54. /*
  55. * SOC devices don't support MCU requests.
  56. */
  57. if (rt2x00_is_soc(rt2x00dev))
  58. return;
  59. for (i = 0; i < 200; i++) {
  60. rt2800_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
  61. if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
  62. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
  63. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
  64. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
  65. break;
  66. udelay(REGISTER_BUSY_DELAY);
  67. }
  68. if (i == 200)
  69. ERROR(rt2x00dev, "MCU request failed, no response from hardware\n");
  70. rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  71. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  72. }
  73. #ifdef CONFIG_RT2800PCI_SOC
  74. static void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
  75. {
  76. u32 *base_addr = (u32 *) KSEG1ADDR(0x1F040000); /* XXX for RT3052 */
  77. memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
  78. }
  79. #else
  80. static inline void rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
  81. {
  82. }
  83. #endif /* CONFIG_RT2800PCI_SOC */
  84. #ifdef CONFIG_RT2800PCI_PCI
  85. static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  86. {
  87. struct rt2x00_dev *rt2x00dev = eeprom->data;
  88. u32 reg;
  89. rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
  90. eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
  91. eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
  92. eeprom->reg_data_clock =
  93. !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
  94. eeprom->reg_chip_select =
  95. !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
  96. }
  97. static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  98. {
  99. struct rt2x00_dev *rt2x00dev = eeprom->data;
  100. u32 reg = 0;
  101. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
  102. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
  103. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
  104. !!eeprom->reg_data_clock);
  105. rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
  106. !!eeprom->reg_chip_select);
  107. rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
  108. }
  109. static void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
  110. {
  111. struct eeprom_93cx6 eeprom;
  112. u32 reg;
  113. rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
  114. eeprom.data = rt2x00dev;
  115. eeprom.register_read = rt2800pci_eepromregister_read;
  116. eeprom.register_write = rt2800pci_eepromregister_write;
  117. eeprom.width = !rt2x00_get_field32(reg, E2PROM_CSR_TYPE) ?
  118. PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
  119. eeprom.reg_data_in = 0;
  120. eeprom.reg_data_out = 0;
  121. eeprom.reg_data_clock = 0;
  122. eeprom.reg_chip_select = 0;
  123. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  124. EEPROM_SIZE / sizeof(u16));
  125. }
  126. static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
  127. {
  128. return rt2800_efuse_detect(rt2x00dev);
  129. }
  130. static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  131. {
  132. rt2800_read_eeprom_efuse(rt2x00dev);
  133. }
  134. #else
  135. static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
  136. {
  137. }
  138. static inline int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
  139. {
  140. return 0;
  141. }
  142. static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  143. {
  144. }
  145. #endif /* CONFIG_RT2800PCI_PCI */
  146. /*
  147. * Firmware functions
  148. */
  149. static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  150. {
  151. return FIRMWARE_RT2860;
  152. }
  153. static int rt2800pci_check_firmware(struct rt2x00_dev *rt2x00dev,
  154. const u8 *data, const size_t len)
  155. {
  156. u16 fw_crc;
  157. u16 crc;
  158. /*
  159. * Only support 8kb firmware files.
  160. */
  161. if (len != 8192)
  162. return FW_BAD_LENGTH;
  163. /*
  164. * The last 2 bytes in the firmware array are the crc checksum itself,
  165. * this means that we should never pass those 2 bytes to the crc
  166. * algorithm.
  167. */
  168. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  169. /*
  170. * Use the crc ccitt algorithm.
  171. * This will return the same value as the legacy driver which
  172. * used bit ordering reversion on the both the firmware bytes
  173. * before input input as well as on the final output.
  174. * Obviously using crc ccitt directly is much more efficient.
  175. */
  176. crc = crc_ccitt(~0, data, len - 2);
  177. /*
  178. * There is a small difference between the crc-itu-t + bitrev and
  179. * the crc-ccitt crc calculation. In the latter method the 2 bytes
  180. * will be swapped, use swab16 to convert the crc to the correct
  181. * value.
  182. */
  183. crc = swab16(crc);
  184. return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
  185. }
  186. static int rt2800pci_load_firmware(struct rt2x00_dev *rt2x00dev,
  187. const u8 *data, const size_t len)
  188. {
  189. unsigned int i;
  190. u32 reg;
  191. /*
  192. * Wait for stable hardware.
  193. */
  194. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  195. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  196. if (reg && reg != ~0)
  197. break;
  198. msleep(1);
  199. }
  200. if (i == REGISTER_BUSY_COUNT) {
  201. ERROR(rt2x00dev, "Unstable hardware.\n");
  202. return -EBUSY;
  203. }
  204. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
  205. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
  206. /*
  207. * Disable DMA, will be reenabled later when enabling
  208. * the radio.
  209. */
  210. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  211. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  212. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  213. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  214. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  215. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  216. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  217. /*
  218. * enable Host program ram write selection
  219. */
  220. reg = 0;
  221. rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
  222. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
  223. /*
  224. * Write firmware to device.
  225. */
  226. rt2800_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  227. data, len);
  228. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
  229. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
  230. /*
  231. * Wait for device to stabilize.
  232. */
  233. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  234. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  235. if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  236. break;
  237. msleep(1);
  238. }
  239. if (i == REGISTER_BUSY_COUNT) {
  240. ERROR(rt2x00dev, "PBF system register not ready.\n");
  241. return -EBUSY;
  242. }
  243. /*
  244. * Disable interrupts
  245. */
  246. rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);
  247. /*
  248. * Initialize BBP R/W access agent
  249. */
  250. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  251. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  252. return 0;
  253. }
  254. /*
  255. * Initialization functions.
  256. */
  257. static bool rt2800pci_get_entry_state(struct queue_entry *entry)
  258. {
  259. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  260. u32 word;
  261. if (entry->queue->qid == QID_RX) {
  262. rt2x00_desc_read(entry_priv->desc, 1, &word);
  263. return (!rt2x00_get_field32(word, RXD_W1_DMA_DONE));
  264. } else {
  265. rt2x00_desc_read(entry_priv->desc, 1, &word);
  266. return (!rt2x00_get_field32(word, TXD_W1_DMA_DONE));
  267. }
  268. }
  269. static void rt2800pci_clear_entry(struct queue_entry *entry)
  270. {
  271. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  272. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  273. u32 word;
  274. if (entry->queue->qid == QID_RX) {
  275. rt2x00_desc_read(entry_priv->desc, 0, &word);
  276. rt2x00_set_field32(&word, RXD_W0_SDP0, skbdesc->skb_dma);
  277. rt2x00_desc_write(entry_priv->desc, 0, word);
  278. rt2x00_desc_read(entry_priv->desc, 1, &word);
  279. rt2x00_set_field32(&word, RXD_W1_DMA_DONE, 0);
  280. rt2x00_desc_write(entry_priv->desc, 1, word);
  281. } else {
  282. rt2x00_desc_read(entry_priv->desc, 1, &word);
  283. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 1);
  284. rt2x00_desc_write(entry_priv->desc, 1, word);
  285. }
  286. }
  287. static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
  288. {
  289. struct queue_entry_priv_pci *entry_priv;
  290. u32 reg;
  291. /*
  292. * Initialize registers.
  293. */
  294. entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
  295. rt2800_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma);
  296. rt2800_register_write(rt2x00dev, TX_MAX_CNT0, rt2x00dev->tx[0].limit);
  297. rt2800_register_write(rt2x00dev, TX_CTX_IDX0, 0);
  298. rt2800_register_write(rt2x00dev, TX_DTX_IDX0, 0);
  299. entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
  300. rt2800_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma);
  301. rt2800_register_write(rt2x00dev, TX_MAX_CNT1, rt2x00dev->tx[1].limit);
  302. rt2800_register_write(rt2x00dev, TX_CTX_IDX1, 0);
  303. rt2800_register_write(rt2x00dev, TX_DTX_IDX1, 0);
  304. entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
  305. rt2800_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma);
  306. rt2800_register_write(rt2x00dev, TX_MAX_CNT2, rt2x00dev->tx[2].limit);
  307. rt2800_register_write(rt2x00dev, TX_CTX_IDX2, 0);
  308. rt2800_register_write(rt2x00dev, TX_DTX_IDX2, 0);
  309. entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
  310. rt2800_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma);
  311. rt2800_register_write(rt2x00dev, TX_MAX_CNT3, rt2x00dev->tx[3].limit);
  312. rt2800_register_write(rt2x00dev, TX_CTX_IDX3, 0);
  313. rt2800_register_write(rt2x00dev, TX_DTX_IDX3, 0);
  314. entry_priv = rt2x00dev->rx->entries[0].priv_data;
  315. rt2800_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
  316. rt2800_register_write(rt2x00dev, RX_MAX_CNT, rt2x00dev->rx[0].limit);
  317. rt2800_register_write(rt2x00dev, RX_CRX_IDX, rt2x00dev->rx[0].limit - 1);
  318. rt2800_register_write(rt2x00dev, RX_DRX_IDX, 0);
  319. /*
  320. * Enable global DMA configuration
  321. */
  322. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  323. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  324. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  325. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  326. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  327. rt2800_register_write(rt2x00dev, DELAY_INT_CFG, 0);
  328. return 0;
  329. }
  330. /*
  331. * Device state switch handlers.
  332. */
  333. static void rt2800pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
  334. enum dev_state state)
  335. {
  336. u32 reg;
  337. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  338. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  339. (state == STATE_RADIO_RX_ON) ||
  340. (state == STATE_RADIO_RX_ON_LINK));
  341. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  342. }
  343. static void rt2800pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  344. enum dev_state state)
  345. {
  346. int mask = (state == STATE_RADIO_IRQ_ON);
  347. u32 reg;
  348. /*
  349. * When interrupts are being enabled, the interrupt registers
  350. * should clear the register to assure a clean state.
  351. */
  352. if (state == STATE_RADIO_IRQ_ON) {
  353. rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  354. rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  355. }
  356. rt2800_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  357. rt2x00_set_field32(&reg, INT_MASK_CSR_RXDELAYINT, mask);
  358. rt2x00_set_field32(&reg, INT_MASK_CSR_TXDELAYINT, mask);
  359. rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, mask);
  360. rt2x00_set_field32(&reg, INT_MASK_CSR_AC0_DMA_DONE, mask);
  361. rt2x00_set_field32(&reg, INT_MASK_CSR_AC1_DMA_DONE, mask);
  362. rt2x00_set_field32(&reg, INT_MASK_CSR_AC2_DMA_DONE, mask);
  363. rt2x00_set_field32(&reg, INT_MASK_CSR_AC3_DMA_DONE, mask);
  364. rt2x00_set_field32(&reg, INT_MASK_CSR_HCCA_DMA_DONE, mask);
  365. rt2x00_set_field32(&reg, INT_MASK_CSR_MGMT_DMA_DONE, mask);
  366. rt2x00_set_field32(&reg, INT_MASK_CSR_MCU_COMMAND, mask);
  367. rt2x00_set_field32(&reg, INT_MASK_CSR_RXTX_COHERENT, mask);
  368. rt2x00_set_field32(&reg, INT_MASK_CSR_TBTT, mask);
  369. rt2x00_set_field32(&reg, INT_MASK_CSR_PRE_TBTT, mask);
  370. rt2x00_set_field32(&reg, INT_MASK_CSR_TX_FIFO_STATUS, mask);
  371. rt2x00_set_field32(&reg, INT_MASK_CSR_AUTO_WAKEUP, mask);
  372. rt2x00_set_field32(&reg, INT_MASK_CSR_GPTIMER, mask);
  373. rt2x00_set_field32(&reg, INT_MASK_CSR_RX_COHERENT, mask);
  374. rt2x00_set_field32(&reg, INT_MASK_CSR_TX_COHERENT, mask);
  375. rt2800_register_write(rt2x00dev, INT_MASK_CSR, reg);
  376. }
  377. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  378. {
  379. u32 reg;
  380. u16 word;
  381. /*
  382. * Initialize all registers.
  383. */
  384. if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
  385. rt2800pci_init_queues(rt2x00dev) ||
  386. rt2800_init_registers(rt2x00dev) ||
  387. rt2800_wait_wpdma_ready(rt2x00dev) ||
  388. rt2800_init_bbp(rt2x00dev) ||
  389. rt2800_init_rfcsr(rt2x00dev)))
  390. return -EIO;
  391. /*
  392. * Send signal to firmware during boot time.
  393. */
  394. rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  395. /*
  396. * Enable RX.
  397. */
  398. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  399. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  400. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
  401. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  402. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  403. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  404. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  405. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
  406. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  407. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  408. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  409. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  410. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  411. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  412. /*
  413. * Initialize LED control
  414. */
  415. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  416. rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  417. word & 0xff, (word >> 8) & 0xff);
  418. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  419. rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  420. word & 0xff, (word >> 8) & 0xff);
  421. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  422. rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  423. word & 0xff, (word >> 8) & 0xff);
  424. return 0;
  425. }
  426. static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  427. {
  428. u32 reg;
  429. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  430. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  431. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  432. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  433. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  434. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  435. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  436. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  437. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  438. rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
  439. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001280);
  440. rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
  441. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
  442. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
  443. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
  444. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
  445. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
  446. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
  447. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
  448. rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
  449. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
  450. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
  451. /* Wait for DMA, ignore error */
  452. rt2800_wait_wpdma_ready(rt2x00dev);
  453. }
  454. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  455. enum dev_state state)
  456. {
  457. /*
  458. * Always put the device to sleep (even when we intend to wakeup!)
  459. * if the device is booting and wasn't asleep it will return
  460. * failure when attempting to wakeup.
  461. */
  462. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  463. if (state == STATE_AWAKE) {
  464. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0);
  465. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
  466. }
  467. return 0;
  468. }
  469. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  470. enum dev_state state)
  471. {
  472. int retval = 0;
  473. switch (state) {
  474. case STATE_RADIO_ON:
  475. /*
  476. * Before the radio can be enabled, the device first has
  477. * to be woken up. After that it needs a bit of time
  478. * to be fully awake and then the radio can be enabled.
  479. */
  480. rt2800pci_set_state(rt2x00dev, STATE_AWAKE);
  481. msleep(1);
  482. retval = rt2800pci_enable_radio(rt2x00dev);
  483. break;
  484. case STATE_RADIO_OFF:
  485. /*
  486. * After the radio has been disabled, the device should
  487. * be put to sleep for powersaving.
  488. */
  489. rt2800pci_disable_radio(rt2x00dev);
  490. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  491. break;
  492. case STATE_RADIO_RX_ON:
  493. case STATE_RADIO_RX_ON_LINK:
  494. case STATE_RADIO_RX_OFF:
  495. case STATE_RADIO_RX_OFF_LINK:
  496. rt2800pci_toggle_rx(rt2x00dev, state);
  497. break;
  498. case STATE_RADIO_IRQ_ON:
  499. case STATE_RADIO_IRQ_OFF:
  500. rt2800pci_toggle_irq(rt2x00dev, state);
  501. break;
  502. case STATE_DEEP_SLEEP:
  503. case STATE_SLEEP:
  504. case STATE_STANDBY:
  505. case STATE_AWAKE:
  506. retval = rt2800pci_set_state(rt2x00dev, state);
  507. break;
  508. default:
  509. retval = -ENOTSUPP;
  510. break;
  511. }
  512. if (unlikely(retval))
  513. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  514. state, retval);
  515. return retval;
  516. }
  517. /*
  518. * TX descriptor initialization
  519. */
  520. static int rt2800pci_write_tx_data(struct queue_entry* entry,
  521. struct txentry_desc *txdesc)
  522. {
  523. int ret;
  524. ret = rt2x00pci_write_tx_data(entry, txdesc);
  525. if (ret)
  526. return ret;
  527. rt2800_write_txwi(entry->skb, txdesc);
  528. return 0;
  529. }
  530. static void rt2800pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  531. struct sk_buff *skb,
  532. struct txentry_desc *txdesc)
  533. {
  534. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  535. __le32 *txd = skbdesc->desc;
  536. u32 word;
  537. /*
  538. * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
  539. * must contains a TXWI structure + 802.11 header + padding + 802.11
  540. * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
  541. * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
  542. * data. It means that LAST_SEC0 is always 0.
  543. */
  544. /*
  545. * Initialize TX descriptor
  546. */
  547. rt2x00_desc_read(txd, 0, &word);
  548. rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
  549. rt2x00_desc_write(txd, 0, word);
  550. rt2x00_desc_read(txd, 1, &word);
  551. rt2x00_set_field32(&word, TXD_W1_SD_LEN1, skb->len);
  552. rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
  553. !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  554. rt2x00_set_field32(&word, TXD_W1_BURST,
  555. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  556. rt2x00_set_field32(&word, TXD_W1_SD_LEN0,
  557. rt2x00dev->ops->extra_tx_headroom);
  558. rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
  559. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
  560. rt2x00_desc_write(txd, 1, word);
  561. rt2x00_desc_read(txd, 2, &word);
  562. rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
  563. skbdesc->skb_dma + rt2x00dev->ops->extra_tx_headroom);
  564. rt2x00_desc_write(txd, 2, word);
  565. rt2x00_desc_read(txd, 3, &word);
  566. rt2x00_set_field32(&word, TXD_W3_WIV,
  567. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  568. rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
  569. rt2x00_desc_write(txd, 3, word);
  570. }
  571. /*
  572. * TX data initialization
  573. */
  574. static void rt2800pci_write_beacon(struct queue_entry *entry)
  575. {
  576. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  577. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  578. unsigned int beacon_base;
  579. u32 reg;
  580. /*
  581. * Disable beaconing while we are reloading the beacon data,
  582. * otherwise we might be sending out invalid data.
  583. */
  584. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  585. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  586. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  587. /*
  588. * Write entire beacon with descriptor to register.
  589. */
  590. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  591. rt2800_register_multiwrite(rt2x00dev,
  592. beacon_base,
  593. skbdesc->desc, skbdesc->desc_len);
  594. rt2800_register_multiwrite(rt2x00dev,
  595. beacon_base + skbdesc->desc_len,
  596. entry->skb->data, entry->skb->len);
  597. /*
  598. * Clean up beacon skb.
  599. */
  600. dev_kfree_skb_any(entry->skb);
  601. entry->skb = NULL;
  602. }
  603. static void rt2800pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  604. const enum data_queue_qid queue_idx)
  605. {
  606. struct data_queue *queue;
  607. unsigned int idx, qidx = 0;
  608. u32 reg;
  609. if (queue_idx == QID_BEACON) {
  610. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  611. if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  612. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  613. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  614. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  615. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  616. }
  617. return;
  618. }
  619. if (queue_idx > QID_HCCA && queue_idx != QID_MGMT)
  620. return;
  621. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  622. idx = queue->index[Q_INDEX];
  623. if (queue_idx == QID_MGMT)
  624. qidx = 5;
  625. else
  626. qidx = queue_idx;
  627. rt2800_register_write(rt2x00dev, TX_CTX_IDX(qidx), idx);
  628. }
  629. static void rt2800pci_kill_tx_queue(struct rt2x00_dev *rt2x00dev,
  630. const enum data_queue_qid qid)
  631. {
  632. u32 reg;
  633. if (qid == QID_BEACON) {
  634. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, 0);
  635. return;
  636. }
  637. rt2800_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
  638. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, (qid == QID_AC_BE));
  639. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, (qid == QID_AC_BK));
  640. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, (qid == QID_AC_VI));
  641. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, (qid == QID_AC_VO));
  642. rt2800_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
  643. }
  644. /*
  645. * RX control handlers
  646. */
  647. static void rt2800pci_fill_rxdone(struct queue_entry *entry,
  648. struct rxdone_entry_desc *rxdesc)
  649. {
  650. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  651. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  652. __le32 *rxd = entry_priv->desc;
  653. u32 word;
  654. rt2x00_desc_read(rxd, 3, &word);
  655. if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
  656. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  657. /*
  658. * Unfortunately we don't know the cipher type used during
  659. * decryption. This prevents us from correct providing
  660. * correct statistics through debugfs.
  661. */
  662. rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
  663. if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
  664. /*
  665. * Hardware has stripped IV/EIV data from 802.11 frame during
  666. * decryption. Unfortunately the descriptor doesn't contain
  667. * any fields with the EIV/IV data either, so they can't
  668. * be restored by rt2x00lib.
  669. */
  670. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  671. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  672. rxdesc->flags |= RX_FLAG_DECRYPTED;
  673. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  674. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  675. }
  676. if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
  677. rxdesc->dev_flags |= RXDONE_MY_BSS;
  678. if (rt2x00_get_field32(word, RXD_W3_L2PAD))
  679. rxdesc->dev_flags |= RXDONE_L2PAD;
  680. /*
  681. * Process the RXWI structure that is at the start of the buffer.
  682. */
  683. rt2800_process_rxwi(entry->skb, rxdesc);
  684. /*
  685. * Set RX IDX in register to inform hardware that we have handled
  686. * this entry and it is available for reuse again.
  687. */
  688. rt2800_register_write(rt2x00dev, RX_CRX_IDX, entry->entry_idx);
  689. }
  690. /*
  691. * Interrupt functions.
  692. */
  693. static void rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
  694. {
  695. struct data_queue *queue;
  696. struct queue_entry *entry;
  697. __le32 *txwi;
  698. struct txdone_entry_desc txdesc;
  699. u32 word;
  700. u32 reg;
  701. u32 old_reg;
  702. int wcid, ack, pid, tx_wcid, tx_ack, tx_pid;
  703. u16 mcs, real_mcs;
  704. /*
  705. * During each loop we will compare the freshly read
  706. * TX_STA_FIFO register value with the value read from
  707. * the previous loop. If the 2 values are equal then
  708. * we should stop processing because the chance it
  709. * quite big that the device has been unplugged and
  710. * we risk going into an endless loop.
  711. */
  712. old_reg = 0;
  713. while (1) {
  714. rt2800_register_read(rt2x00dev, TX_STA_FIFO, &reg);
  715. if (!rt2x00_get_field32(reg, TX_STA_FIFO_VALID))
  716. break;
  717. if (old_reg == reg)
  718. break;
  719. old_reg = reg;
  720. wcid = rt2x00_get_field32(reg, TX_STA_FIFO_WCID);
  721. ack = rt2x00_get_field32(reg, TX_STA_FIFO_TX_ACK_REQUIRED);
  722. pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
  723. /*
  724. * Skip this entry when it contains an invalid
  725. * queue identication number.
  726. */
  727. if (pid <= 0 || pid > QID_RX)
  728. continue;
  729. queue = rt2x00queue_get_queue(rt2x00dev, pid - 1);
  730. if (unlikely(!queue))
  731. continue;
  732. /*
  733. * Inside each queue, we process each entry in a chronological
  734. * order. We first check that the queue is not empty.
  735. */
  736. if (rt2x00queue_empty(queue))
  737. continue;
  738. entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  739. /* Check if we got a match by looking at WCID/ACK/PID
  740. * fields */
  741. txwi = (__le32 *)(entry->skb->data -
  742. rt2x00dev->ops->extra_tx_headroom);
  743. rt2x00_desc_read(txwi, 1, &word);
  744. tx_wcid = rt2x00_get_field32(word, TXWI_W1_WIRELESS_CLI_ID);
  745. tx_ack = rt2x00_get_field32(word, TXWI_W1_ACK);
  746. tx_pid = rt2x00_get_field32(word, TXWI_W1_PACKETID);
  747. if ((wcid != tx_wcid) || (ack != tx_ack) || (pid != tx_pid))
  748. WARNING(rt2x00dev, "invalid TX_STA_FIFO content\n");
  749. /*
  750. * Obtain the status about this packet.
  751. */
  752. txdesc.flags = 0;
  753. rt2x00_desc_read(txwi, 0, &word);
  754. mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
  755. real_mcs = rt2x00_get_field32(reg, TX_STA_FIFO_MCS);
  756. /*
  757. * Ralink has a retry mechanism using a global fallback
  758. * table. We setup this fallback table to try the immediate
  759. * lower rate for all rates. In the TX_STA_FIFO, the MCS field
  760. * always contains the MCS used for the last transmission, be
  761. * it successful or not.
  762. */
  763. if (rt2x00_get_field32(reg, TX_STA_FIFO_TX_SUCCESS)) {
  764. /*
  765. * Transmission succeeded. The number of retries is
  766. * mcs - real_mcs
  767. */
  768. __set_bit(TXDONE_SUCCESS, &txdesc.flags);
  769. txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
  770. } else {
  771. /*
  772. * Transmission failed. The number of retries is
  773. * always 7 in this case (for a total number of 8
  774. * frames sent).
  775. */
  776. __set_bit(TXDONE_FAILURE, &txdesc.flags);
  777. txdesc.retry = 7;
  778. }
  779. __set_bit(TXDONE_FALLBACK, &txdesc.flags);
  780. rt2x00lib_txdone(entry, &txdesc);
  781. }
  782. }
  783. static void rt2800pci_wakeup(struct rt2x00_dev *rt2x00dev)
  784. {
  785. struct ieee80211_conf conf = { .flags = 0 };
  786. struct rt2x00lib_conf libconf = { .conf = &conf };
  787. rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
  788. }
  789. static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
  790. {
  791. struct rt2x00_dev *rt2x00dev = dev_instance;
  792. u32 reg;
  793. /* Read status and ACK all interrupts */
  794. rt2800_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  795. rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  796. if (!reg)
  797. return IRQ_NONE;
  798. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  799. return IRQ_HANDLED;
  800. /*
  801. * 1 - Rx ring done interrupt.
  802. */
  803. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
  804. rt2x00pci_rxdone(rt2x00dev);
  805. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS))
  806. rt2800pci_txdone(rt2x00dev);
  807. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
  808. rt2800pci_wakeup(rt2x00dev);
  809. return IRQ_HANDLED;
  810. }
  811. /*
  812. * Device probe functions.
  813. */
  814. static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  815. {
  816. /*
  817. * Read EEPROM into buffer
  818. */
  819. if (rt2x00_is_soc(rt2x00dev))
  820. rt2800pci_read_eeprom_soc(rt2x00dev);
  821. else if (rt2800pci_efuse_detect(rt2x00dev))
  822. rt2800pci_read_eeprom_efuse(rt2x00dev);
  823. else
  824. rt2800pci_read_eeprom_pci(rt2x00dev);
  825. return rt2800_validate_eeprom(rt2x00dev);
  826. }
  827. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  828. .register_read = rt2x00pci_register_read,
  829. .register_read_lock = rt2x00pci_register_read, /* same for PCI */
  830. .register_write = rt2x00pci_register_write,
  831. .register_write_lock = rt2x00pci_register_write, /* same for PCI */
  832. .register_multiread = rt2x00pci_register_multiread,
  833. .register_multiwrite = rt2x00pci_register_multiwrite,
  834. .regbusy_read = rt2x00pci_regbusy_read,
  835. };
  836. static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  837. {
  838. int retval;
  839. rt2x00dev->priv = (void *)&rt2800pci_rt2800_ops;
  840. /*
  841. * Allocate eeprom data.
  842. */
  843. retval = rt2800pci_validate_eeprom(rt2x00dev);
  844. if (retval)
  845. return retval;
  846. retval = rt2800_init_eeprom(rt2x00dev);
  847. if (retval)
  848. return retval;
  849. /*
  850. * Initialize hw specifications.
  851. */
  852. retval = rt2800_probe_hw_mode(rt2x00dev);
  853. if (retval)
  854. return retval;
  855. /*
  856. * This device has multiple filters for control frames
  857. * and has a separate filter for PS Poll frames.
  858. */
  859. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  860. __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
  861. /*
  862. * This device requires firmware.
  863. */
  864. if (!rt2x00_is_soc(rt2x00dev))
  865. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  866. __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags);
  867. __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
  868. if (!modparam_nohwcrypt)
  869. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  870. /*
  871. * Set the rssi offset.
  872. */
  873. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  874. return 0;
  875. }
  876. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  877. .irq_handler = rt2800pci_interrupt,
  878. .probe_hw = rt2800pci_probe_hw,
  879. .get_firmware_name = rt2800pci_get_firmware_name,
  880. .check_firmware = rt2800pci_check_firmware,
  881. .load_firmware = rt2800pci_load_firmware,
  882. .initialize = rt2x00pci_initialize,
  883. .uninitialize = rt2x00pci_uninitialize,
  884. .get_entry_state = rt2800pci_get_entry_state,
  885. .clear_entry = rt2800pci_clear_entry,
  886. .set_device_state = rt2800pci_set_device_state,
  887. .rfkill_poll = rt2800_rfkill_poll,
  888. .link_stats = rt2800_link_stats,
  889. .reset_tuner = rt2800_reset_tuner,
  890. .link_tuner = rt2800_link_tuner,
  891. .write_tx_desc = rt2800pci_write_tx_desc,
  892. .write_tx_data = rt2800pci_write_tx_data,
  893. .write_beacon = rt2800pci_write_beacon,
  894. .kick_tx_queue = rt2800pci_kick_tx_queue,
  895. .kill_tx_queue = rt2800pci_kill_tx_queue,
  896. .fill_rxdone = rt2800pci_fill_rxdone,
  897. .config_shared_key = rt2800_config_shared_key,
  898. .config_pairwise_key = rt2800_config_pairwise_key,
  899. .config_filter = rt2800_config_filter,
  900. .config_intf = rt2800_config_intf,
  901. .config_erp = rt2800_config_erp,
  902. .config_ant = rt2800_config_ant,
  903. .config = rt2800_config,
  904. };
  905. static const struct data_queue_desc rt2800pci_queue_rx = {
  906. .entry_num = RX_ENTRIES,
  907. .data_size = AGGREGATION_SIZE,
  908. .desc_size = RXD_DESC_SIZE,
  909. .priv_size = sizeof(struct queue_entry_priv_pci),
  910. };
  911. static const struct data_queue_desc rt2800pci_queue_tx = {
  912. .entry_num = TX_ENTRIES,
  913. .data_size = AGGREGATION_SIZE,
  914. .desc_size = TXD_DESC_SIZE,
  915. .priv_size = sizeof(struct queue_entry_priv_pci),
  916. };
  917. static const struct data_queue_desc rt2800pci_queue_bcn = {
  918. .entry_num = 8 * BEACON_ENTRIES,
  919. .data_size = 0, /* No DMA required for beacons */
  920. .desc_size = TXWI_DESC_SIZE,
  921. .priv_size = sizeof(struct queue_entry_priv_pci),
  922. };
  923. static const struct rt2x00_ops rt2800pci_ops = {
  924. .name = KBUILD_MODNAME,
  925. .max_sta_intf = 1,
  926. .max_ap_intf = 8,
  927. .eeprom_size = EEPROM_SIZE,
  928. .rf_size = RF_SIZE,
  929. .tx_queues = NUM_TX_QUEUES,
  930. .extra_tx_headroom = TXWI_DESC_SIZE,
  931. .rx = &rt2800pci_queue_rx,
  932. .tx = &rt2800pci_queue_tx,
  933. .bcn = &rt2800pci_queue_bcn,
  934. .lib = &rt2800pci_rt2x00_ops,
  935. .hw = &rt2800_mac80211_ops,
  936. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  937. .debugfs = &rt2800_rt2x00debug,
  938. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  939. };
  940. /*
  941. * RT2800pci module information.
  942. */
  943. #ifdef CONFIG_RT2800PCI_PCI
  944. static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
  945. { PCI_DEVICE(0x1814, 0x0601), PCI_DEVICE_DATA(&rt2800pci_ops) },
  946. { PCI_DEVICE(0x1814, 0x0681), PCI_DEVICE_DATA(&rt2800pci_ops) },
  947. { PCI_DEVICE(0x1814, 0x0701), PCI_DEVICE_DATA(&rt2800pci_ops) },
  948. { PCI_DEVICE(0x1814, 0x0781), PCI_DEVICE_DATA(&rt2800pci_ops) },
  949. { PCI_DEVICE(0x1432, 0x7708), PCI_DEVICE_DATA(&rt2800pci_ops) },
  950. { PCI_DEVICE(0x1432, 0x7727), PCI_DEVICE_DATA(&rt2800pci_ops) },
  951. { PCI_DEVICE(0x1432, 0x7728), PCI_DEVICE_DATA(&rt2800pci_ops) },
  952. { PCI_DEVICE(0x1432, 0x7738), PCI_DEVICE_DATA(&rt2800pci_ops) },
  953. { PCI_DEVICE(0x1432, 0x7748), PCI_DEVICE_DATA(&rt2800pci_ops) },
  954. { PCI_DEVICE(0x1432, 0x7758), PCI_DEVICE_DATA(&rt2800pci_ops) },
  955. { PCI_DEVICE(0x1432, 0x7768), PCI_DEVICE_DATA(&rt2800pci_ops) },
  956. { PCI_DEVICE(0x1a3b, 0x1059), PCI_DEVICE_DATA(&rt2800pci_ops) },
  957. #ifdef CONFIG_RT2800PCI_RT30XX
  958. { PCI_DEVICE(0x1814, 0x3090), PCI_DEVICE_DATA(&rt2800pci_ops) },
  959. { PCI_DEVICE(0x1814, 0x3091), PCI_DEVICE_DATA(&rt2800pci_ops) },
  960. { PCI_DEVICE(0x1814, 0x3092), PCI_DEVICE_DATA(&rt2800pci_ops) },
  961. { PCI_DEVICE(0x1462, 0x891a), PCI_DEVICE_DATA(&rt2800pci_ops) },
  962. #endif
  963. #ifdef CONFIG_RT2800PCI_RT35XX
  964. { PCI_DEVICE(0x1814, 0x3060), PCI_DEVICE_DATA(&rt2800pci_ops) },
  965. { PCI_DEVICE(0x1814, 0x3062), PCI_DEVICE_DATA(&rt2800pci_ops) },
  966. { PCI_DEVICE(0x1814, 0x3562), PCI_DEVICE_DATA(&rt2800pci_ops) },
  967. { PCI_DEVICE(0x1814, 0x3592), PCI_DEVICE_DATA(&rt2800pci_ops) },
  968. { PCI_DEVICE(0x1814, 0x3593), PCI_DEVICE_DATA(&rt2800pci_ops) },
  969. #endif
  970. { 0, }
  971. };
  972. #endif /* CONFIG_RT2800PCI_PCI */
  973. MODULE_AUTHOR(DRV_PROJECT);
  974. MODULE_VERSION(DRV_VERSION);
  975. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  976. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  977. #ifdef CONFIG_RT2800PCI_PCI
  978. MODULE_FIRMWARE(FIRMWARE_RT2860);
  979. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  980. #endif /* CONFIG_RT2800PCI_PCI */
  981. MODULE_LICENSE("GPL");
  982. #ifdef CONFIG_RT2800PCI_SOC
  983. static int rt2800soc_probe(struct platform_device *pdev)
  984. {
  985. return rt2x00soc_probe(pdev, &rt2800pci_ops);
  986. }
  987. static struct platform_driver rt2800soc_driver = {
  988. .driver = {
  989. .name = "rt2800_wmac",
  990. .owner = THIS_MODULE,
  991. .mod_name = KBUILD_MODNAME,
  992. },
  993. .probe = rt2800soc_probe,
  994. .remove = __devexit_p(rt2x00soc_remove),
  995. .suspend = rt2x00soc_suspend,
  996. .resume = rt2x00soc_resume,
  997. };
  998. #endif /* CONFIG_RT2800PCI_SOC */
  999. #ifdef CONFIG_RT2800PCI_PCI
  1000. static struct pci_driver rt2800pci_driver = {
  1001. .name = KBUILD_MODNAME,
  1002. .id_table = rt2800pci_device_table,
  1003. .probe = rt2x00pci_probe,
  1004. .remove = __devexit_p(rt2x00pci_remove),
  1005. .suspend = rt2x00pci_suspend,
  1006. .resume = rt2x00pci_resume,
  1007. };
  1008. #endif /* CONFIG_RT2800PCI_PCI */
  1009. static int __init rt2800pci_init(void)
  1010. {
  1011. int ret = 0;
  1012. #ifdef CONFIG_RT2800PCI_SOC
  1013. ret = platform_driver_register(&rt2800soc_driver);
  1014. if (ret)
  1015. return ret;
  1016. #endif
  1017. #ifdef CONFIG_RT2800PCI_PCI
  1018. ret = pci_register_driver(&rt2800pci_driver);
  1019. if (ret) {
  1020. #ifdef CONFIG_RT2800PCI_SOC
  1021. platform_driver_unregister(&rt2800soc_driver);
  1022. #endif
  1023. return ret;
  1024. }
  1025. #endif
  1026. return ret;
  1027. }
  1028. static void __exit rt2800pci_exit(void)
  1029. {
  1030. #ifdef CONFIG_RT2800PCI_PCI
  1031. pci_unregister_driver(&rt2800pci_driver);
  1032. #endif
  1033. #ifdef CONFIG_RT2800PCI_SOC
  1034. platform_driver_unregister(&rt2800soc_driver);
  1035. #endif
  1036. }
  1037. module_init(rt2800pci_init);
  1038. module_exit(rt2800pci_exit);