rt2800pci.c 36 KB

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