rt61pci.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  1. /*
  2. Copyright (C) 2004 - 2008 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: rt61pci
  19. Abstract: rt61pci device specific routines.
  20. Supported chipsets: RT2561, RT2561s, RT2661.
  21. */
  22. #include <linux/crc-itu-t.h>
  23. #include <linux/delay.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/eeprom_93cx6.h>
  30. #include "rt2x00.h"
  31. #include "rt2x00pci.h"
  32. #include "rt61pci.h"
  33. /*
  34. * Register access.
  35. * BBP and RF register require indirect register access,
  36. * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this.
  37. * These indirect registers work with busy bits,
  38. * and we will try maximal REGISTER_BUSY_COUNT times to access
  39. * the register while taking a REGISTER_BUSY_DELAY us delay
  40. * between each attampt. When the busy bit is still set at that time,
  41. * the access attempt is considered to have failed,
  42. * and we will print an error.
  43. */
  44. static u32 rt61pci_bbp_check(struct rt2x00_dev *rt2x00dev)
  45. {
  46. u32 reg;
  47. unsigned int i;
  48. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  49. rt2x00pci_register_read(rt2x00dev, PHY_CSR3, &reg);
  50. if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  51. break;
  52. udelay(REGISTER_BUSY_DELAY);
  53. }
  54. return reg;
  55. }
  56. static void rt61pci_bbp_write(struct rt2x00_dev *rt2x00dev,
  57. const unsigned int word, const u8 value)
  58. {
  59. u32 reg;
  60. /*
  61. * Wait until the BBP becomes ready.
  62. */
  63. reg = rt61pci_bbp_check(rt2x00dev);
  64. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  65. ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
  66. return;
  67. }
  68. /*
  69. * Write the data into the BBP.
  70. */
  71. reg = 0;
  72. rt2x00_set_field32(&reg, PHY_CSR3_VALUE, value);
  73. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  74. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  75. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
  76. rt2x00pci_register_write(rt2x00dev, PHY_CSR3, reg);
  77. }
  78. static void rt61pci_bbp_read(struct rt2x00_dev *rt2x00dev,
  79. const unsigned int word, u8 *value)
  80. {
  81. u32 reg;
  82. /*
  83. * Wait until the BBP becomes ready.
  84. */
  85. reg = rt61pci_bbp_check(rt2x00dev);
  86. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  87. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  88. return;
  89. }
  90. /*
  91. * Write the request into the BBP.
  92. */
  93. reg = 0;
  94. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  95. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  96. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
  97. rt2x00pci_register_write(rt2x00dev, PHY_CSR3, reg);
  98. /*
  99. * Wait until the BBP becomes ready.
  100. */
  101. reg = rt61pci_bbp_check(rt2x00dev);
  102. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  103. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  104. *value = 0xff;
  105. return;
  106. }
  107. *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
  108. }
  109. static void rt61pci_rf_write(struct rt2x00_dev *rt2x00dev,
  110. const unsigned int word, const u32 value)
  111. {
  112. u32 reg;
  113. unsigned int i;
  114. if (!word)
  115. return;
  116. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  117. rt2x00pci_register_read(rt2x00dev, PHY_CSR4, &reg);
  118. if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY))
  119. goto rf_write;
  120. udelay(REGISTER_BUSY_DELAY);
  121. }
  122. ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n");
  123. return;
  124. rf_write:
  125. reg = 0;
  126. rt2x00_set_field32(&reg, PHY_CSR4_VALUE, value);
  127. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS, 21);
  128. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  129. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  130. rt2x00pci_register_write(rt2x00dev, PHY_CSR4, reg);
  131. rt2x00_rf_write(rt2x00dev, word, value);
  132. }
  133. #ifdef CONFIG_RT61PCI_LEDS
  134. /*
  135. * This function is only called from rt61pci_led_brightness()
  136. * make gcc happy by placing this function inside the
  137. * same ifdef statement as the caller.
  138. */
  139. static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev,
  140. const u8 command, const u8 token,
  141. const u8 arg0, const u8 arg1)
  142. {
  143. u32 reg;
  144. rt2x00pci_register_read(rt2x00dev, H2M_MAILBOX_CSR, &reg);
  145. if (rt2x00_get_field32(reg, H2M_MAILBOX_CSR_OWNER)) {
  146. ERROR(rt2x00dev, "mcu request error. "
  147. "Request 0x%02x failed for token 0x%02x.\n",
  148. command, token);
  149. return;
  150. }
  151. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  152. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  153. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  154. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  155. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, reg);
  156. rt2x00pci_register_read(rt2x00dev, HOST_CMD_CSR, &reg);
  157. rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  158. rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1);
  159. rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
  160. }
  161. #endif /* CONFIG_RT61PCI_LEDS */
  162. static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  163. {
  164. struct rt2x00_dev *rt2x00dev = eeprom->data;
  165. u32 reg;
  166. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  167. eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
  168. eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
  169. eeprom->reg_data_clock =
  170. !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
  171. eeprom->reg_chip_select =
  172. !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
  173. }
  174. static void rt61pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  175. {
  176. struct rt2x00_dev *rt2x00dev = eeprom->data;
  177. u32 reg = 0;
  178. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
  179. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
  180. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
  181. !!eeprom->reg_data_clock);
  182. rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
  183. !!eeprom->reg_chip_select);
  184. rt2x00pci_register_write(rt2x00dev, E2PROM_CSR, reg);
  185. }
  186. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  187. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
  188. static void rt61pci_read_csr(struct rt2x00_dev *rt2x00dev,
  189. const unsigned int word, u32 *data)
  190. {
  191. rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
  192. }
  193. static void rt61pci_write_csr(struct rt2x00_dev *rt2x00dev,
  194. const unsigned int word, u32 data)
  195. {
  196. rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
  197. }
  198. static const struct rt2x00debug rt61pci_rt2x00debug = {
  199. .owner = THIS_MODULE,
  200. .csr = {
  201. .read = rt61pci_read_csr,
  202. .write = rt61pci_write_csr,
  203. .word_size = sizeof(u32),
  204. .word_count = CSR_REG_SIZE / sizeof(u32),
  205. },
  206. .eeprom = {
  207. .read = rt2x00_eeprom_read,
  208. .write = rt2x00_eeprom_write,
  209. .word_size = sizeof(u16),
  210. .word_count = EEPROM_SIZE / sizeof(u16),
  211. },
  212. .bbp = {
  213. .read = rt61pci_bbp_read,
  214. .write = rt61pci_bbp_write,
  215. .word_size = sizeof(u8),
  216. .word_count = BBP_SIZE / sizeof(u8),
  217. },
  218. .rf = {
  219. .read = rt2x00_rf_read,
  220. .write = rt61pci_rf_write,
  221. .word_size = sizeof(u32),
  222. .word_count = RF_SIZE / sizeof(u32),
  223. },
  224. };
  225. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  226. #ifdef CONFIG_RT61PCI_RFKILL
  227. static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  228. {
  229. u32 reg;
  230. rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
  231. return rt2x00_get_field32(reg, MAC_CSR13_BIT5);
  232. }
  233. #else
  234. #define rt61pci_rfkill_poll NULL
  235. #endif /* CONFIG_RT61PCI_RFKILL */
  236. #ifdef CONFIG_RT61PCI_LEDS
  237. static void rt61pci_brightness_set(struct led_classdev *led_cdev,
  238. enum led_brightness brightness)
  239. {
  240. struct rt2x00_led *led =
  241. container_of(led_cdev, struct rt2x00_led, led_dev);
  242. unsigned int enabled = brightness != LED_OFF;
  243. unsigned int a_mode =
  244. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  245. unsigned int bg_mode =
  246. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  247. if (led->type == LED_TYPE_RADIO) {
  248. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  249. MCU_LEDCS_RADIO_STATUS, enabled);
  250. rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
  251. (led->rt2x00dev->led_mcu_reg & 0xff),
  252. ((led->rt2x00dev->led_mcu_reg >> 8)));
  253. } else if (led->type == LED_TYPE_ASSOC) {
  254. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  255. MCU_LEDCS_LINK_BG_STATUS, bg_mode);
  256. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  257. MCU_LEDCS_LINK_A_STATUS, a_mode);
  258. rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
  259. (led->rt2x00dev->led_mcu_reg & 0xff),
  260. ((led->rt2x00dev->led_mcu_reg >> 8)));
  261. } else if (led->type == LED_TYPE_QUALITY) {
  262. /*
  263. * The brightness is divided into 6 levels (0 - 5),
  264. * this means we need to convert the brightness
  265. * argument into the matching level within that range.
  266. */
  267. rt61pci_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  268. brightness / (LED_FULL / 6), 0);
  269. }
  270. }
  271. static int rt61pci_blink_set(struct led_classdev *led_cdev,
  272. unsigned long *delay_on,
  273. unsigned long *delay_off)
  274. {
  275. struct rt2x00_led *led =
  276. container_of(led_cdev, struct rt2x00_led, led_dev);
  277. u32 reg;
  278. rt2x00pci_register_read(led->rt2x00dev, MAC_CSR14, &reg);
  279. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, *delay_on);
  280. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, *delay_off);
  281. rt2x00pci_register_write(led->rt2x00dev, MAC_CSR14, reg);
  282. return 0;
  283. }
  284. static void rt61pci_init_led(struct rt2x00_dev *rt2x00dev,
  285. struct rt2x00_led *led,
  286. enum led_type type)
  287. {
  288. led->rt2x00dev = rt2x00dev;
  289. led->type = type;
  290. led->led_dev.brightness_set = rt61pci_brightness_set;
  291. led->led_dev.blink_set = rt61pci_blink_set;
  292. led->flags = LED_INITIALIZED;
  293. }
  294. #endif /* CONFIG_RT61PCI_LEDS */
  295. /*
  296. * Configuration handlers.
  297. */
  298. static void rt61pci_config_filter(struct rt2x00_dev *rt2x00dev,
  299. const unsigned int filter_flags)
  300. {
  301. u32 reg;
  302. /*
  303. * Start configuration steps.
  304. * Note that the version error will always be dropped
  305. * and broadcast frames will always be accepted since
  306. * there is no filter for it at this time.
  307. */
  308. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  309. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  310. !(filter_flags & FIF_FCSFAIL));
  311. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  312. !(filter_flags & FIF_PLCPFAIL));
  313. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  314. !(filter_flags & FIF_CONTROL));
  315. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  316. !(filter_flags & FIF_PROMISC_IN_BSS));
  317. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  318. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  319. !rt2x00dev->intf_ap_count);
  320. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  321. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  322. !(filter_flags & FIF_ALLMULTI));
  323. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  324. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS,
  325. !(filter_flags & FIF_CONTROL));
  326. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  327. }
  328. static void rt61pci_config_intf(struct rt2x00_dev *rt2x00dev,
  329. struct rt2x00_intf *intf,
  330. struct rt2x00intf_conf *conf,
  331. const unsigned int flags)
  332. {
  333. unsigned int beacon_base;
  334. u32 reg;
  335. if (flags & CONFIG_UPDATE_TYPE) {
  336. /*
  337. * Clear current synchronisation setup.
  338. * For the Beacon base registers we only need to clear
  339. * the first byte since that byte contains the VALID and OWNER
  340. * bits which (when set to 0) will invalidate the entire beacon.
  341. */
  342. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  343. rt2x00pci_register_write(rt2x00dev, beacon_base, 0);
  344. /*
  345. * Enable synchronisation.
  346. */
  347. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  348. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  349. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  350. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  351. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  352. }
  353. if (flags & CONFIG_UPDATE_MAC) {
  354. reg = le32_to_cpu(conf->mac[1]);
  355. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  356. conf->mac[1] = cpu_to_le32(reg);
  357. rt2x00pci_register_multiwrite(rt2x00dev, MAC_CSR2,
  358. conf->mac, sizeof(conf->mac));
  359. }
  360. if (flags & CONFIG_UPDATE_BSSID) {
  361. reg = le32_to_cpu(conf->bssid[1]);
  362. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  363. conf->bssid[1] = cpu_to_le32(reg);
  364. rt2x00pci_register_multiwrite(rt2x00dev, MAC_CSR4,
  365. conf->bssid, sizeof(conf->bssid));
  366. }
  367. }
  368. static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev,
  369. struct rt2x00lib_erp *erp)
  370. {
  371. u32 reg;
  372. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  373. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, erp->ack_timeout);
  374. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  375. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  376. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  377. !!erp->short_preamble);
  378. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  379. }
  380. static void rt61pci_config_phymode(struct rt2x00_dev *rt2x00dev,
  381. const int basic_rate_mask)
  382. {
  383. rt2x00pci_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask);
  384. }
  385. static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
  386. struct rf_channel *rf, const int txpower)
  387. {
  388. u8 r3;
  389. u8 r94;
  390. u8 smart;
  391. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  392. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  393. smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  394. rt2x00_rf(&rt2x00dev->chip, RF2527));
  395. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  396. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  397. rt61pci_bbp_write(rt2x00dev, 3, r3);
  398. r94 = 6;
  399. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  400. r94 += txpower - MAX_TXPOWER;
  401. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  402. r94 += txpower;
  403. rt61pci_bbp_write(rt2x00dev, 94, r94);
  404. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  405. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  406. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  407. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  408. udelay(200);
  409. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  410. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  411. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  412. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  413. udelay(200);
  414. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  415. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  416. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  417. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  418. msleep(1);
  419. }
  420. static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
  421. const int txpower)
  422. {
  423. struct rf_channel rf;
  424. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  425. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  426. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  427. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  428. rt61pci_config_channel(rt2x00dev, &rf, txpower);
  429. }
  430. static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  431. struct antenna_setup *ant)
  432. {
  433. u8 r3;
  434. u8 r4;
  435. u8 r77;
  436. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  437. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  438. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  439. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE,
  440. rt2x00_rf(&rt2x00dev->chip, RF5325));
  441. /*
  442. * Configure the RX antenna.
  443. */
  444. switch (ant->rx) {
  445. case ANTENNA_HW_DIVERSITY:
  446. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  447. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  448. (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ));
  449. break;
  450. case ANTENNA_A:
  451. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  452. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  453. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  454. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  455. else
  456. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  457. break;
  458. case ANTENNA_B:
  459. default:
  460. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  461. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  462. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  463. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  464. else
  465. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  466. break;
  467. }
  468. rt61pci_bbp_write(rt2x00dev, 77, r77);
  469. rt61pci_bbp_write(rt2x00dev, 3, r3);
  470. rt61pci_bbp_write(rt2x00dev, 4, r4);
  471. }
  472. static void rt61pci_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  473. struct antenna_setup *ant)
  474. {
  475. u8 r3;
  476. u8 r4;
  477. u8 r77;
  478. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  479. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  480. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  481. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE,
  482. rt2x00_rf(&rt2x00dev->chip, RF2529));
  483. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  484. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  485. /*
  486. * Configure the RX antenna.
  487. */
  488. switch (ant->rx) {
  489. case ANTENNA_HW_DIVERSITY:
  490. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  491. break;
  492. case ANTENNA_A:
  493. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  494. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  495. break;
  496. case ANTENNA_B:
  497. default:
  498. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  499. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  500. break;
  501. }
  502. rt61pci_bbp_write(rt2x00dev, 77, r77);
  503. rt61pci_bbp_write(rt2x00dev, 3, r3);
  504. rt61pci_bbp_write(rt2x00dev, 4, r4);
  505. }
  506. static void rt61pci_config_antenna_2529_rx(struct rt2x00_dev *rt2x00dev,
  507. const int p1, const int p2)
  508. {
  509. u32 reg;
  510. rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
  511. rt2x00_set_field32(&reg, MAC_CSR13_BIT4, p1);
  512. rt2x00_set_field32(&reg, MAC_CSR13_BIT12, 0);
  513. rt2x00_set_field32(&reg, MAC_CSR13_BIT3, !p2);
  514. rt2x00_set_field32(&reg, MAC_CSR13_BIT11, 0);
  515. rt2x00pci_register_write(rt2x00dev, MAC_CSR13, reg);
  516. }
  517. static void rt61pci_config_antenna_2529(struct rt2x00_dev *rt2x00dev,
  518. struct antenna_setup *ant)
  519. {
  520. u8 r3;
  521. u8 r4;
  522. u8 r77;
  523. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  524. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  525. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  526. /*
  527. * Configure the RX antenna.
  528. */
  529. switch (ant->rx) {
  530. case ANTENNA_A:
  531. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  532. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  533. rt61pci_config_antenna_2529_rx(rt2x00dev, 0, 0);
  534. break;
  535. case ANTENNA_HW_DIVERSITY:
  536. /*
  537. * FIXME: Antenna selection for the rf 2529 is very confusing
  538. * in the legacy driver. Just default to antenna B until the
  539. * legacy code can be properly translated into rt2x00 code.
  540. */
  541. case ANTENNA_B:
  542. default:
  543. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  544. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  545. rt61pci_config_antenna_2529_rx(rt2x00dev, 1, 1);
  546. break;
  547. }
  548. rt61pci_bbp_write(rt2x00dev, 77, r77);
  549. rt61pci_bbp_write(rt2x00dev, 3, r3);
  550. rt61pci_bbp_write(rt2x00dev, 4, r4);
  551. }
  552. struct antenna_sel {
  553. u8 word;
  554. /*
  555. * value[0] -> non-LNA
  556. * value[1] -> LNA
  557. */
  558. u8 value[2];
  559. };
  560. static const struct antenna_sel antenna_sel_a[] = {
  561. { 96, { 0x58, 0x78 } },
  562. { 104, { 0x38, 0x48 } },
  563. { 75, { 0xfe, 0x80 } },
  564. { 86, { 0xfe, 0x80 } },
  565. { 88, { 0xfe, 0x80 } },
  566. { 35, { 0x60, 0x60 } },
  567. { 97, { 0x58, 0x58 } },
  568. { 98, { 0x58, 0x58 } },
  569. };
  570. static const struct antenna_sel antenna_sel_bg[] = {
  571. { 96, { 0x48, 0x68 } },
  572. { 104, { 0x2c, 0x3c } },
  573. { 75, { 0xfe, 0x80 } },
  574. { 86, { 0xfe, 0x80 } },
  575. { 88, { 0xfe, 0x80 } },
  576. { 35, { 0x50, 0x50 } },
  577. { 97, { 0x48, 0x48 } },
  578. { 98, { 0x48, 0x48 } },
  579. };
  580. static void rt61pci_config_antenna(struct rt2x00_dev *rt2x00dev,
  581. struct antenna_setup *ant)
  582. {
  583. const struct antenna_sel *sel;
  584. unsigned int lna;
  585. unsigned int i;
  586. u32 reg;
  587. /*
  588. * We should never come here because rt2x00lib is supposed
  589. * to catch this and send us the correct antenna explicitely.
  590. */
  591. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  592. ant->tx == ANTENNA_SW_DIVERSITY);
  593. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  594. sel = antenna_sel_a;
  595. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  596. } else {
  597. sel = antenna_sel_bg;
  598. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  599. }
  600. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  601. rt61pci_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  602. rt2x00pci_register_read(rt2x00dev, PHY_CSR0, &reg);
  603. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  604. rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  605. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  606. rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  607. rt2x00pci_register_write(rt2x00dev, PHY_CSR0, reg);
  608. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  609. rt2x00_rf(&rt2x00dev->chip, RF5325))
  610. rt61pci_config_antenna_5x(rt2x00dev, ant);
  611. else if (rt2x00_rf(&rt2x00dev->chip, RF2527))
  612. rt61pci_config_antenna_2x(rt2x00dev, ant);
  613. else if (rt2x00_rf(&rt2x00dev->chip, RF2529)) {
  614. if (test_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags))
  615. rt61pci_config_antenna_2x(rt2x00dev, ant);
  616. else
  617. rt61pci_config_antenna_2529(rt2x00dev, ant);
  618. }
  619. }
  620. static void rt61pci_config_duration(struct rt2x00_dev *rt2x00dev,
  621. struct rt2x00lib_conf *libconf)
  622. {
  623. u32 reg;
  624. rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg);
  625. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, libconf->slot_time);
  626. rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg);
  627. rt2x00pci_register_read(rt2x00dev, MAC_CSR8, &reg);
  628. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, libconf->sifs);
  629. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  630. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, libconf->eifs);
  631. rt2x00pci_register_write(rt2x00dev, MAC_CSR8, reg);
  632. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  633. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  634. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  635. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  636. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  637. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  638. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  639. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  640. libconf->conf->beacon_int * 16);
  641. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  642. }
  643. static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
  644. struct rt2x00lib_conf *libconf,
  645. const unsigned int flags)
  646. {
  647. if (flags & CONFIG_UPDATE_PHYMODE)
  648. rt61pci_config_phymode(rt2x00dev, libconf->basic_rates);
  649. if (flags & CONFIG_UPDATE_CHANNEL)
  650. rt61pci_config_channel(rt2x00dev, &libconf->rf,
  651. libconf->conf->power_level);
  652. if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
  653. rt61pci_config_txpower(rt2x00dev, libconf->conf->power_level);
  654. if (flags & CONFIG_UPDATE_ANTENNA)
  655. rt61pci_config_antenna(rt2x00dev, &libconf->ant);
  656. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  657. rt61pci_config_duration(rt2x00dev, libconf);
  658. }
  659. /*
  660. * Link tuning
  661. */
  662. static void rt61pci_link_stats(struct rt2x00_dev *rt2x00dev,
  663. struct link_qual *qual)
  664. {
  665. u32 reg;
  666. /*
  667. * Update FCS error count from register.
  668. */
  669. rt2x00pci_register_read(rt2x00dev, STA_CSR0, &reg);
  670. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  671. /*
  672. * Update False CCA count from register.
  673. */
  674. rt2x00pci_register_read(rt2x00dev, STA_CSR1, &reg);
  675. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  676. }
  677. static void rt61pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
  678. {
  679. rt61pci_bbp_write(rt2x00dev, 17, 0x20);
  680. rt2x00dev->link.vgc_level = 0x20;
  681. }
  682. static void rt61pci_link_tuner(struct rt2x00_dev *rt2x00dev)
  683. {
  684. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  685. u8 r17;
  686. u8 up_bound;
  687. u8 low_bound;
  688. rt61pci_bbp_read(rt2x00dev, 17, &r17);
  689. /*
  690. * Determine r17 bounds.
  691. */
  692. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  693. low_bound = 0x28;
  694. up_bound = 0x48;
  695. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  696. low_bound += 0x10;
  697. up_bound += 0x10;
  698. }
  699. } else {
  700. low_bound = 0x20;
  701. up_bound = 0x40;
  702. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  703. low_bound += 0x10;
  704. up_bound += 0x10;
  705. }
  706. }
  707. /*
  708. * If we are not associated, we should go straight to the
  709. * dynamic CCA tuning.
  710. */
  711. if (!rt2x00dev->intf_associated)
  712. goto dynamic_cca_tune;
  713. /*
  714. * Special big-R17 for very short distance
  715. */
  716. if (rssi >= -35) {
  717. if (r17 != 0x60)
  718. rt61pci_bbp_write(rt2x00dev, 17, 0x60);
  719. return;
  720. }
  721. /*
  722. * Special big-R17 for short distance
  723. */
  724. if (rssi >= -58) {
  725. if (r17 != up_bound)
  726. rt61pci_bbp_write(rt2x00dev, 17, up_bound);
  727. return;
  728. }
  729. /*
  730. * Special big-R17 for middle-short distance
  731. */
  732. if (rssi >= -66) {
  733. low_bound += 0x10;
  734. if (r17 != low_bound)
  735. rt61pci_bbp_write(rt2x00dev, 17, low_bound);
  736. return;
  737. }
  738. /*
  739. * Special mid-R17 for middle distance
  740. */
  741. if (rssi >= -74) {
  742. low_bound += 0x08;
  743. if (r17 != low_bound)
  744. rt61pci_bbp_write(rt2x00dev, 17, low_bound);
  745. return;
  746. }
  747. /*
  748. * Special case: Change up_bound based on the rssi.
  749. * Lower up_bound when rssi is weaker then -74 dBm.
  750. */
  751. up_bound -= 2 * (-74 - rssi);
  752. if (low_bound > up_bound)
  753. up_bound = low_bound;
  754. if (r17 > up_bound) {
  755. rt61pci_bbp_write(rt2x00dev, 17, up_bound);
  756. return;
  757. }
  758. dynamic_cca_tune:
  759. /*
  760. * r17 does not yet exceed upper limit, continue and base
  761. * the r17 tuning on the false CCA count.
  762. */
  763. if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  764. if (++r17 > up_bound)
  765. r17 = up_bound;
  766. rt61pci_bbp_write(rt2x00dev, 17, r17);
  767. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  768. if (--r17 < low_bound)
  769. r17 = low_bound;
  770. rt61pci_bbp_write(rt2x00dev, 17, r17);
  771. }
  772. }
  773. /*
  774. * Firmware functions
  775. */
  776. static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  777. {
  778. char *fw_name;
  779. switch (rt2x00dev->chip.rt) {
  780. case RT2561:
  781. fw_name = FIRMWARE_RT2561;
  782. break;
  783. case RT2561s:
  784. fw_name = FIRMWARE_RT2561s;
  785. break;
  786. case RT2661:
  787. fw_name = FIRMWARE_RT2661;
  788. break;
  789. default:
  790. fw_name = NULL;
  791. break;
  792. }
  793. return fw_name;
  794. }
  795. static u16 rt61pci_get_firmware_crc(const void *data, const size_t len)
  796. {
  797. u16 crc;
  798. /*
  799. * Use the crc itu-t algorithm.
  800. * The last 2 bytes in the firmware array are the crc checksum itself,
  801. * this means that we should never pass those 2 bytes to the crc
  802. * algorithm.
  803. */
  804. crc = crc_itu_t(0, data, len - 2);
  805. crc = crc_itu_t_byte(crc, 0);
  806. crc = crc_itu_t_byte(crc, 0);
  807. return crc;
  808. }
  809. static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data,
  810. const size_t len)
  811. {
  812. int i;
  813. u32 reg;
  814. /*
  815. * Wait for stable hardware.
  816. */
  817. for (i = 0; i < 100; i++) {
  818. rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
  819. if (reg)
  820. break;
  821. msleep(1);
  822. }
  823. if (!reg) {
  824. ERROR(rt2x00dev, "Unstable hardware.\n");
  825. return -EBUSY;
  826. }
  827. /*
  828. * Prepare MCU and mailbox for firmware loading.
  829. */
  830. reg = 0;
  831. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 1);
  832. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  833. rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff);
  834. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  835. rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, 0);
  836. /*
  837. * Write firmware to device.
  838. */
  839. reg = 0;
  840. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 1);
  841. rt2x00_set_field32(&reg, MCU_CNTL_CSR_SELECT_BANK, 1);
  842. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  843. rt2x00pci_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  844. data, len);
  845. rt2x00_set_field32(&reg, MCU_CNTL_CSR_SELECT_BANK, 0);
  846. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  847. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 0);
  848. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  849. for (i = 0; i < 100; i++) {
  850. rt2x00pci_register_read(rt2x00dev, MCU_CNTL_CSR, &reg);
  851. if (rt2x00_get_field32(reg, MCU_CNTL_CSR_READY))
  852. break;
  853. msleep(1);
  854. }
  855. if (i == 100) {
  856. ERROR(rt2x00dev, "MCU Control register not ready.\n");
  857. return -EBUSY;
  858. }
  859. /*
  860. * Hardware needs another millisecond before it is ready.
  861. */
  862. msleep(1);
  863. /*
  864. * Reset MAC and BBP registers.
  865. */
  866. reg = 0;
  867. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  868. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  869. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  870. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  871. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  872. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  873. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  874. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  875. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  876. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  877. return 0;
  878. }
  879. /*
  880. * Initialization functions.
  881. */
  882. static void rt61pci_init_rxentry(struct rt2x00_dev *rt2x00dev,
  883. struct queue_entry *entry)
  884. {
  885. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  886. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  887. u32 word;
  888. rt2x00_desc_read(entry_priv->desc, 5, &word);
  889. rt2x00_set_field32(&word, RXD_W5_BUFFER_PHYSICAL_ADDRESS,
  890. skbdesc->skb_dma);
  891. rt2x00_desc_write(entry_priv->desc, 5, word);
  892. rt2x00_desc_read(entry_priv->desc, 0, &word);
  893. rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1);
  894. rt2x00_desc_write(entry_priv->desc, 0, word);
  895. }
  896. static void rt61pci_init_txentry(struct rt2x00_dev *rt2x00dev,
  897. struct queue_entry *entry)
  898. {
  899. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  900. u32 word;
  901. rt2x00_desc_read(entry_priv->desc, 0, &word);
  902. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  903. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0);
  904. rt2x00_desc_write(entry_priv->desc, 0, word);
  905. }
  906. static int rt61pci_init_queues(struct rt2x00_dev *rt2x00dev)
  907. {
  908. struct queue_entry_priv_pci *entry_priv;
  909. u32 reg;
  910. /*
  911. * Initialize registers.
  912. */
  913. rt2x00pci_register_read(rt2x00dev, TX_RING_CSR0, &reg);
  914. rt2x00_set_field32(&reg, TX_RING_CSR0_AC0_RING_SIZE,
  915. rt2x00dev->tx[0].limit);
  916. rt2x00_set_field32(&reg, TX_RING_CSR0_AC1_RING_SIZE,
  917. rt2x00dev->tx[1].limit);
  918. rt2x00_set_field32(&reg, TX_RING_CSR0_AC2_RING_SIZE,
  919. rt2x00dev->tx[2].limit);
  920. rt2x00_set_field32(&reg, TX_RING_CSR0_AC3_RING_SIZE,
  921. rt2x00dev->tx[3].limit);
  922. rt2x00pci_register_write(rt2x00dev, TX_RING_CSR0, reg);
  923. rt2x00pci_register_read(rt2x00dev, TX_RING_CSR1, &reg);
  924. rt2x00_set_field32(&reg, TX_RING_CSR1_TXD_SIZE,
  925. rt2x00dev->tx[0].desc_size / 4);
  926. rt2x00pci_register_write(rt2x00dev, TX_RING_CSR1, reg);
  927. entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
  928. rt2x00pci_register_read(rt2x00dev, AC0_BASE_CSR, &reg);
  929. rt2x00_set_field32(&reg, AC0_BASE_CSR_RING_REGISTER,
  930. entry_priv->desc_dma);
  931. rt2x00pci_register_write(rt2x00dev, AC0_BASE_CSR, reg);
  932. entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
  933. rt2x00pci_register_read(rt2x00dev, AC1_BASE_CSR, &reg);
  934. rt2x00_set_field32(&reg, AC1_BASE_CSR_RING_REGISTER,
  935. entry_priv->desc_dma);
  936. rt2x00pci_register_write(rt2x00dev, AC1_BASE_CSR, reg);
  937. entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
  938. rt2x00pci_register_read(rt2x00dev, AC2_BASE_CSR, &reg);
  939. rt2x00_set_field32(&reg, AC2_BASE_CSR_RING_REGISTER,
  940. entry_priv->desc_dma);
  941. rt2x00pci_register_write(rt2x00dev, AC2_BASE_CSR, reg);
  942. entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
  943. rt2x00pci_register_read(rt2x00dev, AC3_BASE_CSR, &reg);
  944. rt2x00_set_field32(&reg, AC3_BASE_CSR_RING_REGISTER,
  945. entry_priv->desc_dma);
  946. rt2x00pci_register_write(rt2x00dev, AC3_BASE_CSR, reg);
  947. rt2x00pci_register_read(rt2x00dev, RX_RING_CSR, &reg);
  948. rt2x00_set_field32(&reg, RX_RING_CSR_RING_SIZE, rt2x00dev->rx->limit);
  949. rt2x00_set_field32(&reg, RX_RING_CSR_RXD_SIZE,
  950. rt2x00dev->rx->desc_size / 4);
  951. rt2x00_set_field32(&reg, RX_RING_CSR_RXD_WRITEBACK_SIZE, 4);
  952. rt2x00pci_register_write(rt2x00dev, RX_RING_CSR, reg);
  953. entry_priv = rt2x00dev->rx->entries[0].priv_data;
  954. rt2x00pci_register_read(rt2x00dev, RX_BASE_CSR, &reg);
  955. rt2x00_set_field32(&reg, RX_BASE_CSR_RING_REGISTER,
  956. entry_priv->desc_dma);
  957. rt2x00pci_register_write(rt2x00dev, RX_BASE_CSR, reg);
  958. rt2x00pci_register_read(rt2x00dev, TX_DMA_DST_CSR, &reg);
  959. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC0, 2);
  960. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC1, 2);
  961. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC2, 2);
  962. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC3, 2);
  963. rt2x00pci_register_write(rt2x00dev, TX_DMA_DST_CSR, reg);
  964. rt2x00pci_register_read(rt2x00dev, LOAD_TX_RING_CSR, &reg);
  965. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC0, 1);
  966. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC1, 1);
  967. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC2, 1);
  968. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC3, 1);
  969. rt2x00pci_register_write(rt2x00dev, LOAD_TX_RING_CSR, reg);
  970. rt2x00pci_register_read(rt2x00dev, RX_CNTL_CSR, &reg);
  971. rt2x00_set_field32(&reg, RX_CNTL_CSR_LOAD_RXD, 1);
  972. rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg);
  973. return 0;
  974. }
  975. static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev)
  976. {
  977. u32 reg;
  978. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  979. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  980. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  981. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  982. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  983. rt2x00pci_register_read(rt2x00dev, TXRX_CSR1, &reg);
  984. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  985. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  986. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  987. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  988. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  989. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  990. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  991. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  992. rt2x00pci_register_write(rt2x00dev, TXRX_CSR1, reg);
  993. /*
  994. * CCK TXD BBP registers
  995. */
  996. rt2x00pci_register_read(rt2x00dev, TXRX_CSR2, &reg);
  997. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  998. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  999. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  1000. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  1001. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  1002. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  1003. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  1004. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  1005. rt2x00pci_register_write(rt2x00dev, TXRX_CSR2, reg);
  1006. /*
  1007. * OFDM TXD BBP registers
  1008. */
  1009. rt2x00pci_register_read(rt2x00dev, TXRX_CSR3, &reg);
  1010. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  1011. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  1012. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  1013. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  1014. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  1015. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  1016. rt2x00pci_register_write(rt2x00dev, TXRX_CSR3, reg);
  1017. rt2x00pci_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1018. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1019. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1020. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1021. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1022. rt2x00pci_register_write(rt2x00dev, TXRX_CSR7, reg);
  1023. rt2x00pci_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1024. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1025. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1026. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1027. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1028. rt2x00pci_register_write(rt2x00dev, TXRX_CSR8, reg);
  1029. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1030. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1031. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1032. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1033. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1034. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1035. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1036. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1037. rt2x00pci_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1038. rt2x00pci_register_write(rt2x00dev, MAC_CSR6, 0x00000fff);
  1039. rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg);
  1040. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1041. rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg);
  1042. rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x0000071c);
  1043. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1044. return -EBUSY;
  1045. rt2x00pci_register_write(rt2x00dev, MAC_CSR13, 0x0000e000);
  1046. /*
  1047. * Invalidate all Shared Keys (SEC_CSR0),
  1048. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1049. */
  1050. rt2x00pci_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1051. rt2x00pci_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1052. rt2x00pci_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1053. rt2x00pci_register_write(rt2x00dev, PHY_CSR1, 0x000023b0);
  1054. rt2x00pci_register_write(rt2x00dev, PHY_CSR5, 0x060a100c);
  1055. rt2x00pci_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1056. rt2x00pci_register_write(rt2x00dev, PHY_CSR7, 0x00000a08);
  1057. rt2x00pci_register_write(rt2x00dev, PCI_CFG_CSR, 0x28ca4404);
  1058. rt2x00pci_register_write(rt2x00dev, TEST_MODE_CSR, 0x00000200);
  1059. rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff);
  1060. rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
  1061. rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC0_TX_OP, 0);
  1062. rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC1_TX_OP, 0);
  1063. rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
  1064. rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
  1065. rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC2_TX_OP, 192);
  1066. rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC3_TX_OP, 48);
  1067. rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
  1068. /*
  1069. * Clear all beacons
  1070. * For the Beacon base registers we only need to clear
  1071. * the first byte since that byte contains the VALID and OWNER
  1072. * bits which (when set to 0) will invalidate the entire beacon.
  1073. */
  1074. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1075. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1076. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1077. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1078. /*
  1079. * We must clear the error counters.
  1080. * These registers are cleared on read,
  1081. * so we may pass a useless variable to store the value.
  1082. */
  1083. rt2x00pci_register_read(rt2x00dev, STA_CSR0, &reg);
  1084. rt2x00pci_register_read(rt2x00dev, STA_CSR1, &reg);
  1085. rt2x00pci_register_read(rt2x00dev, STA_CSR2, &reg);
  1086. /*
  1087. * Reset MAC and BBP registers.
  1088. */
  1089. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1090. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1091. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1092. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1093. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1094. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1095. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1096. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1097. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1098. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1099. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1100. return 0;
  1101. }
  1102. static int rt61pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1103. {
  1104. unsigned int i;
  1105. u8 value;
  1106. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1107. rt61pci_bbp_read(rt2x00dev, 0, &value);
  1108. if ((value != 0xff) && (value != 0x00))
  1109. return 0;
  1110. udelay(REGISTER_BUSY_DELAY);
  1111. }
  1112. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1113. return -EACCES;
  1114. }
  1115. static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev)
  1116. {
  1117. unsigned int i;
  1118. u16 eeprom;
  1119. u8 reg_id;
  1120. u8 value;
  1121. if (unlikely(rt61pci_wait_bbp_ready(rt2x00dev)))
  1122. return -EACCES;
  1123. rt61pci_bbp_write(rt2x00dev, 3, 0x00);
  1124. rt61pci_bbp_write(rt2x00dev, 15, 0x30);
  1125. rt61pci_bbp_write(rt2x00dev, 21, 0xc8);
  1126. rt61pci_bbp_write(rt2x00dev, 22, 0x38);
  1127. rt61pci_bbp_write(rt2x00dev, 23, 0x06);
  1128. rt61pci_bbp_write(rt2x00dev, 24, 0xfe);
  1129. rt61pci_bbp_write(rt2x00dev, 25, 0x0a);
  1130. rt61pci_bbp_write(rt2x00dev, 26, 0x0d);
  1131. rt61pci_bbp_write(rt2x00dev, 34, 0x12);
  1132. rt61pci_bbp_write(rt2x00dev, 37, 0x07);
  1133. rt61pci_bbp_write(rt2x00dev, 39, 0xf8);
  1134. rt61pci_bbp_write(rt2x00dev, 41, 0x60);
  1135. rt61pci_bbp_write(rt2x00dev, 53, 0x10);
  1136. rt61pci_bbp_write(rt2x00dev, 54, 0x18);
  1137. rt61pci_bbp_write(rt2x00dev, 60, 0x10);
  1138. rt61pci_bbp_write(rt2x00dev, 61, 0x04);
  1139. rt61pci_bbp_write(rt2x00dev, 62, 0x04);
  1140. rt61pci_bbp_write(rt2x00dev, 75, 0xfe);
  1141. rt61pci_bbp_write(rt2x00dev, 86, 0xfe);
  1142. rt61pci_bbp_write(rt2x00dev, 88, 0xfe);
  1143. rt61pci_bbp_write(rt2x00dev, 90, 0x0f);
  1144. rt61pci_bbp_write(rt2x00dev, 99, 0x00);
  1145. rt61pci_bbp_write(rt2x00dev, 102, 0x16);
  1146. rt61pci_bbp_write(rt2x00dev, 107, 0x04);
  1147. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1148. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1149. if (eeprom != 0xffff && eeprom != 0x0000) {
  1150. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1151. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1152. rt61pci_bbp_write(rt2x00dev, reg_id, value);
  1153. }
  1154. }
  1155. return 0;
  1156. }
  1157. /*
  1158. * Device state switch handlers.
  1159. */
  1160. static void rt61pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1161. enum dev_state state)
  1162. {
  1163. u32 reg;
  1164. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1165. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  1166. (state == STATE_RADIO_RX_OFF) ||
  1167. (state == STATE_RADIO_RX_OFF_LINK));
  1168. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  1169. }
  1170. static void rt61pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  1171. enum dev_state state)
  1172. {
  1173. int mask = (state == STATE_RADIO_IRQ_OFF);
  1174. u32 reg;
  1175. /*
  1176. * When interrupts are being enabled, the interrupt registers
  1177. * should clear the register to assure a clean state.
  1178. */
  1179. if (state == STATE_RADIO_IRQ_ON) {
  1180. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  1181. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  1182. rt2x00pci_register_read(rt2x00dev, MCU_INT_SOURCE_CSR, &reg);
  1183. rt2x00pci_register_write(rt2x00dev, MCU_INT_SOURCE_CSR, reg);
  1184. }
  1185. /*
  1186. * Only toggle the interrupts bits we are going to use.
  1187. * Non-checked interrupt bits are disabled by default.
  1188. */
  1189. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  1190. rt2x00_set_field32(&reg, INT_MASK_CSR_TXDONE, mask);
  1191. rt2x00_set_field32(&reg, INT_MASK_CSR_RXDONE, mask);
  1192. rt2x00_set_field32(&reg, INT_MASK_CSR_ENABLE_MITIGATION, mask);
  1193. rt2x00_set_field32(&reg, INT_MASK_CSR_MITIGATION_PERIOD, 0xff);
  1194. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  1195. rt2x00pci_register_read(rt2x00dev, MCU_INT_MASK_CSR, &reg);
  1196. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_0, mask);
  1197. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_1, mask);
  1198. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_2, mask);
  1199. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_3, mask);
  1200. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_4, mask);
  1201. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_5, mask);
  1202. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_6, mask);
  1203. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_7, mask);
  1204. rt2x00pci_register_write(rt2x00dev, MCU_INT_MASK_CSR, reg);
  1205. }
  1206. static int rt61pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  1207. {
  1208. u32 reg;
  1209. /*
  1210. * Initialize all registers.
  1211. */
  1212. if (unlikely(rt61pci_init_queues(rt2x00dev) ||
  1213. rt61pci_init_registers(rt2x00dev) ||
  1214. rt61pci_init_bbp(rt2x00dev)))
  1215. return -EIO;
  1216. /*
  1217. * Enable RX.
  1218. */
  1219. rt2x00pci_register_read(rt2x00dev, RX_CNTL_CSR, &reg);
  1220. rt2x00_set_field32(&reg, RX_CNTL_CSR_ENABLE_RX_DMA, 1);
  1221. rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg);
  1222. return 0;
  1223. }
  1224. static void rt61pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  1225. {
  1226. u32 reg;
  1227. rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1228. /*
  1229. * Disable synchronisation.
  1230. */
  1231. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, 0);
  1232. /*
  1233. * Cancel RX and TX.
  1234. */
  1235. rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg);
  1236. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC0, 1);
  1237. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC1, 1);
  1238. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC2, 1);
  1239. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC3, 1);
  1240. rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
  1241. }
  1242. static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1243. {
  1244. u32 reg;
  1245. unsigned int i;
  1246. char put_to_sleep;
  1247. put_to_sleep = (state != STATE_AWAKE);
  1248. rt2x00pci_register_read(rt2x00dev, MAC_CSR12, &reg);
  1249. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1250. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1251. rt2x00pci_register_write(rt2x00dev, MAC_CSR12, reg);
  1252. /*
  1253. * Device is not guaranteed to be in the requested state yet.
  1254. * We must wait until the register indicates that the
  1255. * device has entered the correct state.
  1256. */
  1257. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1258. rt2x00pci_register_read(rt2x00dev, MAC_CSR12, &reg);
  1259. state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
  1260. if (state == !put_to_sleep)
  1261. return 0;
  1262. msleep(10);
  1263. }
  1264. return -EBUSY;
  1265. }
  1266. static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  1267. enum dev_state state)
  1268. {
  1269. int retval = 0;
  1270. switch (state) {
  1271. case STATE_RADIO_ON:
  1272. retval = rt61pci_enable_radio(rt2x00dev);
  1273. break;
  1274. case STATE_RADIO_OFF:
  1275. rt61pci_disable_radio(rt2x00dev);
  1276. break;
  1277. case STATE_RADIO_RX_ON:
  1278. case STATE_RADIO_RX_ON_LINK:
  1279. case STATE_RADIO_RX_OFF:
  1280. case STATE_RADIO_RX_OFF_LINK:
  1281. rt61pci_toggle_rx(rt2x00dev, state);
  1282. break;
  1283. case STATE_RADIO_IRQ_ON:
  1284. case STATE_RADIO_IRQ_OFF:
  1285. rt61pci_toggle_irq(rt2x00dev, state);
  1286. break;
  1287. case STATE_DEEP_SLEEP:
  1288. case STATE_SLEEP:
  1289. case STATE_STANDBY:
  1290. case STATE_AWAKE:
  1291. retval = rt61pci_set_state(rt2x00dev, state);
  1292. break;
  1293. default:
  1294. retval = -ENOTSUPP;
  1295. break;
  1296. }
  1297. if (unlikely(retval))
  1298. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1299. state, retval);
  1300. return retval;
  1301. }
  1302. /*
  1303. * TX descriptor initialization
  1304. */
  1305. static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1306. struct sk_buff *skb,
  1307. struct txentry_desc *txdesc)
  1308. {
  1309. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1310. __le32 *txd = skbdesc->desc;
  1311. u32 word;
  1312. /*
  1313. * Start writing the descriptor words.
  1314. */
  1315. rt2x00_desc_read(txd, 1, &word);
  1316. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, txdesc->queue);
  1317. rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
  1318. rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
  1319. rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
  1320. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER);
  1321. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1322. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1323. rt2x00_set_field32(&word, TXD_W1_BUFFER_COUNT, 1);
  1324. rt2x00_desc_write(txd, 1, word);
  1325. rt2x00_desc_read(txd, 2, &word);
  1326. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  1327. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  1328. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  1329. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  1330. rt2x00_desc_write(txd, 2, word);
  1331. rt2x00_desc_read(txd, 5, &word);
  1332. rt2x00_set_field32(&word, TXD_W5_PID_TYPE, skbdesc->entry->queue->qid);
  1333. rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE,
  1334. skbdesc->entry->entry_idx);
  1335. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1336. TXPOWER_TO_DEV(rt2x00dev->tx_power));
  1337. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1338. rt2x00_desc_write(txd, 5, word);
  1339. rt2x00_desc_read(txd, 6, &word);
  1340. rt2x00_set_field32(&word, TXD_W6_BUFFER_PHYSICAL_ADDRESS,
  1341. skbdesc->skb_dma);
  1342. rt2x00_desc_write(txd, 6, word);
  1343. if (skbdesc->desc_len > TXINFO_SIZE) {
  1344. rt2x00_desc_read(txd, 11, &word);
  1345. rt2x00_set_field32(&word, TXD_W11_BUFFER_LENGTH0, skb->len);
  1346. rt2x00_desc_write(txd, 11, word);
  1347. }
  1348. rt2x00_desc_read(txd, 0, &word);
  1349. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1);
  1350. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1351. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1352. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1353. rt2x00_set_field32(&word, TXD_W0_ACK,
  1354. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1355. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1356. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1357. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1358. test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags));
  1359. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1360. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1361. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1362. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, 0);
  1363. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
  1364. rt2x00_set_field32(&word, TXD_W0_BURST,
  1365. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1366. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, CIPHER_NONE);
  1367. rt2x00_desc_write(txd, 0, word);
  1368. }
  1369. /*
  1370. * TX data initialization
  1371. */
  1372. static void rt61pci_write_beacon(struct queue_entry *entry)
  1373. {
  1374. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1375. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1376. unsigned int beacon_base;
  1377. u32 reg;
  1378. /*
  1379. * Disable beaconing while we are reloading the beacon data,
  1380. * otherwise we might be sending out invalid data.
  1381. */
  1382. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1383. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1384. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1385. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1386. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1387. /*
  1388. * Write entire beacon with descriptor to register.
  1389. */
  1390. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1391. rt2x00pci_register_multiwrite(rt2x00dev,
  1392. beacon_base,
  1393. skbdesc->desc, skbdesc->desc_len);
  1394. rt2x00pci_register_multiwrite(rt2x00dev,
  1395. beacon_base + skbdesc->desc_len,
  1396. entry->skb->data, entry->skb->len);
  1397. /*
  1398. * Clean up beacon skb.
  1399. */
  1400. dev_kfree_skb_any(entry->skb);
  1401. entry->skb = NULL;
  1402. }
  1403. static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1404. const enum data_queue_qid queue)
  1405. {
  1406. u32 reg;
  1407. if (queue == QID_BEACON) {
  1408. /*
  1409. * For Wi-Fi faily generated beacons between participating
  1410. * stations. Set TBTT phase adaptive adjustment step to 8us.
  1411. */
  1412. rt2x00pci_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1413. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1414. if (!rt2x00_get_field32(reg, TXRX_CSR9_BEACON_GEN)) {
  1415. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  1416. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  1417. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1418. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1419. }
  1420. return;
  1421. }
  1422. rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg);
  1423. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC0, (queue == QID_AC_BE));
  1424. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC1, (queue == QID_AC_BK));
  1425. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC2, (queue == QID_AC_VI));
  1426. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC3, (queue == QID_AC_VO));
  1427. rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
  1428. }
  1429. /*
  1430. * RX control handlers
  1431. */
  1432. static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1433. {
  1434. u16 eeprom;
  1435. u8 offset;
  1436. u8 lna;
  1437. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1438. switch (lna) {
  1439. case 3:
  1440. offset = 90;
  1441. break;
  1442. case 2:
  1443. offset = 74;
  1444. break;
  1445. case 1:
  1446. offset = 64;
  1447. break;
  1448. default:
  1449. return 0;
  1450. }
  1451. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  1452. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
  1453. offset += 14;
  1454. if (lna == 3 || lna == 2)
  1455. offset += 10;
  1456. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  1457. offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  1458. } else {
  1459. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  1460. offset += 14;
  1461. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  1462. offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  1463. }
  1464. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1465. }
  1466. static void rt61pci_fill_rxdone(struct queue_entry *entry,
  1467. struct rxdone_entry_desc *rxdesc)
  1468. {
  1469. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  1470. u32 word0;
  1471. u32 word1;
  1472. rt2x00_desc_read(entry_priv->desc, 0, &word0);
  1473. rt2x00_desc_read(entry_priv->desc, 1, &word1);
  1474. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1475. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1476. /*
  1477. * Obtain the status about this packet.
  1478. * When frame was received with an OFDM bitrate,
  1479. * the signal is the PLCP value. If it was received with
  1480. * a CCK bitrate the signal is the rate in 100kbit/s.
  1481. */
  1482. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1483. rxdesc->rssi = rt61pci_agc_to_rssi(entry->queue->rt2x00dev, word1);
  1484. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1485. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1486. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1487. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1488. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1489. }
  1490. /*
  1491. * Interrupt functions.
  1492. */
  1493. static void rt61pci_txdone(struct rt2x00_dev *rt2x00dev)
  1494. {
  1495. struct data_queue *queue;
  1496. struct queue_entry *entry;
  1497. struct queue_entry *entry_done;
  1498. struct queue_entry_priv_pci *entry_priv;
  1499. struct txdone_entry_desc txdesc;
  1500. u32 word;
  1501. u32 reg;
  1502. u32 old_reg;
  1503. int type;
  1504. int index;
  1505. /*
  1506. * During each loop we will compare the freshly read
  1507. * STA_CSR4 register value with the value read from
  1508. * the previous loop. If the 2 values are equal then
  1509. * we should stop processing because the chance it
  1510. * quite big that the device has been unplugged and
  1511. * we risk going into an endless loop.
  1512. */
  1513. old_reg = 0;
  1514. while (1) {
  1515. rt2x00pci_register_read(rt2x00dev, STA_CSR4, &reg);
  1516. if (!rt2x00_get_field32(reg, STA_CSR4_VALID))
  1517. break;
  1518. if (old_reg == reg)
  1519. break;
  1520. old_reg = reg;
  1521. /*
  1522. * Skip this entry when it contains an invalid
  1523. * queue identication number.
  1524. */
  1525. type = rt2x00_get_field32(reg, STA_CSR4_PID_TYPE);
  1526. queue = rt2x00queue_get_queue(rt2x00dev, type);
  1527. if (unlikely(!queue))
  1528. continue;
  1529. /*
  1530. * Skip this entry when it contains an invalid
  1531. * index number.
  1532. */
  1533. index = rt2x00_get_field32(reg, STA_CSR4_PID_SUBTYPE);
  1534. if (unlikely(index >= queue->limit))
  1535. continue;
  1536. entry = &queue->entries[index];
  1537. entry_priv = entry->priv_data;
  1538. rt2x00_desc_read(entry_priv->desc, 0, &word);
  1539. if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) ||
  1540. !rt2x00_get_field32(word, TXD_W0_VALID))
  1541. return;
  1542. entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  1543. while (entry != entry_done) {
  1544. /* Catch up.
  1545. * Just report any entries we missed as failed.
  1546. */
  1547. WARNING(rt2x00dev,
  1548. "TX status report missed for entry %d\n",
  1549. entry_done->entry_idx);
  1550. txdesc.flags = 0;
  1551. __set_bit(TXDONE_UNKNOWN, &txdesc.flags);
  1552. txdesc.retry = 0;
  1553. rt2x00lib_txdone(entry_done, &txdesc);
  1554. entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  1555. }
  1556. /*
  1557. * Obtain the status about this packet.
  1558. */
  1559. txdesc.flags = 0;
  1560. switch (rt2x00_get_field32(reg, STA_CSR4_TX_RESULT)) {
  1561. case 0: /* Success, maybe with retry */
  1562. __set_bit(TXDONE_SUCCESS, &txdesc.flags);
  1563. break;
  1564. case 6: /* Failure, excessive retries */
  1565. __set_bit(TXDONE_EXCESSIVE_RETRY, &txdesc.flags);
  1566. /* Don't break, this is a failed frame! */
  1567. default: /* Failure */
  1568. __set_bit(TXDONE_FAILURE, &txdesc.flags);
  1569. }
  1570. txdesc.retry = rt2x00_get_field32(reg, STA_CSR4_RETRY_COUNT);
  1571. rt2x00lib_txdone(entry, &txdesc);
  1572. }
  1573. }
  1574. static irqreturn_t rt61pci_interrupt(int irq, void *dev_instance)
  1575. {
  1576. struct rt2x00_dev *rt2x00dev = dev_instance;
  1577. u32 reg_mcu;
  1578. u32 reg;
  1579. /*
  1580. * Get the interrupt sources & saved to local variable.
  1581. * Write register value back to clear pending interrupts.
  1582. */
  1583. rt2x00pci_register_read(rt2x00dev, MCU_INT_SOURCE_CSR, &reg_mcu);
  1584. rt2x00pci_register_write(rt2x00dev, MCU_INT_SOURCE_CSR, reg_mcu);
  1585. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  1586. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  1587. if (!reg && !reg_mcu)
  1588. return IRQ_NONE;
  1589. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  1590. return IRQ_HANDLED;
  1591. /*
  1592. * Handle interrupts, walk through all bits
  1593. * and run the tasks, the bits are checked in order of
  1594. * priority.
  1595. */
  1596. /*
  1597. * 1 - Rx ring done interrupt.
  1598. */
  1599. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RXDONE))
  1600. rt2x00pci_rxdone(rt2x00dev);
  1601. /*
  1602. * 2 - Tx ring done interrupt.
  1603. */
  1604. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TXDONE))
  1605. rt61pci_txdone(rt2x00dev);
  1606. /*
  1607. * 3 - Handle MCU command done.
  1608. */
  1609. if (reg_mcu)
  1610. rt2x00pci_register_write(rt2x00dev,
  1611. M2H_CMD_DONE_CSR, 0xffffffff);
  1612. return IRQ_HANDLED;
  1613. }
  1614. /*
  1615. * Device probe functions.
  1616. */
  1617. static int rt61pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1618. {
  1619. struct eeprom_93cx6 eeprom;
  1620. u32 reg;
  1621. u16 word;
  1622. u8 *mac;
  1623. s8 value;
  1624. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  1625. eeprom.data = rt2x00dev;
  1626. eeprom.register_read = rt61pci_eepromregister_read;
  1627. eeprom.register_write = rt61pci_eepromregister_write;
  1628. eeprom.width = rt2x00_get_field32(reg, E2PROM_CSR_TYPE_93C46) ?
  1629. PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
  1630. eeprom.reg_data_in = 0;
  1631. eeprom.reg_data_out = 0;
  1632. eeprom.reg_data_clock = 0;
  1633. eeprom.reg_chip_select = 0;
  1634. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  1635. EEPROM_SIZE / sizeof(u16));
  1636. /*
  1637. * Start validation of the data that has been read.
  1638. */
  1639. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1640. if (!is_valid_ether_addr(mac)) {
  1641. DECLARE_MAC_BUF(macbuf);
  1642. random_ether_addr(mac);
  1643. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1644. }
  1645. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1646. if (word == 0xffff) {
  1647. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1648. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1649. ANTENNA_B);
  1650. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1651. ANTENNA_B);
  1652. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1653. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1654. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1655. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5225);
  1656. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1657. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1658. }
  1659. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1660. if (word == 0xffff) {
  1661. rt2x00_set_field16(&word, EEPROM_NIC_ENABLE_DIVERSITY, 0);
  1662. rt2x00_set_field16(&word, EEPROM_NIC_TX_DIVERSITY, 0);
  1663. rt2x00_set_field16(&word, EEPROM_NIC_TX_RX_FIXED, 0);
  1664. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1665. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1666. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1667. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1668. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1669. }
  1670. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1671. if (word == 0xffff) {
  1672. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1673. LED_MODE_DEFAULT);
  1674. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1675. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1676. }
  1677. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1678. if (word == 0xffff) {
  1679. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1680. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1681. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1682. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1683. }
  1684. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1685. if (word == 0xffff) {
  1686. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1687. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1688. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1689. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1690. } else {
  1691. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1692. if (value < -10 || value > 10)
  1693. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1694. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1695. if (value < -10 || value > 10)
  1696. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1697. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1698. }
  1699. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1700. if (word == 0xffff) {
  1701. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1702. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1703. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1704. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1705. } else {
  1706. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1707. if (value < -10 || value > 10)
  1708. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1709. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1710. if (value < -10 || value > 10)
  1711. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1712. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1713. }
  1714. return 0;
  1715. }
  1716. static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1717. {
  1718. u32 reg;
  1719. u16 value;
  1720. u16 eeprom;
  1721. u16 device;
  1722. /*
  1723. * Read EEPROM word for configuration.
  1724. */
  1725. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1726. /*
  1727. * Identify RF chipset.
  1728. * To determine the RT chip we have to read the
  1729. * PCI header of the device.
  1730. */
  1731. pci_read_config_word(to_pci_dev(rt2x00dev->dev),
  1732. PCI_CONFIG_HEADER_DEVICE, &device);
  1733. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1734. rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
  1735. rt2x00_set_chip(rt2x00dev, device, value, reg);
  1736. if (!rt2x00_rf(&rt2x00dev->chip, RF5225) &&
  1737. !rt2x00_rf(&rt2x00dev->chip, RF5325) &&
  1738. !rt2x00_rf(&rt2x00dev->chip, RF2527) &&
  1739. !rt2x00_rf(&rt2x00dev->chip, RF2529)) {
  1740. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1741. return -ENODEV;
  1742. }
  1743. /*
  1744. * Determine number of antenna's.
  1745. */
  1746. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_NUM) == 2)
  1747. __set_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags);
  1748. /*
  1749. * Identify default antenna configuration.
  1750. */
  1751. rt2x00dev->default_ant.tx =
  1752. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1753. rt2x00dev->default_ant.rx =
  1754. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1755. /*
  1756. * Read the Frame type.
  1757. */
  1758. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1759. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1760. /*
  1761. * Detect if this device has an hardware controlled radio.
  1762. */
  1763. #ifdef CONFIG_RT61PCI_RFKILL
  1764. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1765. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1766. #endif /* CONFIG_RT61PCI_RFKILL */
  1767. /*
  1768. * Read frequency offset and RF programming sequence.
  1769. */
  1770. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1771. if (rt2x00_get_field16(eeprom, EEPROM_FREQ_SEQ))
  1772. __set_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags);
  1773. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1774. /*
  1775. * Read external LNA informations.
  1776. */
  1777. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1778. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  1779. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1780. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  1781. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1782. /*
  1783. * When working with a RF2529 chip without double antenna
  1784. * the antenna settings should be gathered from the NIC
  1785. * eeprom word.
  1786. */
  1787. if (rt2x00_rf(&rt2x00dev->chip, RF2529) &&
  1788. !test_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags)) {
  1789. switch (rt2x00_get_field16(eeprom, EEPROM_NIC_TX_RX_FIXED)) {
  1790. case 0:
  1791. rt2x00dev->default_ant.tx = ANTENNA_B;
  1792. rt2x00dev->default_ant.rx = ANTENNA_A;
  1793. break;
  1794. case 1:
  1795. rt2x00dev->default_ant.tx = ANTENNA_B;
  1796. rt2x00dev->default_ant.rx = ANTENNA_B;
  1797. break;
  1798. case 2:
  1799. rt2x00dev->default_ant.tx = ANTENNA_A;
  1800. rt2x00dev->default_ant.rx = ANTENNA_A;
  1801. break;
  1802. case 3:
  1803. rt2x00dev->default_ant.tx = ANTENNA_A;
  1804. rt2x00dev->default_ant.rx = ANTENNA_B;
  1805. break;
  1806. }
  1807. if (rt2x00_get_field16(eeprom, EEPROM_NIC_TX_DIVERSITY))
  1808. rt2x00dev->default_ant.tx = ANTENNA_SW_DIVERSITY;
  1809. if (rt2x00_get_field16(eeprom, EEPROM_NIC_ENABLE_DIVERSITY))
  1810. rt2x00dev->default_ant.rx = ANTENNA_SW_DIVERSITY;
  1811. }
  1812. /*
  1813. * Store led settings, for correct led behaviour.
  1814. * If the eeprom value is invalid,
  1815. * switch to default led mode.
  1816. */
  1817. #ifdef CONFIG_RT61PCI_LEDS
  1818. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1819. value = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE);
  1820. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1821. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1822. if (value == LED_MODE_SIGNAL_STRENGTH)
  1823. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1824. LED_TYPE_QUALITY);
  1825. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  1826. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1827. rt2x00_get_field16(eeprom,
  1828. EEPROM_LED_POLARITY_GPIO_0));
  1829. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1830. rt2x00_get_field16(eeprom,
  1831. EEPROM_LED_POLARITY_GPIO_1));
  1832. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1833. rt2x00_get_field16(eeprom,
  1834. EEPROM_LED_POLARITY_GPIO_2));
  1835. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1836. rt2x00_get_field16(eeprom,
  1837. EEPROM_LED_POLARITY_GPIO_3));
  1838. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1839. rt2x00_get_field16(eeprom,
  1840. EEPROM_LED_POLARITY_GPIO_4));
  1841. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  1842. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1843. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  1844. rt2x00_get_field16(eeprom,
  1845. EEPROM_LED_POLARITY_RDY_G));
  1846. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  1847. rt2x00_get_field16(eeprom,
  1848. EEPROM_LED_POLARITY_RDY_A));
  1849. #endif /* CONFIG_RT61PCI_LEDS */
  1850. return 0;
  1851. }
  1852. /*
  1853. * RF value list for RF5225 & RF5325
  1854. * Supports: 2.4 GHz & 5.2 GHz, rf_sequence disabled
  1855. */
  1856. static const struct rf_channel rf_vals_noseq[] = {
  1857. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1858. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1859. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1860. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1861. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1862. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1863. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1864. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1865. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1866. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1867. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1868. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1869. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1870. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1871. /* 802.11 UNI / HyperLan 2 */
  1872. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1873. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1874. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1875. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1876. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1877. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1878. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1879. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1880. /* 802.11 HyperLan 2 */
  1881. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1882. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1883. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1884. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1885. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1886. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1887. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1888. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1889. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1890. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1891. /* 802.11 UNII */
  1892. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1893. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1894. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1895. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1896. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1897. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1898. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1899. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1900. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1901. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1902. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1903. };
  1904. /*
  1905. * RF value list for RF5225 & RF5325
  1906. * Supports: 2.4 GHz & 5.2 GHz, rf_sequence enabled
  1907. */
  1908. static const struct rf_channel rf_vals_seq[] = {
  1909. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1910. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1911. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1912. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1913. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1914. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1915. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1916. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1917. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1918. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1919. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1920. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1921. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1922. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1923. /* 802.11 UNI / HyperLan 2 */
  1924. { 36, 0x00002cd4, 0x0004481a, 0x00098455, 0x000c0a03 },
  1925. { 40, 0x00002cd0, 0x00044682, 0x00098455, 0x000c0a03 },
  1926. { 44, 0x00002cd0, 0x00044686, 0x00098455, 0x000c0a1b },
  1927. { 48, 0x00002cd0, 0x0004468e, 0x00098655, 0x000c0a0b },
  1928. { 52, 0x00002cd0, 0x00044692, 0x00098855, 0x000c0a23 },
  1929. { 56, 0x00002cd0, 0x0004469a, 0x00098c55, 0x000c0a13 },
  1930. { 60, 0x00002cd0, 0x000446a2, 0x00098e55, 0x000c0a03 },
  1931. { 64, 0x00002cd0, 0x000446a6, 0x00099255, 0x000c0a1b },
  1932. /* 802.11 HyperLan 2 */
  1933. { 100, 0x00002cd4, 0x0004489a, 0x000b9855, 0x000c0a03 },
  1934. { 104, 0x00002cd4, 0x000448a2, 0x000b9855, 0x000c0a03 },
  1935. { 108, 0x00002cd4, 0x000448aa, 0x000b9855, 0x000c0a03 },
  1936. { 112, 0x00002cd4, 0x000448b2, 0x000b9a55, 0x000c0a03 },
  1937. { 116, 0x00002cd4, 0x000448ba, 0x000b9a55, 0x000c0a03 },
  1938. { 120, 0x00002cd0, 0x00044702, 0x000b9a55, 0x000c0a03 },
  1939. { 124, 0x00002cd0, 0x00044706, 0x000b9a55, 0x000c0a1b },
  1940. { 128, 0x00002cd0, 0x0004470e, 0x000b9c55, 0x000c0a0b },
  1941. { 132, 0x00002cd0, 0x00044712, 0x000b9c55, 0x000c0a23 },
  1942. { 136, 0x00002cd0, 0x0004471a, 0x000b9e55, 0x000c0a13 },
  1943. /* 802.11 UNII */
  1944. { 140, 0x00002cd0, 0x00044722, 0x000b9e55, 0x000c0a03 },
  1945. { 149, 0x00002cd0, 0x0004472e, 0x000ba255, 0x000c0a1b },
  1946. { 153, 0x00002cd0, 0x00044736, 0x000ba255, 0x000c0a0b },
  1947. { 157, 0x00002cd4, 0x0004490a, 0x000ba255, 0x000c0a17 },
  1948. { 161, 0x00002cd4, 0x00044912, 0x000ba255, 0x000c0a17 },
  1949. { 165, 0x00002cd4, 0x0004491a, 0x000ba255, 0x000c0a17 },
  1950. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1951. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000c0a0b },
  1952. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000c0a13 },
  1953. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000c0a1b },
  1954. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000c0a23 },
  1955. };
  1956. static void rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1957. {
  1958. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1959. u8 *txpower;
  1960. unsigned int i;
  1961. /*
  1962. * Initialize all hw fields.
  1963. */
  1964. rt2x00dev->hw->flags =
  1965. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1966. IEEE80211_HW_SIGNAL_DBM;
  1967. rt2x00dev->hw->extra_tx_headroom = 0;
  1968. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1969. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1970. rt2x00_eeprom_addr(rt2x00dev,
  1971. EEPROM_MAC_ADDR_0));
  1972. /*
  1973. * Convert tx_power array in eeprom.
  1974. */
  1975. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1976. for (i = 0; i < 14; i++)
  1977. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1978. /*
  1979. * Initialize hw_mode information.
  1980. */
  1981. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1982. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1983. spec->tx_power_a = NULL;
  1984. spec->tx_power_bg = txpower;
  1985. spec->tx_power_default = DEFAULT_TXPOWER;
  1986. if (!test_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags)) {
  1987. spec->num_channels = 14;
  1988. spec->channels = rf_vals_noseq;
  1989. } else {
  1990. spec->num_channels = 14;
  1991. spec->channels = rf_vals_seq;
  1992. }
  1993. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  1994. rt2x00_rf(&rt2x00dev->chip, RF5325)) {
  1995. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1996. spec->num_channels = ARRAY_SIZE(rf_vals_seq);
  1997. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1998. for (i = 0; i < 14; i++)
  1999. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  2000. spec->tx_power_a = txpower;
  2001. }
  2002. }
  2003. static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  2004. {
  2005. int retval;
  2006. /*
  2007. * Allocate eeprom data.
  2008. */
  2009. retval = rt61pci_validate_eeprom(rt2x00dev);
  2010. if (retval)
  2011. return retval;
  2012. retval = rt61pci_init_eeprom(rt2x00dev);
  2013. if (retval)
  2014. return retval;
  2015. /*
  2016. * Initialize hw specifications.
  2017. */
  2018. rt61pci_probe_hw_mode(rt2x00dev);
  2019. /*
  2020. * This device requires firmware and DMA mapped skbs.
  2021. */
  2022. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2023. __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags);
  2024. /*
  2025. * Set the rssi offset.
  2026. */
  2027. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2028. return 0;
  2029. }
  2030. /*
  2031. * IEEE80211 stack callback functions.
  2032. */
  2033. static int rt61pci_set_retry_limit(struct ieee80211_hw *hw,
  2034. u32 short_retry, u32 long_retry)
  2035. {
  2036. struct rt2x00_dev *rt2x00dev = hw->priv;
  2037. u32 reg;
  2038. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  2039. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry);
  2040. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry);
  2041. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  2042. return 0;
  2043. }
  2044. static u64 rt61pci_get_tsf(struct ieee80211_hw *hw)
  2045. {
  2046. struct rt2x00_dev *rt2x00dev = hw->priv;
  2047. u64 tsf;
  2048. u32 reg;
  2049. rt2x00pci_register_read(rt2x00dev, TXRX_CSR13, &reg);
  2050. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  2051. rt2x00pci_register_read(rt2x00dev, TXRX_CSR12, &reg);
  2052. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  2053. return tsf;
  2054. }
  2055. static const struct ieee80211_ops rt61pci_mac80211_ops = {
  2056. .tx = rt2x00mac_tx,
  2057. .start = rt2x00mac_start,
  2058. .stop = rt2x00mac_stop,
  2059. .add_interface = rt2x00mac_add_interface,
  2060. .remove_interface = rt2x00mac_remove_interface,
  2061. .config = rt2x00mac_config,
  2062. .config_interface = rt2x00mac_config_interface,
  2063. .configure_filter = rt2x00mac_configure_filter,
  2064. .get_stats = rt2x00mac_get_stats,
  2065. .set_retry_limit = rt61pci_set_retry_limit,
  2066. .bss_info_changed = rt2x00mac_bss_info_changed,
  2067. .conf_tx = rt2x00mac_conf_tx,
  2068. .get_tx_stats = rt2x00mac_get_tx_stats,
  2069. .get_tsf = rt61pci_get_tsf,
  2070. };
  2071. static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
  2072. .irq_handler = rt61pci_interrupt,
  2073. .probe_hw = rt61pci_probe_hw,
  2074. .get_firmware_name = rt61pci_get_firmware_name,
  2075. .get_firmware_crc = rt61pci_get_firmware_crc,
  2076. .load_firmware = rt61pci_load_firmware,
  2077. .initialize = rt2x00pci_initialize,
  2078. .uninitialize = rt2x00pci_uninitialize,
  2079. .init_rxentry = rt61pci_init_rxentry,
  2080. .init_txentry = rt61pci_init_txentry,
  2081. .set_device_state = rt61pci_set_device_state,
  2082. .rfkill_poll = rt61pci_rfkill_poll,
  2083. .link_stats = rt61pci_link_stats,
  2084. .reset_tuner = rt61pci_reset_tuner,
  2085. .link_tuner = rt61pci_link_tuner,
  2086. .write_tx_desc = rt61pci_write_tx_desc,
  2087. .write_tx_data = rt2x00pci_write_tx_data,
  2088. .write_beacon = rt61pci_write_beacon,
  2089. .kick_tx_queue = rt61pci_kick_tx_queue,
  2090. .fill_rxdone = rt61pci_fill_rxdone,
  2091. .config_filter = rt61pci_config_filter,
  2092. .config_intf = rt61pci_config_intf,
  2093. .config_erp = rt61pci_config_erp,
  2094. .config = rt61pci_config,
  2095. };
  2096. static const struct data_queue_desc rt61pci_queue_rx = {
  2097. .entry_num = RX_ENTRIES,
  2098. .data_size = DATA_FRAME_SIZE,
  2099. .desc_size = RXD_DESC_SIZE,
  2100. .priv_size = sizeof(struct queue_entry_priv_pci),
  2101. };
  2102. static const struct data_queue_desc rt61pci_queue_tx = {
  2103. .entry_num = TX_ENTRIES,
  2104. .data_size = DATA_FRAME_SIZE,
  2105. .desc_size = TXD_DESC_SIZE,
  2106. .priv_size = sizeof(struct queue_entry_priv_pci),
  2107. };
  2108. static const struct data_queue_desc rt61pci_queue_bcn = {
  2109. .entry_num = 4 * BEACON_ENTRIES,
  2110. .data_size = 0, /* No DMA required for beacons */
  2111. .desc_size = TXINFO_SIZE,
  2112. .priv_size = sizeof(struct queue_entry_priv_pci),
  2113. };
  2114. static const struct rt2x00_ops rt61pci_ops = {
  2115. .name = KBUILD_MODNAME,
  2116. .max_sta_intf = 1,
  2117. .max_ap_intf = 4,
  2118. .eeprom_size = EEPROM_SIZE,
  2119. .rf_size = RF_SIZE,
  2120. .tx_queues = NUM_TX_QUEUES,
  2121. .rx = &rt61pci_queue_rx,
  2122. .tx = &rt61pci_queue_tx,
  2123. .bcn = &rt61pci_queue_bcn,
  2124. .lib = &rt61pci_rt2x00_ops,
  2125. .hw = &rt61pci_mac80211_ops,
  2126. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2127. .debugfs = &rt61pci_rt2x00debug,
  2128. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2129. };
  2130. /*
  2131. * RT61pci module information.
  2132. */
  2133. static struct pci_device_id rt61pci_device_table[] = {
  2134. /* RT2561s */
  2135. { PCI_DEVICE(0x1814, 0x0301), PCI_DEVICE_DATA(&rt61pci_ops) },
  2136. /* RT2561 v2 */
  2137. { PCI_DEVICE(0x1814, 0x0302), PCI_DEVICE_DATA(&rt61pci_ops) },
  2138. /* RT2661 */
  2139. { PCI_DEVICE(0x1814, 0x0401), PCI_DEVICE_DATA(&rt61pci_ops) },
  2140. { 0, }
  2141. };
  2142. MODULE_AUTHOR(DRV_PROJECT);
  2143. MODULE_VERSION(DRV_VERSION);
  2144. MODULE_DESCRIPTION("Ralink RT61 PCI & PCMCIA Wireless LAN driver.");
  2145. MODULE_SUPPORTED_DEVICE("Ralink RT2561, RT2561s & RT2661 "
  2146. "PCI & PCMCIA chipset based cards");
  2147. MODULE_DEVICE_TABLE(pci, rt61pci_device_table);
  2148. MODULE_FIRMWARE(FIRMWARE_RT2561);
  2149. MODULE_FIRMWARE(FIRMWARE_RT2561s);
  2150. MODULE_FIRMWARE(FIRMWARE_RT2661);
  2151. MODULE_LICENSE("GPL");
  2152. static struct pci_driver rt61pci_driver = {
  2153. .name = KBUILD_MODNAME,
  2154. .id_table = rt61pci_device_table,
  2155. .probe = rt2x00pci_probe,
  2156. .remove = __devexit_p(rt2x00pci_remove),
  2157. .suspend = rt2x00pci_suspend,
  2158. .resume = rt2x00pci_resume,
  2159. };
  2160. static int __init rt61pci_init(void)
  2161. {
  2162. return pci_register_driver(&rt61pci_driver);
  2163. }
  2164. static void __exit rt61pci_exit(void)
  2165. {
  2166. pci_unregister_driver(&rt61pci_driver);
  2167. }
  2168. module_init(rt61pci_init);
  2169. module_exit(rt61pci_exit);