rt73usb.c 62 KB

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