rt73usb.c 76 KB

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