rt73usb.c 76 KB

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