rt73usb.c 75 KB

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