rt2800pci.c 36 KB

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