rt73usb.c 76 KB

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