rt73usb.c 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  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: rt73usb
  19. Abstract: rt73usb device specific routines.
  20. Supported chipsets: rt2571W & rt2671.
  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/slab.h>
  29. #include <linux/usb.h>
  30. #include "rt2x00.h"
  31. #include "rt2x00usb.h"
  32. #include "rt73usb.h"
  33. /*
  34. * Allow hardware encryption to be disabled.
  35. */
  36. static int modparam_nohwcrypt;
  37. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  38. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  39. /*
  40. * Register access.
  41. * All access to the CSR registers will go through the methods
  42. * rt2x00usb_register_read and rt2x00usb_register_write.
  43. * BBP and RF register require indirect register access,
  44. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  45. * These indirect registers work with busy bits,
  46. * and we will try maximal REGISTER_BUSY_COUNT times to access
  47. * the register while taking a REGISTER_BUSY_DELAY us delay
  48. * between each attampt. When the busy bit is still set at that time,
  49. * the access attempt is considered to have failed,
  50. * and we will print an error.
  51. * The _lock versions must be used if you already hold the csr_mutex
  52. */
  53. #define WAIT_FOR_BBP(__dev, __reg) \
  54. rt2x00usb_regbusy_read((__dev), PHY_CSR3, PHY_CSR3_BUSY, (__reg))
  55. #define WAIT_FOR_RF(__dev, __reg) \
  56. rt2x00usb_regbusy_read((__dev), PHY_CSR4, PHY_CSR4_BUSY, (__reg))
  57. static void rt73usb_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. rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
  73. }
  74. mutex_unlock(&rt2x00dev->csr_mutex);
  75. }
  76. static void rt73usb_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. rt2x00usb_register_write_lock(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 rt73usb_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. /*
  113. * RF5225 and RF2527 contain 21 bits per RF register value,
  114. * all others contain 20 bits.
  115. */
  116. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS,
  117. 20 + (rt2x00_rf(rt2x00dev, RF5225) ||
  118. rt2x00_rf(rt2x00dev, RF2527)));
  119. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  120. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  121. rt2x00usb_register_write_lock(rt2x00dev, PHY_CSR4, reg);
  122. rt2x00_rf_write(rt2x00dev, word, value);
  123. }
  124. mutex_unlock(&rt2x00dev->csr_mutex);
  125. }
  126. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  127. static const struct rt2x00debug rt73usb_rt2x00debug = {
  128. .owner = THIS_MODULE,
  129. .csr = {
  130. .read = rt2x00usb_register_read,
  131. .write = rt2x00usb_register_write,
  132. .flags = RT2X00DEBUGFS_OFFSET,
  133. .word_base = CSR_REG_BASE,
  134. .word_size = sizeof(u32),
  135. .word_count = CSR_REG_SIZE / sizeof(u32),
  136. },
  137. .eeprom = {
  138. .read = rt2x00_eeprom_read,
  139. .write = rt2x00_eeprom_write,
  140. .word_base = EEPROM_BASE,
  141. .word_size = sizeof(u16),
  142. .word_count = EEPROM_SIZE / sizeof(u16),
  143. },
  144. .bbp = {
  145. .read = rt73usb_bbp_read,
  146. .write = rt73usb_bbp_write,
  147. .word_base = BBP_BASE,
  148. .word_size = sizeof(u8),
  149. .word_count = BBP_SIZE / sizeof(u8),
  150. },
  151. .rf = {
  152. .read = rt2x00_rf_read,
  153. .write = rt73usb_rf_write,
  154. .word_base = RF_BASE,
  155. .word_size = sizeof(u32),
  156. .word_count = RF_SIZE / sizeof(u32),
  157. },
  158. };
  159. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  160. static int rt73usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  161. {
  162. u32 reg;
  163. rt2x00usb_register_read(rt2x00dev, MAC_CSR13, &reg);
  164. return rt2x00_get_field32(reg, MAC_CSR13_BIT7);
  165. }
  166. #ifdef CONFIG_RT2X00_LIB_LEDS
  167. static void rt73usb_brightness_set(struct led_classdev *led_cdev,
  168. enum led_brightness brightness)
  169. {
  170. struct rt2x00_led *led =
  171. container_of(led_cdev, struct rt2x00_led, led_dev);
  172. unsigned int enabled = brightness != LED_OFF;
  173. unsigned int a_mode =
  174. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  175. unsigned int bg_mode =
  176. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  177. if (led->type == LED_TYPE_RADIO) {
  178. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  179. MCU_LEDCS_RADIO_STATUS, enabled);
  180. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  181. 0, led->rt2x00dev->led_mcu_reg,
  182. REGISTER_TIMEOUT);
  183. } else if (led->type == LED_TYPE_ASSOC) {
  184. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  185. MCU_LEDCS_LINK_BG_STATUS, bg_mode);
  186. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  187. MCU_LEDCS_LINK_A_STATUS, a_mode);
  188. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  189. 0, led->rt2x00dev->led_mcu_reg,
  190. REGISTER_TIMEOUT);
  191. } else if (led->type == LED_TYPE_QUALITY) {
  192. /*
  193. * The brightness is divided into 6 levels (0 - 5),
  194. * this means we need to convert the brightness
  195. * argument into the matching level within that range.
  196. */
  197. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  198. brightness / (LED_FULL / 6),
  199. led->rt2x00dev->led_mcu_reg,
  200. REGISTER_TIMEOUT);
  201. }
  202. }
  203. static int rt73usb_blink_set(struct led_classdev *led_cdev,
  204. unsigned long *delay_on,
  205. unsigned long *delay_off)
  206. {
  207. struct rt2x00_led *led =
  208. container_of(led_cdev, struct rt2x00_led, led_dev);
  209. u32 reg;
  210. rt2x00usb_register_read(led->rt2x00dev, MAC_CSR14, &reg);
  211. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, *delay_on);
  212. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, *delay_off);
  213. rt2x00usb_register_write(led->rt2x00dev, MAC_CSR14, reg);
  214. return 0;
  215. }
  216. static void rt73usb_init_led(struct rt2x00_dev *rt2x00dev,
  217. struct rt2x00_led *led,
  218. enum led_type type)
  219. {
  220. led->rt2x00dev = rt2x00dev;
  221. led->type = type;
  222. led->led_dev.brightness_set = rt73usb_brightness_set;
  223. led->led_dev.blink_set = rt73usb_blink_set;
  224. led->flags = LED_INITIALIZED;
  225. }
  226. #endif /* CONFIG_RT2X00_LIB_LEDS */
  227. /*
  228. * Configuration handlers.
  229. */
  230. static int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  231. struct rt2x00lib_crypto *crypto,
  232. struct ieee80211_key_conf *key)
  233. {
  234. struct hw_key_entry key_entry;
  235. struct rt2x00_field32 field;
  236. u32 mask;
  237. u32 reg;
  238. if (crypto->cmd == SET_KEY) {
  239. /*
  240. * rt2x00lib can't determine the correct free
  241. * key_idx for shared keys. We have 1 register
  242. * with key valid bits. The goal is simple, read
  243. * the register, if that is full we have no slots
  244. * left.
  245. * Note that each BSS is allowed to have up to 4
  246. * shared keys, so put a mask over the allowed
  247. * entries.
  248. */
  249. mask = (0xf << crypto->bssidx);
  250. rt2x00usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  251. reg &= mask;
  252. if (reg && reg == mask)
  253. return -ENOSPC;
  254. key->hw_key_idx += reg ? ffz(reg) : 0;
  255. /*
  256. * Upload key to hardware
  257. */
  258. memcpy(key_entry.key, crypto->key,
  259. sizeof(key_entry.key));
  260. memcpy(key_entry.tx_mic, crypto->tx_mic,
  261. sizeof(key_entry.tx_mic));
  262. memcpy(key_entry.rx_mic, crypto->rx_mic,
  263. sizeof(key_entry.rx_mic));
  264. reg = SHARED_KEY_ENTRY(key->hw_key_idx);
  265. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  266. &key_entry, sizeof(key_entry));
  267. /*
  268. * The cipher types are stored over 2 registers.
  269. * bssidx 0 and 1 keys are stored in SEC_CSR1 and
  270. * bssidx 1 and 2 keys are stored in SEC_CSR5.
  271. * Using the correct defines correctly will cause overhead,
  272. * so just calculate the correct offset.
  273. */
  274. if (key->hw_key_idx < 8) {
  275. field.bit_offset = (3 * key->hw_key_idx);
  276. field.bit_mask = 0x7 << field.bit_offset;
  277. rt2x00usb_register_read(rt2x00dev, SEC_CSR1, &reg);
  278. rt2x00_set_field32(&reg, field, crypto->cipher);
  279. rt2x00usb_register_write(rt2x00dev, SEC_CSR1, reg);
  280. } else {
  281. field.bit_offset = (3 * (key->hw_key_idx - 8));
  282. field.bit_mask = 0x7 << field.bit_offset;
  283. rt2x00usb_register_read(rt2x00dev, SEC_CSR5, &reg);
  284. rt2x00_set_field32(&reg, field, crypto->cipher);
  285. rt2x00usb_register_write(rt2x00dev, SEC_CSR5, reg);
  286. }
  287. /*
  288. * The driver does not support the IV/EIV generation
  289. * in hardware. However it doesn't support the IV/EIV
  290. * inside the ieee80211 frame either, but requires it
  291. * to be provided separately for the descriptor.
  292. * rt2x00lib will cut the IV/EIV data out of all frames
  293. * given to us by mac80211, but we must tell mac80211
  294. * to generate the IV/EIV data.
  295. */
  296. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  297. }
  298. /*
  299. * SEC_CSR0 contains only single-bit fields to indicate
  300. * a particular key is valid. Because using the FIELD32()
  301. * defines directly will cause a lot of overhead we use
  302. * a calculation to determine the correct bit directly.
  303. */
  304. mask = 1 << key->hw_key_idx;
  305. rt2x00usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  306. if (crypto->cmd == SET_KEY)
  307. reg |= mask;
  308. else if (crypto->cmd == DISABLE_KEY)
  309. reg &= ~mask;
  310. rt2x00usb_register_write(rt2x00dev, SEC_CSR0, reg);
  311. return 0;
  312. }
  313. static int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  314. struct rt2x00lib_crypto *crypto,
  315. struct ieee80211_key_conf *key)
  316. {
  317. struct hw_pairwise_ta_entry addr_entry;
  318. struct hw_key_entry key_entry;
  319. u32 mask;
  320. u32 reg;
  321. if (crypto->cmd == SET_KEY) {
  322. /*
  323. * rt2x00lib can't determine the correct free
  324. * key_idx for pairwise keys. We have 2 registers
  325. * with key valid bits. The goal is simple, read
  326. * the first register, if that is full move to
  327. * the next register.
  328. * When both registers are full, we drop the key,
  329. * otherwise we use the first invalid entry.
  330. */
  331. rt2x00usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  332. if (reg && reg == ~0) {
  333. key->hw_key_idx = 32;
  334. rt2x00usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  335. if (reg && reg == ~0)
  336. return -ENOSPC;
  337. }
  338. key->hw_key_idx += reg ? ffz(reg) : 0;
  339. /*
  340. * Upload key to hardware
  341. */
  342. memcpy(key_entry.key, crypto->key,
  343. sizeof(key_entry.key));
  344. memcpy(key_entry.tx_mic, crypto->tx_mic,
  345. sizeof(key_entry.tx_mic));
  346. memcpy(key_entry.rx_mic, crypto->rx_mic,
  347. sizeof(key_entry.rx_mic));
  348. reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  349. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  350. &key_entry, sizeof(key_entry));
  351. /*
  352. * Send the address and cipher type to the hardware register.
  353. */
  354. memset(&addr_entry, 0, sizeof(addr_entry));
  355. memcpy(&addr_entry, crypto->address, ETH_ALEN);
  356. addr_entry.cipher = crypto->cipher;
  357. reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
  358. rt2x00usb_register_multiwrite(rt2x00dev, reg,
  359. &addr_entry, sizeof(addr_entry));
  360. /*
  361. * Enable pairwise lookup table for given BSS idx,
  362. * without this received frames will not be decrypted
  363. * by the hardware.
  364. */
  365. rt2x00usb_register_read(rt2x00dev, SEC_CSR4, &reg);
  366. reg |= (1 << crypto->bssidx);
  367. rt2x00usb_register_write(rt2x00dev, SEC_CSR4, reg);
  368. /*
  369. * The driver does not support the IV/EIV generation
  370. * in hardware. However it doesn't support the IV/EIV
  371. * inside the ieee80211 frame either, but requires it
  372. * to be provided separately for the descriptor.
  373. * rt2x00lib will cut the IV/EIV data out of all frames
  374. * given to us by mac80211, but we must tell mac80211
  375. * to generate the IV/EIV data.
  376. */
  377. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  378. }
  379. /*
  380. * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
  381. * a particular key is valid. Because using the FIELD32()
  382. * defines directly will cause a lot of overhead we use
  383. * a calculation to determine the correct bit directly.
  384. */
  385. if (key->hw_key_idx < 32) {
  386. mask = 1 << key->hw_key_idx;
  387. rt2x00usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  388. if (crypto->cmd == SET_KEY)
  389. reg |= mask;
  390. else if (crypto->cmd == DISABLE_KEY)
  391. reg &= ~mask;
  392. rt2x00usb_register_write(rt2x00dev, SEC_CSR2, reg);
  393. } else {
  394. mask = 1 << (key->hw_key_idx - 32);
  395. rt2x00usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  396. if (crypto->cmd == SET_KEY)
  397. reg |= mask;
  398. else if (crypto->cmd == DISABLE_KEY)
  399. reg &= ~mask;
  400. rt2x00usb_register_write(rt2x00dev, SEC_CSR3, reg);
  401. }
  402. return 0;
  403. }
  404. static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev,
  405. const unsigned int filter_flags)
  406. {
  407. u32 reg;
  408. /*
  409. * Start configuration steps.
  410. * Note that the version error will always be dropped
  411. * and broadcast frames will always be accepted since
  412. * there is no filter for it at this time.
  413. */
  414. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  415. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  416. !(filter_flags & FIF_FCSFAIL));
  417. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  418. !(filter_flags & FIF_PLCPFAIL));
  419. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  420. !(filter_flags & (FIF_CONTROL | FIF_PSPOLL)));
  421. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  422. !(filter_flags & FIF_PROMISC_IN_BSS));
  423. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  424. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  425. !rt2x00dev->intf_ap_count);
  426. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  427. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  428. !(filter_flags & FIF_ALLMULTI));
  429. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  430. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS,
  431. !(filter_flags & FIF_CONTROL));
  432. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  433. }
  434. static void rt73usb_config_intf(struct rt2x00_dev *rt2x00dev,
  435. struct rt2x00_intf *intf,
  436. struct rt2x00intf_conf *conf,
  437. const unsigned int flags)
  438. {
  439. unsigned int beacon_base;
  440. u32 reg;
  441. if (flags & CONFIG_UPDATE_TYPE) {
  442. /*
  443. * Clear current synchronisation setup.
  444. * For the Beacon base registers we only need to clear
  445. * the first byte since that byte contains the VALID and OWNER
  446. * bits which (when set to 0) will invalidate the entire beacon.
  447. */
  448. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  449. rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
  450. /*
  451. * Enable synchronisation.
  452. */
  453. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  454. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  455. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  456. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  457. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  458. }
  459. if (flags & CONFIG_UPDATE_MAC) {
  460. reg = le32_to_cpu(conf->mac[1]);
  461. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  462. conf->mac[1] = cpu_to_le32(reg);
  463. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR2,
  464. conf->mac, sizeof(conf->mac));
  465. }
  466. if (flags & CONFIG_UPDATE_BSSID) {
  467. reg = le32_to_cpu(conf->bssid[1]);
  468. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  469. conf->bssid[1] = cpu_to_le32(reg);
  470. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR4,
  471. conf->bssid, sizeof(conf->bssid));
  472. }
  473. }
  474. static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
  475. struct rt2x00lib_erp *erp,
  476. u32 changed)
  477. {
  478. u32 reg;
  479. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  480. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, 0x32);
  481. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  482. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  483. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  484. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  485. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  486. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  487. !!erp->short_preamble);
  488. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  489. }
  490. if (changed & BSS_CHANGED_BASIC_RATES)
  491. rt2x00usb_register_write(rt2x00dev, TXRX_CSR5,
  492. erp->basic_rates);
  493. if (changed & BSS_CHANGED_BEACON_INT) {
  494. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  495. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  496. erp->beacon_int * 16);
  497. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  498. }
  499. if (changed & BSS_CHANGED_ERP_SLOT) {
  500. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  501. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
  502. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  503. rt2x00usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  504. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
  505. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  506. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
  507. rt2x00usb_register_write(rt2x00dev, MAC_CSR8, reg);
  508. }
  509. }
  510. static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  511. struct antenna_setup *ant)
  512. {
  513. u8 r3;
  514. u8 r4;
  515. u8 r77;
  516. u8 temp;
  517. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  518. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  519. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  520. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  521. /*
  522. * Configure the RX antenna.
  523. */
  524. switch (ant->rx) {
  525. case ANTENNA_HW_DIVERSITY:
  526. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  527. temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags)
  528. && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ);
  529. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp);
  530. break;
  531. case ANTENNA_A:
  532. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  533. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  534. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  535. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  536. else
  537. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  538. break;
  539. case ANTENNA_B:
  540. default:
  541. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  542. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  543. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  544. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  545. else
  546. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  547. break;
  548. }
  549. rt73usb_bbp_write(rt2x00dev, 77, r77);
  550. rt73usb_bbp_write(rt2x00dev, 3, r3);
  551. rt73usb_bbp_write(rt2x00dev, 4, r4);
  552. }
  553. static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  554. struct antenna_setup *ant)
  555. {
  556. u8 r3;
  557. u8 r4;
  558. u8 r77;
  559. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  560. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  561. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  562. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  563. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  564. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  565. /*
  566. * Configure the RX antenna.
  567. */
  568. switch (ant->rx) {
  569. case ANTENNA_HW_DIVERSITY:
  570. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  571. break;
  572. case ANTENNA_A:
  573. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  574. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  575. break;
  576. case ANTENNA_B:
  577. default:
  578. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  579. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  580. break;
  581. }
  582. rt73usb_bbp_write(rt2x00dev, 77, r77);
  583. rt73usb_bbp_write(rt2x00dev, 3, r3);
  584. rt73usb_bbp_write(rt2x00dev, 4, r4);
  585. }
  586. struct antenna_sel {
  587. u8 word;
  588. /*
  589. * value[0] -> non-LNA
  590. * value[1] -> LNA
  591. */
  592. u8 value[2];
  593. };
  594. static const struct antenna_sel antenna_sel_a[] = {
  595. { 96, { 0x58, 0x78 } },
  596. { 104, { 0x38, 0x48 } },
  597. { 75, { 0xfe, 0x80 } },
  598. { 86, { 0xfe, 0x80 } },
  599. { 88, { 0xfe, 0x80 } },
  600. { 35, { 0x60, 0x60 } },
  601. { 97, { 0x58, 0x58 } },
  602. { 98, { 0x58, 0x58 } },
  603. };
  604. static const struct antenna_sel antenna_sel_bg[] = {
  605. { 96, { 0x48, 0x68 } },
  606. { 104, { 0x2c, 0x3c } },
  607. { 75, { 0xfe, 0x80 } },
  608. { 86, { 0xfe, 0x80 } },
  609. { 88, { 0xfe, 0x80 } },
  610. { 35, { 0x50, 0x50 } },
  611. { 97, { 0x48, 0x48 } },
  612. { 98, { 0x48, 0x48 } },
  613. };
  614. static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
  615. struct antenna_setup *ant)
  616. {
  617. const struct antenna_sel *sel;
  618. unsigned int lna;
  619. unsigned int i;
  620. u32 reg;
  621. /*
  622. * We should never come here because rt2x00lib is supposed
  623. * to catch this and send us the correct antenna explicitely.
  624. */
  625. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  626. ant->tx == ANTENNA_SW_DIVERSITY);
  627. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  628. sel = antenna_sel_a;
  629. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  630. } else {
  631. sel = antenna_sel_bg;
  632. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  633. }
  634. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  635. rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  636. rt2x00usb_register_read(rt2x00dev, PHY_CSR0, &reg);
  637. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  638. (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ));
  639. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  640. (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ));
  641. rt2x00usb_register_write(rt2x00dev, PHY_CSR0, reg);
  642. if (rt2x00_rf(rt2x00dev, RF5226) || rt2x00_rf(rt2x00dev, RF5225))
  643. rt73usb_config_antenna_5x(rt2x00dev, ant);
  644. else if (rt2x00_rf(rt2x00dev, RF2528) || rt2x00_rf(rt2x00dev, RF2527))
  645. rt73usb_config_antenna_2x(rt2x00dev, ant);
  646. }
  647. static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  648. struct rt2x00lib_conf *libconf)
  649. {
  650. u16 eeprom;
  651. short lna_gain = 0;
  652. if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
  653. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  654. lna_gain += 14;
  655. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  656. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  657. } else {
  658. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  659. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  660. }
  661. rt2x00dev->lna_gain = lna_gain;
  662. }
  663. static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
  664. struct rf_channel *rf, const int txpower)
  665. {
  666. u8 r3;
  667. u8 r94;
  668. u8 smart;
  669. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  670. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  671. smart = !(rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527));
  672. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  673. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  674. rt73usb_bbp_write(rt2x00dev, 3, r3);
  675. r94 = 6;
  676. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  677. r94 += txpower - MAX_TXPOWER;
  678. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  679. r94 += txpower;
  680. rt73usb_bbp_write(rt2x00dev, 94, r94);
  681. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  682. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  683. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  684. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  685. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  686. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  687. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  688. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  689. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  690. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  691. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  692. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  693. udelay(10);
  694. }
  695. static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  696. const int txpower)
  697. {
  698. struct rf_channel rf;
  699. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  700. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  701. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  702. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  703. rt73usb_config_channel(rt2x00dev, &rf, txpower);
  704. }
  705. static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  706. struct rt2x00lib_conf *libconf)
  707. {
  708. u32 reg;
  709. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  710. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_DOWN, 1);
  711. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_STEP, 0);
  712. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_FALLBACK_CCK, 0);
  713. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
  714. libconf->conf->long_frame_max_tx_count);
  715. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
  716. libconf->conf->short_frame_max_tx_count);
  717. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  718. }
  719. static void rt73usb_config_ps(struct rt2x00_dev *rt2x00dev,
  720. struct rt2x00lib_conf *libconf)
  721. {
  722. enum dev_state state =
  723. (libconf->conf->flags & IEEE80211_CONF_PS) ?
  724. STATE_SLEEP : STATE_AWAKE;
  725. u32 reg;
  726. if (state == STATE_SLEEP) {
  727. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  728. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN,
  729. rt2x00dev->beacon_int - 10);
  730. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP,
  731. libconf->conf->listen_interval - 1);
  732. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 5);
  733. /* We must first disable autowake before it can be enabled */
  734. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  735. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  736. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 1);
  737. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  738. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  739. USB_MODE_SLEEP, REGISTER_TIMEOUT);
  740. } else {
  741. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  742. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN, 0);
  743. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP, 0);
  744. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  745. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 0);
  746. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  747. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  748. USB_MODE_WAKEUP, REGISTER_TIMEOUT);
  749. }
  750. }
  751. static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
  752. struct rt2x00lib_conf *libconf,
  753. const unsigned int flags)
  754. {
  755. /* Always recalculate LNA gain before changing configuration */
  756. rt73usb_config_lna_gain(rt2x00dev, libconf);
  757. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  758. rt73usb_config_channel(rt2x00dev, &libconf->rf,
  759. libconf->conf->power_level);
  760. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  761. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  762. rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  763. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  764. rt73usb_config_retry_limit(rt2x00dev, libconf);
  765. if (flags & IEEE80211_CONF_CHANGE_PS)
  766. rt73usb_config_ps(rt2x00dev, libconf);
  767. }
  768. /*
  769. * Link tuning
  770. */
  771. static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev,
  772. struct link_qual *qual)
  773. {
  774. u32 reg;
  775. /*
  776. * Update FCS error count from register.
  777. */
  778. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  779. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  780. /*
  781. * Update False CCA count from register.
  782. */
  783. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  784. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  785. }
  786. static inline void rt73usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  787. struct link_qual *qual, u8 vgc_level)
  788. {
  789. if (qual->vgc_level != vgc_level) {
  790. rt73usb_bbp_write(rt2x00dev, 17, vgc_level);
  791. qual->vgc_level = vgc_level;
  792. qual->vgc_level_reg = vgc_level;
  793. }
  794. }
  795. static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  796. struct link_qual *qual)
  797. {
  798. rt73usb_set_vgc(rt2x00dev, qual, 0x20);
  799. }
  800. static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  801. struct link_qual *qual, const u32 count)
  802. {
  803. u8 up_bound;
  804. u8 low_bound;
  805. /*
  806. * Determine r17 bounds.
  807. */
  808. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  809. low_bound = 0x28;
  810. up_bound = 0x48;
  811. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  812. low_bound += 0x10;
  813. up_bound += 0x10;
  814. }
  815. } else {
  816. if (qual->rssi > -82) {
  817. low_bound = 0x1c;
  818. up_bound = 0x40;
  819. } else if (qual->rssi > -84) {
  820. low_bound = 0x1c;
  821. up_bound = 0x20;
  822. } else {
  823. low_bound = 0x1c;
  824. up_bound = 0x1c;
  825. }
  826. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  827. low_bound += 0x14;
  828. up_bound += 0x10;
  829. }
  830. }
  831. /*
  832. * If we are not associated, we should go straight to the
  833. * dynamic CCA tuning.
  834. */
  835. if (!rt2x00dev->intf_associated)
  836. goto dynamic_cca_tune;
  837. /*
  838. * Special big-R17 for very short distance
  839. */
  840. if (qual->rssi > -35) {
  841. rt73usb_set_vgc(rt2x00dev, qual, 0x60);
  842. return;
  843. }
  844. /*
  845. * Special big-R17 for short distance
  846. */
  847. if (qual->rssi >= -58) {
  848. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  849. return;
  850. }
  851. /*
  852. * Special big-R17 for middle-short distance
  853. */
  854. if (qual->rssi >= -66) {
  855. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x10);
  856. return;
  857. }
  858. /*
  859. * Special mid-R17 for middle distance
  860. */
  861. if (qual->rssi >= -74) {
  862. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x08);
  863. return;
  864. }
  865. /*
  866. * Special case: Change up_bound based on the rssi.
  867. * Lower up_bound when rssi is weaker then -74 dBm.
  868. */
  869. up_bound -= 2 * (-74 - qual->rssi);
  870. if (low_bound > up_bound)
  871. up_bound = low_bound;
  872. if (qual->vgc_level > up_bound) {
  873. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  874. return;
  875. }
  876. dynamic_cca_tune:
  877. /*
  878. * r17 does not yet exceed upper limit, continue and base
  879. * the r17 tuning on the false CCA count.
  880. */
  881. if ((qual->false_cca > 512) && (qual->vgc_level < up_bound))
  882. rt73usb_set_vgc(rt2x00dev, qual,
  883. min_t(u8, qual->vgc_level + 4, up_bound));
  884. else if ((qual->false_cca < 100) && (qual->vgc_level > low_bound))
  885. rt73usb_set_vgc(rt2x00dev, qual,
  886. max_t(u8, qual->vgc_level - 4, low_bound));
  887. }
  888. /*
  889. * Firmware functions
  890. */
  891. static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  892. {
  893. return FIRMWARE_RT2571;
  894. }
  895. static int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  896. const u8 *data, const size_t len)
  897. {
  898. u16 fw_crc;
  899. u16 crc;
  900. /*
  901. * Only support 2kb firmware files.
  902. */
  903. if (len != 2048)
  904. return FW_BAD_LENGTH;
  905. /*
  906. * The last 2 bytes in the firmware array are the crc checksum itself,
  907. * this means that we should never pass those 2 bytes to the crc
  908. * algorithm.
  909. */
  910. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  911. /*
  912. * Use the crc itu-t algorithm.
  913. */
  914. crc = crc_itu_t(0, data, len - 2);
  915. crc = crc_itu_t_byte(crc, 0);
  916. crc = crc_itu_t_byte(crc, 0);
  917. return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
  918. }
  919. static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  920. const u8 *data, const size_t len)
  921. {
  922. unsigned int i;
  923. int status;
  924. u32 reg;
  925. /*
  926. * Wait for stable hardware.
  927. */
  928. for (i = 0; i < 100; i++) {
  929. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  930. if (reg)
  931. break;
  932. msleep(1);
  933. }
  934. if (!reg) {
  935. ERROR(rt2x00dev, "Unstable hardware.\n");
  936. return -EBUSY;
  937. }
  938. /*
  939. * Write firmware to device.
  940. */
  941. rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, data, len);
  942. /*
  943. * Send firmware request to device to load firmware,
  944. * we need to specify a long timeout time.
  945. */
  946. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  947. 0, USB_MODE_FIRMWARE,
  948. REGISTER_TIMEOUT_FIRMWARE);
  949. if (status < 0) {
  950. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  951. return status;
  952. }
  953. return 0;
  954. }
  955. /*
  956. * Initialization functions.
  957. */
  958. static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
  959. {
  960. u32 reg;
  961. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  962. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  963. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  964. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  965. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  966. rt2x00usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  967. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  968. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  969. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  970. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  971. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  972. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  973. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  974. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  975. rt2x00usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  976. /*
  977. * CCK TXD BBP registers
  978. */
  979. rt2x00usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  980. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  981. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  982. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  983. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  984. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  985. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  986. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  987. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  988. rt2x00usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  989. /*
  990. * OFDM TXD BBP registers
  991. */
  992. rt2x00usb_register_read(rt2x00dev, TXRX_CSR3, &reg);
  993. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  994. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  995. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  996. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  997. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  998. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  999. rt2x00usb_register_write(rt2x00dev, TXRX_CSR3, reg);
  1000. rt2x00usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1001. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1002. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1003. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1004. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1005. rt2x00usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  1006. rt2x00usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1007. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1008. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1009. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1010. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1011. rt2x00usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  1012. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1013. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1014. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1015. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1016. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1017. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1018. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1019. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1020. rt2x00usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1021. rt2x00usb_register_read(rt2x00dev, MAC_CSR6, &reg);
  1022. rt2x00_set_field32(&reg, MAC_CSR6_MAX_FRAME_UNIT, 0xfff);
  1023. rt2x00usb_register_write(rt2x00dev, MAC_CSR6, reg);
  1024. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718);
  1025. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1026. return -EBUSY;
  1027. rt2x00usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00);
  1028. /*
  1029. * Invalidate all Shared Keys (SEC_CSR0),
  1030. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1031. */
  1032. rt2x00usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1033. rt2x00usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1034. rt2x00usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1035. reg = 0x000023b0;
  1036. if (rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527))
  1037. rt2x00_set_field32(&reg, PHY_CSR1_RF_RPI, 1);
  1038. rt2x00usb_register_write(rt2x00dev, PHY_CSR1, reg);
  1039. rt2x00usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06);
  1040. rt2x00usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1041. rt2x00usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
  1042. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  1043. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1044. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  1045. /*
  1046. * Clear all beacons
  1047. * For the Beacon base registers we only need to clear
  1048. * the first byte since that byte contains the VALID and OWNER
  1049. * bits which (when set to 0) will invalidate the entire beacon.
  1050. */
  1051. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1052. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1053. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1054. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1055. /*
  1056. * We must clear the error counters.
  1057. * These registers are cleared on read,
  1058. * so we may pass a useless variable to store the value.
  1059. */
  1060. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  1061. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  1062. rt2x00usb_register_read(rt2x00dev, STA_CSR2, &reg);
  1063. /*
  1064. * Reset MAC and BBP registers.
  1065. */
  1066. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1067. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1068. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1069. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1070. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1071. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1072. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1073. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1074. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1075. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1076. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1077. return 0;
  1078. }
  1079. static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1080. {
  1081. unsigned int i;
  1082. u8 value;
  1083. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1084. rt73usb_bbp_read(rt2x00dev, 0, &value);
  1085. if ((value != 0xff) && (value != 0x00))
  1086. return 0;
  1087. udelay(REGISTER_BUSY_DELAY);
  1088. }
  1089. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1090. return -EACCES;
  1091. }
  1092. static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1093. {
  1094. unsigned int i;
  1095. u16 eeprom;
  1096. u8 reg_id;
  1097. u8 value;
  1098. if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
  1099. return -EACCES;
  1100. rt73usb_bbp_write(rt2x00dev, 3, 0x80);
  1101. rt73usb_bbp_write(rt2x00dev, 15, 0x30);
  1102. rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
  1103. rt73usb_bbp_write(rt2x00dev, 22, 0x38);
  1104. rt73usb_bbp_write(rt2x00dev, 23, 0x06);
  1105. rt73usb_bbp_write(rt2x00dev, 24, 0xfe);
  1106. rt73usb_bbp_write(rt2x00dev, 25, 0x0a);
  1107. rt73usb_bbp_write(rt2x00dev, 26, 0x0d);
  1108. rt73usb_bbp_write(rt2x00dev, 32, 0x0b);
  1109. rt73usb_bbp_write(rt2x00dev, 34, 0x12);
  1110. rt73usb_bbp_write(rt2x00dev, 37, 0x07);
  1111. rt73usb_bbp_write(rt2x00dev, 39, 0xf8);
  1112. rt73usb_bbp_write(rt2x00dev, 41, 0x60);
  1113. rt73usb_bbp_write(rt2x00dev, 53, 0x10);
  1114. rt73usb_bbp_write(rt2x00dev, 54, 0x18);
  1115. rt73usb_bbp_write(rt2x00dev, 60, 0x10);
  1116. rt73usb_bbp_write(rt2x00dev, 61, 0x04);
  1117. rt73usb_bbp_write(rt2x00dev, 62, 0x04);
  1118. rt73usb_bbp_write(rt2x00dev, 75, 0xfe);
  1119. rt73usb_bbp_write(rt2x00dev, 86, 0xfe);
  1120. rt73usb_bbp_write(rt2x00dev, 88, 0xfe);
  1121. rt73usb_bbp_write(rt2x00dev, 90, 0x0f);
  1122. rt73usb_bbp_write(rt2x00dev, 99, 0x00);
  1123. rt73usb_bbp_write(rt2x00dev, 102, 0x16);
  1124. rt73usb_bbp_write(rt2x00dev, 107, 0x04);
  1125. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1126. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1127. if (eeprom != 0xffff && eeprom != 0x0000) {
  1128. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1129. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1130. rt73usb_bbp_write(rt2x00dev, reg_id, value);
  1131. }
  1132. }
  1133. return 0;
  1134. }
  1135. /*
  1136. * Device state switch handlers.
  1137. */
  1138. static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1139. enum dev_state state)
  1140. {
  1141. u32 reg;
  1142. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1143. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  1144. (state == STATE_RADIO_RX_OFF));
  1145. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1146. }
  1147. static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1148. {
  1149. /*
  1150. * Initialize all registers.
  1151. */
  1152. if (unlikely(rt73usb_init_registers(rt2x00dev) ||
  1153. rt73usb_init_bbp(rt2x00dev)))
  1154. return -EIO;
  1155. return 0;
  1156. }
  1157. static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1158. {
  1159. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1160. /*
  1161. * Disable synchronisation.
  1162. */
  1163. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  1164. rt2x00usb_disable_radio(rt2x00dev);
  1165. }
  1166. static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1167. {
  1168. u32 reg, reg2;
  1169. unsigned int i;
  1170. char put_to_sleep;
  1171. put_to_sleep = (state != STATE_AWAKE);
  1172. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  1173. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1174. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1175. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1176. /*
  1177. * Device is not guaranteed to be in the requested state yet.
  1178. * We must wait until the register indicates that the
  1179. * device has entered the correct state.
  1180. */
  1181. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1182. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg2);
  1183. state = rt2x00_get_field32(reg2, MAC_CSR12_BBP_CURRENT_STATE);
  1184. if (state == !put_to_sleep)
  1185. return 0;
  1186. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1187. msleep(10);
  1188. }
  1189. return -EBUSY;
  1190. }
  1191. static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1192. enum dev_state state)
  1193. {
  1194. int retval = 0;
  1195. switch (state) {
  1196. case STATE_RADIO_ON:
  1197. retval = rt73usb_enable_radio(rt2x00dev);
  1198. break;
  1199. case STATE_RADIO_OFF:
  1200. rt73usb_disable_radio(rt2x00dev);
  1201. break;
  1202. case STATE_RADIO_RX_ON:
  1203. case STATE_RADIO_RX_OFF:
  1204. rt73usb_toggle_rx(rt2x00dev, state);
  1205. break;
  1206. case STATE_RADIO_IRQ_ON:
  1207. case STATE_RADIO_IRQ_ON_ISR:
  1208. case STATE_RADIO_IRQ_OFF:
  1209. case STATE_RADIO_IRQ_OFF_ISR:
  1210. /* No support, but no error either */
  1211. break;
  1212. case STATE_DEEP_SLEEP:
  1213. case STATE_SLEEP:
  1214. case STATE_STANDBY:
  1215. case STATE_AWAKE:
  1216. retval = rt73usb_set_state(rt2x00dev, state);
  1217. break;
  1218. default:
  1219. retval = -ENOTSUPP;
  1220. break;
  1221. }
  1222. if (unlikely(retval))
  1223. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1224. state, retval);
  1225. return retval;
  1226. }
  1227. /*
  1228. * TX descriptor initialization
  1229. */
  1230. static void rt73usb_write_tx_desc(struct queue_entry *entry,
  1231. struct txentry_desc *txdesc)
  1232. {
  1233. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1234. __le32 *txd = (__le32 *) entry->skb->data;
  1235. u32 word;
  1236. /*
  1237. * Start writing the descriptor words.
  1238. */
  1239. rt2x00_desc_read(txd, 0, &word);
  1240. rt2x00_set_field32(&word, TXD_W0_BURST,
  1241. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1242. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1243. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1244. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1245. rt2x00_set_field32(&word, TXD_W0_ACK,
  1246. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1247. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1248. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1249. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1250. (txdesc->rate_mode == RATE_MODE_OFDM));
  1251. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1252. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1253. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1254. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
  1255. test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
  1256. rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
  1257. test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
  1258. rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
  1259. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length);
  1260. rt2x00_set_field32(&word, TXD_W0_BURST2,
  1261. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1262. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
  1263. rt2x00_desc_write(txd, 0, word);
  1264. rt2x00_desc_read(txd, 1, &word);
  1265. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, entry->queue->qid);
  1266. rt2x00_set_field32(&word, TXD_W1_AIFSN, entry->queue->aifs);
  1267. rt2x00_set_field32(&word, TXD_W1_CWMIN, entry->queue->cw_min);
  1268. rt2x00_set_field32(&word, TXD_W1_CWMAX, entry->queue->cw_max);
  1269. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  1270. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1271. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1272. rt2x00_desc_write(txd, 1, word);
  1273. rt2x00_desc_read(txd, 2, &word);
  1274. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  1275. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  1276. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  1277. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  1278. rt2x00_desc_write(txd, 2, word);
  1279. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1280. _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
  1281. _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
  1282. }
  1283. rt2x00_desc_read(txd, 5, &word);
  1284. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1285. TXPOWER_TO_DEV(entry->queue->rt2x00dev->tx_power));
  1286. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1287. rt2x00_desc_write(txd, 5, word);
  1288. /*
  1289. * Register descriptor details in skb frame descriptor.
  1290. */
  1291. skbdesc->flags |= SKBDESC_DESC_IN_SKB;
  1292. skbdesc->desc = txd;
  1293. skbdesc->desc_len = TXD_DESC_SIZE;
  1294. }
  1295. /*
  1296. * TX data initialization
  1297. */
  1298. static void rt73usb_write_beacon(struct queue_entry *entry,
  1299. struct txentry_desc *txdesc)
  1300. {
  1301. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1302. unsigned int beacon_base;
  1303. u32 reg;
  1304. /*
  1305. * Disable beaconing while we are reloading the beacon data,
  1306. * otherwise we might be sending out invalid data.
  1307. */
  1308. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1309. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1310. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1311. /*
  1312. * Add space for the descriptor in front of the skb.
  1313. */
  1314. skb_push(entry->skb, TXD_DESC_SIZE);
  1315. memset(entry->skb->data, 0, TXD_DESC_SIZE);
  1316. /*
  1317. * Write the TX descriptor for the beacon.
  1318. */
  1319. rt73usb_write_tx_desc(entry, txdesc);
  1320. /*
  1321. * Dump beacon to userspace through debugfs.
  1322. */
  1323. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
  1324. /*
  1325. * Write entire beacon with descriptor to register.
  1326. */
  1327. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1328. rt2x00usb_register_multiwrite(rt2x00dev, beacon_base,
  1329. entry->skb->data, entry->skb->len);
  1330. /*
  1331. * Enable beaconing again.
  1332. *
  1333. * For Wi-Fi faily generated beacons between participating stations.
  1334. * Set TBTT phase adaptive adjustment step to 8us (default 16us)
  1335. */
  1336. rt2x00usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1337. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  1338. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  1339. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1340. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1341. /*
  1342. * Clean up the beacon skb.
  1343. */
  1344. dev_kfree_skb(entry->skb);
  1345. entry->skb = NULL;
  1346. }
  1347. static int rt73usb_get_tx_data_len(struct queue_entry *entry)
  1348. {
  1349. int length;
  1350. /*
  1351. * The length _must_ be a multiple of 4,
  1352. * but it must _not_ be a multiple of the USB packet size.
  1353. */
  1354. length = roundup(entry->skb->len, 4);
  1355. length += (4 * !(length % entry->queue->usb_maxpacket));
  1356. return length;
  1357. }
  1358. static void rt73usb_kill_tx_queue(struct data_queue *queue)
  1359. {
  1360. if (queue->qid == QID_BEACON)
  1361. rt2x00usb_register_write(queue->rt2x00dev, TXRX_CSR9, 0);
  1362. rt2x00usb_kill_tx_queue(queue);
  1363. }
  1364. /*
  1365. * RX control handlers
  1366. */
  1367. static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1368. {
  1369. u8 offset = rt2x00dev->lna_gain;
  1370. u8 lna;
  1371. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1372. switch (lna) {
  1373. case 3:
  1374. offset += 90;
  1375. break;
  1376. case 2:
  1377. offset += 74;
  1378. break;
  1379. case 1:
  1380. offset += 64;
  1381. break;
  1382. default:
  1383. return 0;
  1384. }
  1385. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  1386. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  1387. if (lna == 3 || lna == 2)
  1388. offset += 10;
  1389. } else {
  1390. if (lna == 3)
  1391. offset += 6;
  1392. else if (lna == 2)
  1393. offset += 8;
  1394. }
  1395. }
  1396. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1397. }
  1398. static void rt73usb_fill_rxdone(struct queue_entry *entry,
  1399. struct rxdone_entry_desc *rxdesc)
  1400. {
  1401. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1402. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1403. __le32 *rxd = (__le32 *)entry->skb->data;
  1404. u32 word0;
  1405. u32 word1;
  1406. /*
  1407. * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
  1408. * frame data in rt2x00usb.
  1409. */
  1410. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1411. rxd = (__le32 *)skbdesc->desc;
  1412. /*
  1413. * It is now safe to read the descriptor on all architectures.
  1414. */
  1415. rt2x00_desc_read(rxd, 0, &word0);
  1416. rt2x00_desc_read(rxd, 1, &word1);
  1417. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1418. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1419. rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
  1420. rxdesc->cipher_status = rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
  1421. if (rxdesc->cipher != CIPHER_NONE) {
  1422. _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
  1423. _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
  1424. rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
  1425. _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
  1426. rxdesc->dev_flags |= RXDONE_CRYPTO_ICV;
  1427. /*
  1428. * Hardware has stripped IV/EIV data from 802.11 frame during
  1429. * decryption. It has provided the data separately but rt2x00lib
  1430. * should decide if it should be reinserted.
  1431. */
  1432. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1433. /*
  1434. * FIXME: Legacy driver indicates that the frame does
  1435. * contain the Michael Mic. Unfortunately, in rt2x00
  1436. * the MIC seems to be missing completely...
  1437. */
  1438. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1439. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1440. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1441. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1442. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1443. }
  1444. /*
  1445. * Obtain the status about this packet.
  1446. * When frame was received with an OFDM bitrate,
  1447. * the signal is the PLCP value. If it was received with
  1448. * a CCK bitrate the signal is the rate in 100kbit/s.
  1449. */
  1450. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1451. rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1);
  1452. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1453. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1454. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1455. else
  1456. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1457. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1458. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1459. /*
  1460. * Set skb pointers, and update frame information.
  1461. */
  1462. skb_pull(entry->skb, entry->queue->desc_size);
  1463. skb_trim(entry->skb, rxdesc->size);
  1464. }
  1465. /*
  1466. * Device probe functions.
  1467. */
  1468. static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1469. {
  1470. u16 word;
  1471. u8 *mac;
  1472. s8 value;
  1473. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1474. /*
  1475. * Start validation of the data that has been read.
  1476. */
  1477. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1478. if (!is_valid_ether_addr(mac)) {
  1479. random_ether_addr(mac);
  1480. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1481. }
  1482. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1483. if (word == 0xffff) {
  1484. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1485. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1486. ANTENNA_B);
  1487. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1488. ANTENNA_B);
  1489. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1490. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1491. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1492. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226);
  1493. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1494. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1495. }
  1496. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1497. if (word == 0xffff) {
  1498. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0);
  1499. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1500. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1501. }
  1502. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1503. if (word == 0xffff) {
  1504. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0);
  1505. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0);
  1506. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0);
  1507. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0);
  1508. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0);
  1509. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0);
  1510. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0);
  1511. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0);
  1512. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1513. LED_MODE_DEFAULT);
  1514. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1515. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1516. }
  1517. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1518. if (word == 0xffff) {
  1519. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1520. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1521. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1522. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1523. }
  1524. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1525. if (word == 0xffff) {
  1526. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1527. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1528. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1529. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1530. } else {
  1531. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1532. if (value < -10 || value > 10)
  1533. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1534. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1535. if (value < -10 || value > 10)
  1536. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1537. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1538. }
  1539. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1540. if (word == 0xffff) {
  1541. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1542. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1543. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1544. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1545. } else {
  1546. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1547. if (value < -10 || value > 10)
  1548. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1549. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1550. if (value < -10 || value > 10)
  1551. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1552. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1553. }
  1554. return 0;
  1555. }
  1556. static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1557. {
  1558. u32 reg;
  1559. u16 value;
  1560. u16 eeprom;
  1561. /*
  1562. * Read EEPROM word for configuration.
  1563. */
  1564. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1565. /*
  1566. * Identify RF chipset.
  1567. */
  1568. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1569. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1570. rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET),
  1571. value, rt2x00_get_field32(reg, MAC_CSR0_REVISION));
  1572. if (!rt2x00_rt(rt2x00dev, RT2573) || (rt2x00_rev(rt2x00dev) == 0)) {
  1573. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1574. return -ENODEV;
  1575. }
  1576. if (!rt2x00_rf(rt2x00dev, RF5226) &&
  1577. !rt2x00_rf(rt2x00dev, RF2528) &&
  1578. !rt2x00_rf(rt2x00dev, RF5225) &&
  1579. !rt2x00_rf(rt2x00dev, RF2527)) {
  1580. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1581. return -ENODEV;
  1582. }
  1583. /*
  1584. * Identify default antenna configuration.
  1585. */
  1586. rt2x00dev->default_ant.tx =
  1587. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1588. rt2x00dev->default_ant.rx =
  1589. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1590. /*
  1591. * Read the Frame type.
  1592. */
  1593. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1594. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1595. /*
  1596. * Detect if this device has an hardware controlled radio.
  1597. */
  1598. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1599. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1600. /*
  1601. * Read frequency offset.
  1602. */
  1603. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1604. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1605. /*
  1606. * Read external LNA informations.
  1607. */
  1608. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1609. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) {
  1610. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1611. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1612. }
  1613. /*
  1614. * Store led settings, for correct led behaviour.
  1615. */
  1616. #ifdef CONFIG_RT2X00_LIB_LEDS
  1617. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1618. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1619. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1620. if (value == LED_MODE_SIGNAL_STRENGTH)
  1621. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1622. LED_TYPE_QUALITY);
  1623. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  1624. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1625. rt2x00_get_field16(eeprom,
  1626. EEPROM_LED_POLARITY_GPIO_0));
  1627. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1628. rt2x00_get_field16(eeprom,
  1629. EEPROM_LED_POLARITY_GPIO_1));
  1630. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1631. rt2x00_get_field16(eeprom,
  1632. EEPROM_LED_POLARITY_GPIO_2));
  1633. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1634. rt2x00_get_field16(eeprom,
  1635. EEPROM_LED_POLARITY_GPIO_3));
  1636. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1637. rt2x00_get_field16(eeprom,
  1638. EEPROM_LED_POLARITY_GPIO_4));
  1639. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  1640. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1641. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  1642. rt2x00_get_field16(eeprom,
  1643. EEPROM_LED_POLARITY_RDY_G));
  1644. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  1645. rt2x00_get_field16(eeprom,
  1646. EEPROM_LED_POLARITY_RDY_A));
  1647. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1648. return 0;
  1649. }
  1650. /*
  1651. * RF value list for RF2528
  1652. * Supports: 2.4 GHz
  1653. */
  1654. static const struct rf_channel rf_vals_bg_2528[] = {
  1655. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1656. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1657. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1658. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1659. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1660. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1661. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1662. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1663. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1664. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1665. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1666. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1667. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1668. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1669. };
  1670. /*
  1671. * RF value list for RF5226
  1672. * Supports: 2.4 GHz & 5.2 GHz
  1673. */
  1674. static const struct rf_channel rf_vals_5226[] = {
  1675. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1676. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1677. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1678. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1679. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1680. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1681. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1682. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1683. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1684. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1685. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1686. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1687. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1688. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1689. /* 802.11 UNI / HyperLan 2 */
  1690. { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
  1691. { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
  1692. { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
  1693. { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
  1694. { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
  1695. { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
  1696. { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
  1697. { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
  1698. /* 802.11 HyperLan 2 */
  1699. { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
  1700. { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
  1701. { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
  1702. { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
  1703. { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
  1704. { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
  1705. { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
  1706. { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
  1707. { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
  1708. { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
  1709. /* 802.11 UNII */
  1710. { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
  1711. { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
  1712. { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
  1713. { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
  1714. { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
  1715. { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
  1716. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1717. { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
  1718. { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
  1719. { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
  1720. { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
  1721. };
  1722. /*
  1723. * RF value list for RF5225 & RF2527
  1724. * Supports: 2.4 GHz & 5.2 GHz
  1725. */
  1726. static const struct rf_channel rf_vals_5225_2527[] = {
  1727. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1728. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1729. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1730. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1731. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1732. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1733. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1734. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1735. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1736. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1737. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1738. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1739. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1740. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1741. /* 802.11 UNI / HyperLan 2 */
  1742. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1743. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1744. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1745. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1746. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1747. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1748. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1749. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1750. /* 802.11 HyperLan 2 */
  1751. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1752. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1753. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1754. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1755. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1756. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1757. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1758. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1759. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1760. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1761. /* 802.11 UNII */
  1762. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1763. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1764. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1765. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1766. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1767. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1768. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1769. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1770. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1771. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1772. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1773. };
  1774. static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1775. {
  1776. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1777. struct channel_info *info;
  1778. char *tx_power;
  1779. unsigned int i;
  1780. /*
  1781. * Initialize all hw fields.
  1782. *
  1783. * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING unless we are
  1784. * capable of sending the buffered frames out after the DTIM
  1785. * transmission using rt2x00lib_beacondone. This will send out
  1786. * multicast and broadcast traffic immediately instead of buffering it
  1787. * infinitly and thus dropping it after some time.
  1788. */
  1789. rt2x00dev->hw->flags =
  1790. IEEE80211_HW_SIGNAL_DBM |
  1791. IEEE80211_HW_SUPPORTS_PS |
  1792. IEEE80211_HW_PS_NULLFUNC_STACK;
  1793. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1794. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1795. rt2x00_eeprom_addr(rt2x00dev,
  1796. EEPROM_MAC_ADDR_0));
  1797. /*
  1798. * Initialize hw_mode information.
  1799. */
  1800. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1801. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1802. if (rt2x00_rf(rt2x00dev, RF2528)) {
  1803. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
  1804. spec->channels = rf_vals_bg_2528;
  1805. } else if (rt2x00_rf(rt2x00dev, RF5226)) {
  1806. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1807. spec->num_channels = ARRAY_SIZE(rf_vals_5226);
  1808. spec->channels = rf_vals_5226;
  1809. } else if (rt2x00_rf(rt2x00dev, RF2527)) {
  1810. spec->num_channels = 14;
  1811. spec->channels = rf_vals_5225_2527;
  1812. } else if (rt2x00_rf(rt2x00dev, RF5225)) {
  1813. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1814. spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527);
  1815. spec->channels = rf_vals_5225_2527;
  1816. }
  1817. /*
  1818. * Create channel information array
  1819. */
  1820. info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
  1821. if (!info)
  1822. return -ENOMEM;
  1823. spec->channels_info = info;
  1824. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1825. for (i = 0; i < 14; i++) {
  1826. info[i].max_power = MAX_TXPOWER;
  1827. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1828. }
  1829. if (spec->num_channels > 14) {
  1830. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1831. for (i = 14; i < spec->num_channels; i++) {
  1832. info[i].max_power = MAX_TXPOWER;
  1833. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1834. }
  1835. }
  1836. return 0;
  1837. }
  1838. static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1839. {
  1840. int retval;
  1841. /*
  1842. * Allocate eeprom data.
  1843. */
  1844. retval = rt73usb_validate_eeprom(rt2x00dev);
  1845. if (retval)
  1846. return retval;
  1847. retval = rt73usb_init_eeprom(rt2x00dev);
  1848. if (retval)
  1849. return retval;
  1850. /*
  1851. * Initialize hw specifications.
  1852. */
  1853. retval = rt73usb_probe_hw_mode(rt2x00dev);
  1854. if (retval)
  1855. return retval;
  1856. /*
  1857. * This device has multiple filters for control frames,
  1858. * but has no a separate filter for PS Poll frames.
  1859. */
  1860. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  1861. /*
  1862. * This device requires firmware.
  1863. */
  1864. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  1865. if (!modparam_nohwcrypt)
  1866. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  1867. __set_bit(DRIVER_SUPPORT_LINK_TUNING, &rt2x00dev->flags);
  1868. __set_bit(DRIVER_SUPPORT_WATCHDOG, &rt2x00dev->flags);
  1869. /*
  1870. * Set the rssi offset.
  1871. */
  1872. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1873. return 0;
  1874. }
  1875. /*
  1876. * IEEE80211 stack callback functions.
  1877. */
  1878. static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  1879. const struct ieee80211_tx_queue_params *params)
  1880. {
  1881. struct rt2x00_dev *rt2x00dev = hw->priv;
  1882. struct data_queue *queue;
  1883. struct rt2x00_field32 field;
  1884. int retval;
  1885. u32 reg;
  1886. u32 offset;
  1887. /*
  1888. * First pass the configuration through rt2x00lib, that will
  1889. * update the queue settings and validate the input. After that
  1890. * we are free to update the registers based on the value
  1891. * in the queue parameter.
  1892. */
  1893. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  1894. if (retval)
  1895. return retval;
  1896. /*
  1897. * We only need to perform additional register initialization
  1898. * for WMM queues/
  1899. */
  1900. if (queue_idx >= 4)
  1901. return 0;
  1902. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  1903. /* Update WMM TXOP register */
  1904. offset = AC_TXOP_CSR0 + (sizeof(u32) * (!!(queue_idx & 2)));
  1905. field.bit_offset = (queue_idx & 1) * 16;
  1906. field.bit_mask = 0xffff << field.bit_offset;
  1907. rt2x00usb_register_read(rt2x00dev, offset, &reg);
  1908. rt2x00_set_field32(&reg, field, queue->txop);
  1909. rt2x00usb_register_write(rt2x00dev, offset, reg);
  1910. /* Update WMM registers */
  1911. field.bit_offset = queue_idx * 4;
  1912. field.bit_mask = 0xf << field.bit_offset;
  1913. rt2x00usb_register_read(rt2x00dev, AIFSN_CSR, &reg);
  1914. rt2x00_set_field32(&reg, field, queue->aifs);
  1915. rt2x00usb_register_write(rt2x00dev, AIFSN_CSR, reg);
  1916. rt2x00usb_register_read(rt2x00dev, CWMIN_CSR, &reg);
  1917. rt2x00_set_field32(&reg, field, queue->cw_min);
  1918. rt2x00usb_register_write(rt2x00dev, CWMIN_CSR, reg);
  1919. rt2x00usb_register_read(rt2x00dev, CWMAX_CSR, &reg);
  1920. rt2x00_set_field32(&reg, field, queue->cw_max);
  1921. rt2x00usb_register_write(rt2x00dev, CWMAX_CSR, reg);
  1922. return 0;
  1923. }
  1924. static u64 rt73usb_get_tsf(struct ieee80211_hw *hw)
  1925. {
  1926. struct rt2x00_dev *rt2x00dev = hw->priv;
  1927. u64 tsf;
  1928. u32 reg;
  1929. rt2x00usb_register_read(rt2x00dev, TXRX_CSR13, &reg);
  1930. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  1931. rt2x00usb_register_read(rt2x00dev, TXRX_CSR12, &reg);
  1932. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  1933. return tsf;
  1934. }
  1935. static const struct ieee80211_ops rt73usb_mac80211_ops = {
  1936. .tx = rt2x00mac_tx,
  1937. .start = rt2x00mac_start,
  1938. .stop = rt2x00mac_stop,
  1939. .add_interface = rt2x00mac_add_interface,
  1940. .remove_interface = rt2x00mac_remove_interface,
  1941. .config = rt2x00mac_config,
  1942. .configure_filter = rt2x00mac_configure_filter,
  1943. .set_tim = rt2x00mac_set_tim,
  1944. .set_key = rt2x00mac_set_key,
  1945. .sw_scan_start = rt2x00mac_sw_scan_start,
  1946. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  1947. .get_stats = rt2x00mac_get_stats,
  1948. .bss_info_changed = rt2x00mac_bss_info_changed,
  1949. .conf_tx = rt73usb_conf_tx,
  1950. .get_tsf = rt73usb_get_tsf,
  1951. .rfkill_poll = rt2x00mac_rfkill_poll,
  1952. .flush = rt2x00mac_flush,
  1953. };
  1954. static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
  1955. .probe_hw = rt73usb_probe_hw,
  1956. .get_firmware_name = rt73usb_get_firmware_name,
  1957. .check_firmware = rt73usb_check_firmware,
  1958. .load_firmware = rt73usb_load_firmware,
  1959. .initialize = rt2x00usb_initialize,
  1960. .uninitialize = rt2x00usb_uninitialize,
  1961. .clear_entry = rt2x00usb_clear_entry,
  1962. .set_device_state = rt73usb_set_device_state,
  1963. .rfkill_poll = rt73usb_rfkill_poll,
  1964. .link_stats = rt73usb_link_stats,
  1965. .reset_tuner = rt73usb_reset_tuner,
  1966. .link_tuner = rt73usb_link_tuner,
  1967. .watchdog = rt2x00usb_watchdog,
  1968. .write_tx_desc = rt73usb_write_tx_desc,
  1969. .write_beacon = rt73usb_write_beacon,
  1970. .get_tx_data_len = rt73usb_get_tx_data_len,
  1971. .kick_tx_queue = rt2x00usb_kick_tx_queue,
  1972. .kill_tx_queue = rt73usb_kill_tx_queue,
  1973. .fill_rxdone = rt73usb_fill_rxdone,
  1974. .config_shared_key = rt73usb_config_shared_key,
  1975. .config_pairwise_key = rt73usb_config_pairwise_key,
  1976. .config_filter = rt73usb_config_filter,
  1977. .config_intf = rt73usb_config_intf,
  1978. .config_erp = rt73usb_config_erp,
  1979. .config_ant = rt73usb_config_ant,
  1980. .config = rt73usb_config,
  1981. };
  1982. static const struct data_queue_desc rt73usb_queue_rx = {
  1983. .entry_num = 32,
  1984. .data_size = DATA_FRAME_SIZE,
  1985. .desc_size = RXD_DESC_SIZE,
  1986. .priv_size = sizeof(struct queue_entry_priv_usb),
  1987. };
  1988. static const struct data_queue_desc rt73usb_queue_tx = {
  1989. .entry_num = 32,
  1990. .data_size = DATA_FRAME_SIZE,
  1991. .desc_size = TXD_DESC_SIZE,
  1992. .priv_size = sizeof(struct queue_entry_priv_usb),
  1993. };
  1994. static const struct data_queue_desc rt73usb_queue_bcn = {
  1995. .entry_num = 4,
  1996. .data_size = MGMT_FRAME_SIZE,
  1997. .desc_size = TXINFO_SIZE,
  1998. .priv_size = sizeof(struct queue_entry_priv_usb),
  1999. };
  2000. static const struct rt2x00_ops rt73usb_ops = {
  2001. .name = KBUILD_MODNAME,
  2002. .max_sta_intf = 1,
  2003. .max_ap_intf = 4,
  2004. .eeprom_size = EEPROM_SIZE,
  2005. .rf_size = RF_SIZE,
  2006. .tx_queues = NUM_TX_QUEUES,
  2007. .extra_tx_headroom = TXD_DESC_SIZE,
  2008. .rx = &rt73usb_queue_rx,
  2009. .tx = &rt73usb_queue_tx,
  2010. .bcn = &rt73usb_queue_bcn,
  2011. .lib = &rt73usb_rt2x00_ops,
  2012. .hw = &rt73usb_mac80211_ops,
  2013. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2014. .debugfs = &rt73usb_rt2x00debug,
  2015. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2016. };
  2017. /*
  2018. * rt73usb module information.
  2019. */
  2020. static struct usb_device_id rt73usb_device_table[] = {
  2021. /* AboCom */
  2022. { USB_DEVICE(0x07b8, 0xb21b), USB_DEVICE_DATA(&rt73usb_ops) },
  2023. { USB_DEVICE(0x07b8, 0xb21c), USB_DEVICE_DATA(&rt73usb_ops) },
  2024. { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops) },
  2025. { USB_DEVICE(0x07b8, 0xb21e), USB_DEVICE_DATA(&rt73usb_ops) },
  2026. { USB_DEVICE(0x07b8, 0xb21f), USB_DEVICE_DATA(&rt73usb_ops) },
  2027. /* AL */
  2028. { USB_DEVICE(0x14b2, 0x3c10), USB_DEVICE_DATA(&rt73usb_ops) },
  2029. /* Amigo */
  2030. { USB_DEVICE(0x148f, 0x9021), USB_DEVICE_DATA(&rt73usb_ops) },
  2031. { USB_DEVICE(0x0eb0, 0x9021), USB_DEVICE_DATA(&rt73usb_ops) },
  2032. /* AMIT */
  2033. { USB_DEVICE(0x18c5, 0x0002), USB_DEVICE_DATA(&rt73usb_ops) },
  2034. /* Askey */
  2035. { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops) },
  2036. /* ASUS */
  2037. { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops) },
  2038. { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops) },
  2039. /* Belkin */
  2040. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops) },
  2041. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops) },
  2042. { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops) },
  2043. { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops) },
  2044. /* Billionton */
  2045. { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops) },
  2046. { USB_DEVICE(0x08dd, 0x0120), USB_DEVICE_DATA(&rt73usb_ops) },
  2047. /* Buffalo */
  2048. { USB_DEVICE(0x0411, 0x00d8), USB_DEVICE_DATA(&rt73usb_ops) },
  2049. { USB_DEVICE(0x0411, 0x00d9), USB_DEVICE_DATA(&rt73usb_ops) },
  2050. { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops) },
  2051. { USB_DEVICE(0x0411, 0x0116), USB_DEVICE_DATA(&rt73usb_ops) },
  2052. { USB_DEVICE(0x0411, 0x0119), USB_DEVICE_DATA(&rt73usb_ops) },
  2053. { USB_DEVICE(0x0411, 0x0137), USB_DEVICE_DATA(&rt73usb_ops) },
  2054. /* CEIVA */
  2055. { USB_DEVICE(0x178d, 0x02be), USB_DEVICE_DATA(&rt73usb_ops) },
  2056. /* CNet */
  2057. { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops) },
  2058. { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops) },
  2059. /* Conceptronic */
  2060. { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops) },
  2061. /* Corega */
  2062. { USB_DEVICE(0x07aa, 0x002e), USB_DEVICE_DATA(&rt73usb_ops) },
  2063. /* D-Link */
  2064. { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops) },
  2065. { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops) },
  2066. { USB_DEVICE(0x07d1, 0x3c06), USB_DEVICE_DATA(&rt73usb_ops) },
  2067. { USB_DEVICE(0x07d1, 0x3c07), USB_DEVICE_DATA(&rt73usb_ops) },
  2068. /* Edimax */
  2069. { USB_DEVICE(0x7392, 0x7318), USB_DEVICE_DATA(&rt73usb_ops) },
  2070. { USB_DEVICE(0x7392, 0x7618), USB_DEVICE_DATA(&rt73usb_ops) },
  2071. /* EnGenius */
  2072. { USB_DEVICE(0x1740, 0x3701), USB_DEVICE_DATA(&rt73usb_ops) },
  2073. /* Gemtek */
  2074. { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops) },
  2075. /* Gigabyte */
  2076. { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops) },
  2077. { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops) },
  2078. /* Huawei-3Com */
  2079. { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops) },
  2080. /* Hercules */
  2081. { USB_DEVICE(0x06f8, 0xe002), USB_DEVICE_DATA(&rt73usb_ops) },
  2082. { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops) },
  2083. { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops) },
  2084. /* Linksys */
  2085. { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
  2086. { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
  2087. { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) },
  2088. /* MSI */
  2089. { USB_DEVICE(0x0db0, 0x4600), USB_DEVICE_DATA(&rt73usb_ops) },
  2090. { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
  2091. { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
  2092. { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) },
  2093. { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) },
  2094. /* Ovislink */
  2095. { USB_DEVICE(0x1b75, 0x7318), USB_DEVICE_DATA(&rt73usb_ops) },
  2096. /* Ralink */
  2097. { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) },
  2098. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) },
  2099. { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) },
  2100. /* Qcom */
  2101. { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) },
  2102. { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) },
  2103. { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops) },
  2104. /* Samsung */
  2105. { USB_DEVICE(0x04e8, 0x4471), USB_DEVICE_DATA(&rt73usb_ops) },
  2106. /* Senao */
  2107. { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops) },
  2108. /* Sitecom */
  2109. { USB_DEVICE(0x0df6, 0x0024), USB_DEVICE_DATA(&rt73usb_ops) },
  2110. { USB_DEVICE(0x0df6, 0x0027), USB_DEVICE_DATA(&rt73usb_ops) },
  2111. { USB_DEVICE(0x0df6, 0x002f), USB_DEVICE_DATA(&rt73usb_ops) },
  2112. { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops) },
  2113. { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops) },
  2114. /* Surecom */
  2115. { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops) },
  2116. /* Tilgin */
  2117. { USB_DEVICE(0x6933, 0x5001), USB_DEVICE_DATA(&rt73usb_ops) },
  2118. /* Philips */
  2119. { USB_DEVICE(0x0471, 0x200a), USB_DEVICE_DATA(&rt73usb_ops) },
  2120. /* Planex */
  2121. { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) },
  2122. { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) },
  2123. /* WideTell */
  2124. { USB_DEVICE(0x7167, 0x3840), USB_DEVICE_DATA(&rt73usb_ops) },
  2125. /* Zcom */
  2126. { USB_DEVICE(0x0cde, 0x001c), USB_DEVICE_DATA(&rt73usb_ops) },
  2127. /* ZyXEL */
  2128. { USB_DEVICE(0x0586, 0x3415), USB_DEVICE_DATA(&rt73usb_ops) },
  2129. { 0, }
  2130. };
  2131. MODULE_AUTHOR(DRV_PROJECT);
  2132. MODULE_VERSION(DRV_VERSION);
  2133. MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
  2134. MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
  2135. MODULE_DEVICE_TABLE(usb, rt73usb_device_table);
  2136. MODULE_FIRMWARE(FIRMWARE_RT2571);
  2137. MODULE_LICENSE("GPL");
  2138. static struct usb_driver rt73usb_driver = {
  2139. .name = KBUILD_MODNAME,
  2140. .id_table = rt73usb_device_table,
  2141. .probe = rt2x00usb_probe,
  2142. .disconnect = rt2x00usb_disconnect,
  2143. .suspend = rt2x00usb_suspend,
  2144. .resume = rt2x00usb_resume,
  2145. };
  2146. static int __init rt73usb_init(void)
  2147. {
  2148. return usb_register(&rt73usb_driver);
  2149. }
  2150. static void __exit rt73usb_exit(void)
  2151. {
  2152. usb_deregister(&rt73usb_driver);
  2153. }
  2154. module_init(rt73usb_init);
  2155. module_exit(rt73usb_exit);