rt2800pci.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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 int modparam_nohwcrypt = 0;
  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. u32 reg;
  308. /*
  309. * Initialize registers.
  310. */
  311. entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
  312. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR0, entry_priv->desc_dma);
  313. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT0,
  314. rt2x00dev->tx[0].limit);
  315. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX0, 0);
  316. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX0, 0);
  317. entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
  318. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR1, entry_priv->desc_dma);
  319. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT1,
  320. rt2x00dev->tx[1].limit);
  321. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX1, 0);
  322. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX1, 0);
  323. entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
  324. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR2, entry_priv->desc_dma);
  325. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT2,
  326. rt2x00dev->tx[2].limit);
  327. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX2, 0);
  328. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX2, 0);
  329. entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
  330. rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR3, entry_priv->desc_dma);
  331. rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT3,
  332. rt2x00dev->tx[3].limit);
  333. rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX3, 0);
  334. rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX3, 0);
  335. entry_priv = rt2x00dev->rx->entries[0].priv_data;
  336. rt2x00pci_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
  337. rt2x00pci_register_write(rt2x00dev, RX_MAX_CNT,
  338. rt2x00dev->rx[0].limit);
  339. rt2x00pci_register_write(rt2x00dev, RX_CRX_IDX,
  340. rt2x00dev->rx[0].limit - 1);
  341. rt2x00pci_register_write(rt2x00dev, RX_DRX_IDX, 0);
  342. /*
  343. * Enable global DMA configuration
  344. */
  345. rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  346. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  347. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  348. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  349. rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  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. int mask = (state == STATE_RADIO_IRQ_ON);
  360. u32 reg;
  361. unsigned long flags;
  362. /*
  363. * When interrupts are being enabled, the interrupt registers
  364. * should clear the register to assure a clean state.
  365. */
  366. if (state == STATE_RADIO_IRQ_ON) {
  367. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  368. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  369. }
  370. spin_lock_irqsave(&rt2x00dev->irqmask_lock, flags);
  371. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  372. rt2x00_set_field32(&reg, INT_MASK_CSR_RXDELAYINT, 0);
  373. rt2x00_set_field32(&reg, INT_MASK_CSR_TXDELAYINT, 0);
  374. rt2x00_set_field32(&reg, INT_MASK_CSR_RX_DONE, mask);
  375. rt2x00_set_field32(&reg, INT_MASK_CSR_AC0_DMA_DONE, 0);
  376. rt2x00_set_field32(&reg, INT_MASK_CSR_AC1_DMA_DONE, 0);
  377. rt2x00_set_field32(&reg, INT_MASK_CSR_AC2_DMA_DONE, 0);
  378. rt2x00_set_field32(&reg, INT_MASK_CSR_AC3_DMA_DONE, 0);
  379. rt2x00_set_field32(&reg, INT_MASK_CSR_HCCA_DMA_DONE, 0);
  380. rt2x00_set_field32(&reg, INT_MASK_CSR_MGMT_DMA_DONE, 0);
  381. rt2x00_set_field32(&reg, INT_MASK_CSR_MCU_COMMAND, 0);
  382. rt2x00_set_field32(&reg, INT_MASK_CSR_RXTX_COHERENT, 0);
  383. rt2x00_set_field32(&reg, INT_MASK_CSR_TBTT, mask);
  384. rt2x00_set_field32(&reg, INT_MASK_CSR_PRE_TBTT, mask);
  385. rt2x00_set_field32(&reg, INT_MASK_CSR_TX_FIFO_STATUS, mask);
  386. rt2x00_set_field32(&reg, INT_MASK_CSR_AUTO_WAKEUP, mask);
  387. rt2x00_set_field32(&reg, INT_MASK_CSR_GPTIMER, 0);
  388. rt2x00_set_field32(&reg, INT_MASK_CSR_RX_COHERENT, 0);
  389. rt2x00_set_field32(&reg, INT_MASK_CSR_TX_COHERENT, 0);
  390. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  391. spin_unlock_irqrestore(&rt2x00dev->irqmask_lock, flags);
  392. if (state == STATE_RADIO_IRQ_OFF) {
  393. /*
  394. * Wait for possibly running tasklets to finish.
  395. */
  396. tasklet_kill(&rt2x00dev->txstatus_tasklet);
  397. tasklet_kill(&rt2x00dev->rxdone_tasklet);
  398. tasklet_kill(&rt2x00dev->autowake_tasklet);
  399. tasklet_kill(&rt2x00dev->tbtt_tasklet);
  400. tasklet_kill(&rt2x00dev->pretbtt_tasklet);
  401. }
  402. }
  403. static int rt2800pci_init_registers(struct rt2x00_dev *rt2x00dev)
  404. {
  405. u32 reg;
  406. /*
  407. * Reset DMA indexes
  408. */
  409. rt2x00pci_register_read(rt2x00dev, WPDMA_RST_IDX, &reg);
  410. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX0, 1);
  411. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX1, 1);
  412. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX2, 1);
  413. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX3, 1);
  414. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX4, 1);
  415. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DTX_IDX5, 1);
  416. rt2x00_set_field32(&reg, WPDMA_RST_IDX_DRX_IDX0, 1);
  417. rt2x00pci_register_write(rt2x00dev, WPDMA_RST_IDX, reg);
  418. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e1f);
  419. rt2x00pci_register_write(rt2x00dev, PBF_SYS_CTRL, 0x00000e00);
  420. if (rt2x00_is_pcie(rt2x00dev) &&
  421. (rt2x00_rt(rt2x00dev, RT3572) ||
  422. rt2x00_rt(rt2x00dev, RT5390))) {
  423. rt2x00pci_register_read(rt2x00dev, AUX_CTRL, &reg);
  424. rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
  425. rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
  426. rt2x00pci_register_write(rt2x00dev, AUX_CTRL, reg);
  427. }
  428. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  429. rt2x00pci_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  430. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  431. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  432. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  433. rt2x00pci_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  434. return 0;
  435. }
  436. static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  437. {
  438. if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
  439. rt2800pci_init_queues(rt2x00dev)))
  440. return -EIO;
  441. return rt2800_enable_radio(rt2x00dev);
  442. }
  443. static void rt2800pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  444. {
  445. if (rt2x00_is_soc(rt2x00dev)) {
  446. rt2800_disable_radio(rt2x00dev);
  447. rt2x00pci_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  448. rt2x00pci_register_write(rt2x00dev, TX_PIN_CFG, 0);
  449. }
  450. }
  451. static int rt2800pci_set_state(struct rt2x00_dev *rt2x00dev,
  452. enum dev_state state)
  453. {
  454. if (state == STATE_AWAKE) {
  455. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, TOKEN_WAKUP, 0, 0x02);
  456. rt2800pci_mcu_status(rt2x00dev, TOKEN_WAKUP);
  457. } else if (state == STATE_SLEEP) {
  458. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_STATUS,
  459. 0xffffffff);
  460. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID,
  461. 0xffffffff);
  462. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0x01, 0xff, 0x01);
  463. }
  464. return 0;
  465. }
  466. static int rt2800pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  467. enum dev_state state)
  468. {
  469. int retval = 0;
  470. switch (state) {
  471. case STATE_RADIO_ON:
  472. /*
  473. * Before the radio can be enabled, the device first has
  474. * to be woken up. After that it needs a bit of time
  475. * to be fully awake and then the radio can be enabled.
  476. */
  477. rt2800pci_set_state(rt2x00dev, STATE_AWAKE);
  478. msleep(1);
  479. retval = rt2800pci_enable_radio(rt2x00dev);
  480. break;
  481. case STATE_RADIO_OFF:
  482. /*
  483. * After the radio has been disabled, the device should
  484. * be put to sleep for powersaving.
  485. */
  486. rt2800pci_disable_radio(rt2x00dev);
  487. rt2800pci_set_state(rt2x00dev, STATE_SLEEP);
  488. break;
  489. case STATE_RADIO_IRQ_ON:
  490. case STATE_RADIO_IRQ_OFF:
  491. rt2800pci_toggle_irq(rt2x00dev, state);
  492. break;
  493. case STATE_DEEP_SLEEP:
  494. case STATE_SLEEP:
  495. case STATE_STANDBY:
  496. case STATE_AWAKE:
  497. retval = rt2800pci_set_state(rt2x00dev, state);
  498. break;
  499. default:
  500. retval = -ENOTSUPP;
  501. break;
  502. }
  503. if (unlikely(retval))
  504. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  505. state, retval);
  506. return retval;
  507. }
  508. /*
  509. * TX descriptor initialization
  510. */
  511. static __le32 *rt2800pci_get_txwi(struct queue_entry *entry)
  512. {
  513. return (__le32 *) entry->skb->data;
  514. }
  515. static void rt2800pci_write_tx_desc(struct queue_entry *entry,
  516. struct txentry_desc *txdesc)
  517. {
  518. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  519. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  520. __le32 *txd = entry_priv->desc;
  521. u32 word;
  522. /*
  523. * The buffers pointed by SD_PTR0/SD_LEN0 and SD_PTR1/SD_LEN1
  524. * must contains a TXWI structure + 802.11 header + padding + 802.11
  525. * data. We choose to have SD_PTR0/SD_LEN0 only contains TXWI and
  526. * SD_PTR1/SD_LEN1 contains 802.11 header + padding + 802.11
  527. * data. It means that LAST_SEC0 is always 0.
  528. */
  529. /*
  530. * Initialize TX descriptor
  531. */
  532. rt2x00_desc_read(txd, 0, &word);
  533. rt2x00_set_field32(&word, TXD_W0_SD_PTR0, skbdesc->skb_dma);
  534. rt2x00_desc_write(txd, 0, word);
  535. rt2x00_desc_read(txd, 1, &word);
  536. rt2x00_set_field32(&word, TXD_W1_SD_LEN1, entry->skb->len);
  537. rt2x00_set_field32(&word, TXD_W1_LAST_SEC1,
  538. !test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  539. rt2x00_set_field32(&word, TXD_W1_BURST,
  540. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  541. rt2x00_set_field32(&word, TXD_W1_SD_LEN0, TXWI_DESC_SIZE);
  542. rt2x00_set_field32(&word, TXD_W1_LAST_SEC0, 0);
  543. rt2x00_set_field32(&word, TXD_W1_DMA_DONE, 0);
  544. rt2x00_desc_write(txd, 1, word);
  545. rt2x00_desc_read(txd, 2, &word);
  546. rt2x00_set_field32(&word, TXD_W2_SD_PTR1,
  547. skbdesc->skb_dma + TXWI_DESC_SIZE);
  548. rt2x00_desc_write(txd, 2, word);
  549. rt2x00_desc_read(txd, 3, &word);
  550. rt2x00_set_field32(&word, TXD_W3_WIV,
  551. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  552. rt2x00_set_field32(&word, TXD_W3_QSEL, 2);
  553. rt2x00_desc_write(txd, 3, word);
  554. /*
  555. * Register descriptor details in skb frame descriptor.
  556. */
  557. skbdesc->desc = txd;
  558. skbdesc->desc_len = TXD_DESC_SIZE;
  559. }
  560. /*
  561. * RX control handlers
  562. */
  563. static void rt2800pci_fill_rxdone(struct queue_entry *entry,
  564. struct rxdone_entry_desc *rxdesc)
  565. {
  566. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  567. __le32 *rxd = entry_priv->desc;
  568. u32 word;
  569. rt2x00_desc_read(rxd, 3, &word);
  570. if (rt2x00_get_field32(word, RXD_W3_CRC_ERROR))
  571. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  572. /*
  573. * Unfortunately we don't know the cipher type used during
  574. * decryption. This prevents us from correct providing
  575. * correct statistics through debugfs.
  576. */
  577. rxdesc->cipher_status = rt2x00_get_field32(word, RXD_W3_CIPHER_ERROR);
  578. if (rt2x00_get_field32(word, RXD_W3_DECRYPTED)) {
  579. /*
  580. * Hardware has stripped IV/EIV data from 802.11 frame during
  581. * decryption. Unfortunately the descriptor doesn't contain
  582. * any fields with the EIV/IV data either, so they can't
  583. * be restored by rt2x00lib.
  584. */
  585. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  586. /*
  587. * The hardware has already checked the Michael Mic and has
  588. * stripped it from the frame. Signal this to mac80211.
  589. */
  590. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  591. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  592. rxdesc->flags |= RX_FLAG_DECRYPTED;
  593. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  594. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  595. }
  596. if (rt2x00_get_field32(word, RXD_W3_MY_BSS))
  597. rxdesc->dev_flags |= RXDONE_MY_BSS;
  598. if (rt2x00_get_field32(word, RXD_W3_L2PAD))
  599. rxdesc->dev_flags |= RXDONE_L2PAD;
  600. /*
  601. * Process the RXWI structure that is at the start of the buffer.
  602. */
  603. rt2800_process_rxwi(entry, rxdesc);
  604. }
  605. /*
  606. * Interrupt functions.
  607. */
  608. static void rt2800pci_wakeup(struct rt2x00_dev *rt2x00dev)
  609. {
  610. struct ieee80211_conf conf = { .flags = 0 };
  611. struct rt2x00lib_conf libconf = { .conf = &conf };
  612. rt2800_config(rt2x00dev, &libconf, IEEE80211_CONF_CHANGE_PS);
  613. }
  614. static bool rt2800pci_txdone(struct rt2x00_dev *rt2x00dev)
  615. {
  616. struct data_queue *queue;
  617. struct queue_entry *entry;
  618. u32 status;
  619. u8 qid;
  620. int max_tx_done = 16;
  621. while (kfifo_get(&rt2x00dev->txstatus_fifo, &status)) {
  622. qid = rt2x00_get_field32(status, TX_STA_FIFO_PID_QUEUE);
  623. if (unlikely(qid >= QID_RX)) {
  624. /*
  625. * Unknown queue, this shouldn't happen. Just drop
  626. * this tx status.
  627. */
  628. WARNING(rt2x00dev, "Got TX status report with "
  629. "unexpected pid %u, dropping\n", qid);
  630. break;
  631. }
  632. queue = rt2x00queue_get_tx_queue(rt2x00dev, qid);
  633. if (unlikely(queue == NULL)) {
  634. /*
  635. * The queue is NULL, this shouldn't happen. Stop
  636. * processing here and drop the tx status
  637. */
  638. WARNING(rt2x00dev, "Got TX status for an unavailable "
  639. "queue %u, dropping\n", qid);
  640. break;
  641. }
  642. if (unlikely(rt2x00queue_empty(queue))) {
  643. /*
  644. * The queue is empty. Stop processing here
  645. * and drop the tx status.
  646. */
  647. WARNING(rt2x00dev, "Got TX status for an empty "
  648. "queue %u, dropping\n", qid);
  649. break;
  650. }
  651. entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  652. rt2800_txdone_entry(entry, status);
  653. if (--max_tx_done == 0)
  654. break;
  655. }
  656. return !max_tx_done;
  657. }
  658. static inline void rt2800pci_enable_interrupt(struct rt2x00_dev *rt2x00dev,
  659. struct rt2x00_field32 irq_field)
  660. {
  661. u32 reg;
  662. /*
  663. * Enable a single interrupt. The interrupt mask register
  664. * access needs locking.
  665. */
  666. spin_lock_irq(&rt2x00dev->irqmask_lock);
  667. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  668. rt2x00_set_field32(&reg, irq_field, 1);
  669. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  670. spin_unlock_irq(&rt2x00dev->irqmask_lock);
  671. }
  672. static void rt2800pci_txstatus_tasklet(unsigned long data)
  673. {
  674. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  675. if (rt2800pci_txdone(rt2x00dev))
  676. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  677. /*
  678. * No need to enable the tx status interrupt here as we always
  679. * leave it enabled to minimize the possibility of a tx status
  680. * register overflow. See comment in interrupt handler.
  681. */
  682. }
  683. static void rt2800pci_pretbtt_tasklet(unsigned long data)
  684. {
  685. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  686. rt2x00lib_pretbtt(rt2x00dev);
  687. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  688. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_PRE_TBTT);
  689. }
  690. static void rt2800pci_tbtt_tasklet(unsigned long data)
  691. {
  692. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  693. rt2x00lib_beacondone(rt2x00dev);
  694. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  695. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_TBTT);
  696. }
  697. static void rt2800pci_rxdone_tasklet(unsigned long data)
  698. {
  699. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  700. if (rt2x00pci_rxdone(rt2x00dev))
  701. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  702. else if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  703. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_RX_DONE);
  704. }
  705. static void rt2800pci_autowake_tasklet(unsigned long data)
  706. {
  707. struct rt2x00_dev *rt2x00dev = (struct rt2x00_dev *)data;
  708. rt2800pci_wakeup(rt2x00dev);
  709. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  710. rt2800pci_enable_interrupt(rt2x00dev, INT_MASK_CSR_AUTO_WAKEUP);
  711. }
  712. static void rt2800pci_txstatus_interrupt(struct rt2x00_dev *rt2x00dev)
  713. {
  714. u32 status;
  715. int i;
  716. /*
  717. * The TX_FIFO_STATUS interrupt needs special care. We should
  718. * read TX_STA_FIFO but we should do it immediately as otherwise
  719. * the register can overflow and we would lose status reports.
  720. *
  721. * Hence, read the TX_STA_FIFO register and copy all tx status
  722. * reports into a kernel FIFO which is handled in the txstatus
  723. * tasklet. We use a tasklet to process the tx status reports
  724. * because we can schedule the tasklet multiple times (when the
  725. * interrupt fires again during tx status processing).
  726. *
  727. * Furthermore we don't disable the TX_FIFO_STATUS
  728. * interrupt here but leave it enabled so that the TX_STA_FIFO
  729. * can also be read while the tx status tasklet gets executed.
  730. *
  731. * Since we have only one producer and one consumer we don't
  732. * need to lock the kfifo.
  733. */
  734. for (i = 0; i < rt2x00dev->ops->tx->entry_num; i++) {
  735. rt2x00pci_register_read(rt2x00dev, TX_STA_FIFO, &status);
  736. if (!rt2x00_get_field32(status, TX_STA_FIFO_VALID))
  737. break;
  738. if (!kfifo_put(&rt2x00dev->txstatus_fifo, &status)) {
  739. WARNING(rt2x00dev, "TX status FIFO overrun,"
  740. "drop tx status report.\n");
  741. break;
  742. }
  743. }
  744. /* Schedule the tasklet for processing the tx status. */
  745. tasklet_schedule(&rt2x00dev->txstatus_tasklet);
  746. }
  747. static irqreturn_t rt2800pci_interrupt(int irq, void *dev_instance)
  748. {
  749. struct rt2x00_dev *rt2x00dev = dev_instance;
  750. u32 reg, mask;
  751. /* Read status and ACK all interrupts */
  752. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  753. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  754. if (!reg)
  755. return IRQ_NONE;
  756. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  757. return IRQ_HANDLED;
  758. /*
  759. * Since INT_MASK_CSR and INT_SOURCE_CSR use the same bits
  760. * for interrupts and interrupt masks we can just use the value of
  761. * INT_SOURCE_CSR to create the interrupt mask.
  762. */
  763. mask = ~reg;
  764. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TX_FIFO_STATUS)) {
  765. rt2800pci_txstatus_interrupt(rt2x00dev);
  766. /*
  767. * Never disable the TX_FIFO_STATUS interrupt.
  768. */
  769. rt2x00_set_field32(&mask, INT_MASK_CSR_TX_FIFO_STATUS, 1);
  770. }
  771. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_PRE_TBTT))
  772. tasklet_hi_schedule(&rt2x00dev->pretbtt_tasklet);
  773. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TBTT))
  774. tasklet_hi_schedule(&rt2x00dev->tbtt_tasklet);
  775. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RX_DONE))
  776. tasklet_schedule(&rt2x00dev->rxdone_tasklet);
  777. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_AUTO_WAKEUP))
  778. tasklet_schedule(&rt2x00dev->autowake_tasklet);
  779. /*
  780. * Disable all interrupts for which a tasklet was scheduled right now,
  781. * the tasklet will reenable the appropriate interrupts.
  782. */
  783. spin_lock(&rt2x00dev->irqmask_lock);
  784. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  785. reg &= mask;
  786. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  787. spin_unlock(&rt2x00dev->irqmask_lock);
  788. return IRQ_HANDLED;
  789. }
  790. /*
  791. * Device probe functions.
  792. */
  793. static int rt2800pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  794. {
  795. /*
  796. * Read EEPROM into buffer
  797. */
  798. if (rt2x00_is_soc(rt2x00dev))
  799. rt2800pci_read_eeprom_soc(rt2x00dev);
  800. else if (rt2800pci_efuse_detect(rt2x00dev))
  801. rt2800pci_read_eeprom_efuse(rt2x00dev);
  802. else
  803. rt2800pci_read_eeprom_pci(rt2x00dev);
  804. return rt2800_validate_eeprom(rt2x00dev);
  805. }
  806. static int rt2800pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  807. {
  808. int retval;
  809. /*
  810. * Allocate eeprom data.
  811. */
  812. retval = rt2800pci_validate_eeprom(rt2x00dev);
  813. if (retval)
  814. return retval;
  815. retval = rt2800_init_eeprom(rt2x00dev);
  816. if (retval)
  817. return retval;
  818. /*
  819. * Initialize hw specifications.
  820. */
  821. retval = rt2800_probe_hw_mode(rt2x00dev);
  822. if (retval)
  823. return retval;
  824. /*
  825. * This device has multiple filters for control frames
  826. * and has a separate filter for PS Poll frames.
  827. */
  828. __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
  829. __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
  830. /*
  831. * This device has a pre tbtt interrupt and thus fetches
  832. * a new beacon directly prior to transmission.
  833. */
  834. __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
  835. /*
  836. * This device requires firmware.
  837. */
  838. if (!rt2x00_is_soc(rt2x00dev))
  839. __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
  840. __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
  841. __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
  842. __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
  843. __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
  844. if (!modparam_nohwcrypt)
  845. __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
  846. __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
  847. __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
  848. /*
  849. * Set the rssi offset.
  850. */
  851. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  852. return 0;
  853. }
  854. static const struct ieee80211_ops rt2800pci_mac80211_ops = {
  855. .tx = rt2x00mac_tx,
  856. .start = rt2x00mac_start,
  857. .stop = rt2x00mac_stop,
  858. .add_interface = rt2x00mac_add_interface,
  859. .remove_interface = rt2x00mac_remove_interface,
  860. .config = rt2x00mac_config,
  861. .configure_filter = rt2x00mac_configure_filter,
  862. .set_key = rt2x00mac_set_key,
  863. .sw_scan_start = rt2x00mac_sw_scan_start,
  864. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  865. .get_stats = rt2x00mac_get_stats,
  866. .get_tkip_seq = rt2800_get_tkip_seq,
  867. .set_rts_threshold = rt2800_set_rts_threshold,
  868. .bss_info_changed = rt2x00mac_bss_info_changed,
  869. .conf_tx = rt2800_conf_tx,
  870. .get_tsf = rt2800_get_tsf,
  871. .rfkill_poll = rt2x00mac_rfkill_poll,
  872. .ampdu_action = rt2800_ampdu_action,
  873. .flush = rt2x00mac_flush,
  874. .get_survey = rt2800_get_survey,
  875. .get_ringparam = rt2x00mac_get_ringparam,
  876. .tx_frames_pending = rt2x00mac_tx_frames_pending,
  877. };
  878. static const struct rt2800_ops rt2800pci_rt2800_ops = {
  879. .register_read = rt2x00pci_register_read,
  880. .register_read_lock = rt2x00pci_register_read, /* same for PCI */
  881. .register_write = rt2x00pci_register_write,
  882. .register_write_lock = rt2x00pci_register_write, /* same for PCI */
  883. .register_multiread = rt2x00pci_register_multiread,
  884. .register_multiwrite = rt2x00pci_register_multiwrite,
  885. .regbusy_read = rt2x00pci_regbusy_read,
  886. .drv_write_firmware = rt2800pci_write_firmware,
  887. .drv_init_registers = rt2800pci_init_registers,
  888. .drv_get_txwi = rt2800pci_get_txwi,
  889. };
  890. static const struct rt2x00lib_ops rt2800pci_rt2x00_ops = {
  891. .irq_handler = rt2800pci_interrupt,
  892. .txstatus_tasklet = rt2800pci_txstatus_tasklet,
  893. .pretbtt_tasklet = rt2800pci_pretbtt_tasklet,
  894. .tbtt_tasklet = rt2800pci_tbtt_tasklet,
  895. .rxdone_tasklet = rt2800pci_rxdone_tasklet,
  896. .autowake_tasklet = rt2800pci_autowake_tasklet,
  897. .probe_hw = rt2800pci_probe_hw,
  898. .get_firmware_name = rt2800pci_get_firmware_name,
  899. .check_firmware = rt2800_check_firmware,
  900. .load_firmware = rt2800_load_firmware,
  901. .initialize = rt2x00pci_initialize,
  902. .uninitialize = rt2x00pci_uninitialize,
  903. .get_entry_state = rt2800pci_get_entry_state,
  904. .clear_entry = rt2800pci_clear_entry,
  905. .set_device_state = rt2800pci_set_device_state,
  906. .rfkill_poll = rt2800_rfkill_poll,
  907. .link_stats = rt2800_link_stats,
  908. .reset_tuner = rt2800_reset_tuner,
  909. .link_tuner = rt2800_link_tuner,
  910. .gain_calibration = rt2800_gain_calibration,
  911. .start_queue = rt2800pci_start_queue,
  912. .kick_queue = rt2800pci_kick_queue,
  913. .stop_queue = rt2800pci_stop_queue,
  914. .flush_queue = rt2x00pci_flush_queue,
  915. .write_tx_desc = rt2800pci_write_tx_desc,
  916. .write_tx_data = rt2800_write_tx_data,
  917. .write_beacon = rt2800_write_beacon,
  918. .clear_beacon = rt2800_clear_beacon,
  919. .fill_rxdone = rt2800pci_fill_rxdone,
  920. .config_shared_key = rt2800_config_shared_key,
  921. .config_pairwise_key = rt2800_config_pairwise_key,
  922. .config_filter = rt2800_config_filter,
  923. .config_intf = rt2800_config_intf,
  924. .config_erp = rt2800_config_erp,
  925. .config_ant = rt2800_config_ant,
  926. .config = rt2800_config,
  927. };
  928. static const struct data_queue_desc rt2800pci_queue_rx = {
  929. .entry_num = 128,
  930. .data_size = AGGREGATION_SIZE,
  931. .desc_size = RXD_DESC_SIZE,
  932. .priv_size = sizeof(struct queue_entry_priv_pci),
  933. };
  934. static const struct data_queue_desc rt2800pci_queue_tx = {
  935. .entry_num = 64,
  936. .data_size = AGGREGATION_SIZE,
  937. .desc_size = TXD_DESC_SIZE,
  938. .priv_size = sizeof(struct queue_entry_priv_pci),
  939. };
  940. static const struct data_queue_desc rt2800pci_queue_bcn = {
  941. .entry_num = 8,
  942. .data_size = 0, /* No DMA required for beacons */
  943. .desc_size = TXWI_DESC_SIZE,
  944. .priv_size = sizeof(struct queue_entry_priv_pci),
  945. };
  946. static const struct rt2x00_ops rt2800pci_ops = {
  947. .name = KBUILD_MODNAME,
  948. .max_sta_intf = 1,
  949. .max_ap_intf = 8,
  950. .eeprom_size = EEPROM_SIZE,
  951. .rf_size = RF_SIZE,
  952. .tx_queues = NUM_TX_QUEUES,
  953. .extra_tx_headroom = TXWI_DESC_SIZE,
  954. .rx = &rt2800pci_queue_rx,
  955. .tx = &rt2800pci_queue_tx,
  956. .bcn = &rt2800pci_queue_bcn,
  957. .lib = &rt2800pci_rt2x00_ops,
  958. .drv = &rt2800pci_rt2800_ops,
  959. .hw = &rt2800pci_mac80211_ops,
  960. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  961. .debugfs = &rt2800_rt2x00debug,
  962. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  963. };
  964. /*
  965. * RT2800pci module information.
  966. */
  967. #ifdef CONFIG_PCI
  968. static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
  969. { PCI_DEVICE(0x1814, 0x0601) },
  970. { PCI_DEVICE(0x1814, 0x0681) },
  971. { PCI_DEVICE(0x1814, 0x0701) },
  972. { PCI_DEVICE(0x1814, 0x0781) },
  973. { PCI_DEVICE(0x1814, 0x3090) },
  974. { PCI_DEVICE(0x1814, 0x3091) },
  975. { PCI_DEVICE(0x1814, 0x3092) },
  976. { PCI_DEVICE(0x1432, 0x7708) },
  977. { PCI_DEVICE(0x1432, 0x7727) },
  978. { PCI_DEVICE(0x1432, 0x7728) },
  979. { PCI_DEVICE(0x1432, 0x7738) },
  980. { PCI_DEVICE(0x1432, 0x7748) },
  981. { PCI_DEVICE(0x1432, 0x7758) },
  982. { PCI_DEVICE(0x1432, 0x7768) },
  983. { PCI_DEVICE(0x1462, 0x891a) },
  984. { PCI_DEVICE(0x1a3b, 0x1059) },
  985. #ifdef CONFIG_RT2800PCI_RT33XX
  986. { PCI_DEVICE(0x1814, 0x3390) },
  987. #endif
  988. #ifdef CONFIG_RT2800PCI_RT35XX
  989. { PCI_DEVICE(0x1432, 0x7711) },
  990. { PCI_DEVICE(0x1432, 0x7722) },
  991. { PCI_DEVICE(0x1814, 0x3060) },
  992. { PCI_DEVICE(0x1814, 0x3062) },
  993. { PCI_DEVICE(0x1814, 0x3562) },
  994. { PCI_DEVICE(0x1814, 0x3592) },
  995. { PCI_DEVICE(0x1814, 0x3593) },
  996. #endif
  997. #ifdef CONFIG_RT2800PCI_RT53XX
  998. { PCI_DEVICE(0x1814, 0x5390) },
  999. { PCI_DEVICE(0x1814, 0x539f) },
  1000. #endif
  1001. { 0, }
  1002. };
  1003. #endif /* CONFIG_PCI */
  1004. MODULE_AUTHOR(DRV_PROJECT);
  1005. MODULE_VERSION(DRV_VERSION);
  1006. MODULE_DESCRIPTION("Ralink RT2800 PCI & PCMCIA Wireless LAN driver.");
  1007. MODULE_SUPPORTED_DEVICE("Ralink RT2860 PCI & PCMCIA chipset based cards");
  1008. #ifdef CONFIG_PCI
  1009. MODULE_FIRMWARE(FIRMWARE_RT2860);
  1010. MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
  1011. #endif /* CONFIG_PCI */
  1012. MODULE_LICENSE("GPL");
  1013. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1014. static int rt2800soc_probe(struct platform_device *pdev)
  1015. {
  1016. return rt2x00soc_probe(pdev, &rt2800pci_ops);
  1017. }
  1018. static struct platform_driver rt2800soc_driver = {
  1019. .driver = {
  1020. .name = "rt2800_wmac",
  1021. .owner = THIS_MODULE,
  1022. .mod_name = KBUILD_MODNAME,
  1023. },
  1024. .probe = rt2800soc_probe,
  1025. .remove = __devexit_p(rt2x00soc_remove),
  1026. .suspend = rt2x00soc_suspend,
  1027. .resume = rt2x00soc_resume,
  1028. };
  1029. #endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */
  1030. #ifdef CONFIG_PCI
  1031. static int rt2800pci_probe(struct pci_dev *pci_dev,
  1032. const struct pci_device_id *id)
  1033. {
  1034. return rt2x00pci_probe(pci_dev, &rt2800pci_ops);
  1035. }
  1036. static struct pci_driver rt2800pci_driver = {
  1037. .name = KBUILD_MODNAME,
  1038. .id_table = rt2800pci_device_table,
  1039. .probe = rt2800pci_probe,
  1040. .remove = __devexit_p(rt2x00pci_remove),
  1041. .suspend = rt2x00pci_suspend,
  1042. .resume = rt2x00pci_resume,
  1043. };
  1044. #endif /* CONFIG_PCI */
  1045. static int __init rt2800pci_init(void)
  1046. {
  1047. int ret = 0;
  1048. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1049. ret = platform_driver_register(&rt2800soc_driver);
  1050. if (ret)
  1051. return ret;
  1052. #endif
  1053. #ifdef CONFIG_PCI
  1054. ret = pci_register_driver(&rt2800pci_driver);
  1055. if (ret) {
  1056. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1057. platform_driver_unregister(&rt2800soc_driver);
  1058. #endif
  1059. return ret;
  1060. }
  1061. #endif
  1062. return ret;
  1063. }
  1064. static void __exit rt2800pci_exit(void)
  1065. {
  1066. #ifdef CONFIG_PCI
  1067. pci_unregister_driver(&rt2800pci_driver);
  1068. #endif
  1069. #if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X)
  1070. platform_driver_unregister(&rt2800soc_driver);
  1071. #endif
  1072. }
  1073. module_init(rt2800pci_init);
  1074. module_exit(rt2800pci_exit);