rt2800pci.c 14 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 rt3290.bin.
  141. */
  142. if (rt2x00_rt(rt2x00dev, RT3290))
  143. return FIRMWARE_RT3290;
  144. else
  145. return FIRMWARE_RT2860;
  146. }
  147. static int rt2800pci_write_firmware(struct rt2x00_dev *rt2x00dev,
  148. const u8 *data, const size_t len)
  149. {
  150. u32 reg;
  151. /*
  152. * enable Host program ram write selection
  153. */
  154. reg = 0;
  155. rt2x00_set_field32(&reg, PBF_SYS_CTRL_HOST_RAM_WRITE, 1);
  156. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, reg);
  157. /*
  158. * Write firmware to device.
  159. */
  160. rt2x00mmio_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  161. data, len);
  162. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000);
  163. rt2x00mmio_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00001);
  164. rt2x00mmio_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  165. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  166. return 0;
  167. }
  168. /*
  169. * Device state switch handlers.
  170. */
  171. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  172. {
  173. int retval;
  174. retval = rt2800mmio_enable_radio(rt2x00dev);
  175. if (retval)
  176. return retval;
  177. /* After resume MCU_BOOT_SIGNAL will trash these. */
  178. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  179. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  180. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_RADIO_OFF, 0xff, 0x02);
  181. rt2800pci_mcu_status(rt2x00dev, TOKEN_RADIO_OFF);
  182. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP, 0, 0);
  183. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
  184. return retval;
  185. }
  186. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  187. enum dev_state state)
  188. {
  189. if (state == STATE_AWAKE) {
  190. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKEUP,
  191. 0, 0x02);
  192. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKEUP);
  193. } else if (state == STATE_SLEEP) {
  194. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
  195. 0xffffffff);
  196. rt2x00mmio_register_write(rt2x00dev, H2M_MAILBOX_CID,
  197. 0xffffffff);
  198. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, TOKEN_SLEEP,
  199. 0xff, 0x01);
  200. }
  201. return 0;
  202. }
  203. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  204. enum dev_state state)
  205. {
  206. int retval = 0;
  207. switch (state) {
  208. case STATE_RADIO_ON:
  209. retval = rt2800pci_enable_radio(rt2x00dev);
  210. break;
  211. case STATE_RADIO_OFF:
  212. /*
  213. * After the radio has been disabled, the device should
  214. * be put to sleep for powersaving.
  215. */
  216. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  217. break;
  218. case STATE_RADIO_IRQ_ON:
  219. case STATE_RADIO_IRQ_OFF:
  220. rt2800mmio_toggle_irq(rt2x00dev, state);
  221. break;
  222. case STATE_DEEP_SLEEP:
  223. case STATE_SLEEP:
  224. case STATE_STANDBY:
  225. case STATE_AWAKE:
  226. retval = rt2800pci_set_state(rt2x00dev, state);
  227. break;
  228. default:
  229. retval = -ENOTSUPP;
  230. break;
  231. }
  232. if (unlikely(retval))
  233. rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
  234. state, retval);
  235. return retval;
  236. }
  237. /*
  238. * Device probe functions.
  239. */
  240. static int rt2800pci_read_eeprom(struct rt2x00_dev *rt2x00dev)
  241. {
  242. int retval;
  243. if (rt2800pci_efuse_detect(rt2x00dev))
  244. retval = rt2800pci_read_eeprom_efuse(rt2x00dev);
  245. else
  246. retval = rt2800pci_read_eeprom_pci(rt2x00dev);
  247. return retval;
  248. }
  249. static const struct ieee80211_ops rt2800pci_mac80211_ops = {
  250. .tx = rt2x00mac_tx,
  251. .start = rt2x00mac_start,
  252. .stop = rt2x00mac_stop,
  253. .add_interface = rt2x00mac_add_interface,
  254. .remove_interface = rt2x00mac_remove_interface,
  255. .config = rt2x00mac_config,
  256. .configure_filter = rt2x00mac_configure_filter,
  257. .set_key = rt2x00mac_set_key,
  258. .sw_scan_start = rt2x00mac_sw_scan_start,
  259. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  260. .get_stats = rt2x00mac_get_stats,
  261. .get_key_seq = rt2800_get_key_seq,
  262. .set_rts_threshold = rt2800_set_rts_threshold,
  263. .sta_add = rt2x00mac_sta_add,
  264. .sta_remove = rt2x00mac_sta_remove,
  265. .bss_info_changed = rt2x00mac_bss_info_changed,
  266. .conf_tx = rt2800_conf_tx,
  267. .get_tsf = rt2800_get_tsf,
  268. .rfkill_poll = rt2x00mac_rfkill_poll,
  269. .ampdu_action = rt2800_ampdu_action,
  270. .flush = rt2x00mac_flush,
  271. .get_survey = rt2800_get_survey,
  272. .get_ringparam = rt2x00mac_get_ringparam,
  273. .tx_frames_pending = rt2x00mac_tx_frames_pending,
  274. };
  275. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  276. .register_read = rt2x00mmio_register_read,
  277. .register_read_lock = rt2x00mmio_register_read, /* same for PCI */
  278. .register_write = rt2x00mmio_register_write,
  279. .register_write_lock = rt2x00mmio_register_write, /* same for PCI */
  280. .register_multiread = rt2x00mmio_register_multiread,
  281. .register_multiwrite = rt2x00mmio_register_multiwrite,
  282. .regbusy_read = rt2x00mmio_regbusy_read,
  283. .read_eeprom = rt2800pci_read_eeprom,
  284. .hwcrypt_disabled = rt2800pci_hwcrypt_disabled,
  285. .drv_write_firmware = rt2800pci_write_firmware,
  286. .drv_init_registers = rt2800mmio_init_registers,
  287. .drv_get_txwi = rt2800mmio_get_txwi,
  288. };
  289. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  290. .irq_handler = rt2800mmio_interrupt,
  291. .txstatus_tasklet = rt2800mmio_txstatus_tasklet,
  292. .pretbtt_tasklet = rt2800mmio_pretbtt_tasklet,
  293. .tbtt_tasklet = rt2800mmio_tbtt_tasklet,
  294. .rxdone_tasklet = rt2800mmio_rxdone_tasklet,
  295. .autowake_tasklet = rt2800mmio_autowake_tasklet,
  296. .probe_hw = rt2800_probe_hw,
  297. .get_firmware_name = rt2800pci_get_firmware_name,
  298. .check_firmware = rt2800_check_firmware,
  299. .load_firmware = rt2800_load_firmware,
  300. .initialize = rt2x00mmio_initialize,
  301. .uninitialize = rt2x00mmio_uninitialize,
  302. .get_entry_state = rt2800mmio_get_entry_state,
  303. .clear_entry = rt2800mmio_clear_entry,
  304. .set_device_state = rt2800pci_set_device_state,
  305. .rfkill_poll = rt2800_rfkill_poll,
  306. .link_stats = rt2800_link_stats,
  307. .reset_tuner = rt2800_reset_tuner,
  308. .link_tuner = rt2800_link_tuner,
  309. .gain_calibration = rt2800_gain_calibration,
  310. .vco_calibration = rt2800_vco_calibration,
  311. .start_queue = rt2800mmio_start_queue,
  312. .kick_queue = rt2800mmio_kick_queue,
  313. .stop_queue = rt2800mmio_stop_queue,
  314. .flush_queue = rt2x00mmio_flush_queue,
  315. .write_tx_desc = rt2800mmio_write_tx_desc,
  316. .write_tx_data = rt2800_write_tx_data,
  317. .write_beacon = rt2800_write_beacon,
  318. .clear_beacon = rt2800_clear_beacon,
  319. .fill_rxdone = rt2800mmio_fill_rxdone,
  320. .config_shared_key = rt2800_config_shared_key,
  321. .config_pairwise_key = rt2800_config_pairwise_key,
  322. .config_filter = rt2800_config_filter,
  323. .config_intf = rt2800_config_intf,
  324. .config_erp = rt2800_config_erp,
  325. .config_ant = rt2800_config_ant,
  326. .config = rt2800_config,
  327. .sta_add = rt2800_sta_add,
  328. .sta_remove = rt2800_sta_remove,
  329. };
  330. static const struct rt2x00_ops rt2800pci_ops = {
  331. .name = KBUILD_MODNAME,
  332. .drv_data_size = sizeof(struct rt2800_drv_data),
  333. .max_ap_intf = 8,
  334. .eeprom_size = EEPROM_SIZE,
  335. .rf_size = RF_SIZE,
  336. .tx_queues = NUM_TX_QUEUES,
  337. .queue_init = rt2800mmio_queue_init,
  338. .lib = &rt2800pci_rt2x00_ops,
  339. .drv = &rt2800pci_rt2800_ops,
  340. .hw = &rt2800pci_mac80211_ops,
  341. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  342. .debugfs = &rt2800_rt2x00debug,
  343. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  344. };
  345. /*
  346. * RT2800pci module information.
  347. */
  348. static const struct pci_device_id rt2800pci_device_table[] = {
  349. { PCI_DEVICE(0x1814, 0x0601) },
  350. { PCI_DEVICE(0x1814, 0x0681) },
  351. { PCI_DEVICE(0x1814, 0x0701) },
  352. { PCI_DEVICE(0x1814, 0x0781) },
  353. { PCI_DEVICE(0x1814, 0x3090) },
  354. { PCI_DEVICE(0x1814, 0x3091) },
  355. { PCI_DEVICE(0x1814, 0x3092) },
  356. { PCI_DEVICE(0x1432, 0x7708) },
  357. { PCI_DEVICE(0x1432, 0x7727) },
  358. { PCI_DEVICE(0x1432, 0x7728) },
  359. { PCI_DEVICE(0x1432, 0x7738) },
  360. { PCI_DEVICE(0x1432, 0x7748) },
  361. { PCI_DEVICE(0x1432, 0x7758) },
  362. { PCI_DEVICE(0x1432, 0x7768) },
  363. { PCI_DEVICE(0x1462, 0x891a) },
  364. { PCI_DEVICE(0x1a3b, 0x1059) },
  365. #ifdef CONFIG_RT2800PCI_RT3290
  366. { PCI_DEVICE(0x1814, 0x3290) },
  367. #endif
  368. #ifdef CONFIG_RT2800PCI_RT33XX
  369. { PCI_DEVICE(0x1814, 0x3390) },
  370. #endif
  371. #ifdef CONFIG_RT2800PCI_RT35XX
  372. { PCI_DEVICE(0x1432, 0x7711) },
  373. { PCI_DEVICE(0x1432, 0x7722) },
  374. { PCI_DEVICE(0x1814, 0x3060) },
  375. { PCI_DEVICE(0x1814, 0x3062) },
  376. { PCI_DEVICE(0x1814, 0x3562) },
  377. { PCI_DEVICE(0x1814, 0x3592) },
  378. { PCI_DEVICE(0x1814, 0x3593) },
  379. { PCI_DEVICE(0x1814, 0x359f) },
  380. #endif
  381. #ifdef CONFIG_RT2800PCI_RT53XX
  382. { PCI_DEVICE(0x1814, 0x5360) },
  383. { PCI_DEVICE(0x1814, 0x5362) },
  384. { PCI_DEVICE(0x1814, 0x5390) },
  385. { PCI_DEVICE(0x1814, 0x5392) },
  386. { PCI_DEVICE(0x1814, 0x539a) },
  387. { PCI_DEVICE(0x1814, 0x539b) },
  388. { PCI_DEVICE(0x1814, 0x539f) },
  389. #endif
  390. { 0, }
  391. };
  392. MODULE_AUTHOR(DRV_PROJECT);
  393. MODULE_VERSION(DRV_VERSION);
  394. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  395. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  396. MODULE_FIRMWARE(FIRMWARE_RT2860);
  397. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  398. MODULE_LICENSE("GPL");
  399. static int rt2800pci_probe(struct pci_dev *pci_dev,
  400. const struct pci_device_id *id)
  401. {
  402. return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
  403. }
  404. static struct pci_driver rt2800pci_driver = {
  405. .name = KBUILD_MODNAME,
  406. .id_table = rt2800pci_device_table,
  407. .probe = rt2800pci_probe,
  408. .remove = rt2x00pci_remove,
  409. .suspend = rt2x00pci_suspend,
  410. .resume = rt2x00pci_resume,
  411. };
  412. module_pci_driver(rt2800pci_driver);