rt2800usb.c 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118
  1. /*
  2. Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2800usb
  19. Abstract: rt2800usb device specific routines.
  20. Supported chipsets: RT2800U.
  21. */
  22. #include <linux/crc-ccitt.h>
  23. #include <linux/delay.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/usb.h>
  29. #include "rt2x00.h"
  30. #include "rt2x00usb.h"
  31. #include "rt2800lib.h"
  32. #include "rt2800usb.h"
  33. /*
  34. * Allow hardware encryption to be disabled.
  35. */
  36. static int modparam_nohwcrypt = 1;
  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. * rt2800_register_read and rt2800_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. rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
  55. #define WAIT_FOR_RFCSR(__dev, __reg) \
  56. rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
  57. #define WAIT_FOR_RF(__dev, __reg) \
  58. rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
  59. #define WAIT_FOR_MCU(__dev, __reg) \
  60. rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
  61. H2M_MAILBOX_CSR_OWNER, (__reg))
  62. static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  63. const unsigned int word, const u8 value)
  64. {
  65. u32 reg;
  66. mutex_lock(&rt2x00dev->csr_mutex);
  67. /*
  68. * Wait until the BBP becomes available, afterwards we
  69. * can safely write the new data into the register.
  70. */
  71. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  72. reg = 0;
  73. rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
  74. rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  75. rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  76. rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
  77. rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  78. }
  79. mutex_unlock(&rt2x00dev->csr_mutex);
  80. }
  81. static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  82. const unsigned int word, u8 *value)
  83. {
  84. u32 reg;
  85. mutex_lock(&rt2x00dev->csr_mutex);
  86. /*
  87. * Wait until the BBP becomes available, afterwards we
  88. * can safely write the read request into the register.
  89. * After the data has been written, we wait until hardware
  90. * returns the correct value, if at any time the register
  91. * doesn't become available in time, reg will be 0xffffffff
  92. * which means we return 0xff to the caller.
  93. */
  94. if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  95. reg = 0;
  96. rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  97. rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  98. rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
  99. rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  100. WAIT_FOR_BBP(rt2x00dev, &reg);
  101. }
  102. *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
  103. mutex_unlock(&rt2x00dev->csr_mutex);
  104. }
  105. static inline void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
  106. const unsigned int word, const u8 value)
  107. {
  108. rt2800usb_bbp_write(rt2x00dev, word, value);
  109. }
  110. static inline void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
  111. const unsigned int word, u8 *value)
  112. {
  113. rt2800usb_bbp_read(rt2x00dev, word, value);
  114. }
  115. static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
  116. const unsigned int word, const u8 value)
  117. {
  118. u32 reg;
  119. mutex_lock(&rt2x00dev->csr_mutex);
  120. /*
  121. * Wait until the RFCSR becomes available, afterwards we
  122. * can safely write the new data into the register.
  123. */
  124. if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  125. reg = 0;
  126. rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
  127. rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  128. rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
  129. rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  130. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  131. }
  132. mutex_unlock(&rt2x00dev->csr_mutex);
  133. }
  134. static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
  135. const unsigned int word, u8 *value)
  136. {
  137. u32 reg;
  138. mutex_lock(&rt2x00dev->csr_mutex);
  139. /*
  140. * Wait until the RFCSR becomes available, afterwards we
  141. * can safely write the read request into the register.
  142. * After the data has been written, we wait until hardware
  143. * returns the correct value, if at any time the register
  144. * doesn't become available in time, reg will be 0xffffffff
  145. * which means we return 0xff to the caller.
  146. */
  147. if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  148. reg = 0;
  149. rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  150. rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
  151. rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  152. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  153. WAIT_FOR_RFCSR(rt2x00dev, &reg);
  154. }
  155. *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
  156. mutex_unlock(&rt2x00dev->csr_mutex);
  157. }
  158. static inline void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
  159. const unsigned int word, const u8 value)
  160. {
  161. rt2800usb_rfcsr_write(rt2x00dev, word, value);
  162. }
  163. static inline void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
  164. const unsigned int word, u8 *value)
  165. {
  166. rt2800usb_rfcsr_read(rt2x00dev, word, value);
  167. }
  168. static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
  169. const unsigned int word, const u32 value)
  170. {
  171. u32 reg;
  172. mutex_lock(&rt2x00dev->csr_mutex);
  173. /*
  174. * Wait until the RF becomes available, afterwards we
  175. * can safely write the new data into the register.
  176. */
  177. if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  178. reg = 0;
  179. rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
  180. rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
  181. rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
  182. rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
  183. rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
  184. rt2x00_rf_write(rt2x00dev, word, value);
  185. }
  186. mutex_unlock(&rt2x00dev->csr_mutex);
  187. }
  188. static inline void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
  189. const unsigned int word, const u32 value)
  190. {
  191. rt2800usb_rf_write(rt2x00dev, word, value);
  192. }
  193. static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
  194. const u8 command, const u8 token,
  195. const u8 arg0, const u8 arg1)
  196. {
  197. u32 reg;
  198. mutex_lock(&rt2x00dev->csr_mutex);
  199. /*
  200. * Wait until the MCU becomes available, afterwards we
  201. * can safely write the new data into the register.
  202. */
  203. if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
  204. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  205. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  206. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  207. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  208. rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
  209. reg = 0;
  210. rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  211. rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
  212. }
  213. mutex_unlock(&rt2x00dev->csr_mutex);
  214. }
  215. static inline void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
  216. const u8 command, const u8 token,
  217. const u8 arg0, const u8 arg1)
  218. {
  219. rt2800usb_mcu_request(rt2x00dev, command, token, arg0, arg1);
  220. }
  221. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  222. static const struct rt2x00debug rt2800usb_rt2x00debug = {
  223. .owner = THIS_MODULE,
  224. .csr = {
  225. .read = rt2800_register_read,
  226. .write = rt2800_register_write,
  227. .flags = RT2X00DEBUGFS_OFFSET,
  228. .word_base = CSR_REG_BASE,
  229. .word_size = sizeof(u32),
  230. .word_count = CSR_REG_SIZE / sizeof(u32),
  231. },
  232. .eeprom = {
  233. .read = rt2x00_eeprom_read,
  234. .write = rt2x00_eeprom_write,
  235. .word_base = EEPROM_BASE,
  236. .word_size = sizeof(u16),
  237. .word_count = EEPROM_SIZE / sizeof(u16),
  238. },
  239. .bbp = {
  240. .read = rt2800_bbp_read,
  241. .write = rt2800_bbp_write,
  242. .word_base = BBP_BASE,
  243. .word_size = sizeof(u8),
  244. .word_count = BBP_SIZE / sizeof(u8),
  245. },
  246. .rf = {
  247. .read = rt2x00_rf_read,
  248. .write = rt2800_rf_write,
  249. .word_base = RF_BASE,
  250. .word_size = sizeof(u32),
  251. .word_count = RF_SIZE / sizeof(u32),
  252. },
  253. };
  254. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  255. static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  256. {
  257. u32 reg;
  258. rt2800_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
  259. return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
  260. }
  261. #ifdef CONFIG_RT2X00_LIB_LEDS
  262. static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
  263. enum led_brightness brightness)
  264. {
  265. struct rt2x00_led *led =
  266. container_of(led_cdev, struct rt2x00_led, led_dev);
  267. unsigned int enabled = brightness != LED_OFF;
  268. unsigned int bg_mode =
  269. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  270. unsigned int polarity =
  271. rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  272. EEPROM_FREQ_LED_POLARITY);
  273. unsigned int ledmode =
  274. rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  275. EEPROM_FREQ_LED_MODE);
  276. if (led->type == LED_TYPE_RADIO) {
  277. rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  278. enabled ? 0x20 : 0);
  279. } else if (led->type == LED_TYPE_ASSOC) {
  280. rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  281. enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
  282. } else if (led->type == LED_TYPE_QUALITY) {
  283. /*
  284. * The brightness is divided into 6 levels (0 - 5),
  285. * The specs tell us the following levels:
  286. * 0, 1 ,3, 7, 15, 31
  287. * to determine the level in a simple way we can simply
  288. * work with bitshifting:
  289. * (1 << level) - 1
  290. */
  291. rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  292. (1 << brightness / (LED_FULL / 6)) - 1,
  293. polarity);
  294. }
  295. }
  296. static int rt2800usb_blink_set(struct led_classdev *led_cdev,
  297. unsigned long *delay_on,
  298. unsigned long *delay_off)
  299. {
  300. struct rt2x00_led *led =
  301. container_of(led_cdev, struct rt2x00_led, led_dev);
  302. u32 reg;
  303. rt2800_register_read(led->rt2x00dev, LED_CFG, &reg);
  304. rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
  305. rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
  306. rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
  307. rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
  308. rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
  309. rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
  310. rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
  311. rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
  312. return 0;
  313. }
  314. static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
  315. struct rt2x00_led *led,
  316. enum led_type type)
  317. {
  318. led->rt2x00dev = rt2x00dev;
  319. led->type = type;
  320. led->led_dev.brightness_set = rt2800usb_brightness_set;
  321. led->led_dev.blink_set = rt2800usb_blink_set;
  322. led->flags = LED_INITIALIZED;
  323. }
  324. #endif /* CONFIG_RT2X00_LIB_LEDS */
  325. /*
  326. * Configuration handlers.
  327. */
  328. static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
  329. struct rt2x00lib_crypto *crypto,
  330. struct ieee80211_key_conf *key)
  331. {
  332. struct mac_wcid_entry wcid_entry;
  333. struct mac_iveiv_entry iveiv_entry;
  334. u32 offset;
  335. u32 reg;
  336. offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
  337. rt2800_register_read(rt2x00dev, offset, &reg);
  338. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
  339. !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
  340. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
  341. (crypto->cmd == SET_KEY) * crypto->cipher);
  342. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
  343. (crypto->cmd == SET_KEY) * crypto->bssidx);
  344. rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
  345. rt2800_register_write(rt2x00dev, offset, reg);
  346. offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
  347. memset(&iveiv_entry, 0, sizeof(iveiv_entry));
  348. if ((crypto->cipher == CIPHER_TKIP) ||
  349. (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
  350. (crypto->cipher == CIPHER_AES))
  351. iveiv_entry.iv[3] |= 0x20;
  352. iveiv_entry.iv[3] |= key->keyidx << 6;
  353. rt2800_register_multiwrite(rt2x00dev, offset,
  354. &iveiv_entry, sizeof(iveiv_entry));
  355. offset = MAC_WCID_ENTRY(key->hw_key_idx);
  356. memset(&wcid_entry, 0, sizeof(wcid_entry));
  357. if (crypto->cmd == SET_KEY)
  358. memcpy(&wcid_entry, crypto->address, ETH_ALEN);
  359. rt2800_register_multiwrite(rt2x00dev, offset,
  360. &wcid_entry, sizeof(wcid_entry));
  361. }
  362. static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  363. struct rt2x00lib_crypto *crypto,
  364. struct ieee80211_key_conf *key)
  365. {
  366. struct hw_key_entry key_entry;
  367. struct rt2x00_field32 field;
  368. u32 offset;
  369. u32 reg;
  370. if (crypto->cmd == SET_KEY) {
  371. key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
  372. memcpy(key_entry.key, crypto->key,
  373. sizeof(key_entry.key));
  374. memcpy(key_entry.tx_mic, crypto->tx_mic,
  375. sizeof(key_entry.tx_mic));
  376. memcpy(key_entry.rx_mic, crypto->rx_mic,
  377. sizeof(key_entry.rx_mic));
  378. offset = SHARED_KEY_ENTRY(key->hw_key_idx);
  379. rt2800_register_multiwrite(rt2x00dev, offset,
  380. &key_entry, sizeof(key_entry));
  381. }
  382. /*
  383. * The cipher types are stored over multiple registers
  384. * starting with SHARED_KEY_MODE_BASE each word will have
  385. * 32 bits and contains the cipher types for 2 bssidx each.
  386. * Using the correct defines correctly will cause overhead,
  387. * so just calculate the correct offset.
  388. */
  389. field.bit_offset = 4 * (key->hw_key_idx % 8);
  390. field.bit_mask = 0x7 << field.bit_offset;
  391. offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
  392. rt2800_register_read(rt2x00dev, offset, &reg);
  393. rt2x00_set_field32(&reg, field,
  394. (crypto->cmd == SET_KEY) * crypto->cipher);
  395. rt2800_register_write(rt2x00dev, offset, reg);
  396. /*
  397. * Update WCID information
  398. */
  399. rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  400. return 0;
  401. }
  402. static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  403. struct rt2x00lib_crypto *crypto,
  404. struct ieee80211_key_conf *key)
  405. {
  406. struct hw_key_entry key_entry;
  407. u32 offset;
  408. if (crypto->cmd == SET_KEY) {
  409. /*
  410. * 1 pairwise key is possible per AID, this means that the AID
  411. * equals our hw_key_idx. Make sure the WCID starts _after_ the
  412. * last possible shared key entry.
  413. */
  414. if (crypto->aid > (256 - 32))
  415. return -ENOSPC;
  416. key->hw_key_idx = 32 + crypto->aid;
  417. memcpy(key_entry.key, crypto->key,
  418. sizeof(key_entry.key));
  419. memcpy(key_entry.tx_mic, crypto->tx_mic,
  420. sizeof(key_entry.tx_mic));
  421. memcpy(key_entry.rx_mic, crypto->rx_mic,
  422. sizeof(key_entry.rx_mic));
  423. offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  424. rt2800_register_multiwrite(rt2x00dev, offset,
  425. &key_entry, sizeof(key_entry));
  426. }
  427. /*
  428. * Update WCID information
  429. */
  430. rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  431. return 0;
  432. }
  433. static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
  434. const unsigned int filter_flags)
  435. {
  436. u32 reg;
  437. /*
  438. * Start configuration steps.
  439. * Note that the version error will always be dropped
  440. * and broadcast frames will always be accepted since
  441. * there is no filter for it at this time.
  442. */
  443. rt2800_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
  444. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
  445. !(filter_flags & FIF_FCSFAIL));
  446. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
  447. !(filter_flags & FIF_PLCPFAIL));
  448. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
  449. !(filter_flags & FIF_PROMISC_IN_BSS));
  450. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
  451. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
  452. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
  453. !(filter_flags & FIF_ALLMULTI));
  454. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
  455. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
  456. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
  457. !(filter_flags & FIF_CONTROL));
  458. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
  459. !(filter_flags & FIF_CONTROL));
  460. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
  461. !(filter_flags & FIF_CONTROL));
  462. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
  463. !(filter_flags & FIF_CONTROL));
  464. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
  465. !(filter_flags & FIF_CONTROL));
  466. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
  467. !(filter_flags & FIF_PSPOLL));
  468. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
  469. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
  470. rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
  471. !(filter_flags & FIF_CONTROL));
  472. rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
  473. }
  474. static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
  475. struct rt2x00_intf *intf,
  476. struct rt2x00intf_conf *conf,
  477. const unsigned int flags)
  478. {
  479. unsigned int beacon_base;
  480. u32 reg;
  481. if (flags & CONFIG_UPDATE_TYPE) {
  482. /*
  483. * Clear current synchronisation setup.
  484. * For the Beacon base registers we only need to clear
  485. * the first byte since that byte contains the VALID and OWNER
  486. * bits which (when set to 0) will invalidate the entire beacon.
  487. */
  488. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  489. rt2800_register_write(rt2x00dev, beacon_base, 0);
  490. /*
  491. * Enable synchronisation.
  492. */
  493. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  494. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  495. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
  496. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  497. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  498. }
  499. if (flags & CONFIG_UPDATE_MAC) {
  500. reg = le32_to_cpu(conf->mac[1]);
  501. rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
  502. conf->mac[1] = cpu_to_le32(reg);
  503. rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
  504. conf->mac, sizeof(conf->mac));
  505. }
  506. if (flags & CONFIG_UPDATE_BSSID) {
  507. reg = le32_to_cpu(conf->bssid[1]);
  508. rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
  509. rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
  510. conf->bssid[1] = cpu_to_le32(reg);
  511. rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
  512. conf->bssid, sizeof(conf->bssid));
  513. }
  514. }
  515. static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
  516. struct rt2x00lib_erp *erp)
  517. {
  518. u32 reg;
  519. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  520. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 0x20);
  521. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  522. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  523. rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
  524. !!erp->short_preamble);
  525. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
  526. !!erp->short_preamble);
  527. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  528. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  529. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
  530. erp->cts_protection ? 2 : 0);
  531. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  532. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
  533. erp->basic_rates);
  534. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  535. rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
  536. rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
  537. rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
  538. rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
  539. rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
  540. rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
  541. rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
  542. rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
  543. rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
  544. rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
  545. rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
  546. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  547. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
  548. erp->beacon_int * 16);
  549. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  550. }
  551. static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
  552. struct antenna_setup *ant)
  553. {
  554. u8 r1;
  555. u8 r3;
  556. rt2800_bbp_read(rt2x00dev, 1, &r1);
  557. rt2800_bbp_read(rt2x00dev, 3, &r3);
  558. /*
  559. * Configure the TX antenna.
  560. */
  561. switch ((int)ant->tx) {
  562. case 1:
  563. rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
  564. break;
  565. case 2:
  566. rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
  567. break;
  568. case 3:
  569. /* Do nothing */
  570. break;
  571. }
  572. /*
  573. * Configure the RX antenna.
  574. */
  575. switch ((int)ant->rx) {
  576. case 1:
  577. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
  578. break;
  579. case 2:
  580. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
  581. break;
  582. case 3:
  583. rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
  584. break;
  585. }
  586. rt2800_bbp_write(rt2x00dev, 3, r3);
  587. rt2800_bbp_write(rt2x00dev, 1, r1);
  588. }
  589. static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  590. struct rt2x00lib_conf *libconf)
  591. {
  592. u16 eeprom;
  593. short lna_gain;
  594. if (libconf->rf.channel <= 14) {
  595. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  596. lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
  597. } else if (libconf->rf.channel <= 64) {
  598. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  599. lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
  600. } else if (libconf->rf.channel <= 128) {
  601. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
  602. lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
  603. } else {
  604. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
  605. lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
  606. }
  607. rt2x00dev->lna_gain = lna_gain;
  608. }
  609. static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
  610. struct ieee80211_conf *conf,
  611. struct rf_channel *rf,
  612. struct channel_info *info)
  613. {
  614. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  615. if (rt2x00dev->default_ant.tx == 1)
  616. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
  617. if (rt2x00dev->default_ant.rx == 1) {
  618. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
  619. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  620. } else if (rt2x00dev->default_ant.rx == 2)
  621. rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  622. if (rf->channel > 14) {
  623. /*
  624. * When TX power is below 0, we should increase it by 7 to
  625. * make it a positive value (Minumum value is -7).
  626. * However this means that values between 0 and 7 have
  627. * double meaning, and we should set a 7DBm boost flag.
  628. */
  629. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
  630. (info->tx_power1 >= 0));
  631. if (info->tx_power1 < 0)
  632. info->tx_power1 += 7;
  633. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
  634. TXPOWER_A_TO_DEV(info->tx_power1));
  635. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
  636. (info->tx_power2 >= 0));
  637. if (info->tx_power2 < 0)
  638. info->tx_power2 += 7;
  639. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
  640. TXPOWER_A_TO_DEV(info->tx_power2));
  641. } else {
  642. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
  643. TXPOWER_G_TO_DEV(info->tx_power1));
  644. rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
  645. TXPOWER_G_TO_DEV(info->tx_power2));
  646. }
  647. rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
  648. rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  649. rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  650. rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  651. rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  652. udelay(200);
  653. rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  654. rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  655. rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  656. rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  657. udelay(200);
  658. rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  659. rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  660. rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  661. rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  662. }
  663. static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
  664. struct ieee80211_conf *conf,
  665. struct rf_channel *rf,
  666. struct channel_info *info)
  667. {
  668. u8 rfcsr;
  669. rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
  670. rt2800_rfcsr_write(rt2x00dev, 2, rf->rf3);
  671. rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
  672. rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
  673. rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
  674. rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
  675. rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
  676. TXPOWER_G_TO_DEV(info->tx_power1));
  677. rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
  678. rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
  679. rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
  680. rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
  681. rt2800_rfcsr_write(rt2x00dev, 24,
  682. rt2x00dev->calibration[conf_is_ht40(conf)]);
  683. rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
  684. rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  685. rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
  686. }
  687. static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
  688. struct ieee80211_conf *conf,
  689. struct rf_channel *rf,
  690. struct channel_info *info)
  691. {
  692. u32 reg;
  693. unsigned int tx_pin;
  694. u8 bbp;
  695. if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  696. rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
  697. else
  698. rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
  699. /*
  700. * Change BBP settings
  701. */
  702. rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  703. rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  704. rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  705. rt2800_bbp_write(rt2x00dev, 86, 0);
  706. if (rf->channel <= 14) {
  707. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  708. rt2800_bbp_write(rt2x00dev, 82, 0x62);
  709. rt2800_bbp_write(rt2x00dev, 75, 0x46);
  710. } else {
  711. rt2800_bbp_write(rt2x00dev, 82, 0x84);
  712. rt2800_bbp_write(rt2x00dev, 75, 0x50);
  713. }
  714. } else {
  715. rt2800_bbp_write(rt2x00dev, 82, 0xf2);
  716. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
  717. rt2800_bbp_write(rt2x00dev, 75, 0x46);
  718. else
  719. rt2800_bbp_write(rt2x00dev, 75, 0x50);
  720. }
  721. rt2800_register_read(rt2x00dev, TX_BAND_CFG, &reg);
  722. rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
  723. rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
  724. rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
  725. rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
  726. tx_pin = 0;
  727. /* Turn on unused PA or LNA when not using 1T or 1R */
  728. if (rt2x00dev->default_ant.tx != 1) {
  729. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
  730. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
  731. }
  732. /* Turn on unused PA or LNA when not using 1T or 1R */
  733. if (rt2x00dev->default_ant.rx != 1) {
  734. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
  735. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
  736. }
  737. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
  738. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
  739. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
  740. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
  741. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
  742. rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
  743. rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  744. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  745. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
  746. rt2800_bbp_write(rt2x00dev, 4, bbp);
  747. rt2800_bbp_read(rt2x00dev, 3, &bbp);
  748. rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
  749. rt2800_bbp_write(rt2x00dev, 3, bbp);
  750. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  751. if (conf_is_ht40(conf)) {
  752. rt2800_bbp_write(rt2x00dev, 69, 0x1a);
  753. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  754. rt2800_bbp_write(rt2x00dev, 73, 0x16);
  755. } else {
  756. rt2800_bbp_write(rt2x00dev, 69, 0x16);
  757. rt2800_bbp_write(rt2x00dev, 70, 0x08);
  758. rt2800_bbp_write(rt2x00dev, 73, 0x11);
  759. }
  760. }
  761. msleep(1);
  762. }
  763. static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  764. const int txpower)
  765. {
  766. u32 reg;
  767. u32 value = TXPOWER_G_TO_DEV(txpower);
  768. u8 r1;
  769. rt2800_bbp_read(rt2x00dev, 1, &r1);
  770. rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
  771. rt2800_bbp_write(rt2x00dev, 1, r1);
  772. rt2800_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
  773. rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
  774. rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
  775. rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
  776. rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
  777. rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
  778. rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
  779. rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
  780. rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
  781. rt2800_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
  782. rt2800_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
  783. rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
  784. rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
  785. rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
  786. rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
  787. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
  788. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
  789. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
  790. rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
  791. rt2800_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
  792. rt2800_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
  793. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
  794. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
  795. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
  796. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
  797. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
  798. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
  799. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
  800. rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
  801. rt2800_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
  802. rt2800_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
  803. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
  804. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
  805. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
  806. rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
  807. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
  808. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
  809. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
  810. rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
  811. rt2800_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
  812. rt2800_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
  813. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
  814. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
  815. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
  816. rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
  817. rt2800_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
  818. }
  819. static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  820. struct rt2x00lib_conf *libconf)
  821. {
  822. u32 reg;
  823. rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
  824. rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
  825. libconf->conf->short_frame_max_tx_count);
  826. rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
  827. libconf->conf->long_frame_max_tx_count);
  828. rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
  829. rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
  830. rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
  831. rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
  832. rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
  833. }
  834. static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
  835. struct rt2x00lib_conf *libconf)
  836. {
  837. enum dev_state state =
  838. (libconf->conf->flags & IEEE80211_CONF_PS) ?
  839. STATE_SLEEP : STATE_AWAKE;
  840. u32 reg;
  841. if (state == STATE_SLEEP) {
  842. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
  843. rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  844. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
  845. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
  846. libconf->conf->listen_interval - 1);
  847. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
  848. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  849. rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  850. } else {
  851. rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  852. rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  853. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
  854. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
  855. rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
  856. rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  857. }
  858. }
  859. static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
  860. struct rt2x00lib_conf *libconf,
  861. const unsigned int flags)
  862. {
  863. /* Always recalculate LNA gain before changing configuration */
  864. rt2800usb_config_lna_gain(rt2x00dev, libconf);
  865. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  866. rt2800usb_config_channel(rt2x00dev, libconf->conf,
  867. &libconf->rf, &libconf->channel);
  868. if (flags & IEEE80211_CONF_CHANGE_POWER)
  869. rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  870. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  871. rt2800usb_config_retry_limit(rt2x00dev, libconf);
  872. if (flags & IEEE80211_CONF_CHANGE_PS)
  873. rt2800usb_config_ps(rt2x00dev, libconf);
  874. }
  875. /*
  876. * Link tuning
  877. */
  878. static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
  879. struct link_qual *qual)
  880. {
  881. u32 reg;
  882. /*
  883. * Update FCS error count from register.
  884. */
  885. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  886. qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
  887. }
  888. static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
  889. {
  890. if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  891. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
  892. return 0x1c + (2 * rt2x00dev->lna_gain);
  893. else
  894. return 0x2e + rt2x00dev->lna_gain;
  895. }
  896. if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  897. return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
  898. else
  899. return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
  900. }
  901. static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  902. struct link_qual *qual, u8 vgc_level)
  903. {
  904. if (qual->vgc_level != vgc_level) {
  905. rt2800_bbp_write(rt2x00dev, 66, vgc_level);
  906. qual->vgc_level = vgc_level;
  907. qual->vgc_level_reg = vgc_level;
  908. }
  909. }
  910. static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  911. struct link_qual *qual)
  912. {
  913. rt2800usb_set_vgc(rt2x00dev, qual,
  914. rt2800usb_get_default_vgc(rt2x00dev));
  915. }
  916. static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  917. struct link_qual *qual, const u32 count)
  918. {
  919. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
  920. return;
  921. /*
  922. * When RSSI is better then -80 increase VGC level with 0x10
  923. */
  924. rt2800usb_set_vgc(rt2x00dev, qual,
  925. rt2800usb_get_default_vgc(rt2x00dev) +
  926. ((qual->rssi > -80) * 0x10));
  927. }
  928. /*
  929. * Firmware functions
  930. */
  931. static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  932. {
  933. return FIRMWARE_RT2870;
  934. }
  935. static bool rt2800usb_check_crc(const u8 *data, const size_t len)
  936. {
  937. u16 fw_crc;
  938. u16 crc;
  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 ccitt algorithm.
  947. * This will return the same value as the legacy driver which
  948. * used bit ordering reversion on the both the firmware bytes
  949. * before input input as well as on the final output.
  950. * Obviously using crc ccitt directly is much more efficient.
  951. */
  952. crc = crc_ccitt(~0, data, len - 2);
  953. /*
  954. * There is a small difference between the crc-itu-t + bitrev and
  955. * the crc-ccitt crc calculation. In the latter method the 2 bytes
  956. * will be swapped, use swab16 to convert the crc to the correct
  957. * value.
  958. */
  959. crc = swab16(crc);
  960. return fw_crc == crc;
  961. }
  962. static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  963. const u8 *data, const size_t len)
  964. {
  965. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  966. size_t offset = 0;
  967. /*
  968. * Firmware files:
  969. * There are 2 variations of the rt2870 firmware.
  970. * a) size: 4kb
  971. * b) size: 8kb
  972. * Note that (b) contains 2 seperate firmware blobs of 4k
  973. * within the file. The first blob is the same firmware as (a),
  974. * but the second blob is for the additional chipsets.
  975. */
  976. if (len != 4096 && len != 8192)
  977. return FW_BAD_LENGTH;
  978. /*
  979. * Check if we need the upper 4kb firmware data or not.
  980. */
  981. if ((len == 4096) &&
  982. (chipset != 0x2860) &&
  983. (chipset != 0x2872) &&
  984. (chipset != 0x3070))
  985. return FW_BAD_VERSION;
  986. /*
  987. * 8kb firmware files must be checked as if it were
  988. * 2 seperate firmware files.
  989. */
  990. while (offset < len) {
  991. if (!rt2800usb_check_crc(data + offset, 4096))
  992. return FW_BAD_CRC;
  993. offset += 4096;
  994. }
  995. return FW_OK;
  996. }
  997. static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  998. const u8 *data, const size_t len)
  999. {
  1000. unsigned int i;
  1001. int status;
  1002. u32 reg;
  1003. u32 offset;
  1004. u32 length;
  1005. u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  1006. /*
  1007. * Check which section of the firmware we need.
  1008. */
  1009. if ((chipset == 0x2860) ||
  1010. (chipset == 0x2872) ||
  1011. (chipset == 0x3070)) {
  1012. offset = 0;
  1013. length = 4096;
  1014. } else {
  1015. offset = 4096;
  1016. length = 4096;
  1017. }
  1018. /*
  1019. * Wait for stable hardware.
  1020. */
  1021. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1022. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1023. if (reg && reg != ~0)
  1024. break;
  1025. msleep(1);
  1026. }
  1027. if (i == REGISTER_BUSY_COUNT) {
  1028. ERROR(rt2x00dev, "Unstable hardware.\n");
  1029. return -EBUSY;
  1030. }
  1031. /*
  1032. * Write firmware to device.
  1033. */
  1034. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1035. USB_VENDOR_REQUEST_OUT,
  1036. FIRMWARE_IMAGE_BASE,
  1037. data + offset, length,
  1038. REGISTER_TIMEOUT32(length));
  1039. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  1040. rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  1041. /*
  1042. * Send firmware request to device to load firmware,
  1043. * we need to specify a long timeout time.
  1044. */
  1045. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  1046. 0, USB_MODE_FIRMWARE,
  1047. REGISTER_TIMEOUT_FIRMWARE);
  1048. if (status < 0) {
  1049. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  1050. return status;
  1051. }
  1052. msleep(10);
  1053. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1054. /*
  1055. * Send signal to firmware during boot time.
  1056. */
  1057. rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  1058. if ((chipset == 0x3070) ||
  1059. (chipset == 0x3071) ||
  1060. (chipset == 0x3572)) {
  1061. udelay(200);
  1062. rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
  1063. udelay(10);
  1064. }
  1065. /*
  1066. * Wait for device to stabilize.
  1067. */
  1068. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1069. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1070. if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  1071. break;
  1072. msleep(1);
  1073. }
  1074. if (i == REGISTER_BUSY_COUNT) {
  1075. ERROR(rt2x00dev, "PBF system register not ready.\n");
  1076. return -EBUSY;
  1077. }
  1078. /*
  1079. * Initialize firmware.
  1080. */
  1081. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1082. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1083. msleep(1);
  1084. return 0;
  1085. }
  1086. /*
  1087. * Initialization functions.
  1088. */
  1089. static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
  1090. {
  1091. u32 reg;
  1092. unsigned int i;
  1093. /*
  1094. * Wait untill BBP and RF are ready.
  1095. */
  1096. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1097. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  1098. if (reg && reg != ~0)
  1099. break;
  1100. msleep(1);
  1101. }
  1102. if (i == REGISTER_BUSY_COUNT) {
  1103. ERROR(rt2x00dev, "Unstable hardware.\n");
  1104. return -EBUSY;
  1105. }
  1106. rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1107. rt2800_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
  1108. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1109. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  1110. rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  1111. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1112. rt2800_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
  1113. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  1114. USB_MODE_RESET, REGISTER_TIMEOUT);
  1115. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1116. rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  1117. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  1118. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  1119. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  1120. rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  1121. rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
  1122. rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  1123. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  1124. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  1125. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  1126. rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  1127. rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
  1128. rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  1129. rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  1130. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1131. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1132. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
  1133. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  1134. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  1135. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  1136. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1137. rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  1138. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1139. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1140. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  1141. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  1142. rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  1143. } else {
  1144. rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  1145. rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  1146. }
  1147. rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  1148. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  1149. rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  1150. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  1151. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  1152. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  1153. rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  1154. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  1155. rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  1156. rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
  1157. rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  1158. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  1159. rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  1160. rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  1161. rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  1162. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  1163. if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
  1164. rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
  1165. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  1166. else
  1167. rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  1168. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  1169. rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  1170. rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  1171. rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  1172. rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  1173. rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  1174. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  1175. rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  1176. rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  1177. rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  1178. rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  1179. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  1180. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
  1181. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  1182. rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
  1183. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1184. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1185. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1186. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1187. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1188. rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1189. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  1190. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  1191. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
  1192. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  1193. rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
  1194. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1195. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1196. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1197. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1198. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1199. rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1200. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  1201. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  1202. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  1203. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  1204. rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
  1205. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1206. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1207. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1208. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1209. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1210. rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1211. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  1212. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  1213. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  1214. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  1215. rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
  1216. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1217. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1218. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1219. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1220. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1221. rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1222. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  1223. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  1224. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  1225. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  1226. rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
  1227. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1228. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1229. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1230. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1231. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1232. rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1233. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  1234. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  1235. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  1236. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  1237. rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
  1238. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1239. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1240. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1241. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1242. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1243. rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1244. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  1245. rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  1246. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1247. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1248. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  1249. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1250. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  1251. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  1252. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  1253. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  1254. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  1255. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  1256. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1257. rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
  1258. rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
  1259. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  1260. rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  1261. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  1262. IEEE80211_MAX_RTS_THRESHOLD);
  1263. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  1264. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  1265. rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  1266. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  1267. /*
  1268. * ASIC will keep garbage value after boot, clear encryption keys.
  1269. */
  1270. for (i = 0; i < 4; i++)
  1271. rt2800_register_write(rt2x00dev,
  1272. SHARED_KEY_MODE_ENTRY(i), 0);
  1273. for (i = 0; i < 256; i++) {
  1274. u32 wcid[2] = { 0xffffffff, 0x00ffffff };
  1275. rt2800_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
  1276. wcid, sizeof(wcid));
  1277. rt2800_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
  1278. rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  1279. }
  1280. /*
  1281. * Clear all beacons
  1282. * For the Beacon base registers we only need to clear
  1283. * the first byte since that byte contains the VALID and OWNER
  1284. * bits which (when set to 0) will invalidate the entire beacon.
  1285. */
  1286. rt2800_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1287. rt2800_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1288. rt2800_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1289. rt2800_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1290. rt2800_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
  1291. rt2800_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
  1292. rt2800_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
  1293. rt2800_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
  1294. rt2800_register_read(rt2x00dev, USB_CYC_CFG, &reg);
  1295. rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
  1296. rt2800_register_write(rt2x00dev, USB_CYC_CFG, reg);
  1297. rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  1298. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  1299. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  1300. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  1301. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  1302. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  1303. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  1304. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  1305. rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  1306. rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  1307. rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  1308. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  1309. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  1310. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  1311. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  1312. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  1313. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  1314. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  1315. rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  1316. rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  1317. rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  1318. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  1319. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  1320. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
  1321. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  1322. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  1323. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  1324. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  1325. rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  1326. rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  1327. rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  1328. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  1329. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  1330. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  1331. rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  1332. rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  1333. /*
  1334. * We must clear the error counters.
  1335. * These registers are cleared on read,
  1336. * so we may pass a useless variable to store the value.
  1337. */
  1338. rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  1339. rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  1340. rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  1341. rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  1342. rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  1343. rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  1344. return 0;
  1345. }
  1346. static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  1347. {
  1348. unsigned int i;
  1349. u32 reg;
  1350. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1351. rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  1352. if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  1353. return 0;
  1354. udelay(REGISTER_BUSY_DELAY);
  1355. }
  1356. ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
  1357. return -EACCES;
  1358. }
  1359. static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1360. {
  1361. unsigned int i;
  1362. u8 value;
  1363. /*
  1364. * BBP was enabled after firmware was loaded,
  1365. * but we need to reactivate it now.
  1366. */
  1367. rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1368. rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1369. msleep(1);
  1370. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1371. rt2800_bbp_read(rt2x00dev, 0, &value);
  1372. if ((value != 0xff) && (value != 0x00))
  1373. return 0;
  1374. udelay(REGISTER_BUSY_DELAY);
  1375. }
  1376. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1377. return -EACCES;
  1378. }
  1379. static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1380. {
  1381. unsigned int i;
  1382. u16 eeprom;
  1383. u8 reg_id;
  1384. u8 value;
  1385. if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
  1386. rt2800usb_wait_bbp_ready(rt2x00dev)))
  1387. return -EACCES;
  1388. rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  1389. rt2800_bbp_write(rt2x00dev, 66, 0x38);
  1390. rt2800_bbp_write(rt2x00dev, 69, 0x12);
  1391. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  1392. rt2800_bbp_write(rt2x00dev, 73, 0x10);
  1393. rt2800_bbp_write(rt2x00dev, 81, 0x37);
  1394. rt2800_bbp_write(rt2x00dev, 82, 0x62);
  1395. rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  1396. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  1397. rt2800_bbp_write(rt2x00dev, 86, 0x00);
  1398. rt2800_bbp_write(rt2x00dev, 91, 0x04);
  1399. rt2800_bbp_write(rt2x00dev, 92, 0x00);
  1400. rt2800_bbp_write(rt2x00dev, 103, 0x00);
  1401. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  1402. if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  1403. rt2800_bbp_write(rt2x00dev, 69, 0x16);
  1404. rt2800_bbp_write(rt2x00dev, 73, 0x12);
  1405. }
  1406. if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
  1407. rt2800_bbp_write(rt2x00dev, 84, 0x19);
  1408. }
  1409. if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1410. rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  1411. rt2800_bbp_write(rt2x00dev, 84, 0x99);
  1412. rt2800_bbp_write(rt2x00dev, 105, 0x05);
  1413. }
  1414. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1415. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1416. if (eeprom != 0xffff && eeprom != 0x0000) {
  1417. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1418. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1419. rt2800_bbp_write(rt2x00dev, reg_id, value);
  1420. }
  1421. }
  1422. return 0;
  1423. }
  1424. static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
  1425. bool bw40, u8 rfcsr24, u8 filter_target)
  1426. {
  1427. unsigned int i;
  1428. u8 bbp;
  1429. u8 rfcsr;
  1430. u8 passband;
  1431. u8 stopband;
  1432. u8 overtuned = 0;
  1433. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1434. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  1435. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  1436. rt2800_bbp_write(rt2x00dev, 4, bbp);
  1437. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1438. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  1439. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  1440. /*
  1441. * Set power & frequency of passband test tone
  1442. */
  1443. rt2800_bbp_write(rt2x00dev, 24, 0);
  1444. for (i = 0; i < 100; i++) {
  1445. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  1446. msleep(1);
  1447. rt2800_bbp_read(rt2x00dev, 55, &passband);
  1448. if (passband)
  1449. break;
  1450. }
  1451. /*
  1452. * Set power & frequency of stopband test tone
  1453. */
  1454. rt2800_bbp_write(rt2x00dev, 24, 0x06);
  1455. for (i = 0; i < 100; i++) {
  1456. rt2800_bbp_write(rt2x00dev, 25, 0x90);
  1457. msleep(1);
  1458. rt2800_bbp_read(rt2x00dev, 55, &stopband);
  1459. if ((passband - stopband) <= filter_target) {
  1460. rfcsr24++;
  1461. overtuned += ((passband - stopband) == filter_target);
  1462. } else
  1463. break;
  1464. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1465. }
  1466. rfcsr24 -= !!overtuned;
  1467. rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1468. return rfcsr24;
  1469. }
  1470. static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  1471. {
  1472. u8 rfcsr;
  1473. u8 bbp;
  1474. if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  1475. return 0;
  1476. /*
  1477. * Init RF calibration.
  1478. */
  1479. rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  1480. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  1481. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  1482. msleep(1);
  1483. rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  1484. rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  1485. rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  1486. rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
  1487. rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
  1488. rt2800_rfcsr_write(rt2x00dev, 7, 0x70);
  1489. rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
  1490. rt2800_rfcsr_write(rt2x00dev, 10, 0x71);
  1491. rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  1492. rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
  1493. rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  1494. rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
  1495. rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
  1496. rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
  1497. rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
  1498. rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  1499. rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
  1500. rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
  1501. rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
  1502. rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  1503. rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  1504. rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
  1505. /*
  1506. * Set RX Filter calibration for 20MHz and 40MHz
  1507. */
  1508. rt2x00dev->calibration[0] =
  1509. rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
  1510. rt2x00dev->calibration[1] =
  1511. rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
  1512. /*
  1513. * Set back to initial state
  1514. */
  1515. rt2800_bbp_write(rt2x00dev, 24, 0);
  1516. rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1517. rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  1518. rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  1519. /*
  1520. * set BBP back to BW20
  1521. */
  1522. rt2800_bbp_read(rt2x00dev, 4, &bbp);
  1523. rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  1524. rt2800_bbp_write(rt2x00dev, 4, bbp);
  1525. return 0;
  1526. }
  1527. /*
  1528. * Device state switch handlers.
  1529. */
  1530. static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1531. enum dev_state state)
  1532. {
  1533. u32 reg;
  1534. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1535. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  1536. (state == STATE_RADIO_RX_ON) ||
  1537. (state == STATE_RADIO_RX_ON_LINK));
  1538. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1539. }
  1540. static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  1541. {
  1542. unsigned int i;
  1543. u32 reg;
  1544. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1545. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1546. if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  1547. !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  1548. return 0;
  1549. msleep(1);
  1550. }
  1551. ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
  1552. return -EACCES;
  1553. }
  1554. static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1555. {
  1556. u32 reg;
  1557. u16 word;
  1558. /*
  1559. * Initialize all registers.
  1560. */
  1561. if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
  1562. rt2800usb_init_registers(rt2x00dev) ||
  1563. rt2800usb_init_bbp(rt2x00dev) ||
  1564. rt2800usb_init_rfcsr(rt2x00dev)))
  1565. return -EIO;
  1566. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1567. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1568. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1569. udelay(50);
  1570. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1571. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  1572. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  1573. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  1574. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1575. rt2800_register_read(rt2x00dev, USB_DMA_CFG, &reg);
  1576. rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
  1577. /* Don't use bulk in aggregation when working with USB 1.1 */
  1578. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
  1579. (rt2x00dev->rx->usb_maxpacket == 512));
  1580. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
  1581. /*
  1582. * Total room for RX frames in kilobytes, PBF might still exceed
  1583. * this limit so reduce the number to prevent errors.
  1584. */
  1585. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
  1586. ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
  1587. rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
  1588. rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
  1589. rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
  1590. rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1591. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1592. rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  1593. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1594. /*
  1595. * Initialize LED control
  1596. */
  1597. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  1598. rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  1599. word & 0xff, (word >> 8) & 0xff);
  1600. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  1601. rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  1602. word & 0xff, (word >> 8) & 0xff);
  1603. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  1604. rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  1605. word & 0xff, (word >> 8) & 0xff);
  1606. return 0;
  1607. }
  1608. static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1609. {
  1610. u32 reg;
  1611. rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1612. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1613. rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1614. rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1615. rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  1616. rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  1617. rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
  1618. /* Wait for DMA, ignore error */
  1619. rt2800usb_wait_wpdma_ready(rt2x00dev);
  1620. rt2x00usb_disable_radio(rt2x00dev);
  1621. }
  1622. static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
  1623. enum dev_state state)
  1624. {
  1625. if (state == STATE_AWAKE)
  1626. rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  1627. else
  1628. rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  1629. return 0;
  1630. }
  1631. static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1632. enum dev_state state)
  1633. {
  1634. int retval = 0;
  1635. switch (state) {
  1636. case STATE_RADIO_ON:
  1637. /*
  1638. * Before the radio can be enabled, the device first has
  1639. * to be woken up. After that it needs a bit of time
  1640. * to be fully awake and then the radio can be enabled.
  1641. */
  1642. rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
  1643. msleep(1);
  1644. retval = rt2800usb_enable_radio(rt2x00dev);
  1645. break;
  1646. case STATE_RADIO_OFF:
  1647. /*
  1648. * After the radio has been disabled, the device should
  1649. * be put to sleep for powersaving.
  1650. */
  1651. rt2800usb_disable_radio(rt2x00dev);
  1652. rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
  1653. break;
  1654. case STATE_RADIO_RX_ON:
  1655. case STATE_RADIO_RX_ON_LINK:
  1656. case STATE_RADIO_RX_OFF:
  1657. case STATE_RADIO_RX_OFF_LINK:
  1658. rt2800usb_toggle_rx(rt2x00dev, state);
  1659. break;
  1660. case STATE_RADIO_IRQ_ON:
  1661. case STATE_RADIO_IRQ_OFF:
  1662. /* No support, but no error either */
  1663. break;
  1664. case STATE_DEEP_SLEEP:
  1665. case STATE_SLEEP:
  1666. case STATE_STANDBY:
  1667. case STATE_AWAKE:
  1668. retval = rt2800usb_set_state(rt2x00dev, state);
  1669. break;
  1670. default:
  1671. retval = -ENOTSUPP;
  1672. break;
  1673. }
  1674. if (unlikely(retval))
  1675. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1676. state, retval);
  1677. return retval;
  1678. }
  1679. /*
  1680. * TX descriptor initialization
  1681. */
  1682. static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1683. struct sk_buff *skb,
  1684. struct txentry_desc *txdesc)
  1685. {
  1686. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1687. __le32 *txi = skbdesc->desc;
  1688. __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
  1689. u32 word;
  1690. /*
  1691. * Initialize TX Info descriptor
  1692. */
  1693. rt2x00_desc_read(txwi, 0, &word);
  1694. rt2x00_set_field32(&word, TXWI_W0_FRAG,
  1695. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1696. rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
  1697. rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  1698. rt2x00_set_field32(&word, TXWI_W0_TS,
  1699. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1700. rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  1701. test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  1702. rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
  1703. rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
  1704. rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
  1705. rt2x00_set_field32(&word, TXWI_W0_BW,
  1706. test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  1707. rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  1708. test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  1709. rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
  1710. rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  1711. rt2x00_desc_write(txwi, 0, word);
  1712. rt2x00_desc_read(txwi, 1, &word);
  1713. rt2x00_set_field32(&word, TXWI_W1_ACK,
  1714. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1715. rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  1716. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1717. rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
  1718. rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  1719. test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  1720. txdesc->key_idx : 0xff);
  1721. rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
  1722. skb->len - txdesc->l2pad);
  1723. rt2x00_set_field32(&word, TXWI_W1_PACKETID,
  1724. skbdesc->entry->queue->qid + 1);
  1725. rt2x00_desc_write(txwi, 1, word);
  1726. /*
  1727. * Always write 0 to IV/EIV fields, hardware will insert the IV
  1728. * from the IVEIV register when TXINFO_W0_WIV is set to 0.
  1729. * When TXINFO_W0_WIV is set to 1 it will use the IV data
  1730. * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  1731. * crypto entry in the registers should be used to encrypt the frame.
  1732. */
  1733. _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
  1734. _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
  1735. /*
  1736. * Initialize TX descriptor
  1737. */
  1738. rt2x00_desc_read(txi, 0, &word);
  1739. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
  1740. skb->len + TXWI_DESC_SIZE);
  1741. rt2x00_set_field32(&word, TXINFO_W0_WIV,
  1742. !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  1743. rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
  1744. rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
  1745. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
  1746. rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
  1747. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1748. rt2x00_desc_write(txi, 0, word);
  1749. }
  1750. /*
  1751. * TX data initialization
  1752. */
  1753. static void rt2800usb_write_beacon(struct queue_entry *entry)
  1754. {
  1755. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1756. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1757. unsigned int beacon_base;
  1758. u32 reg;
  1759. /*
  1760. * Add the descriptor in front of the skb.
  1761. */
  1762. skb_push(entry->skb, entry->queue->desc_size);
  1763. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  1764. skbdesc->desc = entry->skb->data;
  1765. /*
  1766. * Disable beaconing while we are reloading the beacon data,
  1767. * otherwise we might be sending out invalid data.
  1768. */
  1769. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1770. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1771. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1772. /*
  1773. * Write entire beacon with descriptor to register.
  1774. */
  1775. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1776. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1777. USB_VENDOR_REQUEST_OUT, beacon_base,
  1778. entry->skb->data, entry->skb->len,
  1779. REGISTER_TIMEOUT32(entry->skb->len));
  1780. /*
  1781. * Clean up the beacon skb.
  1782. */
  1783. dev_kfree_skb(entry->skb);
  1784. entry->skb = NULL;
  1785. }
  1786. static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
  1787. {
  1788. int length;
  1789. /*
  1790. * The length _must_ include 4 bytes padding,
  1791. * it should always be multiple of 4,
  1792. * but it must _not_ be a multiple of the USB packet size.
  1793. */
  1794. length = roundup(entry->skb->len + 4, 4);
  1795. length += (4 * !(length % entry->queue->usb_maxpacket));
  1796. return length;
  1797. }
  1798. static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1799. const enum data_queue_qid queue)
  1800. {
  1801. u32 reg;
  1802. if (queue != QID_BEACON) {
  1803. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  1804. return;
  1805. }
  1806. rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1807. if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  1808. rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  1809. rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  1810. rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  1811. rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1812. }
  1813. }
  1814. /*
  1815. * RX control handlers
  1816. */
  1817. static void rt2800usb_fill_rxdone(struct queue_entry *entry,
  1818. struct rxdone_entry_desc *rxdesc)
  1819. {
  1820. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1821. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1822. __le32 *rxd = (__le32 *)entry->skb->data;
  1823. __le32 *rxwi;
  1824. u32 rxd0;
  1825. u32 rxwi0;
  1826. u32 rxwi1;
  1827. u32 rxwi2;
  1828. u32 rxwi3;
  1829. /*
  1830. * Copy descriptor to the skbdesc->desc buffer, making it safe from
  1831. * moving of frame data in rt2x00usb.
  1832. */
  1833. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1834. rxd = (__le32 *)skbdesc->desc;
  1835. rxwi = &rxd[RXINFO_DESC_SIZE / sizeof(__le32)];
  1836. /*
  1837. * It is now safe to read the descriptor on all architectures.
  1838. */
  1839. rt2x00_desc_read(rxd, 0, &rxd0);
  1840. rt2x00_desc_read(rxwi, 0, &rxwi0);
  1841. rt2x00_desc_read(rxwi, 1, &rxwi1);
  1842. rt2x00_desc_read(rxwi, 2, &rxwi2);
  1843. rt2x00_desc_read(rxwi, 3, &rxwi3);
  1844. if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
  1845. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1846. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1847. rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
  1848. rxdesc->cipher_status =
  1849. rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
  1850. }
  1851. if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
  1852. /*
  1853. * Hardware has stripped IV/EIV data from 802.11 frame during
  1854. * decryption. Unfortunately the descriptor doesn't contain
  1855. * any fields with the EIV/IV data either, so they can't
  1856. * be restored by rt2x00lib.
  1857. */
  1858. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1859. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1860. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1861. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1862. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1863. }
  1864. if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
  1865. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1866. if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD)) {
  1867. rxdesc->dev_flags |= RXDONE_L2PAD;
  1868. skbdesc->flags |= SKBDESC_L2_PADDED;
  1869. }
  1870. if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
  1871. rxdesc->flags |= RX_FLAG_SHORT_GI;
  1872. if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
  1873. rxdesc->flags |= RX_FLAG_40MHZ;
  1874. /*
  1875. * Detect RX rate, always use MCS as signal type.
  1876. */
  1877. rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  1878. rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
  1879. rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
  1880. /*
  1881. * Mask of 0x8 bit to remove the short preamble flag.
  1882. */
  1883. if (rxdesc->rate_mode == RATE_MODE_CCK)
  1884. rxdesc->signal &= ~0x8;
  1885. rxdesc->rssi =
  1886. (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
  1887. rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
  1888. rxdesc->noise =
  1889. (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
  1890. rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
  1891. rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  1892. /*
  1893. * Remove RXWI descriptor from start of buffer.
  1894. */
  1895. skb_pull(entry->skb, skbdesc->desc_len);
  1896. skb_trim(entry->skb, rxdesc->size);
  1897. }
  1898. /*
  1899. * Device probe functions.
  1900. */
  1901. static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1902. {
  1903. u16 word;
  1904. u8 *mac;
  1905. u8 default_lna_gain;
  1906. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1907. /*
  1908. * Start validation of the data that has been read.
  1909. */
  1910. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1911. if (!is_valid_ether_addr(mac)) {
  1912. random_ether_addr(mac);
  1913. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1914. }
  1915. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1916. if (word == 0xffff) {
  1917. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1918. rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
  1919. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
  1920. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1921. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1922. } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
  1923. /*
  1924. * There is a max of 2 RX streams for RT2870 series
  1925. */
  1926. if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
  1927. rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  1928. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1929. }
  1930. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1931. if (word == 0xffff) {
  1932. rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
  1933. rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
  1934. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1935. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1936. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1937. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
  1938. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
  1939. rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
  1940. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
  1941. rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
  1942. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1943. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1944. }
  1945. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1946. if ((word & 0x00ff) == 0x00ff) {
  1947. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1948. rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  1949. LED_MODE_TXRX_ACTIVITY);
  1950. rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  1951. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1952. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
  1953. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
  1954. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
  1955. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1956. }
  1957. /*
  1958. * During the LNA validation we are going to use
  1959. * lna0 as correct value. Note that EEPROM_LNA
  1960. * is never validated.
  1961. */
  1962. rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  1963. default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  1964. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  1965. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  1966. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  1967. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  1968. rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  1969. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  1970. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  1971. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  1972. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  1973. if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  1974. rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  1975. rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  1976. default_lna_gain);
  1977. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  1978. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  1979. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  1980. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  1981. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  1982. rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  1983. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  1984. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  1985. if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  1986. rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  1987. if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  1988. rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  1989. rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  1990. default_lna_gain);
  1991. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  1992. return 0;
  1993. }
  1994. static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1995. {
  1996. u32 reg;
  1997. u16 value;
  1998. u16 eeprom;
  1999. /*
  2000. * Read EEPROM word for configuration.
  2001. */
  2002. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2003. /*
  2004. * Identify RF chipset.
  2005. */
  2006. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  2007. rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  2008. rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
  2009. /*
  2010. * The check for rt2860 is not a typo, some rt2870 hardware
  2011. * identifies itself as rt2860 in the CSR register.
  2012. */
  2013. if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
  2014. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
  2015. !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
  2016. !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
  2017. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  2018. return -ENODEV;
  2019. }
  2020. if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
  2021. !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
  2022. !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
  2023. !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
  2024. !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
  2025. !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2026. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  2027. return -ENODEV;
  2028. }
  2029. /*
  2030. * Identify default antenna configuration.
  2031. */
  2032. rt2x00dev->default_ant.tx =
  2033. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
  2034. rt2x00dev->default_ant.rx =
  2035. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
  2036. /*
  2037. * Read frequency offset and RF programming sequence.
  2038. */
  2039. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  2040. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  2041. /*
  2042. * Read external LNA informations.
  2043. */
  2044. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  2045. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  2046. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  2047. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  2048. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  2049. /*
  2050. * Detect if this device has an hardware controlled radio.
  2051. */
  2052. if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
  2053. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  2054. /*
  2055. * Store led settings, for correct led behaviour.
  2056. */
  2057. #ifdef CONFIG_RT2X00_LIB_LEDS
  2058. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  2059. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  2060. rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  2061. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
  2062. &rt2x00dev->led_mcu_reg);
  2063. #endif /* CONFIG_RT2X00_LIB_LEDS */
  2064. return 0;
  2065. }
  2066. /*
  2067. * RF value list for rt2870
  2068. * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  2069. */
  2070. static const struct rf_channel rf_vals[] = {
  2071. { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  2072. { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  2073. { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  2074. { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  2075. { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  2076. { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  2077. { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  2078. { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  2079. { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  2080. { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  2081. { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  2082. { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  2083. { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  2084. { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  2085. /* 802.11 UNI / HyperLan 2 */
  2086. { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  2087. { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  2088. { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  2089. { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  2090. { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  2091. { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  2092. { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  2093. { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  2094. { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  2095. { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  2096. { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  2097. { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  2098. /* 802.11 HyperLan 2 */
  2099. { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  2100. { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  2101. { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
  2102. { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
  2103. { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  2104. { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  2105. { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  2106. { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  2107. { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  2108. { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  2109. { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  2110. { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  2111. { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  2112. { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  2113. { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  2114. { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  2115. /* 802.11 UNII */
  2116. { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  2117. { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  2118. { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  2119. { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  2120. { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  2121. { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  2122. { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  2123. { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
  2124. { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
  2125. { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
  2126. { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
  2127. /* 802.11 Japan */
  2128. { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  2129. { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  2130. { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  2131. { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  2132. { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  2133. { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  2134. { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  2135. };
  2136. /*
  2137. * RF value list for rt3070
  2138. * Supports: 2.4 GHz
  2139. */
  2140. static const struct rf_channel rf_vals_3070[] = {
  2141. {1, 241, 2, 2 },
  2142. {2, 241, 2, 7 },
  2143. {3, 242, 2, 2 },
  2144. {4, 242, 2, 7 },
  2145. {5, 243, 2, 2 },
  2146. {6, 243, 2, 7 },
  2147. {7, 244, 2, 2 },
  2148. {8, 244, 2, 7 },
  2149. {9, 245, 2, 2 },
  2150. {10, 245, 2, 7 },
  2151. {11, 246, 2, 2 },
  2152. {12, 246, 2, 7 },
  2153. {13, 247, 2, 2 },
  2154. {14, 248, 2, 4 },
  2155. };
  2156. static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  2157. {
  2158. struct hw_mode_spec *spec = &rt2x00dev->spec;
  2159. struct channel_info *info;
  2160. char *tx_power1;
  2161. char *tx_power2;
  2162. unsigned int i;
  2163. u16 eeprom;
  2164. /*
  2165. * Initialize all hw fields.
  2166. */
  2167. rt2x00dev->hw->flags =
  2168. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  2169. IEEE80211_HW_SIGNAL_DBM |
  2170. IEEE80211_HW_SUPPORTS_PS |
  2171. IEEE80211_HW_PS_NULLFUNC_STACK;
  2172. rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
  2173. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  2174. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  2175. rt2x00_eeprom_addr(rt2x00dev,
  2176. EEPROM_MAC_ADDR_0));
  2177. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2178. /*
  2179. * Initialize HT information.
  2180. */
  2181. spec->ht.ht_supported = true;
  2182. spec->ht.cap =
  2183. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  2184. IEEE80211_HT_CAP_GRN_FLD |
  2185. IEEE80211_HT_CAP_SGI_20 |
  2186. IEEE80211_HT_CAP_SGI_40 |
  2187. IEEE80211_HT_CAP_TX_STBC |
  2188. IEEE80211_HT_CAP_RX_STBC |
  2189. IEEE80211_HT_CAP_PSMP_SUPPORT;
  2190. spec->ht.ampdu_factor = 3;
  2191. spec->ht.ampdu_density = 4;
  2192. spec->ht.mcs.tx_params =
  2193. IEEE80211_HT_MCS_TX_DEFINED |
  2194. IEEE80211_HT_MCS_TX_RX_DIFF |
  2195. ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
  2196. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  2197. switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  2198. case 3:
  2199. spec->ht.mcs.rx_mask[2] = 0xff;
  2200. case 2:
  2201. spec->ht.mcs.rx_mask[1] = 0xff;
  2202. case 1:
  2203. spec->ht.mcs.rx_mask[0] = 0xff;
  2204. spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  2205. break;
  2206. }
  2207. /*
  2208. * Initialize hw_mode information.
  2209. */
  2210. spec->supported_bands = SUPPORT_BAND_2GHZ;
  2211. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  2212. if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
  2213. rt2x00_rf(&rt2x00dev->chip, RF2720)) {
  2214. spec->num_channels = 14;
  2215. spec->channels = rf_vals;
  2216. } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
  2217. rt2x00_rf(&rt2x00dev->chip, RF2750)) {
  2218. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  2219. spec->num_channels = ARRAY_SIZE(rf_vals);
  2220. spec->channels = rf_vals;
  2221. } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
  2222. rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2223. spec->num_channels = ARRAY_SIZE(rf_vals_3070);
  2224. spec->channels = rf_vals_3070;
  2225. }
  2226. /*
  2227. * Create channel information array
  2228. */
  2229. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  2230. if (!info)
  2231. return -ENOMEM;
  2232. spec->channels_info = info;
  2233. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  2234. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  2235. for (i = 0; i < 14; i++) {
  2236. info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
  2237. info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
  2238. }
  2239. if (spec->num_channels > 14) {
  2240. tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  2241. tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  2242. for (i = 14; i < spec->num_channels; i++) {
  2243. info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
  2244. info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
  2245. }
  2246. }
  2247. return 0;
  2248. }
  2249. static const struct rt2800_ops rt2800usb_rt2800_ops = {
  2250. .register_read = rt2x00usb_register_read,
  2251. .register_write = rt2x00usb_register_write,
  2252. .register_write_lock = rt2x00usb_register_write_lock,
  2253. .register_multiread = rt2x00usb_register_multiread,
  2254. .register_multiwrite = rt2x00usb_register_multiwrite,
  2255. .regbusy_read = rt2x00usb_regbusy_read,
  2256. };
  2257. static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  2258. {
  2259. int retval;
  2260. rt2x00dev->priv = (void *)&rt2800usb_rt2800_ops;
  2261. /*
  2262. * Allocate eeprom data.
  2263. */
  2264. retval = rt2800usb_validate_eeprom(rt2x00dev);
  2265. if (retval)
  2266. return retval;
  2267. retval = rt2800usb_init_eeprom(rt2x00dev);
  2268. if (retval)
  2269. return retval;
  2270. /*
  2271. * Initialize hw specifications.
  2272. */
  2273. retval = rt2800usb_probe_hw_mode(rt2x00dev);
  2274. if (retval)
  2275. return retval;
  2276. /*
  2277. * This device has multiple filters for control frames
  2278. * and has a separate filter for PS Poll frames.
  2279. */
  2280. __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
  2281. __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
  2282. /*
  2283. * This device requires firmware.
  2284. */
  2285. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2286. __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
  2287. if (!modparam_nohwcrypt)
  2288. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  2289. /*
  2290. * Set the rssi offset.
  2291. */
  2292. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2293. return 0;
  2294. }
  2295. /*
  2296. * IEEE80211 stack callback functions.
  2297. */
  2298. static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
  2299. u32 *iv32, u16 *iv16)
  2300. {
  2301. struct rt2x00_dev *rt2x00dev = hw->priv;
  2302. struct mac_iveiv_entry iveiv_entry;
  2303. u32 offset;
  2304. offset = MAC_IVEIV_ENTRY(hw_key_idx);
  2305. rt2800_register_multiread(rt2x00dev, offset,
  2306. &iveiv_entry, sizeof(iveiv_entry));
  2307. memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
  2308. memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
  2309. }
  2310. static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2311. {
  2312. struct rt2x00_dev *rt2x00dev = hw->priv;
  2313. u32 reg;
  2314. bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  2315. rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  2316. rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  2317. rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  2318. rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  2319. rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  2320. rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  2321. rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  2322. rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  2323. rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  2324. rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  2325. rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  2326. rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  2327. rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  2328. rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  2329. rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  2330. rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  2331. rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  2332. rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  2333. rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  2334. rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  2335. rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  2336. return 0;
  2337. }
  2338. static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  2339. const struct ieee80211_tx_queue_params *params)
  2340. {
  2341. struct rt2x00_dev *rt2x00dev = hw->priv;
  2342. struct data_queue *queue;
  2343. struct rt2x00_field32 field;
  2344. int retval;
  2345. u32 reg;
  2346. u32 offset;
  2347. /*
  2348. * First pass the configuration through rt2x00lib, that will
  2349. * update the queue settings and validate the input. After that
  2350. * we are free to update the registers based on the value
  2351. * in the queue parameter.
  2352. */
  2353. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  2354. if (retval)
  2355. return retval;
  2356. /*
  2357. * We only need to perform additional register initialization
  2358. * for WMM queues/
  2359. */
  2360. if (queue_idx >= 4)
  2361. return 0;
  2362. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  2363. /* Update WMM TXOP register */
  2364. offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  2365. field.bit_offset = (queue_idx & 1) * 16;
  2366. field.bit_mask = 0xffff << field.bit_offset;
  2367. rt2800_register_read(rt2x00dev, offset, &reg);
  2368. rt2x00_set_field32(&reg, field, queue->txop);
  2369. rt2800_register_write(rt2x00dev, offset, reg);
  2370. /* Update WMM registers */
  2371. field.bit_offset = queue_idx * 4;
  2372. field.bit_mask = 0xf << field.bit_offset;
  2373. rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  2374. rt2x00_set_field32(&reg, field, queue->aifs);
  2375. rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  2376. rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  2377. rt2x00_set_field32(&reg, field, queue->cw_min);
  2378. rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  2379. rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  2380. rt2x00_set_field32(&reg, field, queue->cw_max);
  2381. rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  2382. /* Update EDCA registers */
  2383. offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  2384. rt2800_register_read(rt2x00dev, offset, &reg);
  2385. rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  2386. rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  2387. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  2388. rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  2389. rt2800_register_write(rt2x00dev, offset, reg);
  2390. return 0;
  2391. }
  2392. static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
  2393. {
  2394. struct rt2x00_dev *rt2x00dev = hw->priv;
  2395. u64 tsf;
  2396. u32 reg;
  2397. rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  2398. tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  2399. rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  2400. tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  2401. return tsf;
  2402. }
  2403. static const struct ieee80211_ops rt2800usb_mac80211_ops = {
  2404. .tx = rt2x00mac_tx,
  2405. .start = rt2x00mac_start,
  2406. .stop = rt2x00mac_stop,
  2407. .add_interface = rt2x00mac_add_interface,
  2408. .remove_interface = rt2x00mac_remove_interface,
  2409. .config = rt2x00mac_config,
  2410. .configure_filter = rt2x00mac_configure_filter,
  2411. .set_tim = rt2x00mac_set_tim,
  2412. .set_key = rt2x00mac_set_key,
  2413. .get_stats = rt2x00mac_get_stats,
  2414. .get_tkip_seq = rt2800usb_get_tkip_seq,
  2415. .set_rts_threshold = rt2800usb_set_rts_threshold,
  2416. .bss_info_changed = rt2x00mac_bss_info_changed,
  2417. .conf_tx = rt2800usb_conf_tx,
  2418. .get_tx_stats = rt2x00mac_get_tx_stats,
  2419. .get_tsf = rt2800usb_get_tsf,
  2420. .rfkill_poll = rt2x00mac_rfkill_poll,
  2421. };
  2422. static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
  2423. .probe_hw = rt2800usb_probe_hw,
  2424. .get_firmware_name = rt2800usb_get_firmware_name,
  2425. .check_firmware = rt2800usb_check_firmware,
  2426. .load_firmware = rt2800usb_load_firmware,
  2427. .initialize = rt2x00usb_initialize,
  2428. .uninitialize = rt2x00usb_uninitialize,
  2429. .clear_entry = rt2x00usb_clear_entry,
  2430. .set_device_state = rt2800usb_set_device_state,
  2431. .rfkill_poll = rt2800usb_rfkill_poll,
  2432. .link_stats = rt2800usb_link_stats,
  2433. .reset_tuner = rt2800usb_reset_tuner,
  2434. .link_tuner = rt2800usb_link_tuner,
  2435. .write_tx_desc = rt2800usb_write_tx_desc,
  2436. .write_tx_data = rt2x00usb_write_tx_data,
  2437. .write_beacon = rt2800usb_write_beacon,
  2438. .get_tx_data_len = rt2800usb_get_tx_data_len,
  2439. .kick_tx_queue = rt2800usb_kick_tx_queue,
  2440. .kill_tx_queue = rt2x00usb_kill_tx_queue,
  2441. .fill_rxdone = rt2800usb_fill_rxdone,
  2442. .config_shared_key = rt2800usb_config_shared_key,
  2443. .config_pairwise_key = rt2800usb_config_pairwise_key,
  2444. .config_filter = rt2800usb_config_filter,
  2445. .config_intf = rt2800usb_config_intf,
  2446. .config_erp = rt2800usb_config_erp,
  2447. .config_ant = rt2800usb_config_ant,
  2448. .config = rt2800usb_config,
  2449. };
  2450. static const struct data_queue_desc rt2800usb_queue_rx = {
  2451. .entry_num = RX_ENTRIES,
  2452. .data_size = AGGREGATION_SIZE,
  2453. .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE,
  2454. .priv_size = sizeof(struct queue_entry_priv_usb),
  2455. };
  2456. static const struct data_queue_desc rt2800usb_queue_tx = {
  2457. .entry_num = TX_ENTRIES,
  2458. .data_size = AGGREGATION_SIZE,
  2459. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2460. .priv_size = sizeof(struct queue_entry_priv_usb),
  2461. };
  2462. static const struct data_queue_desc rt2800usb_queue_bcn = {
  2463. .entry_num = 8 * BEACON_ENTRIES,
  2464. .data_size = MGMT_FRAME_SIZE,
  2465. .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2466. .priv_size = sizeof(struct queue_entry_priv_usb),
  2467. };
  2468. static const struct rt2x00_ops rt2800usb_ops = {
  2469. .name = KBUILD_MODNAME,
  2470. .max_sta_intf = 1,
  2471. .max_ap_intf = 8,
  2472. .eeprom_size = EEPROM_SIZE,
  2473. .rf_size = RF_SIZE,
  2474. .tx_queues = NUM_TX_QUEUES,
  2475. .rx = &rt2800usb_queue_rx,
  2476. .tx = &rt2800usb_queue_tx,
  2477. .bcn = &rt2800usb_queue_bcn,
  2478. .lib = &rt2800usb_rt2x00_ops,
  2479. .hw = &rt2800usb_mac80211_ops,
  2480. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2481. .debugfs = &rt2800usb_rt2x00debug,
  2482. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2483. };
  2484. /*
  2485. * rt2800usb module information.
  2486. */
  2487. static struct usb_device_id rt2800usb_device_table[] = {
  2488. /* Abocom */
  2489. { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2490. { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2491. { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2492. { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2493. { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2494. { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2495. /* AirTies */
  2496. { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
  2497. /* Amigo */
  2498. { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2499. { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
  2500. /* Amit */
  2501. { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2502. /* ASUS */
  2503. { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
  2504. { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
  2505. { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
  2506. { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
  2507. { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
  2508. /* AzureWave */
  2509. { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
  2510. { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
  2511. { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
  2512. { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
  2513. /* Belkin */
  2514. { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
  2515. { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2516. { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2517. { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2518. /* Buffalo */
  2519. { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
  2520. { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2521. /* Conceptronic */
  2522. { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2523. { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
  2524. { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
  2525. { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2526. { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2527. { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
  2528. { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
  2529. { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2530. { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
  2531. { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
  2532. /* Corega */
  2533. { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2534. { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2535. { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2536. { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2537. { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
  2538. /* D-Link */
  2539. { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2540. { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2541. { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2542. { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2543. { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2544. { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2545. { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2546. { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
  2547. /* Edimax */
  2548. { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
  2549. { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
  2550. { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
  2551. /* Encore */
  2552. { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
  2553. /* EnGenius */
  2554. { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
  2555. { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
  2556. { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
  2557. { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
  2558. { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
  2559. { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
  2560. /* Gemtek */
  2561. { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
  2562. /* Gigabyte */
  2563. { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2564. { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2565. { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2566. /* Hawking */
  2567. { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
  2568. { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
  2569. { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
  2570. { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2571. /* I-O DATA */
  2572. { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
  2573. /* LevelOne */
  2574. { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
  2575. { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
  2576. /* Linksys */
  2577. { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2578. { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2579. { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
  2580. /* Logitec */
  2581. { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
  2582. { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
  2583. { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
  2584. /* Motorola */
  2585. { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2586. { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
  2587. /* Ovislink */
  2588. { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2589. /* Pegatron */
  2590. { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
  2591. { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2592. { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2593. /* Philips */
  2594. { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2595. /* Planex */
  2596. { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2597. { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
  2598. { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2599. /* Qcom */
  2600. { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
  2601. /* Quanta */
  2602. { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
  2603. /* Ralink */
  2604. { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
  2605. { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
  2606. { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2607. { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2608. { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2609. { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2610. { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2611. { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2612. { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
  2613. /* Samsung */
  2614. { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
  2615. /* Siemens */
  2616. { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
  2617. /* Sitecom */
  2618. { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
  2619. { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2620. { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2621. { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2622. { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
  2623. { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2624. { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2625. { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2626. { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2627. { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2628. { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
  2629. { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
  2630. /* SMC */
  2631. { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2632. { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
  2633. { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2634. { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2635. { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2636. { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
  2637. { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
  2638. { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2639. { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
  2640. /* Sparklan */
  2641. { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
  2642. /* Sweex */
  2643. { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
  2644. { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
  2645. { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
  2646. /* U-Media*/
  2647. { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2648. /* ZCOM */
  2649. { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
  2650. { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
  2651. /* Zinwell */
  2652. { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
  2653. { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
  2654. { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
  2655. { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
  2656. /* Zyxel */
  2657. { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
  2658. { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2659. { 0, }
  2660. };
  2661. MODULE_AUTHOR(DRV_PROJECT);
  2662. MODULE_VERSION(DRV_VERSION);
  2663. MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
  2664. MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
  2665. MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
  2666. MODULE_FIRMWARE(FIRMWARE_RT2870);
  2667. MODULE_LICENSE("GPL");
  2668. static struct usb_driver rt2800usb_driver = {
  2669. .name = KBUILD_MODNAME,
  2670. .id_table = rt2800usb_device_table,
  2671. .probe = rt2x00usb_probe,
  2672. .disconnect = rt2x00usb_disconnect,
  2673. .suspend = rt2x00usb_suspend,
  2674. .resume = rt2x00usb_resume,
  2675. };
  2676. static int __init rt2800usb_init(void)
  2677. {
  2678. return usb_register(&rt2800usb_driver);
  2679. }
  2680. static void __exit rt2800usb_exit(void)
  2681. {
  2682. usb_deregister(&rt2800usb_driver);
  2683. }
  2684. module_init(rt2800usb_init);
  2685. module_exit(rt2800usb_exit);