rt2800pci.c 37 KB

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