rt2400pci.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. /*
  2. Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2400pci
  19. Abstract: rt2400pci device specific routines.
  20. Supported chipsets: RT2460.
  21. */
  22. /*
  23. * Set enviroment defines for rt2x00.h
  24. */
  25. #define DRV_NAME "rt2400pci"
  26. #include <linux/delay.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/init.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/pci.h>
  32. #include <linux/eeprom_93cx6.h>
  33. #include "rt2x00.h"
  34. #include "rt2x00pci.h"
  35. #include "rt2400pci.h"
  36. /*
  37. * Register access.
  38. * All access to the CSR registers will go through the methods
  39. * rt2x00pci_register_read and rt2x00pci_register_write.
  40. * BBP and RF register require indirect register access,
  41. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  42. * These indirect registers work with busy bits,
  43. * and we will try maximal REGISTER_BUSY_COUNT times to access
  44. * the register while taking a REGISTER_BUSY_DELAY us delay
  45. * between each attampt. When the busy bit is still set at that time,
  46. * the access attempt is considered to have failed,
  47. * and we will print an error.
  48. */
  49. static u32 rt2400pci_bbp_check(const struct rt2x00_dev *rt2x00dev)
  50. {
  51. u32 reg;
  52. unsigned int i;
  53. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  54. rt2x00pci_register_read(rt2x00dev, BBPCSR, &reg);
  55. if (!rt2x00_get_field32(reg, BBPCSR_BUSY))
  56. break;
  57. udelay(REGISTER_BUSY_DELAY);
  58. }
  59. return reg;
  60. }
  61. static void rt2400pci_bbp_write(const struct rt2x00_dev *rt2x00dev,
  62. const unsigned int word, const u8 value)
  63. {
  64. u32 reg;
  65. /*
  66. * Wait until the BBP becomes ready.
  67. */
  68. reg = rt2400pci_bbp_check(rt2x00dev);
  69. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  70. ERROR(rt2x00dev, "BBPCSR register busy. Write failed.\n");
  71. return;
  72. }
  73. /*
  74. * Write the data into the BBP.
  75. */
  76. reg = 0;
  77. rt2x00_set_field32(&reg, BBPCSR_VALUE, value);
  78. rt2x00_set_field32(&reg, BBPCSR_REGNUM, word);
  79. rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
  80. rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 1);
  81. rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);
  82. }
  83. static void rt2400pci_bbp_read(const struct rt2x00_dev *rt2x00dev,
  84. const unsigned int word, u8 *value)
  85. {
  86. u32 reg;
  87. /*
  88. * Wait until the BBP becomes ready.
  89. */
  90. reg = rt2400pci_bbp_check(rt2x00dev);
  91. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  92. ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n");
  93. return;
  94. }
  95. /*
  96. * Write the request into the BBP.
  97. */
  98. reg = 0;
  99. rt2x00_set_field32(&reg, BBPCSR_REGNUM, word);
  100. rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
  101. rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 0);
  102. rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);
  103. /*
  104. * Wait until the BBP becomes ready.
  105. */
  106. reg = rt2400pci_bbp_check(rt2x00dev);
  107. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  108. ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n");
  109. *value = 0xff;
  110. return;
  111. }
  112. *value = rt2x00_get_field32(reg, BBPCSR_VALUE);
  113. }
  114. static void rt2400pci_rf_write(const struct rt2x00_dev *rt2x00dev,
  115. const unsigned int word, const u32 value)
  116. {
  117. u32 reg;
  118. unsigned int i;
  119. if (!word)
  120. return;
  121. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  122. rt2x00pci_register_read(rt2x00dev, RFCSR, &reg);
  123. if (!rt2x00_get_field32(reg, RFCSR_BUSY))
  124. goto rf_write;
  125. udelay(REGISTER_BUSY_DELAY);
  126. }
  127. ERROR(rt2x00dev, "RFCSR register busy. Write failed.\n");
  128. return;
  129. rf_write:
  130. reg = 0;
  131. rt2x00_set_field32(&reg, RFCSR_VALUE, value);
  132. rt2x00_set_field32(&reg, RFCSR_NUMBER_OF_BITS, 20);
  133. rt2x00_set_field32(&reg, RFCSR_IF_SELECT, 0);
  134. rt2x00_set_field32(&reg, RFCSR_BUSY, 1);
  135. rt2x00pci_register_write(rt2x00dev, RFCSR, reg);
  136. rt2x00_rf_write(rt2x00dev, word, value);
  137. }
  138. static void rt2400pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  139. {
  140. struct rt2x00_dev *rt2x00dev = eeprom->data;
  141. u32 reg;
  142. rt2x00pci_register_read(rt2x00dev, CSR21, &reg);
  143. eeprom->reg_data_in = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_IN);
  144. eeprom->reg_data_out = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_OUT);
  145. eeprom->reg_data_clock =
  146. !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_CLOCK);
  147. eeprom->reg_chip_select =
  148. !!rt2x00_get_field32(reg, CSR21_EEPROM_CHIP_SELECT);
  149. }
  150. static void rt2400pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  151. {
  152. struct rt2x00_dev *rt2x00dev = eeprom->data;
  153. u32 reg = 0;
  154. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_IN, !!eeprom->reg_data_in);
  155. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_OUT, !!eeprom->reg_data_out);
  156. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_CLOCK,
  157. !!eeprom->reg_data_clock);
  158. rt2x00_set_field32(&reg, CSR21_EEPROM_CHIP_SELECT,
  159. !!eeprom->reg_chip_select);
  160. rt2x00pci_register_write(rt2x00dev, CSR21, reg);
  161. }
  162. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  163. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
  164. static void rt2400pci_read_csr(const struct rt2x00_dev *rt2x00dev,
  165. const unsigned int word, u32 *data)
  166. {
  167. rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
  168. }
  169. static void rt2400pci_write_csr(const struct rt2x00_dev *rt2x00dev,
  170. const unsigned int word, u32 data)
  171. {
  172. rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
  173. }
  174. static const struct rt2x00debug rt2400pci_rt2x00debug = {
  175. .owner = THIS_MODULE,
  176. .csr = {
  177. .read = rt2400pci_read_csr,
  178. .write = rt2400pci_write_csr,
  179. .word_size = sizeof(u32),
  180. .word_count = CSR_REG_SIZE / sizeof(u32),
  181. },
  182. .eeprom = {
  183. .read = rt2x00_eeprom_read,
  184. .write = rt2x00_eeprom_write,
  185. .word_size = sizeof(u16),
  186. .word_count = EEPROM_SIZE / sizeof(u16),
  187. },
  188. .bbp = {
  189. .read = rt2400pci_bbp_read,
  190. .write = rt2400pci_bbp_write,
  191. .word_size = sizeof(u8),
  192. .word_count = BBP_SIZE / sizeof(u8),
  193. },
  194. .rf = {
  195. .read = rt2x00_rf_read,
  196. .write = rt2400pci_rf_write,
  197. .word_size = sizeof(u32),
  198. .word_count = RF_SIZE / sizeof(u32),
  199. },
  200. };
  201. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  202. #ifdef CONFIG_RT2400PCI_RFKILL
  203. static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  204. {
  205. u32 reg;
  206. rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
  207. return rt2x00_get_field32(reg, GPIOCSR_BIT0);
  208. }
  209. #else
  210. #define rt2400pci_rfkill_poll NULL
  211. #endif /* CONFIG_RT2400PCI_RFKILL */
  212. /*
  213. * Configuration handlers.
  214. */
  215. static void rt2400pci_config_mac_addr(struct rt2x00_dev *rt2x00dev,
  216. __le32 *mac)
  217. {
  218. rt2x00pci_register_multiwrite(rt2x00dev, CSR3, mac,
  219. (2 * sizeof(__le32)));
  220. }
  221. static void rt2400pci_config_bssid(struct rt2x00_dev *rt2x00dev,
  222. __le32 *bssid)
  223. {
  224. rt2x00pci_register_multiwrite(rt2x00dev, CSR5, bssid,
  225. (2 * sizeof(__le32)));
  226. }
  227. static void rt2400pci_config_type(struct rt2x00_dev *rt2x00dev, const int type,
  228. const int tsf_sync)
  229. {
  230. u32 reg;
  231. rt2x00pci_register_write(rt2x00dev, CSR14, 0);
  232. /*
  233. * Enable beacon config
  234. */
  235. rt2x00pci_register_read(rt2x00dev, BCNCSR1, &reg);
  236. rt2x00_set_field32(&reg, BCNCSR1_PRELOAD,
  237. PREAMBLE + get_duration(IEEE80211_HEADER, 20));
  238. rt2x00pci_register_write(rt2x00dev, BCNCSR1, reg);
  239. /*
  240. * Enable synchronisation.
  241. */
  242. rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
  243. rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1);
  244. rt2x00_set_field32(&reg, CSR14_TBCN, 1);
  245. rt2x00_set_field32(&reg, CSR14_BEACON_GEN, 0);
  246. rt2x00_set_field32(&reg, CSR14_TSF_SYNC, tsf_sync);
  247. rt2x00pci_register_write(rt2x00dev, CSR14, reg);
  248. }
  249. static void rt2400pci_config_preamble(struct rt2x00_dev *rt2x00dev,
  250. const int short_preamble,
  251. const int ack_timeout,
  252. const int ack_consume_time)
  253. {
  254. int preamble_mask;
  255. u32 reg;
  256. /*
  257. * When short preamble is enabled, we should set bit 0x08
  258. */
  259. preamble_mask = short_preamble << 3;
  260. rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
  261. rt2x00_set_field32(&reg, TXCSR1_ACK_TIMEOUT, ack_timeout);
  262. rt2x00_set_field32(&reg, TXCSR1_ACK_CONSUME_TIME, ack_consume_time);
  263. rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
  264. rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg);
  265. rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00 | preamble_mask);
  266. rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04);
  267. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10));
  268. rt2x00pci_register_write(rt2x00dev, ARCSR2, reg);
  269. rt2x00pci_register_read(rt2x00dev, ARCSR3, &reg);
  270. rt2x00_set_field32(&reg, ARCSR3_SIGNAL, 0x01 | preamble_mask);
  271. rt2x00_set_field32(&reg, ARCSR3_SERVICE, 0x04);
  272. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 20));
  273. rt2x00pci_register_write(rt2x00dev, ARCSR3, reg);
  274. rt2x00pci_register_read(rt2x00dev, ARCSR4, &reg);
  275. rt2x00_set_field32(&reg, ARCSR4_SIGNAL, 0x02 | preamble_mask);
  276. rt2x00_set_field32(&reg, ARCSR4_SERVICE, 0x04);
  277. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 55));
  278. rt2x00pci_register_write(rt2x00dev, ARCSR4, reg);
  279. rt2x00pci_register_read(rt2x00dev, ARCSR5, &reg);
  280. rt2x00_set_field32(&reg, ARCSR5_SIGNAL, 0x03 | preamble_mask);
  281. rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84);
  282. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110));
  283. rt2x00pci_register_write(rt2x00dev, ARCSR5, reg);
  284. }
  285. static void rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev,
  286. const int basic_rate_mask)
  287. {
  288. rt2x00pci_register_write(rt2x00dev, ARCSR1, basic_rate_mask);
  289. }
  290. static void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev,
  291. struct rf_channel *rf)
  292. {
  293. /*
  294. * Switch on tuning bits.
  295. */
  296. rt2x00_set_field32(&rf->rf1, RF1_TUNER, 1);
  297. rt2x00_set_field32(&rf->rf3, RF3_TUNER, 1);
  298. rt2400pci_rf_write(rt2x00dev, 1, rf->rf1);
  299. rt2400pci_rf_write(rt2x00dev, 2, rf->rf2);
  300. rt2400pci_rf_write(rt2x00dev, 3, rf->rf3);
  301. /*
  302. * RF2420 chipset don't need any additional actions.
  303. */
  304. if (rt2x00_rf(&rt2x00dev->chip, RF2420))
  305. return;
  306. /*
  307. * For the RT2421 chipsets we need to write an invalid
  308. * reference clock rate to activate auto_tune.
  309. * After that we set the value back to the correct channel.
  310. */
  311. rt2400pci_rf_write(rt2x00dev, 1, rf->rf1);
  312. rt2400pci_rf_write(rt2x00dev, 2, 0x000c2a32);
  313. rt2400pci_rf_write(rt2x00dev, 3, rf->rf3);
  314. msleep(1);
  315. rt2400pci_rf_write(rt2x00dev, 1, rf->rf1);
  316. rt2400pci_rf_write(rt2x00dev, 2, rf->rf2);
  317. rt2400pci_rf_write(rt2x00dev, 3, rf->rf3);
  318. msleep(1);
  319. /*
  320. * Switch off tuning bits.
  321. */
  322. rt2x00_set_field32(&rf->rf1, RF1_TUNER, 0);
  323. rt2x00_set_field32(&rf->rf3, RF3_TUNER, 0);
  324. rt2400pci_rf_write(rt2x00dev, 1, rf->rf1);
  325. rt2400pci_rf_write(rt2x00dev, 3, rf->rf3);
  326. /*
  327. * Clear false CRC during channel switch.
  328. */
  329. rt2x00pci_register_read(rt2x00dev, CNT0, &rf->rf1);
  330. }
  331. static void rt2400pci_config_txpower(struct rt2x00_dev *rt2x00dev, int txpower)
  332. {
  333. rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower));
  334. }
  335. static void rt2400pci_config_antenna(struct rt2x00_dev *rt2x00dev,
  336. struct antenna_setup *ant)
  337. {
  338. u8 r1;
  339. u8 r4;
  340. rt2400pci_bbp_read(rt2x00dev, 4, &r4);
  341. rt2400pci_bbp_read(rt2x00dev, 1, &r1);
  342. /*
  343. * Configure the TX antenna.
  344. */
  345. switch (ant->tx) {
  346. case ANTENNA_SW_DIVERSITY:
  347. case ANTENNA_HW_DIVERSITY:
  348. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1);
  349. break;
  350. case ANTENNA_A:
  351. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0);
  352. break;
  353. case ANTENNA_B:
  354. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 2);
  355. break;
  356. }
  357. /*
  358. * Configure the RX antenna.
  359. */
  360. switch (ant->rx) {
  361. case ANTENNA_SW_DIVERSITY:
  362. case ANTENNA_HW_DIVERSITY:
  363. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  364. break;
  365. case ANTENNA_A:
  366. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 0);
  367. break;
  368. case ANTENNA_B:
  369. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
  370. break;
  371. }
  372. rt2400pci_bbp_write(rt2x00dev, 4, r4);
  373. rt2400pci_bbp_write(rt2x00dev, 1, r1);
  374. }
  375. static void rt2400pci_config_duration(struct rt2x00_dev *rt2x00dev,
  376. struct rt2x00lib_conf *libconf)
  377. {
  378. u32 reg;
  379. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  380. rt2x00_set_field32(&reg, CSR11_SLOT_TIME, libconf->slot_time);
  381. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  382. rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
  383. rt2x00_set_field32(&reg, CSR18_SIFS, libconf->sifs);
  384. rt2x00_set_field32(&reg, CSR18_PIFS, libconf->pifs);
  385. rt2x00pci_register_write(rt2x00dev, CSR18, reg);
  386. rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
  387. rt2x00_set_field32(&reg, CSR19_DIFS, libconf->difs);
  388. rt2x00_set_field32(&reg, CSR19_EIFS, libconf->eifs);
  389. rt2x00pci_register_write(rt2x00dev, CSR19, reg);
  390. rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
  391. rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER);
  392. rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1);
  393. rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
  394. rt2x00pci_register_read(rt2x00dev, CSR12, &reg);
  395. rt2x00_set_field32(&reg, CSR12_BEACON_INTERVAL,
  396. libconf->conf->beacon_int * 16);
  397. rt2x00_set_field32(&reg, CSR12_CFP_MAX_DURATION,
  398. libconf->conf->beacon_int * 16);
  399. rt2x00pci_register_write(rt2x00dev, CSR12, reg);
  400. }
  401. static void rt2400pci_config(struct rt2x00_dev *rt2x00dev,
  402. const unsigned int flags,
  403. struct rt2x00lib_conf *libconf)
  404. {
  405. if (flags & CONFIG_UPDATE_PHYMODE)
  406. rt2400pci_config_phymode(rt2x00dev, libconf->basic_rates);
  407. if (flags & CONFIG_UPDATE_CHANNEL)
  408. rt2400pci_config_channel(rt2x00dev, &libconf->rf);
  409. if (flags & CONFIG_UPDATE_TXPOWER)
  410. rt2400pci_config_txpower(rt2x00dev,
  411. libconf->conf->power_level);
  412. if (flags & CONFIG_UPDATE_ANTENNA)
  413. rt2400pci_config_antenna(rt2x00dev, &libconf->ant);
  414. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  415. rt2400pci_config_duration(rt2x00dev, libconf);
  416. }
  417. static void rt2400pci_config_cw(struct rt2x00_dev *rt2x00dev,
  418. struct ieee80211_tx_queue_params *params)
  419. {
  420. u32 reg;
  421. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  422. rt2x00_set_field32(&reg, CSR11_CWMIN, params->cw_min);
  423. rt2x00_set_field32(&reg, CSR11_CWMAX, params->cw_max);
  424. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  425. }
  426. /*
  427. * LED functions.
  428. */
  429. static void rt2400pci_enable_led(struct rt2x00_dev *rt2x00dev)
  430. {
  431. u32 reg;
  432. rt2x00pci_register_read(rt2x00dev, LEDCSR, &reg);
  433. rt2x00_set_field32(&reg, LEDCSR_ON_PERIOD, 70);
  434. rt2x00_set_field32(&reg, LEDCSR_OFF_PERIOD, 30);
  435. if (rt2x00dev->led_mode == LED_MODE_TXRX_ACTIVITY) {
  436. rt2x00_set_field32(&reg, LEDCSR_LINK, 1);
  437. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 0);
  438. } else if (rt2x00dev->led_mode == LED_MODE_ASUS) {
  439. rt2x00_set_field32(&reg, LEDCSR_LINK, 0);
  440. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 1);
  441. } else {
  442. rt2x00_set_field32(&reg, LEDCSR_LINK, 1);
  443. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 1);
  444. }
  445. rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);
  446. }
  447. static void rt2400pci_disable_led(struct rt2x00_dev *rt2x00dev)
  448. {
  449. u32 reg;
  450. rt2x00pci_register_read(rt2x00dev, LEDCSR, &reg);
  451. rt2x00_set_field32(&reg, LEDCSR_LINK, 0);
  452. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 0);
  453. rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);
  454. }
  455. /*
  456. * Link tuning
  457. */
  458. static void rt2400pci_link_stats(struct rt2x00_dev *rt2x00dev,
  459. struct link_qual *qual)
  460. {
  461. u32 reg;
  462. u8 bbp;
  463. /*
  464. * Update FCS error count from register.
  465. */
  466. rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
  467. qual->rx_failed = rt2x00_get_field32(reg, CNT0_FCS_ERROR);
  468. /*
  469. * Update False CCA count from register.
  470. */
  471. rt2400pci_bbp_read(rt2x00dev, 39, &bbp);
  472. qual->false_cca = bbp;
  473. }
  474. static void rt2400pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
  475. {
  476. rt2400pci_bbp_write(rt2x00dev, 13, 0x08);
  477. rt2x00dev->link.vgc_level = 0x08;
  478. }
  479. static void rt2400pci_link_tuner(struct rt2x00_dev *rt2x00dev)
  480. {
  481. u8 reg;
  482. /*
  483. * The link tuner should not run longer then 60 seconds,
  484. * and should run once every 2 seconds.
  485. */
  486. if (rt2x00dev->link.count > 60 || !(rt2x00dev->link.count & 1))
  487. return;
  488. /*
  489. * Base r13 link tuning on the false cca count.
  490. */
  491. rt2400pci_bbp_read(rt2x00dev, 13, &reg);
  492. if (rt2x00dev->link.qual.false_cca > 512 && reg < 0x20) {
  493. rt2400pci_bbp_write(rt2x00dev, 13, ++reg);
  494. rt2x00dev->link.vgc_level = reg;
  495. } else if (rt2x00dev->link.qual.false_cca < 100 && reg > 0x08) {
  496. rt2400pci_bbp_write(rt2x00dev, 13, --reg);
  497. rt2x00dev->link.vgc_level = reg;
  498. }
  499. }
  500. /*
  501. * Initialization functions.
  502. */
  503. static void rt2400pci_init_rxring(struct rt2x00_dev *rt2x00dev)
  504. {
  505. struct data_ring *ring = rt2x00dev->rx;
  506. struct data_desc *rxd;
  507. unsigned int i;
  508. u32 word;
  509. memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
  510. for (i = 0; i < ring->stats.limit; i++) {
  511. rxd = ring->entry[i].priv;
  512. rt2x00_desc_read(rxd, 2, &word);
  513. rt2x00_set_field32(&word, RXD_W2_BUFFER_LENGTH,
  514. ring->data_size);
  515. rt2x00_desc_write(rxd, 2, word);
  516. rt2x00_desc_read(rxd, 1, &word);
  517. rt2x00_set_field32(&word, RXD_W1_BUFFER_ADDRESS,
  518. ring->entry[i].data_dma);
  519. rt2x00_desc_write(rxd, 1, word);
  520. rt2x00_desc_read(rxd, 0, &word);
  521. rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1);
  522. rt2x00_desc_write(rxd, 0, word);
  523. }
  524. rt2x00_ring_index_clear(rt2x00dev->rx);
  525. }
  526. static void rt2400pci_init_txring(struct rt2x00_dev *rt2x00dev, const int queue)
  527. {
  528. struct data_ring *ring = rt2x00lib_get_ring(rt2x00dev, queue);
  529. struct data_desc *txd;
  530. unsigned int i;
  531. u32 word;
  532. memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
  533. for (i = 0; i < ring->stats.limit; i++) {
  534. txd = ring->entry[i].priv;
  535. rt2x00_desc_read(txd, 1, &word);
  536. rt2x00_set_field32(&word, TXD_W1_BUFFER_ADDRESS,
  537. ring->entry[i].data_dma);
  538. rt2x00_desc_write(txd, 1, word);
  539. rt2x00_desc_read(txd, 2, &word);
  540. rt2x00_set_field32(&word, TXD_W2_BUFFER_LENGTH,
  541. ring->data_size);
  542. rt2x00_desc_write(txd, 2, word);
  543. rt2x00_desc_read(txd, 0, &word);
  544. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  545. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0);
  546. rt2x00_desc_write(txd, 0, word);
  547. }
  548. rt2x00_ring_index_clear(ring);
  549. }
  550. static int rt2400pci_init_rings(struct rt2x00_dev *rt2x00dev)
  551. {
  552. u32 reg;
  553. /*
  554. * Initialize rings.
  555. */
  556. rt2400pci_init_rxring(rt2x00dev);
  557. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA0);
  558. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA1);
  559. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_AFTER_BEACON);
  560. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
  561. /*
  562. * Initialize registers.
  563. */
  564. rt2x00pci_register_read(rt2x00dev, TXCSR2, &reg);
  565. rt2x00_set_field32(&reg, TXCSR2_TXD_SIZE,
  566. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].desc_size);
  567. rt2x00_set_field32(&reg, TXCSR2_NUM_TXD,
  568. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].stats.limit);
  569. rt2x00_set_field32(&reg, TXCSR2_NUM_ATIM,
  570. rt2x00dev->bcn[1].stats.limit);
  571. rt2x00_set_field32(&reg, TXCSR2_NUM_PRIO,
  572. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].stats.limit);
  573. rt2x00pci_register_write(rt2x00dev, TXCSR2, reg);
  574. rt2x00pci_register_read(rt2x00dev, TXCSR3, &reg);
  575. rt2x00_set_field32(&reg, TXCSR3_TX_RING_REGISTER,
  576. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].data_dma);
  577. rt2x00pci_register_write(rt2x00dev, TXCSR3, reg);
  578. rt2x00pci_register_read(rt2x00dev, TXCSR5, &reg);
  579. rt2x00_set_field32(&reg, TXCSR5_PRIO_RING_REGISTER,
  580. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].data_dma);
  581. rt2x00pci_register_write(rt2x00dev, TXCSR5, reg);
  582. rt2x00pci_register_read(rt2x00dev, TXCSR4, &reg);
  583. rt2x00_set_field32(&reg, TXCSR4_ATIM_RING_REGISTER,
  584. rt2x00dev->bcn[1].data_dma);
  585. rt2x00pci_register_write(rt2x00dev, TXCSR4, reg);
  586. rt2x00pci_register_read(rt2x00dev, TXCSR6, &reg);
  587. rt2x00_set_field32(&reg, TXCSR6_BEACON_RING_REGISTER,
  588. rt2x00dev->bcn[0].data_dma);
  589. rt2x00pci_register_write(rt2x00dev, TXCSR6, reg);
  590. rt2x00pci_register_read(rt2x00dev, RXCSR1, &reg);
  591. rt2x00_set_field32(&reg, RXCSR1_RXD_SIZE, rt2x00dev->rx->desc_size);
  592. rt2x00_set_field32(&reg, RXCSR1_NUM_RXD, rt2x00dev->rx->stats.limit);
  593. rt2x00pci_register_write(rt2x00dev, RXCSR1, reg);
  594. rt2x00pci_register_read(rt2x00dev, RXCSR2, &reg);
  595. rt2x00_set_field32(&reg, RXCSR2_RX_RING_REGISTER,
  596. rt2x00dev->rx->data_dma);
  597. rt2x00pci_register_write(rt2x00dev, RXCSR2, reg);
  598. return 0;
  599. }
  600. static int rt2400pci_init_registers(struct rt2x00_dev *rt2x00dev)
  601. {
  602. u32 reg;
  603. rt2x00pci_register_write(rt2x00dev, PSCSR0, 0x00020002);
  604. rt2x00pci_register_write(rt2x00dev, PSCSR1, 0x00000002);
  605. rt2x00pci_register_write(rt2x00dev, PSCSR2, 0x00023f20);
  606. rt2x00pci_register_write(rt2x00dev, PSCSR3, 0x00000002);
  607. rt2x00pci_register_read(rt2x00dev, TIMECSR, &reg);
  608. rt2x00_set_field32(&reg, TIMECSR_US_COUNT, 33);
  609. rt2x00_set_field32(&reg, TIMECSR_US_64_COUNT, 63);
  610. rt2x00_set_field32(&reg, TIMECSR_BEACON_EXPECT, 0);
  611. rt2x00pci_register_write(rt2x00dev, TIMECSR, reg);
  612. rt2x00pci_register_read(rt2x00dev, CSR9, &reg);
  613. rt2x00_set_field32(&reg, CSR9_MAX_FRAME_UNIT,
  614. (rt2x00dev->rx->data_size / 128));
  615. rt2x00pci_register_write(rt2x00dev, CSR9, reg);
  616. rt2x00pci_register_write(rt2x00dev, CNT3, 0x3f080000);
  617. rt2x00pci_register_read(rt2x00dev, ARCSR0, &reg);
  618. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_DATA0, 133);
  619. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_ID0, 134);
  620. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_DATA1, 136);
  621. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_ID1, 135);
  622. rt2x00pci_register_write(rt2x00dev, ARCSR0, reg);
  623. rt2x00pci_register_read(rt2x00dev, RXCSR3, &reg);
  624. rt2x00_set_field32(&reg, RXCSR3_BBP_ID0, 3); /* Tx power.*/
  625. rt2x00_set_field32(&reg, RXCSR3_BBP_ID0_VALID, 1);
  626. rt2x00_set_field32(&reg, RXCSR3_BBP_ID1, 32); /* Signal */
  627. rt2x00_set_field32(&reg, RXCSR3_BBP_ID1_VALID, 1);
  628. rt2x00_set_field32(&reg, RXCSR3_BBP_ID2, 36); /* Rssi */
  629. rt2x00_set_field32(&reg, RXCSR3_BBP_ID2_VALID, 1);
  630. rt2x00pci_register_write(rt2x00dev, RXCSR3, reg);
  631. rt2x00pci_register_write(rt2x00dev, PWRCSR0, 0x3f3b3100);
  632. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  633. return -EBUSY;
  634. rt2x00pci_register_write(rt2x00dev, MACCSR0, 0x00217223);
  635. rt2x00pci_register_write(rt2x00dev, MACCSR1, 0x00235518);
  636. rt2x00pci_register_read(rt2x00dev, MACCSR2, &reg);
  637. rt2x00_set_field32(&reg, MACCSR2_DELAY, 64);
  638. rt2x00pci_register_write(rt2x00dev, MACCSR2, reg);
  639. rt2x00pci_register_read(rt2x00dev, RALINKCSR, &reg);
  640. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_DATA0, 17);
  641. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_ID0, 154);
  642. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_DATA1, 0);
  643. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_ID1, 154);
  644. rt2x00pci_register_write(rt2x00dev, RALINKCSR, reg);
  645. rt2x00pci_register_read(rt2x00dev, CSR1, &reg);
  646. rt2x00_set_field32(&reg, CSR1_SOFT_RESET, 1);
  647. rt2x00_set_field32(&reg, CSR1_BBP_RESET, 0);
  648. rt2x00_set_field32(&reg, CSR1_HOST_READY, 0);
  649. rt2x00pci_register_write(rt2x00dev, CSR1, reg);
  650. rt2x00pci_register_read(rt2x00dev, CSR1, &reg);
  651. rt2x00_set_field32(&reg, CSR1_SOFT_RESET, 0);
  652. rt2x00_set_field32(&reg, CSR1_HOST_READY, 1);
  653. rt2x00pci_register_write(rt2x00dev, CSR1, reg);
  654. /*
  655. * We must clear the FCS and FIFO error count.
  656. * These registers are cleared on read,
  657. * so we may pass a useless variable to store the value.
  658. */
  659. rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
  660. rt2x00pci_register_read(rt2x00dev, CNT4, &reg);
  661. return 0;
  662. }
  663. static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev)
  664. {
  665. unsigned int i;
  666. u16 eeprom;
  667. u8 reg_id;
  668. u8 value;
  669. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  670. rt2400pci_bbp_read(rt2x00dev, 0, &value);
  671. if ((value != 0xff) && (value != 0x00))
  672. goto continue_csr_init;
  673. NOTICE(rt2x00dev, "Waiting for BBP register.\n");
  674. udelay(REGISTER_BUSY_DELAY);
  675. }
  676. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  677. return -EACCES;
  678. continue_csr_init:
  679. rt2400pci_bbp_write(rt2x00dev, 1, 0x00);
  680. rt2400pci_bbp_write(rt2x00dev, 3, 0x27);
  681. rt2400pci_bbp_write(rt2x00dev, 4, 0x08);
  682. rt2400pci_bbp_write(rt2x00dev, 10, 0x0f);
  683. rt2400pci_bbp_write(rt2x00dev, 15, 0x72);
  684. rt2400pci_bbp_write(rt2x00dev, 16, 0x74);
  685. rt2400pci_bbp_write(rt2x00dev, 17, 0x20);
  686. rt2400pci_bbp_write(rt2x00dev, 18, 0x72);
  687. rt2400pci_bbp_write(rt2x00dev, 19, 0x0b);
  688. rt2400pci_bbp_write(rt2x00dev, 20, 0x00);
  689. rt2400pci_bbp_write(rt2x00dev, 28, 0x11);
  690. rt2400pci_bbp_write(rt2x00dev, 29, 0x04);
  691. rt2400pci_bbp_write(rt2x00dev, 30, 0x21);
  692. rt2400pci_bbp_write(rt2x00dev, 31, 0x00);
  693. DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
  694. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  695. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  696. if (eeprom != 0xffff && eeprom != 0x0000) {
  697. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  698. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  699. DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
  700. reg_id, value);
  701. rt2400pci_bbp_write(rt2x00dev, reg_id, value);
  702. }
  703. }
  704. DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
  705. return 0;
  706. }
  707. /*
  708. * Device state switch handlers.
  709. */
  710. static void rt2400pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
  711. enum dev_state state)
  712. {
  713. u32 reg;
  714. rt2x00pci_register_read(rt2x00dev, RXCSR0, &reg);
  715. rt2x00_set_field32(&reg, RXCSR0_DISABLE_RX,
  716. state == STATE_RADIO_RX_OFF);
  717. rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
  718. }
  719. static void rt2400pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  720. enum dev_state state)
  721. {
  722. int mask = (state == STATE_RADIO_IRQ_OFF);
  723. u32 reg;
  724. /*
  725. * When interrupts are being enabled, the interrupt registers
  726. * should clear the register to assure a clean state.
  727. */
  728. if (state == STATE_RADIO_IRQ_ON) {
  729. rt2x00pci_register_read(rt2x00dev, CSR7, &reg);
  730. rt2x00pci_register_write(rt2x00dev, CSR7, reg);
  731. }
  732. /*
  733. * Only toggle the interrupts bits we are going to use.
  734. * Non-checked interrupt bits are disabled by default.
  735. */
  736. rt2x00pci_register_read(rt2x00dev, CSR8, &reg);
  737. rt2x00_set_field32(&reg, CSR8_TBCN_EXPIRE, mask);
  738. rt2x00_set_field32(&reg, CSR8_TXDONE_TXRING, mask);
  739. rt2x00_set_field32(&reg, CSR8_TXDONE_ATIMRING, mask);
  740. rt2x00_set_field32(&reg, CSR8_TXDONE_PRIORING, mask);
  741. rt2x00_set_field32(&reg, CSR8_RXDONE, mask);
  742. rt2x00pci_register_write(rt2x00dev, CSR8, reg);
  743. }
  744. static int rt2400pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  745. {
  746. /*
  747. * Initialize all registers.
  748. */
  749. if (rt2400pci_init_rings(rt2x00dev) ||
  750. rt2400pci_init_registers(rt2x00dev) ||
  751. rt2400pci_init_bbp(rt2x00dev)) {
  752. ERROR(rt2x00dev, "Register initialization failed.\n");
  753. return -EIO;
  754. }
  755. /*
  756. * Enable interrupts.
  757. */
  758. rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON);
  759. /*
  760. * Enable LED
  761. */
  762. rt2400pci_enable_led(rt2x00dev);
  763. return 0;
  764. }
  765. static void rt2400pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  766. {
  767. u32 reg;
  768. /*
  769. * Disable LED
  770. */
  771. rt2400pci_disable_led(rt2x00dev);
  772. rt2x00pci_register_write(rt2x00dev, PWRCSR0, 0);
  773. /*
  774. * Disable synchronisation.
  775. */
  776. rt2x00pci_register_write(rt2x00dev, CSR14, 0);
  777. /*
  778. * Cancel RX and TX.
  779. */
  780. rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
  781. rt2x00_set_field32(&reg, TXCSR0_ABORT, 1);
  782. rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
  783. /*
  784. * Disable interrupts.
  785. */
  786. rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF);
  787. }
  788. static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev,
  789. enum dev_state state)
  790. {
  791. u32 reg;
  792. unsigned int i;
  793. char put_to_sleep;
  794. char bbp_state;
  795. char rf_state;
  796. put_to_sleep = (state != STATE_AWAKE);
  797. rt2x00pci_register_read(rt2x00dev, PWRCSR1, &reg);
  798. rt2x00_set_field32(&reg, PWRCSR1_SET_STATE, 1);
  799. rt2x00_set_field32(&reg, PWRCSR1_BBP_DESIRE_STATE, state);
  800. rt2x00_set_field32(&reg, PWRCSR1_RF_DESIRE_STATE, state);
  801. rt2x00_set_field32(&reg, PWRCSR1_PUT_TO_SLEEP, put_to_sleep);
  802. rt2x00pci_register_write(rt2x00dev, PWRCSR1, reg);
  803. /*
  804. * Device is not guaranteed to be in the requested state yet.
  805. * We must wait until the register indicates that the
  806. * device has entered the correct state.
  807. */
  808. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  809. rt2x00pci_register_read(rt2x00dev, PWRCSR1, &reg);
  810. bbp_state = rt2x00_get_field32(reg, PWRCSR1_BBP_CURR_STATE);
  811. rf_state = rt2x00_get_field32(reg, PWRCSR1_RF_CURR_STATE);
  812. if (bbp_state == state && rf_state == state)
  813. return 0;
  814. msleep(10);
  815. }
  816. NOTICE(rt2x00dev, "Device failed to enter state %d, "
  817. "current device state: bbp %d and rf %d.\n",
  818. state, bbp_state, rf_state);
  819. return -EBUSY;
  820. }
  821. static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  822. enum dev_state state)
  823. {
  824. int retval = 0;
  825. switch (state) {
  826. case STATE_RADIO_ON:
  827. retval = rt2400pci_enable_radio(rt2x00dev);
  828. break;
  829. case STATE_RADIO_OFF:
  830. rt2400pci_disable_radio(rt2x00dev);
  831. break;
  832. case STATE_RADIO_RX_ON:
  833. case STATE_RADIO_RX_OFF:
  834. rt2400pci_toggle_rx(rt2x00dev, state);
  835. break;
  836. case STATE_DEEP_SLEEP:
  837. case STATE_SLEEP:
  838. case STATE_STANDBY:
  839. case STATE_AWAKE:
  840. retval = rt2400pci_set_state(rt2x00dev, state);
  841. break;
  842. default:
  843. retval = -ENOTSUPP;
  844. break;
  845. }
  846. return retval;
  847. }
  848. /*
  849. * TX descriptor initialization
  850. */
  851. static void rt2400pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  852. struct data_desc *txd,
  853. struct txdata_entry_desc *desc,
  854. struct ieee80211_hdr *ieee80211hdr,
  855. unsigned int length,
  856. struct ieee80211_tx_control *control)
  857. {
  858. u32 word;
  859. u32 signal = 0;
  860. u32 service = 0;
  861. u32 length_high = 0;
  862. u32 length_low = 0;
  863. /*
  864. * The PLCP values should be treated as if they
  865. * were BBP values.
  866. */
  867. rt2x00_set_field32(&signal, BBPCSR_VALUE, desc->signal);
  868. rt2x00_set_field32(&signal, BBPCSR_REGNUM, 5);
  869. rt2x00_set_field32(&signal, BBPCSR_BUSY, 1);
  870. rt2x00_set_field32(&service, BBPCSR_VALUE, desc->service);
  871. rt2x00_set_field32(&service, BBPCSR_REGNUM, 6);
  872. rt2x00_set_field32(&service, BBPCSR_BUSY, 1);
  873. rt2x00_set_field32(&length_high, BBPCSR_VALUE, desc->length_high);
  874. rt2x00_set_field32(&length_high, BBPCSR_REGNUM, 7);
  875. rt2x00_set_field32(&length_high, BBPCSR_BUSY, 1);
  876. rt2x00_set_field32(&length_low, BBPCSR_VALUE, desc->length_low);
  877. rt2x00_set_field32(&length_low, BBPCSR_REGNUM, 8);
  878. rt2x00_set_field32(&length_low, BBPCSR_BUSY, 1);
  879. /*
  880. * Start writing the descriptor words.
  881. */
  882. rt2x00_desc_read(txd, 2, &word);
  883. rt2x00_set_field32(&word, TXD_W2_DATABYTE_COUNT, length);
  884. rt2x00_desc_write(txd, 2, word);
  885. rt2x00_desc_read(txd, 3, &word);
  886. rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL, signal);
  887. rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE, service);
  888. rt2x00_desc_write(txd, 3, word);
  889. rt2x00_desc_read(txd, 4, &word);
  890. rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_LOW, length_low);
  891. rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_HIGH, length_high);
  892. rt2x00_desc_write(txd, 4, word);
  893. rt2x00_desc_read(txd, 0, &word);
  894. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1);
  895. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  896. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  897. test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
  898. rt2x00_set_field32(&word, TXD_W0_ACK,
  899. !(control->flags & IEEE80211_TXCTL_NO_ACK));
  900. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  901. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
  902. rt2x00_set_field32(&word, TXD_W0_RTS,
  903. test_bit(ENTRY_TXD_RTS_FRAME, &desc->flags));
  904. rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
  905. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  906. !!(control->flags &
  907. IEEE80211_TXCTL_LONG_RETRY_LIMIT));
  908. rt2x00_desc_write(txd, 0, word);
  909. }
  910. /*
  911. * TX data initialization
  912. */
  913. static void rt2400pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  914. unsigned int queue)
  915. {
  916. u32 reg;
  917. if (queue == IEEE80211_TX_QUEUE_BEACON) {
  918. rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
  919. if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) {
  920. rt2x00_set_field32(&reg, CSR14_BEACON_GEN, 1);
  921. rt2x00pci_register_write(rt2x00dev, CSR14, reg);
  922. }
  923. return;
  924. }
  925. rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
  926. if (queue == IEEE80211_TX_QUEUE_DATA0)
  927. rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, 1);
  928. else if (queue == IEEE80211_TX_QUEUE_DATA1)
  929. rt2x00_set_field32(&reg, TXCSR0_KICK_TX, 1);
  930. else if (queue == IEEE80211_TX_QUEUE_AFTER_BEACON)
  931. rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM, 1);
  932. rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
  933. }
  934. /*
  935. * RX control handlers
  936. */
  937. static void rt2400pci_fill_rxdone(struct data_entry *entry,
  938. struct rxdata_entry_desc *desc)
  939. {
  940. struct data_desc *rxd = entry->priv;
  941. u32 word0;
  942. u32 word2;
  943. rt2x00_desc_read(rxd, 0, &word0);
  944. rt2x00_desc_read(rxd, 2, &word2);
  945. desc->flags = 0;
  946. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  947. desc->flags |= RX_FLAG_FAILED_FCS_CRC;
  948. if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
  949. desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
  950. /*
  951. * Obtain the status about this packet.
  952. */
  953. desc->signal = rt2x00_get_field32(word2, RXD_W2_SIGNAL);
  954. desc->rssi = rt2x00_get_field32(word2, RXD_W2_RSSI) -
  955. entry->ring->rt2x00dev->rssi_offset;
  956. desc->ofdm = 0;
  957. desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  958. }
  959. /*
  960. * Interrupt functions.
  961. */
  962. static void rt2400pci_txdone(struct rt2x00_dev *rt2x00dev, const int queue)
  963. {
  964. struct data_ring *ring = rt2x00lib_get_ring(rt2x00dev, queue);
  965. struct data_entry *entry;
  966. struct data_desc *txd;
  967. u32 word;
  968. int tx_status;
  969. int retry;
  970. while (!rt2x00_ring_empty(ring)) {
  971. entry = rt2x00_get_data_entry_done(ring);
  972. txd = entry->priv;
  973. rt2x00_desc_read(txd, 0, &word);
  974. if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) ||
  975. !rt2x00_get_field32(word, TXD_W0_VALID))
  976. break;
  977. /*
  978. * Obtain the status about this packet.
  979. */
  980. tx_status = rt2x00_get_field32(word, TXD_W0_RESULT);
  981. retry = rt2x00_get_field32(word, TXD_W0_RETRY_COUNT);
  982. rt2x00lib_txdone(entry, tx_status, retry);
  983. /*
  984. * Make this entry available for reuse.
  985. */
  986. entry->flags = 0;
  987. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  988. rt2x00_desc_write(txd, 0, word);
  989. rt2x00_ring_index_done_inc(ring);
  990. }
  991. /*
  992. * If the data ring was full before the txdone handler
  993. * we must make sure the packet queue in the mac80211 stack
  994. * is reenabled when the txdone handler has finished.
  995. */
  996. entry = ring->entry;
  997. if (!rt2x00_ring_full(ring))
  998. ieee80211_wake_queue(rt2x00dev->hw,
  999. entry->tx_status.control.queue);
  1000. }
  1001. static irqreturn_t rt2400pci_interrupt(int irq, void *dev_instance)
  1002. {
  1003. struct rt2x00_dev *rt2x00dev = dev_instance;
  1004. u32 reg;
  1005. /*
  1006. * Get the interrupt sources & saved to local variable.
  1007. * Write register value back to clear pending interrupts.
  1008. */
  1009. rt2x00pci_register_read(rt2x00dev, CSR7, &reg);
  1010. rt2x00pci_register_write(rt2x00dev, CSR7, reg);
  1011. if (!reg)
  1012. return IRQ_NONE;
  1013. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  1014. return IRQ_HANDLED;
  1015. /*
  1016. * Handle interrupts, walk through all bits
  1017. * and run the tasks, the bits are checked in order of
  1018. * priority.
  1019. */
  1020. /*
  1021. * 1 - Beacon timer expired interrupt.
  1022. */
  1023. if (rt2x00_get_field32(reg, CSR7_TBCN_EXPIRE))
  1024. rt2x00lib_beacondone(rt2x00dev);
  1025. /*
  1026. * 2 - Rx ring done interrupt.
  1027. */
  1028. if (rt2x00_get_field32(reg, CSR7_RXDONE))
  1029. rt2x00pci_rxdone(rt2x00dev);
  1030. /*
  1031. * 3 - Atim ring transmit done interrupt.
  1032. */
  1033. if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING))
  1034. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_AFTER_BEACON);
  1035. /*
  1036. * 4 - Priority ring transmit done interrupt.
  1037. */
  1038. if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING))
  1039. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA0);
  1040. /*
  1041. * 5 - Tx ring transmit done interrupt.
  1042. */
  1043. if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING))
  1044. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA1);
  1045. return IRQ_HANDLED;
  1046. }
  1047. /*
  1048. * Device probe functions.
  1049. */
  1050. static int rt2400pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1051. {
  1052. struct eeprom_93cx6 eeprom;
  1053. u32 reg;
  1054. u16 word;
  1055. u8 *mac;
  1056. rt2x00pci_register_read(rt2x00dev, CSR21, &reg);
  1057. eeprom.data = rt2x00dev;
  1058. eeprom.register_read = rt2400pci_eepromregister_read;
  1059. eeprom.register_write = rt2400pci_eepromregister_write;
  1060. eeprom.width = rt2x00_get_field32(reg, CSR21_TYPE_93C46) ?
  1061. PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
  1062. eeprom.reg_data_in = 0;
  1063. eeprom.reg_data_out = 0;
  1064. eeprom.reg_data_clock = 0;
  1065. eeprom.reg_chip_select = 0;
  1066. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  1067. EEPROM_SIZE / sizeof(u16));
  1068. /*
  1069. * Start validation of the data that has been read.
  1070. */
  1071. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1072. if (!is_valid_ether_addr(mac)) {
  1073. DECLARE_MAC_BUF(macbuf);
  1074. random_ether_addr(mac);
  1075. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1076. }
  1077. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1078. if (word == 0xffff) {
  1079. ERROR(rt2x00dev, "Invalid EEPROM data detected.\n");
  1080. return -EINVAL;
  1081. }
  1082. return 0;
  1083. }
  1084. static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1085. {
  1086. u32 reg;
  1087. u16 value;
  1088. u16 eeprom;
  1089. /*
  1090. * Read EEPROM word for configuration.
  1091. */
  1092. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1093. /*
  1094. * Identify RF chipset.
  1095. */
  1096. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1097. rt2x00pci_register_read(rt2x00dev, CSR0, &reg);
  1098. rt2x00_set_chip(rt2x00dev, RT2460, value, reg);
  1099. if (!rt2x00_rf(&rt2x00dev->chip, RF2420) &&
  1100. !rt2x00_rf(&rt2x00dev->chip, RF2421)) {
  1101. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1102. return -ENODEV;
  1103. }
  1104. /*
  1105. * Identify default antenna configuration.
  1106. */
  1107. rt2x00dev->default_ant.tx =
  1108. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1109. rt2x00dev->default_ant.rx =
  1110. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1111. /*
  1112. * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
  1113. * I am not 100% sure about this, but the legacy drivers do not
  1114. * indicate antenna swapping in software is required when
  1115. * diversity is enabled.
  1116. */
  1117. if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
  1118. rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
  1119. if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
  1120. rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
  1121. /*
  1122. * Store led mode, for correct led behaviour.
  1123. */
  1124. rt2x00dev->led_mode =
  1125. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
  1126. /*
  1127. * Detect if this device has an hardware controlled radio.
  1128. */
  1129. #ifdef CONFIG_RT2400PCI_RFKILL
  1130. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1131. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1132. #endif /* CONFIG_RT2400PCI_RFKILL */
  1133. /*
  1134. * Check if the BBP tuning should be enabled.
  1135. */
  1136. if (!rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_AGCVGC_TUNING))
  1137. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1138. return 0;
  1139. }
  1140. /*
  1141. * RF value list for RF2420 & RF2421
  1142. * Supports: 2.4 GHz
  1143. */
  1144. static const struct rf_channel rf_vals_bg[] = {
  1145. { 1, 0x00022058, 0x000c1fda, 0x00000101, 0 },
  1146. { 2, 0x00022058, 0x000c1fee, 0x00000101, 0 },
  1147. { 3, 0x00022058, 0x000c2002, 0x00000101, 0 },
  1148. { 4, 0x00022058, 0x000c2016, 0x00000101, 0 },
  1149. { 5, 0x00022058, 0x000c202a, 0x00000101, 0 },
  1150. { 6, 0x00022058, 0x000c203e, 0x00000101, 0 },
  1151. { 7, 0x00022058, 0x000c2052, 0x00000101, 0 },
  1152. { 8, 0x00022058, 0x000c2066, 0x00000101, 0 },
  1153. { 9, 0x00022058, 0x000c207a, 0x00000101, 0 },
  1154. { 10, 0x00022058, 0x000c208e, 0x00000101, 0 },
  1155. { 11, 0x00022058, 0x000c20a2, 0x00000101, 0 },
  1156. { 12, 0x00022058, 0x000c20b6, 0x00000101, 0 },
  1157. { 13, 0x00022058, 0x000c20ca, 0x00000101, 0 },
  1158. { 14, 0x00022058, 0x000c20fa, 0x00000101, 0 },
  1159. };
  1160. static void rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1161. {
  1162. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1163. u8 *txpower;
  1164. unsigned int i;
  1165. /*
  1166. * Initialize all hw fields.
  1167. */
  1168. rt2x00dev->hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  1169. rt2x00dev->hw->extra_tx_headroom = 0;
  1170. rt2x00dev->hw->max_signal = MAX_SIGNAL;
  1171. rt2x00dev->hw->max_rssi = MAX_RX_SSI;
  1172. rt2x00dev->hw->queues = 2;
  1173. SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_pci(rt2x00dev)->dev);
  1174. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1175. rt2x00_eeprom_addr(rt2x00dev,
  1176. EEPROM_MAC_ADDR_0));
  1177. /*
  1178. * Convert tx_power array in eeprom.
  1179. */
  1180. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
  1181. for (i = 0; i < 14; i++)
  1182. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1183. /*
  1184. * Initialize hw_mode information.
  1185. */
  1186. spec->num_modes = 1;
  1187. spec->num_rates = 4;
  1188. spec->tx_power_a = NULL;
  1189. spec->tx_power_bg = txpower;
  1190. spec->tx_power_default = DEFAULT_TXPOWER;
  1191. spec->num_channels = ARRAY_SIZE(rf_vals_bg);
  1192. spec->channels = rf_vals_bg;
  1193. }
  1194. static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  1195. {
  1196. int retval;
  1197. /*
  1198. * Allocate eeprom data.
  1199. */
  1200. retval = rt2400pci_validate_eeprom(rt2x00dev);
  1201. if (retval)
  1202. return retval;
  1203. retval = rt2400pci_init_eeprom(rt2x00dev);
  1204. if (retval)
  1205. return retval;
  1206. /*
  1207. * Initialize hw specifications.
  1208. */
  1209. rt2400pci_probe_hw_mode(rt2x00dev);
  1210. /*
  1211. * This device requires the beacon ring
  1212. */
  1213. __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
  1214. /*
  1215. * Set the rssi offset.
  1216. */
  1217. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1218. return 0;
  1219. }
  1220. /*
  1221. * IEEE80211 stack callback functions.
  1222. */
  1223. static void rt2400pci_configure_filter(struct ieee80211_hw *hw,
  1224. unsigned int changed_flags,
  1225. unsigned int *total_flags,
  1226. int mc_count,
  1227. struct dev_addr_list *mc_list)
  1228. {
  1229. struct rt2x00_dev *rt2x00dev = hw->priv;
  1230. struct interface *intf = &rt2x00dev->interface;
  1231. u32 reg;
  1232. /*
  1233. * Mask off any flags we are going to ignore from
  1234. * the total_flags field.
  1235. */
  1236. *total_flags &=
  1237. FIF_ALLMULTI |
  1238. FIF_FCSFAIL |
  1239. FIF_PLCPFAIL |
  1240. FIF_CONTROL |
  1241. FIF_OTHER_BSS |
  1242. FIF_PROMISC_IN_BSS;
  1243. /*
  1244. * Apply some rules to the filters:
  1245. * - Some filters imply different filters to be set.
  1246. * - Some things we can't filter out at all.
  1247. * - Some filters are set based on interface type.
  1248. */
  1249. *total_flags |= FIF_ALLMULTI;
  1250. if (*total_flags & FIF_OTHER_BSS ||
  1251. *total_flags & FIF_PROMISC_IN_BSS)
  1252. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  1253. if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
  1254. *total_flags |= FIF_PROMISC_IN_BSS;
  1255. /*
  1256. * Check if there is any work left for us.
  1257. */
  1258. if (intf->filter == *total_flags)
  1259. return;
  1260. intf->filter = *total_flags;
  1261. /*
  1262. * Start configuration steps.
  1263. * Note that the version error will always be dropped
  1264. * since there is no filter for it at this time.
  1265. */
  1266. rt2x00pci_register_read(rt2x00dev, RXCSR0, &reg);
  1267. rt2x00_set_field32(&reg, RXCSR0_DROP_CRC,
  1268. !(*total_flags & FIF_FCSFAIL));
  1269. rt2x00_set_field32(&reg, RXCSR0_DROP_PHYSICAL,
  1270. !(*total_flags & FIF_PLCPFAIL));
  1271. rt2x00_set_field32(&reg, RXCSR0_DROP_CONTROL,
  1272. !(*total_flags & FIF_CONTROL));
  1273. rt2x00_set_field32(&reg, RXCSR0_DROP_NOT_TO_ME,
  1274. !(*total_flags & FIF_PROMISC_IN_BSS));
  1275. rt2x00_set_field32(&reg, RXCSR0_DROP_TODS,
  1276. !(*total_flags & FIF_PROMISC_IN_BSS));
  1277. rt2x00_set_field32(&reg, RXCSR0_DROP_VERSION_ERROR, 1);
  1278. rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
  1279. }
  1280. static int rt2400pci_set_retry_limit(struct ieee80211_hw *hw,
  1281. u32 short_retry, u32 long_retry)
  1282. {
  1283. struct rt2x00_dev *rt2x00dev = hw->priv;
  1284. u32 reg;
  1285. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  1286. rt2x00_set_field32(&reg, CSR11_LONG_RETRY, long_retry);
  1287. rt2x00_set_field32(&reg, CSR11_SHORT_RETRY, short_retry);
  1288. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  1289. return 0;
  1290. }
  1291. static int rt2400pci_conf_tx(struct ieee80211_hw *hw,
  1292. int queue,
  1293. const struct ieee80211_tx_queue_params *params)
  1294. {
  1295. struct rt2x00_dev *rt2x00dev = hw->priv;
  1296. /*
  1297. * We don't support variating cw_min and cw_max variables
  1298. * per queue. So by default we only configure the TX queue,
  1299. * and ignore all other configurations.
  1300. */
  1301. if (queue != IEEE80211_TX_QUEUE_DATA0)
  1302. return -EINVAL;
  1303. if (rt2x00mac_conf_tx(hw, queue, params))
  1304. return -EINVAL;
  1305. /*
  1306. * Write configuration to register.
  1307. */
  1308. rt2400pci_config_cw(rt2x00dev, &rt2x00dev->tx->tx_params);
  1309. return 0;
  1310. }
  1311. static u64 rt2400pci_get_tsf(struct ieee80211_hw *hw)
  1312. {
  1313. struct rt2x00_dev *rt2x00dev = hw->priv;
  1314. u64 tsf;
  1315. u32 reg;
  1316. rt2x00pci_register_read(rt2x00dev, CSR17, &reg);
  1317. tsf = (u64) rt2x00_get_field32(reg, CSR17_HIGH_TSFTIMER) << 32;
  1318. rt2x00pci_register_read(rt2x00dev, CSR16, &reg);
  1319. tsf |= rt2x00_get_field32(reg, CSR16_LOW_TSFTIMER);
  1320. return tsf;
  1321. }
  1322. static void rt2400pci_reset_tsf(struct ieee80211_hw *hw)
  1323. {
  1324. struct rt2x00_dev *rt2x00dev = hw->priv;
  1325. rt2x00pci_register_write(rt2x00dev, CSR16, 0);
  1326. rt2x00pci_register_write(rt2x00dev, CSR17, 0);
  1327. }
  1328. static int rt2400pci_tx_last_beacon(struct ieee80211_hw *hw)
  1329. {
  1330. struct rt2x00_dev *rt2x00dev = hw->priv;
  1331. u32 reg;
  1332. rt2x00pci_register_read(rt2x00dev, CSR15, &reg);
  1333. return rt2x00_get_field32(reg, CSR15_BEACON_SENT);
  1334. }
  1335. static const struct ieee80211_ops rt2400pci_mac80211_ops = {
  1336. .tx = rt2x00mac_tx,
  1337. .start = rt2x00mac_start,
  1338. .stop = rt2x00mac_stop,
  1339. .add_interface = rt2x00mac_add_interface,
  1340. .remove_interface = rt2x00mac_remove_interface,
  1341. .config = rt2x00mac_config,
  1342. .config_interface = rt2x00mac_config_interface,
  1343. .configure_filter = rt2400pci_configure_filter,
  1344. .get_stats = rt2x00mac_get_stats,
  1345. .set_retry_limit = rt2400pci_set_retry_limit,
  1346. .erp_ie_changed = rt2x00mac_erp_ie_changed,
  1347. .conf_tx = rt2400pci_conf_tx,
  1348. .get_tx_stats = rt2x00mac_get_tx_stats,
  1349. .get_tsf = rt2400pci_get_tsf,
  1350. .reset_tsf = rt2400pci_reset_tsf,
  1351. .beacon_update = rt2x00pci_beacon_update,
  1352. .tx_last_beacon = rt2400pci_tx_last_beacon,
  1353. };
  1354. static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = {
  1355. .irq_handler = rt2400pci_interrupt,
  1356. .probe_hw = rt2400pci_probe_hw,
  1357. .initialize = rt2x00pci_initialize,
  1358. .uninitialize = rt2x00pci_uninitialize,
  1359. .set_device_state = rt2400pci_set_device_state,
  1360. .rfkill_poll = rt2400pci_rfkill_poll,
  1361. .link_stats = rt2400pci_link_stats,
  1362. .reset_tuner = rt2400pci_reset_tuner,
  1363. .link_tuner = rt2400pci_link_tuner,
  1364. .write_tx_desc = rt2400pci_write_tx_desc,
  1365. .write_tx_data = rt2x00pci_write_tx_data,
  1366. .kick_tx_queue = rt2400pci_kick_tx_queue,
  1367. .fill_rxdone = rt2400pci_fill_rxdone,
  1368. .config_mac_addr = rt2400pci_config_mac_addr,
  1369. .config_bssid = rt2400pci_config_bssid,
  1370. .config_type = rt2400pci_config_type,
  1371. .config_preamble = rt2400pci_config_preamble,
  1372. .config = rt2400pci_config,
  1373. };
  1374. static const struct rt2x00_ops rt2400pci_ops = {
  1375. .name = DRV_NAME,
  1376. .rxd_size = RXD_DESC_SIZE,
  1377. .txd_size = TXD_DESC_SIZE,
  1378. .eeprom_size = EEPROM_SIZE,
  1379. .rf_size = RF_SIZE,
  1380. .lib = &rt2400pci_rt2x00_ops,
  1381. .hw = &rt2400pci_mac80211_ops,
  1382. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1383. .debugfs = &rt2400pci_rt2x00debug,
  1384. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1385. };
  1386. /*
  1387. * RT2400pci module information.
  1388. */
  1389. static struct pci_device_id rt2400pci_device_table[] = {
  1390. { PCI_DEVICE(0x1814, 0x0101), PCI_DEVICE_DATA(&rt2400pci_ops) },
  1391. { 0, }
  1392. };
  1393. MODULE_AUTHOR(DRV_PROJECT);
  1394. MODULE_VERSION(DRV_VERSION);
  1395. MODULE_DESCRIPTION("Ralink RT2400 PCI & PCMCIA Wireless LAN driver.");
  1396. MODULE_SUPPORTED_DEVICE("Ralink RT2460 PCI & PCMCIA chipset based cards");
  1397. MODULE_DEVICE_TABLE(pci, rt2400pci_device_table);
  1398. MODULE_LICENSE("GPL");
  1399. static struct pci_driver rt2400pci_driver = {
  1400. .name = DRV_NAME,
  1401. .id_table = rt2400pci_device_table,
  1402. .probe = rt2x00pci_probe,
  1403. .remove = __devexit_p(rt2x00pci_remove),
  1404. .suspend = rt2x00pci_suspend,
  1405. .resume = rt2x00pci_resume,
  1406. };
  1407. static int __init rt2400pci_init(void)
  1408. {
  1409. return pci_register_driver(&rt2400pci_driver);
  1410. }
  1411. static void __exit rt2400pci_exit(void)
  1412. {
  1413. pci_unregister_driver(&rt2400pci_driver);
  1414. }
  1415. module_init(rt2400pci_init);
  1416. module_exit(rt2400pci_exit);