rt73usb.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480
  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 = 0;
  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. unsigned int beacon_base;
  440. u32 reg;
  441. if (flags & CONFIG_UPDATE_TYPE) {
  442. /*
  443. * Clear current synchronisation setup.
  444. * For the Beacon base registers we only need to clear
  445. * the first byte since that byte contains the VALID and OWNER
  446. * bits which (when set to 0) will invalidate the entire beacon.
  447. */
  448. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  449. rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
  450. /*
  451. * Enable synchronisation.
  452. */
  453. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  454. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  455. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  456. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  457. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  458. }
  459. if (flags & CONFIG_UPDATE_MAC) {
  460. reg = le32_to_cpu(conf->mac[1]);
  461. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  462. conf->mac[1] = cpu_to_le32(reg);
  463. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR2,
  464. conf->mac, sizeof(conf->mac));
  465. }
  466. if (flags & CONFIG_UPDATE_BSSID) {
  467. reg = le32_to_cpu(conf->bssid[1]);
  468. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  469. conf->bssid[1] = cpu_to_le32(reg);
  470. rt2x00usb_register_multiwrite(rt2x00dev, MAC_CSR4,
  471. conf->bssid, sizeof(conf->bssid));
  472. }
  473. }
  474. static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
  475. struct rt2x00lib_erp *erp,
  476. u32 changed)
  477. {
  478. u32 reg;
  479. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  480. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, 0x32);
  481. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  482. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  483. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  484. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  485. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  486. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  487. !!erp->short_preamble);
  488. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  489. }
  490. if (changed & BSS_CHANGED_BASIC_RATES)
  491. rt2x00usb_register_write(rt2x00dev, TXRX_CSR5,
  492. erp->basic_rates);
  493. if (changed & BSS_CHANGED_BEACON_INT) {
  494. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  495. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  496. erp->beacon_int * 16);
  497. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  498. }
  499. if (changed & BSS_CHANGED_ERP_SLOT) {
  500. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  501. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
  502. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  503. rt2x00usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  504. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
  505. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  506. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
  507. rt2x00usb_register_write(rt2x00dev, MAC_CSR8, reg);
  508. }
  509. }
  510. static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  511. struct antenna_setup *ant)
  512. {
  513. u8 r3;
  514. u8 r4;
  515. u8 r77;
  516. u8 temp;
  517. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  518. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  519. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  520. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  521. /*
  522. * Configure the RX antenna.
  523. */
  524. switch (ant->rx) {
  525. case ANTENNA_HW_DIVERSITY:
  526. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  527. temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags)
  528. && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ);
  529. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp);
  530. break;
  531. case ANTENNA_A:
  532. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  533. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  534. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  535. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  536. else
  537. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  538. break;
  539. case ANTENNA_B:
  540. default:
  541. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  542. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  543. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  544. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  545. else
  546. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  547. break;
  548. }
  549. rt73usb_bbp_write(rt2x00dev, 77, r77);
  550. rt73usb_bbp_write(rt2x00dev, 3, r3);
  551. rt73usb_bbp_write(rt2x00dev, 4, r4);
  552. }
  553. static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  554. struct antenna_setup *ant)
  555. {
  556. u8 r3;
  557. u8 r4;
  558. u8 r77;
  559. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  560. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  561. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  562. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  563. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  564. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  565. /*
  566. * Configure the RX antenna.
  567. */
  568. switch (ant->rx) {
  569. case ANTENNA_HW_DIVERSITY:
  570. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  571. break;
  572. case ANTENNA_A:
  573. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  574. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  575. break;
  576. case ANTENNA_B:
  577. default:
  578. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  579. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  580. break;
  581. }
  582. rt73usb_bbp_write(rt2x00dev, 77, r77);
  583. rt73usb_bbp_write(rt2x00dev, 3, r3);
  584. rt73usb_bbp_write(rt2x00dev, 4, r4);
  585. }
  586. struct antenna_sel {
  587. u8 word;
  588. /*
  589. * value[0] -> non-LNA
  590. * value[1] -> LNA
  591. */
  592. u8 value[2];
  593. };
  594. static const struct antenna_sel antenna_sel_a[] = {
  595. { 96, { 0x58, 0x78 } },
  596. { 104, { 0x38, 0x48 } },
  597. { 75, { 0xfe, 0x80 } },
  598. { 86, { 0xfe, 0x80 } },
  599. { 88, { 0xfe, 0x80 } },
  600. { 35, { 0x60, 0x60 } },
  601. { 97, { 0x58, 0x58 } },
  602. { 98, { 0x58, 0x58 } },
  603. };
  604. static const struct antenna_sel antenna_sel_bg[] = {
  605. { 96, { 0x48, 0x68 } },
  606. { 104, { 0x2c, 0x3c } },
  607. { 75, { 0xfe, 0x80 } },
  608. { 86, { 0xfe, 0x80 } },
  609. { 88, { 0xfe, 0x80 } },
  610. { 35, { 0x50, 0x50 } },
  611. { 97, { 0x48, 0x48 } },
  612. { 98, { 0x48, 0x48 } },
  613. };
  614. static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
  615. struct antenna_setup *ant)
  616. {
  617. const struct antenna_sel *sel;
  618. unsigned int lna;
  619. unsigned int i;
  620. u32 reg;
  621. /*
  622. * We should never come here because rt2x00lib is supposed
  623. * to catch this and send us the correct antenna explicitely.
  624. */
  625. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  626. ant->tx == ANTENNA_SW_DIVERSITY);
  627. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  628. sel = antenna_sel_a;
  629. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  630. } else {
  631. sel = antenna_sel_bg;
  632. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  633. }
  634. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  635. rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  636. rt2x00usb_register_read(rt2x00dev, PHY_CSR0, &reg);
  637. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  638. (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ));
  639. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  640. (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ));
  641. rt2x00usb_register_write(rt2x00dev, PHY_CSR0, reg);
  642. if (rt2x00_rf(rt2x00dev, RF5226) || rt2x00_rf(rt2x00dev, RF5225))
  643. rt73usb_config_antenna_5x(rt2x00dev, ant);
  644. else if (rt2x00_rf(rt2x00dev, RF2528) || rt2x00_rf(rt2x00dev, RF2527))
  645. rt73usb_config_antenna_2x(rt2x00dev, ant);
  646. }
  647. static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  648. struct rt2x00lib_conf *libconf)
  649. {
  650. u16 eeprom;
  651. short lna_gain = 0;
  652. if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
  653. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  654. lna_gain += 14;
  655. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  656. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  657. } else {
  658. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  659. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  660. }
  661. rt2x00dev->lna_gain = lna_gain;
  662. }
  663. static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
  664. struct rf_channel *rf, const int txpower)
  665. {
  666. u8 r3;
  667. u8 r94;
  668. u8 smart;
  669. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  670. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  671. smart = !(rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527));
  672. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  673. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  674. rt73usb_bbp_write(rt2x00dev, 3, r3);
  675. r94 = 6;
  676. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  677. r94 += txpower - MAX_TXPOWER;
  678. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  679. r94 += txpower;
  680. rt73usb_bbp_write(rt2x00dev, 94, r94);
  681. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  682. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  683. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  684. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  685. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  686. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  687. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  688. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  689. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  690. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  691. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  692. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  693. udelay(10);
  694. }
  695. static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  696. const int txpower)
  697. {
  698. struct rf_channel rf;
  699. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  700. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  701. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  702. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  703. rt73usb_config_channel(rt2x00dev, &rf, txpower);
  704. }
  705. static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  706. struct rt2x00lib_conf *libconf)
  707. {
  708. u32 reg;
  709. rt2x00usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  710. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_DOWN, 1);
  711. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_RATE_STEP, 0);
  712. rt2x00_set_field32(&reg, TXRX_CSR4_OFDM_TX_FALLBACK_CCK, 0);
  713. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
  714. libconf->conf->long_frame_max_tx_count);
  715. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
  716. libconf->conf->short_frame_max_tx_count);
  717. rt2x00usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  718. }
  719. static void rt73usb_config_ps(struct rt2x00_dev *rt2x00dev,
  720. struct rt2x00lib_conf *libconf)
  721. {
  722. enum dev_state state =
  723. (libconf->conf->flags & IEEE80211_CONF_PS) ?
  724. STATE_SLEEP : STATE_AWAKE;
  725. u32 reg;
  726. if (state == STATE_SLEEP) {
  727. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  728. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN,
  729. rt2x00dev->beacon_int - 10);
  730. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP,
  731. libconf->conf->listen_interval - 1);
  732. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 5);
  733. /* We must first disable autowake before it can be enabled */
  734. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  735. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  736. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 1);
  737. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  738. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  739. USB_MODE_SLEEP, REGISTER_TIMEOUT);
  740. } else {
  741. rt2x00usb_register_read(rt2x00dev, MAC_CSR11, &reg);
  742. rt2x00_set_field32(&reg, MAC_CSR11_DELAY_AFTER_TBCN, 0);
  743. rt2x00_set_field32(&reg, MAC_CSR11_TBCN_BEFORE_WAKEUP, 0);
  744. rt2x00_set_field32(&reg, MAC_CSR11_AUTOWAKE, 0);
  745. rt2x00_set_field32(&reg, MAC_CSR11_WAKEUP_LATENCY, 0);
  746. rt2x00usb_register_write(rt2x00dev, MAC_CSR11, reg);
  747. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  748. USB_MODE_WAKEUP, REGISTER_TIMEOUT);
  749. }
  750. }
  751. static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
  752. struct rt2x00lib_conf *libconf,
  753. const unsigned int flags)
  754. {
  755. /* Always recalculate LNA gain before changing configuration */
  756. rt73usb_config_lna_gain(rt2x00dev, libconf);
  757. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  758. rt73usb_config_channel(rt2x00dev, &libconf->rf,
  759. libconf->conf->power_level);
  760. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  761. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  762. rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  763. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  764. rt73usb_config_retry_limit(rt2x00dev, libconf);
  765. if (flags & IEEE80211_CONF_CHANGE_PS)
  766. rt73usb_config_ps(rt2x00dev, libconf);
  767. }
  768. /*
  769. * Link tuning
  770. */
  771. static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev,
  772. struct link_qual *qual)
  773. {
  774. u32 reg;
  775. /*
  776. * Update FCS error count from register.
  777. */
  778. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  779. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  780. /*
  781. * Update False CCA count from register.
  782. */
  783. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  784. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  785. }
  786. static inline void rt73usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  787. struct link_qual *qual, u8 vgc_level)
  788. {
  789. if (qual->vgc_level != vgc_level) {
  790. rt73usb_bbp_write(rt2x00dev, 17, vgc_level);
  791. qual->vgc_level = vgc_level;
  792. qual->vgc_level_reg = vgc_level;
  793. }
  794. }
  795. static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  796. struct link_qual *qual)
  797. {
  798. rt73usb_set_vgc(rt2x00dev, qual, 0x20);
  799. }
  800. static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  801. struct link_qual *qual, const u32 count)
  802. {
  803. u8 up_bound;
  804. u8 low_bound;
  805. /*
  806. * Determine r17 bounds.
  807. */
  808. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  809. low_bound = 0x28;
  810. up_bound = 0x48;
  811. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  812. low_bound += 0x10;
  813. up_bound += 0x10;
  814. }
  815. } else {
  816. if (qual->rssi > -82) {
  817. low_bound = 0x1c;
  818. up_bound = 0x40;
  819. } else if (qual->rssi > -84) {
  820. low_bound = 0x1c;
  821. up_bound = 0x20;
  822. } else {
  823. low_bound = 0x1c;
  824. up_bound = 0x1c;
  825. }
  826. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  827. low_bound += 0x14;
  828. up_bound += 0x10;
  829. }
  830. }
  831. /*
  832. * If we are not associated, we should go straight to the
  833. * dynamic CCA tuning.
  834. */
  835. if (!rt2x00dev->intf_associated)
  836. goto dynamic_cca_tune;
  837. /*
  838. * Special big-R17 for very short distance
  839. */
  840. if (qual->rssi > -35) {
  841. rt73usb_set_vgc(rt2x00dev, qual, 0x60);
  842. return;
  843. }
  844. /*
  845. * Special big-R17 for short distance
  846. */
  847. if (qual->rssi >= -58) {
  848. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  849. return;
  850. }
  851. /*
  852. * Special big-R17 for middle-short distance
  853. */
  854. if (qual->rssi >= -66) {
  855. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x10);
  856. return;
  857. }
  858. /*
  859. * Special mid-R17 for middle distance
  860. */
  861. if (qual->rssi >= -74) {
  862. rt73usb_set_vgc(rt2x00dev, qual, low_bound + 0x08);
  863. return;
  864. }
  865. /*
  866. * Special case: Change up_bound based on the rssi.
  867. * Lower up_bound when rssi is weaker then -74 dBm.
  868. */
  869. up_bound -= 2 * (-74 - qual->rssi);
  870. if (low_bound > up_bound)
  871. up_bound = low_bound;
  872. if (qual->vgc_level > up_bound) {
  873. rt73usb_set_vgc(rt2x00dev, qual, up_bound);
  874. return;
  875. }
  876. dynamic_cca_tune:
  877. /*
  878. * r17 does not yet exceed upper limit, continue and base
  879. * the r17 tuning on the false CCA count.
  880. */
  881. if ((qual->false_cca > 512) && (qual->vgc_level < up_bound))
  882. rt73usb_set_vgc(rt2x00dev, qual,
  883. min_t(u8, qual->vgc_level + 4, up_bound));
  884. else if ((qual->false_cca < 100) && (qual->vgc_level > low_bound))
  885. rt73usb_set_vgc(rt2x00dev, qual,
  886. max_t(u8, qual->vgc_level - 4, low_bound));
  887. }
  888. /*
  889. * Firmware functions
  890. */
  891. static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  892. {
  893. return FIRMWARE_RT2571;
  894. }
  895. static int rt73usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  896. const u8 *data, const size_t len)
  897. {
  898. u16 fw_crc;
  899. u16 crc;
  900. /*
  901. * Only support 2kb firmware files.
  902. */
  903. if (len != 2048)
  904. return FW_BAD_LENGTH;
  905. /*
  906. * The last 2 bytes in the firmware array are the crc checksum itself,
  907. * this means that we should never pass those 2 bytes to the crc
  908. * algorithm.
  909. */
  910. fw_crc = (data[len - 2] << 8 | data[len - 1]);
  911. /*
  912. * Use the crc itu-t algorithm.
  913. */
  914. crc = crc_itu_t(0, data, len - 2);
  915. crc = crc_itu_t_byte(crc, 0);
  916. crc = crc_itu_t_byte(crc, 0);
  917. return (fw_crc == crc) ? FW_OK : FW_BAD_CRC;
  918. }
  919. static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  920. const u8 *data, const size_t len)
  921. {
  922. unsigned int i;
  923. int status;
  924. u32 reg;
  925. /*
  926. * Wait for stable hardware.
  927. */
  928. for (i = 0; i < 100; i++) {
  929. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  930. if (reg)
  931. break;
  932. msleep(1);
  933. }
  934. if (!reg) {
  935. ERROR(rt2x00dev, "Unstable hardware.\n");
  936. return -EBUSY;
  937. }
  938. /*
  939. * Write firmware to device.
  940. */
  941. rt2x00usb_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE, data, len);
  942. /*
  943. * Send firmware request to device to load firmware,
  944. * we need to specify a long timeout time.
  945. */
  946. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  947. 0, USB_MODE_FIRMWARE,
  948. REGISTER_TIMEOUT_FIRMWARE);
  949. if (status < 0) {
  950. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  951. return status;
  952. }
  953. return 0;
  954. }
  955. /*
  956. * Initialization functions.
  957. */
  958. static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
  959. {
  960. u32 reg;
  961. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  962. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  963. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  964. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  965. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  966. rt2x00usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  967. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  968. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  969. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  970. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  971. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  972. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  973. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  974. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  975. rt2x00usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  976. /*
  977. * CCK TXD BBP registers
  978. */
  979. rt2x00usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  980. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  981. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  982. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  983. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  984. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  985. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  986. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  987. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  988. rt2x00usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  989. /*
  990. * OFDM TXD BBP registers
  991. */
  992. rt2x00usb_register_read(rt2x00dev, TXRX_CSR3, &reg);
  993. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  994. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  995. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  996. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  997. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  998. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  999. rt2x00usb_register_write(rt2x00dev, TXRX_CSR3, reg);
  1000. rt2x00usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1001. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1002. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1003. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1004. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1005. rt2x00usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  1006. rt2x00usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1007. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1008. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1009. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1010. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1011. rt2x00usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  1012. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1013. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1014. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1015. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1016. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1017. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1018. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1019. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1020. rt2x00usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1021. rt2x00usb_register_read(rt2x00dev, MAC_CSR6, &reg);
  1022. rt2x00_set_field32(&reg, MAC_CSR6_MAX_FRAME_UNIT, 0xfff);
  1023. rt2x00usb_register_write(rt2x00dev, MAC_CSR6, reg);
  1024. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718);
  1025. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1026. return -EBUSY;
  1027. rt2x00usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00);
  1028. /*
  1029. * Invalidate all Shared Keys (SEC_CSR0),
  1030. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1031. */
  1032. rt2x00usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1033. rt2x00usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1034. rt2x00usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1035. reg = 0x000023b0;
  1036. if (rt2x00_rf(rt2x00dev, RF5225) || rt2x00_rf(rt2x00dev, RF2527))
  1037. rt2x00_set_field32(&reg, PHY_CSR1_RF_RPI, 1);
  1038. rt2x00usb_register_write(rt2x00dev, PHY_CSR1, reg);
  1039. rt2x00usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06);
  1040. rt2x00usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1041. rt2x00usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
  1042. rt2x00usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  1043. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1044. rt2x00usb_register_write(rt2x00dev, MAC_CSR9, reg);
  1045. /*
  1046. * Clear all beacons
  1047. * For the Beacon base registers we only need to clear
  1048. * the first byte since that byte contains the VALID and OWNER
  1049. * bits which (when set to 0) will invalidate the entire beacon.
  1050. */
  1051. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1052. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1053. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1054. rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1055. /*
  1056. * We must clear the error counters.
  1057. * These registers are cleared on read,
  1058. * so we may pass a useless variable to store the value.
  1059. */
  1060. rt2x00usb_register_read(rt2x00dev, STA_CSR0, &reg);
  1061. rt2x00usb_register_read(rt2x00dev, STA_CSR1, &reg);
  1062. rt2x00usb_register_read(rt2x00dev, STA_CSR2, &reg);
  1063. /*
  1064. * Reset MAC and BBP registers.
  1065. */
  1066. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1067. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1068. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1069. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1070. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1071. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1072. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1073. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1074. rt2x00usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1075. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1076. rt2x00usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1077. return 0;
  1078. }
  1079. static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1080. {
  1081. unsigned int i;
  1082. u8 value;
  1083. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1084. rt73usb_bbp_read(rt2x00dev, 0, &value);
  1085. if ((value != 0xff) && (value != 0x00))
  1086. return 0;
  1087. udelay(REGISTER_BUSY_DELAY);
  1088. }
  1089. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1090. return -EACCES;
  1091. }
  1092. static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1093. {
  1094. unsigned int i;
  1095. u16 eeprom;
  1096. u8 reg_id;
  1097. u8 value;
  1098. if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
  1099. return -EACCES;
  1100. rt73usb_bbp_write(rt2x00dev, 3, 0x80);
  1101. rt73usb_bbp_write(rt2x00dev, 15, 0x30);
  1102. rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
  1103. rt73usb_bbp_write(rt2x00dev, 22, 0x38);
  1104. rt73usb_bbp_write(rt2x00dev, 23, 0x06);
  1105. rt73usb_bbp_write(rt2x00dev, 24, 0xfe);
  1106. rt73usb_bbp_write(rt2x00dev, 25, 0x0a);
  1107. rt73usb_bbp_write(rt2x00dev, 26, 0x0d);
  1108. rt73usb_bbp_write(rt2x00dev, 32, 0x0b);
  1109. rt73usb_bbp_write(rt2x00dev, 34, 0x12);
  1110. rt73usb_bbp_write(rt2x00dev, 37, 0x07);
  1111. rt73usb_bbp_write(rt2x00dev, 39, 0xf8);
  1112. rt73usb_bbp_write(rt2x00dev, 41, 0x60);
  1113. rt73usb_bbp_write(rt2x00dev, 53, 0x10);
  1114. rt73usb_bbp_write(rt2x00dev, 54, 0x18);
  1115. rt73usb_bbp_write(rt2x00dev, 60, 0x10);
  1116. rt73usb_bbp_write(rt2x00dev, 61, 0x04);
  1117. rt73usb_bbp_write(rt2x00dev, 62, 0x04);
  1118. rt73usb_bbp_write(rt2x00dev, 75, 0xfe);
  1119. rt73usb_bbp_write(rt2x00dev, 86, 0xfe);
  1120. rt73usb_bbp_write(rt2x00dev, 88, 0xfe);
  1121. rt73usb_bbp_write(rt2x00dev, 90, 0x0f);
  1122. rt73usb_bbp_write(rt2x00dev, 99, 0x00);
  1123. rt73usb_bbp_write(rt2x00dev, 102, 0x16);
  1124. rt73usb_bbp_write(rt2x00dev, 107, 0x04);
  1125. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1126. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1127. if (eeprom != 0xffff && eeprom != 0x0000) {
  1128. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1129. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1130. rt73usb_bbp_write(rt2x00dev, reg_id, value);
  1131. }
  1132. }
  1133. return 0;
  1134. }
  1135. /*
  1136. * Device state switch handlers.
  1137. */
  1138. static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1139. enum dev_state state)
  1140. {
  1141. u32 reg;
  1142. rt2x00usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1143. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  1144. (state == STATE_RADIO_RX_OFF) ||
  1145. (state == STATE_RADIO_RX_OFF_LINK));
  1146. rt2x00usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1147. }
  1148. static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1149. {
  1150. /*
  1151. * Initialize all registers.
  1152. */
  1153. if (unlikely(rt73usb_init_registers(rt2x00dev) ||
  1154. rt73usb_init_bbp(rt2x00dev)))
  1155. return -EIO;
  1156. return 0;
  1157. }
  1158. static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1159. {
  1160. rt2x00usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1161. /*
  1162. * Disable synchronisation.
  1163. */
  1164. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  1165. rt2x00usb_disable_radio(rt2x00dev);
  1166. }
  1167. static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1168. {
  1169. u32 reg, reg2;
  1170. unsigned int i;
  1171. char put_to_sleep;
  1172. put_to_sleep = (state != STATE_AWAKE);
  1173. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  1174. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1175. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1176. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1177. /*
  1178. * Device is not guaranteed to be in the requested state yet.
  1179. * We must wait until the register indicates that the
  1180. * device has entered the correct state.
  1181. */
  1182. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1183. rt2x00usb_register_read(rt2x00dev, MAC_CSR12, &reg2);
  1184. state = rt2x00_get_field32(reg2, MAC_CSR12_BBP_CURRENT_STATE);
  1185. if (state == !put_to_sleep)
  1186. return 0;
  1187. rt2x00usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1188. msleep(10);
  1189. }
  1190. return -EBUSY;
  1191. }
  1192. static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1193. enum dev_state state)
  1194. {
  1195. int retval = 0;
  1196. switch (state) {
  1197. case STATE_RADIO_ON:
  1198. retval = rt73usb_enable_radio(rt2x00dev);
  1199. break;
  1200. case STATE_RADIO_OFF:
  1201. rt73usb_disable_radio(rt2x00dev);
  1202. break;
  1203. case STATE_RADIO_RX_ON:
  1204. case STATE_RADIO_RX_ON_LINK:
  1205. case STATE_RADIO_RX_OFF:
  1206. case STATE_RADIO_RX_OFF_LINK:
  1207. rt73usb_toggle_rx(rt2x00dev, state);
  1208. break;
  1209. case STATE_RADIO_IRQ_ON:
  1210. case STATE_RADIO_IRQ_ON_ISR:
  1211. case STATE_RADIO_IRQ_OFF:
  1212. case STATE_RADIO_IRQ_OFF_ISR:
  1213. /* No support, but no error either */
  1214. break;
  1215. case STATE_DEEP_SLEEP:
  1216. case STATE_SLEEP:
  1217. case STATE_STANDBY:
  1218. case STATE_AWAKE:
  1219. retval = rt73usb_set_state(rt2x00dev, state);
  1220. break;
  1221. default:
  1222. retval = -ENOTSUPP;
  1223. break;
  1224. }
  1225. if (unlikely(retval))
  1226. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1227. state, retval);
  1228. return retval;
  1229. }
  1230. /*
  1231. * TX descriptor initialization
  1232. */
  1233. static void rt73usb_write_tx_desc(struct queue_entry *entry,
  1234. struct txentry_desc *txdesc)
  1235. {
  1236. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1237. __le32 *txd = (__le32 *) entry->skb->data;
  1238. u32 word;
  1239. /*
  1240. * Start writing the descriptor words.
  1241. */
  1242. rt2x00_desc_read(txd, 0, &word);
  1243. rt2x00_set_field32(&word, TXD_W0_BURST,
  1244. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1245. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1246. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1247. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1248. rt2x00_set_field32(&word, TXD_W0_ACK,
  1249. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1250. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1251. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1252. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1253. (txdesc->rate_mode == RATE_MODE_OFDM));
  1254. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1255. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1256. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1257. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
  1258. test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
  1259. rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
  1260. test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
  1261. rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
  1262. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length);
  1263. rt2x00_set_field32(&word, TXD_W0_BURST2,
  1264. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1265. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
  1266. rt2x00_desc_write(txd, 0, word);
  1267. rt2x00_desc_read(txd, 1, &word);
  1268. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, txdesc->qid);
  1269. rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
  1270. rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
  1271. rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
  1272. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  1273. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1274. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1275. rt2x00_desc_write(txd, 1, word);
  1276. rt2x00_desc_read(txd, 2, &word);
  1277. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  1278. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  1279. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  1280. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  1281. rt2x00_desc_write(txd, 2, word);
  1282. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1283. _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
  1284. _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
  1285. }
  1286. rt2x00_desc_read(txd, 5, &word);
  1287. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1288. TXPOWER_TO_DEV(entry->queue->rt2x00dev->tx_power));
  1289. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1290. rt2x00_desc_write(txd, 5, word);
  1291. /*
  1292. * Register descriptor details in skb frame descriptor.
  1293. */
  1294. skbdesc->flags |= SKBDESC_DESC_IN_SKB;
  1295. skbdesc->desc = txd;
  1296. skbdesc->desc_len = TXD_DESC_SIZE;
  1297. }
  1298. /*
  1299. * TX data initialization
  1300. */
  1301. static void rt73usb_write_beacon(struct queue_entry *entry,
  1302. struct txentry_desc *txdesc)
  1303. {
  1304. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1305. unsigned int beacon_base;
  1306. u32 reg;
  1307. /*
  1308. * Disable beaconing while we are reloading the beacon data,
  1309. * otherwise we might be sending out invalid data.
  1310. */
  1311. rt2x00usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1312. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1313. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1314. /*
  1315. * Add space for the descriptor in front of the skb.
  1316. */
  1317. skb_push(entry->skb, TXD_DESC_SIZE);
  1318. memset(entry->skb->data, 0, TXD_DESC_SIZE);
  1319. /*
  1320. * Write the TX descriptor for the beacon.
  1321. */
  1322. rt73usb_write_tx_desc(entry, txdesc);
  1323. /*
  1324. * Dump beacon to userspace through debugfs.
  1325. */
  1326. rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
  1327. /*
  1328. * Write entire beacon with descriptor to register.
  1329. */
  1330. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1331. rt2x00usb_register_multiwrite(rt2x00dev, beacon_base,
  1332. entry->skb->data, entry->skb->len);
  1333. /*
  1334. * Enable beaconing again.
  1335. *
  1336. * For Wi-Fi faily generated beacons between participating stations.
  1337. * Set TBTT phase adaptive adjustment step to 8us (default 16us)
  1338. */
  1339. rt2x00usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1340. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  1341. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  1342. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1343. rt2x00usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1344. /*
  1345. * Clean up the beacon skb.
  1346. */
  1347. dev_kfree_skb(entry->skb);
  1348. entry->skb = NULL;
  1349. }
  1350. static int rt73usb_get_tx_data_len(struct queue_entry *entry)
  1351. {
  1352. int length;
  1353. /*
  1354. * The length _must_ be a multiple of 4,
  1355. * but it must _not_ be a multiple of the USB packet size.
  1356. */
  1357. length = roundup(entry->skb->len, 4);
  1358. length += (4 * !(length % entry->queue->usb_maxpacket));
  1359. return length;
  1360. }
  1361. static void rt73usb_kill_tx_queue(struct data_queue *queue)
  1362. {
  1363. if (queue->qid == QID_BEACON)
  1364. rt2x00usb_register_write(queue->rt2x00dev, TXRX_CSR9, 0);
  1365. rt2x00usb_kill_tx_queue(queue);
  1366. }
  1367. /*
  1368. * RX control handlers
  1369. */
  1370. static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1371. {
  1372. u8 offset = rt2x00dev->lna_gain;
  1373. u8 lna;
  1374. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1375. switch (lna) {
  1376. case 3:
  1377. offset += 90;
  1378. break;
  1379. case 2:
  1380. offset += 74;
  1381. break;
  1382. case 1:
  1383. offset += 64;
  1384. break;
  1385. default:
  1386. return 0;
  1387. }
  1388. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  1389. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  1390. if (lna == 3 || lna == 2)
  1391. offset += 10;
  1392. } else {
  1393. if (lna == 3)
  1394. offset += 6;
  1395. else if (lna == 2)
  1396. offset += 8;
  1397. }
  1398. }
  1399. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1400. }
  1401. static void rt73usb_fill_rxdone(struct queue_entry *entry,
  1402. struct rxdone_entry_desc *rxdesc)
  1403. {
  1404. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1405. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1406. __le32 *rxd = (__le32 *)entry->skb->data;
  1407. u32 word0;
  1408. u32 word1;
  1409. /*
  1410. * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
  1411. * frame data in rt2x00usb.
  1412. */
  1413. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1414. rxd = (__le32 *)skbdesc->desc;
  1415. /*
  1416. * It is now safe to read the descriptor on all architectures.
  1417. */
  1418. rt2x00_desc_read(rxd, 0, &word0);
  1419. rt2x00_desc_read(rxd, 1, &word1);
  1420. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1421. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1422. rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
  1423. rxdesc->cipher_status = rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
  1424. if (rxdesc->cipher != CIPHER_NONE) {
  1425. _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
  1426. _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
  1427. rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
  1428. _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
  1429. rxdesc->dev_flags |= RXDONE_CRYPTO_ICV;
  1430. /*
  1431. * Hardware has stripped IV/EIV data from 802.11 frame during
  1432. * decryption. It has provided the data separately but rt2x00lib
  1433. * should decide if it should be reinserted.
  1434. */
  1435. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1436. /*
  1437. * FIXME: Legacy driver indicates that the frame does
  1438. * contain the Michael Mic. Unfortunately, in rt2x00
  1439. * the MIC seems to be missing completely...
  1440. */
  1441. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1442. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1443. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1444. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1445. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1446. }
  1447. /*
  1448. * Obtain the status about this packet.
  1449. * When frame was received with an OFDM bitrate,
  1450. * the signal is the PLCP value. If it was received with
  1451. * a CCK bitrate the signal is the rate in 100kbit/s.
  1452. */
  1453. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1454. rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1);
  1455. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1456. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1457. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1458. else
  1459. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1460. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1461. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1462. /*
  1463. * Set skb pointers, and update frame information.
  1464. */
  1465. skb_pull(entry->skb, entry->queue->desc_size);
  1466. skb_trim(entry->skb, rxdesc->size);
  1467. }
  1468. /*
  1469. * Device probe functions.
  1470. */
  1471. static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1472. {
  1473. u16 word;
  1474. u8 *mac;
  1475. s8 value;
  1476. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1477. /*
  1478. * Start validation of the data that has been read.
  1479. */
  1480. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1481. if (!is_valid_ether_addr(mac)) {
  1482. random_ether_addr(mac);
  1483. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1484. }
  1485. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1486. if (word == 0xffff) {
  1487. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1488. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1489. ANTENNA_B);
  1490. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1491. ANTENNA_B);
  1492. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1493. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1494. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1495. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226);
  1496. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1497. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1498. }
  1499. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1500. if (word == 0xffff) {
  1501. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0);
  1502. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1503. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1504. }
  1505. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1506. if (word == 0xffff) {
  1507. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0);
  1508. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0);
  1509. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0);
  1510. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0);
  1511. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0);
  1512. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0);
  1513. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0);
  1514. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0);
  1515. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1516. LED_MODE_DEFAULT);
  1517. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1518. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1519. }
  1520. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1521. if (word == 0xffff) {
  1522. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1523. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1524. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1525. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1526. }
  1527. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1528. if (word == 0xffff) {
  1529. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1530. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1531. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1532. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1533. } else {
  1534. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1535. if (value < -10 || value > 10)
  1536. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1537. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1538. if (value < -10 || value > 10)
  1539. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1540. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1541. }
  1542. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1543. if (word == 0xffff) {
  1544. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1545. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1546. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1547. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1548. } else {
  1549. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1550. if (value < -10 || value > 10)
  1551. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1552. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1553. if (value < -10 || value > 10)
  1554. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1555. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1556. }
  1557. return 0;
  1558. }
  1559. static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1560. {
  1561. u32 reg;
  1562. u16 value;
  1563. u16 eeprom;
  1564. /*
  1565. * Read EEPROM word for configuration.
  1566. */
  1567. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1568. /*
  1569. * Identify RF chipset.
  1570. */
  1571. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1572. rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1573. rt2x00_set_chip(rt2x00dev, rt2x00_get_field32(reg, MAC_CSR0_CHIPSET),
  1574. value, rt2x00_get_field32(reg, MAC_CSR0_REVISION));
  1575. if (!rt2x00_rt(rt2x00dev, RT2573) || (rt2x00_rev(rt2x00dev) == 0)) {
  1576. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1577. return -ENODEV;
  1578. }
  1579. if (!rt2x00_rf(rt2x00dev, RF5226) &&
  1580. !rt2x00_rf(rt2x00dev, RF2528) &&
  1581. !rt2x00_rf(rt2x00dev, RF5225) &&
  1582. !rt2x00_rf(rt2x00dev, RF2527)) {
  1583. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1584. return -ENODEV;
  1585. }
  1586. /*
  1587. * Identify default antenna configuration.
  1588. */
  1589. rt2x00dev->default_ant.tx =
  1590. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1591. rt2x00dev->default_ant.rx =
  1592. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1593. /*
  1594. * Read the Frame type.
  1595. */
  1596. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1597. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1598. /*
  1599. * Detect if this device has an hardware controlled radio.
  1600. */
  1601. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1602. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1603. /*
  1604. * Read frequency offset.
  1605. */
  1606. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1607. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1608. /*
  1609. * Read external LNA informations.
  1610. */
  1611. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1612. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) {
  1613. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1614. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1615. }
  1616. /*
  1617. * Store led settings, for correct led behaviour.
  1618. */
  1619. #ifdef CONFIG_RT2X00_LIB_LEDS
  1620. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1621. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1622. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1623. if (value == LED_MODE_SIGNAL_STRENGTH)
  1624. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1625. LED_TYPE_QUALITY);
  1626. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  1627. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1628. rt2x00_get_field16(eeprom,
  1629. EEPROM_LED_POLARITY_GPIO_0));
  1630. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1631. rt2x00_get_field16(eeprom,
  1632. EEPROM_LED_POLARITY_GPIO_1));
  1633. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1634. rt2x00_get_field16(eeprom,
  1635. EEPROM_LED_POLARITY_GPIO_2));
  1636. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1637. rt2x00_get_field16(eeprom,
  1638. EEPROM_LED_POLARITY_GPIO_3));
  1639. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1640. rt2x00_get_field16(eeprom,
  1641. EEPROM_LED_POLARITY_GPIO_4));
  1642. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  1643. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1644. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  1645. rt2x00_get_field16(eeprom,
  1646. EEPROM_LED_POLARITY_RDY_G));
  1647. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  1648. rt2x00_get_field16(eeprom,
  1649. EEPROM_LED_POLARITY_RDY_A));
  1650. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1651. return 0;
  1652. }
  1653. /*
  1654. * RF value list for RF2528
  1655. * Supports: 2.4 GHz
  1656. */
  1657. static const struct rf_channel rf_vals_bg_2528[] = {
  1658. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1659. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1660. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1661. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1662. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1663. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1664. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1665. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1666. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1667. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1668. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1669. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1670. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1671. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1672. };
  1673. /*
  1674. * RF value list for RF5226
  1675. * Supports: 2.4 GHz & 5.2 GHz
  1676. */
  1677. static const struct rf_channel rf_vals_5226[] = {
  1678. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1679. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1680. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1681. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1682. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1683. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1684. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1685. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1686. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1687. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1688. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1689. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1690. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1691. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1692. /* 802.11 UNI / HyperLan 2 */
  1693. { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
  1694. { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
  1695. { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
  1696. { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
  1697. { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
  1698. { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
  1699. { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
  1700. { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
  1701. /* 802.11 HyperLan 2 */
  1702. { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
  1703. { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
  1704. { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
  1705. { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
  1706. { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
  1707. { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
  1708. { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
  1709. { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
  1710. { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
  1711. { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
  1712. /* 802.11 UNII */
  1713. { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
  1714. { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
  1715. { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
  1716. { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
  1717. { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
  1718. { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
  1719. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1720. { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
  1721. { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
  1722. { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
  1723. { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
  1724. };
  1725. /*
  1726. * RF value list for RF5225 & RF2527
  1727. * Supports: 2.4 GHz & 5.2 GHz
  1728. */
  1729. static const struct rf_channel rf_vals_5225_2527[] = {
  1730. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1731. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1732. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1733. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1734. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1735. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1736. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1737. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1738. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1739. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1740. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1741. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1742. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1743. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1744. /* 802.11 UNI / HyperLan 2 */
  1745. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1746. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1747. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1748. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1749. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1750. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1751. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1752. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1753. /* 802.11 HyperLan 2 */
  1754. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1755. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1756. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1757. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1758. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1759. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1760. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1761. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1762. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1763. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1764. /* 802.11 UNII */
  1765. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1766. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1767. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1768. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1769. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1770. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1771. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1772. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1773. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1774. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1775. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1776. };
  1777. static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1778. {
  1779. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1780. struct channel_info *info;
  1781. char *tx_power;
  1782. unsigned int i;
  1783. /*
  1784. * Initialize all hw fields.
  1785. *
  1786. * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING unless we are
  1787. * capable of sending the buffered frames out after the DTIM
  1788. * transmission using rt2x00lib_beacondone. This will send out
  1789. * multicast and broadcast traffic immediately instead of buffering it
  1790. * infinitly and thus dropping it after some time.
  1791. */
  1792. rt2x00dev->hw->flags =
  1793. IEEE80211_HW_SIGNAL_DBM |
  1794. IEEE80211_HW_SUPPORTS_PS |
  1795. IEEE80211_HW_PS_NULLFUNC_STACK;
  1796. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1797. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1798. rt2x00_eeprom_addr(rt2x00dev,
  1799. EEPROM_MAC_ADDR_0));
  1800. /*
  1801. * Initialize hw_mode information.
  1802. */
  1803. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1804. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1805. if (rt2x00_rf(rt2x00dev, RF2528)) {
  1806. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
  1807. spec->channels = rf_vals_bg_2528;
  1808. } else if (rt2x00_rf(rt2x00dev, RF5226)) {
  1809. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1810. spec->num_channels = ARRAY_SIZE(rf_vals_5226);
  1811. spec->channels = rf_vals_5226;
  1812. } else if (rt2x00_rf(rt2x00dev, RF2527)) {
  1813. spec->num_channels = 14;
  1814. spec->channels = rf_vals_5225_2527;
  1815. } else if (rt2x00_rf(rt2x00dev, RF5225)) {
  1816. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1817. spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527);
  1818. spec->channels = rf_vals_5225_2527;
  1819. }
  1820. /*
  1821. * Create channel information array
  1822. */
  1823. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  1824. if (!info)
  1825. return -ENOMEM;
  1826. spec->channels_info = info;
  1827. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1828. for (i = 0; i < 14; i++) {
  1829. info[i].max_power = MAX_TXPOWER;
  1830. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1831. }
  1832. if (spec->num_channels > 14) {
  1833. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1834. for (i = 14; i < spec->num_channels; i++) {
  1835. info[i].max_power = MAX_TXPOWER;
  1836. info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1837. }
  1838. }
  1839. return 0;
  1840. }
  1841. static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1842. {
  1843. int retval;
  1844. /*
  1845. * Allocate eeprom data.
  1846. */
  1847. retval = rt73usb_validate_eeprom(rt2x00dev);
  1848. if (retval)
  1849. return retval;
  1850. retval = rt73usb_init_eeprom(rt2x00dev);
  1851. if (retval)
  1852. return retval;
  1853. /*
  1854. * Initialize hw specifications.
  1855. */
  1856. retval = rt73usb_probe_hw_mode(rt2x00dev);
  1857. if (retval)
  1858. return retval;
  1859. /*
  1860. * This device has multiple filters for control frames,
  1861. * but has no a separate filter for PS Poll frames.
  1862. */
  1863. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  1864. /*
  1865. * This device requires firmware.
  1866. */
  1867. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  1868. if (!modparam_nohwcrypt)
  1869. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  1870. __set_bit(DRIVER_SUPPORT_LINK_TUNING, &rt2x00dev->flags);
  1871. __set_bit(DRIVER_SUPPORT_WATCHDOG, &rt2x00dev->flags);
  1872. /*
  1873. * Set the rssi offset.
  1874. */
  1875. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1876. return 0;
  1877. }
  1878. /*
  1879. * IEEE80211 stack callback functions.
  1880. */
  1881. static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  1882. const struct ieee80211_tx_queue_params *params)
  1883. {
  1884. struct rt2x00_dev *rt2x00dev = hw->priv;
  1885. struct data_queue *queue;
  1886. struct rt2x00_field32 field;
  1887. int retval;
  1888. u32 reg;
  1889. u32 offset;
  1890. /*
  1891. * First pass the configuration through rt2x00lib, that will
  1892. * update the queue settings and validate the input. After that
  1893. * we are free to update the registers based on the value
  1894. * in the queue parameter.
  1895. */
  1896. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  1897. if (retval)
  1898. return retval;
  1899. /*
  1900. * We only need to perform additional register initialization
  1901. * for WMM queues/
  1902. */
  1903. if (queue_idx >= 4)
  1904. return 0;
  1905. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  1906. /* Update WMM TXOP register */
  1907. offset = AC_TXOP_CSR0 + (sizeof(u32) * (!!(queue_idx & 2)));
  1908. field.bit_offset = (queue_idx & 1) * 16;
  1909. field.bit_mask = 0xffff << field.bit_offset;
  1910. rt2x00usb_register_read(rt2x00dev, offset, &reg);
  1911. rt2x00_set_field32(&reg, field, queue->txop);
  1912. rt2x00usb_register_write(rt2x00dev, offset, reg);
  1913. /* Update WMM registers */
  1914. field.bit_offset = queue_idx * 4;
  1915. field.bit_mask = 0xf << field.bit_offset;
  1916. rt2x00usb_register_read(rt2x00dev, AIFSN_CSR, &reg);
  1917. rt2x00_set_field32(&reg, field, queue->aifs);
  1918. rt2x00usb_register_write(rt2x00dev, AIFSN_CSR, reg);
  1919. rt2x00usb_register_read(rt2x00dev, CWMIN_CSR, &reg);
  1920. rt2x00_set_field32(&reg, field, queue->cw_min);
  1921. rt2x00usb_register_write(rt2x00dev, CWMIN_CSR, reg);
  1922. rt2x00usb_register_read(rt2x00dev, CWMAX_CSR, &reg);
  1923. rt2x00_set_field32(&reg, field, queue->cw_max);
  1924. rt2x00usb_register_write(rt2x00dev, CWMAX_CSR, reg);
  1925. return 0;
  1926. }
  1927. static u64 rt73usb_get_tsf(struct ieee80211_hw *hw)
  1928. {
  1929. struct rt2x00_dev *rt2x00dev = hw->priv;
  1930. u64 tsf;
  1931. u32 reg;
  1932. rt2x00usb_register_read(rt2x00dev, TXRX_CSR13, &reg);
  1933. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  1934. rt2x00usb_register_read(rt2x00dev, TXRX_CSR12, &reg);
  1935. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  1936. return tsf;
  1937. }
  1938. static const struct ieee80211_ops rt73usb_mac80211_ops = {
  1939. .tx = rt2x00mac_tx,
  1940. .start = rt2x00mac_start,
  1941. .stop = rt2x00mac_stop,
  1942. .add_interface = rt2x00mac_add_interface,
  1943. .remove_interface = rt2x00mac_remove_interface,
  1944. .config = rt2x00mac_config,
  1945. .configure_filter = rt2x00mac_configure_filter,
  1946. .set_tim = rt2x00mac_set_tim,
  1947. .set_key = rt2x00mac_set_key,
  1948. .sw_scan_start = rt2x00mac_sw_scan_start,
  1949. .sw_scan_complete = rt2x00mac_sw_scan_complete,
  1950. .get_stats = rt2x00mac_get_stats,
  1951. .bss_info_changed = rt2x00mac_bss_info_changed,
  1952. .conf_tx = rt73usb_conf_tx,
  1953. .get_tsf = rt73usb_get_tsf,
  1954. .rfkill_poll = rt2x00mac_rfkill_poll,
  1955. };
  1956. static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
  1957. .probe_hw = rt73usb_probe_hw,
  1958. .get_firmware_name = rt73usb_get_firmware_name,
  1959. .check_firmware = rt73usb_check_firmware,
  1960. .load_firmware = rt73usb_load_firmware,
  1961. .initialize = rt2x00usb_initialize,
  1962. .uninitialize = rt2x00usb_uninitialize,
  1963. .clear_entry = rt2x00usb_clear_entry,
  1964. .set_device_state = rt73usb_set_device_state,
  1965. .rfkill_poll = rt73usb_rfkill_poll,
  1966. .link_stats = rt73usb_link_stats,
  1967. .reset_tuner = rt73usb_reset_tuner,
  1968. .link_tuner = rt73usb_link_tuner,
  1969. .watchdog = rt2x00usb_watchdog,
  1970. .write_tx_desc = rt73usb_write_tx_desc,
  1971. .write_beacon = rt73usb_write_beacon,
  1972. .get_tx_data_len = rt73usb_get_tx_data_len,
  1973. .kick_tx_queue = rt2x00usb_kick_tx_queue,
  1974. .kill_tx_queue = rt73usb_kill_tx_queue,
  1975. .fill_rxdone = rt73usb_fill_rxdone,
  1976. .config_shared_key = rt73usb_config_shared_key,
  1977. .config_pairwise_key = rt73usb_config_pairwise_key,
  1978. .config_filter = rt73usb_config_filter,
  1979. .config_intf = rt73usb_config_intf,
  1980. .config_erp = rt73usb_config_erp,
  1981. .config_ant = rt73usb_config_ant,
  1982. .config = rt73usb_config,
  1983. };
  1984. static const struct data_queue_desc rt73usb_queue_rx = {
  1985. .entry_num = RX_ENTRIES,
  1986. .data_size = DATA_FRAME_SIZE,
  1987. .desc_size = RXD_DESC_SIZE,
  1988. .priv_size = sizeof(struct queue_entry_priv_usb),
  1989. };
  1990. static const struct data_queue_desc rt73usb_queue_tx = {
  1991. .entry_num = TX_ENTRIES,
  1992. .data_size = DATA_FRAME_SIZE,
  1993. .desc_size = TXD_DESC_SIZE,
  1994. .priv_size = sizeof(struct queue_entry_priv_usb),
  1995. };
  1996. static const struct data_queue_desc rt73usb_queue_bcn = {
  1997. .entry_num = 4 * BEACON_ENTRIES,
  1998. .data_size = MGMT_FRAME_SIZE,
  1999. .desc_size = TXINFO_SIZE,
  2000. .priv_size = sizeof(struct queue_entry_priv_usb),
  2001. };
  2002. static const struct rt2x00_ops rt73usb_ops = {
  2003. .name = KBUILD_MODNAME,
  2004. .max_sta_intf = 1,
  2005. .max_ap_intf = 4,
  2006. .eeprom_size = EEPROM_SIZE,
  2007. .rf_size = RF_SIZE,
  2008. .tx_queues = NUM_TX_QUEUES,
  2009. .extra_tx_headroom = TXD_DESC_SIZE,
  2010. .rx = &rt73usb_queue_rx,
  2011. .tx = &rt73usb_queue_tx,
  2012. .bcn = &rt73usb_queue_bcn,
  2013. .lib = &rt73usb_rt2x00_ops,
  2014. .hw = &rt73usb_mac80211_ops,
  2015. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2016. .debugfs = &rt73usb_rt2x00debug,
  2017. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2018. };
  2019. /*
  2020. * rt73usb module information.
  2021. */
  2022. static struct usb_device_id rt73usb_device_table[] = {
  2023. /* AboCom */
  2024. { USB_DEVICE(0x07b8, 0xb21b), USB_DEVICE_DATA(&rt73usb_ops) },
  2025. { USB_DEVICE(0x07b8, 0xb21c), USB_DEVICE_DATA(&rt73usb_ops) },
  2026. { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops) },
  2027. { USB_DEVICE(0x07b8, 0xb21e), USB_DEVICE_DATA(&rt73usb_ops) },
  2028. { USB_DEVICE(0x07b8, 0xb21f), USB_DEVICE_DATA(&rt73usb_ops) },
  2029. /* AL */
  2030. { USB_DEVICE(0x14b2, 0x3c10), USB_DEVICE_DATA(&rt73usb_ops) },
  2031. /* Amigo */
  2032. { USB_DEVICE(0x148f, 0x9021), USB_DEVICE_DATA(&rt73usb_ops) },
  2033. { USB_DEVICE(0x0eb0, 0x9021), USB_DEVICE_DATA(&rt73usb_ops) },
  2034. /* AMIT */
  2035. { USB_DEVICE(0x18c5, 0x0002), USB_DEVICE_DATA(&rt73usb_ops) },
  2036. /* Askey */
  2037. { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops) },
  2038. /* ASUS */
  2039. { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops) },
  2040. { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops) },
  2041. /* Belkin */
  2042. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops) },
  2043. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops) },
  2044. { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops) },
  2045. { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops) },
  2046. /* Billionton */
  2047. { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops) },
  2048. { USB_DEVICE(0x08dd, 0x0120), USB_DEVICE_DATA(&rt73usb_ops) },
  2049. /* Buffalo */
  2050. { USB_DEVICE(0x0411, 0x00d8), USB_DEVICE_DATA(&rt73usb_ops) },
  2051. { USB_DEVICE(0x0411, 0x00d9), USB_DEVICE_DATA(&rt73usb_ops) },
  2052. { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops) },
  2053. { USB_DEVICE(0x0411, 0x0116), USB_DEVICE_DATA(&rt73usb_ops) },
  2054. { USB_DEVICE(0x0411, 0x0119), USB_DEVICE_DATA(&rt73usb_ops) },
  2055. { USB_DEVICE(0x0411, 0x0137), USB_DEVICE_DATA(&rt73usb_ops) },
  2056. /* CEIVA */
  2057. { USB_DEVICE(0x178d, 0x02be), USB_DEVICE_DATA(&rt73usb_ops) },
  2058. /* CNet */
  2059. { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops) },
  2060. { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops) },
  2061. /* Conceptronic */
  2062. { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops) },
  2063. /* Corega */
  2064. { USB_DEVICE(0x07aa, 0x002e), USB_DEVICE_DATA(&rt73usb_ops) },
  2065. /* D-Link */
  2066. { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops) },
  2067. { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops) },
  2068. { USB_DEVICE(0x07d1, 0x3c06), USB_DEVICE_DATA(&rt73usb_ops) },
  2069. { USB_DEVICE(0x07d1, 0x3c07), USB_DEVICE_DATA(&rt73usb_ops) },
  2070. /* Edimax */
  2071. { USB_DEVICE(0x7392, 0x7318), USB_DEVICE_DATA(&rt73usb_ops) },
  2072. { USB_DEVICE(0x7392, 0x7618), USB_DEVICE_DATA(&rt73usb_ops) },
  2073. /* EnGenius */
  2074. { USB_DEVICE(0x1740, 0x3701), USB_DEVICE_DATA(&rt73usb_ops) },
  2075. /* Gemtek */
  2076. { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops) },
  2077. /* Gigabyte */
  2078. { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops) },
  2079. { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops) },
  2080. /* Huawei-3Com */
  2081. { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops) },
  2082. /* Hercules */
  2083. { USB_DEVICE(0x06f8, 0xe002), USB_DEVICE_DATA(&rt73usb_ops) },
  2084. { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops) },
  2085. { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops) },
  2086. /* Linksys */
  2087. { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
  2088. { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
  2089. { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) },
  2090. /* MSI */
  2091. { USB_DEVICE(0x0db0, 0x4600), USB_DEVICE_DATA(&rt73usb_ops) },
  2092. { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
  2093. { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
  2094. { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) },
  2095. { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) },
  2096. /* Ovislink */
  2097. { USB_DEVICE(0x1b75, 0x7318), USB_DEVICE_DATA(&rt73usb_ops) },
  2098. /* Ralink */
  2099. { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops) },
  2100. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) },
  2101. { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) },
  2102. /* Qcom */
  2103. { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) },
  2104. { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) },
  2105. { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops) },
  2106. /* Samsung */
  2107. { USB_DEVICE(0x04e8, 0x4471), USB_DEVICE_DATA(&rt73usb_ops) },
  2108. /* Senao */
  2109. { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops) },
  2110. /* Sitecom */
  2111. { USB_DEVICE(0x0df6, 0x0024), USB_DEVICE_DATA(&rt73usb_ops) },
  2112. { USB_DEVICE(0x0df6, 0x0027), USB_DEVICE_DATA(&rt73usb_ops) },
  2113. { USB_DEVICE(0x0df6, 0x002f), USB_DEVICE_DATA(&rt73usb_ops) },
  2114. { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops) },
  2115. { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops) },
  2116. /* Surecom */
  2117. { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops) },
  2118. /* Tilgin */
  2119. { USB_DEVICE(0x6933, 0x5001), USB_DEVICE_DATA(&rt73usb_ops) },
  2120. /* Philips */
  2121. { USB_DEVICE(0x0471, 0x200a), USB_DEVICE_DATA(&rt73usb_ops) },
  2122. /* Planex */
  2123. { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) },
  2124. { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) },
  2125. /* WideTell */
  2126. { USB_DEVICE(0x7167, 0x3840), USB_DEVICE_DATA(&rt73usb_ops) },
  2127. /* Zcom */
  2128. { USB_DEVICE(0x0cde, 0x001c), USB_DEVICE_DATA(&rt73usb_ops) },
  2129. /* ZyXEL */
  2130. { USB_DEVICE(0x0586, 0x3415), USB_DEVICE_DATA(&rt73usb_ops) },
  2131. { 0, }
  2132. };
  2133. MODULE_AUTHOR(DRV_PROJECT);
  2134. MODULE_VERSION(DRV_VERSION);
  2135. MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
  2136. MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
  2137. MODULE_DEVICE_TABLE(usb, rt73usb_device_table);
  2138. MODULE_FIRMWARE(FIRMWARE_RT2571);
  2139. MODULE_LICENSE("GPL");
  2140. static struct usb_driver rt73usb_driver = {
  2141. .name = KBUILD_MODNAME,
  2142. .id_table = rt73usb_device_table,
  2143. .probe = rt2x00usb_probe,
  2144. .disconnect = rt2x00usb_disconnect,
  2145. .suspend = rt2x00usb_suspend,
  2146. .resume = rt2x00usb_resume,
  2147. };
  2148. static int __init rt73usb_init(void)
  2149. {
  2150. return usb_register(&rt73usb_driver);
  2151. }
  2152. static void __exit rt73usb_exit(void)
  2153. {
  2154. usb_deregister(&rt73usb_driver);
  2155. }
  2156. module_init(rt73usb_init);
  2157. module_exit(rt73usb_exit);