rt2800pci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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, see <http://www.gnu.org/licenses/>.
  21. */
  22. /*
  23. Module: rt2800pci
  24. Abstract: rt2800pci device specific routines.
  25. Supported chipsets: RT2800E & RT2800ED.
  26. */
  27. #include <linux/delay.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/init.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/pci.h>
  33. #include <linux/eeprom_93cx6.h>
  34. #include "rt2x00.h"
  35. #include "rt2x00mmio.h"
  36. #include "rt2x00pci.h"
  37. #include "rt2800lib.h"
  38. #include "rt2800mmio.h"
  39. #include "rt2800.h"
  40. #include "rt2800pci.h"
  41. /*
  42. * Allow hardware encryption to be disabled.
  43. */
  44. static bool modparam_nohwcrypt = false;
  45. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  46. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  47. static bool rt2800pci_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
  48. {
  49. return modparam_nohwcrypt;
  50. }
  51. static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
  52. {
  53. unsigned int i;
  54. u32 reg;
  55. /*
  56. * SOC devices don't support MCU requests.
  57. */
  58. if (rt2x00_is_soc(rt2x00dev))
  59. return;
  60. for (i = 0; i < 200; i++) {
  61. rt2x00mmio_register_read(rt2x00dev, H2M_MAILBOX_CID, &reg);
  62. if ((rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD0) == token) ||
  63. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD1) == token) ||
  64. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD2) == token) ||
  65. (rt2x00_get_field32(reg, H2M_MAILBOX_CID_CMD3) == token))
  66. break;
  67. udelay(REGISTER_BUSY_DELAY);
  68. }
  69. if (i == 200)
  70. rt2x00_err(rt2x00dev, "MCU request failed, no response from hardware\n");
  71. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  72. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  73. }
  74. static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  75. {
  76. struct rt2x00_dev *rt2x00dev = eeprom->data;
  77. u32 reg;
  78. rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, &reg);
  79. eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
  80. eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
  81. eeprom->reg_data_clock =
  82. !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
  83. eeprom->reg_chip_select =
  84. !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
  85. }
  86. static void rt2800pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  87. {
  88. struct rt2x00_dev *rt2x00dev = eeprom->data;
  89. u32 reg = 0;
  90. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
  91. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
  92. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
  93. !!eeprom->reg_data_clock);
  94. rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
  95. !!eeprom->reg_chip_select);
  96. rt2x00mmio_register_write(rt2x00dev, E2PROM_CSR, reg);
  97. }
  98. static int rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
  99. {
  100. struct eeprom_93cx6 eeprom;
  101. u32 reg;
  102. rt2x00mmio_register_read(rt2x00dev, E2PROM_CSR, &reg);
  103. eeprom.data = rt2x00dev;
  104. eeprom.register_read = rt2800pci_eepromregister_read;
  105. eeprom.register_write = rt2800pci_eepromregister_write;
  106. switch (rt2x00_get_field32(reg, E2PROM_CSR_TYPE))
  107. {
  108. case 0:
  109. eeprom.width = PCI_EEPROM_WIDTH_93C46;
  110. break;
  111. case 1:
  112. eeprom.width = PCI_EEPROM_WIDTH_93C66;
  113. break;
  114. default:
  115. eeprom.width = PCI_EEPROM_WIDTH_93C86;
  116. break;
  117. }
  118. eeprom.reg_data_in = 0;
  119. eeprom.reg_data_out = 0;
  120. eeprom.reg_data_clock = 0;
  121. eeprom.reg_chip_select = 0;
  122. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  123. EEPROM_SIZE / sizeof(u16));
  124. return 0;
  125. }
  126. static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
  127. {
  128. return rt2800_efuse_detect(rt2x00dev);
  129. }
  130. static inline int rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  131. {
  132. return rt2800_read_eeprom_efuse(rt2x00dev);
  133. }
  134. /*
  135. * Firmware functions
  136. */
  137. static char *rt2800pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  138. {
  139. /*
  140. * Chip rt3290 use specific 4KB firmware named /*(DEBLOBBED)*/
  141. if (rt2x00_rt(rt2x00dev, RT3290))
  142. return FIRMWARE_RT3290;
  143. else
  144. return FIRMWARE_RT2860;
  145. }
  146. static int rt2800pci_write_firmware(struct rt2x00_dev *rt2x00dev,
  147. const u8 *data, const size_t len)
  148. {
  149. u32 reg;
  150. /*
  151. * enable Host program ram write selection
  152. */
  153. reg = 0;
  154. rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
  155. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
  156. /*
  157. * Write firmware to device.
  158. */
  159. rt2x00mmio_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  160. data, len);
  161. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
  162. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
  163. rt2x00mmio_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  164. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  165. return 0;
  166. }
  167. /*
  168. * Device state switch handlers.
  169. */
  170. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  171. {
  172. int retval;
  173. retval = rt2800mmio_enable_radio(rt2x00dev);
  174. if (retval)
  175. return retval;
  176. /* After resume MCU_BOOT_SIGNAL will trash these. */
  177. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  178. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  179. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_RADIO_OFF, 0xff, 0x02);
  180. rt2800pci_mcu_status(rt2x00dev, TOKEN_RADIO_OFF);
  181. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP, 0, 0);
  182. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
  183. return retval;
  184. }
  185. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  186. enum dev_state state)
  187. {
  188. if (state == STATE_AWAKE) {
  189. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP,
  190. 0, 0x02);
  191. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
  192. } else if (state == STATE_SLEEP) {
  193. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
  194. 0xffffffff);
  195. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID,
  196. 0xffffffff);
  197. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_SLEEP,
  198. 0xff, 0x01);
  199. }
  200. return 0;
  201. }
  202. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  203. enum dev_state state)
  204. {
  205. int retval = 0;
  206. switch (state) {
  207. case STATE_RADIO_ON:
  208. retval = rt2800pci_enable_radio(rt2x00dev);
  209. break;
  210. case STATE_RADIO_OFF:
  211. /*
  212. * After the radio has been disabled, the device should
  213. * be put to sleep for powersaving.
  214. */
  215. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  216. break;
  217. case STATE_RADIO_IRQ_ON:
  218. case STATE_RADIO_IRQ_OFF:
  219. rt2800mmio_toggle_irq(rt2x00dev, state);
  220. break;
  221. case STATE_DEEP_SLEEP:
  222. case STATE_SLEEP:
  223. case STATE_STANDBY:
  224. case STATE_AWAKE:
  225. retval = rt2800pci_set_state(rt2x00dev, state);
  226. break;
  227. default:
  228. retval = -ENOTSUPP;
  229. break;
  230. }
  231. if (unlikely(retval))
  232. rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
  233. state, retval);
  234. return retval;
  235. }
  236. /*
  237. * Device probe functions.
  238. */
  239. static int rt2800pci_read_eeprom(struct rt2x00_dev *rt2x00dev)
  240. {
  241. int retval;
  242. if (rt2800pci_efuse_detect(rt2x00dev))
  243. retval = rt2800pci_read_eeprom_efuse(rt2x00dev);
  244. else
  245. retval = rt2800pci_read_eeprom_pci(rt2x00dev);
  246. return retval;
  247. }
  248. static const struct ieee80211_ops rt2800pci_mac80211_ops = {
  249. .tx = rt2x00mac_tx,
  250. .start = rt2x00mac_start,
  251. .stop = rt2x00mac_stop,
  252. .add_interface = rt2x00mac_add_interface,
  253. .remove_interface = rt2x00mac_remove_interface,
  254. .config = rt2x00mac_config,
  255. .configure_filter = rt2x00mac_configure_filter,
  256. .set_key = rt2x00mac_set_key,
  257. .sw_scan_start = rt2x00mac_sw_scan_start,
  258. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  259. .get_stats = rt2x00mac_get_stats,
  260. .get_key_seq = rt2800_get_key_seq,
  261. .set_rts_threshold = rt2800_set_rts_threshold,
  262. .sta_add = rt2x00mac_sta_add,
  263. .sta_remove = rt2x00mac_sta_remove,
  264. .bss_info_changed = rt2x00mac_bss_info_changed,
  265. .conf_tx = rt2800_conf_tx,
  266. .get_tsf = rt2800_get_tsf,
  267. .rfkill_poll = rt2x00mac_rfkill_poll,
  268. .ampdu_action = rt2800_ampdu_action,
  269. .flush = rt2x00mac_flush,
  270. .get_survey = rt2800_get_survey,
  271. .get_ringparam = rt2x00mac_get_ringparam,
  272. .tx_frames_pending = rt2x00mac_tx_frames_pending,
  273. };
  274. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  275. .register_read = rt2x00mmio_register_read,
  276. .register_read_lock = rt2x00mmio_register_read, /* same for PCI */
  277. .register_write = rt2x00mmio_register_write,
  278. .register_write_lock = rt2x00mmio_register_write, /* same for PCI */
  279. .register_multiread = rt2x00mmio_register_multiread,
  280. .register_multiwrite = rt2x00mmio_register_multiwrite,
  281. .regbusy_read = rt2x00mmio_regbusy_read,
  282. .read_eeprom = rt2800pci_read_eeprom,
  283. .hwcrypt_disabled = rt2800pci_hwcrypt_disabled,
  284. .drv_write_firmware = rt2800pci_write_firmware,
  285. .drv_init_registers = rt2800mmio_init_registers,
  286. .drv_get_txwi = rt2800mmio_get_txwi,
  287. };
  288. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  289. .irq_handler = rt2800mmio_interrupt,
  290. .txstatus_tasklet = rt2800mmio_txstatus_tasklet,
  291. .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet,
  292. .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
  293. .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
  294. .autowake_tasklet = rt2800mmio_autowake_tasklet,
  295. .probe_hw = rt2800_probe_hw,
  296. .get_firmware_name = rt2800pci_get_firmware_name,
  297. .check_firmware = rt2800_check_firmware,
  298. .load_firmware = rt2800_load_firmware,
  299. .initialize = rt2x00mmio_initialize,
  300. .uninitialize = rt2x00mmio_uninitialize,
  301. .get_entry_state = rt2800mmio_get_entry_state,
  302. .clear_entry = rt2800mmio_clear_entry,
  303. .set_device_state = rt2800pci_set_device_state,
  304. .rfkill_poll = rt2800_rfkill_poll,
  305. .link_stats = rt2800_link_stats,
  306. .reset_tuner = rt2800_reset_tuner,
  307. .link_tuner = rt2800_link_tuner,
  308. .gain_calibration = rt2800_gain_calibration,
  309. .vco_calibration = rt2800_vco_calibration,
  310. .start_queue = rt2800mmio_start_queue,
  311. .kick_queue = rt2800mmio_kick_queue,
  312. .stop_queue = rt2800mmio_stop_queue,
  313. .flush_queue = rt2x00mmio_flush_queue,
  314. .write_tx_desc = rt2800mmio_write_tx_desc,
  315. .write_tx_data = rt2800_write_tx_data,
  316. .write_beacon = rt2800_write_beacon,
  317. .clear_beacon = rt2800_clear_beacon,
  318. .fill_rxdone = rt2800mmio_fill_rxdone,
  319. .config_shared_key = rt2800_config_shared_key,
  320. .config_pairwise_key = rt2800_config_pairwise_key,
  321. .config_filter = rt2800_config_filter,
  322. .config_intf = rt2800_config_intf,
  323. .config_erp = rt2800_config_erp,
  324. .config_ant = rt2800_config_ant,
  325. .config = rt2800_config,
  326. .sta_add = rt2800_sta_add,
  327. .sta_remove = rt2800_sta_remove,
  328. };
  329. static const struct rt2x00_ops rt2800pci_ops = {
  330. .name = KBUILD_MODNAME,
  331. .drv_data_size = sizeof(struct rt2800_drv_data),
  332. .max_ap_intf = 8,
  333. .eeprom_size = EEPROM_SIZE,
  334. .rf_size = RF_SIZE,
  335. .tx_queues = NUM_TX_QUEUES,
  336. .queue_init = rt2800mmio_queue_init,
  337. .lib = &rt2800pci_rt2x00_ops,
  338. .drv = &rt2800pci_rt2800_ops,
  339. .hw = &rt2800pci_mac80211_ops,
  340. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  341. .debugfs = &rt2800_rt2x00debug,
  342. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  343. };
  344. /*
  345. * RT2800pci module information.
  346. */
  347. static const struct pci_device_id rt2800pci_device_table[] = {
  348. { PCI_DEVICE(0x1814, 0x0601) },
  349. { PCI_DEVICE(0x1814, 0x0681) },
  350. { PCI_DEVICE(0x1814, 0x0701) },
  351. { PCI_DEVICE(0x1814, 0x0781) },
  352. { PCI_DEVICE(0x1814, 0x3090) },
  353. { PCI_DEVICE(0x1814, 0x3091) },
  354. { PCI_DEVICE(0x1814, 0x3092) },
  355. { PCI_DEVICE(0x1432, 0x7708) },
  356. { PCI_DEVICE(0x1432, 0x7727) },
  357. { PCI_DEVICE(0x1432, 0x7728) },
  358. { PCI_DEVICE(0x1432, 0x7738) },
  359. { PCI_DEVICE(0x1432, 0x7748) },
  360. { PCI_DEVICE(0x1432, 0x7758) },
  361. { PCI_DEVICE(0x1432, 0x7768) },
  362. { PCI_DEVICE(0x1462, 0x891a) },
  363. { PCI_DEVICE(0x1a3b, 0x1059) },
  364. #ifdef CONFIG_RT2800PCI_RT3290
  365. { PCI_DEVICE(0x1814, 0x3290) },
  366. #endif
  367. #ifdef CONFIG_RT2800PCI_RT33XX
  368. { PCI_DEVICE(0x1814, 0x3390) },
  369. #endif
  370. #ifdef CONFIG_RT2800PCI_RT35XX
  371. { PCI_DEVICE(0x1432, 0x7711) },
  372. { PCI_DEVICE(0x1432, 0x7722) },
  373. { PCI_DEVICE(0x1814, 0x3060) },
  374. { PCI_DEVICE(0x1814, 0x3062) },
  375. { PCI_DEVICE(0x1814, 0x3562) },
  376. { PCI_DEVICE(0x1814, 0x3592) },
  377. { PCI_DEVICE(0x1814, 0x3593) },
  378. { PCI_DEVICE(0x1814, 0x359f) },
  379. #endif
  380. #ifdef CONFIG_RT2800PCI_RT53XX
  381. { PCI_DEVICE(0x1814, 0x5360) },
  382. { PCI_DEVICE(0x1814, 0x5362) },
  383. { PCI_DEVICE(0x1814, 0x5390) },
  384. { PCI_DEVICE(0x1814, 0x5392) },
  385. { PCI_DEVICE(0x1814, 0x539a) },
  386. { PCI_DEVICE(0x1814, 0x539b) },
  387. { PCI_DEVICE(0x1814, 0x539f) },
  388. #endif
  389. { 0, }
  390. };
  391. MODULE_AUTHOR(DRV_PROJECT);
  392. MODULE_VERSION(DRV_VERSION);
  393. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  394. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  395. /*(DEBLOBBED)*/
  396. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  397. MODULE_LICENSE("GPL");
  398. static int rt2800pci_probe(struct pci_dev *pci_dev,
  399. const struct pci_device_id *id)
  400. {
  401. return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
  402. }
  403. static struct pci_driver rt2800pci_driver = {
  404. .name = KBUILD_MODNAME,
  405. .id_table = rt2800pci_device_table,
  406. .probe = rt2800pci_probe,
  407. .remove = rt2x00pci_remove,
  408. .suspend = rt2x00pci_suspend,
  409. .resume = rt2x00pci_resume,
  410. };
  411. module_pci_driver(rt2800pci_driver);