rt61pci.c 86 KB

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