303-rt2x00-Implement-support-for-rt2800usb.patch 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026
  1. From 101b65d221593c1bdeacf0c6085d885ea5447c4c Mon Sep 17 00:00:00 2001
  2. From: Ivo van Doorn <[email protected]>
  3. Date: Sat, 14 Mar 2009 20:46:40 +0100
  4. Subject: [PATCH] rt2x00: Implement support for rt2800usb
  5. Add support for the rt2800usb chipset.
  6. Includes various patches from Mattias, Felix, Xose and Axel.
  7. Signed-off-by: Mattias Nissler <[email protected]>
  8. Signed-off-by: Felix Fietkau <[email protected]>
  9. Signed-off-by: Xose Vazquez Perez <[email protected]>
  10. Signed-off-by: Axel Kollhofer <[email protected]>
  11. Signed-off-by: Ivo van Doorn <[email protected]>
  12. ---
  13. drivers/net/wireless/rt2x00/Kconfig | 14 +
  14. drivers/net/wireless/rt2x00/Makefile | 1 +
  15. drivers/net/wireless/rt2x00/rt2800usb.c | 3032 +++++++++++++++++++++++++++++++
  16. drivers/net/wireless/rt2x00/rt2800usb.h | 1934 ++++++++++++++++++++
  17. drivers/net/wireless/rt2x00/rt2x00.h | 7 +
  18. 5 files changed, 4988 insertions(+), 0 deletions(-)
  19. create mode 100644 drivers/net/wireless/rt2x00/rt2800usb.c
  20. create mode 100644 drivers/net/wireless/rt2x00/rt2800usb.h
  21. --- a/drivers/net/wireless/rt2x00/Makefile
  22. +++ b/drivers/net/wireless/rt2x00/Makefile
  23. @@ -19,3 +19,4 @@ obj-$(CONFIG_RT61PCI) += rt61pci.o
  24. obj-$(CONFIG_RT2800PCI) += rt2800pci.o
  25. obj-$(CONFIG_RT2500USB) += rt2500usb.o
  26. obj-$(CONFIG_RT73USB) += rt73usb.o
  27. +obj-$(CONFIG_RT2800USB) += rt2800usb.o
  28. --- /dev/null
  29. +++ b/drivers/net/wireless/rt2x00/rt2800usb.c
  30. @@ -0,0 +1,3032 @@
  31. +/*
  32. + Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
  33. + <http://rt2x00.serialmonkey.com>
  34. +
  35. + This program is free software; you can redistribute it and/or modify
  36. + it under the terms of the GNU General Public License as published by
  37. + the Free Software Foundation; either version 2 of the License, or
  38. + (at your option) any later version.
  39. +
  40. + This program is distributed in the hope that it will be useful,
  41. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43. + GNU General Public License for more details.
  44. +
  45. + You should have received a copy of the GNU General Public License
  46. + along with this program; if not, write to the
  47. + Free Software Foundation, Inc.,
  48. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  49. + */
  50. +
  51. +/*
  52. + Module: rt2800usb
  53. + Abstract: rt2800usb device specific routines.
  54. + Supported chipsets: RT2800U.
  55. + */
  56. +
  57. +#include <linux/crc-ccitt.h>
  58. +#include <linux/delay.h>
  59. +#include <linux/etherdevice.h>
  60. +#include <linux/init.h>
  61. +#include <linux/kernel.h>
  62. +#include <linux/module.h>
  63. +#include <linux/usb.h>
  64. +
  65. +#include "rt2x00.h"
  66. +#include "rt2x00usb.h"
  67. +#include "rt2800usb.h"
  68. +
  69. +/*
  70. + * Allow hardware encryption to be disabled.
  71. + */
  72. +static int modparam_nohwcrypt = 0;
  73. +module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  74. +MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  75. +
  76. +/*
  77. + * Register access.
  78. + * All access to the CSR registers will go through the methods
  79. + * rt2x00usb_register_read and rt2x00usb_register_write.
  80. + * BBP and RF register require indirect register access,
  81. + * and use the CSR registers BBPCSR and RFCSR to achieve this.
  82. + * These indirect registers work with busy bits,
  83. + * and we will try maximal REGISTER_BUSY_COUNT times to access
  84. + * the register while taking a REGISTER_BUSY_DELAY us delay
  85. + * between each attampt. When the busy bit is still set at that time,
  86. + * the access attempt is considered to have failed,
  87. + * and we will print an error.
  88. + * The _lock versions must be used if you already hold the csr_mutex
  89. + */
  90. +#define WAIT_FOR_BBP(__dev, __reg) \
  91. + rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
  92. +#define WAIT_FOR_RFCSR(__dev, __reg) \
  93. + rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
  94. +#define WAIT_FOR_RF(__dev, __reg) \
  95. + rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
  96. +#define WAIT_FOR_MCU(__dev, __reg) \
  97. + rt2x00usb_regbusy_read((__dev), H2M_MAILBOX_CSR, \
  98. + H2M_MAILBOX_CSR_OWNER, (__reg))
  99. +
  100. +static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  101. + const unsigned int word, const u8 value)
  102. +{
  103. + u32 reg;
  104. +
  105. + mutex_lock(&rt2x00dev->csr_mutex);
  106. +
  107. + /*
  108. + * Wait until the BBP becomes available, afterwards we
  109. + * can safely write the new data into the register.
  110. + */
  111. + if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  112. + reg = 0;
  113. + rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
  114. + rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  115. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  116. + rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
  117. +
  118. + rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  119. + }
  120. +
  121. + mutex_unlock(&rt2x00dev->csr_mutex);
  122. +}
  123. +
  124. +static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  125. + const unsigned int word, u8 *value)
  126. +{
  127. + u32 reg;
  128. +
  129. + mutex_lock(&rt2x00dev->csr_mutex);
  130. +
  131. + /*
  132. + * Wait until the BBP becomes available, afterwards we
  133. + * can safely write the read request into the register.
  134. + * After the data has been written, we wait until hardware
  135. + * returns the correct value, if at any time the register
  136. + * doesn't become available in time, reg will be 0xffffffff
  137. + * which means we return 0xff to the caller.
  138. + */
  139. + if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  140. + reg = 0;
  141. + rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  142. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  143. + rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
  144. +
  145. + rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  146. +
  147. + WAIT_FOR_BBP(rt2x00dev, &reg);
  148. + }
  149. +
  150. + *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
  151. +
  152. + mutex_unlock(&rt2x00dev->csr_mutex);
  153. +}
  154. +
  155. +static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
  156. + const unsigned int word, const u8 value)
  157. +{
  158. + u32 reg;
  159. +
  160. + mutex_lock(&rt2x00dev->csr_mutex);
  161. +
  162. + /*
  163. + * Wait until the RFCSR becomes available, afterwards we
  164. + * can safely write the new data into the register.
  165. + */
  166. + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  167. + reg = 0;
  168. + rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
  169. + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  170. + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
  171. + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  172. +
  173. + rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  174. + }
  175. +
  176. + mutex_unlock(&rt2x00dev->csr_mutex);
  177. +}
  178. +
  179. +static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
  180. + const unsigned int word, u8 *value)
  181. +{
  182. + u32 reg;
  183. +
  184. + mutex_lock(&rt2x00dev->csr_mutex);
  185. +
  186. + /*
  187. + * Wait until the RFCSR becomes available, afterwards we
  188. + * can safely write the read request into the register.
  189. + * After the data has been written, we wait until hardware
  190. + * returns the correct value, if at any time the register
  191. + * doesn't become available in time, reg will be 0xffffffff
  192. + * which means we return 0xff to the caller.
  193. + */
  194. + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  195. + reg = 0;
  196. + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  197. + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
  198. + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  199. +
  200. + rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  201. +
  202. + WAIT_FOR_RFCSR(rt2x00dev, &reg);
  203. + }
  204. +
  205. + *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
  206. +
  207. + mutex_unlock(&rt2x00dev->csr_mutex);
  208. +}
  209. +
  210. +static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
  211. + const unsigned int word, const u32 value)
  212. +{
  213. + u32 reg;
  214. +
  215. + mutex_lock(&rt2x00dev->csr_mutex);
  216. +
  217. + /*
  218. + * Wait until the RF becomes available, afterwards we
  219. + * can safely write the new data into the register.
  220. + */
  221. + if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  222. + reg = 0;
  223. + rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
  224. + rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
  225. + rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
  226. + rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
  227. +
  228. + rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
  229. + rt2x00_rf_write(rt2x00dev, word, value);
  230. + }
  231. +
  232. + mutex_unlock(&rt2x00dev->csr_mutex);
  233. +}
  234. +
  235. +static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
  236. + const u8 command, const u8 token,
  237. + const u8 arg0, const u8 arg1)
  238. +{
  239. + u32 reg;
  240. +
  241. + mutex_lock(&rt2x00dev->csr_mutex);
  242. +
  243. + /*
  244. + * Wait until the MCU becomes available, afterwards we
  245. + * can safely write the new data into the register.
  246. + */
  247. + if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
  248. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  249. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  250. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  251. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  252. + rt2x00usb_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
  253. +
  254. + reg = 0;
  255. + rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  256. + rt2x00usb_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
  257. + }
  258. +
  259. + mutex_unlock(&rt2x00dev->csr_mutex);
  260. +}
  261. +
  262. +#ifdef CONFIG_RT2X00_LIB_DEBUGFS
  263. +static const struct rt2x00debug rt2800usb_rt2x00debug = {
  264. + .owner = THIS_MODULE,
  265. + .csr = {
  266. + .read = rt2x00usb_register_read,
  267. + .write = rt2x00usb_register_write,
  268. + .flags = RT2X00DEBUGFS_OFFSET,
  269. + .word_base = CSR_REG_BASE,
  270. + .word_size = sizeof(u32),
  271. + .word_count = CSR_REG_SIZE / sizeof(u32),
  272. + },
  273. + .eeprom = {
  274. + .read = rt2x00_eeprom_read,
  275. + .write = rt2x00_eeprom_write,
  276. + .word_base = EEPROM_BASE,
  277. + .word_size = sizeof(u16),
  278. + .word_count = EEPROM_SIZE / sizeof(u16),
  279. + },
  280. + .bbp = {
  281. + .read = rt2800usb_bbp_read,
  282. + .write = rt2800usb_bbp_write,
  283. + .word_base = BBP_BASE,
  284. + .word_size = sizeof(u8),
  285. + .word_count = BBP_SIZE / sizeof(u8),
  286. + },
  287. + .rf = {
  288. + .read = rt2x00_rf_read,
  289. + .write = rt2800usb_rf_write,
  290. + .word_base = RF_BASE,
  291. + .word_size = sizeof(u32),
  292. + .word_count = RF_SIZE / sizeof(u32),
  293. + },
  294. +};
  295. +#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  296. +
  297. +#ifdef CONFIG_RT2X00_LIB_RFKILL
  298. +static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  299. +{
  300. + u32 reg;
  301. +
  302. + rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, &reg);
  303. + return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
  304. +}
  305. +#else
  306. +#define rt2800usb_rfkill_poll NULL
  307. +#endif /* CONFIG_RT2X00_LIB_RFKILL */
  308. +
  309. +#ifdef CONFIG_RT2X00_LIB_LEDS
  310. +static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
  311. + enum led_brightness brightness)
  312. +{
  313. + struct rt2x00_led *led =
  314. + container_of(led_cdev, struct rt2x00_led, led_dev);
  315. + unsigned int enabled = brightness != LED_OFF;
  316. + unsigned int bg_mode =
  317. + (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  318. + unsigned int polarity =
  319. + rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  320. + EEPROM_FREQ_LED_POLARITY);
  321. + unsigned int ledmode =
  322. + rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  323. + EEPROM_FREQ_LED_MODE);
  324. +
  325. + if (led->type == LED_TYPE_RADIO) {
  326. + rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  327. + enabled ? 0x20 : 0);
  328. + } else if (led->type == LED_TYPE_ASSOC) {
  329. + rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  330. + enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
  331. + } else if (led->type == LED_TYPE_QUALITY) {
  332. + /*
  333. + * The brightness is divided into 6 levels (0 - 5),
  334. + * The specs tell us the following levels:
  335. + * 0, 1 ,3, 7, 15, 31
  336. + * to determine the level in a simple way we can simply
  337. + * work with bitshifting:
  338. + * (1 << level) - 1
  339. + */
  340. + rt2800usb_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  341. + (1 << brightness / (LED_FULL / 6)) - 1,
  342. + polarity);
  343. + }
  344. +}
  345. +
  346. +static int rt2800usb_blink_set(struct led_classdev *led_cdev,
  347. + unsigned long *delay_on,
  348. + unsigned long *delay_off)
  349. +{
  350. + struct rt2x00_led *led =
  351. + container_of(led_cdev, struct rt2x00_led, led_dev);
  352. + u32 reg;
  353. +
  354. + rt2x00usb_register_read(led->rt2x00dev, LED_CFG, &reg);
  355. + rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, *delay_on);
  356. + rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, *delay_off);
  357. + rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
  358. + rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
  359. + rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 12);
  360. + rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
  361. + rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
  362. + rt2x00usb_register_write(led->rt2x00dev, LED_CFG, reg);
  363. +
  364. + return 0;
  365. +}
  366. +
  367. +static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
  368. + struct rt2x00_led *led,
  369. + enum led_type type)
  370. +{
  371. + led->rt2x00dev = rt2x00dev;
  372. + led->type = type;
  373. + led->led_dev.brightness_set = rt2800usb_brightness_set;
  374. + led->led_dev.blink_set = rt2800usb_blink_set;
  375. + led->flags = LED_INITIALIZED;
  376. +}
  377. +#endif /* CONFIG_RT2X00_LIB_LEDS */
  378. +
  379. +/*
  380. + * Configuration handlers.
  381. + */
  382. +static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
  383. + struct rt2x00lib_crypto *crypto,
  384. + struct ieee80211_key_conf *key)
  385. +{
  386. + struct mac_wcid_entry wcid_entry;
  387. + struct mac_iveiv_entry iveiv_entry;
  388. + u32 offset;
  389. + u32 reg;
  390. +
  391. + offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
  392. +
  393. + rt2x00usb_register_read(rt2x00dev, offset, &reg);
  394. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
  395. + !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
  396. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
  397. + (crypto->cmd == SET_KEY) * crypto->cipher);
  398. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX,
  399. + (crypto->cmd == SET_KEY) * crypto->bssidx);
  400. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
  401. + rt2x00usb_register_write(rt2x00dev, offset, reg);
  402. +
  403. + offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
  404. +
  405. + memset(&iveiv_entry, 0, sizeof(iveiv_entry));
  406. + if ((crypto->cipher == CIPHER_TKIP) ||
  407. + (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
  408. + (crypto->cipher == CIPHER_AES))
  409. + iveiv_entry.iv[3] |= 0x20;
  410. + iveiv_entry.iv[3] |= key->keyidx << 6;
  411. + rt2x00usb_register_multiwrite(rt2x00dev, offset,
  412. + &iveiv_entry, sizeof(iveiv_entry));
  413. +
  414. + offset = MAC_WCID_ENTRY(key->hw_key_idx);
  415. +
  416. + memset(&wcid_entry, 0, sizeof(wcid_entry));
  417. + if (crypto->cmd == SET_KEY)
  418. + memcpy(&wcid_entry, crypto->address, ETH_ALEN);
  419. + rt2x00usb_register_multiwrite(rt2x00dev, offset,
  420. + &wcid_entry, sizeof(wcid_entry));
  421. +}
  422. +
  423. +static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  424. + struct rt2x00lib_crypto *crypto,
  425. + struct ieee80211_key_conf *key)
  426. +{
  427. + struct hw_key_entry key_entry;
  428. + struct rt2x00_field32 field;
  429. + int timeout;
  430. + u32 offset;
  431. + u32 reg;
  432. +
  433. + if (crypto->cmd == SET_KEY) {
  434. + key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
  435. +
  436. + memcpy(key_entry.key, crypto->key,
  437. + sizeof(key_entry.key));
  438. + memcpy(key_entry.tx_mic, crypto->tx_mic,
  439. + sizeof(key_entry.tx_mic));
  440. + memcpy(key_entry.rx_mic, crypto->rx_mic,
  441. + sizeof(key_entry.rx_mic));
  442. +
  443. + offset = SHARED_KEY_ENTRY(key->hw_key_idx);
  444. + timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
  445. + rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  446. + USB_VENDOR_REQUEST_OUT,
  447. + offset, &key_entry,
  448. + sizeof(key_entry),
  449. + timeout);
  450. + }
  451. +
  452. + /*
  453. + * The cipher types are stored over multiple registers
  454. + * starting with SHARED_KEY_MODE_BASE each word will have
  455. + * 32 bits and contains the cipher types for 2 bssidx each.
  456. + * Using the correct defines correctly will cause overhead,
  457. + * so just calculate the correct offset.
  458. + */
  459. + field.bit_offset = 4 * (key->hw_key_idx % 8);
  460. + field.bit_mask = 0x7 << field.bit_offset;
  461. +
  462. + offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
  463. +
  464. + rt2x00usb_register_read(rt2x00dev, offset, &reg);
  465. + rt2x00_set_field32(&reg, field,
  466. + (crypto->cmd == SET_KEY) * crypto->cipher);
  467. + rt2x00usb_register_write(rt2x00dev, offset, reg);
  468. +
  469. + /*
  470. + * Update WCID information
  471. + */
  472. + rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  473. +
  474. + return 0;
  475. +}
  476. +
  477. +static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  478. + struct rt2x00lib_crypto *crypto,
  479. + struct ieee80211_key_conf *key)
  480. +{
  481. + struct hw_key_entry key_entry;
  482. + int timeout;
  483. + u32 offset;
  484. +
  485. + if (crypto->cmd == SET_KEY) {
  486. + /*
  487. + * 1 pairwise key is possible per AID, this means that the AID
  488. + * equals our hw_key_idx. Make sure the WCID starts _after_ the
  489. + * last possible shared key entry.
  490. + */
  491. + if (crypto->aid > (256 - 32))
  492. + return -ENOSPC;
  493. +
  494. + key->hw_key_idx = 32 + crypto->aid;
  495. +
  496. + memcpy(key_entry.key, crypto->key,
  497. + sizeof(key_entry.key));
  498. + memcpy(key_entry.tx_mic, crypto->tx_mic,
  499. + sizeof(key_entry.tx_mic));
  500. + memcpy(key_entry.rx_mic, crypto->rx_mic,
  501. + sizeof(key_entry.rx_mic));
  502. +
  503. + offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  504. + timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
  505. + rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  506. + USB_VENDOR_REQUEST_OUT,
  507. + offset, &key_entry,
  508. + sizeof(key_entry),
  509. + timeout);
  510. + }
  511. +
  512. + /*
  513. + * Update WCID information
  514. + */
  515. + rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
  516. +
  517. + return 0;
  518. +}
  519. +
  520. +static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
  521. + const unsigned int filter_flags)
  522. +{
  523. + u32 reg;
  524. +
  525. + /*
  526. + * Start configuration steps.
  527. + * Note that the version error will always be dropped
  528. + * and broadcast frames will always be accepted since
  529. + * there is no filter for it at this time.
  530. + */
  531. + rt2x00usb_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
  532. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
  533. + !(filter_flags & FIF_FCSFAIL));
  534. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
  535. + !(filter_flags & FIF_PLCPFAIL));
  536. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
  537. + !(filter_flags & FIF_PROMISC_IN_BSS));
  538. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
  539. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
  540. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
  541. + !(filter_flags & FIF_ALLMULTI));
  542. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
  543. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
  544. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
  545. + !(filter_flags & FIF_CONTROL));
  546. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
  547. + !(filter_flags & FIF_CONTROL));
  548. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
  549. + !(filter_flags & FIF_CONTROL));
  550. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
  551. + !(filter_flags & FIF_CONTROL));
  552. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
  553. + !(filter_flags & FIF_CONTROL));
  554. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
  555. + !(filter_flags & FIF_CONTROL));
  556. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 1);
  557. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR, 0);
  558. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
  559. + !(filter_flags & FIF_CONTROL));
  560. + rt2x00usb_register_write(rt2x00dev, RX_FILTER_CFG, reg);
  561. +}
  562. +
  563. +static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
  564. + struct rt2x00_intf *intf,
  565. + struct rt2x00intf_conf *conf,
  566. + const unsigned int flags)
  567. +{
  568. + unsigned int beacon_base;
  569. + u32 reg;
  570. +
  571. + if (flags & CONFIG_UPDATE_TYPE) {
  572. + /*
  573. + * Clear current synchronisation setup.
  574. + * For the Beacon base registers we only need to clear
  575. + * the first byte since that byte contains the VALID and OWNER
  576. + * bits which (when set to 0) will invalidate the entire beacon.
  577. + */
  578. + beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  579. + rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
  580. +
  581. + /*
  582. + * Enable synchronisation.
  583. + */
  584. + rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  585. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  586. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
  587. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  588. + rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  589. + }
  590. +
  591. + if (flags & CONFIG_UPDATE_MAC) {
  592. + reg = le32_to_cpu(conf->mac[1]);
  593. + rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
  594. + conf->mac[1] = cpu_to_le32(reg);
  595. +
  596. + rt2x00usb_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
  597. + conf->mac, sizeof(conf->mac));
  598. + }
  599. +
  600. + if (flags & CONFIG_UPDATE_BSSID) {
  601. + reg = le32_to_cpu(conf->bssid[1]);
  602. + rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 0);
  603. + rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
  604. + conf->bssid[1] = cpu_to_le32(reg);
  605. +
  606. + rt2x00usb_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
  607. + conf->bssid, sizeof(conf->bssid));
  608. + }
  609. +}
  610. +
  611. +static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
  612. + struct rt2x00lib_erp *erp)
  613. +{
  614. + u32 reg;
  615. +
  616. + rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  617. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT,
  618. + DIV_ROUND_UP(erp->ack_timeout, erp->slot_time));
  619. + rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  620. +
  621. + rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  622. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
  623. + !!erp->short_preamble);
  624. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
  625. + !!erp->short_preamble);
  626. + rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  627. +
  628. + rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  629. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
  630. + erp->cts_protection ? 2 : 0);
  631. + rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  632. +
  633. + rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE,
  634. + erp->basic_rates);
  635. + rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  636. +
  637. + rt2x00usb_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
  638. + rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
  639. + rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
  640. + rt2x00usb_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
  641. +
  642. + rt2x00usb_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
  643. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
  644. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
  645. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
  646. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
  647. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
  648. + rt2x00usb_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
  649. +}
  650. +
  651. +static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
  652. + struct antenna_setup *ant)
  653. +{
  654. + u16 eeprom;
  655. + u8 r1;
  656. + u8 r3;
  657. +
  658. + /*
  659. + * FIXME: Use requested antenna configuration.
  660. + */
  661. +
  662. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  663. +
  664. + rt2800usb_bbp_read(rt2x00dev, 1, &r1);
  665. + rt2800usb_bbp_read(rt2x00dev, 3, &r3);
  666. +
  667. + /*
  668. + * Configure the TX antenna.
  669. + */
  670. + switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH)) {
  671. + case 1:
  672. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
  673. + break;
  674. + case 2:
  675. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
  676. + break;
  677. + case 3:
  678. + /* Do nothing */
  679. + break;
  680. + }
  681. +
  682. + /*
  683. + * Configure the RX antenna.
  684. + */
  685. + switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  686. + case 1:
  687. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
  688. + break;
  689. + case 2:
  690. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
  691. + break;
  692. + case 3:
  693. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
  694. + break;
  695. + }
  696. +
  697. + rt2800usb_bbp_write(rt2x00dev, 3, r3);
  698. + rt2800usb_bbp_write(rt2x00dev, 1, r1);
  699. +}
  700. +
  701. +static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  702. + struct rt2x00lib_conf *libconf)
  703. +{
  704. + u16 eeprom;
  705. + short lna_gain;
  706. +
  707. + if (libconf->rf.channel <= 14) {
  708. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  709. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
  710. + } else if (libconf->rf.channel <= 64) {
  711. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  712. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
  713. + } else if (libconf->rf.channel <= 128) {
  714. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
  715. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
  716. + } else {
  717. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
  718. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
  719. + }
  720. +
  721. + rt2x00dev->lna_gain = lna_gain;
  722. +}
  723. +
  724. +static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
  725. + struct ieee80211_conf *conf,
  726. + struct rf_channel *rf,
  727. + struct channel_info *info)
  728. +{
  729. + u16 eeprom;
  730. +
  731. + rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  732. +
  733. + /*
  734. + * Determine antenna settings from EEPROM
  735. + */
  736. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  737. +
  738. + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1)
  739. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
  740. +
  741. + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) {
  742. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
  743. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  744. + } else if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 2)
  745. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  746. +
  747. + if (rf->channel > 14) {
  748. + /*
  749. + * When TX power is below 0, we should increase it by 7 to
  750. + * make it a positive value (Minumum value is -7).
  751. + * However this means that values between 0 and 7 have
  752. + * double meaning, and we should set a 7DBm boost flag.
  753. + */
  754. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
  755. + (info->tx_power1 >= 0));
  756. +
  757. + if (info->tx_power1 < 0)
  758. + info->tx_power1 += 7;
  759. +
  760. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
  761. + TXPOWER_A_TO_DEV(info->tx_power1));
  762. +
  763. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
  764. + (info->tx_power2 >= 0));
  765. +
  766. + if (info->tx_power2 < 0)
  767. + info->tx_power2 += 7;
  768. +
  769. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
  770. + TXPOWER_A_TO_DEV(info->tx_power2));
  771. + } else {
  772. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
  773. + TXPOWER_G_TO_DEV(info->tx_power1));
  774. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
  775. + TXPOWER_G_TO_DEV(info->tx_power2));
  776. + }
  777. +
  778. + rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
  779. +
  780. + rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  781. + rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  782. + rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  783. + rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  784. +
  785. + udelay(200);
  786. +
  787. + rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  788. + rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  789. + rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  790. + rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  791. +
  792. + udelay(200);
  793. +
  794. + rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
  795. + rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
  796. + rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  797. + rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
  798. +}
  799. +
  800. +static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
  801. + struct ieee80211_conf *conf,
  802. + struct rf_channel *rf,
  803. + struct channel_info *info)
  804. +{
  805. + u8 rfcsr;
  806. +
  807. + rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
  808. + rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
  809. +
  810. + rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
  811. + rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
  812. + rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
  813. +
  814. + rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
  815. + rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
  816. + TXPOWER_G_TO_DEV(info->tx_power1));
  817. + rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
  818. +
  819. + rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
  820. + rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
  821. + rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
  822. +
  823. + if (conf_is_ht40(conf))
  824. + rt2800usb_rfcsr_write(rt2x00dev, 24,
  825. + rt2x00dev->calibration_bw40);
  826. + else
  827. + rt2800usb_rfcsr_write(rt2x00dev, 24,
  828. + rt2x00dev->calibration_bw20);
  829. +
  830. + rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
  831. + rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  832. + rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
  833. +}
  834. +
  835. +static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
  836. + struct ieee80211_conf *conf,
  837. + struct rf_channel *rf,
  838. + struct channel_info *info)
  839. +{
  840. + u32 reg;
  841. + unsigned int tx_pin;
  842. + u16 eeprom;
  843. + u8 bbp;
  844. +
  845. + /*
  846. + * Determine antenna settings from EEPROM
  847. + */
  848. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  849. +
  850. + if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  851. + rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
  852. + else
  853. + rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
  854. +
  855. + /*
  856. + * Change BBP settings
  857. + */
  858. + rt2800usb_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  859. + rt2800usb_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  860. + rt2800usb_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  861. + rt2800usb_bbp_write(rt2x00dev, 86, 0);
  862. +
  863. + if (rf->channel <= 14) {
  864. + if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  865. + rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
  866. + rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
  867. + } else {
  868. + rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
  869. + rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
  870. + }
  871. + } else {
  872. + rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
  873. +
  874. + if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
  875. + rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
  876. + else
  877. + rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
  878. + }
  879. +
  880. + rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
  881. + rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
  882. + rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
  883. + rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
  884. + rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
  885. +
  886. + tx_pin = 0;
  887. +
  888. + /* Turn on unused PA or LNA when not using 1T or 1R */
  889. + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) != 1) {
  890. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
  891. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
  892. + }
  893. +
  894. + /* Turn on unused PA or LNA when not using 1T or 1R */
  895. + if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) != 1) {
  896. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
  897. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
  898. + }
  899. +
  900. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
  901. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
  902. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
  903. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
  904. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
  905. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
  906. +
  907. + rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  908. +
  909. + rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  910. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
  911. + rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  912. +
  913. + rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
  914. + rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
  915. + rt2800usb_bbp_write(rt2x00dev, 3, bbp);
  916. +
  917. + if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  918. + if (conf_is_ht40(conf)) {
  919. + rt2800usb_bbp_write(rt2x00dev, 69, 0x1a);
  920. + rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  921. + rt2800usb_bbp_write(rt2x00dev, 73, 0x16);
  922. + } else {
  923. + rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
  924. + rt2800usb_bbp_write(rt2x00dev, 70, 0x08);
  925. + rt2800usb_bbp_write(rt2x00dev, 73, 0x11);
  926. + }
  927. + }
  928. +
  929. + msleep(1);
  930. +}
  931. +
  932. +static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  933. + const int txpower)
  934. +{
  935. + u32 reg;
  936. + u32 value = TXPOWER_G_TO_DEV(txpower);
  937. + u8 r1;
  938. +
  939. + rt2800usb_bbp_read(rt2x00dev, 1, &r1);
  940. + rt2x00_set_field8(&reg, BBP1_TX_POWER, 0);
  941. + rt2800usb_bbp_write(rt2x00dev, 1, r1);
  942. +
  943. + rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_0, &reg);
  944. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_1MBS, value);
  945. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_2MBS, value);
  946. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_55MBS, value);
  947. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_11MBS, value);
  948. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_6MBS, value);
  949. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_9MBS, value);
  950. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_12MBS, value);
  951. + rt2x00_set_field32(&reg, TX_PWR_CFG_0_18MBS, value);
  952. + rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
  953. +
  954. + rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_1, &reg);
  955. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_24MBS, value);
  956. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_36MBS, value);
  957. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_48MBS, value);
  958. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_54MBS, value);
  959. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS0, value);
  960. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS1, value);
  961. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS2, value);
  962. + rt2x00_set_field32(&reg, TX_PWR_CFG_1_MCS3, value);
  963. + rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
  964. +
  965. + rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_2, &reg);
  966. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS4, value);
  967. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS5, value);
  968. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS6, value);
  969. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS7, value);
  970. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS8, value);
  971. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS9, value);
  972. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS10, value);
  973. + rt2x00_set_field32(&reg, TX_PWR_CFG_2_MCS11, value);
  974. + rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
  975. +
  976. + rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_3, &reg);
  977. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS12, value);
  978. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS13, value);
  979. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS14, value);
  980. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_MCS15, value);
  981. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN1, value);
  982. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN2, value);
  983. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN3, value);
  984. + rt2x00_set_field32(&reg, TX_PWR_CFG_3_UKNOWN4, value);
  985. + rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
  986. +
  987. + rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_4, &reg);
  988. + rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN5, value);
  989. + rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN6, value);
  990. + rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN7, value);
  991. + rt2x00_set_field32(&reg, TX_PWR_CFG_4_UKNOWN8, value);
  992. + rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
  993. +}
  994. +
  995. +static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  996. + struct rt2x00lib_conf *libconf)
  997. +{
  998. + u32 reg;
  999. +
  1000. + rt2x00usb_register_read(rt2x00dev, TX_RTY_CFG, &reg);
  1001. + rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
  1002. + libconf->conf->short_frame_max_tx_count);
  1003. + rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
  1004. + libconf->conf->long_frame_max_tx_count);
  1005. + rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
  1006. + rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
  1007. + rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
  1008. + rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
  1009. + rt2x00usb_register_write(rt2x00dev, TX_RTY_CFG, reg);
  1010. +}
  1011. +
  1012. +static void rt2800usb_config_duration(struct rt2x00_dev *rt2x00dev,
  1013. + struct rt2x00lib_conf *libconf)
  1014. +{
  1015. + u32 reg;
  1016. +
  1017. + rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1018. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
  1019. + libconf->conf->beacon_int * 16);
  1020. + rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1021. +}
  1022. +
  1023. +static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
  1024. + struct rt2x00lib_conf *libconf)
  1025. +{
  1026. + enum dev_state state =
  1027. + (libconf->conf->flags & IEEE80211_CONF_PS) ?
  1028. + STATE_SLEEP : STATE_AWAKE;
  1029. + u32 reg;
  1030. +
  1031. + if (state == STATE_SLEEP) {
  1032. + rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
  1033. +
  1034. + rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  1035. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
  1036. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
  1037. + libconf->conf->listen_interval - 1);
  1038. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
  1039. + rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  1040. +
  1041. + rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 0);
  1042. + } else {
  1043. + rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  1044. +
  1045. + rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  1046. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
  1047. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
  1048. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
  1049. + rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  1050. + }
  1051. +}
  1052. +
  1053. +static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
  1054. + struct rt2x00lib_conf *libconf,
  1055. + const unsigned int flags)
  1056. +{
  1057. + /* Always recalculate LNA gain before changing configuration */
  1058. + rt2800usb_config_lna_gain(rt2x00dev, libconf);
  1059. +
  1060. + if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  1061. + rt2800usb_config_channel(rt2x00dev, libconf->conf,
  1062. + &libconf->rf, &libconf->channel);
  1063. + if (flags & IEEE80211_CONF_CHANGE_POWER)
  1064. + rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  1065. + if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  1066. + rt2800usb_config_retry_limit(rt2x00dev, libconf);
  1067. + if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
  1068. + rt2800usb_config_duration(rt2x00dev, libconf);
  1069. + if (flags & IEEE80211_CONF_CHANGE_PS)
  1070. + rt2800usb_config_ps(rt2x00dev, libconf);
  1071. +}
  1072. +
  1073. +/*
  1074. + * Link tuning
  1075. + */
  1076. +static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
  1077. + struct link_qual *qual)
  1078. +{
  1079. + u32 reg;
  1080. +
  1081. + /*
  1082. + * Update FCS error count from register.
  1083. + */
  1084. + rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  1085. + qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
  1086. +}
  1087. +
  1088. +static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
  1089. +{
  1090. + if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  1091. + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
  1092. + return 0x1c + (2 * rt2x00dev->lna_gain);
  1093. + else
  1094. + return 0x2e + rt2x00dev->lna_gain;
  1095. + }
  1096. +
  1097. + if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  1098. + return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
  1099. + else
  1100. + return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
  1101. +}
  1102. +
  1103. +static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
  1104. + struct link_qual *qual, u8 vgc_level)
  1105. +{
  1106. + if (qual->vgc_level != vgc_level) {
  1107. + rt2800usb_bbp_write(rt2x00dev, 66, vgc_level);
  1108. + qual->vgc_level = vgc_level;
  1109. + qual->vgc_level_reg = vgc_level;
  1110. + }
  1111. +}
  1112. +
  1113. +static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
  1114. + struct link_qual *qual)
  1115. +{
  1116. + rt2800usb_set_vgc(rt2x00dev, qual,
  1117. + rt2800usb_get_default_vgc(rt2x00dev));
  1118. +}
  1119. +
  1120. +static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
  1121. + struct link_qual *qual, const u32 count)
  1122. +{
  1123. + if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
  1124. + return;
  1125. +
  1126. + /*
  1127. + * When RSSI is better then -80 increase VGC level with 0x10
  1128. + */
  1129. + rt2800usb_set_vgc(rt2x00dev, qual,
  1130. + rt2800usb_get_default_vgc(rt2x00dev) +
  1131. + ((qual->rssi > -80) * 0x10));
  1132. +}
  1133. +
  1134. +/*
  1135. + * Firmware functions
  1136. + */
  1137. +static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  1138. +{
  1139. + return FIRMWARE_RT2870;
  1140. +}
  1141. +
  1142. +static bool rt2800usb_check_crc(const u8 *data, const size_t len)
  1143. +{
  1144. + u16 fw_crc;
  1145. + u16 crc;
  1146. +
  1147. + /*
  1148. + * The last 2 bytes in the firmware array are the crc checksum itself,
  1149. + * this means that we should never pass those 2 bytes to the crc
  1150. + * algorithm.
  1151. + */
  1152. + fw_crc = (data[len - 2] << 8 | data[len - 1]);
  1153. +
  1154. + /*
  1155. + * Use the crc ccitt algorithm.
  1156. + * This will return the same value as the legacy driver which
  1157. + * used bit ordering reversion on the both the firmware bytes
  1158. + * before input input as well as on the final output.
  1159. + * Obviously using crc ccitt directly is much more efficient.
  1160. + */
  1161. + crc = crc_ccitt(~0, data, len - 2);
  1162. +
  1163. + /*
  1164. + * There is a small difference between the crc-itu-t + bitrev and
  1165. + * the crc-ccitt crc calculation. In the latter method the 2 bytes
  1166. + * will be swapped, use swab16 to convert the crc to the correct
  1167. + * value.
  1168. + */
  1169. + crc = swab16(crc);
  1170. +
  1171. + return fw_crc == crc;
  1172. +}
  1173. +
  1174. +static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
  1175. + const u8 *data, const size_t len)
  1176. +{
  1177. + u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  1178. + size_t offset = 0;
  1179. +
  1180. + /*
  1181. + * Firmware files:
  1182. + * There are 2 variations of the rt2870 firmware.
  1183. + * a) size: 4kb
  1184. + * b) size: 8kb
  1185. + * Note that (b) contains 2 seperate firmware blobs of 4k
  1186. + * within the file. The first blob is the same firmware as (a),
  1187. + * but the second blob is for the additional chipsets.
  1188. + */
  1189. + if (len != 4096 && len != 8192)
  1190. + return FW_BAD_LENGTH;
  1191. +
  1192. + /*
  1193. + * Check if we need the upper 4kb firmware data or not.
  1194. + */
  1195. + if ((len == 4096) &&
  1196. + (chipset != 0x2860) &&
  1197. + (chipset != 0x2872) &&
  1198. + (chipset != 0x3070))
  1199. + return FW_BAD_VERSION;
  1200. +
  1201. + /*
  1202. + * 8kb firmware files must be checked as if it were
  1203. + * 2 seperate firmware files.
  1204. + */
  1205. + while (offset < len) {
  1206. + if (!rt2800usb_check_crc(data + offset, 4096))
  1207. + return FW_BAD_CRC;
  1208. +
  1209. + offset += 4096;
  1210. + }
  1211. +
  1212. + return FW_OK;
  1213. +}
  1214. +
  1215. +static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
  1216. + const u8 *data, const size_t len)
  1217. +{
  1218. + unsigned int i;
  1219. + int status;
  1220. + u32 reg;
  1221. + u32 offset;
  1222. + u32 length;
  1223. + u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
  1224. +
  1225. + /*
  1226. + * Check which section of the firmware we need.
  1227. + */
  1228. + if ((chipset == 0x2860) || (chipset == 0x2872) || (chipset == 0x3070)) {
  1229. + offset = 0;
  1230. + length = 4096;
  1231. + } else {
  1232. + offset = 4096;
  1233. + length = 4096;
  1234. + }
  1235. +
  1236. + /*
  1237. + * Wait for stable hardware.
  1238. + */
  1239. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1240. + rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1241. + if (reg && reg != ~0)
  1242. + break;
  1243. + msleep(1);
  1244. + }
  1245. +
  1246. + if (i == REGISTER_BUSY_COUNT) {
  1247. + ERROR(rt2x00dev, "Unstable hardware.\n");
  1248. + return -EBUSY;
  1249. + }
  1250. +
  1251. + /*
  1252. + * Write firmware to device.
  1253. + */
  1254. + rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1255. + USB_VENDOR_REQUEST_OUT,
  1256. + FIRMWARE_IMAGE_BASE,
  1257. + data + offset, length,
  1258. + REGISTER_TIMEOUT32(length));
  1259. +
  1260. + rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
  1261. + rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
  1262. +
  1263. + /*
  1264. + * Send firmware request to device to load firmware,
  1265. + * we need to specify a long timeout time.
  1266. + */
  1267. + status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  1268. + 0, USB_MODE_FIRMWARE,
  1269. + REGISTER_TIMEOUT_FIRMWARE);
  1270. + if (status < 0) {
  1271. + ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  1272. + return status;
  1273. + }
  1274. +
  1275. + /*
  1276. + * Wait for device to stabilize.
  1277. + */
  1278. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1279. + rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1280. + if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  1281. + break;
  1282. + msleep(1);
  1283. + }
  1284. +
  1285. + if (i == REGISTER_BUSY_COUNT) {
  1286. + ERROR(rt2x00dev, "PBF system register not ready.\n");
  1287. + return -EBUSY;
  1288. + }
  1289. +
  1290. + /*
  1291. + * Initialize firmware.
  1292. + */
  1293. + rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  1294. + rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1295. + msleep(1);
  1296. +
  1297. + return 0;
  1298. +}
  1299. +
  1300. +/*
  1301. + * Initialization functions.
  1302. + */
  1303. +static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
  1304. +{
  1305. + u32 reg;
  1306. + unsigned int i;
  1307. +
  1308. + /*
  1309. + * Wait untill BBP and RF are ready.
  1310. + */
  1311. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1312. + rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1313. + if (reg && reg != ~0)
  1314. + break;
  1315. + msleep(1);
  1316. + }
  1317. +
  1318. + if (i == REGISTER_BUSY_COUNT) {
  1319. + ERROR(rt2x00dev, "Unstable hardware.\n");
  1320. + return -EBUSY;
  1321. + }
  1322. +
  1323. + rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  1324. + rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
  1325. +
  1326. + rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1327. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_CSR, 1);
  1328. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_RESET_BBP, 1);
  1329. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1330. +
  1331. + rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
  1332. +
  1333. + rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
  1334. + USB_MODE_RESET, REGISTER_TIMEOUT);
  1335. +
  1336. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1337. +
  1338. + rt2x00usb_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  1339. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  1340. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  1341. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  1342. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  1343. + rt2x00usb_register_write(rt2x00dev, BCN_OFFSET0, reg);
  1344. +
  1345. + rt2x00usb_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  1346. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  1347. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  1348. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  1349. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  1350. + rt2x00usb_register_write(rt2x00dev, BCN_OFFSET1, reg);
  1351. +
  1352. + rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  1353. + rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  1354. +
  1355. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  1356. +
  1357. + rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  1358. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 0);
  1359. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  1360. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  1361. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  1362. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  1363. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  1364. + rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  1365. +
  1366. + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1367. + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  1368. + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  1369. + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  1370. + } else {
  1371. + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  1372. + rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  1373. + }
  1374. +
  1375. + rt2x00usb_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  1376. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  1377. + rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  1378. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  1379. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  1380. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  1381. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  1382. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  1383. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  1384. + rt2x00usb_register_write(rt2x00dev, TX_LINK_CFG, reg);
  1385. +
  1386. + rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  1387. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  1388. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  1389. + rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  1390. +
  1391. + rt2x00usb_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  1392. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  1393. + if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
  1394. + rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
  1395. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  1396. + else
  1397. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  1398. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  1399. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  1400. + rt2x00usb_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  1401. +
  1402. + rt2x00usb_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  1403. +
  1404. + rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  1405. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  1406. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  1407. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  1408. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  1409. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  1410. + rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  1411. +
  1412. + rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  1413. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 8);
  1414. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  1415. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV, 1);
  1416. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1417. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1418. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1419. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1420. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1421. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1422. + rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  1423. +
  1424. + rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  1425. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 8);
  1426. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  1427. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV, 1);
  1428. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1429. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1430. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1431. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1432. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1433. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1434. + rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  1435. +
  1436. + rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  1437. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  1438. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  1439. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV, 1);
  1440. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1441. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1442. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1443. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1444. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1445. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1446. + rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  1447. +
  1448. + rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  1449. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  1450. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  1451. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV, 1);
  1452. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1453. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1454. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1455. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1456. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1457. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1458. + rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  1459. +
  1460. + rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  1461. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  1462. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  1463. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV, 1);
  1464. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1465. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1466. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1467. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  1468. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1469. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  1470. + rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  1471. +
  1472. + rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  1473. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  1474. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  1475. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV, 1);
  1476. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  1477. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  1478. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  1479. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  1480. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  1481. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  1482. + rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  1483. +
  1484. + rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  1485. +
  1486. + rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1487. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1488. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  1489. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1490. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  1491. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  1492. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  1493. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  1494. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  1495. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  1496. + rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1497. +
  1498. + rt2x00usb_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
  1499. + rt2x00usb_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
  1500. +
  1501. + rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  1502. + rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  1503. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  1504. + IEEE80211_MAX_RTS_THRESHOLD);
  1505. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  1506. + rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
  1507. +
  1508. + rt2x00usb_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  1509. + rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  1510. +
  1511. + /*
  1512. + * ASIC will keep garbage value after boot, clear encryption keys.
  1513. + */
  1514. + for (i = 0; i < 256; i++) {
  1515. + u32 wcid[2] = { 0xffffffff, 0x00ffffff };
  1516. + rt2x00usb_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
  1517. + wcid, sizeof(wcid));
  1518. +
  1519. + rt2x00usb_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
  1520. + rt2x00usb_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  1521. + }
  1522. +
  1523. + for (i = 0; i < 16; i++)
  1524. + rt2x00usb_register_write(rt2x00dev,
  1525. + SHARED_KEY_MODE_ENTRY(i), 0);
  1526. +
  1527. + /*
  1528. + * Clear all beacons
  1529. + * For the Beacon base registers we only need to clear
  1530. + * the first byte since that byte contains the VALID and OWNER
  1531. + * bits which (when set to 0) will invalidate the entire beacon.
  1532. + */
  1533. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1534. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1535. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1536. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1537. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
  1538. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
  1539. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
  1540. + rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
  1541. +
  1542. + rt2x00usb_register_read(rt2x00dev, USB_CYC_CFG, &reg);
  1543. + rt2x00_set_field32(&reg, USB_CYC_CFG_CLOCK_CYCLE, 30);
  1544. + rt2x00usb_register_write(rt2x00dev, USB_CYC_CFG, reg);
  1545. +
  1546. + rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  1547. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  1548. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  1549. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  1550. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  1551. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  1552. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  1553. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  1554. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  1555. + rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  1556. +
  1557. + rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  1558. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  1559. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  1560. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  1561. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  1562. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  1563. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  1564. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  1565. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  1566. + rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  1567. +
  1568. + rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  1569. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  1570. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  1571. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 3);
  1572. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  1573. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  1574. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  1575. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  1576. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  1577. + rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  1578. +
  1579. + rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  1580. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  1581. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  1582. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  1583. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  1584. + rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  1585. +
  1586. + /*
  1587. + * We must clear the error counters.
  1588. + * These registers are cleared on read,
  1589. + * so we may pass a useless variable to store the value.
  1590. + */
  1591. + rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  1592. + rt2x00usb_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  1593. + rt2x00usb_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  1594. + rt2x00usb_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  1595. + rt2x00usb_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  1596. + rt2x00usb_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  1597. +
  1598. + return 0;
  1599. +}
  1600. +
  1601. +static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  1602. +{
  1603. + unsigned int i;
  1604. + u32 reg;
  1605. +
  1606. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1607. + rt2x00usb_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  1608. + if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  1609. + return 0;
  1610. +
  1611. + udelay(REGISTER_BUSY_DELAY);
  1612. + }
  1613. +
  1614. + ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
  1615. + return -EACCES;
  1616. +}
  1617. +
  1618. +static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1619. +{
  1620. + unsigned int i;
  1621. + u8 value;
  1622. +
  1623. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1624. + rt2800usb_bbp_read(rt2x00dev, 0, &value);
  1625. + if ((value != 0xff) && (value != 0x00))
  1626. + return 0;
  1627. + udelay(REGISTER_BUSY_DELAY);
  1628. + }
  1629. +
  1630. + ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1631. + return -EACCES;
  1632. +}
  1633. +
  1634. +static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1635. +{
  1636. + unsigned int i;
  1637. + u16 eeprom;
  1638. + u8 reg_id;
  1639. + u8 value;
  1640. +
  1641. + if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
  1642. + rt2800usb_wait_bbp_ready(rt2x00dev)))
  1643. + return -EACCES;
  1644. +
  1645. + rt2800usb_bbp_write(rt2x00dev, 65, 0x2c);
  1646. + rt2800usb_bbp_write(rt2x00dev, 66, 0x38);
  1647. + rt2800usb_bbp_write(rt2x00dev, 69, 0x12);
  1648. + rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  1649. + rt2800usb_bbp_write(rt2x00dev, 73, 0x10);
  1650. + rt2800usb_bbp_write(rt2x00dev, 81, 0x37);
  1651. + rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
  1652. + rt2800usb_bbp_write(rt2x00dev, 83, 0x6a);
  1653. + rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
  1654. + rt2800usb_bbp_write(rt2x00dev, 86, 0x00);
  1655. + rt2800usb_bbp_write(rt2x00dev, 91, 0x04);
  1656. + rt2800usb_bbp_write(rt2x00dev, 92, 0x00);
  1657. + rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
  1658. + rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
  1659. +
  1660. + if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
  1661. + rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
  1662. + rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
  1663. + }
  1664. +
  1665. + if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
  1666. + rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
  1667. + }
  1668. +
  1669. + if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
  1670. + rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
  1671. + rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
  1672. + rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
  1673. + }
  1674. +
  1675. + for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1676. + rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1677. +
  1678. + if (eeprom != 0xffff && eeprom != 0x0000) {
  1679. + reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1680. + value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1681. + rt2800usb_bbp_write(rt2x00dev, reg_id, value);
  1682. + }
  1683. + }
  1684. +
  1685. + return 0;
  1686. +}
  1687. +
  1688. +static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
  1689. + bool bw40, u8 rfcsr24, u8 filter_target)
  1690. +{
  1691. + unsigned int i;
  1692. + u8 bbp;
  1693. + u8 rfcsr;
  1694. + u8 passband;
  1695. + u8 stopband;
  1696. + u8 overtuned = 0;
  1697. +
  1698. + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1699. +
  1700. + rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  1701. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  1702. + rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  1703. +
  1704. + rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1705. + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  1706. + rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
  1707. +
  1708. + /*
  1709. + * Set power & frequency of passband test tone
  1710. + */
  1711. + rt2800usb_bbp_write(rt2x00dev, 24, 0);
  1712. +
  1713. + for (i = 0; i < 100; i++) {
  1714. + rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
  1715. + msleep(1);
  1716. +
  1717. + rt2800usb_bbp_read(rt2x00dev, 55, &passband);
  1718. + if (passband)
  1719. + break;
  1720. + }
  1721. +
  1722. + /*
  1723. + * Set power & frequency of stopband test tone
  1724. + */
  1725. + rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
  1726. +
  1727. + for (i = 0; i < 100; i++) {
  1728. + rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
  1729. + msleep(1);
  1730. +
  1731. + rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
  1732. +
  1733. + if ((passband - stopband) <= filter_target) {
  1734. + rfcsr24++;
  1735. + overtuned += ((passband - stopband) == filter_target);
  1736. + } else
  1737. + break;
  1738. +
  1739. + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1740. + }
  1741. +
  1742. + rfcsr24 -= !!overtuned;
  1743. +
  1744. + rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
  1745. + return rfcsr24;
  1746. +}
  1747. +
  1748. +static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  1749. +{
  1750. + u8 rfcsr;
  1751. + u8 bbp;
  1752. +
  1753. + if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
  1754. + return 0;
  1755. +
  1756. + /*
  1757. + * Init RF calibration.
  1758. + */
  1759. + rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
  1760. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  1761. + rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
  1762. + msleep(1);
  1763. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  1764. + rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
  1765. +
  1766. + rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
  1767. + rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
  1768. + rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
  1769. + rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
  1770. + rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
  1771. + rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
  1772. + rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
  1773. + rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
  1774. + rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
  1775. + rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
  1776. + rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
  1777. + rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
  1778. + rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
  1779. + rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
  1780. + rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
  1781. + rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
  1782. + rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
  1783. + rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
  1784. + rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
  1785. + rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
  1786. +
  1787. + /*
  1788. + * Set RX Filter calibration for 20MHz and 40MHz
  1789. + */
  1790. + rt2x00dev->calibration_bw20 =
  1791. + rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
  1792. + rt2x00dev->calibration_bw40 =
  1793. + rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
  1794. +
  1795. + /*
  1796. + * Set back to initial state
  1797. + */
  1798. + rt2800usb_bbp_write(rt2x00dev, 24, 0);
  1799. +
  1800. + rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
  1801. + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  1802. + rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
  1803. +
  1804. + /*
  1805. + * set BBP back to BW20
  1806. + */
  1807. + rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
  1808. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  1809. + rt2800usb_bbp_write(rt2x00dev, 4, bbp);
  1810. +
  1811. + return 0;
  1812. +}
  1813. +
  1814. +/*
  1815. + * Device state switch handlers.
  1816. + */
  1817. +static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1818. + enum dev_state state)
  1819. +{
  1820. + u32 reg;
  1821. +
  1822. + rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1823. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX,
  1824. + (state == STATE_RADIO_RX_ON) ||
  1825. + (state == STATE_RADIO_RX_ON_LINK));
  1826. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1827. +}
  1828. +
  1829. +static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  1830. +{
  1831. + unsigned int i;
  1832. + u32 reg;
  1833. +
  1834. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1835. + rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1836. + if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  1837. + !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  1838. + return 0;
  1839. +
  1840. + msleep(1);
  1841. + }
  1842. +
  1843. + ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
  1844. + return -EACCES;
  1845. +}
  1846. +
  1847. +static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1848. +{
  1849. + u32 reg;
  1850. + u16 word;
  1851. +
  1852. + /*
  1853. + * Initialize all registers.
  1854. + */
  1855. + if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
  1856. + rt2800usb_init_registers(rt2x00dev) ||
  1857. + rt2800usb_init_bbp(rt2x00dev) ||
  1858. + rt2800usb_init_rfcsr(rt2x00dev)))
  1859. + return -EIO;
  1860. +
  1861. + rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1862. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1863. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1864. +
  1865. + udelay(50);
  1866. +
  1867. + rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1868. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  1869. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  1870. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  1871. + rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1872. +
  1873. +
  1874. + rt2x00usb_register_read(rt2x00dev, USB_DMA_CFG, &reg);
  1875. + rt2x00_set_field32(&reg, USB_DMA_CFG_PHY_CLEAR, 0);
  1876. + /* Don't use bulk in aggregation when working with USB 1.1 */
  1877. + rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_EN,
  1878. + (rt2x00dev->rx->usb_maxpacket == 512));
  1879. + rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
  1880. + /* FIXME: Calculate this value based on Aggregation defines */
  1881. + rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_AGG_LIMIT, 21);
  1882. + rt2x00_set_field32(&reg, USB_DMA_CFG_RX_BULK_EN, 1);
  1883. + rt2x00_set_field32(&reg, USB_DMA_CFG_TX_BULK_EN, 1);
  1884. + rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg);
  1885. +
  1886. + rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  1887. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  1888. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  1889. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  1890. +
  1891. + /*
  1892. + * Send signal to firmware during boot time.
  1893. + */
  1894. + rt2800usb_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
  1895. +
  1896. + /*
  1897. + * Initialize LED control
  1898. + */
  1899. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
  1900. + rt2800usb_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
  1901. + word & 0xff, (word >> 8) & 0xff);
  1902. +
  1903. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
  1904. + rt2800usb_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
  1905. + word & 0xff, (word >> 8) & 0xff);
  1906. +
  1907. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
  1908. + rt2800usb_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
  1909. + word & 0xff, (word >> 8) & 0xff);
  1910. +
  1911. + return 0;
  1912. +}
  1913. +
  1914. +static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1915. +{
  1916. + u32 reg;
  1917. +
  1918. + rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  1919. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  1920. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  1921. + rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  1922. +
  1923. + rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
  1924. + rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0);
  1925. + rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, 0);
  1926. +
  1927. + /* Wait for DMA, ignore error */
  1928. + rt2800usb_wait_wpdma_ready(rt2x00dev);
  1929. +
  1930. + rt2x00usb_disable_radio(rt2x00dev);
  1931. +}
  1932. +
  1933. +static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
  1934. + enum dev_state state)
  1935. +{
  1936. + rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
  1937. +
  1938. + if (state == STATE_AWAKE)
  1939. + rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
  1940. + else
  1941. + rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
  1942. +
  1943. + return 0;
  1944. +}
  1945. +
  1946. +static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1947. + enum dev_state state)
  1948. +{
  1949. + int retval = 0;
  1950. +
  1951. + switch (state) {
  1952. + case STATE_RADIO_ON:
  1953. + /*
  1954. + * Before the radio can be enabled, the device first has
  1955. + * to be woken up. After that it needs a bit of time
  1956. + * to be fully awake and the radio can be enabled.
  1957. + */
  1958. + rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
  1959. + msleep(1);
  1960. + retval = rt2800usb_enable_radio(rt2x00dev);
  1961. + break;
  1962. + case STATE_RADIO_OFF:
  1963. + /*
  1964. + * After the radio has been disablee, the device should
  1965. + * be put to sleep for powersaving.
  1966. + */
  1967. + rt2800usb_disable_radio(rt2x00dev);
  1968. + rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
  1969. + break;
  1970. + case STATE_RADIO_RX_ON:
  1971. + case STATE_RADIO_RX_ON_LINK:
  1972. + case STATE_RADIO_RX_OFF:
  1973. + case STATE_RADIO_RX_OFF_LINK:
  1974. + rt2800usb_toggle_rx(rt2x00dev, state);
  1975. + break;
  1976. + case STATE_RADIO_IRQ_ON:
  1977. + case STATE_RADIO_IRQ_OFF:
  1978. + /* No support, but no error either */
  1979. + break;
  1980. + case STATE_DEEP_SLEEP:
  1981. + case STATE_SLEEP:
  1982. + case STATE_STANDBY:
  1983. + case STATE_AWAKE:
  1984. + retval = rt2800usb_set_state(rt2x00dev, state);
  1985. + break;
  1986. + default:
  1987. + retval = -ENOTSUPP;
  1988. + break;
  1989. + }
  1990. +
  1991. + if (unlikely(retval))
  1992. + ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1993. + state, retval);
  1994. +
  1995. + return retval;
  1996. +}
  1997. +
  1998. +/*
  1999. + * TX descriptor initialization
  2000. + */
  2001. +static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  2002. + struct sk_buff *skb,
  2003. + struct txentry_desc *txdesc)
  2004. +{
  2005. + struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  2006. + __le32 *txi = skbdesc->desc;
  2007. + __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
  2008. + u32 word;
  2009. +
  2010. + /*
  2011. + * Initialize TX Info descriptor
  2012. + */
  2013. + rt2x00_desc_read(txwi, 0, &word);
  2014. + rt2x00_set_field32(&word, TXWI_W0_FRAG,
  2015. + test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  2016. + rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
  2017. + rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  2018. + rt2x00_set_field32(&word, TXWI_W0_TS,
  2019. + test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  2020. + rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  2021. + test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  2022. + rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
  2023. + rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
  2024. + rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
  2025. + rt2x00_set_field32(&word, TXWI_W0_BW,
  2026. + test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  2027. + rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  2028. + test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  2029. + rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
  2030. + rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  2031. + rt2x00_desc_write(txwi, 0, word);
  2032. +
  2033. + rt2x00_desc_read(txwi, 1, &word);
  2034. + rt2x00_set_field32(&word, TXWI_W1_ACK,
  2035. + test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  2036. + rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  2037. + test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  2038. + rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
  2039. + rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  2040. + test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  2041. + txdesc->key_idx : 0xff);
  2042. + rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT, skb->len);
  2043. + rt2x00_set_field32(&word, TXWI_W1_PACKETID,
  2044. + skbdesc->entry->entry_idx);
  2045. + rt2x00_desc_write(txwi, 1, word);
  2046. +
  2047. + /*
  2048. + * Always write 0 to IV/EIV fields, hardware will insert the IV
  2049. + * from the IVEIV register when TXINFO_W0_WIV is set to 0.
  2050. + * When TXINFO_W0_WIV is set to 1 it will use the IV data
  2051. + * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  2052. + * crypto entry in the registers should be used to encrypt the frame.
  2053. + */
  2054. + _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
  2055. + _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
  2056. +
  2057. + /*
  2058. + * Initialize TX descriptor
  2059. + */
  2060. + rt2x00_desc_read(txi, 0, &word);
  2061. + rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
  2062. + skb->len + TXWI_DESC_SIZE);
  2063. + rt2x00_set_field32(&word, TXINFO_W0_WIV,
  2064. + !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
  2065. + rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
  2066. + rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
  2067. + rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
  2068. + rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
  2069. + test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  2070. + rt2x00_desc_write(txi, 0, word);
  2071. +}
  2072. +
  2073. +/*
  2074. + * TX data initialization
  2075. + */
  2076. +static void rt2800usb_write_beacon(struct queue_entry *entry)
  2077. +{
  2078. + struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  2079. + struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  2080. + unsigned int beacon_base;
  2081. + u32 reg;
  2082. +
  2083. + /*
  2084. + * Add the descriptor in front of the skb.
  2085. + */
  2086. + skb_push(entry->skb, entry->queue->desc_size);
  2087. + memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  2088. + skbdesc->desc = entry->skb->data;
  2089. +
  2090. + /*
  2091. + * Disable beaconing while we are reloading the beacon data,
  2092. + * otherwise we might be sending out invalid data.
  2093. + */
  2094. + rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  2095. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  2096. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  2097. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  2098. + rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  2099. +
  2100. + /*
  2101. + * Write entire beacon with descriptor to register.
  2102. + */
  2103. + beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  2104. + rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  2105. + USB_VENDOR_REQUEST_OUT, beacon_base,
  2106. + entry->skb->data, entry->skb->len,
  2107. + REGISTER_TIMEOUT32(entry->skb->len));
  2108. +
  2109. + /*
  2110. + * Clean up the beacon skb.
  2111. + */
  2112. + dev_kfree_skb(entry->skb);
  2113. + entry->skb = NULL;
  2114. +}
  2115. +
  2116. +static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
  2117. +{
  2118. + int length;
  2119. +
  2120. + /*
  2121. + * The length _must_ include 4 bytes padding,
  2122. + * it should always be multiple of 4,
  2123. + * but it must _not_ be a multiple of the USB packet size.
  2124. + */
  2125. + length = roundup(entry->skb->len + 4, 4);
  2126. + length += (4 * !(length % entry->queue->usb_maxpacket));
  2127. +
  2128. + return length;
  2129. +}
  2130. +
  2131. +static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  2132. + const enum data_queue_qid queue)
  2133. +{
  2134. + u32 reg;
  2135. +
  2136. + if (queue != QID_BEACON) {
  2137. + rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  2138. + return;
  2139. + }
  2140. +
  2141. + rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  2142. + if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
  2143. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 1);
  2144. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 1);
  2145. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  2146. + rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  2147. + }
  2148. +}
  2149. +
  2150. +/*
  2151. + * RX control handlers
  2152. + */
  2153. +static void rt2800usb_fill_rxdone(struct queue_entry *entry,
  2154. + struct rxdone_entry_desc *rxdesc)
  2155. +{
  2156. + struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  2157. + struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  2158. + __le32 *rxd = (__le32 *)entry->skb->data;
  2159. + __le32 *rxwi;
  2160. + u32 rxd0;
  2161. + u32 rxwi0;
  2162. + u32 rxwi1;
  2163. + u32 rxwi2;
  2164. + u32 rxwi3;
  2165. +
  2166. + /*
  2167. + * Copy descriptor to the skbdesc->desc buffer, making it safe from
  2168. + * moving of frame data in rt2x00usb.
  2169. + */
  2170. + memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  2171. + rxd = (__le32 *)skbdesc->desc;
  2172. + rxwi = &rxd[RXD_DESC_SIZE / sizeof(__le32)];
  2173. +
  2174. + /*
  2175. + * It is now safe to read the descriptor on all architectures.
  2176. + */
  2177. + rt2x00_desc_read(rxd, 0, &rxd0);
  2178. + rt2x00_desc_read(rxwi, 0, &rxwi0);
  2179. + rt2x00_desc_read(rxwi, 1, &rxwi1);
  2180. + rt2x00_desc_read(rxwi, 2, &rxwi2);
  2181. + rt2x00_desc_read(rxwi, 3, &rxwi3);
  2182. +
  2183. + if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
  2184. + rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  2185. +
  2186. + if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  2187. + rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
  2188. + rxdesc->cipher_status =
  2189. + rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
  2190. + }
  2191. +
  2192. + if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
  2193. + /*
  2194. + * Hardware has stripped IV/EIV data from 802.11 frame during
  2195. + * decryption. Unfortunately the descriptor doesn't contain
  2196. + * any fields with the EIV/IV data either, so they can't
  2197. + * be restored by rt2x00lib.
  2198. + */
  2199. + rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  2200. +
  2201. + if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  2202. + rxdesc->flags |= RX_FLAG_DECRYPTED;
  2203. + else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  2204. + rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  2205. + }
  2206. +
  2207. + if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
  2208. + rxdesc->dev_flags |= RXDONE_MY_BSS;
  2209. +
  2210. + if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
  2211. + rxdesc->flags |= RX_FLAG_SHORT_GI;
  2212. +
  2213. + if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
  2214. + rxdesc->flags |= RX_FLAG_40MHZ;
  2215. +
  2216. + /*
  2217. + * Detect RX rate, always use MCS as signal type.
  2218. + */
  2219. + rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  2220. + rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
  2221. + rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
  2222. +
  2223. + /*
  2224. + * Mask of 0x8 bit to remove the short preamble flag.
  2225. + */
  2226. + if (rxdesc->rate_mode == RATE_MODE_CCK)
  2227. + rxdesc->signal &= ~0x8;
  2228. +
  2229. + rxdesc->rssi =
  2230. + (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
  2231. + rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
  2232. +
  2233. + rxdesc->noise =
  2234. + (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
  2235. + rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
  2236. +
  2237. + rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  2238. +
  2239. + /*
  2240. + * Remove RXWI descriptor from start of buffer.
  2241. + */
  2242. + skb_pull(entry->skb, skbdesc->desc_len);
  2243. + skb_trim(entry->skb, rxdesc->size);
  2244. +}
  2245. +
  2246. +/*
  2247. + * Device probe functions.
  2248. + */
  2249. +static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  2250. +{
  2251. + u16 word;
  2252. + u8 *mac;
  2253. + u8 default_lna_gain;
  2254. +
  2255. + rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  2256. +
  2257. + /*
  2258. + * Start validation of the data that has been read.
  2259. + */
  2260. + mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  2261. + if (!is_valid_ether_addr(mac)) {
  2262. + DECLARE_MAC_BUF(macbuf);
  2263. +
  2264. + random_ether_addr(mac);
  2265. + EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  2266. + }
  2267. +
  2268. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  2269. + if (word == 0xffff) {
  2270. + rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  2271. + rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
  2272. + rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
  2273. + rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  2274. + EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  2275. + } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
  2276. + /*
  2277. + * There is a max of 2 RX streams for RT2860 series
  2278. + */
  2279. + if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
  2280. + rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
  2281. + rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  2282. + }
  2283. +
  2284. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  2285. + if (word == 0xffff) {
  2286. + rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
  2287. + rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
  2288. + rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  2289. + rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  2290. + rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  2291. + rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
  2292. + rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
  2293. + rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
  2294. + rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
  2295. + rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
  2296. + rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  2297. + EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  2298. + }
  2299. +
  2300. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  2301. + if ((word & 0x00ff) == 0x00ff) {
  2302. + rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  2303. + rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  2304. + LED_MODE_TXRX_ACTIVITY);
  2305. + rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  2306. + rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  2307. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
  2308. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
  2309. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
  2310. + EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  2311. + }
  2312. +
  2313. + /*
  2314. + * During the LNA validation we are going to use
  2315. + * lna0 as correct value. Note that EEPROM_LNA
  2316. + * is never validated.
  2317. + */
  2318. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  2319. + default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  2320. +
  2321. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  2322. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  2323. + rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  2324. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  2325. + rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  2326. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  2327. +
  2328. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  2329. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  2330. + rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  2331. + if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  2332. + rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  2333. + rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  2334. + default_lna_gain);
  2335. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  2336. +
  2337. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  2338. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  2339. + rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  2340. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  2341. + rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  2342. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  2343. +
  2344. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  2345. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  2346. + rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  2347. + if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  2348. + rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  2349. + rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  2350. + default_lna_gain);
  2351. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  2352. +
  2353. + return 0;
  2354. +}
  2355. +
  2356. +static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  2357. +{
  2358. + u32 reg;
  2359. + u16 value;
  2360. + u16 eeprom;
  2361. +
  2362. + /*
  2363. + * Read EEPROM word for configuration.
  2364. + */
  2365. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2366. +
  2367. + /*
  2368. + * Identify RF chipset.
  2369. + */
  2370. + value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  2371. + rt2x00usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  2372. + rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
  2373. +
  2374. + /*
  2375. + * The check for rt2860 is not a typo, some rt2870 hardware
  2376. + * identifies itself as rt2860 in the CSR register.
  2377. + */
  2378. + if ((rt2x00_get_field32(reg, MAC_CSR0_ASIC_VER) != 0x2860) &&
  2379. + (rt2x00_get_field32(reg, MAC_CSR0_ASIC_VER) != 0x2870) &&
  2380. + (rt2x00_get_field32(reg, MAC_CSR0_ASIC_VER) != 0x3070)) {
  2381. + ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  2382. + return -ENODEV;
  2383. + }
  2384. +
  2385. + if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
  2386. + !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
  2387. + !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
  2388. + !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
  2389. + !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
  2390. + !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2391. + ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  2392. + return -ENODEV;
  2393. + }
  2394. +
  2395. + /*
  2396. + * Read frequency offset and RF programming sequence.
  2397. + */
  2398. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  2399. + rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  2400. +
  2401. + /*
  2402. + * Read external LNA informations.
  2403. + */
  2404. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  2405. +
  2406. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  2407. + __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  2408. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  2409. + __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  2410. +
  2411. + /*
  2412. + * Detect if this device has an hardware controlled radio.
  2413. + */
  2414. +#ifdef CONFIG_RT2X00_LIB_RFKILL
  2415. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
  2416. + __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  2417. +#endif /* CONFIG_RT2X00_LIB_RFKILL */
  2418. +
  2419. + /*
  2420. + * Store led settings, for correct led behaviour.
  2421. + */
  2422. +#ifdef CONFIG_RT2X00_LIB_LEDS
  2423. + rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  2424. + rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  2425. + rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  2426. +
  2427. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
  2428. + &rt2x00dev->led_mcu_reg);
  2429. +#endif /* CONFIG_RT2X00_LIB_LEDS */
  2430. +
  2431. + return 0;
  2432. +}
  2433. +
  2434. +/*
  2435. + * RF value list for rt2870
  2436. + * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  2437. + */
  2438. +static const struct rf_channel rf_vals[] = {
  2439. + { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  2440. + { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  2441. + { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  2442. + { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  2443. + { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  2444. + { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  2445. + { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  2446. + { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  2447. + { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  2448. + { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  2449. + { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  2450. + { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  2451. + { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  2452. + { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  2453. +
  2454. + /* 802.11 UNI / HyperLan 2 */
  2455. + { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  2456. + { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  2457. + { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  2458. + { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  2459. + { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  2460. + { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  2461. + { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  2462. + { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  2463. + { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  2464. + { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  2465. + { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  2466. + { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  2467. +
  2468. + /* 802.11 HyperLan 2 */
  2469. + { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  2470. + { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  2471. + { 104, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed1a3 },
  2472. + { 108, 0x18402ecc, 0x184c0a32, 0x18578a55, 0x180ed193 },
  2473. + { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  2474. + { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  2475. + { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  2476. + { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  2477. + { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  2478. + { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  2479. + { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  2480. + { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  2481. + { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  2482. + { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  2483. + { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  2484. + { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  2485. +
  2486. + /* 802.11 UNII */
  2487. + { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  2488. + { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  2489. + { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  2490. + { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  2491. + { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  2492. + { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  2493. + { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  2494. +
  2495. + /* 802.11 Japan */
  2496. + { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  2497. + { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  2498. + { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  2499. + { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  2500. + { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  2501. + { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  2502. + { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  2503. +};
  2504. +
  2505. +/*
  2506. + * RF value list for rt3070
  2507. + * Supports: 2.4 GHz
  2508. + */
  2509. +static const struct rf_channel rf_vals_3070[] = {
  2510. + {1, 241, 2, 2 },
  2511. + {2, 241, 2, 7 },
  2512. + {3, 242, 2, 2 },
  2513. + {4, 242, 2, 7 },
  2514. + {5, 243, 2, 2 },
  2515. + {6, 243, 2, 7 },
  2516. + {7, 244, 2, 2 },
  2517. + {8, 244, 2, 7 },
  2518. + {9, 245, 2, 2 },
  2519. + {10, 245, 2, 7 },
  2520. + {11, 246, 2, 2 },
  2521. + {12, 246, 2, 7 },
  2522. + {13, 247, 2, 2 },
  2523. + {14, 248, 2, 4 },
  2524. +};
  2525. +
  2526. +static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  2527. +{
  2528. + struct hw_mode_spec *spec = &rt2x00dev->spec;
  2529. + struct channel_info *info;
  2530. + char *tx_power1;
  2531. + char *tx_power2;
  2532. + unsigned int i;
  2533. + u16 eeprom;
  2534. +
  2535. + /*
  2536. + * Initialize all hw fields.
  2537. + */
  2538. + rt2x00dev->hw->flags =
  2539. + IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  2540. + IEEE80211_HW_SIGNAL_DBM |
  2541. + IEEE80211_HW_SUPPORTS_PS |
  2542. + IEEE80211_HW_PS_NULLFUNC_STACK;
  2543. + rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
  2544. +
  2545. + SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  2546. + SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  2547. + rt2x00_eeprom_addr(rt2x00dev,
  2548. + EEPROM_MAC_ADDR_0));
  2549. +
  2550. + rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  2551. +
  2552. + /*
  2553. + * Initialize HT information.
  2554. + */
  2555. + spec->ht.ht_supported = true;
  2556. + spec->ht.cap =
  2557. + IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  2558. + IEEE80211_HT_CAP_GRN_FLD |
  2559. + IEEE80211_HT_CAP_SGI_20 |
  2560. + IEEE80211_HT_CAP_SGI_40 |
  2561. + IEEE80211_HT_CAP_TX_STBC |
  2562. + IEEE80211_HT_CAP_RX_STBC |
  2563. + IEEE80211_HT_CAP_PSMP_SUPPORT;
  2564. + spec->ht.ampdu_factor = 3;
  2565. + spec->ht.ampdu_density = 4;
  2566. + spec->ht.mcs.tx_params =
  2567. + IEEE80211_HT_MCS_TX_DEFINED |
  2568. + IEEE80211_HT_MCS_TX_RX_DIFF |
  2569. + ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
  2570. + IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  2571. +
  2572. + switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
  2573. + case 3:
  2574. + spec->ht.mcs.rx_mask[2] = 0xff;
  2575. + case 2:
  2576. + spec->ht.mcs.rx_mask[1] = 0xff;
  2577. + case 1:
  2578. + spec->ht.mcs.rx_mask[0] = 0xff;
  2579. + spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  2580. + break;
  2581. + }
  2582. +
  2583. + /*
  2584. + * Initialize hw_mode information.
  2585. + */
  2586. + spec->supported_bands = SUPPORT_BAND_2GHZ;
  2587. + spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  2588. +
  2589. + if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
  2590. + rt2x00_rf(&rt2x00dev->chip, RF2720)) {
  2591. + spec->num_channels = 14;
  2592. + spec->channels = rf_vals;
  2593. + } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
  2594. + rt2x00_rf(&rt2x00dev->chip, RF2750)) {
  2595. + spec->supported_bands |= SUPPORT_BAND_5GHZ;
  2596. + spec->num_channels = ARRAY_SIZE(rf_vals);
  2597. + spec->channels = rf_vals;
  2598. + } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
  2599. + rt2x00_rf(&rt2x00dev->chip, RF2020)) {
  2600. + spec->num_channels = ARRAY_SIZE(rf_vals_3070);
  2601. + spec->channels = rf_vals_3070;
  2602. + }
  2603. +
  2604. + /*
  2605. + * Create channel information array
  2606. + */
  2607. + info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  2608. + if (!info)
  2609. + return -ENOMEM;
  2610. +
  2611. + spec->channels_info = info;
  2612. +
  2613. + tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  2614. + tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  2615. +
  2616. + for (i = 0; i < 14; i++) {
  2617. + info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
  2618. + info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
  2619. + }
  2620. +
  2621. + if (spec->num_channels > 14) {
  2622. + tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  2623. + tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  2624. +
  2625. + for (i = 14; i < spec->num_channels; i++) {
  2626. + info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
  2627. + info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
  2628. + }
  2629. + }
  2630. +
  2631. + return 0;
  2632. +}
  2633. +
  2634. +static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  2635. +{
  2636. + int retval;
  2637. +
  2638. + /*
  2639. + * Allocate eeprom data.
  2640. + */
  2641. + retval = rt2800usb_validate_eeprom(rt2x00dev);
  2642. + if (retval)
  2643. + return retval;
  2644. +
  2645. + retval = rt2800usb_init_eeprom(rt2x00dev);
  2646. + if (retval)
  2647. + return retval;
  2648. +
  2649. + /*
  2650. + * Initialize hw specifications.
  2651. + */
  2652. + retval = rt2800usb_probe_hw_mode(rt2x00dev);
  2653. + if (retval)
  2654. + return retval;
  2655. +
  2656. + /*
  2657. + * This device requires firmware.
  2658. + */
  2659. + __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2660. + __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
  2661. + if (!modparam_nohwcrypt)
  2662. + __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  2663. +
  2664. + /*
  2665. + * Set the rssi offset.
  2666. + */
  2667. + rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2668. +
  2669. + return 0;
  2670. +}
  2671. +
  2672. +/*
  2673. + * IEEE80211 stack callback functions.
  2674. + */
  2675. +static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
  2676. + u32 *iv32, u16 *iv16)
  2677. +{
  2678. + struct rt2x00_dev *rt2x00dev = hw->priv;
  2679. + struct mac_iveiv_entry iveiv_entry;
  2680. + u32 offset;
  2681. +
  2682. + offset = MAC_IVEIV_ENTRY(hw_key_idx);
  2683. + rt2x00usb_register_multiread(rt2x00dev, offset,
  2684. + &iveiv_entry, sizeof(iveiv_entry));
  2685. +
  2686. + memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
  2687. + memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
  2688. +}
  2689. +
  2690. +static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2691. +{
  2692. + struct rt2x00_dev *rt2x00dev = hw->priv;
  2693. + u32 reg;
  2694. + bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  2695. +
  2696. + rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  2697. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  2698. + rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
  2699. +
  2700. + rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  2701. + rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  2702. + rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  2703. +
  2704. + rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  2705. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  2706. + rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  2707. +
  2708. + rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  2709. + rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  2710. + rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  2711. +
  2712. + rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  2713. + rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  2714. + rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  2715. +
  2716. + rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  2717. + rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  2718. + rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  2719. +
  2720. + rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  2721. + rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  2722. + rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  2723. +
  2724. + return 0;
  2725. +}
  2726. +
  2727. +static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  2728. + const struct ieee80211_tx_queue_params *params)
  2729. +{
  2730. + struct rt2x00_dev *rt2x00dev = hw->priv;
  2731. + struct data_queue *queue;
  2732. + struct rt2x00_field32 field;
  2733. + int retval;
  2734. + u32 reg;
  2735. + u32 offset;
  2736. +
  2737. + /*
  2738. + * First pass the configuration through rt2x00lib, that will
  2739. + * update the queue settings and validate the input. After that
  2740. + * we are free to update the registers based on the value
  2741. + * in the queue parameter.
  2742. + */
  2743. + retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  2744. + if (retval)
  2745. + return retval;
  2746. +
  2747. + /*
  2748. + * We only need to perform additional register initialization
  2749. + * for WMM queues/
  2750. + */
  2751. + if (queue_idx >= 4)
  2752. + return 0;
  2753. +
  2754. + queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  2755. +
  2756. + /* Update WMM TXOP register */
  2757. + offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  2758. + field.bit_offset = (queue_idx & 1) * 16;
  2759. + field.bit_mask = 0xffff << field.bit_offset;
  2760. +
  2761. + rt2x00usb_register_read(rt2x00dev, offset, &reg);
  2762. + rt2x00_set_field32(&reg, field, queue->txop);
  2763. + rt2x00usb_register_write(rt2x00dev, offset, reg);
  2764. +
  2765. + /* Update WMM registers */
  2766. + field.bit_offset = queue_idx * 4;
  2767. + field.bit_mask = 0xf << field.bit_offset;
  2768. +
  2769. + rt2x00usb_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  2770. + rt2x00_set_field32(&reg, field, queue->aifs);
  2771. + rt2x00usb_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  2772. +
  2773. + rt2x00usb_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  2774. + rt2x00_set_field32(&reg, field, queue->cw_min);
  2775. + rt2x00usb_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  2776. +
  2777. + rt2x00usb_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  2778. + rt2x00_set_field32(&reg, field, queue->cw_max);
  2779. + rt2x00usb_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  2780. +
  2781. + /* Update EDCA registers */
  2782. + offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  2783. +
  2784. + rt2x00usb_register_read(rt2x00dev, offset, &reg);
  2785. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  2786. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  2787. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  2788. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  2789. + rt2x00usb_register_write(rt2x00dev, offset, reg);
  2790. +
  2791. + return 0;
  2792. +}
  2793. +
  2794. +static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
  2795. +{
  2796. + struct rt2x00_dev *rt2x00dev = hw->priv;
  2797. + u64 tsf;
  2798. + u32 reg;
  2799. +
  2800. + rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  2801. + tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  2802. + rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  2803. + tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  2804. +
  2805. + return tsf;
  2806. +}
  2807. +
  2808. +static const struct ieee80211_ops rt2800usb_mac80211_ops = {
  2809. + .tx = rt2x00mac_tx,
  2810. + .start = rt2x00mac_start,
  2811. + .stop = rt2x00mac_stop,
  2812. + .add_interface = rt2x00mac_add_interface,
  2813. + .remove_interface = rt2x00mac_remove_interface,
  2814. + .config = rt2x00mac_config,
  2815. + .config_interface = rt2x00mac_config_interface,
  2816. + .configure_filter = rt2x00mac_configure_filter,
  2817. + .set_key = rt2x00mac_set_key,
  2818. + .get_stats = rt2x00mac_get_stats,
  2819. + .get_tkip_seq = rt2800usb_get_tkip_seq,
  2820. + .set_rts_threshold = rt2800usb_set_rts_threshold,
  2821. + .bss_info_changed = rt2x00mac_bss_info_changed,
  2822. + .conf_tx = rt2800usb_conf_tx,
  2823. + .get_tx_stats = rt2x00mac_get_tx_stats,
  2824. + .get_tsf = rt2800usb_get_tsf,
  2825. +};
  2826. +
  2827. +static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
  2828. + .probe_hw = rt2800usb_probe_hw,
  2829. + .get_firmware_name = rt2800usb_get_firmware_name,
  2830. + .check_firmware = rt2800usb_check_firmware,
  2831. + .load_firmware = rt2800usb_load_firmware,
  2832. + .initialize = rt2x00usb_initialize,
  2833. + .uninitialize = rt2x00usb_uninitialize,
  2834. + .clear_entry = rt2x00usb_clear_entry,
  2835. + .set_device_state = rt2800usb_set_device_state,
  2836. + .rfkill_poll = rt2800usb_rfkill_poll,
  2837. + .link_stats = rt2800usb_link_stats,
  2838. + .reset_tuner = rt2800usb_reset_tuner,
  2839. + .link_tuner = rt2800usb_link_tuner,
  2840. + .write_tx_desc = rt2800usb_write_tx_desc,
  2841. + .write_tx_data = rt2x00usb_write_tx_data,
  2842. + .write_beacon = rt2800usb_write_beacon,
  2843. + .get_tx_data_len = rt2800usb_get_tx_data_len,
  2844. + .kick_tx_queue = rt2800usb_kick_tx_queue,
  2845. + .kill_tx_queue = rt2x00usb_kill_tx_queue,
  2846. + .fill_rxdone = rt2800usb_fill_rxdone,
  2847. + .config_shared_key = rt2800usb_config_shared_key,
  2848. + .config_pairwise_key = rt2800usb_config_pairwise_key,
  2849. + .config_filter = rt2800usb_config_filter,
  2850. + .config_intf = rt2800usb_config_intf,
  2851. + .config_erp = rt2800usb_config_erp,
  2852. + .config_ant = rt2800usb_config_ant,
  2853. + .config = rt2800usb_config,
  2854. +};
  2855. +
  2856. +static const struct data_queue_desc rt2800usb_queue_rx = {
  2857. + .entry_num = RX_ENTRIES,
  2858. + .data_size = AGGREGATION_SIZE,
  2859. + .desc_size = RXD_DESC_SIZE + RXWI_DESC_SIZE,
  2860. + .priv_size = sizeof(struct queue_entry_priv_usb),
  2861. +};
  2862. +
  2863. +static const struct data_queue_desc rt2800usb_queue_tx = {
  2864. + .entry_num = TX_ENTRIES,
  2865. + .data_size = AGGREGATION_SIZE,
  2866. + .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2867. + .priv_size = sizeof(struct queue_entry_priv_usb),
  2868. +};
  2869. +
  2870. +static const struct data_queue_desc rt2800usb_queue_bcn = {
  2871. + .entry_num = 8 * BEACON_ENTRIES,
  2872. + .data_size = MGMT_FRAME_SIZE,
  2873. + .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
  2874. + .priv_size = sizeof(struct queue_entry_priv_usb),
  2875. +};
  2876. +
  2877. +static const struct rt2x00_ops rt2800usb_ops = {
  2878. + .name = KBUILD_MODNAME,
  2879. + .max_sta_intf = 1,
  2880. + .max_ap_intf = 8,
  2881. + .eeprom_size = EEPROM_SIZE,
  2882. + .rf_size = RF_SIZE,
  2883. + .tx_queues = NUM_TX_QUEUES,
  2884. + .rx = &rt2800usb_queue_rx,
  2885. + .tx = &rt2800usb_queue_tx,
  2886. + .bcn = &rt2800usb_queue_bcn,
  2887. + .lib = &rt2800usb_rt2x00_ops,
  2888. + .hw = &rt2800usb_mac80211_ops,
  2889. +#ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2890. + .debugfs = &rt2800usb_rt2x00debug,
  2891. +#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2892. +};
  2893. +
  2894. +/*
  2895. + * rt2800usb module information.
  2896. + */
  2897. +static struct usb_device_id rt2800usb_device_table[] = {
  2898. + /* Abocom */
  2899. + { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2900. + { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2901. + { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2902. + { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2903. + { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2904. + { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2905. + /* AirTies */
  2906. + { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
  2907. + /* Amigo */
  2908. + { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
  2909. + { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
  2910. + /* Amit */
  2911. + { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2912. + /* ASUS */
  2913. + { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
  2914. + { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
  2915. + { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
  2916. + { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
  2917. + { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
  2918. + /* AzureWave */
  2919. + { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
  2920. + { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
  2921. + { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
  2922. + /* Belkin */
  2923. + { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
  2924. + { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2925. + { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2926. + /* Buffalo */
  2927. + { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
  2928. + /* Conceptronic */
  2929. + { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2930. + { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
  2931. + { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2932. + { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
  2933. + { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
  2934. + { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2935. + { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
  2936. + { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
  2937. + /* Corega */
  2938. + { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2939. + { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2940. + { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2941. + { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
  2942. + { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
  2943. + /* D-Link */
  2944. + { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2945. + { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
  2946. + { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
  2947. + { USB_DEVICE(0x2001, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
  2948. + { USB_DEVICE(0x2001, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
  2949. + /* Edimax */
  2950. + { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
  2951. + { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
  2952. + { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
  2953. + /* EnGenius */
  2954. + { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
  2955. + { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
  2956. + { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
  2957. + /* Gemtek */
  2958. + { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
  2959. + /* Gigabyte */
  2960. + { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2961. + { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
  2962. + { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
  2963. + /* Hawking */
  2964. + { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
  2965. + { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
  2966. + { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
  2967. + { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
  2968. + /* LevelOne */
  2969. + { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
  2970. + { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
  2971. + /* Linksys */
  2972. + { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2973. + /* Logitec */
  2974. + { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
  2975. + { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
  2976. + { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
  2977. + /* Pegatron */
  2978. + { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
  2979. + /* Philips */
  2980. + { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
  2981. + /* Planex */
  2982. + { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
  2983. + { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
  2984. + { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
  2985. + /* Qcom */
  2986. + { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
  2987. + /* Quanta */
  2988. + { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
  2989. + /* Ralink */
  2990. + { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2991. + { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
  2992. + { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
  2993. + { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
  2994. + { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
  2995. + { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
  2996. + /* Samsung */
  2997. + { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
  2998. + /* Siemens */
  2999. + { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
  3000. + /* Sitecom */
  3001. + { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
  3002. + { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
  3003. + { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
  3004. + { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
  3005. + { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
  3006. + { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
  3007. + { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
  3008. + { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
  3009. + { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
  3010. + { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
  3011. + /* SMC */
  3012. + { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
  3013. + { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
  3014. + { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
  3015. + { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
  3016. + { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
  3017. + { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
  3018. + { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
  3019. + /* Sparklan */
  3020. + { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
  3021. + /* U-Media*/
  3022. + { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
  3023. + /* ZCOM */
  3024. + { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
  3025. + { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
  3026. + /* Zinwell */
  3027. + { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
  3028. + { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
  3029. + /* Zyxel */
  3030. + { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
  3031. + { 0, }
  3032. +};
  3033. +
  3034. +MODULE_AUTHOR(DRV_PROJECT);
  3035. +MODULE_VERSION(DRV_VERSION);
  3036. +MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
  3037. +MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
  3038. +MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
  3039. +MODULE_FIRMWARE(FIRMWARE_RT2870);
  3040. +MODULE_LICENSE("GPL");
  3041. +
  3042. +static struct usb_driver rt2800usb_driver = {
  3043. + .name = KBUILD_MODNAME,
  3044. + .id_table = rt2800usb_device_table,
  3045. + .probe = rt2x00usb_probe,
  3046. + .disconnect = rt2x00usb_disconnect,
  3047. + .suspend = rt2x00usb_suspend,
  3048. + .resume = rt2x00usb_resume,
  3049. +};
  3050. +
  3051. +static int __init rt2800usb_init(void)
  3052. +{
  3053. + return usb_register(&rt2800usb_driver);
  3054. +}
  3055. +
  3056. +static void __exit rt2800usb_exit(void)
  3057. +{
  3058. + usb_deregister(&rt2800usb_driver);
  3059. +}
  3060. +
  3061. +module_init(rt2800usb_init);
  3062. +module_exit(rt2800usb_exit);
  3063. --- /dev/null
  3064. +++ b/drivers/net/wireless/rt2x00/rt2800usb.h
  3065. @@ -0,0 +1,1934 @@
  3066. +/*
  3067. + Copyright (C) 2004 - 2009 rt2x00 SourceForge Project
  3068. + <http://rt2x00.serialmonkey.com>
  3069. +
  3070. + This program is free software; you can redistribute it and/or modify
  3071. + it under the terms of the GNU General Public License as published by
  3072. + the Free Software Foundation; either version 2 of the License, or
  3073. + (at your option) any later version.
  3074. +
  3075. + This program is distributed in the hope that it will be useful,
  3076. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3077. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3078. + GNU General Public License for more details.
  3079. +
  3080. + You should have received a copy of the GNU General Public License
  3081. + along with this program; if not, write to the
  3082. + Free Software Foundation, Inc.,
  3083. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  3084. + */
  3085. +
  3086. +/*
  3087. + Module: rt2800usb
  3088. + Abstract: Data structures and registers for the rt2800usb module.
  3089. + Supported chipsets: RT2800U.
  3090. + */
  3091. +
  3092. +#ifndef RT2800USB_H
  3093. +#define RT2800USB_H
  3094. +
  3095. +/*
  3096. + * RF chip defines.
  3097. + *
  3098. + * RF2820 2.4G 2T3R
  3099. + * RF2850 2.4G/5G 2T3R
  3100. + * RF2720 2.4G 1T2R
  3101. + * RF2750 2.4G/5G 1T2R
  3102. + * RF3020 2.4G 1T1R
  3103. + * RF2020 2.4G B/G
  3104. + */
  3105. +#define RF2820 0x0001
  3106. +#define RF2850 0x0002
  3107. +#define RF2720 0x0003
  3108. +#define RF2750 0x0004
  3109. +#define RF3020 0x0005
  3110. +#define RF2020 0x0006
  3111. +
  3112. +/*
  3113. + * RT2870 version
  3114. + */
  3115. +#define RT2860C_VERSION 0x28600100
  3116. +#define RT2860D_VERSION 0x28600101
  3117. +#define RT2880E_VERSION 0x28720200
  3118. +#define RT2883_VERSION 0x28830300
  3119. +#define RT3070_VERSION 0x30700200
  3120. +
  3121. +/*
  3122. + * Signal information.
  3123. + * Defaul offset is required for RSSI <-> dBm conversion.
  3124. + */
  3125. +#define DEFAULT_RSSI_OFFSET 120 /* FIXME */
  3126. +
  3127. +/*
  3128. + * Register layout information.
  3129. + */
  3130. +#define CSR_REG_BASE 0x1000
  3131. +#define CSR_REG_SIZE 0x0800
  3132. +#define EEPROM_BASE 0x0000
  3133. +#define EEPROM_SIZE 0x0110
  3134. +#define BBP_BASE 0x0000
  3135. +#define BBP_SIZE 0x0080
  3136. +#define RF_BASE 0x0004
  3137. +#define RF_SIZE 0x0010
  3138. +
  3139. +/*
  3140. + * Number of TX queues.
  3141. + */
  3142. +#define NUM_TX_QUEUES 4
  3143. +
  3144. +/*
  3145. + * USB registers.
  3146. + */
  3147. +
  3148. +/*
  3149. + * HOST-MCU shared memory
  3150. + */
  3151. +#define HOST_CMD_CSR 0x0404
  3152. +#define HOST_CMD_CSR_HOST_COMMAND FIELD32(0x000000ff)
  3153. +
  3154. +/*
  3155. + * INT_SOURCE_CSR: Interrupt source register.
  3156. + * Write one to clear corresponding bit.
  3157. + * TX_FIFO_STATUS: FIFO Statistics is full, sw should read 0x171c
  3158. + */
  3159. +#define INT_SOURCE_CSR 0x0200
  3160. +#define INT_SOURCE_CSR_RXDELAYINT FIELD32(0x00000001)
  3161. +#define INT_SOURCE_CSR_TXDELAYINT FIELD32(0x00000002)
  3162. +#define INT_SOURCE_CSR_RX_DONE FIELD32(0x00000004)
  3163. +#define INT_SOURCE_CSR_AC0_DMA_DONE FIELD32(0x00000008)
  3164. +#define INT_SOURCE_CSR_AC1_DMA_DONE FIELD32(0x00000010)
  3165. +#define INT_SOURCE_CSR_AC2_DMA_DONE FIELD32(0x00000020)
  3166. +#define INT_SOURCE_CSR_AC3_DMA_DONE FIELD32(0x00000040)
  3167. +#define INT_SOURCE_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
  3168. +#define INT_SOURCE_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
  3169. +#define INT_SOURCE_CSR_MCU_COMMAND FIELD32(0x00000200)
  3170. +#define INT_SOURCE_CSR_RXTX_COHERENT FIELD32(0x00000400)
  3171. +#define INT_SOURCE_CSR_TBTT FIELD32(0x00000800)
  3172. +#define INT_SOURCE_CSR_PRE_TBTT FIELD32(0x00001000)
  3173. +#define INT_SOURCE_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
  3174. +#define INT_SOURCE_CSR_AUTO_WAKEUP FIELD32(0x00004000)
  3175. +#define INT_SOURCE_CSR_GPTIMER FIELD32(0x00008000)
  3176. +#define INT_SOURCE_CSR_RX_COHERENT FIELD32(0x00010000)
  3177. +#define INT_SOURCE_CSR_TX_COHERENT FIELD32(0x00020000)
  3178. +
  3179. +/*
  3180. + * INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF.
  3181. + */
  3182. +#define INT_MASK_CSR 0x0204
  3183. +#define INT_MASK_CSR_RXDELAYINT FIELD32(0x00000001)
  3184. +#define INT_MASK_CSR_TXDELAYINT FIELD32(0x00000002)
  3185. +#define INT_MASK_CSR_RX_DONE FIELD32(0x00000004)
  3186. +#define INT_MASK_CSR_AC0_DMA_DONE FIELD32(0x00000008)
  3187. +#define INT_MASK_CSR_AC1_DMA_DONE FIELD32(0x00000010)
  3188. +#define INT_MASK_CSR_AC2_DMA_DONE FIELD32(0x00000020)
  3189. +#define INT_MASK_CSR_AC3_DMA_DONE FIELD32(0x00000040)
  3190. +#define INT_MASK_CSR_HCCA_DMA_DONE FIELD32(0x00000080)
  3191. +#define INT_MASK_CSR_MGMT_DMA_DONE FIELD32(0x00000100)
  3192. +#define INT_MASK_CSR_MCU_COMMAND FIELD32(0x00000200)
  3193. +#define INT_MASK_CSR_RXTX_COHERENT FIELD32(0x00000400)
  3194. +#define INT_MASK_CSR_TBTT FIELD32(0x00000800)
  3195. +#define INT_MASK_CSR_PRE_TBTT FIELD32(0x00001000)
  3196. +#define INT_MASK_CSR_TX_FIFO_STATUS FIELD32(0x00002000)
  3197. +#define INT_MASK_CSR_AUTO_WAKEUP FIELD32(0x00004000)
  3198. +#define INT_MASK_CSR_GPTIMER FIELD32(0x00008000)
  3199. +#define INT_MASK_CSR_RX_COHERENT FIELD32(0x00010000)
  3200. +#define INT_MASK_CSR_TX_COHERENT FIELD32(0x00020000)
  3201. +
  3202. +/*
  3203. + * WPDMA_GLO_CFG
  3204. + */
  3205. +#define WPDMA_GLO_CFG 0x0208
  3206. +#define WPDMA_GLO_CFG_ENABLE_TX_DMA FIELD32(0x00000001)
  3207. +#define WPDMA_GLO_CFG_TX_DMA_BUSY FIELD32(0x00000002)
  3208. +#define WPDMA_GLO_CFG_ENABLE_RX_DMA FIELD32(0x00000004)
  3209. +#define WPDMA_GLO_CFG_RX_DMA_BUSY FIELD32(0x00000008)
  3210. +#define WPDMA_GLO_CFG_WP_DMA_BURST_SIZE FIELD32(0x00000030)
  3211. +#define WPDMA_GLO_CFG_TX_WRITEBACK_DONE FIELD32(0x00000040)
  3212. +#define WPDMA_GLO_CFG_BIG_ENDIAN FIELD32(0x00000080)
  3213. +#define WPDMA_GLO_CFG_RX_HDR_SCATTER FIELD32(0x0000ff00)
  3214. +#define WPDMA_GLO_CFG_HDR_SEG_LEN FIELD32(0xffff0000)
  3215. +
  3216. +/*
  3217. + * WPDMA_RST_IDX
  3218. + */
  3219. +#define WPDMA_RST_IDX 0x020c
  3220. +#define WPDMA_RST_IDX_DTX_IDX0 FIELD32(0x00000001)
  3221. +#define WPDMA_RST_IDX_DTX_IDX1 FIELD32(0x00000002)
  3222. +#define WPDMA_RST_IDX_DTX_IDX2 FIELD32(0x00000004)
  3223. +#define WPDMA_RST_IDX_DTX_IDX3 FIELD32(0x00000008)
  3224. +#define WPDMA_RST_IDX_DTX_IDX4 FIELD32(0x00000010)
  3225. +#define WPDMA_RST_IDX_DTX_IDX5 FIELD32(0x00000020)
  3226. +#define WPDMA_RST_IDX_DRX_IDX0 FIELD32(0x00010000)
  3227. +
  3228. +/*
  3229. + * DELAY_INT_CFG
  3230. + */
  3231. +#define DELAY_INT_CFG 0x0210
  3232. +#define DELAY_INT_CFG_RXMAX_PTIME FIELD32(0x000000ff)
  3233. +#define DELAY_INT_CFG_RXMAX_PINT FIELD32(0x00007f00)
  3234. +#define DELAY_INT_CFG_RXDLY_INT_EN FIELD32(0x00008000)
  3235. +#define DELAY_INT_CFG_TXMAX_PTIME FIELD32(0x00ff0000)
  3236. +#define DELAY_INT_CFG_TXMAX_PINT FIELD32(0x7f000000)
  3237. +#define DELAY_INT_CFG_TXDLY_INT_EN FIELD32(0x80000000)
  3238. +
  3239. +/*
  3240. + * WMM_AIFSN_CFG: Aifsn for each EDCA AC
  3241. + * AIFSN0: AC_BE
  3242. + * AIFSN1: AC_BK
  3243. + * AIFSN1: AC_VI
  3244. + * AIFSN1: AC_VO
  3245. + */
  3246. +#define WMM_AIFSN_CFG 0x0214
  3247. +#define WMM_AIFSN_CFG_AIFSN0 FIELD32(0x0000000f)
  3248. +#define WMM_AIFSN_CFG_AIFSN1 FIELD32(0x000000f0)
  3249. +#define WMM_AIFSN_CFG_AIFSN2 FIELD32(0x00000f00)
  3250. +#define WMM_AIFSN_CFG_AIFSN3 FIELD32(0x0000f000)
  3251. +
  3252. +/*
  3253. + * WMM_CWMIN_CSR: CWmin for each EDCA AC
  3254. + * CWMIN0: AC_BE
  3255. + * CWMIN1: AC_BK
  3256. + * CWMIN1: AC_VI
  3257. + * CWMIN1: AC_VO
  3258. + */
  3259. +#define WMM_CWMIN_CFG 0x0218
  3260. +#define WMM_CWMIN_CFG_CWMIN0 FIELD32(0x0000000f)
  3261. +#define WMM_CWMIN_CFG_CWMIN1 FIELD32(0x000000f0)
  3262. +#define WMM_CWMIN_CFG_CWMIN2 FIELD32(0x00000f00)
  3263. +#define WMM_CWMIN_CFG_CWMIN3 FIELD32(0x0000f000)
  3264. +
  3265. +/*
  3266. + * WMM_CWMAX_CSR: CWmax for each EDCA AC
  3267. + * CWMAX0: AC_BE
  3268. + * CWMAX1: AC_BK
  3269. + * CWMAX1: AC_VI
  3270. + * CWMAX1: AC_VO
  3271. + */
  3272. +#define WMM_CWMAX_CFG 0x021c
  3273. +#define WMM_CWMAX_CFG_CWMAX0 FIELD32(0x0000000f)
  3274. +#define WMM_CWMAX_CFG_CWMAX1 FIELD32(0x000000f0)
  3275. +#define WMM_CWMAX_CFG_CWMAX2 FIELD32(0x00000f00)
  3276. +#define WMM_CWMAX_CFG_CWMAX3 FIELD32(0x0000f000)
  3277. +
  3278. +/*
  3279. + * AC_TXOP0: AC_BK/AC_BE TXOP register
  3280. + * AC0TXOP: AC_BK in unit of 32us
  3281. + * AC1TXOP: AC_BE in unit of 32us
  3282. + */
  3283. +#define WMM_TXOP0_CFG 0x0220
  3284. +#define WMM_TXOP0_CFG_AC0TXOP FIELD32(0x0000ffff)
  3285. +#define WMM_TXOP0_CFG_AC1TXOP FIELD32(0xffff0000)
  3286. +
  3287. +/*
  3288. + * AC_TXOP1: AC_VO/AC_VI TXOP register
  3289. + * AC2TXOP: AC_VI in unit of 32us
  3290. + * AC3TXOP: AC_VO in unit of 32us
  3291. + */
  3292. +#define WMM_TXOP1_CFG 0x0224
  3293. +#define WMM_TXOP1_CFG_AC2TXOP FIELD32(0x0000ffff)
  3294. +#define WMM_TXOP1_CFG_AC3TXOP FIELD32(0xffff0000)
  3295. +
  3296. +/*
  3297. + * GPIO_CTRL_CFG:
  3298. + */
  3299. +#define GPIO_CTRL_CFG 0x0228
  3300. +#define GPIO_CTRL_CFG_BIT0 FIELD32(0x00000001)
  3301. +#define GPIO_CTRL_CFG_BIT1 FIELD32(0x00000002)
  3302. +#define GPIO_CTRL_CFG_BIT2 FIELD32(0x00000004)
  3303. +#define GPIO_CTRL_CFG_BIT3 FIELD32(0x00000008)
  3304. +#define GPIO_CTRL_CFG_BIT4 FIELD32(0x00000010)
  3305. +#define GPIO_CTRL_CFG_BIT5 FIELD32(0x00000020)
  3306. +#define GPIO_CTRL_CFG_BIT6 FIELD32(0x00000040)
  3307. +#define GPIO_CTRL_CFG_BIT7 FIELD32(0x00000080)
  3308. +#define GPIO_CTRL_CFG_BIT8 FIELD32(0x00000100)
  3309. +
  3310. +/*
  3311. + * MCU_CMD_CFG
  3312. + */
  3313. +#define MCU_CMD_CFG 0x022c
  3314. +
  3315. +/*
  3316. + * AC_BK register offsets
  3317. + */
  3318. +#define TX_BASE_PTR0 0x0230
  3319. +#define TX_MAX_CNT0 0x0234
  3320. +#define TX_CTX_IDX0 0x0238
  3321. +#define TX_DTX_IDX0 0x023c
  3322. +
  3323. +/*
  3324. + * AC_BE register offsets
  3325. + */
  3326. +#define TX_BASE_PTR1 0x0240
  3327. +#define TX_MAX_CNT1 0x0244
  3328. +#define TX_CTX_IDX1 0x0248
  3329. +#define TX_DTX_IDX1 0x024c
  3330. +
  3331. +/*
  3332. + * AC_VI register offsets
  3333. + */
  3334. +#define TX_BASE_PTR2 0x0250
  3335. +#define TX_MAX_CNT2 0x0254
  3336. +#define TX_CTX_IDX2 0x0258
  3337. +#define TX_DTX_IDX2 0x025c
  3338. +
  3339. +/*
  3340. + * AC_VO register offsets
  3341. + */
  3342. +#define TX_BASE_PTR3 0x0260
  3343. +#define TX_MAX_CNT3 0x0264
  3344. +#define TX_CTX_IDX3 0x0268
  3345. +#define TX_DTX_IDX3 0x026c
  3346. +
  3347. +/*
  3348. + * HCCA register offsets
  3349. + */
  3350. +#define TX_BASE_PTR4 0x0270
  3351. +#define TX_MAX_CNT4 0x0274
  3352. +#define TX_CTX_IDX4 0x0278
  3353. +#define TX_DTX_IDX4 0x027c
  3354. +
  3355. +/*
  3356. + * MGMT register offsets
  3357. + */
  3358. +#define TX_BASE_PTR5 0x0280
  3359. +#define TX_MAX_CNT5 0x0284
  3360. +#define TX_CTX_IDX5 0x0288
  3361. +#define TX_DTX_IDX5 0x028c
  3362. +
  3363. +/*
  3364. + * RX register offsets
  3365. + */
  3366. +#define RX_BASE_PTR 0x0290
  3367. +#define RX_MAX_CNT 0x0294
  3368. +#define RX_CRX_IDX 0x0298
  3369. +#define RX_DRX_IDX 0x029c
  3370. +
  3371. +/*
  3372. + * USB_DMA_CFG
  3373. + * RX_BULK_AGG_TIMEOUT: Rx Bulk Aggregation TimeOut in unit of 33ns.
  3374. + * RX_BULK_AGG_LIMIT: Rx Bulk Aggregation Limit in unit of 256 bytes.
  3375. + * PHY_CLEAR: phy watch dog enable.
  3376. + * TX_CLEAR: Clear USB DMA TX path.
  3377. + * TXOP_HALT: Halt TXOP count down when TX buffer is full.
  3378. + * RX_BULK_AGG_EN: Enable Rx Bulk Aggregation.
  3379. + * RX_BULK_EN: Enable USB DMA Rx.
  3380. + * TX_BULK_EN: Enable USB DMA Tx.
  3381. + * EP_OUT_VALID: OUT endpoint data valid.
  3382. + * RX_BUSY: USB DMA RX FSM busy.
  3383. + * TX_BUSY: USB DMA TX FSM busy.
  3384. + */
  3385. +#define USB_DMA_CFG 0x02a0
  3386. +#define USB_DMA_CFG_RX_BULK_AGG_TIMEOUT FIELD32(0x000000ff)
  3387. +#define USB_DMA_CFG_RX_BULK_AGG_LIMIT FIELD32(0x0000ff00)
  3388. +#define USB_DMA_CFG_PHY_CLEAR FIELD32(0x00010000)
  3389. +#define USB_DMA_CFG_TX_CLEAR FIELD32(0x00080000)
  3390. +#define USB_DMA_CFG_TXOP_HALT FIELD32(0x00100000)
  3391. +#define USB_DMA_CFG_RX_BULK_AGG_EN FIELD32(0x00200000)
  3392. +#define USB_DMA_CFG_RX_BULK_EN FIELD32(0x00400000)
  3393. +#define USB_DMA_CFG_TX_BULK_EN FIELD32(0x00800000)
  3394. +#define USB_DMA_CFG_EP_OUT_VALID FIELD32(0x3f000000)
  3395. +#define USB_DMA_CFG_RX_BUSY FIELD32(0x40000000)
  3396. +#define USB_DMA_CFG_TX_BUSY FIELD32(0x80000000)
  3397. +
  3398. +/*
  3399. + * USB_CYC_CFG
  3400. + */
  3401. +#define USB_CYC_CFG 0x02a4
  3402. +#define USB_CYC_CFG_CLOCK_CYCLE FIELD32(0x000000ff)
  3403. +
  3404. +/*
  3405. + * PBF_SYS_CTRL
  3406. + * HOST_RAM_WRITE: enable Host program ram write selection
  3407. + */
  3408. +#define PBF_SYS_CTRL 0x0400
  3409. +#define PBF_SYS_CTRL_READY FIELD32(0x00000080)
  3410. +#define PBF_SYS_CTRL_HOST_RAM_WRITE FIELD32(0x00010000)
  3411. +
  3412. +/*
  3413. + * PBF registers
  3414. + * Most are for debug. Driver doesn't touch PBF register.
  3415. + */
  3416. +#define PBF_CFG 0x0408
  3417. +#define PBF_MAX_PCNT 0x040c
  3418. +#define PBF_CTRL 0x0410
  3419. +#define PBF_INT_STA 0x0414
  3420. +#define PBF_INT_ENA 0x0418
  3421. +
  3422. +/*
  3423. + * BCN_OFFSET0:
  3424. + */
  3425. +#define BCN_OFFSET0 0x042c
  3426. +#define BCN_OFFSET0_BCN0 FIELD32(0x000000ff)
  3427. +#define BCN_OFFSET0_BCN1 FIELD32(0x0000ff00)
  3428. +#define BCN_OFFSET0_BCN2 FIELD32(0x00ff0000)
  3429. +#define BCN_OFFSET0_BCN3 FIELD32(0xff000000)
  3430. +
  3431. +/*
  3432. + * BCN_OFFSET1:
  3433. + */
  3434. +#define BCN_OFFSET1 0x0430
  3435. +#define BCN_OFFSET1_BCN4 FIELD32(0x000000ff)
  3436. +#define BCN_OFFSET1_BCN5 FIELD32(0x0000ff00)
  3437. +#define BCN_OFFSET1_BCN6 FIELD32(0x00ff0000)
  3438. +#define BCN_OFFSET1_BCN7 FIELD32(0xff000000)
  3439. +
  3440. +/*
  3441. + * PBF registers
  3442. + * Most are for debug. Driver doesn't touch PBF register.
  3443. + */
  3444. +#define TXRXQ_PCNT 0x0438
  3445. +#define PBF_DBG 0x043c
  3446. +
  3447. +/*
  3448. + * RF registers
  3449. + */
  3450. +#define RF_CSR_CFG 0x0500
  3451. +#define RF_CSR_CFG_DATA FIELD32(0x000000ff)
  3452. +#define RF_CSR_CFG_REGNUM FIELD32(0x00001f00)
  3453. +#define RF_CSR_CFG_WRITE FIELD32(0x00010000)
  3454. +#define RF_CSR_CFG_BUSY FIELD32(0x00020000)
  3455. +
  3456. +/*
  3457. + * MAC Control/Status Registers(CSR).
  3458. + * Some values are set in TU, whereas 1 TU == 1024 us.
  3459. + */
  3460. +
  3461. +/*
  3462. + * MAC_CSR0: ASIC revision number.
  3463. + * ASIC_REV: 0
  3464. + * ASIC_VER: 2870
  3465. + */
  3466. +#define MAC_CSR0 0x1000
  3467. +#define MAC_CSR0_ASIC_REV FIELD32(0x0000ffff)
  3468. +#define MAC_CSR0_ASIC_VER FIELD32(0xffff0000)
  3469. +
  3470. +/*
  3471. + * MAC_SYS_CTRL:
  3472. + */
  3473. +#define MAC_SYS_CTRL 0x1004
  3474. +#define MAC_SYS_CTRL_RESET_CSR FIELD32(0x00000001)
  3475. +#define MAC_SYS_CTRL_RESET_BBP FIELD32(0x00000002)
  3476. +#define MAC_SYS_CTRL_ENABLE_TX FIELD32(0x00000004)
  3477. +#define MAC_SYS_CTRL_ENABLE_RX FIELD32(0x00000008)
  3478. +#define MAC_SYS_CTRL_CONTINUOUS_TX FIELD32(0x00000010)
  3479. +#define MAC_SYS_CTRL_LOOPBACK FIELD32(0x00000020)
  3480. +#define MAC_SYS_CTRL_WLAN_HALT FIELD32(0x00000040)
  3481. +#define MAC_SYS_CTRL_RX_TIMESTAMP FIELD32(0x00000080)
  3482. +
  3483. +/*
  3484. + * MAC_ADDR_DW0: STA MAC register 0
  3485. + */
  3486. +#define MAC_ADDR_DW0 0x1008
  3487. +#define MAC_ADDR_DW0_BYTE0 FIELD32(0x000000ff)
  3488. +#define MAC_ADDR_DW0_BYTE1 FIELD32(0x0000ff00)
  3489. +#define MAC_ADDR_DW0_BYTE2 FIELD32(0x00ff0000)
  3490. +#define MAC_ADDR_DW0_BYTE3 FIELD32(0xff000000)
  3491. +
  3492. +/*
  3493. + * MAC_ADDR_DW1: STA MAC register 1
  3494. + * UNICAST_TO_ME_MASK:
  3495. + * Used to mask off bits from byte 5 of the MAC address
  3496. + * to determine the UNICAST_TO_ME bit for RX frames.
  3497. + * The full mask is complemented by BSS_ID_MASK:
  3498. + * MASK = BSS_ID_MASK & UNICAST_TO_ME_MASK
  3499. + */
  3500. +#define MAC_ADDR_DW1 0x100c
  3501. +#define MAC_ADDR_DW1_BYTE4 FIELD32(0x000000ff)
  3502. +#define MAC_ADDR_DW1_BYTE5 FIELD32(0x0000ff00)
  3503. +#define MAC_ADDR_DW1_UNICAST_TO_ME_MASK FIELD32(0x00ff0000)
  3504. +
  3505. +/*
  3506. + * MAC_BSSID_DW0: BSSID register 0
  3507. + */
  3508. +#define MAC_BSSID_DW0 0x1010
  3509. +#define MAC_BSSID_DW0_BYTE0 FIELD32(0x000000ff)
  3510. +#define MAC_BSSID_DW0_BYTE1 FIELD32(0x0000ff00)
  3511. +#define MAC_BSSID_DW0_BYTE2 FIELD32(0x00ff0000)
  3512. +#define MAC_BSSID_DW0_BYTE3 FIELD32(0xff000000)
  3513. +
  3514. +/*
  3515. + * MAC_BSSID_DW1: BSSID register 1
  3516. + * BSS_ID_MASK:
  3517. + * 0: 1-BSSID mode (BSS index = 0)
  3518. + * 1: 2-BSSID mode (BSS index: Byte5, bit 0)
  3519. + * 2: 4-BSSID mode (BSS index: byte5, bit 0 - 1)
  3520. + * 3: 8-BSSID mode (BSS index: byte5, bit 0 - 2)
  3521. + * This mask is used to mask off bits 0, 1 and 2 of byte 5 of the
  3522. + * BSSID. This will make sure that those bits will be ignored
  3523. + * when determining the MY_BSS of RX frames.
  3524. + */
  3525. +#define MAC_BSSID_DW1 0x1014
  3526. +#define MAC_BSSID_DW1_BYTE4 FIELD32(0x000000ff)
  3527. +#define MAC_BSSID_DW1_BYTE5 FIELD32(0x0000ff00)
  3528. +#define MAC_BSSID_DW1_BSS_ID_MASK FIELD32(0x00030000)
  3529. +#define MAC_BSSID_DW1_BSS_BCN_NUM FIELD32(0x001c0000)
  3530. +
  3531. +/*
  3532. + * MAX_LEN_CFG: Maximum frame length register.
  3533. + * MAX_MPDU: rt2860b max 16k bytes
  3534. + * MAX_PSDU: Maximum PSDU length
  3535. + * (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16
  3536. + */
  3537. +#define MAX_LEN_CFG 0x1018
  3538. +#define MAX_LEN_CFG_MAX_MPDU FIELD32(0x00000fff)
  3539. +#define MAX_LEN_CFG_MAX_PSDU FIELD32(0x00003000)
  3540. +#define MAX_LEN_CFG_MIN_PSDU FIELD32(0x0000c000)
  3541. +#define MAX_LEN_CFG_MIN_MPDU FIELD32(0x000f0000)
  3542. +
  3543. +/*
  3544. + * BBP_CSR_CFG: BBP serial control register
  3545. + * VALUE: Register value to program into BBP
  3546. + * REG_NUM: Selected BBP register
  3547. + * READ_CONTROL: 0 write BBP, 1 read BBP
  3548. + * BUSY: ASIC is busy executing BBP commands
  3549. + * BBP_PAR_DUR: 0 4 MAC clocks, 1 8 MAC clocks
  3550. + * BBP_RW_MODE: 0 serial, 1 paralell
  3551. + */
  3552. +#define BBP_CSR_CFG 0x101c
  3553. +#define BBP_CSR_CFG_VALUE FIELD32(0x000000ff)
  3554. +#define BBP_CSR_CFG_REGNUM FIELD32(0x0000ff00)
  3555. +#define BBP_CSR_CFG_READ_CONTROL FIELD32(0x00010000)
  3556. +#define BBP_CSR_CFG_BUSY FIELD32(0x00020000)
  3557. +#define BBP_CSR_CFG_BBP_PAR_DUR FIELD32(0x00040000)
  3558. +#define BBP_CSR_CFG_BBP_RW_MODE FIELD32(0x00080000)
  3559. +
  3560. +/*
  3561. + * RF_CSR_CFG0: RF control register
  3562. + * REGID_AND_VALUE: Register value to program into RF
  3563. + * BITWIDTH: Selected RF register
  3564. + * STANDBYMODE: 0 high when standby, 1 low when standby
  3565. + * SEL: 0 RF_LE0 activate, 1 RF_LE1 activate
  3566. + * BUSY: ASIC is busy executing RF commands
  3567. + */
  3568. +#define RF_CSR_CFG0 0x1020
  3569. +#define RF_CSR_CFG0_REGID_AND_VALUE FIELD32(0x00ffffff)
  3570. +#define RF_CSR_CFG0_BITWIDTH FIELD32(0x1f000000)
  3571. +#define RF_CSR_CFG0_REG_VALUE_BW FIELD32(0x1fffffff)
  3572. +#define RF_CSR_CFG0_STANDBYMODE FIELD32(0x20000000)
  3573. +#define RF_CSR_CFG0_SEL FIELD32(0x40000000)
  3574. +#define RF_CSR_CFG0_BUSY FIELD32(0x80000000)
  3575. +
  3576. +/*
  3577. + * RF_CSR_CFG1: RF control register
  3578. + * REGID_AND_VALUE: Register value to program into RF
  3579. + * RFGAP: Gap between BB_CONTROL_RF and RF_LE
  3580. + * 0: 3 system clock cycle (37.5usec)
  3581. + * 1: 5 system clock cycle (62.5usec)
  3582. + */
  3583. +#define RF_CSR_CFG1 0x1024
  3584. +#define RF_CSR_CFG1_REGID_AND_VALUE FIELD32(0x00ffffff)
  3585. +#define RF_CSR_CFG1_RFGAP FIELD32(0x1f000000)
  3586. +
  3587. +/*
  3588. + * RF_CSR_CFG2: RF control register
  3589. + * VALUE: Register value to program into RF
  3590. + * RFGAP: Gap between BB_CONTROL_RF and RF_LE
  3591. + * 0: 3 system clock cycle (37.5usec)
  3592. + * 1: 5 system clock cycle (62.5usec)
  3593. + */
  3594. +#define RF_CSR_CFG2 0x1028
  3595. +#define RF_CSR_CFG2_VALUE FIELD32(0x00ffffff)
  3596. +
  3597. +/*
  3598. + * LED_CFG: LED control
  3599. + * color LED's:
  3600. + * 0: off
  3601. + * 1: blinking upon TX2
  3602. + * 2: periodic slow blinking
  3603. + * 3: always on
  3604. + * LED polarity:
  3605. + * 0: active low
  3606. + * 1: active high
  3607. + */
  3608. +#define LED_CFG 0x102c
  3609. +#define LED_CFG_ON_PERIOD FIELD32(0x000000ff)
  3610. +#define LED_CFG_OFF_PERIOD FIELD32(0x0000ff00)
  3611. +#define LED_CFG_SLOW_BLINK_PERIOD FIELD32(0x003f0000)
  3612. +#define LED_CFG_R_LED_MODE FIELD32(0x03000000)
  3613. +#define LED_CFG_G_LED_MODE FIELD32(0x0c000000)
  3614. +#define LED_CFG_Y_LED_MODE FIELD32(0x30000000)
  3615. +#define LED_CFG_LED_POLAR FIELD32(0x40000000)
  3616. +
  3617. +/*
  3618. + * XIFS_TIME_CFG: MAC timing
  3619. + * CCKM_SIFS_TIME: unit 1us. Applied after CCK RX/TX
  3620. + * OFDM_SIFS_TIME: unit 1us. Applied after OFDM RX/TX
  3621. + * OFDM_XIFS_TIME: unit 1us. Applied after OFDM RX
  3622. + * when MAC doesn't reference BBP signal BBRXEND
  3623. + * EIFS: unit 1us
  3624. + * BB_RXEND_ENABLE: reference RXEND signal to begin XIFS defer
  3625. + *
  3626. + */
  3627. +#define XIFS_TIME_CFG 0x1100
  3628. +#define XIFS_TIME_CFG_CCKM_SIFS_TIME FIELD32(0x000000ff)
  3629. +#define XIFS_TIME_CFG_OFDM_SIFS_TIME FIELD32(0x0000ff00)
  3630. +#define XIFS_TIME_CFG_OFDM_XIFS_TIME FIELD32(0x000f0000)
  3631. +#define XIFS_TIME_CFG_EIFS FIELD32(0x1ff00000)
  3632. +#define XIFS_TIME_CFG_BB_RXEND_ENABLE FIELD32(0x20000000)
  3633. +
  3634. +/*
  3635. + * BKOFF_SLOT_CFG:
  3636. + */
  3637. +#define BKOFF_SLOT_CFG 0x1104
  3638. +#define BKOFF_SLOT_CFG_SLOT_TIME FIELD32(0x000000ff)
  3639. +#define BKOFF_SLOT_CFG_CC_DELAY_TIME FIELD32(0x0000ff00)
  3640. +
  3641. +/*
  3642. + * NAV_TIME_CFG:
  3643. + */
  3644. +#define NAV_TIME_CFG 0x1108
  3645. +#define NAV_TIME_CFG_SIFS FIELD32(0x000000ff)
  3646. +#define NAV_TIME_CFG_SLOT_TIME FIELD32(0x0000ff00)
  3647. +#define NAV_TIME_CFG_EIFS FIELD32(0x01ff0000)
  3648. +#define NAV_TIME_ZERO_SIFS FIELD32(0x02000000)
  3649. +
  3650. +/*
  3651. + * CH_TIME_CFG: count as channel busy
  3652. + */
  3653. +#define CH_TIME_CFG 0x110c
  3654. +
  3655. +/*
  3656. + * PBF_LIFE_TIMER: TX/RX MPDU timestamp timer (free run) Unit: 1us
  3657. + */
  3658. +#define PBF_LIFE_TIMER 0x1110
  3659. +
  3660. +/*
  3661. + * BCN_TIME_CFG:
  3662. + * BEACON_INTERVAL: in unit of 1/16 TU
  3663. + * TSF_TICKING: Enable TSF auto counting
  3664. + * TSF_SYNC: Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode
  3665. + * BEACON_GEN: Enable beacon generator
  3666. + */
  3667. +#define BCN_TIME_CFG 0x1114
  3668. +#define BCN_TIME_CFG_BEACON_INTERVAL FIELD32(0x0000ffff)
  3669. +#define BCN_TIME_CFG_TSF_TICKING FIELD32(0x00010000)
  3670. +#define BCN_TIME_CFG_TSF_SYNC FIELD32(0x00060000)
  3671. +#define BCN_TIME_CFG_TBTT_ENABLE FIELD32(0x00080000)
  3672. +#define BCN_TIME_CFG_BEACON_GEN FIELD32(0x00100000)
  3673. +#define BCN_TIME_CFG_TX_TIME_COMPENSATE FIELD32(0xf0000000)
  3674. +
  3675. +/*
  3676. + * TBTT_SYNC_CFG:
  3677. + */
  3678. +#define TBTT_SYNC_CFG 0x1118
  3679. +
  3680. +/*
  3681. + * TSF_TIMER_DW0: Local lsb TSF timer, read-only
  3682. + */
  3683. +#define TSF_TIMER_DW0 0x111c
  3684. +#define TSF_TIMER_DW0_LOW_WORD FIELD32(0xffffffff)
  3685. +
  3686. +/*
  3687. + * TSF_TIMER_DW1: Local msb TSF timer, read-only
  3688. + */
  3689. +#define TSF_TIMER_DW1 0x1120
  3690. +#define TSF_TIMER_DW1_HIGH_WORD FIELD32(0xffffffff)
  3691. +
  3692. +/*
  3693. + * TBTT_TIMER: TImer remains till next TBTT, read-only
  3694. + */
  3695. +#define TBTT_TIMER 0x1124
  3696. +
  3697. +/*
  3698. + * INT_TIMER_CFG:
  3699. + */
  3700. +#define INT_TIMER_CFG 0x1128
  3701. +
  3702. +/*
  3703. + * INT_TIMER_EN: GP-timer and pre-tbtt Int enable
  3704. + */
  3705. +#define INT_TIMER_EN 0x112c
  3706. +
  3707. +/*
  3708. + * CH_IDLE_STA: channel idle time
  3709. + */
  3710. +#define CH_IDLE_STA 0x1130
  3711. +
  3712. +/*
  3713. + * CH_BUSY_STA: channel busy time
  3714. + */
  3715. +#define CH_BUSY_STA 0x1134
  3716. +
  3717. +/*
  3718. + * MAC_STATUS_CFG:
  3719. + * BBP_RF_BUSY: When set to 0, BBP and RF are stable.
  3720. + * if 1 or higher one of the 2 registers is busy.
  3721. + */
  3722. +#define MAC_STATUS_CFG 0x1200
  3723. +#define MAC_STATUS_CFG_BBP_RF_BUSY FIELD32(0x00000003)
  3724. +
  3725. +/*
  3726. + * PWR_PIN_CFG:
  3727. + */
  3728. +#define PWR_PIN_CFG 0x1204
  3729. +
  3730. +/*
  3731. + * AUTOWAKEUP_CFG: Manual power control / status register
  3732. + * TBCN_BEFORE_WAKE: ForceWake has high privilege than PutToSleep when both set
  3733. + * AUTOWAKE: 0:sleep, 1:awake
  3734. + */
  3735. +#define AUTOWAKEUP_CFG 0x1208
  3736. +#define AUTOWAKEUP_CFG_AUTO_LEAD_TIME FIELD32(0x000000ff)
  3737. +#define AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE FIELD32(0x00007f00)
  3738. +#define AUTOWAKEUP_CFG_AUTOWAKE FIELD32(0x00008000)
  3739. +
  3740. +/*
  3741. + * EDCA_AC0_CFG:
  3742. + */
  3743. +#define EDCA_AC0_CFG 0x1300
  3744. +#define EDCA_AC0_CFG_TX_OP FIELD32(0x000000ff)
  3745. +#define EDCA_AC0_CFG_AIFSN FIELD32(0x00000f00)
  3746. +#define EDCA_AC0_CFG_CWMIN FIELD32(0x0000f000)
  3747. +#define EDCA_AC0_CFG_CWMAX FIELD32(0x000f0000)
  3748. +
  3749. +/*
  3750. + * EDCA_AC1_CFG:
  3751. + */
  3752. +#define EDCA_AC1_CFG 0x1304
  3753. +#define EDCA_AC1_CFG_TX_OP FIELD32(0x000000ff)
  3754. +#define EDCA_AC1_CFG_AIFSN FIELD32(0x00000f00)
  3755. +#define EDCA_AC1_CFG_CWMIN FIELD32(0x0000f000)
  3756. +#define EDCA_AC1_CFG_CWMAX FIELD32(0x000f0000)
  3757. +
  3758. +/*
  3759. + * EDCA_AC2_CFG:
  3760. + */
  3761. +#define EDCA_AC2_CFG 0x1308
  3762. +#define EDCA_AC2_CFG_TX_OP FIELD32(0x000000ff)
  3763. +#define EDCA_AC2_CFG_AIFSN FIELD32(0x00000f00)
  3764. +#define EDCA_AC2_CFG_CWMIN FIELD32(0x0000f000)
  3765. +#define EDCA_AC2_CFG_CWMAX FIELD32(0x000f0000)
  3766. +
  3767. +/*
  3768. + * EDCA_AC3_CFG:
  3769. + */
  3770. +#define EDCA_AC3_CFG 0x130c
  3771. +#define EDCA_AC3_CFG_TX_OP FIELD32(0x000000ff)
  3772. +#define EDCA_AC3_CFG_AIFSN FIELD32(0x00000f00)
  3773. +#define EDCA_AC3_CFG_CWMIN FIELD32(0x0000f000)
  3774. +#define EDCA_AC3_CFG_CWMAX FIELD32(0x000f0000)
  3775. +
  3776. +/*
  3777. + * EDCA_TID_AC_MAP:
  3778. + */
  3779. +#define EDCA_TID_AC_MAP 0x1310
  3780. +
  3781. +/*
  3782. + * TX_PWR_CFG_0:
  3783. + */
  3784. +#define TX_PWR_CFG_0 0x1314
  3785. +#define TX_PWR_CFG_0_1MBS FIELD32(0x0000000f)
  3786. +#define TX_PWR_CFG_0_2MBS FIELD32(0x000000f0)
  3787. +#define TX_PWR_CFG_0_55MBS FIELD32(0x00000f00)
  3788. +#define TX_PWR_CFG_0_11MBS FIELD32(0x0000f000)
  3789. +#define TX_PWR_CFG_0_6MBS FIELD32(0x000f0000)
  3790. +#define TX_PWR_CFG_0_9MBS FIELD32(0x00f00000)
  3791. +#define TX_PWR_CFG_0_12MBS FIELD32(0x0f000000)
  3792. +#define TX_PWR_CFG_0_18MBS FIELD32(0xf0000000)
  3793. +
  3794. +/*
  3795. + * TX_PWR_CFG_1:
  3796. + */
  3797. +#define TX_PWR_CFG_1 0x1318
  3798. +#define TX_PWR_CFG_1_24MBS FIELD32(0x0000000f)
  3799. +#define TX_PWR_CFG_1_36MBS FIELD32(0x000000f0)
  3800. +#define TX_PWR_CFG_1_48MBS FIELD32(0x00000f00)
  3801. +#define TX_PWR_CFG_1_54MBS FIELD32(0x0000f000)
  3802. +#define TX_PWR_CFG_1_MCS0 FIELD32(0x000f0000)
  3803. +#define TX_PWR_CFG_1_MCS1 FIELD32(0x00f00000)
  3804. +#define TX_PWR_CFG_1_MCS2 FIELD32(0x0f000000)
  3805. +#define TX_PWR_CFG_1_MCS3 FIELD32(0xf0000000)
  3806. +
  3807. +/*
  3808. + * TX_PWR_CFG_2:
  3809. + */
  3810. +#define TX_PWR_CFG_2 0x131c
  3811. +#define TX_PWR_CFG_2_MCS4 FIELD32(0x0000000f)
  3812. +#define TX_PWR_CFG_2_MCS5 FIELD32(0x000000f0)
  3813. +#define TX_PWR_CFG_2_MCS6 FIELD32(0x00000f00)
  3814. +#define TX_PWR_CFG_2_MCS7 FIELD32(0x0000f000)
  3815. +#define TX_PWR_CFG_2_MCS8 FIELD32(0x000f0000)
  3816. +#define TX_PWR_CFG_2_MCS9 FIELD32(0x00f00000)
  3817. +#define TX_PWR_CFG_2_MCS10 FIELD32(0x0f000000)
  3818. +#define TX_PWR_CFG_2_MCS11 FIELD32(0xf0000000)
  3819. +
  3820. +/*
  3821. + * TX_PWR_CFG_3:
  3822. + */
  3823. +#define TX_PWR_CFG_3 0x1320
  3824. +#define TX_PWR_CFG_3_MCS12 FIELD32(0x0000000f)
  3825. +#define TX_PWR_CFG_3_MCS13 FIELD32(0x000000f0)
  3826. +#define TX_PWR_CFG_3_MCS14 FIELD32(0x00000f00)
  3827. +#define TX_PWR_CFG_3_MCS15 FIELD32(0x0000f000)
  3828. +#define TX_PWR_CFG_3_UKNOWN1 FIELD32(0x000f0000)
  3829. +#define TX_PWR_CFG_3_UKNOWN2 FIELD32(0x00f00000)
  3830. +#define TX_PWR_CFG_3_UKNOWN3 FIELD32(0x0f000000)
  3831. +#define TX_PWR_CFG_3_UKNOWN4 FIELD32(0xf0000000)
  3832. +
  3833. +/*
  3834. + * TX_PWR_CFG_4:
  3835. + */
  3836. +#define TX_PWR_CFG_4 0x1324
  3837. +#define TX_PWR_CFG_4_UKNOWN5 FIELD32(0x0000000f)
  3838. +#define TX_PWR_CFG_4_UKNOWN6 FIELD32(0x000000f0)
  3839. +#define TX_PWR_CFG_4_UKNOWN7 FIELD32(0x00000f00)
  3840. +#define TX_PWR_CFG_4_UKNOWN8 FIELD32(0x0000f000)
  3841. +
  3842. +/*
  3843. + * TX_PIN_CFG:
  3844. + */
  3845. +#define TX_PIN_CFG 0x1328
  3846. +#define TX_PIN_CFG_PA_PE_A0_EN FIELD32(0x00000001)
  3847. +#define TX_PIN_CFG_PA_PE_G0_EN FIELD32(0x00000002)
  3848. +#define TX_PIN_CFG_PA_PE_A1_EN FIELD32(0x00000004)
  3849. +#define TX_PIN_CFG_PA_PE_G1_EN FIELD32(0x00000008)
  3850. +#define TX_PIN_CFG_PA_PE_A0_POL FIELD32(0x00000010)
  3851. +#define TX_PIN_CFG_PA_PE_G0_POL FIELD32(0x00000020)
  3852. +#define TX_PIN_CFG_PA_PE_A1_POL FIELD32(0x00000040)
  3853. +#define TX_PIN_CFG_PA_PE_G1_POL FIELD32(0x00000080)
  3854. +#define TX_PIN_CFG_LNA_PE_A0_EN FIELD32(0x00000100)
  3855. +#define TX_PIN_CFG_LNA_PE_G0_EN FIELD32(0x00000200)
  3856. +#define TX_PIN_CFG_LNA_PE_A1_EN FIELD32(0x00000400)
  3857. +#define TX_PIN_CFG_LNA_PE_G1_EN FIELD32(0x00000800)
  3858. +#define TX_PIN_CFG_LNA_PE_A0_POL FIELD32(0x00001000)
  3859. +#define TX_PIN_CFG_LNA_PE_G0_POL FIELD32(0x00002000)
  3860. +#define TX_PIN_CFG_LNA_PE_A1_POL FIELD32(0x00004000)
  3861. +#define TX_PIN_CFG_LNA_PE_G1_POL FIELD32(0x00008000)
  3862. +#define TX_PIN_CFG_RFTR_EN FIELD32(0x00010000)
  3863. +#define TX_PIN_CFG_RFTR_POL FIELD32(0x00020000)
  3864. +#define TX_PIN_CFG_TRSW_EN FIELD32(0x00040000)
  3865. +#define TX_PIN_CFG_TRSW_POL FIELD32(0x00080000)
  3866. +
  3867. +/*
  3868. + * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
  3869. + */
  3870. +#define TX_BAND_CFG 0x132c
  3871. +#define TX_BAND_CFG_HT40_PLUS FIELD32(0x00000001)
  3872. +#define TX_BAND_CFG_A FIELD32(0x00000002)
  3873. +#define TX_BAND_CFG_BG FIELD32(0x00000004)
  3874. +
  3875. +/*
  3876. + * TX_SW_CFG0:
  3877. + */
  3878. +#define TX_SW_CFG0 0x1330
  3879. +
  3880. +/*
  3881. + * TX_SW_CFG1:
  3882. + */
  3883. +#define TX_SW_CFG1 0x1334
  3884. +
  3885. +/*
  3886. + * TX_SW_CFG2:
  3887. + */
  3888. +#define TX_SW_CFG2 0x1338
  3889. +
  3890. +/*
  3891. + * TXOP_THRES_CFG:
  3892. + */
  3893. +#define TXOP_THRES_CFG 0x133c
  3894. +
  3895. +/*
  3896. + * TXOP_CTRL_CFG:
  3897. + */
  3898. +#define TXOP_CTRL_CFG 0x1340
  3899. +
  3900. +/*
  3901. + * TX_RTS_CFG:
  3902. + * RTS_THRES: unit:byte
  3903. + * RTS_FBK_EN: enable rts rate fallback
  3904. + */
  3905. +#define TX_RTS_CFG 0x1344
  3906. +#define TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT FIELD32(0x000000ff)
  3907. +#define TX_RTS_CFG_RTS_THRES FIELD32(0x00ffff00)
  3908. +#define TX_RTS_CFG_RTS_FBK_EN FIELD32(0x01000000)
  3909. +
  3910. +/*
  3911. + * TX_TIMEOUT_CFG:
  3912. + * MPDU_LIFETIME: expiration time = 2^(9+MPDU LIFE TIME) us
  3913. + * RX_ACK_TIMEOUT: unit:slot. Used for TX procedure
  3914. + * TX_OP_TIMEOUT: TXOP timeout value for TXOP truncation.
  3915. + * it is recommended that:
  3916. + * (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT)
  3917. + */
  3918. +#define TX_TIMEOUT_CFG 0x1348
  3919. +#define TX_TIMEOUT_CFG_MPDU_LIFETIME FIELD32(0x000000f0)
  3920. +#define TX_TIMEOUT_CFG_RX_ACK_TIMEOUT FIELD32(0x0000ff00)
  3921. +#define TX_TIMEOUT_CFG_TX_OP_TIMEOUT FIELD32(0x00ff0000)
  3922. +
  3923. +/*
  3924. + * TX_RTY_CFG:
  3925. + * SHORT_RTY_LIMIT: short retry limit
  3926. + * LONG_RTY_LIMIT: long retry limit
  3927. + * LONG_RTY_THRE: Long retry threshoold
  3928. + * NON_AGG_RTY_MODE: Non-Aggregate MPDU retry mode
  3929. + * 0:expired by retry limit, 1: expired by mpdu life timer
  3930. + * AGG_RTY_MODE: Aggregate MPDU retry mode
  3931. + * 0:expired by retry limit, 1: expired by mpdu life timer
  3932. + * TX_AUTO_FB_ENABLE: Tx retry PHY rate auto fallback enable
  3933. + */
  3934. +#define TX_RTY_CFG 0x134c
  3935. +#define TX_RTY_CFG_SHORT_RTY_LIMIT FIELD32(0x000000ff)
  3936. +#define TX_RTY_CFG_LONG_RTY_LIMIT FIELD32(0x0000ff00)
  3937. +#define TX_RTY_CFG_LONG_RTY_THRE FIELD32(0x0fff0000)
  3938. +#define TX_RTY_CFG_NON_AGG_RTY_MODE FIELD32(0x10000000)
  3939. +#define TX_RTY_CFG_AGG_RTY_MODE FIELD32(0x20000000)
  3940. +#define TX_RTY_CFG_TX_AUTO_FB_ENABLE FIELD32(0x40000000)
  3941. +
  3942. +/*
  3943. + * TX_LINK_CFG:
  3944. + * REMOTE_MFB_LIFETIME: remote MFB life time. unit: 32us
  3945. + * MFB_ENABLE: TX apply remote MFB 1:enable
  3946. + * REMOTE_UMFS_ENABLE: remote unsolicit MFB enable
  3947. + * 0: not apply remote remote unsolicit (MFS=7)
  3948. + * TX_MRQ_EN: MCS request TX enable
  3949. + * TX_RDG_EN: RDG TX enable
  3950. + * TX_CF_ACK_EN: Piggyback CF-ACK enable
  3951. + * REMOTE_MFB: remote MCS feedback
  3952. + * REMOTE_MFS: remote MCS feedback sequence number
  3953. + */
  3954. +#define TX_LINK_CFG 0x1350
  3955. +#define TX_LINK_CFG_REMOTE_MFB_LIFETIME FIELD32(0x000000ff)
  3956. +#define TX_LINK_CFG_MFB_ENABLE FIELD32(0x00000100)
  3957. +#define TX_LINK_CFG_REMOTE_UMFS_ENABLE FIELD32(0x00000200)
  3958. +#define TX_LINK_CFG_TX_MRQ_EN FIELD32(0x00000400)
  3959. +#define TX_LINK_CFG_TX_RDG_EN FIELD32(0x00000800)
  3960. +#define TX_LINK_CFG_TX_CF_ACK_EN FIELD32(0x00001000)
  3961. +#define TX_LINK_CFG_REMOTE_MFB FIELD32(0x00ff0000)
  3962. +#define TX_LINK_CFG_REMOTE_MFS FIELD32(0xff000000)
  3963. +
  3964. +/*
  3965. + * HT_FBK_CFG0:
  3966. + */
  3967. +#define HT_FBK_CFG0 0x1354
  3968. +#define HT_FBK_CFG0_HTMCS0FBK FIELD32(0x0000000f)
  3969. +#define HT_FBK_CFG0_HTMCS1FBK FIELD32(0x000000f0)
  3970. +#define HT_FBK_CFG0_HTMCS2FBK FIELD32(0x00000f00)
  3971. +#define HT_FBK_CFG0_HTMCS3FBK FIELD32(0x0000f000)
  3972. +#define HT_FBK_CFG0_HTMCS4FBK FIELD32(0x000f0000)
  3973. +#define HT_FBK_CFG0_HTMCS5FBK FIELD32(0x00f00000)
  3974. +#define HT_FBK_CFG0_HTMCS6FBK FIELD32(0x0f000000)
  3975. +#define HT_FBK_CFG0_HTMCS7FBK FIELD32(0xf0000000)
  3976. +
  3977. +/*
  3978. + * HT_FBK_CFG1:
  3979. + */
  3980. +#define HT_FBK_CFG1 0x1358
  3981. +#define HT_FBK_CFG1_HTMCS8FBK FIELD32(0x0000000f)
  3982. +#define HT_FBK_CFG1_HTMCS9FBK FIELD32(0x000000f0)
  3983. +#define HT_FBK_CFG1_HTMCS10FBK FIELD32(0x00000f00)
  3984. +#define HT_FBK_CFG1_HTMCS11FBK FIELD32(0x0000f000)
  3985. +#define HT_FBK_CFG1_HTMCS12FBK FIELD32(0x000f0000)
  3986. +#define HT_FBK_CFG1_HTMCS13FBK FIELD32(0x00f00000)
  3987. +#define HT_FBK_CFG1_HTMCS14FBK FIELD32(0x0f000000)
  3988. +#define HT_FBK_CFG1_HTMCS15FBK FIELD32(0xf0000000)
  3989. +
  3990. +/*
  3991. + * LG_FBK_CFG0:
  3992. + */
  3993. +#define LG_FBK_CFG0 0x135c
  3994. +#define LG_FBK_CFG0_OFDMMCS0FBK FIELD32(0x0000000f)
  3995. +#define LG_FBK_CFG0_OFDMMCS1FBK FIELD32(0x000000f0)
  3996. +#define LG_FBK_CFG0_OFDMMCS2FBK FIELD32(0x00000f00)
  3997. +#define LG_FBK_CFG0_OFDMMCS3FBK FIELD32(0x0000f000)
  3998. +#define LG_FBK_CFG0_OFDMMCS4FBK FIELD32(0x000f0000)
  3999. +#define LG_FBK_CFG0_OFDMMCS5FBK FIELD32(0x00f00000)
  4000. +#define LG_FBK_CFG0_OFDMMCS6FBK FIELD32(0x0f000000)
  4001. +#define LG_FBK_CFG0_OFDMMCS7FBK FIELD32(0xf0000000)
  4002. +
  4003. +/*
  4004. + * LG_FBK_CFG1:
  4005. + */
  4006. +#define LG_FBK_CFG1 0x1360
  4007. +#define LG_FBK_CFG0_CCKMCS0FBK FIELD32(0x0000000f)
  4008. +#define LG_FBK_CFG0_CCKMCS1FBK FIELD32(0x000000f0)
  4009. +#define LG_FBK_CFG0_CCKMCS2FBK FIELD32(0x00000f00)
  4010. +#define LG_FBK_CFG0_CCKMCS3FBK FIELD32(0x0000f000)
  4011. +
  4012. +/*
  4013. + * CCK_PROT_CFG: CCK Protection
  4014. + * PROTECT_RATE: Protection control frame rate for CCK TX(RTS/CTS/CFEnd)
  4015. + * PROTECT_CTRL: Protection control frame type for CCK TX
  4016. + * 0:none, 1:RTS/CTS, 2:CTS-to-self
  4017. + * PROTECT_NAV: TXOP protection type for CCK TX
  4018. + * 0:none, 1:ShortNAVprotect, 2:LongNAVProtect
  4019. + * TX_OP_ALLOW_CCK: CCK TXOP allowance, 0:disallow
  4020. + * TX_OP_ALLOW_OFDM: CCK TXOP allowance, 0:disallow
  4021. + * TX_OP_ALLOW_MM20: CCK TXOP allowance, 0:disallow
  4022. + * TX_OP_ALLOW_MM40: CCK TXOP allowance, 0:disallow
  4023. + * TX_OP_ALLOW_GF20: CCK TXOP allowance, 0:disallow
  4024. + * TX_OP_ALLOW_GF40: CCK TXOP allowance, 0:disallow
  4025. + * RTS_TH_EN: RTS threshold enable on CCK TX
  4026. + */
  4027. +#define CCK_PROT_CFG 0x1364
  4028. +#define CCK_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4029. +#define CCK_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4030. +#define CCK_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4031. +#define CCK_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4032. +#define CCK_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4033. +#define CCK_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4034. +#define CCK_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4035. +#define CCK_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4036. +#define CCK_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4037. +#define CCK_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4038. +
  4039. +/*
  4040. + * OFDM_PROT_CFG: OFDM Protection
  4041. + */
  4042. +#define OFDM_PROT_CFG 0x1368
  4043. +#define OFDM_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4044. +#define OFDM_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4045. +#define OFDM_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4046. +#define OFDM_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4047. +#define OFDM_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4048. +#define OFDM_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4049. +#define OFDM_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4050. +#define OFDM_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4051. +#define OFDM_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4052. +#define OFDM_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4053. +
  4054. +/*
  4055. + * MM20_PROT_CFG: MM20 Protection
  4056. + */
  4057. +#define MM20_PROT_CFG 0x136c
  4058. +#define MM20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4059. +#define MM20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4060. +#define MM20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4061. +#define MM20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4062. +#define MM20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4063. +#define MM20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4064. +#define MM20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4065. +#define MM20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4066. +#define MM20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4067. +#define MM20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4068. +
  4069. +/*
  4070. + * MM40_PROT_CFG: MM40 Protection
  4071. + */
  4072. +#define MM40_PROT_CFG 0x1370
  4073. +#define MM40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4074. +#define MM40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4075. +#define MM40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4076. +#define MM40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4077. +#define MM40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4078. +#define MM40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4079. +#define MM40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4080. +#define MM40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4081. +#define MM40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4082. +#define MM40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4083. +
  4084. +/*
  4085. + * GF20_PROT_CFG: GF20 Protection
  4086. + */
  4087. +#define GF20_PROT_CFG 0x1374
  4088. +#define GF20_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4089. +#define GF20_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4090. +#define GF20_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4091. +#define GF20_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4092. +#define GF20_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4093. +#define GF20_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4094. +#define GF20_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4095. +#define GF20_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4096. +#define GF20_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4097. +#define GF20_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4098. +
  4099. +/*
  4100. + * GF40_PROT_CFG: GF40 Protection
  4101. + */
  4102. +#define GF40_PROT_CFG 0x1378
  4103. +#define GF40_PROT_CFG_PROTECT_RATE FIELD32(0x0000ffff)
  4104. +#define GF40_PROT_CFG_PROTECT_CTRL FIELD32(0x00030000)
  4105. +#define GF40_PROT_CFG_PROTECT_NAV FIELD32(0x000c0000)
  4106. +#define GF40_PROT_CFG_TX_OP_ALLOW_CCK FIELD32(0x00100000)
  4107. +#define GF40_PROT_CFG_TX_OP_ALLOW_OFDM FIELD32(0x00200000)
  4108. +#define GF40_PROT_CFG_TX_OP_ALLOW_MM20 FIELD32(0x00400000)
  4109. +#define GF40_PROT_CFG_TX_OP_ALLOW_MM40 FIELD32(0x00800000)
  4110. +#define GF40_PROT_CFG_TX_OP_ALLOW_GF20 FIELD32(0x01000000)
  4111. +#define GF40_PROT_CFG_TX_OP_ALLOW_GF40 FIELD32(0x02000000)
  4112. +#define GF40_PROT_CFG_RTS_TH_EN FIELD32(0x04000000)
  4113. +
  4114. +/*
  4115. + * EXP_CTS_TIME:
  4116. + */
  4117. +#define EXP_CTS_TIME 0x137c
  4118. +
  4119. +/*
  4120. + * EXP_ACK_TIME:
  4121. + */
  4122. +#define EXP_ACK_TIME 0x1380
  4123. +
  4124. +/*
  4125. + * RX_FILTER_CFG: RX configuration register.
  4126. + */
  4127. +#define RX_FILTER_CFG 0x1400
  4128. +#define RX_FILTER_CFG_DROP_CRC_ERROR FIELD32(0x00000001)
  4129. +#define RX_FILTER_CFG_DROP_PHY_ERROR FIELD32(0x00000002)
  4130. +#define RX_FILTER_CFG_DROP_NOT_TO_ME FIELD32(0x00000004)
  4131. +#define RX_FILTER_CFG_DROP_NOT_MY_BSSD FIELD32(0x00000008)
  4132. +#define RX_FILTER_CFG_DROP_VER_ERROR FIELD32(0x00000010)
  4133. +#define RX_FILTER_CFG_DROP_MULTICAST FIELD32(0x00000020)
  4134. +#define RX_FILTER_CFG_DROP_BROADCAST FIELD32(0x00000040)
  4135. +#define RX_FILTER_CFG_DROP_DUPLICATE FIELD32(0x00000080)
  4136. +#define RX_FILTER_CFG_DROP_CF_END_ACK FIELD32(0x00000100)
  4137. +#define RX_FILTER_CFG_DROP_CF_END FIELD32(0x00000200)
  4138. +#define RX_FILTER_CFG_DROP_ACK FIELD32(0x00000400)
  4139. +#define RX_FILTER_CFG_DROP_CTS FIELD32(0x00000800)
  4140. +#define RX_FILTER_CFG_DROP_RTS FIELD32(0x00001000)
  4141. +#define RX_FILTER_CFG_DROP_PSPOLL FIELD32(0x00002000)
  4142. +#define RX_FILTER_CFG_DROP_BA FIELD32(0x00004000)
  4143. +#define RX_FILTER_CFG_DROP_BAR FIELD32(0x00008000)
  4144. +#define RX_FILTER_CFG_DROP_CNTL FIELD32(0x00010000)
  4145. +
  4146. +/*
  4147. + * AUTO_RSP_CFG:
  4148. + * AUTORESPONDER: 0: disable, 1: enable
  4149. + * BAC_ACK_POLICY: 0:long, 1:short preamble
  4150. + * CTS_40_MMODE: Response CTS 40MHz duplicate mode
  4151. + * CTS_40_MREF: Response CTS 40MHz duplicate mode
  4152. + * AR_PREAMBLE: Auto responder preamble 0:long, 1:short preamble
  4153. + * DUAL_CTS_EN: Power bit value in control frame
  4154. + * ACK_CTS_PSM_BIT:Power bit value in control frame
  4155. + */
  4156. +#define AUTO_RSP_CFG 0x1404
  4157. +#define AUTO_RSP_CFG_AUTORESPONDER FIELD32(0x00000001)
  4158. +#define AUTO_RSP_CFG_BAC_ACK_POLICY FIELD32(0x00000002)
  4159. +#define AUTO_RSP_CFG_CTS_40_MMODE FIELD32(0x00000004)
  4160. +#define AUTO_RSP_CFG_CTS_40_MREF FIELD32(0x00000008)
  4161. +#define AUTO_RSP_CFG_AR_PREAMBLE FIELD32(0x00000010)
  4162. +#define AUTO_RSP_CFG_DUAL_CTS_EN FIELD32(0x00000040)
  4163. +#define AUTO_RSP_CFG_ACK_CTS_PSM_BIT FIELD32(0x00000080)
  4164. +
  4165. +/*
  4166. + * LEGACY_BASIC_RATE:
  4167. + */
  4168. +#define LEGACY_BASIC_RATE 0x1408
  4169. +
  4170. +/*
  4171. + * HT_BASIC_RATE:
  4172. + */
  4173. +#define HT_BASIC_RATE 0x140c
  4174. +
  4175. +/*
  4176. + * HT_CTRL_CFG:
  4177. + */
  4178. +#define HT_CTRL_CFG 0x1410
  4179. +
  4180. +/*
  4181. + * SIFS_COST_CFG:
  4182. + */
  4183. +#define SIFS_COST_CFG 0x1414
  4184. +
  4185. +/*
  4186. + * RX_PARSER_CFG:
  4187. + * Set NAV for all received frames
  4188. + */
  4189. +#define RX_PARSER_CFG 0x1418
  4190. +
  4191. +/*
  4192. + * TX_SEC_CNT0:
  4193. + */
  4194. +#define TX_SEC_CNT0 0x1500
  4195. +
  4196. +/*
  4197. + * RX_SEC_CNT0:
  4198. + */
  4199. +#define RX_SEC_CNT0 0x1504
  4200. +
  4201. +/*
  4202. + * CCMP_FC_MUTE:
  4203. + */
  4204. +#define CCMP_FC_MUTE 0x1508
  4205. +
  4206. +/*
  4207. + * TXOP_HLDR_ADDR0:
  4208. + */
  4209. +#define TXOP_HLDR_ADDR0 0x1600
  4210. +
  4211. +/*
  4212. + * TXOP_HLDR_ADDR1:
  4213. + */
  4214. +#define TXOP_HLDR_ADDR1 0x1604
  4215. +
  4216. +/*
  4217. + * TXOP_HLDR_ET:
  4218. + */
  4219. +#define TXOP_HLDR_ET 0x1608
  4220. +
  4221. +/*
  4222. + * QOS_CFPOLL_RA_DW0:
  4223. + */
  4224. +#define QOS_CFPOLL_RA_DW0 0x160c
  4225. +
  4226. +/*
  4227. + * QOS_CFPOLL_RA_DW1:
  4228. + */
  4229. +#define QOS_CFPOLL_RA_DW1 0x1610
  4230. +
  4231. +/*
  4232. + * QOS_CFPOLL_QC:
  4233. + */
  4234. +#define QOS_CFPOLL_QC 0x1614
  4235. +
  4236. +/*
  4237. + * RX_STA_CNT0: RX PLCP error count & RX CRC error count
  4238. + */
  4239. +#define RX_STA_CNT0 0x1700
  4240. +#define RX_STA_CNT0_CRC_ERR FIELD32(0x0000ffff)
  4241. +#define RX_STA_CNT0_PHY_ERR FIELD32(0xffff0000)
  4242. +
  4243. +/*
  4244. + * RX_STA_CNT1: RX False CCA count & RX LONG frame count
  4245. + */
  4246. +#define RX_STA_CNT1 0x1704
  4247. +#define RX_STA_CNT1_FALSE_CCA FIELD32(0x0000ffff)
  4248. +#define RX_STA_CNT1_PLCP_ERR FIELD32(0xffff0000)
  4249. +
  4250. +/*
  4251. + * RX_STA_CNT2:
  4252. + */
  4253. +#define RX_STA_CNT2 0x1708
  4254. +#define RX_STA_CNT2_RX_DUPLI_COUNT FIELD32(0x0000ffff)
  4255. +#define RX_STA_CNT2_RX_FIFO_OVERFLOW FIELD32(0xffff0000)
  4256. +
  4257. +/*
  4258. + * TX_STA_CNT0: TX Beacon count
  4259. + */
  4260. +#define TX_STA_CNT0 0x170c
  4261. +#define TX_STA_CNT0_TX_FAIL_COUNT FIELD32(0x0000ffff)
  4262. +#define TX_STA_CNT0_TX_BEACON_COUNT FIELD32(0xffff0000)
  4263. +
  4264. +/*
  4265. + * TX_STA_CNT1: TX tx count
  4266. + */
  4267. +#define TX_STA_CNT1 0x1710
  4268. +#define TX_STA_CNT1_TX_SUCCESS FIELD32(0x0000ffff)
  4269. +#define TX_STA_CNT1_TX_RETRANSMIT FIELD32(0xffff0000)
  4270. +
  4271. +/*
  4272. + * TX_STA_CNT2: TX tx count
  4273. + */
  4274. +#define TX_STA_CNT2 0x1714
  4275. +#define TX_STA_CNT2_TX_ZERO_LEN_COUNT FIELD32(0x0000ffff)
  4276. +#define TX_STA_CNT2_TX_UNDER_FLOW_COUNT FIELD32(0xffff0000)
  4277. +
  4278. +/*
  4279. + * TX_STA_FIFO: TX Result for specific PID status fifo register
  4280. + */
  4281. +#define TX_STA_FIFO 0x1718
  4282. +#define TX_STA_FIFO_VALID FIELD32(0x00000001)
  4283. +#define TX_STA_FIFO_PID_TYPE FIELD32(0x0000001e)
  4284. +#define TX_STA_FIFO_TX_SUCCESS FIELD32(0x00000020)
  4285. +#define TX_STA_FIFO_TX_AGGRE FIELD32(0x00000040)
  4286. +#define TX_STA_FIFO_TX_ACK_REQUIRED FIELD32(0x00000080)
  4287. +#define TX_STA_FIFO_WCID FIELD32(0x0000ff00)
  4288. +#define TX_STA_FIFO_SUCCESS_RATE FIELD32(0xffff0000)
  4289. +
  4290. +/*
  4291. + * TX_AGG_CNT: Debug counter
  4292. + */
  4293. +#define TX_AGG_CNT 0x171c
  4294. +#define TX_AGG_CNT_NON_AGG_TX_COUNT FIELD32(0x0000ffff)
  4295. +#define TX_AGG_CNT_AGG_TX_COUNT FIELD32(0xffff0000)
  4296. +
  4297. +/*
  4298. + * TX_AGG_CNT0:
  4299. + */
  4300. +#define TX_AGG_CNT0 0x1720
  4301. +#define TX_AGG_CNT0_AGG_SIZE_1_COUNT FIELD32(0x0000ffff)
  4302. +#define TX_AGG_CNT0_AGG_SIZE_2_COUNT FIELD32(0xffff0000)
  4303. +
  4304. +/*
  4305. + * TX_AGG_CNT1:
  4306. + */
  4307. +#define TX_AGG_CNT1 0x1724
  4308. +#define TX_AGG_CNT1_AGG_SIZE_3_COUNT FIELD32(0x0000ffff)
  4309. +#define TX_AGG_CNT1_AGG_SIZE_4_COUNT FIELD32(0xffff0000)
  4310. +
  4311. +/*
  4312. + * TX_AGG_CNT2:
  4313. + */
  4314. +#define TX_AGG_CNT2 0x1728
  4315. +#define TX_AGG_CNT2_AGG_SIZE_5_COUNT FIELD32(0x0000ffff)
  4316. +#define TX_AGG_CNT2_AGG_SIZE_6_COUNT FIELD32(0xffff0000)
  4317. +
  4318. +/*
  4319. + * TX_AGG_CNT3:
  4320. + */
  4321. +#define TX_AGG_CNT3 0x172c
  4322. +#define TX_AGG_CNT3_AGG_SIZE_7_COUNT FIELD32(0x0000ffff)
  4323. +#define TX_AGG_CNT3_AGG_SIZE_8_COUNT FIELD32(0xffff0000)
  4324. +
  4325. +/*
  4326. + * TX_AGG_CNT4:
  4327. + */
  4328. +#define TX_AGG_CNT4 0x1730
  4329. +#define TX_AGG_CNT4_AGG_SIZE_9_COUNT FIELD32(0x0000ffff)
  4330. +#define TX_AGG_CNT4_AGG_SIZE_10_COUNT FIELD32(0xffff0000)
  4331. +
  4332. +/*
  4333. + * TX_AGG_CNT5:
  4334. + */
  4335. +#define TX_AGG_CNT5 0x1734
  4336. +#define TX_AGG_CNT5_AGG_SIZE_11_COUNT FIELD32(0x0000ffff)
  4337. +#define TX_AGG_CNT5_AGG_SIZE_12_COUNT FIELD32(0xffff0000)
  4338. +
  4339. +/*
  4340. + * TX_AGG_CNT6:
  4341. + */
  4342. +#define TX_AGG_CNT6 0x1738
  4343. +#define TX_AGG_CNT6_AGG_SIZE_13_COUNT FIELD32(0x0000ffff)
  4344. +#define TX_AGG_CNT6_AGG_SIZE_14_COUNT FIELD32(0xffff0000)
  4345. +
  4346. +/*
  4347. + * TX_AGG_CNT7:
  4348. + */
  4349. +#define TX_AGG_CNT7 0x173c
  4350. +#define TX_AGG_CNT7_AGG_SIZE_15_COUNT FIELD32(0x0000ffff)
  4351. +#define TX_AGG_CNT7_AGG_SIZE_16_COUNT FIELD32(0xffff0000)
  4352. +
  4353. +/*
  4354. + * MPDU_DENSITY_CNT:
  4355. + * TX_ZERO_DEL: TX zero length delimiter count
  4356. + * RX_ZERO_DEL: RX zero length delimiter count
  4357. + */
  4358. +#define MPDU_DENSITY_CNT 0x1740
  4359. +#define MPDU_DENSITY_CNT_TX_ZERO_DEL FIELD32(0x0000ffff)
  4360. +#define MPDU_DENSITY_CNT_RX_ZERO_DEL FIELD32(0xffff0000)
  4361. +
  4362. +/*
  4363. + * Security key table memory.
  4364. + * MAC_WCID_BASE: 8-bytes (use only 6 bytes) * 256 entry
  4365. + * PAIRWISE_KEY_TABLE_BASE: 32-byte * 256 entry
  4366. + * MAC_IVEIV_TABLE_BASE: 8-byte * 256-entry
  4367. + * MAC_WCID_ATTRIBUTE_BASE: 4-byte * 256-entry
  4368. + * SHARED_KEY_TABLE_BASE: 32-byte * 16-entry
  4369. + * SHARED_KEY_MODE_BASE: 4-byte * 16-entry
  4370. + */
  4371. +#define MAC_WCID_BASE 0x1800
  4372. +#define PAIRWISE_KEY_TABLE_BASE 0x4000
  4373. +#define MAC_IVEIV_TABLE_BASE 0x6000
  4374. +#define MAC_WCID_ATTRIBUTE_BASE 0x6800
  4375. +#define SHARED_KEY_TABLE_BASE 0x6c00
  4376. +#define SHARED_KEY_MODE_BASE 0x7000
  4377. +
  4378. +#define MAC_WCID_ENTRY(__idx) \
  4379. + ( MAC_WCID_BASE + ((__idx) * sizeof(struct mac_wcid_entry)) )
  4380. +#define PAIRWISE_KEY_ENTRY(__idx) \
  4381. + ( PAIRWISE_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
  4382. +#define MAC_IVEIV_ENTRY(__idx) \
  4383. + ( MAC_IVEIV_TABLE_BASE + ((__idx) & sizeof(struct mac_iveiv_entry)) )
  4384. +#define MAC_WCID_ATTR_ENTRY(__idx) \
  4385. + ( MAC_WCID_ATTRIBUTE_BASE + ((__idx) * sizeof(u32)) )
  4386. +#define SHARED_KEY_ENTRY(__idx) \
  4387. + ( SHARED_KEY_TABLE_BASE + ((__idx) * sizeof(struct hw_key_entry)) )
  4388. +#define SHARED_KEY_MODE_ENTRY(__idx) \
  4389. + ( SHARED_KEY_MODE_BASE + ((__idx) * sizeof(u32)) )
  4390. +
  4391. +struct mac_wcid_entry {
  4392. + u8 mac[6];
  4393. + u8 reserved[2];
  4394. +} __attribute__ ((packed));
  4395. +
  4396. +struct hw_key_entry {
  4397. + u8 key[16];
  4398. + u8 tx_mic[8];
  4399. + u8 rx_mic[8];
  4400. +} __attribute__ ((packed));
  4401. +
  4402. +struct mac_iveiv_entry {
  4403. + u8 iv[8];
  4404. +} __attribute__ ((packed));
  4405. +
  4406. +/*
  4407. + * MAC_WCID_ATTRIBUTE:
  4408. + */
  4409. +#define MAC_WCID_ATTRIBUTE_KEYTAB FIELD32(0x00000001)
  4410. +#define MAC_WCID_ATTRIBUTE_CIPHER FIELD32(0x0000000e)
  4411. +#define MAC_WCID_ATTRIBUTE_BSS_IDX FIELD32(0x00000070)
  4412. +#define MAC_WCID_ATTRIBUTE_RX_WIUDF FIELD32(0x00000380)
  4413. +
  4414. +/*
  4415. + * SHARED_KEY_MODE:
  4416. + */
  4417. +#define SHARED_KEY_MODE_BSS0_KEY0 FIELD32(0x00000007)
  4418. +#define SHARED_KEY_MODE_BSS0_KEY1 FIELD32(0x00000070)
  4419. +#define SHARED_KEY_MODE_BSS0_KEY2 FIELD32(0x00000700)
  4420. +#define SHARED_KEY_MODE_BSS0_KEY3 FIELD32(0x00007000)
  4421. +#define SHARED_KEY_MODE_BSS1_KEY0 FIELD32(0x00070000)
  4422. +#define SHARED_KEY_MODE_BSS1_KEY1 FIELD32(0x00700000)
  4423. +#define SHARED_KEY_MODE_BSS1_KEY2 FIELD32(0x07000000)
  4424. +#define SHARED_KEY_MODE_BSS1_KEY3 FIELD32(0x70000000)
  4425. +
  4426. +/*
  4427. + * HOST-MCU communication
  4428. + */
  4429. +
  4430. +/*
  4431. + * H2M_MAILBOX_CSR: Host-to-MCU Mailbox.
  4432. + */
  4433. +#define H2M_MAILBOX_CSR 0x7010
  4434. +#define H2M_MAILBOX_CSR_ARG0 FIELD32(0x000000ff)
  4435. +#define H2M_MAILBOX_CSR_ARG1 FIELD32(0x0000ff00)
  4436. +#define H2M_MAILBOX_CSR_CMD_TOKEN FIELD32(0x00ff0000)
  4437. +#define H2M_MAILBOX_CSR_OWNER FIELD32(0xff000000)
  4438. +
  4439. +/*
  4440. + * H2M_MAILBOX_CID:
  4441. + */
  4442. +#define H2M_MAILBOX_CID 0x7014
  4443. +
  4444. +/*
  4445. + * H2M_MAILBOX_STATUS:
  4446. + */
  4447. +#define H2M_MAILBOX_STATUS 0x701c
  4448. +
  4449. +/*
  4450. + * H2M_INT_SRC:
  4451. + */
  4452. +#define H2M_INT_SRC 0x7024
  4453. +
  4454. +/*
  4455. + * H2M_BBP_AGENT:
  4456. + */
  4457. +#define H2M_BBP_AGENT 0x7028
  4458. +
  4459. +/*
  4460. + * MCU_LEDCS: LED control for MCU Mailbox.
  4461. + */
  4462. +#define MCU_LEDCS_LED_MODE FIELD8(0x1f)
  4463. +#define MCU_LEDCS_POLARITY FIELD8(0x01)
  4464. +
  4465. +/*
  4466. + * HW_CS_CTS_BASE:
  4467. + * Carrier-sense CTS frame base address.
  4468. + * It's where mac stores carrier-sense frame for carrier-sense function.
  4469. + */
  4470. +#define HW_CS_CTS_BASE 0x7700
  4471. +
  4472. +/*
  4473. + * HW_DFS_CTS_BASE:
  4474. + * FS CTS frame base address. It's where mac stores CTS frame for DFS.
  4475. + */
  4476. +#define HW_DFS_CTS_BASE 0x7780
  4477. +
  4478. +/*
  4479. + * TXRX control registers - base address 0x3000
  4480. + */
  4481. +
  4482. +/*
  4483. + * TXRX_CSR1:
  4484. + * rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first..
  4485. + */
  4486. +#define TXRX_CSR1 0x77d0
  4487. +
  4488. +/*
  4489. + * HW_DEBUG_SETTING_BASE:
  4490. + * since NULL frame won't be that long (256 byte)
  4491. + * We steal 16 tail bytes to save debugging settings
  4492. + */
  4493. +#define HW_DEBUG_SETTING_BASE 0x77f0
  4494. +#define HW_DEBUG_SETTING_BASE2 0x7770
  4495. +
  4496. +/*
  4497. + * HW_BEACON_BASE
  4498. + * In order to support maximum 8 MBSS and its maximum length
  4499. + * is 512 bytes for each beacon
  4500. + * Three section discontinue memory segments will be used.
  4501. + * 1. The original region for BCN 0~3
  4502. + * 2. Extract memory from FCE table for BCN 4~5
  4503. + * 3. Extract memory from Pair-wise key table for BCN 6~7
  4504. + * It occupied those memory of wcid 238~253 for BCN 6
  4505. + * and wcid 222~237 for BCN 7
  4506. + *
  4507. + * IMPORTANT NOTE: Not sure why legacy driver does this,
  4508. + * but HW_BEACON_BASE7 is 0x0200 bytes below HW_BEACON_BASE6.
  4509. + */
  4510. +#define HW_BEACON_BASE0 0x7800
  4511. +#define HW_BEACON_BASE1 0x7a00
  4512. +#define HW_BEACON_BASE2 0x7c00
  4513. +#define HW_BEACON_BASE3 0x7e00
  4514. +#define HW_BEACON_BASE4 0x7200
  4515. +#define HW_BEACON_BASE5 0x7400
  4516. +#define HW_BEACON_BASE6 0x5dc0
  4517. +#define HW_BEACON_BASE7 0x5bc0
  4518. +
  4519. +#define HW_BEACON_OFFSET(__index) \
  4520. + ( ((__index) < 4) ? ( HW_BEACON_BASE0 + (__index * 0x0200) ) : \
  4521. + (((__index) < 6) ? ( HW_BEACON_BASE4 + ((__index - 4) * 0x0200) ) : \
  4522. + (HW_BEACON_BASE6 - ((__index - 6) * 0x0200))) )
  4523. +
  4524. +/*
  4525. + * 8051 firmware image.
  4526. + */
  4527. +#define FIRMWARE_RT2870 "rt2870.bin"
  4528. +#define FIRMWARE_IMAGE_BASE 0x3000
  4529. +
  4530. +/*
  4531. + * BBP registers.
  4532. + * The wordsize of the BBP is 8 bits.
  4533. + */
  4534. +
  4535. +/*
  4536. + * BBP 1: TX Antenna
  4537. + */
  4538. +#define BBP1_TX_POWER FIELD8(0x07)
  4539. +#define BBP1_TX_ANTENNA FIELD8(0x18)
  4540. +
  4541. +/*
  4542. + * BBP 3: RX Antenna
  4543. + */
  4544. +#define BBP3_RX_ANTENNA FIELD8(0x18)
  4545. +#define BBP3_HT40_PLUS FIELD8(0x20)
  4546. +
  4547. +/*
  4548. + * BBP 4: Bandwidth
  4549. + */
  4550. +#define BBP4_TX_BF FIELD8(0x01)
  4551. +#define BBP4_BANDWIDTH FIELD8(0x18)
  4552. +
  4553. +/*
  4554. + * RFCSR registers
  4555. + * The wordsize of the RFCSR is 8 bits.
  4556. + */
  4557. +
  4558. +/*
  4559. + * RFCSR 6:
  4560. + */
  4561. +#define RFCSR6_R FIELD8(0x03)
  4562. +
  4563. +/*
  4564. + * RFCSR 7:
  4565. + */
  4566. +#define RFCSR7_RF_TUNING FIELD8(0x01)
  4567. +
  4568. +/*
  4569. + * RFCSR 12:
  4570. + */
  4571. +#define RFCSR12_TX_POWER FIELD8(0x1f)
  4572. +
  4573. +/*
  4574. + * RFCSR 22:
  4575. + */
  4576. +#define RFCSR22_BASEBAND_LOOPBACK FIELD8(0x01)
  4577. +
  4578. +/*
  4579. + * RFCSR 23:
  4580. + */
  4581. +#define RFCSR23_FREQ_OFFSET FIELD8(0x7f)
  4582. +
  4583. +/*
  4584. + * RFCSR 30:
  4585. + */
  4586. +#define RFCSR30_RF_CALIBRATION FIELD8(0x80)
  4587. +
  4588. +/*
  4589. + * RF registers
  4590. + */
  4591. +
  4592. +/*
  4593. + * RF 2
  4594. + */
  4595. +#define RF2_ANTENNA_RX2 FIELD32(0x00000040)
  4596. +#define RF2_ANTENNA_TX1 FIELD32(0x00004000)
  4597. +#define RF2_ANTENNA_RX1 FIELD32(0x00020000)
  4598. +
  4599. +/*
  4600. + * RF 3
  4601. + */
  4602. +#define RF3_TXPOWER_G FIELD32(0x00003e00)
  4603. +#define RF3_TXPOWER_A_7DBM_BOOST FIELD32(0x00000200)
  4604. +#define RF3_TXPOWER_A FIELD32(0x00003c00)
  4605. +
  4606. +/*
  4607. + * RF 4
  4608. + */
  4609. +#define RF4_TXPOWER_G FIELD32(0x000007c0)
  4610. +#define RF4_TXPOWER_A_7DBM_BOOST FIELD32(0x00000040)
  4611. +#define RF4_TXPOWER_A FIELD32(0x00000780)
  4612. +#define RF4_FREQ_OFFSET FIELD32(0x001f8000)
  4613. +#define RF4_HT40 FIELD32(0x00200000)
  4614. +
  4615. +/*
  4616. + * EEPROM content.
  4617. + * The wordsize of the EEPROM is 16 bits.
  4618. + */
  4619. +
  4620. +/*
  4621. + * EEPROM Version
  4622. + */
  4623. +#define EEPROM_VERSION 0x0001
  4624. +#define EEPROM_VERSION_FAE FIELD16(0x00ff)
  4625. +#define EEPROM_VERSION_VERSION FIELD16(0xff00)
  4626. +
  4627. +/*
  4628. + * HW MAC address.
  4629. + */
  4630. +#define EEPROM_MAC_ADDR_0 0x0002
  4631. +#define EEPROM_MAC_ADDR_BYTE0 FIELD16(0x00ff)
  4632. +#define EEPROM_MAC_ADDR_BYTE1 FIELD16(0xff00)
  4633. +#define EEPROM_MAC_ADDR_1 0x0003
  4634. +#define EEPROM_MAC_ADDR_BYTE2 FIELD16(0x00ff)
  4635. +#define EEPROM_MAC_ADDR_BYTE3 FIELD16(0xff00)
  4636. +#define EEPROM_MAC_ADDR_2 0x0004
  4637. +#define EEPROM_MAC_ADDR_BYTE4 FIELD16(0x00ff)
  4638. +#define EEPROM_MAC_ADDR_BYTE5 FIELD16(0xff00)
  4639. +
  4640. +/*
  4641. + * EEPROM ANTENNA config
  4642. + * RXPATH: 1: 1R, 2: 2R, 3: 3R
  4643. + * TXPATH: 1: 1T, 2: 2T
  4644. + */
  4645. +#define EEPROM_ANTENNA 0x001a
  4646. +#define EEPROM_ANTENNA_RXPATH FIELD16(0x000f)
  4647. +#define EEPROM_ANTENNA_TXPATH FIELD16(0x00f0)
  4648. +#define EEPROM_ANTENNA_RF_TYPE FIELD16(0x0f00)
  4649. +
  4650. +/*
  4651. + * EEPROM NIC config
  4652. + * CARDBUS_ACCEL: 0 - enable, 1 - disable
  4653. + */
  4654. +#define EEPROM_NIC 0x001b
  4655. +#define EEPROM_NIC_HW_RADIO FIELD16(0x0001)
  4656. +#define EEPROM_NIC_DYNAMIC_TX_AGC FIELD16(0x0002)
  4657. +#define EEPROM_NIC_EXTERNAL_LNA_BG FIELD16(0x0004)
  4658. +#define EEPROM_NIC_EXTERNAL_LNA_A FIELD16(0x0008)
  4659. +#define EEPROM_NIC_CARDBUS_ACCEL FIELD16(0x0010)
  4660. +#define EEPROM_NIC_BW40M_SB_BG FIELD16(0x0020)
  4661. +#define EEPROM_NIC_BW40M_SB_A FIELD16(0x0040)
  4662. +#define EEPROM_NIC_WPS_PBC FIELD16(0x0080)
  4663. +#define EEPROM_NIC_BW40M_BG FIELD16(0x0100)
  4664. +#define EEPROM_NIC_BW40M_A FIELD16(0x0200)
  4665. +
  4666. +/*
  4667. + * EEPROM frequency
  4668. + */
  4669. +#define EEPROM_FREQ 0x001d
  4670. +#define EEPROM_FREQ_OFFSET FIELD16(0x00ff)
  4671. +#define EEPROM_FREQ_LED_MODE FIELD16(0x7f00)
  4672. +#define EEPROM_FREQ_LED_POLARITY FIELD16(0x1000)
  4673. +
  4674. +/*
  4675. + * EEPROM LED
  4676. + * POLARITY_RDY_G: Polarity RDY_G setting.
  4677. + * POLARITY_RDY_A: Polarity RDY_A setting.
  4678. + * POLARITY_ACT: Polarity ACT setting.
  4679. + * POLARITY_GPIO_0: Polarity GPIO0 setting.
  4680. + * POLARITY_GPIO_1: Polarity GPIO1 setting.
  4681. + * POLARITY_GPIO_2: Polarity GPIO2 setting.
  4682. + * POLARITY_GPIO_3: Polarity GPIO3 setting.
  4683. + * POLARITY_GPIO_4: Polarity GPIO4 setting.
  4684. + * LED_MODE: Led mode.
  4685. + */
  4686. +#define EEPROM_LED1 0x001e
  4687. +#define EEPROM_LED2 0x001f
  4688. +#define EEPROM_LED3 0x0020
  4689. +#define EEPROM_LED_POLARITY_RDY_BG FIELD16(0x0001)
  4690. +#define EEPROM_LED_POLARITY_RDY_A FIELD16(0x0002)
  4691. +#define EEPROM_LED_POLARITY_ACT FIELD16(0x0004)
  4692. +#define EEPROM_LED_POLARITY_GPIO_0 FIELD16(0x0008)
  4693. +#define EEPROM_LED_POLARITY_GPIO_1 FIELD16(0x0010)
  4694. +#define EEPROM_LED_POLARITY_GPIO_2 FIELD16(0x0020)
  4695. +#define EEPROM_LED_POLARITY_GPIO_3 FIELD16(0x0040)
  4696. +#define EEPROM_LED_POLARITY_GPIO_4 FIELD16(0x0080)
  4697. +#define EEPROM_LED_LED_MODE FIELD16(0x1f00)
  4698. +
  4699. +/*
  4700. + * EEPROM LNA
  4701. + */
  4702. +#define EEPROM_LNA 0x0022
  4703. +#define EEPROM_LNA_BG FIELD16(0x00ff)
  4704. +#define EEPROM_LNA_A0 FIELD16(0xff00)
  4705. +
  4706. +/*
  4707. + * EEPROM RSSI BG offset
  4708. + */
  4709. +#define EEPROM_RSSI_BG 0x0023
  4710. +#define EEPROM_RSSI_BG_OFFSET0 FIELD16(0x00ff)
  4711. +#define EEPROM_RSSI_BG_OFFSET1 FIELD16(0xff00)
  4712. +
  4713. +/*
  4714. + * EEPROM RSSI BG2 offset
  4715. + */
  4716. +#define EEPROM_RSSI_BG2 0x0024
  4717. +#define EEPROM_RSSI_BG2_OFFSET2 FIELD16(0x00ff)
  4718. +#define EEPROM_RSSI_BG2_LNA_A1 FIELD16(0xff00)
  4719. +
  4720. +/*
  4721. + * EEPROM RSSI A offset
  4722. + */
  4723. +#define EEPROM_RSSI_A 0x0025
  4724. +#define EEPROM_RSSI_A_OFFSET0 FIELD16(0x00ff)
  4725. +#define EEPROM_RSSI_A_OFFSET1 FIELD16(0xff00)
  4726. +
  4727. +/*
  4728. + * EEPROM RSSI A2 offset
  4729. + */
  4730. +#define EEPROM_RSSI_A2 0x0026
  4731. +#define EEPROM_RSSI_A2_OFFSET2 FIELD16(0x00ff)
  4732. +#define EEPROM_RSSI_A2_LNA_A2 FIELD16(0xff00)
  4733. +
  4734. +/*
  4735. + * EEPROM TXpower delta: 20MHZ AND 40 MHZ use different power.
  4736. + * This is delta in 40MHZ.
  4737. + * VALUE: Tx Power dalta value (MAX=4)
  4738. + * TYPE: 1: Plus the delta value, 0: minus the delta value
  4739. + * TXPOWER: Enable:
  4740. + */
  4741. +#define EEPROM_TXPOWER_DELTA 0x0028
  4742. +#define EEPROM_TXPOWER_DELTA_VALUE FIELD16(0x003f)
  4743. +#define EEPROM_TXPOWER_DELTA_TYPE FIELD16(0x0040)
  4744. +#define EEPROM_TXPOWER_DELTA_TXPOWER FIELD16(0x0080)
  4745. +
  4746. +/*
  4747. + * EEPROM TXPOWER 802.11BG
  4748. + */
  4749. +#define EEPROM_TXPOWER_BG1 0x0029
  4750. +#define EEPROM_TXPOWER_BG2 0x0030
  4751. +#define EEPROM_TXPOWER_BG_SIZE 7
  4752. +#define EEPROM_TXPOWER_BG_1 FIELD16(0x00ff)
  4753. +#define EEPROM_TXPOWER_BG_2 FIELD16(0xff00)
  4754. +
  4755. +/*
  4756. + * EEPROM TXPOWER 802.11A
  4757. + */
  4758. +#define EEPROM_TXPOWER_A1 0x003c
  4759. +#define EEPROM_TXPOWER_A2 0x0053
  4760. +#define EEPROM_TXPOWER_A_SIZE 6
  4761. +#define EEPROM_TXPOWER_A_1 FIELD16(0x00ff)
  4762. +#define EEPROM_TXPOWER_A_2 FIELD16(0xff00)
  4763. +
  4764. +/*
  4765. + * EEPROM TXpower byrate: 20MHZ power
  4766. + */
  4767. +#define EEPROM_TXPOWER_BYRATE 0x006f
  4768. +
  4769. +/*
  4770. + * EEPROM BBP.
  4771. + */
  4772. +#define EEPROM_BBP_START 0x0078
  4773. +#define EEPROM_BBP_SIZE 16
  4774. +#define EEPROM_BBP_VALUE FIELD16(0x00ff)
  4775. +#define EEPROM_BBP_REG_ID FIELD16(0xff00)
  4776. +
  4777. +/*
  4778. + * MCU mailbox commands.
  4779. + */
  4780. +#define MCU_SLEEP 0x30
  4781. +#define MCU_WAKEUP 0x31
  4782. +#define MCU_RADIO_OFF 0x35
  4783. +#define MCU_LED 0x50
  4784. +#define MCU_LED_STRENGTH 0x51
  4785. +#define MCU_LED_1 0x52
  4786. +#define MCU_LED_2 0x53
  4787. +#define MCU_LED_3 0x54
  4788. +#define MCU_RADAR 0x60
  4789. +#define MCU_BOOT_SIGNAL 0x72
  4790. +#define MCU_BBP_SIGNAL 0x80
  4791. +
  4792. +/*
  4793. + * DMA descriptor defines.
  4794. + */
  4795. +#define TXD_DESC_SIZE ( 4 * sizeof(__le32) )
  4796. +#define TXINFO_DESC_SIZE ( 1 * sizeof(__le32) )
  4797. +#define TXWI_DESC_SIZE ( 4 * sizeof(__le32) )
  4798. +#define RXD_DESC_SIZE ( 1 * sizeof(__le32) )
  4799. +#define RXWI_DESC_SIZE ( 4 * sizeof(__le32) )
  4800. +
  4801. +/*
  4802. + * TX descriptor format for TX, PRIO and Beacon Ring.
  4803. + */
  4804. +
  4805. +/*
  4806. + * Word0
  4807. + */
  4808. +#define TXD_W0_SD_PTR0 FIELD32(0xffffffff)
  4809. +
  4810. +/*
  4811. + * Word1
  4812. + */
  4813. +#define TXD_W1_SD_LEN1 FIELD32(0x00003fff)
  4814. +#define TXD_W1_LAST_SEC1 FIELD32(0x00004000)
  4815. +#define TXD_W1_BURST FIELD32(0x00008000)
  4816. +#define TXD_W1_SD_LEN0 FIELD32(0x3fff0000)
  4817. +#define TXD_W1_LAST_SEC0 FIELD32(0x40000000)
  4818. +#define TXD_W1_DMA_DONE FIELD32(0x80000000)
  4819. +
  4820. +/*
  4821. + * Word2
  4822. + */
  4823. +#define TXD_W2_SD_PTR1 FIELD32(0xffffffff)
  4824. +
  4825. +/*
  4826. + * Word3
  4827. + * WIV: Wireless Info Valid. 1: Driver filled WI, 0: DMA needs to copy WI
  4828. + * QSEL: Select on-chip FIFO ID for 2nd-stage output scheduler.
  4829. + * 0:MGMT, 1:HCCA 2:EDCA
  4830. + */
  4831. +#define TXD_W3_WIV FIELD32(0x01000000)
  4832. +#define TXD_W3_QSEL FIELD32(0x06000000)
  4833. +#define TXD_W3_TCO FIELD32(0x20000000)
  4834. +#define TXD_W3_UCO FIELD32(0x40000000)
  4835. +#define TXD_W3_ICO FIELD32(0x80000000)
  4836. +
  4837. +/*
  4838. + * TX Info structure
  4839. + */
  4840. +
  4841. +/*
  4842. + * Word0
  4843. + * WIV: Wireless Info Valid. 1: Driver filled WI, 0: DMA needs to copy WI
  4844. + * QSEL: Select on-chip FIFO ID for 2nd-stage output scheduler.
  4845. + * 0:MGMT, 1:HCCA 2:EDCA
  4846. + * USB_DMA_NEXT_VALID: Used ONLY in USB bulk Aggregation, NextValid
  4847. + * DMA_TX_BURST: used ONLY in USB bulk Aggregation.
  4848. + * Force USB DMA transmit frame from current selected endpoint
  4849. + */
  4850. +#define TXINFO_W0_USB_DMA_TX_PKT_LEN FIELD32(0x0000ffff)
  4851. +#define TXINFO_W0_WIV FIELD32(0x01000000)
  4852. +#define TXINFO_W0_QSEL FIELD32(0x06000000)
  4853. +#define TXINFO_W0_SW_USE_LAST_ROUND FIELD32(0x08000000)
  4854. +#define TXINFO_W0_USB_DMA_NEXT_VALID FIELD32(0x40000000)
  4855. +#define TXINFO_W0_USB_DMA_TX_BURST FIELD32(0x80000000)
  4856. +
  4857. +/*
  4858. + * TX WI structure
  4859. + */
  4860. +
  4861. +/*
  4862. + * Word0
  4863. + * FRAG: 1 To inform TKIP engine this is a fragment.
  4864. + * MIMO_PS: The remote peer is in dynamic MIMO-PS mode
  4865. + * TX_OP: 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs
  4866. + * BW: Channel bandwidth 20MHz or 40 MHz
  4867. + * STBC: 1: STBC support MCS =0-7, 2,3 : RESERVED
  4868. + */
  4869. +#define TXWI_W0_FRAG FIELD32(0x00000001)
  4870. +#define TXWI_W0_MIMO_PS FIELD32(0x00000002)
  4871. +#define TXWI_W0_CF_ACK FIELD32(0x00000004)
  4872. +#define TXWI_W0_TS FIELD32(0x00000008)
  4873. +#define TXWI_W0_AMPDU FIELD32(0x00000010)
  4874. +#define TXWI_W0_MPDU_DENSITY FIELD32(0x000000e0)
  4875. +#define TXWI_W0_TX_OP FIELD32(0x00000300)
  4876. +#define TXWI_W0_MCS FIELD32(0x007f0000)
  4877. +#define TXWI_W0_BW FIELD32(0x00800000)
  4878. +#define TXWI_W0_SHORT_GI FIELD32(0x01000000)
  4879. +#define TXWI_W0_STBC FIELD32(0x06000000)
  4880. +#define TXWI_W0_IFS FIELD32(0x08000000)
  4881. +#define TXWI_W0_PHYMODE FIELD32(0xc0000000)
  4882. +
  4883. +/*
  4884. + * Word1
  4885. + */
  4886. +#define TXWI_W1_ACK FIELD32(0x00000001)
  4887. +#define TXWI_W1_NSEQ FIELD32(0x00000002)
  4888. +#define TXWI_W1_BW_WIN_SIZE FIELD32(0x000000fc)
  4889. +#define TXWI_W1_WIRELESS_CLI_ID FIELD32(0x0000ff00)
  4890. +#define TXWI_W1_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
  4891. +#define TXWI_W1_PACKETID FIELD32(0xf0000000)
  4892. +
  4893. +/*
  4894. + * Word2
  4895. + */
  4896. +#define TXWI_W2_IV FIELD32(0xffffffff)
  4897. +
  4898. +/*
  4899. + * Word3
  4900. + */
  4901. +#define TXWI_W3_EIV FIELD32(0xffffffff)
  4902. +
  4903. +/*
  4904. + * RX descriptor format for RX Ring.
  4905. + */
  4906. +
  4907. +/*
  4908. + * Word0
  4909. + * UNICAST_TO_ME: This RX frame is unicast to me.
  4910. + * MULTICAST: This is a multicast frame.
  4911. + * BROADCAST: This is a broadcast frame.
  4912. + * MY_BSS: this frame belongs to the same BSSID.
  4913. + * CRC_ERROR: CRC error.
  4914. + * CIPHER_ERROR: 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid.
  4915. + * AMSDU: rx with 802.3 header, not 802.11 header.
  4916. + */
  4917. +
  4918. +#define RXD_W0_BA FIELD32(0x00000001)
  4919. +#define RXD_W0_DATA FIELD32(0x00000002)
  4920. +#define RXD_W0_NULLDATA FIELD32(0x00000004)
  4921. +#define RXD_W0_FRAG FIELD32(0x00000008)
  4922. +#define RXD_W0_UNICAST_TO_ME FIELD32(0x00000010)
  4923. +#define RXD_W0_MULTICAST FIELD32(0x00000020)
  4924. +#define RXD_W0_BROADCAST FIELD32(0x00000040)
  4925. +#define RXD_W0_MY_BSS FIELD32(0x00000080)
  4926. +#define RXD_W0_CRC_ERROR FIELD32(0x00000100)
  4927. +#define RXD_W0_CIPHER_ERROR FIELD32(0x00000600)
  4928. +#define RXD_W0_AMSDU FIELD32(0x00000800)
  4929. +#define RXD_W0_HTC FIELD32(0x00001000)
  4930. +#define RXD_W0_RSSI FIELD32(0x00002000)
  4931. +#define RXD_W0_L2PAD FIELD32(0x00004000)
  4932. +#define RXD_W0_AMPDU FIELD32(0x00008000)
  4933. +#define RXD_W0_DECRYPTED FIELD32(0x00010000)
  4934. +#define RXD_W0_PLCP_RSSI FIELD32(0x00020000)
  4935. +#define RXD_W0_CIPHER_ALG FIELD32(0x00040000)
  4936. +#define RXD_W0_LAST_AMSDU FIELD32(0x00080000)
  4937. +#define RXD_W0_PLCP_SIGNAL FIELD32(0xfff00000)
  4938. +
  4939. +/*
  4940. + * RX WI structure
  4941. + */
  4942. +
  4943. +/*
  4944. + * Word0
  4945. + */
  4946. +#define RXWI_W0_WIRELESS_CLI_ID FIELD32(0x000000ff)
  4947. +#define RXWI_W0_KEY_INDEX FIELD32(0x00000300)
  4948. +#define RXWI_W0_BSSID FIELD32(0x00001c00)
  4949. +#define RXWI_W0_UDF FIELD32(0x0000e000)
  4950. +#define RXWI_W0_MPDU_TOTAL_BYTE_COUNT FIELD32(0x0fff0000)
  4951. +#define RXWI_W0_TID FIELD32(0xf0000000)
  4952. +
  4953. +/*
  4954. + * Word1
  4955. + */
  4956. +#define RXWI_W1_FRAG FIELD32(0x0000000f)
  4957. +#define RXWI_W1_SEQUENCE FIELD32(0x0000fff0)
  4958. +#define RXWI_W1_MCS FIELD32(0x007f0000)
  4959. +#define RXWI_W1_BW FIELD32(0x00800000)
  4960. +#define RXWI_W1_SHORT_GI FIELD32(0x01000000)
  4961. +#define RXWI_W1_STBC FIELD32(0x06000000)
  4962. +#define RXWI_W1_PHYMODE FIELD32(0xc0000000)
  4963. +
  4964. +/*
  4965. + * Word2
  4966. + */
  4967. +#define RXWI_W2_RSSI0 FIELD32(0x000000ff)
  4968. +#define RXWI_W2_RSSI1 FIELD32(0x0000ff00)
  4969. +#define RXWI_W2_RSSI2 FIELD32(0x00ff0000)
  4970. +
  4971. +/*
  4972. + * Word3
  4973. + */
  4974. +#define RXWI_W3_SNR0 FIELD32(0x000000ff)
  4975. +#define RXWI_W3_SNR1 FIELD32(0x0000ff00)
  4976. +
  4977. +/*
  4978. + * Macro's for converting txpower from EEPROM to mac80211 value
  4979. + * and from mac80211 value to register value.
  4980. + */
  4981. +#define MIN_G_TXPOWER 0
  4982. +#define MIN_A_TXPOWER -7
  4983. +#define MAX_G_TXPOWER 31
  4984. +#define MAX_A_TXPOWER 15
  4985. +#define DEFAULT_TXPOWER 5
  4986. +
  4987. +#define TXPOWER_G_FROM_DEV(__txpower) \
  4988. + ((__txpower) > MAX_G_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
  4989. +
  4990. +#define TXPOWER_G_TO_DEV(__txpower) \
  4991. + clamp_t(char, __txpower, MIN_G_TXPOWER, MAX_G_TXPOWER)
  4992. +
  4993. +#define TXPOWER_A_FROM_DEV(__txpower) \
  4994. + ((__txpower) > MAX_A_TXPOWER) ? DEFAULT_TXPOWER : (__txpower)
  4995. +
  4996. +#define TXPOWER_A_TO_DEV(__txpower) \
  4997. + clamp_t(char, __txpower, MIN_A_TXPOWER, MAX_A_TXPOWER)
  4998. +
  4999. +#endif /* RT2800USB_H */
  5000. --- a/drivers/net/wireless/rt2x00/rt2x00.h
  5001. +++ b/drivers/net/wireless/rt2x00/rt2x00.h
  5002. @@ -144,6 +144,7 @@ struct rt2x00_chip {
  5003. #define RT2890D 0x0781 /* 2.4GHz, 5GHz PCIe */
  5004. #define RT2880 0x2880 /* WSOC */
  5005. #define RT3052 0x3052 /* WSOC */
  5006. +#define RT2870 0x1600
  5007. u16 rf;
  5008. u32 rev;
  5009. @@ -788,6 +789,12 @@ struct rt2x00_dev {
  5010. u8 freq_offset;
  5011. /*
  5012. + * Calibration information (for rt2800usb).
  5013. + */
  5014. + u8 calibration_bw20;
  5015. + u8 calibration_bw40;
  5016. +
  5017. + /*
  5018. * Low level statistics which will have
  5019. * to be kept up to date while device is running.
  5020. */