rt73usb.c 77 KB

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