rt61pci.c 86 KB

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