rt73usb.c 76 KB

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