rt73usb.c 75 KB

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