rt73usb.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  1. /*
  2. Copyright (C) 2004 - 2007 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. /*
  23. * Set enviroment defines for rt2x00.h
  24. */
  25. #define DRV_NAME "rt73usb"
  26. #include <linux/delay.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/init.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/usb.h>
  32. #include "rt2x00.h"
  33. #include "rt2x00usb.h"
  34. #include "rt73usb.h"
  35. /*
  36. * Register access.
  37. * All access to the CSR registers will go through the methods
  38. * rt73usb_register_read and rt73usb_register_write.
  39. * BBP and RF register require indirect register access,
  40. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  41. * These indirect registers work with busy bits,
  42. * and we will try maximal REGISTER_BUSY_COUNT times to access
  43. * the register while taking a REGISTER_BUSY_DELAY us delay
  44. * between each attampt. When the busy bit is still set at that time,
  45. * the access attempt is considered to have failed,
  46. * and we will print an error.
  47. */
  48. static inline void rt73usb_register_read(const struct rt2x00_dev *rt2x00dev,
  49. const unsigned int offset, u32 *value)
  50. {
  51. __le32 reg;
  52. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  53. USB_VENDOR_REQUEST_IN, offset,
  54. &reg, sizeof(u32), REGISTER_TIMEOUT);
  55. *value = le32_to_cpu(reg);
  56. }
  57. static inline void rt73usb_register_multiread(const struct rt2x00_dev
  58. *rt2x00dev,
  59. const unsigned int offset,
  60. void *value, const u32 length)
  61. {
  62. int timeout = REGISTER_TIMEOUT * (length / sizeof(u32));
  63. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  64. USB_VENDOR_REQUEST_IN, offset,
  65. value, length, timeout);
  66. }
  67. static inline void rt73usb_register_write(const struct rt2x00_dev *rt2x00dev,
  68. const unsigned int offset, u32 value)
  69. {
  70. __le32 reg = cpu_to_le32(value);
  71. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  72. USB_VENDOR_REQUEST_OUT, offset,
  73. &reg, sizeof(u32), REGISTER_TIMEOUT);
  74. }
  75. static inline void rt73usb_register_multiwrite(const struct rt2x00_dev
  76. *rt2x00dev,
  77. const unsigned int offset,
  78. void *value, const u32 length)
  79. {
  80. int timeout = REGISTER_TIMEOUT * (length / sizeof(u32));
  81. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  82. USB_VENDOR_REQUEST_OUT, offset,
  83. value, length, timeout);
  84. }
  85. static u32 rt73usb_bbp_check(const struct rt2x00_dev *rt2x00dev)
  86. {
  87. u32 reg;
  88. unsigned int i;
  89. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  90. rt73usb_register_read(rt2x00dev, PHY_CSR3, &reg);
  91. if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  92. break;
  93. udelay(REGISTER_BUSY_DELAY);
  94. }
  95. return reg;
  96. }
  97. static void rt73usb_bbp_write(const struct rt2x00_dev *rt2x00dev,
  98. const unsigned int word, const u8 value)
  99. {
  100. u32 reg;
  101. /*
  102. * Wait until the BBP becomes ready.
  103. */
  104. reg = rt73usb_bbp_check(rt2x00dev);
  105. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  106. ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
  107. return;
  108. }
  109. /*
  110. * Write the data into the BBP.
  111. */
  112. reg = 0;
  113. rt2x00_set_field32(&reg, PHY_CSR3_VALUE, value);
  114. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  115. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  116. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
  117. rt73usb_register_write(rt2x00dev, PHY_CSR3, reg);
  118. }
  119. static void rt73usb_bbp_read(const struct rt2x00_dev *rt2x00dev,
  120. const unsigned int word, u8 *value)
  121. {
  122. u32 reg;
  123. /*
  124. * Wait until the BBP becomes ready.
  125. */
  126. reg = rt73usb_bbp_check(rt2x00dev);
  127. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  128. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  129. return;
  130. }
  131. /*
  132. * Write the request into the BBP.
  133. */
  134. reg = 0;
  135. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  136. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  137. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
  138. rt73usb_register_write(rt2x00dev, PHY_CSR3, reg);
  139. /*
  140. * Wait until the BBP becomes ready.
  141. */
  142. reg = rt73usb_bbp_check(rt2x00dev);
  143. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  144. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  145. *value = 0xff;
  146. return;
  147. }
  148. *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
  149. }
  150. static void rt73usb_rf_write(const struct rt2x00_dev *rt2x00dev,
  151. const unsigned int word, const u32 value)
  152. {
  153. u32 reg;
  154. unsigned int i;
  155. if (!word)
  156. return;
  157. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  158. rt73usb_register_read(rt2x00dev, PHY_CSR4, &reg);
  159. if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY))
  160. goto rf_write;
  161. udelay(REGISTER_BUSY_DELAY);
  162. }
  163. ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n");
  164. return;
  165. rf_write:
  166. reg = 0;
  167. rt2x00_set_field32(&reg, PHY_CSR4_VALUE, value);
  168. /*
  169. * RF5225 and RF2527 contain 21 bits per RF register value,
  170. * all others contain 20 bits.
  171. */
  172. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS,
  173. 20 + !!(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  174. rt2x00_rf(&rt2x00dev->chip, RF2527)));
  175. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  176. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  177. rt73usb_register_write(rt2x00dev, PHY_CSR4, reg);
  178. rt2x00_rf_write(rt2x00dev, word, value);
  179. }
  180. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  181. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
  182. static void rt73usb_read_csr(const struct rt2x00_dev *rt2x00dev,
  183. const unsigned int word, u32 *data)
  184. {
  185. rt73usb_register_read(rt2x00dev, CSR_OFFSET(word), data);
  186. }
  187. static void rt73usb_write_csr(const struct rt2x00_dev *rt2x00dev,
  188. const unsigned int word, u32 data)
  189. {
  190. rt73usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
  191. }
  192. static const struct rt2x00debug rt73usb_rt2x00debug = {
  193. .owner = THIS_MODULE,
  194. .csr = {
  195. .read = rt73usb_read_csr,
  196. .write = rt73usb_write_csr,
  197. .word_size = sizeof(u32),
  198. .word_count = CSR_REG_SIZE / sizeof(u32),
  199. },
  200. .eeprom = {
  201. .read = rt2x00_eeprom_read,
  202. .write = rt2x00_eeprom_write,
  203. .word_size = sizeof(u16),
  204. .word_count = EEPROM_SIZE / sizeof(u16),
  205. },
  206. .bbp = {
  207. .read = rt73usb_bbp_read,
  208. .write = rt73usb_bbp_write,
  209. .word_size = sizeof(u8),
  210. .word_count = BBP_SIZE / sizeof(u8),
  211. },
  212. .rf = {
  213. .read = rt2x00_rf_read,
  214. .write = rt73usb_rf_write,
  215. .word_size = sizeof(u32),
  216. .word_count = RF_SIZE / sizeof(u32),
  217. },
  218. };
  219. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  220. /*
  221. * Configuration handlers.
  222. */
  223. static void rt73usb_config_mac_addr(struct rt2x00_dev *rt2x00dev, __le32 *mac)
  224. {
  225. u32 tmp;
  226. tmp = le32_to_cpu(mac[1]);
  227. rt2x00_set_field32(&tmp, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  228. mac[1] = cpu_to_le32(tmp);
  229. rt73usb_register_multiwrite(rt2x00dev, MAC_CSR2, mac,
  230. (2 * sizeof(__le32)));
  231. }
  232. static void rt73usb_config_bssid(struct rt2x00_dev *rt2x00dev, __le32 *bssid)
  233. {
  234. u32 tmp;
  235. tmp = le32_to_cpu(bssid[1]);
  236. rt2x00_set_field32(&tmp, MAC_CSR5_BSS_ID_MASK, 3);
  237. bssid[1] = cpu_to_le32(tmp);
  238. rt73usb_register_multiwrite(rt2x00dev, MAC_CSR4, bssid,
  239. (2 * sizeof(__le32)));
  240. }
  241. static void rt73usb_config_type(struct rt2x00_dev *rt2x00dev, const int type,
  242. const int tsf_sync)
  243. {
  244. u32 reg;
  245. /*
  246. * Clear current synchronisation setup.
  247. * For the Beacon base registers we only need to clear
  248. * the first byte since that byte contains the VALID and OWNER
  249. * bits which (when set to 0) will invalidate the entire beacon.
  250. */
  251. rt73usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  252. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  253. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  254. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  255. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  256. /*
  257. * Enable synchronisation.
  258. */
  259. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  260. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  261. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  262. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  263. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, tsf_sync);
  264. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  265. }
  266. static void rt73usb_config_preamble(struct rt2x00_dev *rt2x00dev,
  267. const int short_preamble,
  268. const int ack_timeout,
  269. const int ack_consume_time)
  270. {
  271. u32 reg;
  272. /*
  273. * When in atomic context, reschedule and let rt2x00lib
  274. * call this function again.
  275. */
  276. if (in_atomic()) {
  277. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work);
  278. return;
  279. }
  280. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  281. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, ack_timeout);
  282. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  283. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  284. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  285. !!short_preamble);
  286. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  287. }
  288. static void rt73usb_config_phymode(struct rt2x00_dev *rt2x00dev,
  289. const int basic_rate_mask)
  290. {
  291. rt73usb_register_write(rt2x00dev, TXRX_CSR5, basic_rate_mask);
  292. }
  293. static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
  294. struct rf_channel *rf, const int txpower)
  295. {
  296. u8 r3;
  297. u8 r94;
  298. u8 smart;
  299. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  300. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  301. smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  302. rt2x00_rf(&rt2x00dev->chip, RF2527));
  303. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  304. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  305. rt73usb_bbp_write(rt2x00dev, 3, r3);
  306. r94 = 6;
  307. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  308. r94 += txpower - MAX_TXPOWER;
  309. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  310. r94 += txpower;
  311. rt73usb_bbp_write(rt2x00dev, 94, r94);
  312. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  313. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  314. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  315. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  316. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  317. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  318. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  319. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  320. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  321. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  322. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  323. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  324. udelay(10);
  325. }
  326. static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  327. const int txpower)
  328. {
  329. struct rf_channel rf;
  330. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  331. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  332. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  333. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  334. rt73usb_config_channel(rt2x00dev, &rf, txpower);
  335. }
  336. static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  337. struct antenna_setup *ant)
  338. {
  339. u8 r3;
  340. u8 r4;
  341. u8 r77;
  342. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  343. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  344. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  345. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  346. switch (ant->rx) {
  347. case ANTENNA_SW_DIVERSITY:
  348. case ANTENNA_HW_DIVERSITY:
  349. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
  350. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  351. !!(rt2x00dev->curr_hwmode != HWMODE_A));
  352. break;
  353. case ANTENNA_A:
  354. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  355. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  356. if (rt2x00dev->curr_hwmode == HWMODE_A)
  357. rt2x00_set_field8(&r77, BBP_R77_PAIR, 0);
  358. else
  359. rt2x00_set_field8(&r77, BBP_R77_PAIR, 3);
  360. break;
  361. case ANTENNA_B:
  362. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  363. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  364. if (rt2x00dev->curr_hwmode == HWMODE_A)
  365. rt2x00_set_field8(&r77, BBP_R77_PAIR, 3);
  366. else
  367. rt2x00_set_field8(&r77, BBP_R77_PAIR, 0);
  368. break;
  369. }
  370. rt73usb_bbp_write(rt2x00dev, 77, r77);
  371. rt73usb_bbp_write(rt2x00dev, 3, r3);
  372. rt73usb_bbp_write(rt2x00dev, 4, r4);
  373. }
  374. static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  375. struct antenna_setup *ant)
  376. {
  377. u8 r3;
  378. u8 r4;
  379. u8 r77;
  380. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  381. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  382. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  383. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  384. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  385. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  386. switch (ant->rx) {
  387. case ANTENNA_SW_DIVERSITY:
  388. case ANTENNA_HW_DIVERSITY:
  389. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
  390. break;
  391. case ANTENNA_A:
  392. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  393. rt2x00_set_field8(&r77, BBP_R77_PAIR, 3);
  394. break;
  395. case ANTENNA_B:
  396. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  397. rt2x00_set_field8(&r77, BBP_R77_PAIR, 0);
  398. break;
  399. }
  400. rt73usb_bbp_write(rt2x00dev, 77, r77);
  401. rt73usb_bbp_write(rt2x00dev, 3, r3);
  402. rt73usb_bbp_write(rt2x00dev, 4, r4);
  403. }
  404. struct antenna_sel {
  405. u8 word;
  406. /*
  407. * value[0] -> non-LNA
  408. * value[1] -> LNA
  409. */
  410. u8 value[2];
  411. };
  412. static const struct antenna_sel antenna_sel_a[] = {
  413. { 96, { 0x58, 0x78 } },
  414. { 104, { 0x38, 0x48 } },
  415. { 75, { 0xfe, 0x80 } },
  416. { 86, { 0xfe, 0x80 } },
  417. { 88, { 0xfe, 0x80 } },
  418. { 35, { 0x60, 0x60 } },
  419. { 97, { 0x58, 0x58 } },
  420. { 98, { 0x58, 0x58 } },
  421. };
  422. static const struct antenna_sel antenna_sel_bg[] = {
  423. { 96, { 0x48, 0x68 } },
  424. { 104, { 0x2c, 0x3c } },
  425. { 75, { 0xfe, 0x80 } },
  426. { 86, { 0xfe, 0x80 } },
  427. { 88, { 0xfe, 0x80 } },
  428. { 35, { 0x50, 0x50 } },
  429. { 97, { 0x48, 0x48 } },
  430. { 98, { 0x48, 0x48 } },
  431. };
  432. static void rt73usb_config_antenna(struct rt2x00_dev *rt2x00dev,
  433. struct antenna_setup *ant)
  434. {
  435. const struct antenna_sel *sel;
  436. unsigned int lna;
  437. unsigned int i;
  438. u32 reg;
  439. rt73usb_register_read(rt2x00dev, PHY_CSR0, &reg);
  440. if (rt2x00dev->curr_hwmode == HWMODE_A) {
  441. sel = antenna_sel_a;
  442. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  443. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG, 0);
  444. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A, 1);
  445. } else {
  446. sel = antenna_sel_bg;
  447. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  448. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG, 1);
  449. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A, 0);
  450. }
  451. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  452. rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  453. rt73usb_register_write(rt2x00dev, PHY_CSR0, reg);
  454. if (rt2x00_rf(&rt2x00dev->chip, RF5226) ||
  455. rt2x00_rf(&rt2x00dev->chip, RF5225))
  456. rt73usb_config_antenna_5x(rt2x00dev, ant);
  457. else if (rt2x00_rf(&rt2x00dev->chip, RF2528) ||
  458. rt2x00_rf(&rt2x00dev->chip, RF2527))
  459. rt73usb_config_antenna_2x(rt2x00dev, ant);
  460. }
  461. static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev,
  462. struct rt2x00lib_conf *libconf)
  463. {
  464. u32 reg;
  465. rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  466. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, libconf->slot_time);
  467. rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
  468. rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  469. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, libconf->sifs);
  470. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  471. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, libconf->eifs);
  472. rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
  473. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  474. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  475. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  476. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  477. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  478. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  479. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  480. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  481. libconf->conf->beacon_int * 16);
  482. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  483. }
  484. static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
  485. const unsigned int flags,
  486. struct rt2x00lib_conf *libconf)
  487. {
  488. if (flags & CONFIG_UPDATE_PHYMODE)
  489. rt73usb_config_phymode(rt2x00dev, libconf->basic_rates);
  490. if (flags & CONFIG_UPDATE_CHANNEL)
  491. rt73usb_config_channel(rt2x00dev, &libconf->rf,
  492. libconf->conf->power_level);
  493. if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
  494. rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  495. if (flags & CONFIG_UPDATE_ANTENNA)
  496. rt73usb_config_antenna(rt2x00dev, &libconf->ant);
  497. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  498. rt73usb_config_duration(rt2x00dev, libconf);
  499. }
  500. /*
  501. * LED functions.
  502. */
  503. static void rt73usb_enable_led(struct rt2x00_dev *rt2x00dev)
  504. {
  505. u32 reg;
  506. rt73usb_register_read(rt2x00dev, MAC_CSR14, &reg);
  507. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, 70);
  508. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, 30);
  509. rt73usb_register_write(rt2x00dev, MAC_CSR14, reg);
  510. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 1);
  511. if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A)
  512. rt2x00_set_field16(&rt2x00dev->led_reg,
  513. MCU_LEDCS_LINK_A_STATUS, 1);
  514. else
  515. rt2x00_set_field16(&rt2x00dev->led_reg,
  516. MCU_LEDCS_LINK_BG_STATUS, 1);
  517. rt2x00usb_vendor_request_sw(rt2x00dev, USB_LED_CONTROL, 0x0000,
  518. rt2x00dev->led_reg, REGISTER_TIMEOUT);
  519. }
  520. static void rt73usb_disable_led(struct rt2x00_dev *rt2x00dev)
  521. {
  522. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_RADIO_STATUS, 0);
  523. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_BG_STATUS, 0);
  524. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LINK_A_STATUS, 0);
  525. rt2x00usb_vendor_request_sw(rt2x00dev, USB_LED_CONTROL, 0x0000,
  526. rt2x00dev->led_reg, REGISTER_TIMEOUT);
  527. }
  528. static void rt73usb_activity_led(struct rt2x00_dev *rt2x00dev, int rssi)
  529. {
  530. u32 led;
  531. if (rt2x00dev->led_mode != LED_MODE_SIGNAL_STRENGTH)
  532. return;
  533. /*
  534. * Led handling requires a positive value for the rssi,
  535. * to do that correctly we need to add the correction.
  536. */
  537. rssi += rt2x00dev->rssi_offset;
  538. if (rssi <= 30)
  539. led = 0;
  540. else if (rssi <= 39)
  541. led = 1;
  542. else if (rssi <= 49)
  543. led = 2;
  544. else if (rssi <= 53)
  545. led = 3;
  546. else if (rssi <= 63)
  547. led = 4;
  548. else
  549. led = 5;
  550. rt2x00usb_vendor_request_sw(rt2x00dev, USB_LED_CONTROL, led,
  551. rt2x00dev->led_reg, REGISTER_TIMEOUT);
  552. }
  553. /*
  554. * Link tuning
  555. */
  556. static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev,
  557. struct link_qual *qual)
  558. {
  559. u32 reg;
  560. /*
  561. * Update FCS error count from register.
  562. */
  563. rt73usb_register_read(rt2x00dev, STA_CSR0, &reg);
  564. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  565. /*
  566. * Update False CCA count from register.
  567. */
  568. rt73usb_register_read(rt2x00dev, STA_CSR1, &reg);
  569. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  570. }
  571. static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
  572. {
  573. rt73usb_bbp_write(rt2x00dev, 17, 0x20);
  574. rt2x00dev->link.vgc_level = 0x20;
  575. }
  576. static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev)
  577. {
  578. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  579. u8 r17;
  580. u8 up_bound;
  581. u8 low_bound;
  582. /*
  583. * Update Led strength
  584. */
  585. rt73usb_activity_led(rt2x00dev, rssi);
  586. rt73usb_bbp_read(rt2x00dev, 17, &r17);
  587. /*
  588. * Determine r17 bounds.
  589. */
  590. if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) {
  591. low_bound = 0x28;
  592. up_bound = 0x48;
  593. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  594. low_bound += 0x10;
  595. up_bound += 0x10;
  596. }
  597. } else {
  598. if (rssi > -82) {
  599. low_bound = 0x1c;
  600. up_bound = 0x40;
  601. } else if (rssi > -84) {
  602. low_bound = 0x1c;
  603. up_bound = 0x20;
  604. } else {
  605. low_bound = 0x1c;
  606. up_bound = 0x1c;
  607. }
  608. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  609. low_bound += 0x14;
  610. up_bound += 0x10;
  611. }
  612. }
  613. /*
  614. * Special big-R17 for very short distance
  615. */
  616. if (rssi > -35) {
  617. if (r17 != 0x60)
  618. rt73usb_bbp_write(rt2x00dev, 17, 0x60);
  619. return;
  620. }
  621. /*
  622. * Special big-R17 for short distance
  623. */
  624. if (rssi >= -58) {
  625. if (r17 != up_bound)
  626. rt73usb_bbp_write(rt2x00dev, 17, up_bound);
  627. return;
  628. }
  629. /*
  630. * Special big-R17 for middle-short distance
  631. */
  632. if (rssi >= -66) {
  633. low_bound += 0x10;
  634. if (r17 != low_bound)
  635. rt73usb_bbp_write(rt2x00dev, 17, low_bound);
  636. return;
  637. }
  638. /*
  639. * Special mid-R17 for middle distance
  640. */
  641. if (rssi >= -74) {
  642. if (r17 != (low_bound + 0x10))
  643. rt73usb_bbp_write(rt2x00dev, 17, low_bound + 0x08);
  644. return;
  645. }
  646. /*
  647. * Special case: Change up_bound based on the rssi.
  648. * Lower up_bound when rssi is weaker then -74 dBm.
  649. */
  650. up_bound -= 2 * (-74 - rssi);
  651. if (low_bound > up_bound)
  652. up_bound = low_bound;
  653. if (r17 > up_bound) {
  654. rt73usb_bbp_write(rt2x00dev, 17, up_bound);
  655. return;
  656. }
  657. /*
  658. * r17 does not yet exceed upper limit, continue and base
  659. * the r17 tuning on the false CCA count.
  660. */
  661. if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  662. r17 += 4;
  663. if (r17 > up_bound)
  664. r17 = up_bound;
  665. rt73usb_bbp_write(rt2x00dev, 17, r17);
  666. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  667. r17 -= 4;
  668. if (r17 < low_bound)
  669. r17 = low_bound;
  670. rt73usb_bbp_write(rt2x00dev, 17, r17);
  671. }
  672. }
  673. /*
  674. * Firmware name function.
  675. */
  676. static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  677. {
  678. return FIRMWARE_RT2571;
  679. }
  680. /*
  681. * Initialization functions.
  682. */
  683. static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
  684. const size_t len)
  685. {
  686. unsigned int i;
  687. int status;
  688. u32 reg;
  689. char *ptr = data;
  690. char *cache;
  691. int buflen;
  692. int timeout;
  693. /*
  694. * Wait for stable hardware.
  695. */
  696. for (i = 0; i < 100; i++) {
  697. rt73usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  698. if (reg)
  699. break;
  700. msleep(1);
  701. }
  702. if (!reg) {
  703. ERROR(rt2x00dev, "Unstable hardware.\n");
  704. return -EBUSY;
  705. }
  706. /*
  707. * Write firmware to device.
  708. * We setup a seperate cache for this action,
  709. * since we are going to write larger chunks of data
  710. * then normally used cache size.
  711. */
  712. cache = kmalloc(CSR_CACHE_SIZE_FIRMWARE, GFP_KERNEL);
  713. if (!cache) {
  714. ERROR(rt2x00dev, "Failed to allocate firmware cache.\n");
  715. return -ENOMEM;
  716. }
  717. for (i = 0; i < len; i += CSR_CACHE_SIZE_FIRMWARE) {
  718. buflen = min_t(int, len - i, CSR_CACHE_SIZE_FIRMWARE);
  719. timeout = REGISTER_TIMEOUT * (buflen / sizeof(u32));
  720. memcpy(cache, ptr, buflen);
  721. rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE,
  722. USB_VENDOR_REQUEST_OUT,
  723. FIRMWARE_IMAGE_BASE + i, 0x0000,
  724. cache, buflen, timeout);
  725. ptr += buflen;
  726. }
  727. kfree(cache);
  728. /*
  729. * Send firmware request to device to load firmware,
  730. * we need to specify a long timeout time.
  731. */
  732. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  733. 0x0000, USB_MODE_FIRMWARE,
  734. REGISTER_TIMEOUT_FIRMWARE);
  735. if (status < 0) {
  736. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  737. return status;
  738. }
  739. rt73usb_disable_led(rt2x00dev);
  740. return 0;
  741. }
  742. static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
  743. {
  744. u32 reg;
  745. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  746. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  747. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  748. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  749. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  750. rt73usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  751. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  752. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  753. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  754. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  755. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  756. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  757. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  758. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  759. rt73usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  760. /*
  761. * CCK TXD BBP registers
  762. */
  763. rt73usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  764. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  765. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  766. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  767. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  768. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  769. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  770. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  771. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  772. rt73usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  773. /*
  774. * OFDM TXD BBP registers
  775. */
  776. rt73usb_register_read(rt2x00dev, TXRX_CSR3, &reg);
  777. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  778. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  779. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  780. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  781. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  782. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  783. rt73usb_register_write(rt2x00dev, TXRX_CSR3, reg);
  784. rt73usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  785. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  786. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  787. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  788. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  789. rt73usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  790. rt73usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  791. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  792. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  793. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  794. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  795. rt73usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  796. rt73usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  797. rt73usb_register_read(rt2x00dev, MAC_CSR6, &reg);
  798. rt2x00_set_field32(&reg, MAC_CSR6_MAX_FRAME_UNIT, 0xfff);
  799. rt73usb_register_write(rt2x00dev, MAC_CSR6, reg);
  800. rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718);
  801. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  802. return -EBUSY;
  803. rt73usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00);
  804. /*
  805. * Invalidate all Shared Keys (SEC_CSR0),
  806. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  807. */
  808. rt73usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  809. rt73usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  810. rt73usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  811. reg = 0x000023b0;
  812. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  813. rt2x00_rf(&rt2x00dev->chip, RF2527))
  814. rt2x00_set_field32(&reg, PHY_CSR1_RF_RPI, 1);
  815. rt73usb_register_write(rt2x00dev, PHY_CSR1, reg);
  816. rt73usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06);
  817. rt73usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  818. rt73usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
  819. rt73usb_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
  820. rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC0_TX_OP, 0);
  821. rt2x00_set_field32(&reg, AC_TXOP_CSR0_AC1_TX_OP, 0);
  822. rt73usb_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
  823. rt73usb_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
  824. rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC2_TX_OP, 192);
  825. rt2x00_set_field32(&reg, AC_TXOP_CSR1_AC3_TX_OP, 48);
  826. rt73usb_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
  827. rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  828. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  829. rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
  830. /*
  831. * We must clear the error counters.
  832. * These registers are cleared on read,
  833. * so we may pass a useless variable to store the value.
  834. */
  835. rt73usb_register_read(rt2x00dev, STA_CSR0, &reg);
  836. rt73usb_register_read(rt2x00dev, STA_CSR1, &reg);
  837. rt73usb_register_read(rt2x00dev, STA_CSR2, &reg);
  838. /*
  839. * Reset MAC and BBP registers.
  840. */
  841. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  842. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  843. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  844. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  845. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  846. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  847. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  848. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  849. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  850. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  851. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  852. return 0;
  853. }
  854. static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  855. {
  856. unsigned int i;
  857. u16 eeprom;
  858. u8 reg_id;
  859. u8 value;
  860. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  861. rt73usb_bbp_read(rt2x00dev, 0, &value);
  862. if ((value != 0xff) && (value != 0x00))
  863. goto continue_csr_init;
  864. NOTICE(rt2x00dev, "Waiting for BBP register.\n");
  865. udelay(REGISTER_BUSY_DELAY);
  866. }
  867. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  868. return -EACCES;
  869. continue_csr_init:
  870. rt73usb_bbp_write(rt2x00dev, 3, 0x80);
  871. rt73usb_bbp_write(rt2x00dev, 15, 0x30);
  872. rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
  873. rt73usb_bbp_write(rt2x00dev, 22, 0x38);
  874. rt73usb_bbp_write(rt2x00dev, 23, 0x06);
  875. rt73usb_bbp_write(rt2x00dev, 24, 0xfe);
  876. rt73usb_bbp_write(rt2x00dev, 25, 0x0a);
  877. rt73usb_bbp_write(rt2x00dev, 26, 0x0d);
  878. rt73usb_bbp_write(rt2x00dev, 32, 0x0b);
  879. rt73usb_bbp_write(rt2x00dev, 34, 0x12);
  880. rt73usb_bbp_write(rt2x00dev, 37, 0x07);
  881. rt73usb_bbp_write(rt2x00dev, 39, 0xf8);
  882. rt73usb_bbp_write(rt2x00dev, 41, 0x60);
  883. rt73usb_bbp_write(rt2x00dev, 53, 0x10);
  884. rt73usb_bbp_write(rt2x00dev, 54, 0x18);
  885. rt73usb_bbp_write(rt2x00dev, 60, 0x10);
  886. rt73usb_bbp_write(rt2x00dev, 61, 0x04);
  887. rt73usb_bbp_write(rt2x00dev, 62, 0x04);
  888. rt73usb_bbp_write(rt2x00dev, 75, 0xfe);
  889. rt73usb_bbp_write(rt2x00dev, 86, 0xfe);
  890. rt73usb_bbp_write(rt2x00dev, 88, 0xfe);
  891. rt73usb_bbp_write(rt2x00dev, 90, 0x0f);
  892. rt73usb_bbp_write(rt2x00dev, 99, 0x00);
  893. rt73usb_bbp_write(rt2x00dev, 102, 0x16);
  894. rt73usb_bbp_write(rt2x00dev, 107, 0x04);
  895. DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
  896. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  897. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  898. if (eeprom != 0xffff && eeprom != 0x0000) {
  899. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  900. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  901. DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
  902. reg_id, value);
  903. rt73usb_bbp_write(rt2x00dev, reg_id, value);
  904. }
  905. }
  906. DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
  907. return 0;
  908. }
  909. /*
  910. * Device state switch handlers.
  911. */
  912. static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  913. enum dev_state state)
  914. {
  915. u32 reg;
  916. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  917. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  918. state == STATE_RADIO_RX_OFF);
  919. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  920. }
  921. static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  922. {
  923. /*
  924. * Initialize all registers.
  925. */
  926. if (rt73usb_init_registers(rt2x00dev) ||
  927. rt73usb_init_bbp(rt2x00dev)) {
  928. ERROR(rt2x00dev, "Register initialization failed.\n");
  929. return -EIO;
  930. }
  931. rt2x00usb_enable_radio(rt2x00dev);
  932. /*
  933. * Enable LED
  934. */
  935. rt73usb_enable_led(rt2x00dev);
  936. return 0;
  937. }
  938. static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  939. {
  940. /*
  941. * Disable LED
  942. */
  943. rt73usb_disable_led(rt2x00dev);
  944. rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  945. /*
  946. * Disable synchronisation.
  947. */
  948. rt73usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  949. rt2x00usb_disable_radio(rt2x00dev);
  950. }
  951. static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  952. {
  953. u32 reg;
  954. unsigned int i;
  955. char put_to_sleep;
  956. char current_state;
  957. put_to_sleep = (state != STATE_AWAKE);
  958. rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  959. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  960. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  961. rt73usb_register_write(rt2x00dev, MAC_CSR12, reg);
  962. /*
  963. * Device is not guaranteed to be in the requested state yet.
  964. * We must wait until the register indicates that the
  965. * device has entered the correct state.
  966. */
  967. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  968. rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  969. current_state =
  970. rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
  971. if (current_state == !put_to_sleep)
  972. return 0;
  973. msleep(10);
  974. }
  975. NOTICE(rt2x00dev, "Device failed to enter state %d, "
  976. "current device state %d.\n", !put_to_sleep, current_state);
  977. return -EBUSY;
  978. }
  979. static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  980. enum dev_state state)
  981. {
  982. int retval = 0;
  983. switch (state) {
  984. case STATE_RADIO_ON:
  985. retval = rt73usb_enable_radio(rt2x00dev);
  986. break;
  987. case STATE_RADIO_OFF:
  988. rt73usb_disable_radio(rt2x00dev);
  989. break;
  990. case STATE_RADIO_RX_ON:
  991. case STATE_RADIO_RX_OFF:
  992. rt73usb_toggle_rx(rt2x00dev, state);
  993. break;
  994. case STATE_DEEP_SLEEP:
  995. case STATE_SLEEP:
  996. case STATE_STANDBY:
  997. case STATE_AWAKE:
  998. retval = rt73usb_set_state(rt2x00dev, state);
  999. break;
  1000. default:
  1001. retval = -ENOTSUPP;
  1002. break;
  1003. }
  1004. return retval;
  1005. }
  1006. /*
  1007. * TX descriptor initialization
  1008. */
  1009. static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1010. struct data_desc *txd,
  1011. struct txdata_entry_desc *desc,
  1012. struct ieee80211_hdr *ieee80211hdr,
  1013. unsigned int length,
  1014. struct ieee80211_tx_control *control)
  1015. {
  1016. u32 word;
  1017. /*
  1018. * Start writing the descriptor words.
  1019. */
  1020. rt2x00_desc_read(txd, 1, &word);
  1021. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, desc->queue);
  1022. rt2x00_set_field32(&word, TXD_W1_AIFSN, desc->aifs);
  1023. rt2x00_set_field32(&word, TXD_W1_CWMIN, desc->cw_min);
  1024. rt2x00_set_field32(&word, TXD_W1_CWMAX, desc->cw_max);
  1025. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER);
  1026. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE, 1);
  1027. rt2x00_desc_write(txd, 1, word);
  1028. rt2x00_desc_read(txd, 2, &word);
  1029. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, desc->signal);
  1030. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, desc->service);
  1031. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, desc->length_low);
  1032. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, desc->length_high);
  1033. rt2x00_desc_write(txd, 2, word);
  1034. rt2x00_desc_read(txd, 5, &word);
  1035. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1036. TXPOWER_TO_DEV(control->power_level));
  1037. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1038. rt2x00_desc_write(txd, 5, word);
  1039. rt2x00_desc_read(txd, 0, &word);
  1040. rt2x00_set_field32(&word, TXD_W0_BURST,
  1041. test_bit(ENTRY_TXD_BURST, &desc->flags));
  1042. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1043. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1044. test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
  1045. rt2x00_set_field32(&word, TXD_W0_ACK,
  1046. !(control->flags & IEEE80211_TXCTL_NO_ACK));
  1047. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1048. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
  1049. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1050. test_bit(ENTRY_TXD_OFDM_RATE, &desc->flags));
  1051. rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
  1052. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1053. !!(control->flags &
  1054. IEEE80211_TXCTL_LONG_RETRY_LIMIT));
  1055. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC, 0);
  1056. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, length);
  1057. rt2x00_set_field32(&word, TXD_W0_BURST2,
  1058. test_bit(ENTRY_TXD_BURST, &desc->flags));
  1059. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, CIPHER_NONE);
  1060. rt2x00_desc_write(txd, 0, word);
  1061. }
  1062. static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
  1063. struct sk_buff *skb)
  1064. {
  1065. int length;
  1066. /*
  1067. * The length _must_ be a multiple of 4,
  1068. * but it must _not_ be a multiple of the USB packet size.
  1069. */
  1070. length = roundup(skb->len, 4);
  1071. length += (4 * !(length % rt2x00dev->usb_maxpacket));
  1072. return length;
  1073. }
  1074. /*
  1075. * TX data initialization
  1076. */
  1077. static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1078. unsigned int queue)
  1079. {
  1080. u32 reg;
  1081. if (queue != IEEE80211_TX_QUEUE_BEACON)
  1082. return;
  1083. /*
  1084. * For Wi-Fi faily generated beacons between participating stations.
  1085. * Set TBTT phase adaptive adjustment step to 8us (default 16us)
  1086. */
  1087. rt73usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1088. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1089. if (!rt2x00_get_field32(reg, TXRX_CSR9_BEACON_GEN)) {
  1090. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1091. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1092. }
  1093. }
  1094. /*
  1095. * RX control handlers
  1096. */
  1097. static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1098. {
  1099. u16 eeprom;
  1100. u8 offset;
  1101. u8 lna;
  1102. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1103. switch (lna) {
  1104. case 3:
  1105. offset = 90;
  1106. break;
  1107. case 2:
  1108. offset = 74;
  1109. break;
  1110. case 1:
  1111. offset = 64;
  1112. break;
  1113. default:
  1114. return 0;
  1115. }
  1116. if (rt2x00dev->rx_status.phymode == MODE_IEEE80211A) {
  1117. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  1118. if (lna == 3 || lna == 2)
  1119. offset += 10;
  1120. } else {
  1121. if (lna == 3)
  1122. offset += 6;
  1123. else if (lna == 2)
  1124. offset += 8;
  1125. }
  1126. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  1127. offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  1128. } else {
  1129. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  1130. offset += 14;
  1131. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  1132. offset -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  1133. }
  1134. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1135. }
  1136. static void rt73usb_fill_rxdone(struct data_entry *entry,
  1137. struct rxdata_entry_desc *desc)
  1138. {
  1139. struct data_desc *rxd = (struct data_desc *)entry->skb->data;
  1140. u32 word0;
  1141. u32 word1;
  1142. rt2x00_desc_read(rxd, 0, &word0);
  1143. rt2x00_desc_read(rxd, 1, &word1);
  1144. desc->flags = 0;
  1145. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1146. desc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1147. /*
  1148. * Obtain the status about this packet.
  1149. */
  1150. desc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1151. desc->rssi = rt73usb_agc_to_rssi(entry->ring->rt2x00dev, word1);
  1152. desc->ofdm = rt2x00_get_field32(word0, RXD_W0_OFDM);
  1153. desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1154. /*
  1155. * Pull the skb to clear the descriptor area.
  1156. */
  1157. skb_pull(entry->skb, entry->ring->desc_size);
  1158. return;
  1159. }
  1160. /*
  1161. * Device probe functions.
  1162. */
  1163. static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1164. {
  1165. u16 word;
  1166. u8 *mac;
  1167. s8 value;
  1168. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1169. /*
  1170. * Start validation of the data that has been read.
  1171. */
  1172. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1173. if (!is_valid_ether_addr(mac)) {
  1174. DECLARE_MAC_BUF(macbuf);
  1175. random_ether_addr(mac);
  1176. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1177. }
  1178. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1179. if (word == 0xffff) {
  1180. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1181. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1182. ANTENNA_B);
  1183. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1184. ANTENNA_B);
  1185. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1186. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1187. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1188. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226);
  1189. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1190. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1191. }
  1192. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1193. if (word == 0xffff) {
  1194. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0);
  1195. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1196. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1197. }
  1198. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1199. if (word == 0xffff) {
  1200. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0);
  1201. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0);
  1202. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0);
  1203. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0);
  1204. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0);
  1205. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0);
  1206. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0);
  1207. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0);
  1208. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1209. LED_MODE_DEFAULT);
  1210. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1211. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1212. }
  1213. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1214. if (word == 0xffff) {
  1215. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1216. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1217. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1218. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1219. }
  1220. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1221. if (word == 0xffff) {
  1222. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1223. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1224. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1225. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1226. } else {
  1227. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1228. if (value < -10 || value > 10)
  1229. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1230. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1231. if (value < -10 || value > 10)
  1232. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1233. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1234. }
  1235. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1236. if (word == 0xffff) {
  1237. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1238. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1239. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1240. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1241. } else {
  1242. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1243. if (value < -10 || value > 10)
  1244. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1245. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1246. if (value < -10 || value > 10)
  1247. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1248. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1249. }
  1250. return 0;
  1251. }
  1252. static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1253. {
  1254. u32 reg;
  1255. u16 value;
  1256. u16 eeprom;
  1257. /*
  1258. * Read EEPROM word for configuration.
  1259. */
  1260. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1261. /*
  1262. * Identify RF chipset.
  1263. */
  1264. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1265. rt73usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1266. rt2x00_set_chip(rt2x00dev, RT2571, value, reg);
  1267. if (!rt2x00_check_rev(&rt2x00dev->chip, 0x25730)) {
  1268. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1269. return -ENODEV;
  1270. }
  1271. if (!rt2x00_rf(&rt2x00dev->chip, RF5226) &&
  1272. !rt2x00_rf(&rt2x00dev->chip, RF2528) &&
  1273. !rt2x00_rf(&rt2x00dev->chip, RF5225) &&
  1274. !rt2x00_rf(&rt2x00dev->chip, RF2527)) {
  1275. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1276. return -ENODEV;
  1277. }
  1278. /*
  1279. * Identify default antenna configuration.
  1280. */
  1281. rt2x00dev->default_ant.tx =
  1282. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1283. rt2x00dev->default_ant.rx =
  1284. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1285. /*
  1286. * Read the Frame type.
  1287. */
  1288. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1289. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1290. /*
  1291. * Read frequency offset.
  1292. */
  1293. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1294. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1295. /*
  1296. * Read external LNA informations.
  1297. */
  1298. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1299. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) {
  1300. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1301. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1302. }
  1303. /*
  1304. * Store led settings, for correct led behaviour.
  1305. */
  1306. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1307. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_LED_MODE,
  1308. rt2x00dev->led_mode);
  1309. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1310. rt2x00_get_field16(eeprom,
  1311. EEPROM_LED_POLARITY_GPIO_0));
  1312. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1313. rt2x00_get_field16(eeprom,
  1314. EEPROM_LED_POLARITY_GPIO_1));
  1315. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1316. rt2x00_get_field16(eeprom,
  1317. EEPROM_LED_POLARITY_GPIO_2));
  1318. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1319. rt2x00_get_field16(eeprom,
  1320. EEPROM_LED_POLARITY_GPIO_3));
  1321. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1322. rt2x00_get_field16(eeprom,
  1323. EEPROM_LED_POLARITY_GPIO_4));
  1324. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_ACT,
  1325. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1326. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_READY_BG,
  1327. rt2x00_get_field16(eeprom,
  1328. EEPROM_LED_POLARITY_RDY_G));
  1329. rt2x00_set_field16(&rt2x00dev->led_reg, MCU_LEDCS_POLARITY_READY_A,
  1330. rt2x00_get_field16(eeprom,
  1331. EEPROM_LED_POLARITY_RDY_A));
  1332. return 0;
  1333. }
  1334. /*
  1335. * RF value list for RF2528
  1336. * Supports: 2.4 GHz
  1337. */
  1338. static const struct rf_channel rf_vals_bg_2528[] = {
  1339. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1340. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1341. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1342. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1343. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1344. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1345. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1346. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1347. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1348. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1349. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1350. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1351. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1352. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1353. };
  1354. /*
  1355. * RF value list for RF5226
  1356. * Supports: 2.4 GHz & 5.2 GHz
  1357. */
  1358. static const struct rf_channel rf_vals_5226[] = {
  1359. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1360. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1361. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1362. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1363. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1364. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1365. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1366. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1367. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1368. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1369. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1370. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1371. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1372. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1373. /* 802.11 UNI / HyperLan 2 */
  1374. { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
  1375. { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
  1376. { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
  1377. { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
  1378. { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
  1379. { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
  1380. { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
  1381. { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
  1382. /* 802.11 HyperLan 2 */
  1383. { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
  1384. { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
  1385. { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
  1386. { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
  1387. { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
  1388. { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
  1389. { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
  1390. { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
  1391. { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
  1392. { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
  1393. /* 802.11 UNII */
  1394. { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
  1395. { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
  1396. { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
  1397. { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
  1398. { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
  1399. { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
  1400. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1401. { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
  1402. { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
  1403. { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
  1404. { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
  1405. };
  1406. /*
  1407. * RF value list for RF5225 & RF2527
  1408. * Supports: 2.4 GHz & 5.2 GHz
  1409. */
  1410. static const struct rf_channel rf_vals_5225_2527[] = {
  1411. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1412. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1413. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1414. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1415. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1416. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1417. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1418. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1419. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1420. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1421. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1422. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1423. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1424. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1425. /* 802.11 UNI / HyperLan 2 */
  1426. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1427. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1428. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1429. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1430. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1431. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1432. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1433. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1434. /* 802.11 HyperLan 2 */
  1435. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1436. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1437. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1438. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1439. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1440. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1441. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1442. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1443. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1444. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1445. /* 802.11 UNII */
  1446. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1447. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1448. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1449. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1450. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1451. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1452. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1453. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1454. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1455. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1456. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1457. };
  1458. static void rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1459. {
  1460. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1461. u8 *txpower;
  1462. unsigned int i;
  1463. /*
  1464. * Initialize all hw fields.
  1465. */
  1466. rt2x00dev->hw->flags =
  1467. IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
  1468. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  1469. rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
  1470. rt2x00dev->hw->max_signal = MAX_SIGNAL;
  1471. rt2x00dev->hw->max_rssi = MAX_RX_SSI;
  1472. rt2x00dev->hw->queues = 5;
  1473. SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_usb(rt2x00dev)->dev);
  1474. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1475. rt2x00_eeprom_addr(rt2x00dev,
  1476. EEPROM_MAC_ADDR_0));
  1477. /*
  1478. * Convert tx_power array in eeprom.
  1479. */
  1480. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1481. for (i = 0; i < 14; i++)
  1482. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1483. /*
  1484. * Initialize hw_mode information.
  1485. */
  1486. spec->num_modes = 2;
  1487. spec->num_rates = 12;
  1488. spec->tx_power_a = NULL;
  1489. spec->tx_power_bg = txpower;
  1490. spec->tx_power_default = DEFAULT_TXPOWER;
  1491. if (rt2x00_rf(&rt2x00dev->chip, RF2528)) {
  1492. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
  1493. spec->channels = rf_vals_bg_2528;
  1494. } else if (rt2x00_rf(&rt2x00dev->chip, RF5226)) {
  1495. spec->num_channels = ARRAY_SIZE(rf_vals_5226);
  1496. spec->channels = rf_vals_5226;
  1497. } else if (rt2x00_rf(&rt2x00dev->chip, RF2527)) {
  1498. spec->num_channels = 14;
  1499. spec->channels = rf_vals_5225_2527;
  1500. } else if (rt2x00_rf(&rt2x00dev->chip, RF5225)) {
  1501. spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527);
  1502. spec->channels = rf_vals_5225_2527;
  1503. }
  1504. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  1505. rt2x00_rf(&rt2x00dev->chip, RF5226)) {
  1506. spec->num_modes = 3;
  1507. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1508. for (i = 0; i < 14; i++)
  1509. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1510. spec->tx_power_a = txpower;
  1511. }
  1512. }
  1513. static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1514. {
  1515. int retval;
  1516. /*
  1517. * Allocate eeprom data.
  1518. */
  1519. retval = rt73usb_validate_eeprom(rt2x00dev);
  1520. if (retval)
  1521. return retval;
  1522. retval = rt73usb_init_eeprom(rt2x00dev);
  1523. if (retval)
  1524. return retval;
  1525. /*
  1526. * Initialize hw specifications.
  1527. */
  1528. rt73usb_probe_hw_mode(rt2x00dev);
  1529. /*
  1530. * This device requires firmware
  1531. */
  1532. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  1533. /*
  1534. * Set the rssi offset.
  1535. */
  1536. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1537. return 0;
  1538. }
  1539. /*
  1540. * IEEE80211 stack callback functions.
  1541. */
  1542. static void rt73usb_configure_filter(struct ieee80211_hw *hw,
  1543. unsigned int changed_flags,
  1544. unsigned int *total_flags,
  1545. int mc_count,
  1546. struct dev_addr_list *mc_list)
  1547. {
  1548. struct rt2x00_dev *rt2x00dev = hw->priv;
  1549. struct interface *intf = &rt2x00dev->interface;
  1550. u32 reg;
  1551. /*
  1552. * Mask off any flags we are going to ignore from
  1553. * the total_flags field.
  1554. */
  1555. *total_flags &=
  1556. FIF_ALLMULTI |
  1557. FIF_FCSFAIL |
  1558. FIF_PLCPFAIL |
  1559. FIF_CONTROL |
  1560. FIF_OTHER_BSS |
  1561. FIF_PROMISC_IN_BSS;
  1562. /*
  1563. * Apply some rules to the filters:
  1564. * - Some filters imply different filters to be set.
  1565. * - Some things we can't filter out at all.
  1566. * - Some filters are set based on interface type.
  1567. */
  1568. if (mc_count)
  1569. *total_flags |= FIF_ALLMULTI;
  1570. if (*total_flags & FIF_OTHER_BSS ||
  1571. *total_flags & FIF_PROMISC_IN_BSS)
  1572. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  1573. if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
  1574. *total_flags |= FIF_PROMISC_IN_BSS;
  1575. /*
  1576. * Check if there is any work left for us.
  1577. */
  1578. if (intf->filter == *total_flags)
  1579. return;
  1580. intf->filter = *total_flags;
  1581. /*
  1582. * When in atomic context, reschedule and let rt2x00lib
  1583. * call this function again.
  1584. */
  1585. if (in_atomic()) {
  1586. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
  1587. return;
  1588. }
  1589. /*
  1590. * Start configuration steps.
  1591. * Note that the version error will always be dropped
  1592. * and broadcast frames will always be accepted since
  1593. * there is no filter for it at this time.
  1594. */
  1595. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1596. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  1597. !(*total_flags & FIF_FCSFAIL));
  1598. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  1599. !(*total_flags & FIF_PLCPFAIL));
  1600. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  1601. !(*total_flags & FIF_CONTROL));
  1602. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  1603. !(*total_flags & FIF_PROMISC_IN_BSS));
  1604. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  1605. !(*total_flags & FIF_PROMISC_IN_BSS));
  1606. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  1607. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  1608. !(*total_flags & FIF_ALLMULTI));
  1609. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  1610. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS, 1);
  1611. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1612. }
  1613. static int rt73usb_set_retry_limit(struct ieee80211_hw *hw,
  1614. u32 short_retry, u32 long_retry)
  1615. {
  1616. struct rt2x00_dev *rt2x00dev = hw->priv;
  1617. u32 reg;
  1618. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  1619. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT, long_retry);
  1620. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT, short_retry);
  1621. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  1622. return 0;
  1623. }
  1624. #if 0
  1625. /*
  1626. * Mac80211 demands get_tsf must be atomic.
  1627. * This is not possible for rt73usb since all register access
  1628. * functions require sleeping. Untill mac80211 no longer needs
  1629. * get_tsf to be atomic, this function should be disabled.
  1630. */
  1631. static u64 rt73usb_get_tsf(struct ieee80211_hw *hw)
  1632. {
  1633. struct rt2x00_dev *rt2x00dev = hw->priv;
  1634. u64 tsf;
  1635. u32 reg;
  1636. rt73usb_register_read(rt2x00dev, TXRX_CSR13, &reg);
  1637. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  1638. rt73usb_register_read(rt2x00dev, TXRX_CSR12, &reg);
  1639. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  1640. return tsf;
  1641. }
  1642. #else
  1643. #define rt73usb_get_tsf NULL
  1644. #endif
  1645. static void rt73usb_reset_tsf(struct ieee80211_hw *hw)
  1646. {
  1647. struct rt2x00_dev *rt2x00dev = hw->priv;
  1648. rt73usb_register_write(rt2x00dev, TXRX_CSR12, 0);
  1649. rt73usb_register_write(rt2x00dev, TXRX_CSR13, 0);
  1650. }
  1651. static int rt73usb_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
  1652. struct ieee80211_tx_control *control)
  1653. {
  1654. struct rt2x00_dev *rt2x00dev = hw->priv;
  1655. int timeout;
  1656. /*
  1657. * Just in case the ieee80211 doesn't set this,
  1658. * but we need this queue set for the descriptor
  1659. * initialization.
  1660. */
  1661. control->queue = IEEE80211_TX_QUEUE_BEACON;
  1662. /*
  1663. * First we create the beacon.
  1664. */
  1665. skb_push(skb, TXD_DESC_SIZE);
  1666. memset(skb->data, 0, TXD_DESC_SIZE);
  1667. rt2x00lib_write_tx_desc(rt2x00dev, (struct data_desc *)skb->data,
  1668. (struct ieee80211_hdr *)(skb->data +
  1669. TXD_DESC_SIZE),
  1670. skb->len - TXD_DESC_SIZE, control);
  1671. /*
  1672. * Write entire beacon with descriptor to register,
  1673. * and kick the beacon generator.
  1674. */
  1675. timeout = REGISTER_TIMEOUT * (skb->len / sizeof(u32));
  1676. rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE,
  1677. USB_VENDOR_REQUEST_OUT,
  1678. HW_BEACON_BASE0, 0x0000,
  1679. skb->data, skb->len, timeout);
  1680. rt73usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
  1681. return 0;
  1682. }
  1683. static const struct ieee80211_ops rt73usb_mac80211_ops = {
  1684. .tx = rt2x00mac_tx,
  1685. .start = rt2x00mac_start,
  1686. .stop = rt2x00mac_stop,
  1687. .add_interface = rt2x00mac_add_interface,
  1688. .remove_interface = rt2x00mac_remove_interface,
  1689. .config = rt2x00mac_config,
  1690. .config_interface = rt2x00mac_config_interface,
  1691. .configure_filter = rt73usb_configure_filter,
  1692. .get_stats = rt2x00mac_get_stats,
  1693. .set_retry_limit = rt73usb_set_retry_limit,
  1694. .erp_ie_changed = rt2x00mac_erp_ie_changed,
  1695. .conf_tx = rt2x00mac_conf_tx,
  1696. .get_tx_stats = rt2x00mac_get_tx_stats,
  1697. .get_tsf = rt73usb_get_tsf,
  1698. .reset_tsf = rt73usb_reset_tsf,
  1699. .beacon_update = rt73usb_beacon_update,
  1700. };
  1701. static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
  1702. .probe_hw = rt73usb_probe_hw,
  1703. .get_firmware_name = rt73usb_get_firmware_name,
  1704. .load_firmware = rt73usb_load_firmware,
  1705. .initialize = rt2x00usb_initialize,
  1706. .uninitialize = rt2x00usb_uninitialize,
  1707. .set_device_state = rt73usb_set_device_state,
  1708. .link_stats = rt73usb_link_stats,
  1709. .reset_tuner = rt73usb_reset_tuner,
  1710. .link_tuner = rt73usb_link_tuner,
  1711. .write_tx_desc = rt73usb_write_tx_desc,
  1712. .write_tx_data = rt2x00usb_write_tx_data,
  1713. .get_tx_data_len = rt73usb_get_tx_data_len,
  1714. .kick_tx_queue = rt73usb_kick_tx_queue,
  1715. .fill_rxdone = rt73usb_fill_rxdone,
  1716. .config_mac_addr = rt73usb_config_mac_addr,
  1717. .config_bssid = rt73usb_config_bssid,
  1718. .config_type = rt73usb_config_type,
  1719. .config_preamble = rt73usb_config_preamble,
  1720. .config = rt73usb_config,
  1721. };
  1722. static const struct rt2x00_ops rt73usb_ops = {
  1723. .name = DRV_NAME,
  1724. .rxd_size = RXD_DESC_SIZE,
  1725. .txd_size = TXD_DESC_SIZE,
  1726. .eeprom_size = EEPROM_SIZE,
  1727. .rf_size = RF_SIZE,
  1728. .lib = &rt73usb_rt2x00_ops,
  1729. .hw = &rt73usb_mac80211_ops,
  1730. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1731. .debugfs = &rt73usb_rt2x00debug,
  1732. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1733. };
  1734. /*
  1735. * rt73usb module information.
  1736. */
  1737. static struct usb_device_id rt73usb_device_table[] = {
  1738. /* AboCom */
  1739. { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops) },
  1740. /* Askey */
  1741. { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops) },
  1742. /* ASUS */
  1743. { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops) },
  1744. { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops) },
  1745. /* Belkin */
  1746. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops) },
  1747. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops) },
  1748. { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops) },
  1749. { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops) },
  1750. /* Billionton */
  1751. { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops) },
  1752. /* Buffalo */
  1753. { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops) },
  1754. /* CNet */
  1755. { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops) },
  1756. { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops) },
  1757. /* Conceptronic */
  1758. { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops) },
  1759. /* D-Link */
  1760. { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops) },
  1761. { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops) },
  1762. /* Gemtek */
  1763. { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops) },
  1764. /* Gigabyte */
  1765. { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops) },
  1766. { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops) },
  1767. /* Huawei-3Com */
  1768. { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops) },
  1769. /* Hercules */
  1770. { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops) },
  1771. { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops) },
  1772. /* Linksys */
  1773. { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
  1774. { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
  1775. /* MSI */
  1776. { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
  1777. { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
  1778. { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) },
  1779. { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) },
  1780. /* Ralink */
  1781. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) },
  1782. { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) },
  1783. /* Qcom */
  1784. { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) },
  1785. { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) },
  1786. { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops) },
  1787. /* Senao */
  1788. { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops) },
  1789. /* Sitecom */
  1790. { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops) },
  1791. { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops) },
  1792. /* Surecom */
  1793. { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops) },
  1794. /* Planex */
  1795. { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) },
  1796. { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) },
  1797. { 0, }
  1798. };
  1799. MODULE_AUTHOR(DRV_PROJECT);
  1800. MODULE_VERSION(DRV_VERSION);
  1801. MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
  1802. MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
  1803. MODULE_DEVICE_TABLE(usb, rt73usb_device_table);
  1804. MODULE_FIRMWARE(FIRMWARE_RT2571);
  1805. MODULE_LICENSE("GPL");
  1806. static struct usb_driver rt73usb_driver = {
  1807. .name = DRV_NAME,
  1808. .id_table = rt73usb_device_table,
  1809. .probe = rt2x00usb_probe,
  1810. .disconnect = rt2x00usb_disconnect,
  1811. .suspend = rt2x00usb_suspend,
  1812. .resume = rt2x00usb_resume,
  1813. };
  1814. static int __init rt73usb_init(void)
  1815. {
  1816. return usb_register(&rt73usb_driver);
  1817. }
  1818. static void __exit rt73usb_exit(void)
  1819. {
  1820. usb_deregister(&rt73usb_driver);
  1821. }
  1822. module_init(rt73usb_init);
  1823. module_exit(rt73usb_exit);