rt2400pci.c 47 KB

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