rt2800pci.c 38 KB

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