rt73usb.c 76 KB

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