rt73usb.c 76 KB

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