mwl8k.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018
  1. /*
  2. * drivers/net/wireless/mwl8k.c
  3. * Driver for Marvell TOPDOG 802.11 Wireless cards
  4. *
  5. * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/sched.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/list.h>
  17. #include <linux/pci.h>
  18. #include <linux/delay.h>
  19. #include <linux/completion.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/slab.h>
  22. #include <net/mac80211.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/firmware.h>
  25. #include <linux/workqueue.h>
  26. #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
  27. #define MWL8K_NAME KBUILD_MODNAME
  28. #define MWL8K_VERSION "0.12"
  29. /* Module parameters */
  30. static unsigned ap_mode_default;
  31. module_param(ap_mode_default, bool, 0);
  32. MODULE_PARM_DESC(ap_mode_default,
  33. "Set to 1 to make ap mode the default instead of sta mode");
  34. /* Register definitions */
  35. #define MWL8K_HIU_GEN_PTR 0x00000c10
  36. #define MWL8K_MODE_STA 0x0000005a
  37. #define MWL8K_MODE_AP 0x000000a5
  38. #define MWL8K_HIU_INT_CODE 0x00000c14
  39. #define MWL8K_FWSTA_READY 0xf0f1f2f4
  40. #define MWL8K_FWAP_READY 0xf1f2f4a5
  41. #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
  42. #define MWL8K_HIU_SCRATCH 0x00000c40
  43. /* Host->device communications */
  44. #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
  45. #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
  46. #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
  47. #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
  48. #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
  49. #define MWL8K_H2A_INT_DUMMY (1 << 20)
  50. #define MWL8K_H2A_INT_RESET (1 << 15)
  51. #define MWL8K_H2A_INT_DOORBELL (1 << 1)
  52. #define MWL8K_H2A_INT_PPA_READY (1 << 0)
  53. /* Device->host communications */
  54. #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
  55. #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
  56. #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
  57. #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
  58. #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
  59. #define MWL8K_A2H_INT_DUMMY (1 << 20)
  60. #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
  61. #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
  62. #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
  63. #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
  64. #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
  65. #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
  66. #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
  67. #define MWL8K_A2H_INT_RX_READY (1 << 1)
  68. #define MWL8K_A2H_INT_TX_DONE (1 << 0)
  69. #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
  70. MWL8K_A2H_INT_CHNL_SWITCHED | \
  71. MWL8K_A2H_INT_QUEUE_EMPTY | \
  72. MWL8K_A2H_INT_RADAR_DETECT | \
  73. MWL8K_A2H_INT_RADIO_ON | \
  74. MWL8K_A2H_INT_RADIO_OFF | \
  75. MWL8K_A2H_INT_MAC_EVENT | \
  76. MWL8K_A2H_INT_OPC_DONE | \
  77. MWL8K_A2H_INT_RX_READY | \
  78. MWL8K_A2H_INT_TX_DONE)
  79. #define MWL8K_RX_QUEUES 1
  80. #define MWL8K_TX_QUEUES 4
  81. struct rxd_ops {
  82. int rxd_size;
  83. void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
  84. void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
  85. int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
  86. __le16 *qos, s8 *noise);
  87. };
  88. struct mwl8k_device_info {
  89. char *part_name;
  90. char *helper_image;
  91. char *fw_image_sta;
  92. char *fw_image_ap;
  93. struct rxd_ops *ap_rxd_ops;
  94. u32 fw_api_ap;
  95. };
  96. struct mwl8k_rx_queue {
  97. int rxd_count;
  98. /* hw receives here */
  99. int head;
  100. /* refill descs here */
  101. int tail;
  102. void *rxd;
  103. dma_addr_t rxd_dma;
  104. struct {
  105. struct sk_buff *skb;
  106. DEFINE_DMA_UNMAP_ADDR(dma);
  107. } *buf;
  108. };
  109. struct mwl8k_tx_queue {
  110. /* hw transmits here */
  111. int head;
  112. /* sw appends here */
  113. int tail;
  114. unsigned int len;
  115. struct mwl8k_tx_desc *txd;
  116. dma_addr_t txd_dma;
  117. struct sk_buff **skb;
  118. };
  119. struct mwl8k_priv {
  120. struct ieee80211_hw *hw;
  121. struct pci_dev *pdev;
  122. struct mwl8k_device_info *device_info;
  123. void __iomem *sram;
  124. void __iomem *regs;
  125. /* firmware */
  126. const struct firmware *fw_helper;
  127. const struct firmware *fw_ucode;
  128. /* hardware/firmware parameters */
  129. bool ap_fw;
  130. struct rxd_ops *rxd_ops;
  131. struct ieee80211_supported_band band_24;
  132. struct ieee80211_channel channels_24[14];
  133. struct ieee80211_rate rates_24[14];
  134. struct ieee80211_supported_band band_50;
  135. struct ieee80211_channel channels_50[4];
  136. struct ieee80211_rate rates_50[9];
  137. u32 ap_macids_supported;
  138. u32 sta_macids_supported;
  139. /* firmware access */
  140. struct mutex fw_mutex;
  141. struct task_struct *fw_mutex_owner;
  142. int fw_mutex_depth;
  143. struct completion *hostcmd_wait;
  144. /* lock held over TX and TX reap */
  145. spinlock_t tx_lock;
  146. /* TX quiesce completion, protected by fw_mutex and tx_lock */
  147. struct completion *tx_wait;
  148. /* List of interfaces. */
  149. u32 macids_used;
  150. struct list_head vif_list;
  151. /* power management status cookie from firmware */
  152. u32 *cookie;
  153. dma_addr_t cookie_dma;
  154. u16 num_mcaddrs;
  155. u8 hw_rev;
  156. u32 fw_rev;
  157. /*
  158. * Running count of TX packets in flight, to avoid
  159. * iterating over the transmit rings each time.
  160. */
  161. int pending_tx_pkts;
  162. struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
  163. struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
  164. bool radio_on;
  165. bool radio_short_preamble;
  166. bool sniffer_enabled;
  167. bool wmm_enabled;
  168. /* XXX need to convert this to handle multiple interfaces */
  169. bool capture_beacon;
  170. u8 capture_bssid[ETH_ALEN];
  171. struct sk_buff *beacon_skb;
  172. /*
  173. * This FJ worker has to be global as it is scheduled from the
  174. * RX handler. At this point we don't know which interface it
  175. * belongs to until the list of bssids waiting to complete join
  176. * is checked.
  177. */
  178. struct work_struct finalize_join_worker;
  179. /* Tasklet to perform TX reclaim. */
  180. struct tasklet_struct poll_tx_task;
  181. /* Tasklet to perform RX. */
  182. struct tasklet_struct poll_rx_task;
  183. /* Most recently reported noise in dBm */
  184. s8 noise;
  185. /*
  186. * preserve the queue configurations so they can be restored if/when
  187. * the firmware image is swapped.
  188. */
  189. struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
  190. /* async firmware loading state */
  191. unsigned fw_state;
  192. char *fw_pref;
  193. char *fw_alt;
  194. struct completion firmware_loading_complete;
  195. };
  196. #define MAX_WEP_KEY_LEN 13
  197. #define NUM_WEP_KEYS 4
  198. /* Per interface specific private data */
  199. struct mwl8k_vif {
  200. struct list_head list;
  201. struct ieee80211_vif *vif;
  202. /* Firmware macid for this vif. */
  203. int macid;
  204. /* Non AMPDU sequence number assigned by driver. */
  205. u16 seqno;
  206. /* Saved WEP keys */
  207. struct {
  208. u8 enabled;
  209. u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
  210. } wep_key_conf[NUM_WEP_KEYS];
  211. /* BSSID */
  212. u8 bssid[ETH_ALEN];
  213. /* A flag to indicate is HW crypto is enabled for this bssid */
  214. bool is_hw_crypto_enabled;
  215. };
  216. #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
  217. #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
  218. struct mwl8k_sta {
  219. /* Index into station database. Returned by UPDATE_STADB. */
  220. u8 peer_id;
  221. };
  222. #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
  223. static const struct ieee80211_channel mwl8k_channels_24[] = {
  224. { .center_freq = 2412, .hw_value = 1, },
  225. { .center_freq = 2417, .hw_value = 2, },
  226. { .center_freq = 2422, .hw_value = 3, },
  227. { .center_freq = 2427, .hw_value = 4, },
  228. { .center_freq = 2432, .hw_value = 5, },
  229. { .center_freq = 2437, .hw_value = 6, },
  230. { .center_freq = 2442, .hw_value = 7, },
  231. { .center_freq = 2447, .hw_value = 8, },
  232. { .center_freq = 2452, .hw_value = 9, },
  233. { .center_freq = 2457, .hw_value = 10, },
  234. { .center_freq = 2462, .hw_value = 11, },
  235. { .center_freq = 2467, .hw_value = 12, },
  236. { .center_freq = 2472, .hw_value = 13, },
  237. { .center_freq = 2484, .hw_value = 14, },
  238. };
  239. static const struct ieee80211_rate mwl8k_rates_24[] = {
  240. { .bitrate = 10, .hw_value = 2, },
  241. { .bitrate = 20, .hw_value = 4, },
  242. { .bitrate = 55, .hw_value = 11, },
  243. { .bitrate = 110, .hw_value = 22, },
  244. { .bitrate = 220, .hw_value = 44, },
  245. { .bitrate = 60, .hw_value = 12, },
  246. { .bitrate = 90, .hw_value = 18, },
  247. { .bitrate = 120, .hw_value = 24, },
  248. { .bitrate = 180, .hw_value = 36, },
  249. { .bitrate = 240, .hw_value = 48, },
  250. { .bitrate = 360, .hw_value = 72, },
  251. { .bitrate = 480, .hw_value = 96, },
  252. { .bitrate = 540, .hw_value = 108, },
  253. { .bitrate = 720, .hw_value = 144, },
  254. };
  255. static const struct ieee80211_channel mwl8k_channels_50[] = {
  256. { .center_freq = 5180, .hw_value = 36, },
  257. { .center_freq = 5200, .hw_value = 40, },
  258. { .center_freq = 5220, .hw_value = 44, },
  259. { .center_freq = 5240, .hw_value = 48, },
  260. };
  261. static const struct ieee80211_rate mwl8k_rates_50[] = {
  262. { .bitrate = 60, .hw_value = 12, },
  263. { .bitrate = 90, .hw_value = 18, },
  264. { .bitrate = 120, .hw_value = 24, },
  265. { .bitrate = 180, .hw_value = 36, },
  266. { .bitrate = 240, .hw_value = 48, },
  267. { .bitrate = 360, .hw_value = 72, },
  268. { .bitrate = 480, .hw_value = 96, },
  269. { .bitrate = 540, .hw_value = 108, },
  270. { .bitrate = 720, .hw_value = 144, },
  271. };
  272. /* Set or get info from Firmware */
  273. #define MWL8K_CMD_GET 0x0000
  274. #define MWL8K_CMD_SET 0x0001
  275. #define MWL8K_CMD_SET_LIST 0x0002
  276. /* Firmware command codes */
  277. #define MWL8K_CMD_CODE_DNLD 0x0001
  278. #define MWL8K_CMD_GET_HW_SPEC 0x0003
  279. #define MWL8K_CMD_SET_HW_SPEC 0x0004
  280. #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
  281. #define MWL8K_CMD_GET_STAT 0x0014
  282. #define MWL8K_CMD_RADIO_CONTROL 0x001c
  283. #define MWL8K_CMD_RF_TX_POWER 0x001e
  284. #define MWL8K_CMD_TX_POWER 0x001f
  285. #define MWL8K_CMD_RF_ANTENNA 0x0020
  286. #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
  287. #define MWL8K_CMD_SET_PRE_SCAN 0x0107
  288. #define MWL8K_CMD_SET_POST_SCAN 0x0108
  289. #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
  290. #define MWL8K_CMD_SET_AID 0x010d
  291. #define MWL8K_CMD_SET_RATE 0x0110
  292. #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
  293. #define MWL8K_CMD_RTS_THRESHOLD 0x0113
  294. #define MWL8K_CMD_SET_SLOT 0x0114
  295. #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
  296. #define MWL8K_CMD_SET_WMM_MODE 0x0123
  297. #define MWL8K_CMD_MIMO_CONFIG 0x0125
  298. #define MWL8K_CMD_USE_FIXED_RATE 0x0126
  299. #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
  300. #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
  301. #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
  302. #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
  303. #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
  304. #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
  305. #define MWL8K_CMD_UPDATE_STADB 0x1123
  306. static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
  307. {
  308. u16 command = le16_to_cpu(cmd);
  309. #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
  310. snprintf(buf, bufsize, "%s", #x);\
  311. return buf;\
  312. } while (0)
  313. switch (command & ~0x8000) {
  314. MWL8K_CMDNAME(CODE_DNLD);
  315. MWL8K_CMDNAME(GET_HW_SPEC);
  316. MWL8K_CMDNAME(SET_HW_SPEC);
  317. MWL8K_CMDNAME(MAC_MULTICAST_ADR);
  318. MWL8K_CMDNAME(GET_STAT);
  319. MWL8K_CMDNAME(RADIO_CONTROL);
  320. MWL8K_CMDNAME(RF_TX_POWER);
  321. MWL8K_CMDNAME(TX_POWER);
  322. MWL8K_CMDNAME(RF_ANTENNA);
  323. MWL8K_CMDNAME(SET_BEACON);
  324. MWL8K_CMDNAME(SET_PRE_SCAN);
  325. MWL8K_CMDNAME(SET_POST_SCAN);
  326. MWL8K_CMDNAME(SET_RF_CHANNEL);
  327. MWL8K_CMDNAME(SET_AID);
  328. MWL8K_CMDNAME(SET_RATE);
  329. MWL8K_CMDNAME(SET_FINALIZE_JOIN);
  330. MWL8K_CMDNAME(RTS_THRESHOLD);
  331. MWL8K_CMDNAME(SET_SLOT);
  332. MWL8K_CMDNAME(SET_EDCA_PARAMS);
  333. MWL8K_CMDNAME(SET_WMM_MODE);
  334. MWL8K_CMDNAME(MIMO_CONFIG);
  335. MWL8K_CMDNAME(USE_FIXED_RATE);
  336. MWL8K_CMDNAME(ENABLE_SNIFFER);
  337. MWL8K_CMDNAME(SET_MAC_ADDR);
  338. MWL8K_CMDNAME(SET_RATEADAPT_MODE);
  339. MWL8K_CMDNAME(BSS_START);
  340. MWL8K_CMDNAME(SET_NEW_STN);
  341. MWL8K_CMDNAME(UPDATE_ENCRYPTION);
  342. MWL8K_CMDNAME(UPDATE_STADB);
  343. default:
  344. snprintf(buf, bufsize, "0x%x", cmd);
  345. }
  346. #undef MWL8K_CMDNAME
  347. return buf;
  348. }
  349. /* Hardware and firmware reset */
  350. static void mwl8k_hw_reset(struct mwl8k_priv *priv)
  351. {
  352. iowrite32(MWL8K_H2A_INT_RESET,
  353. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  354. iowrite32(MWL8K_H2A_INT_RESET,
  355. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  356. msleep(20);
  357. }
  358. /* Release fw image */
  359. static void mwl8k_release_fw(const struct firmware **fw)
  360. {
  361. if (*fw == NULL)
  362. return;
  363. release_firmware(*fw);
  364. *fw = NULL;
  365. }
  366. static void mwl8k_release_firmware(struct mwl8k_priv *priv)
  367. {
  368. mwl8k_release_fw(&priv->fw_ucode);
  369. mwl8k_release_fw(&priv->fw_helper);
  370. }
  371. /* states for asynchronous f/w loading */
  372. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
  373. enum {
  374. FW_STATE_INIT = 0,
  375. FW_STATE_LOADING_PREF,
  376. FW_STATE_LOADING_ALT,
  377. FW_STATE_ERROR,
  378. };
  379. /* Request fw image */
  380. static int mwl8k_request_fw(struct mwl8k_priv *priv,
  381. const char *fname, const struct firmware **fw,
  382. bool nowait)
  383. {
  384. /* release current image */
  385. if (*fw != NULL)
  386. mwl8k_release_fw(fw);
  387. if (nowait)
  388. return request_firmware_nowait(THIS_MODULE, 1, fname,
  389. &priv->pdev->dev, GFP_KERNEL,
  390. priv, mwl8k_fw_state_machine);
  391. else
  392. return request_firmware(fw, fname, &priv->pdev->dev);
  393. }
  394. static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
  395. bool nowait)
  396. {
  397. struct mwl8k_device_info *di = priv->device_info;
  398. int rc;
  399. if (di->helper_image != NULL) {
  400. if (nowait)
  401. rc = mwl8k_request_fw(priv, di->helper_image,
  402. &priv->fw_helper, true);
  403. else
  404. rc = mwl8k_request_fw(priv, di->helper_image,
  405. &priv->fw_helper, false);
  406. if (rc)
  407. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  408. pci_name(priv->pdev), di->helper_image);
  409. if (rc || nowait)
  410. return rc;
  411. }
  412. if (nowait) {
  413. /*
  414. * if we get here, no helper image is needed. Skip the
  415. * FW_STATE_INIT state.
  416. */
  417. priv->fw_state = FW_STATE_LOADING_PREF;
  418. rc = mwl8k_request_fw(priv, fw_image,
  419. &priv->fw_ucode,
  420. true);
  421. } else
  422. rc = mwl8k_request_fw(priv, fw_image,
  423. &priv->fw_ucode, false);
  424. if (rc) {
  425. printk(KERN_ERR "%s: Error requesting firmware file %s\n",
  426. pci_name(priv->pdev), fw_image);
  427. mwl8k_release_fw(&priv->fw_helper);
  428. return rc;
  429. }
  430. return 0;
  431. }
  432. struct mwl8k_cmd_pkt {
  433. __le16 code;
  434. __le16 length;
  435. __u8 seq_num;
  436. __u8 macid;
  437. __le16 result;
  438. char payload[0];
  439. } __packed;
  440. /*
  441. * Firmware loading.
  442. */
  443. static int
  444. mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
  445. {
  446. void __iomem *regs = priv->regs;
  447. dma_addr_t dma_addr;
  448. int loops;
  449. dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
  450. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  451. return -ENOMEM;
  452. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  453. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  454. iowrite32(MWL8K_H2A_INT_DOORBELL,
  455. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  456. iowrite32(MWL8K_H2A_INT_DUMMY,
  457. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  458. loops = 1000;
  459. do {
  460. u32 int_code;
  461. int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
  462. if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
  463. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  464. break;
  465. }
  466. cond_resched();
  467. udelay(1);
  468. } while (--loops);
  469. pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
  470. return loops ? 0 : -ETIMEDOUT;
  471. }
  472. static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
  473. const u8 *data, size_t length)
  474. {
  475. struct mwl8k_cmd_pkt *cmd;
  476. int done;
  477. int rc = 0;
  478. cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
  479. if (cmd == NULL)
  480. return -ENOMEM;
  481. cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
  482. cmd->seq_num = 0;
  483. cmd->macid = 0;
  484. cmd->result = 0;
  485. done = 0;
  486. while (length) {
  487. int block_size = length > 256 ? 256 : length;
  488. memcpy(cmd->payload, data + done, block_size);
  489. cmd->length = cpu_to_le16(block_size);
  490. rc = mwl8k_send_fw_load_cmd(priv, cmd,
  491. sizeof(*cmd) + block_size);
  492. if (rc)
  493. break;
  494. done += block_size;
  495. length -= block_size;
  496. }
  497. if (!rc) {
  498. cmd->length = 0;
  499. rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
  500. }
  501. kfree(cmd);
  502. return rc;
  503. }
  504. static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
  505. const u8 *data, size_t length)
  506. {
  507. unsigned char *buffer;
  508. int may_continue, rc = 0;
  509. u32 done, prev_block_size;
  510. buffer = kmalloc(1024, GFP_KERNEL);
  511. if (buffer == NULL)
  512. return -ENOMEM;
  513. done = 0;
  514. prev_block_size = 0;
  515. may_continue = 1000;
  516. while (may_continue > 0) {
  517. u32 block_size;
  518. block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
  519. if (block_size & 1) {
  520. block_size &= ~1;
  521. may_continue--;
  522. } else {
  523. done += prev_block_size;
  524. length -= prev_block_size;
  525. }
  526. if (block_size > 1024 || block_size > length) {
  527. rc = -EOVERFLOW;
  528. break;
  529. }
  530. if (length == 0) {
  531. rc = 0;
  532. break;
  533. }
  534. if (block_size == 0) {
  535. rc = -EPROTO;
  536. may_continue--;
  537. udelay(1);
  538. continue;
  539. }
  540. prev_block_size = block_size;
  541. memcpy(buffer, data + done, block_size);
  542. rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
  543. if (rc)
  544. break;
  545. }
  546. if (!rc && length != 0)
  547. rc = -EREMOTEIO;
  548. kfree(buffer);
  549. return rc;
  550. }
  551. static int mwl8k_load_firmware(struct ieee80211_hw *hw)
  552. {
  553. struct mwl8k_priv *priv = hw->priv;
  554. const struct firmware *fw = priv->fw_ucode;
  555. int rc;
  556. int loops;
  557. if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
  558. const struct firmware *helper = priv->fw_helper;
  559. if (helper == NULL) {
  560. printk(KERN_ERR "%s: helper image needed but none "
  561. "given\n", pci_name(priv->pdev));
  562. return -EINVAL;
  563. }
  564. rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
  565. if (rc) {
  566. printk(KERN_ERR "%s: unable to load firmware "
  567. "helper image\n", pci_name(priv->pdev));
  568. return rc;
  569. }
  570. msleep(5);
  571. rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
  572. } else {
  573. rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
  574. }
  575. if (rc) {
  576. printk(KERN_ERR "%s: unable to load firmware image\n",
  577. pci_name(priv->pdev));
  578. return rc;
  579. }
  580. iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
  581. loops = 500000;
  582. do {
  583. u32 ready_code;
  584. ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  585. if (ready_code == MWL8K_FWAP_READY) {
  586. priv->ap_fw = 1;
  587. break;
  588. } else if (ready_code == MWL8K_FWSTA_READY) {
  589. priv->ap_fw = 0;
  590. break;
  591. }
  592. cond_resched();
  593. udelay(1);
  594. } while (--loops);
  595. return loops ? 0 : -ETIMEDOUT;
  596. }
  597. /* DMA header used by firmware and hardware. */
  598. struct mwl8k_dma_data {
  599. __le16 fwlen;
  600. struct ieee80211_hdr wh;
  601. char data[0];
  602. } __packed;
  603. /* Routines to add/remove DMA header from skb. */
  604. static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
  605. {
  606. struct mwl8k_dma_data *tr;
  607. int hdrlen;
  608. tr = (struct mwl8k_dma_data *)skb->data;
  609. hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
  610. if (hdrlen != sizeof(tr->wh)) {
  611. if (ieee80211_is_data_qos(tr->wh.frame_control)) {
  612. memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
  613. *((__le16 *)(tr->data - 2)) = qos;
  614. } else {
  615. memmove(tr->data - hdrlen, &tr->wh, hdrlen);
  616. }
  617. }
  618. if (hdrlen != sizeof(*tr))
  619. skb_pull(skb, sizeof(*tr) - hdrlen);
  620. }
  621. static void
  622. mwl8k_add_dma_header(struct sk_buff *skb, int tail_pad)
  623. {
  624. struct ieee80211_hdr *wh;
  625. int hdrlen;
  626. int reqd_hdrlen;
  627. struct mwl8k_dma_data *tr;
  628. /*
  629. * Add a firmware DMA header; the firmware requires that we
  630. * present a 2-byte payload length followed by a 4-address
  631. * header (without QoS field), followed (optionally) by any
  632. * WEP/ExtIV header (but only filled in for CCMP).
  633. */
  634. wh = (struct ieee80211_hdr *)skb->data;
  635. hdrlen = ieee80211_hdrlen(wh->frame_control);
  636. reqd_hdrlen = sizeof(*tr);
  637. if (hdrlen != reqd_hdrlen)
  638. skb_push(skb, reqd_hdrlen - hdrlen);
  639. if (ieee80211_is_data_qos(wh->frame_control))
  640. hdrlen -= IEEE80211_QOS_CTL_LEN;
  641. tr = (struct mwl8k_dma_data *)skb->data;
  642. if (wh != &tr->wh)
  643. memmove(&tr->wh, wh, hdrlen);
  644. if (hdrlen != sizeof(tr->wh))
  645. memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
  646. /*
  647. * Firmware length is the length of the fully formed "802.11
  648. * payload". That is, everything except for the 802.11 header.
  649. * This includes all crypto material including the MIC.
  650. */
  651. tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
  652. }
  653. static void mwl8k_encapsulate_tx_frame(struct sk_buff *skb)
  654. {
  655. struct ieee80211_hdr *wh;
  656. struct ieee80211_tx_info *tx_info;
  657. struct ieee80211_key_conf *key_conf;
  658. int data_pad;
  659. wh = (struct ieee80211_hdr *)skb->data;
  660. tx_info = IEEE80211_SKB_CB(skb);
  661. key_conf = NULL;
  662. if (ieee80211_is_data(wh->frame_control))
  663. key_conf = tx_info->control.hw_key;
  664. /*
  665. * Make sure the packet header is in the DMA header format (4-address
  666. * without QoS), the necessary crypto padding between the header and the
  667. * payload has already been provided by mac80211, but it doesn't add tail
  668. * padding when HW crypto is enabled.
  669. *
  670. * We have the following trailer padding requirements:
  671. * - WEP: 4 trailer bytes (ICV)
  672. * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
  673. * - CCMP: 8 trailer bytes (MIC)
  674. */
  675. data_pad = 0;
  676. if (key_conf != NULL) {
  677. switch (key_conf->cipher) {
  678. case WLAN_CIPHER_SUITE_WEP40:
  679. case WLAN_CIPHER_SUITE_WEP104:
  680. data_pad = 4;
  681. break;
  682. case WLAN_CIPHER_SUITE_TKIP:
  683. data_pad = 12;
  684. break;
  685. case WLAN_CIPHER_SUITE_CCMP:
  686. data_pad = 8;
  687. break;
  688. }
  689. }
  690. mwl8k_add_dma_header(skb, data_pad);
  691. }
  692. /*
  693. * Packet reception for 88w8366 AP firmware.
  694. */
  695. struct mwl8k_rxd_8366_ap {
  696. __le16 pkt_len;
  697. __u8 sq2;
  698. __u8 rate;
  699. __le32 pkt_phys_addr;
  700. __le32 next_rxd_phys_addr;
  701. __le16 qos_control;
  702. __le16 htsig2;
  703. __le32 hw_rssi_info;
  704. __le32 hw_noise_floor_info;
  705. __u8 noise_floor;
  706. __u8 pad0[3];
  707. __u8 rssi;
  708. __u8 rx_status;
  709. __u8 channel;
  710. __u8 rx_ctrl;
  711. } __packed;
  712. #define MWL8K_8366_AP_RATE_INFO_MCS_FORMAT 0x80
  713. #define MWL8K_8366_AP_RATE_INFO_40MHZ 0x40
  714. #define MWL8K_8366_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
  715. #define MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST 0x80
  716. /* 8366 AP rx_status bits */
  717. #define MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
  718. #define MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
  719. #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
  720. #define MWL8K_8366_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
  721. #define MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
  722. static void mwl8k_rxd_8366_ap_init(void *_rxd, dma_addr_t next_dma_addr)
  723. {
  724. struct mwl8k_rxd_8366_ap *rxd = _rxd;
  725. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  726. rxd->rx_ctrl = MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST;
  727. }
  728. static void mwl8k_rxd_8366_ap_refill(void *_rxd, dma_addr_t addr, int len)
  729. {
  730. struct mwl8k_rxd_8366_ap *rxd = _rxd;
  731. rxd->pkt_len = cpu_to_le16(len);
  732. rxd->pkt_phys_addr = cpu_to_le32(addr);
  733. wmb();
  734. rxd->rx_ctrl = 0;
  735. }
  736. static int
  737. mwl8k_rxd_8366_ap_process(void *_rxd, struct ieee80211_rx_status *status,
  738. __le16 *qos, s8 *noise)
  739. {
  740. struct mwl8k_rxd_8366_ap *rxd = _rxd;
  741. if (!(rxd->rx_ctrl & MWL8K_8366_AP_RX_CTRL_OWNED_BY_HOST))
  742. return -1;
  743. rmb();
  744. memset(status, 0, sizeof(*status));
  745. status->signal = -rxd->rssi;
  746. *noise = -rxd->noise_floor;
  747. if (rxd->rate & MWL8K_8366_AP_RATE_INFO_MCS_FORMAT) {
  748. status->flag |= RX_FLAG_HT;
  749. if (rxd->rate & MWL8K_8366_AP_RATE_INFO_40MHZ)
  750. status->flag |= RX_FLAG_40MHZ;
  751. status->rate_idx = MWL8K_8366_AP_RATE_INFO_RATEID(rxd->rate);
  752. } else {
  753. int i;
  754. for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
  755. if (mwl8k_rates_24[i].hw_value == rxd->rate) {
  756. status->rate_idx = i;
  757. break;
  758. }
  759. }
  760. }
  761. if (rxd->channel > 14) {
  762. status->band = IEEE80211_BAND_5GHZ;
  763. if (!(status->flag & RX_FLAG_HT))
  764. status->rate_idx -= 5;
  765. } else {
  766. status->band = IEEE80211_BAND_2GHZ;
  767. }
  768. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  769. status->band);
  770. *qos = rxd->qos_control;
  771. if ((rxd->rx_status != MWL8K_8366_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
  772. (rxd->rx_status & MWL8K_8366_AP_RXSTAT_DECRYPT_ERR_MASK) &&
  773. (rxd->rx_status & MWL8K_8366_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
  774. status->flag |= RX_FLAG_MMIC_ERROR;
  775. return le16_to_cpu(rxd->pkt_len);
  776. }
  777. static struct rxd_ops rxd_8366_ap_ops = {
  778. .rxd_size = sizeof(struct mwl8k_rxd_8366_ap),
  779. .rxd_init = mwl8k_rxd_8366_ap_init,
  780. .rxd_refill = mwl8k_rxd_8366_ap_refill,
  781. .rxd_process = mwl8k_rxd_8366_ap_process,
  782. };
  783. /*
  784. * Packet reception for STA firmware.
  785. */
  786. struct mwl8k_rxd_sta {
  787. __le16 pkt_len;
  788. __u8 link_quality;
  789. __u8 noise_level;
  790. __le32 pkt_phys_addr;
  791. __le32 next_rxd_phys_addr;
  792. __le16 qos_control;
  793. __le16 rate_info;
  794. __le32 pad0[4];
  795. __u8 rssi;
  796. __u8 channel;
  797. __le16 pad1;
  798. __u8 rx_ctrl;
  799. __u8 rx_status;
  800. __u8 pad2[2];
  801. } __packed;
  802. #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
  803. #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
  804. #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
  805. #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
  806. #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
  807. #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
  808. #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
  809. #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
  810. /* ICV=0 or MIC=1 */
  811. #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
  812. /* Key is uploaded only in failure case */
  813. #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
  814. static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
  815. {
  816. struct mwl8k_rxd_sta *rxd = _rxd;
  817. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  818. rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
  819. }
  820. static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
  821. {
  822. struct mwl8k_rxd_sta *rxd = _rxd;
  823. rxd->pkt_len = cpu_to_le16(len);
  824. rxd->pkt_phys_addr = cpu_to_le32(addr);
  825. wmb();
  826. rxd->rx_ctrl = 0;
  827. }
  828. static int
  829. mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
  830. __le16 *qos, s8 *noise)
  831. {
  832. struct mwl8k_rxd_sta *rxd = _rxd;
  833. u16 rate_info;
  834. if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
  835. return -1;
  836. rmb();
  837. rate_info = le16_to_cpu(rxd->rate_info);
  838. memset(status, 0, sizeof(*status));
  839. status->signal = -rxd->rssi;
  840. *noise = -rxd->noise_level;
  841. status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
  842. status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
  843. if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
  844. status->flag |= RX_FLAG_SHORTPRE;
  845. if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
  846. status->flag |= RX_FLAG_40MHZ;
  847. if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
  848. status->flag |= RX_FLAG_SHORT_GI;
  849. if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
  850. status->flag |= RX_FLAG_HT;
  851. if (rxd->channel > 14) {
  852. status->band = IEEE80211_BAND_5GHZ;
  853. if (!(status->flag & RX_FLAG_HT))
  854. status->rate_idx -= 5;
  855. } else {
  856. status->band = IEEE80211_BAND_2GHZ;
  857. }
  858. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  859. status->band);
  860. *qos = rxd->qos_control;
  861. if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
  862. (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
  863. status->flag |= RX_FLAG_MMIC_ERROR;
  864. return le16_to_cpu(rxd->pkt_len);
  865. }
  866. static struct rxd_ops rxd_sta_ops = {
  867. .rxd_size = sizeof(struct mwl8k_rxd_sta),
  868. .rxd_init = mwl8k_rxd_sta_init,
  869. .rxd_refill = mwl8k_rxd_sta_refill,
  870. .rxd_process = mwl8k_rxd_sta_process,
  871. };
  872. #define MWL8K_RX_DESCS 256
  873. #define MWL8K_RX_MAXSZ 3800
  874. static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
  875. {
  876. struct mwl8k_priv *priv = hw->priv;
  877. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  878. int size;
  879. int i;
  880. rxq->rxd_count = 0;
  881. rxq->head = 0;
  882. rxq->tail = 0;
  883. size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
  884. rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
  885. if (rxq->rxd == NULL) {
  886. wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
  887. return -ENOMEM;
  888. }
  889. memset(rxq->rxd, 0, size);
  890. rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
  891. if (rxq->buf == NULL) {
  892. wiphy_err(hw->wiphy, "failed to alloc RX skbuff list\n");
  893. pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
  894. return -ENOMEM;
  895. }
  896. memset(rxq->buf, 0, MWL8K_RX_DESCS * sizeof(*rxq->buf));
  897. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  898. int desc_size;
  899. void *rxd;
  900. int nexti;
  901. dma_addr_t next_dma_addr;
  902. desc_size = priv->rxd_ops->rxd_size;
  903. rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
  904. nexti = i + 1;
  905. if (nexti == MWL8K_RX_DESCS)
  906. nexti = 0;
  907. next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
  908. priv->rxd_ops->rxd_init(rxd, next_dma_addr);
  909. }
  910. return 0;
  911. }
  912. static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
  913. {
  914. struct mwl8k_priv *priv = hw->priv;
  915. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  916. int refilled;
  917. refilled = 0;
  918. while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
  919. struct sk_buff *skb;
  920. dma_addr_t addr;
  921. int rx;
  922. void *rxd;
  923. skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
  924. if (skb == NULL)
  925. break;
  926. addr = pci_map_single(priv->pdev, skb->data,
  927. MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
  928. rxq->rxd_count++;
  929. rx = rxq->tail++;
  930. if (rxq->tail == MWL8K_RX_DESCS)
  931. rxq->tail = 0;
  932. rxq->buf[rx].skb = skb;
  933. dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
  934. rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
  935. priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
  936. refilled++;
  937. }
  938. return refilled;
  939. }
  940. /* Must be called only when the card's reception is completely halted */
  941. static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
  942. {
  943. struct mwl8k_priv *priv = hw->priv;
  944. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  945. int i;
  946. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  947. if (rxq->buf[i].skb != NULL) {
  948. pci_unmap_single(priv->pdev,
  949. dma_unmap_addr(&rxq->buf[i], dma),
  950. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  951. dma_unmap_addr_set(&rxq->buf[i], dma, 0);
  952. kfree_skb(rxq->buf[i].skb);
  953. rxq->buf[i].skb = NULL;
  954. }
  955. }
  956. kfree(rxq->buf);
  957. rxq->buf = NULL;
  958. pci_free_consistent(priv->pdev,
  959. MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
  960. rxq->rxd, rxq->rxd_dma);
  961. rxq->rxd = NULL;
  962. }
  963. /*
  964. * Scan a list of BSSIDs to process for finalize join.
  965. * Allows for extension to process multiple BSSIDs.
  966. */
  967. static inline int
  968. mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
  969. {
  970. return priv->capture_beacon &&
  971. ieee80211_is_beacon(wh->frame_control) &&
  972. !compare_ether_addr(wh->addr3, priv->capture_bssid);
  973. }
  974. static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
  975. struct sk_buff *skb)
  976. {
  977. struct mwl8k_priv *priv = hw->priv;
  978. priv->capture_beacon = false;
  979. memset(priv->capture_bssid, 0, ETH_ALEN);
  980. /*
  981. * Use GFP_ATOMIC as rxq_process is called from
  982. * the primary interrupt handler, memory allocation call
  983. * must not sleep.
  984. */
  985. priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
  986. if (priv->beacon_skb != NULL)
  987. ieee80211_queue_work(hw, &priv->finalize_join_worker);
  988. }
  989. static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
  990. u8 *bssid)
  991. {
  992. struct mwl8k_vif *mwl8k_vif;
  993. list_for_each_entry(mwl8k_vif,
  994. vif_list, list) {
  995. if (memcmp(bssid, mwl8k_vif->bssid,
  996. ETH_ALEN) == 0)
  997. return mwl8k_vif;
  998. }
  999. return NULL;
  1000. }
  1001. static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
  1002. {
  1003. struct mwl8k_priv *priv = hw->priv;
  1004. struct mwl8k_vif *mwl8k_vif = NULL;
  1005. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1006. int processed;
  1007. processed = 0;
  1008. while (rxq->rxd_count && limit--) {
  1009. struct sk_buff *skb;
  1010. void *rxd;
  1011. int pkt_len;
  1012. struct ieee80211_rx_status status;
  1013. struct ieee80211_hdr *wh;
  1014. __le16 qos;
  1015. skb = rxq->buf[rxq->head].skb;
  1016. if (skb == NULL)
  1017. break;
  1018. rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
  1019. pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
  1020. &priv->noise);
  1021. if (pkt_len < 0)
  1022. break;
  1023. rxq->buf[rxq->head].skb = NULL;
  1024. pci_unmap_single(priv->pdev,
  1025. dma_unmap_addr(&rxq->buf[rxq->head], dma),
  1026. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1027. dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
  1028. rxq->head++;
  1029. if (rxq->head == MWL8K_RX_DESCS)
  1030. rxq->head = 0;
  1031. rxq->rxd_count--;
  1032. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1033. /*
  1034. * Check for a pending join operation. Save a
  1035. * copy of the beacon and schedule a tasklet to
  1036. * send a FINALIZE_JOIN command to the firmware.
  1037. */
  1038. if (mwl8k_capture_bssid(priv, (void *)skb->data))
  1039. mwl8k_save_beacon(hw, skb);
  1040. if (ieee80211_has_protected(wh->frame_control)) {
  1041. /* Check if hw crypto has been enabled for
  1042. * this bss. If yes, set the status flags
  1043. * accordingly
  1044. */
  1045. mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
  1046. wh->addr1);
  1047. if (mwl8k_vif != NULL &&
  1048. mwl8k_vif->is_hw_crypto_enabled == true) {
  1049. /*
  1050. * When MMIC ERROR is encountered
  1051. * by the firmware, payload is
  1052. * dropped and only 32 bytes of
  1053. * mwl8k Firmware header is sent
  1054. * to the host.
  1055. *
  1056. * We need to add four bytes of
  1057. * key information. In it
  1058. * MAC80211 expects keyidx set to
  1059. * 0 for triggering Counter
  1060. * Measure of MMIC failure.
  1061. */
  1062. if (status.flag & RX_FLAG_MMIC_ERROR) {
  1063. struct mwl8k_dma_data *tr;
  1064. tr = (struct mwl8k_dma_data *)skb->data;
  1065. memset((void *)&(tr->data), 0, 4);
  1066. pkt_len += 4;
  1067. }
  1068. if (!ieee80211_is_auth(wh->frame_control))
  1069. status.flag |= RX_FLAG_IV_STRIPPED |
  1070. RX_FLAG_DECRYPTED |
  1071. RX_FLAG_MMIC_STRIPPED;
  1072. }
  1073. }
  1074. skb_put(skb, pkt_len);
  1075. mwl8k_remove_dma_header(skb, qos);
  1076. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  1077. ieee80211_rx_irqsafe(hw, skb);
  1078. processed++;
  1079. }
  1080. return processed;
  1081. }
  1082. /*
  1083. * Packet transmission.
  1084. */
  1085. #define MWL8K_TXD_STATUS_OK 0x00000001
  1086. #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
  1087. #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
  1088. #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
  1089. #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
  1090. #define MWL8K_QOS_QLEN_UNSPEC 0xff00
  1091. #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
  1092. #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
  1093. #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
  1094. #define MWL8K_QOS_EOSP 0x0010
  1095. struct mwl8k_tx_desc {
  1096. __le32 status;
  1097. __u8 data_rate;
  1098. __u8 tx_priority;
  1099. __le16 qos_control;
  1100. __le32 pkt_phys_addr;
  1101. __le16 pkt_len;
  1102. __u8 dest_MAC_addr[ETH_ALEN];
  1103. __le32 next_txd_phys_addr;
  1104. __le32 reserved;
  1105. __le16 rate_info;
  1106. __u8 peer_id;
  1107. __u8 tx_frag_cnt;
  1108. } __packed;
  1109. #define MWL8K_TX_DESCS 128
  1110. static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
  1111. {
  1112. struct mwl8k_priv *priv = hw->priv;
  1113. struct mwl8k_tx_queue *txq = priv->txq + index;
  1114. int size;
  1115. int i;
  1116. txq->len = 0;
  1117. txq->head = 0;
  1118. txq->tail = 0;
  1119. size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
  1120. txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
  1121. if (txq->txd == NULL) {
  1122. wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
  1123. return -ENOMEM;
  1124. }
  1125. memset(txq->txd, 0, size);
  1126. txq->skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->skb), GFP_KERNEL);
  1127. if (txq->skb == NULL) {
  1128. wiphy_err(hw->wiphy, "failed to alloc TX skbuff list\n");
  1129. pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
  1130. return -ENOMEM;
  1131. }
  1132. memset(txq->skb, 0, MWL8K_TX_DESCS * sizeof(*txq->skb));
  1133. for (i = 0; i < MWL8K_TX_DESCS; i++) {
  1134. struct mwl8k_tx_desc *tx_desc;
  1135. int nexti;
  1136. tx_desc = txq->txd + i;
  1137. nexti = (i + 1) % MWL8K_TX_DESCS;
  1138. tx_desc->status = 0;
  1139. tx_desc->next_txd_phys_addr =
  1140. cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
  1141. }
  1142. return 0;
  1143. }
  1144. static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
  1145. {
  1146. iowrite32(MWL8K_H2A_INT_PPA_READY,
  1147. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1148. iowrite32(MWL8K_H2A_INT_DUMMY,
  1149. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1150. ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  1151. }
  1152. static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
  1153. {
  1154. struct mwl8k_priv *priv = hw->priv;
  1155. int i;
  1156. for (i = 0; i < MWL8K_TX_QUEUES; i++) {
  1157. struct mwl8k_tx_queue *txq = priv->txq + i;
  1158. int fw_owned = 0;
  1159. int drv_owned = 0;
  1160. int unused = 0;
  1161. int desc;
  1162. for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
  1163. struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
  1164. u32 status;
  1165. status = le32_to_cpu(tx_desc->status);
  1166. if (status & MWL8K_TXD_STATUS_FW_OWNED)
  1167. fw_owned++;
  1168. else
  1169. drv_owned++;
  1170. if (tx_desc->pkt_len == 0)
  1171. unused++;
  1172. }
  1173. wiphy_err(hw->wiphy,
  1174. "txq[%d] len=%d head=%d tail=%d "
  1175. "fw_owned=%d drv_owned=%d unused=%d\n",
  1176. i,
  1177. txq->len, txq->head, txq->tail,
  1178. fw_owned, drv_owned, unused);
  1179. }
  1180. }
  1181. /*
  1182. * Must be called with priv->fw_mutex held and tx queues stopped.
  1183. */
  1184. #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
  1185. static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
  1186. {
  1187. struct mwl8k_priv *priv = hw->priv;
  1188. DECLARE_COMPLETION_ONSTACK(tx_wait);
  1189. int retry;
  1190. int rc;
  1191. might_sleep();
  1192. /*
  1193. * The TX queues are stopped at this point, so this test
  1194. * doesn't need to take ->tx_lock.
  1195. */
  1196. if (!priv->pending_tx_pkts)
  1197. return 0;
  1198. retry = 0;
  1199. rc = 0;
  1200. spin_lock_bh(&priv->tx_lock);
  1201. priv->tx_wait = &tx_wait;
  1202. while (!rc) {
  1203. int oldcount;
  1204. unsigned long timeout;
  1205. oldcount = priv->pending_tx_pkts;
  1206. spin_unlock_bh(&priv->tx_lock);
  1207. timeout = wait_for_completion_timeout(&tx_wait,
  1208. msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
  1209. spin_lock_bh(&priv->tx_lock);
  1210. if (timeout) {
  1211. WARN_ON(priv->pending_tx_pkts);
  1212. if (retry) {
  1213. wiphy_notice(hw->wiphy, "tx rings drained\n");
  1214. }
  1215. break;
  1216. }
  1217. if (priv->pending_tx_pkts < oldcount) {
  1218. wiphy_notice(hw->wiphy,
  1219. "waiting for tx rings to drain (%d -> %d pkts)\n",
  1220. oldcount, priv->pending_tx_pkts);
  1221. retry = 1;
  1222. continue;
  1223. }
  1224. priv->tx_wait = NULL;
  1225. wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
  1226. MWL8K_TX_WAIT_TIMEOUT_MS);
  1227. mwl8k_dump_tx_rings(hw);
  1228. rc = -ETIMEDOUT;
  1229. }
  1230. spin_unlock_bh(&priv->tx_lock);
  1231. return rc;
  1232. }
  1233. #define MWL8K_TXD_SUCCESS(status) \
  1234. ((status) & (MWL8K_TXD_STATUS_OK | \
  1235. MWL8K_TXD_STATUS_OK_RETRY | \
  1236. MWL8K_TXD_STATUS_OK_MORE_RETRY))
  1237. static int
  1238. mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
  1239. {
  1240. struct mwl8k_priv *priv = hw->priv;
  1241. struct mwl8k_tx_queue *txq = priv->txq + index;
  1242. int processed;
  1243. processed = 0;
  1244. while (txq->len > 0 && limit--) {
  1245. int tx;
  1246. struct mwl8k_tx_desc *tx_desc;
  1247. unsigned long addr;
  1248. int size;
  1249. struct sk_buff *skb;
  1250. struct ieee80211_tx_info *info;
  1251. u32 status;
  1252. tx = txq->head;
  1253. tx_desc = txq->txd + tx;
  1254. status = le32_to_cpu(tx_desc->status);
  1255. if (status & MWL8K_TXD_STATUS_FW_OWNED) {
  1256. if (!force)
  1257. break;
  1258. tx_desc->status &=
  1259. ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
  1260. }
  1261. txq->head = (tx + 1) % MWL8K_TX_DESCS;
  1262. BUG_ON(txq->len == 0);
  1263. txq->len--;
  1264. priv->pending_tx_pkts--;
  1265. addr = le32_to_cpu(tx_desc->pkt_phys_addr);
  1266. size = le16_to_cpu(tx_desc->pkt_len);
  1267. skb = txq->skb[tx];
  1268. txq->skb[tx] = NULL;
  1269. BUG_ON(skb == NULL);
  1270. pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
  1271. mwl8k_remove_dma_header(skb, tx_desc->qos_control);
  1272. /* Mark descriptor as unused */
  1273. tx_desc->pkt_phys_addr = 0;
  1274. tx_desc->pkt_len = 0;
  1275. info = IEEE80211_SKB_CB(skb);
  1276. ieee80211_tx_info_clear_status(info);
  1277. if (MWL8K_TXD_SUCCESS(status))
  1278. info->flags |= IEEE80211_TX_STAT_ACK;
  1279. ieee80211_tx_status_irqsafe(hw, skb);
  1280. processed++;
  1281. }
  1282. if (processed && priv->radio_on && !mutex_is_locked(&priv->fw_mutex))
  1283. ieee80211_wake_queue(hw, index);
  1284. return processed;
  1285. }
  1286. /* must be called only when the card's transmit is completely halted */
  1287. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1288. {
  1289. struct mwl8k_priv *priv = hw->priv;
  1290. struct mwl8k_tx_queue *txq = priv->txq + index;
  1291. mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
  1292. kfree(txq->skb);
  1293. txq->skb = NULL;
  1294. pci_free_consistent(priv->pdev,
  1295. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1296. txq->txd, txq->txd_dma);
  1297. txq->txd = NULL;
  1298. }
  1299. static int
  1300. mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
  1301. {
  1302. struct mwl8k_priv *priv = hw->priv;
  1303. struct ieee80211_tx_info *tx_info;
  1304. struct mwl8k_vif *mwl8k_vif;
  1305. struct ieee80211_hdr *wh;
  1306. struct mwl8k_tx_queue *txq;
  1307. struct mwl8k_tx_desc *tx;
  1308. dma_addr_t dma;
  1309. u32 txstatus;
  1310. u8 txdatarate;
  1311. u16 qos;
  1312. wh = (struct ieee80211_hdr *)skb->data;
  1313. if (ieee80211_is_data_qos(wh->frame_control))
  1314. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1315. else
  1316. qos = 0;
  1317. if (priv->ap_fw)
  1318. mwl8k_encapsulate_tx_frame(skb);
  1319. else
  1320. mwl8k_add_dma_header(skb, 0);
  1321. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1322. tx_info = IEEE80211_SKB_CB(skb);
  1323. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1324. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1325. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1326. wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
  1327. mwl8k_vif->seqno += 0x10;
  1328. }
  1329. /* Setup firmware control bit fields for each frame type. */
  1330. txstatus = 0;
  1331. txdatarate = 0;
  1332. if (ieee80211_is_mgmt(wh->frame_control) ||
  1333. ieee80211_is_ctl(wh->frame_control)) {
  1334. txdatarate = 0;
  1335. qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
  1336. } else if (ieee80211_is_data(wh->frame_control)) {
  1337. txdatarate = 1;
  1338. if (is_multicast_ether_addr(wh->addr1))
  1339. txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1340. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1341. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  1342. qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
  1343. else
  1344. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1345. }
  1346. dma = pci_map_single(priv->pdev, skb->data,
  1347. skb->len, PCI_DMA_TODEVICE);
  1348. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1349. wiphy_debug(hw->wiphy,
  1350. "failed to dma map skb, dropping TX frame.\n");
  1351. dev_kfree_skb(skb);
  1352. return NETDEV_TX_OK;
  1353. }
  1354. spin_lock_bh(&priv->tx_lock);
  1355. txq = priv->txq + index;
  1356. BUG_ON(txq->skb[txq->tail] != NULL);
  1357. txq->skb[txq->tail] = skb;
  1358. tx = txq->txd + txq->tail;
  1359. tx->data_rate = txdatarate;
  1360. tx->tx_priority = index;
  1361. tx->qos_control = cpu_to_le16(qos);
  1362. tx->pkt_phys_addr = cpu_to_le32(dma);
  1363. tx->pkt_len = cpu_to_le16(skb->len);
  1364. tx->rate_info = 0;
  1365. if (!priv->ap_fw && tx_info->control.sta != NULL)
  1366. tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
  1367. else
  1368. tx->peer_id = 0;
  1369. wmb();
  1370. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
  1371. txq->len++;
  1372. priv->pending_tx_pkts++;
  1373. txq->tail++;
  1374. if (txq->tail == MWL8K_TX_DESCS)
  1375. txq->tail = 0;
  1376. if (txq->head == txq->tail)
  1377. ieee80211_stop_queue(hw, index);
  1378. mwl8k_tx_start(priv);
  1379. spin_unlock_bh(&priv->tx_lock);
  1380. return NETDEV_TX_OK;
  1381. }
  1382. /*
  1383. * Firmware access.
  1384. *
  1385. * We have the following requirements for issuing firmware commands:
  1386. * - Some commands require that the packet transmit path is idle when
  1387. * the command is issued. (For simplicity, we'll just quiesce the
  1388. * transmit path for every command.)
  1389. * - There are certain sequences of commands that need to be issued to
  1390. * the hardware sequentially, with no other intervening commands.
  1391. *
  1392. * This leads to an implementation of a "firmware lock" as a mutex that
  1393. * can be taken recursively, and which is taken by both the low-level
  1394. * command submission function (mwl8k_post_cmd) as well as any users of
  1395. * that function that require issuing of an atomic sequence of commands,
  1396. * and quiesces the transmit path whenever it's taken.
  1397. */
  1398. static int mwl8k_fw_lock(struct ieee80211_hw *hw)
  1399. {
  1400. struct mwl8k_priv *priv = hw->priv;
  1401. if (priv->fw_mutex_owner != current) {
  1402. int rc;
  1403. mutex_lock(&priv->fw_mutex);
  1404. ieee80211_stop_queues(hw);
  1405. rc = mwl8k_tx_wait_empty(hw);
  1406. if (rc) {
  1407. ieee80211_wake_queues(hw);
  1408. mutex_unlock(&priv->fw_mutex);
  1409. return rc;
  1410. }
  1411. priv->fw_mutex_owner = current;
  1412. }
  1413. priv->fw_mutex_depth++;
  1414. return 0;
  1415. }
  1416. static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
  1417. {
  1418. struct mwl8k_priv *priv = hw->priv;
  1419. if (!--priv->fw_mutex_depth) {
  1420. ieee80211_wake_queues(hw);
  1421. priv->fw_mutex_owner = NULL;
  1422. mutex_unlock(&priv->fw_mutex);
  1423. }
  1424. }
  1425. /*
  1426. * Command processing.
  1427. */
  1428. /* Timeout firmware commands after 10s */
  1429. #define MWL8K_CMD_TIMEOUT_MS 10000
  1430. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1431. {
  1432. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1433. struct mwl8k_priv *priv = hw->priv;
  1434. void __iomem *regs = priv->regs;
  1435. dma_addr_t dma_addr;
  1436. unsigned int dma_size;
  1437. int rc;
  1438. unsigned long timeout = 0;
  1439. u8 buf[32];
  1440. cmd->result = (__force __le16) 0xffff;
  1441. dma_size = le16_to_cpu(cmd->length);
  1442. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1443. PCI_DMA_BIDIRECTIONAL);
  1444. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1445. return -ENOMEM;
  1446. rc = mwl8k_fw_lock(hw);
  1447. if (rc) {
  1448. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1449. PCI_DMA_BIDIRECTIONAL);
  1450. return rc;
  1451. }
  1452. priv->hostcmd_wait = &cmd_wait;
  1453. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1454. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1455. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1456. iowrite32(MWL8K_H2A_INT_DUMMY,
  1457. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1458. timeout = wait_for_completion_timeout(&cmd_wait,
  1459. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1460. priv->hostcmd_wait = NULL;
  1461. mwl8k_fw_unlock(hw);
  1462. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1463. PCI_DMA_BIDIRECTIONAL);
  1464. if (!timeout) {
  1465. wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
  1466. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1467. MWL8K_CMD_TIMEOUT_MS);
  1468. rc = -ETIMEDOUT;
  1469. } else {
  1470. int ms;
  1471. ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
  1472. rc = cmd->result ? -EINVAL : 0;
  1473. if (rc)
  1474. wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
  1475. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1476. le16_to_cpu(cmd->result));
  1477. else if (ms > 2000)
  1478. wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
  1479. mwl8k_cmd_name(cmd->code,
  1480. buf, sizeof(buf)),
  1481. ms);
  1482. }
  1483. return rc;
  1484. }
  1485. static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
  1486. struct ieee80211_vif *vif,
  1487. struct mwl8k_cmd_pkt *cmd)
  1488. {
  1489. if (vif != NULL)
  1490. cmd->macid = MWL8K_VIF(vif)->macid;
  1491. return mwl8k_post_cmd(hw, cmd);
  1492. }
  1493. /*
  1494. * Setup code shared between STA and AP firmware images.
  1495. */
  1496. static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
  1497. {
  1498. struct mwl8k_priv *priv = hw->priv;
  1499. BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
  1500. memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
  1501. BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
  1502. memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
  1503. priv->band_24.band = IEEE80211_BAND_2GHZ;
  1504. priv->band_24.channels = priv->channels_24;
  1505. priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
  1506. priv->band_24.bitrates = priv->rates_24;
  1507. priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
  1508. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
  1509. }
  1510. static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
  1511. {
  1512. struct mwl8k_priv *priv = hw->priv;
  1513. BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
  1514. memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
  1515. BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
  1516. memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
  1517. priv->band_50.band = IEEE80211_BAND_5GHZ;
  1518. priv->band_50.channels = priv->channels_50;
  1519. priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
  1520. priv->band_50.bitrates = priv->rates_50;
  1521. priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
  1522. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
  1523. }
  1524. /*
  1525. * CMD_GET_HW_SPEC (STA version).
  1526. */
  1527. struct mwl8k_cmd_get_hw_spec_sta {
  1528. struct mwl8k_cmd_pkt header;
  1529. __u8 hw_rev;
  1530. __u8 host_interface;
  1531. __le16 num_mcaddrs;
  1532. __u8 perm_addr[ETH_ALEN];
  1533. __le16 region_code;
  1534. __le32 fw_rev;
  1535. __le32 ps_cookie;
  1536. __le32 caps;
  1537. __u8 mcs_bitmap[16];
  1538. __le32 rx_queue_ptr;
  1539. __le32 num_tx_queues;
  1540. __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
  1541. __le32 caps2;
  1542. __le32 num_tx_desc_per_queue;
  1543. __le32 total_rxd;
  1544. } __packed;
  1545. #define MWL8K_CAP_MAX_AMSDU 0x20000000
  1546. #define MWL8K_CAP_GREENFIELD 0x08000000
  1547. #define MWL8K_CAP_AMPDU 0x04000000
  1548. #define MWL8K_CAP_RX_STBC 0x01000000
  1549. #define MWL8K_CAP_TX_STBC 0x00800000
  1550. #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
  1551. #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
  1552. #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
  1553. #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
  1554. #define MWL8K_CAP_DELAY_BA 0x00003000
  1555. #define MWL8K_CAP_MIMO 0x00000200
  1556. #define MWL8K_CAP_40MHZ 0x00000100
  1557. #define MWL8K_CAP_BAND_MASK 0x00000007
  1558. #define MWL8K_CAP_5GHZ 0x00000004
  1559. #define MWL8K_CAP_2GHZ4 0x00000001
  1560. static void
  1561. mwl8k_set_ht_caps(struct ieee80211_hw *hw,
  1562. struct ieee80211_supported_band *band, u32 cap)
  1563. {
  1564. int rx_streams;
  1565. int tx_streams;
  1566. band->ht_cap.ht_supported = 1;
  1567. if (cap & MWL8K_CAP_MAX_AMSDU)
  1568. band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  1569. if (cap & MWL8K_CAP_GREENFIELD)
  1570. band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
  1571. if (cap & MWL8K_CAP_AMPDU) {
  1572. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  1573. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1574. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1575. }
  1576. if (cap & MWL8K_CAP_RX_STBC)
  1577. band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
  1578. if (cap & MWL8K_CAP_TX_STBC)
  1579. band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  1580. if (cap & MWL8K_CAP_SHORTGI_40MHZ)
  1581. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  1582. if (cap & MWL8K_CAP_SHORTGI_20MHZ)
  1583. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  1584. if (cap & MWL8K_CAP_DELAY_BA)
  1585. band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
  1586. if (cap & MWL8K_CAP_40MHZ)
  1587. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1588. rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
  1589. tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
  1590. band->ht_cap.mcs.rx_mask[0] = 0xff;
  1591. if (rx_streams >= 2)
  1592. band->ht_cap.mcs.rx_mask[1] = 0xff;
  1593. if (rx_streams >= 3)
  1594. band->ht_cap.mcs.rx_mask[2] = 0xff;
  1595. band->ht_cap.mcs.rx_mask[4] = 0x01;
  1596. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  1597. if (rx_streams != tx_streams) {
  1598. band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  1599. band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
  1600. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  1601. }
  1602. }
  1603. static void
  1604. mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
  1605. {
  1606. struct mwl8k_priv *priv = hw->priv;
  1607. if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
  1608. mwl8k_setup_2ghz_band(hw);
  1609. if (caps & MWL8K_CAP_MIMO)
  1610. mwl8k_set_ht_caps(hw, &priv->band_24, caps);
  1611. }
  1612. if (caps & MWL8K_CAP_5GHZ) {
  1613. mwl8k_setup_5ghz_band(hw);
  1614. if (caps & MWL8K_CAP_MIMO)
  1615. mwl8k_set_ht_caps(hw, &priv->band_50, caps);
  1616. }
  1617. }
  1618. static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
  1619. {
  1620. struct mwl8k_priv *priv = hw->priv;
  1621. struct mwl8k_cmd_get_hw_spec_sta *cmd;
  1622. int rc;
  1623. int i;
  1624. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1625. if (cmd == NULL)
  1626. return -ENOMEM;
  1627. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  1628. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1629. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  1630. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  1631. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  1632. cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
  1633. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  1634. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  1635. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  1636. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  1637. rc = mwl8k_post_cmd(hw, &cmd->header);
  1638. if (!rc) {
  1639. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  1640. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  1641. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  1642. priv->hw_rev = cmd->hw_rev;
  1643. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  1644. priv->ap_macids_supported = 0x00000000;
  1645. priv->sta_macids_supported = 0x00000001;
  1646. }
  1647. kfree(cmd);
  1648. return rc;
  1649. }
  1650. /*
  1651. * CMD_GET_HW_SPEC (AP version).
  1652. */
  1653. struct mwl8k_cmd_get_hw_spec_ap {
  1654. struct mwl8k_cmd_pkt header;
  1655. __u8 hw_rev;
  1656. __u8 host_interface;
  1657. __le16 num_wcb;
  1658. __le16 num_mcaddrs;
  1659. __u8 perm_addr[ETH_ALEN];
  1660. __le16 region_code;
  1661. __le16 num_antenna;
  1662. __le32 fw_rev;
  1663. __le32 wcbbase0;
  1664. __le32 rxwrptr;
  1665. __le32 rxrdptr;
  1666. __le32 ps_cookie;
  1667. __le32 wcbbase1;
  1668. __le32 wcbbase2;
  1669. __le32 wcbbase3;
  1670. __le32 fw_api_version;
  1671. } __packed;
  1672. static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
  1673. {
  1674. struct mwl8k_priv *priv = hw->priv;
  1675. struct mwl8k_cmd_get_hw_spec_ap *cmd;
  1676. int rc;
  1677. u32 api_version;
  1678. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1679. if (cmd == NULL)
  1680. return -ENOMEM;
  1681. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  1682. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1683. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  1684. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  1685. rc = mwl8k_post_cmd(hw, &cmd->header);
  1686. if (!rc) {
  1687. int off;
  1688. api_version = le32_to_cpu(cmd->fw_api_version);
  1689. if (priv->device_info->fw_api_ap != api_version) {
  1690. printk(KERN_ERR "%s: Unsupported fw API version for %s."
  1691. " Expected %d got %d.\n", MWL8K_NAME,
  1692. priv->device_info->part_name,
  1693. priv->device_info->fw_api_ap,
  1694. api_version);
  1695. rc = -EINVAL;
  1696. goto done;
  1697. }
  1698. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  1699. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  1700. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  1701. priv->hw_rev = cmd->hw_rev;
  1702. mwl8k_setup_2ghz_band(hw);
  1703. priv->ap_macids_supported = 0x000000ff;
  1704. priv->sta_macids_supported = 0x00000000;
  1705. off = le32_to_cpu(cmd->wcbbase0) & 0xffff;
  1706. iowrite32(priv->txq[0].txd_dma, priv->sram + off);
  1707. off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
  1708. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  1709. off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
  1710. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  1711. off = le32_to_cpu(cmd->wcbbase1) & 0xffff;
  1712. iowrite32(priv->txq[1].txd_dma, priv->sram + off);
  1713. off = le32_to_cpu(cmd->wcbbase2) & 0xffff;
  1714. iowrite32(priv->txq[2].txd_dma, priv->sram + off);
  1715. off = le32_to_cpu(cmd->wcbbase3) & 0xffff;
  1716. iowrite32(priv->txq[3].txd_dma, priv->sram + off);
  1717. }
  1718. done:
  1719. kfree(cmd);
  1720. return rc;
  1721. }
  1722. /*
  1723. * CMD_SET_HW_SPEC.
  1724. */
  1725. struct mwl8k_cmd_set_hw_spec {
  1726. struct mwl8k_cmd_pkt header;
  1727. __u8 hw_rev;
  1728. __u8 host_interface;
  1729. __le16 num_mcaddrs;
  1730. __u8 perm_addr[ETH_ALEN];
  1731. __le16 region_code;
  1732. __le32 fw_rev;
  1733. __le32 ps_cookie;
  1734. __le32 caps;
  1735. __le32 rx_queue_ptr;
  1736. __le32 num_tx_queues;
  1737. __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
  1738. __le32 flags;
  1739. __le32 num_tx_desc_per_queue;
  1740. __le32 total_rxd;
  1741. } __packed;
  1742. #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
  1743. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
  1744. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
  1745. static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
  1746. {
  1747. struct mwl8k_priv *priv = hw->priv;
  1748. struct mwl8k_cmd_set_hw_spec *cmd;
  1749. int rc;
  1750. int i;
  1751. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1752. if (cmd == NULL)
  1753. return -ENOMEM;
  1754. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
  1755. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1756. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  1757. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  1758. cmd->num_tx_queues = cpu_to_le32(MWL8K_TX_QUEUES);
  1759. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  1760. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  1761. cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
  1762. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
  1763. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON);
  1764. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  1765. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  1766. rc = mwl8k_post_cmd(hw, &cmd->header);
  1767. kfree(cmd);
  1768. return rc;
  1769. }
  1770. /*
  1771. * CMD_MAC_MULTICAST_ADR.
  1772. */
  1773. struct mwl8k_cmd_mac_multicast_adr {
  1774. struct mwl8k_cmd_pkt header;
  1775. __le16 action;
  1776. __le16 numaddr;
  1777. __u8 addr[0][ETH_ALEN];
  1778. };
  1779. #define MWL8K_ENABLE_RX_DIRECTED 0x0001
  1780. #define MWL8K_ENABLE_RX_MULTICAST 0x0002
  1781. #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
  1782. #define MWL8K_ENABLE_RX_BROADCAST 0x0008
  1783. static struct mwl8k_cmd_pkt *
  1784. __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
  1785. struct netdev_hw_addr_list *mc_list)
  1786. {
  1787. struct mwl8k_priv *priv = hw->priv;
  1788. struct mwl8k_cmd_mac_multicast_adr *cmd;
  1789. int size;
  1790. int mc_count = 0;
  1791. if (mc_list)
  1792. mc_count = netdev_hw_addr_list_count(mc_list);
  1793. if (allmulti || mc_count > priv->num_mcaddrs) {
  1794. allmulti = 1;
  1795. mc_count = 0;
  1796. }
  1797. size = sizeof(*cmd) + mc_count * ETH_ALEN;
  1798. cmd = kzalloc(size, GFP_ATOMIC);
  1799. if (cmd == NULL)
  1800. return NULL;
  1801. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  1802. cmd->header.length = cpu_to_le16(size);
  1803. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
  1804. MWL8K_ENABLE_RX_BROADCAST);
  1805. if (allmulti) {
  1806. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
  1807. } else if (mc_count) {
  1808. struct netdev_hw_addr *ha;
  1809. int i = 0;
  1810. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  1811. cmd->numaddr = cpu_to_le16(mc_count);
  1812. netdev_hw_addr_list_for_each(ha, mc_list) {
  1813. memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
  1814. }
  1815. }
  1816. return &cmd->header;
  1817. }
  1818. /*
  1819. * CMD_GET_STAT.
  1820. */
  1821. struct mwl8k_cmd_get_stat {
  1822. struct mwl8k_cmd_pkt header;
  1823. __le32 stats[64];
  1824. } __packed;
  1825. #define MWL8K_STAT_ACK_FAILURE 9
  1826. #define MWL8K_STAT_RTS_FAILURE 12
  1827. #define MWL8K_STAT_FCS_ERROR 24
  1828. #define MWL8K_STAT_RTS_SUCCESS 11
  1829. static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
  1830. struct ieee80211_low_level_stats *stats)
  1831. {
  1832. struct mwl8k_cmd_get_stat *cmd;
  1833. int rc;
  1834. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1835. if (cmd == NULL)
  1836. return -ENOMEM;
  1837. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  1838. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1839. rc = mwl8k_post_cmd(hw, &cmd->header);
  1840. if (!rc) {
  1841. stats->dot11ACKFailureCount =
  1842. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  1843. stats->dot11RTSFailureCount =
  1844. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  1845. stats->dot11FCSErrorCount =
  1846. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  1847. stats->dot11RTSSuccessCount =
  1848. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  1849. }
  1850. kfree(cmd);
  1851. return rc;
  1852. }
  1853. /*
  1854. * CMD_RADIO_CONTROL.
  1855. */
  1856. struct mwl8k_cmd_radio_control {
  1857. struct mwl8k_cmd_pkt header;
  1858. __le16 action;
  1859. __le16 control;
  1860. __le16 radio_on;
  1861. } __packed;
  1862. static int
  1863. mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
  1864. {
  1865. struct mwl8k_priv *priv = hw->priv;
  1866. struct mwl8k_cmd_radio_control *cmd;
  1867. int rc;
  1868. if (enable == priv->radio_on && !force)
  1869. return 0;
  1870. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1871. if (cmd == NULL)
  1872. return -ENOMEM;
  1873. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  1874. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1875. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1876. cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
  1877. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  1878. rc = mwl8k_post_cmd(hw, &cmd->header);
  1879. kfree(cmd);
  1880. if (!rc)
  1881. priv->radio_on = enable;
  1882. return rc;
  1883. }
  1884. static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
  1885. {
  1886. return mwl8k_cmd_radio_control(hw, 0, 0);
  1887. }
  1888. static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
  1889. {
  1890. return mwl8k_cmd_radio_control(hw, 1, 0);
  1891. }
  1892. static int
  1893. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  1894. {
  1895. struct mwl8k_priv *priv = hw->priv;
  1896. priv->radio_short_preamble = short_preamble;
  1897. return mwl8k_cmd_radio_control(hw, 1, 1);
  1898. }
  1899. /*
  1900. * CMD_RF_TX_POWER.
  1901. */
  1902. #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
  1903. struct mwl8k_cmd_rf_tx_power {
  1904. struct mwl8k_cmd_pkt header;
  1905. __le16 action;
  1906. __le16 support_level;
  1907. __le16 current_level;
  1908. __le16 reserved;
  1909. __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
  1910. } __packed;
  1911. static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  1912. {
  1913. struct mwl8k_cmd_rf_tx_power *cmd;
  1914. int rc;
  1915. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1916. if (cmd == NULL)
  1917. return -ENOMEM;
  1918. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  1919. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1920. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1921. cmd->support_level = cpu_to_le16(dBm);
  1922. rc = mwl8k_post_cmd(hw, &cmd->header);
  1923. kfree(cmd);
  1924. return rc;
  1925. }
  1926. /*
  1927. * CMD_TX_POWER.
  1928. */
  1929. #define MWL8K_TX_POWER_LEVEL_TOTAL 12
  1930. struct mwl8k_cmd_tx_power {
  1931. struct mwl8k_cmd_pkt header;
  1932. __le16 action;
  1933. __le16 band;
  1934. __le16 channel;
  1935. __le16 bw;
  1936. __le16 sub_ch;
  1937. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  1938. } __attribute__((packed));
  1939. static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
  1940. struct ieee80211_conf *conf,
  1941. unsigned short pwr)
  1942. {
  1943. struct ieee80211_channel *channel = conf->channel;
  1944. struct mwl8k_cmd_tx_power *cmd;
  1945. int rc;
  1946. int i;
  1947. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1948. if (cmd == NULL)
  1949. return -ENOMEM;
  1950. cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
  1951. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1952. cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
  1953. if (channel->band == IEEE80211_BAND_2GHZ)
  1954. cmd->band = cpu_to_le16(0x1);
  1955. else if (channel->band == IEEE80211_BAND_5GHZ)
  1956. cmd->band = cpu_to_le16(0x4);
  1957. cmd->channel = channel->hw_value;
  1958. if (conf->channel_type == NL80211_CHAN_NO_HT ||
  1959. conf->channel_type == NL80211_CHAN_HT20) {
  1960. cmd->bw = cpu_to_le16(0x2);
  1961. } else {
  1962. cmd->bw = cpu_to_le16(0x4);
  1963. if (conf->channel_type == NL80211_CHAN_HT40MINUS)
  1964. cmd->sub_ch = cpu_to_le16(0x3);
  1965. else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
  1966. cmd->sub_ch = cpu_to_le16(0x1);
  1967. }
  1968. for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
  1969. cmd->power_level_list[i] = cpu_to_le16(pwr);
  1970. rc = mwl8k_post_cmd(hw, &cmd->header);
  1971. kfree(cmd);
  1972. return rc;
  1973. }
  1974. /*
  1975. * CMD_RF_ANTENNA.
  1976. */
  1977. struct mwl8k_cmd_rf_antenna {
  1978. struct mwl8k_cmd_pkt header;
  1979. __le16 antenna;
  1980. __le16 mode;
  1981. } __packed;
  1982. #define MWL8K_RF_ANTENNA_RX 1
  1983. #define MWL8K_RF_ANTENNA_TX 2
  1984. static int
  1985. mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
  1986. {
  1987. struct mwl8k_cmd_rf_antenna *cmd;
  1988. int rc;
  1989. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1990. if (cmd == NULL)
  1991. return -ENOMEM;
  1992. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
  1993. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1994. cmd->antenna = cpu_to_le16(antenna);
  1995. cmd->mode = cpu_to_le16(mask);
  1996. rc = mwl8k_post_cmd(hw, &cmd->header);
  1997. kfree(cmd);
  1998. return rc;
  1999. }
  2000. /*
  2001. * CMD_SET_BEACON.
  2002. */
  2003. struct mwl8k_cmd_set_beacon {
  2004. struct mwl8k_cmd_pkt header;
  2005. __le16 beacon_len;
  2006. __u8 beacon[0];
  2007. };
  2008. static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
  2009. struct ieee80211_vif *vif, u8 *beacon, int len)
  2010. {
  2011. struct mwl8k_cmd_set_beacon *cmd;
  2012. int rc;
  2013. cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
  2014. if (cmd == NULL)
  2015. return -ENOMEM;
  2016. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
  2017. cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
  2018. cmd->beacon_len = cpu_to_le16(len);
  2019. memcpy(cmd->beacon, beacon, len);
  2020. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2021. kfree(cmd);
  2022. return rc;
  2023. }
  2024. /*
  2025. * CMD_SET_PRE_SCAN.
  2026. */
  2027. struct mwl8k_cmd_set_pre_scan {
  2028. struct mwl8k_cmd_pkt header;
  2029. } __packed;
  2030. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  2031. {
  2032. struct mwl8k_cmd_set_pre_scan *cmd;
  2033. int rc;
  2034. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2035. if (cmd == NULL)
  2036. return -ENOMEM;
  2037. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  2038. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2039. rc = mwl8k_post_cmd(hw, &cmd->header);
  2040. kfree(cmd);
  2041. return rc;
  2042. }
  2043. /*
  2044. * CMD_SET_POST_SCAN.
  2045. */
  2046. struct mwl8k_cmd_set_post_scan {
  2047. struct mwl8k_cmd_pkt header;
  2048. __le32 isibss;
  2049. __u8 bssid[ETH_ALEN];
  2050. } __packed;
  2051. static int
  2052. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
  2053. {
  2054. struct mwl8k_cmd_set_post_scan *cmd;
  2055. int rc;
  2056. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2057. if (cmd == NULL)
  2058. return -ENOMEM;
  2059. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  2060. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2061. cmd->isibss = 0;
  2062. memcpy(cmd->bssid, mac, ETH_ALEN);
  2063. rc = mwl8k_post_cmd(hw, &cmd->header);
  2064. kfree(cmd);
  2065. return rc;
  2066. }
  2067. /*
  2068. * CMD_SET_RF_CHANNEL.
  2069. */
  2070. struct mwl8k_cmd_set_rf_channel {
  2071. struct mwl8k_cmd_pkt header;
  2072. __le16 action;
  2073. __u8 current_channel;
  2074. __le32 channel_flags;
  2075. } __packed;
  2076. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  2077. struct ieee80211_conf *conf)
  2078. {
  2079. struct ieee80211_channel *channel = conf->channel;
  2080. struct mwl8k_cmd_set_rf_channel *cmd;
  2081. int rc;
  2082. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2083. if (cmd == NULL)
  2084. return -ENOMEM;
  2085. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  2086. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2087. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2088. cmd->current_channel = channel->hw_value;
  2089. if (channel->band == IEEE80211_BAND_2GHZ)
  2090. cmd->channel_flags |= cpu_to_le32(0x00000001);
  2091. else if (channel->band == IEEE80211_BAND_5GHZ)
  2092. cmd->channel_flags |= cpu_to_le32(0x00000004);
  2093. if (conf->channel_type == NL80211_CHAN_NO_HT ||
  2094. conf->channel_type == NL80211_CHAN_HT20)
  2095. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2096. else if (conf->channel_type == NL80211_CHAN_HT40MINUS)
  2097. cmd->channel_flags |= cpu_to_le32(0x000001900);
  2098. else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
  2099. cmd->channel_flags |= cpu_to_le32(0x000000900);
  2100. rc = mwl8k_post_cmd(hw, &cmd->header);
  2101. kfree(cmd);
  2102. return rc;
  2103. }
  2104. /*
  2105. * CMD_SET_AID.
  2106. */
  2107. #define MWL8K_FRAME_PROT_DISABLED 0x00
  2108. #define MWL8K_FRAME_PROT_11G 0x07
  2109. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  2110. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  2111. struct mwl8k_cmd_update_set_aid {
  2112. struct mwl8k_cmd_pkt header;
  2113. __le16 aid;
  2114. /* AP's MAC address (BSSID) */
  2115. __u8 bssid[ETH_ALEN];
  2116. __le16 protection_mode;
  2117. __u8 supp_rates[14];
  2118. } __packed;
  2119. static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
  2120. {
  2121. int i;
  2122. int j;
  2123. /*
  2124. * Clear nonstandard rates 4 and 13.
  2125. */
  2126. mask &= 0x1fef;
  2127. for (i = 0, j = 0; i < 14; i++) {
  2128. if (mask & (1 << i))
  2129. rates[j++] = mwl8k_rates_24[i].hw_value;
  2130. }
  2131. }
  2132. static int
  2133. mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  2134. struct ieee80211_vif *vif, u32 legacy_rate_mask)
  2135. {
  2136. struct mwl8k_cmd_update_set_aid *cmd;
  2137. u16 prot_mode;
  2138. int rc;
  2139. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2140. if (cmd == NULL)
  2141. return -ENOMEM;
  2142. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
  2143. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2144. cmd->aid = cpu_to_le16(vif->bss_conf.aid);
  2145. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  2146. if (vif->bss_conf.use_cts_prot) {
  2147. prot_mode = MWL8K_FRAME_PROT_11G;
  2148. } else {
  2149. switch (vif->bss_conf.ht_operation_mode &
  2150. IEEE80211_HT_OP_MODE_PROTECTION) {
  2151. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  2152. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  2153. break;
  2154. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  2155. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  2156. break;
  2157. default:
  2158. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  2159. break;
  2160. }
  2161. }
  2162. cmd->protection_mode = cpu_to_le16(prot_mode);
  2163. legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
  2164. rc = mwl8k_post_cmd(hw, &cmd->header);
  2165. kfree(cmd);
  2166. return rc;
  2167. }
  2168. /*
  2169. * CMD_SET_RATE.
  2170. */
  2171. struct mwl8k_cmd_set_rate {
  2172. struct mwl8k_cmd_pkt header;
  2173. __u8 legacy_rates[14];
  2174. /* Bitmap for supported MCS codes. */
  2175. __u8 mcs_set[16];
  2176. __u8 reserved[16];
  2177. } __packed;
  2178. static int
  2179. mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2180. u32 legacy_rate_mask, u8 *mcs_rates)
  2181. {
  2182. struct mwl8k_cmd_set_rate *cmd;
  2183. int rc;
  2184. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2185. if (cmd == NULL)
  2186. return -ENOMEM;
  2187. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  2188. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2189. legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
  2190. memcpy(cmd->mcs_set, mcs_rates, 16);
  2191. rc = mwl8k_post_cmd(hw, &cmd->header);
  2192. kfree(cmd);
  2193. return rc;
  2194. }
  2195. /*
  2196. * CMD_FINALIZE_JOIN.
  2197. */
  2198. #define MWL8K_FJ_BEACON_MAXLEN 128
  2199. struct mwl8k_cmd_finalize_join {
  2200. struct mwl8k_cmd_pkt header;
  2201. __le32 sleep_interval; /* Number of beacon periods to sleep */
  2202. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  2203. } __packed;
  2204. static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
  2205. int framelen, int dtim)
  2206. {
  2207. struct mwl8k_cmd_finalize_join *cmd;
  2208. struct ieee80211_mgmt *payload = frame;
  2209. int payload_len;
  2210. int rc;
  2211. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2212. if (cmd == NULL)
  2213. return -ENOMEM;
  2214. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  2215. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2216. cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
  2217. payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
  2218. if (payload_len < 0)
  2219. payload_len = 0;
  2220. else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  2221. payload_len = MWL8K_FJ_BEACON_MAXLEN;
  2222. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  2223. rc = mwl8k_post_cmd(hw, &cmd->header);
  2224. kfree(cmd);
  2225. return rc;
  2226. }
  2227. /*
  2228. * CMD_SET_RTS_THRESHOLD.
  2229. */
  2230. struct mwl8k_cmd_set_rts_threshold {
  2231. struct mwl8k_cmd_pkt header;
  2232. __le16 action;
  2233. __le16 threshold;
  2234. } __packed;
  2235. static int
  2236. mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
  2237. {
  2238. struct mwl8k_cmd_set_rts_threshold *cmd;
  2239. int rc;
  2240. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2241. if (cmd == NULL)
  2242. return -ENOMEM;
  2243. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  2244. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2245. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2246. cmd->threshold = cpu_to_le16(rts_thresh);
  2247. rc = mwl8k_post_cmd(hw, &cmd->header);
  2248. kfree(cmd);
  2249. return rc;
  2250. }
  2251. /*
  2252. * CMD_SET_SLOT.
  2253. */
  2254. struct mwl8k_cmd_set_slot {
  2255. struct mwl8k_cmd_pkt header;
  2256. __le16 action;
  2257. __u8 short_slot;
  2258. } __packed;
  2259. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
  2260. {
  2261. struct mwl8k_cmd_set_slot *cmd;
  2262. int rc;
  2263. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2264. if (cmd == NULL)
  2265. return -ENOMEM;
  2266. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  2267. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2268. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2269. cmd->short_slot = short_slot_time;
  2270. rc = mwl8k_post_cmd(hw, &cmd->header);
  2271. kfree(cmd);
  2272. return rc;
  2273. }
  2274. /*
  2275. * CMD_SET_EDCA_PARAMS.
  2276. */
  2277. struct mwl8k_cmd_set_edca_params {
  2278. struct mwl8k_cmd_pkt header;
  2279. /* See MWL8K_SET_EDCA_XXX below */
  2280. __le16 action;
  2281. /* TX opportunity in units of 32 us */
  2282. __le16 txop;
  2283. union {
  2284. struct {
  2285. /* Log exponent of max contention period: 0...15 */
  2286. __le32 log_cw_max;
  2287. /* Log exponent of min contention period: 0...15 */
  2288. __le32 log_cw_min;
  2289. /* Adaptive interframe spacing in units of 32us */
  2290. __u8 aifs;
  2291. /* TX queue to configure */
  2292. __u8 txq;
  2293. } ap;
  2294. struct {
  2295. /* Log exponent of max contention period: 0...15 */
  2296. __u8 log_cw_max;
  2297. /* Log exponent of min contention period: 0...15 */
  2298. __u8 log_cw_min;
  2299. /* Adaptive interframe spacing in units of 32us */
  2300. __u8 aifs;
  2301. /* TX queue to configure */
  2302. __u8 txq;
  2303. } sta;
  2304. };
  2305. } __packed;
  2306. #define MWL8K_SET_EDCA_CW 0x01
  2307. #define MWL8K_SET_EDCA_TXOP 0x02
  2308. #define MWL8K_SET_EDCA_AIFS 0x04
  2309. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  2310. MWL8K_SET_EDCA_TXOP | \
  2311. MWL8K_SET_EDCA_AIFS)
  2312. static int
  2313. mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  2314. __u16 cw_min, __u16 cw_max,
  2315. __u8 aifs, __u16 txop)
  2316. {
  2317. struct mwl8k_priv *priv = hw->priv;
  2318. struct mwl8k_cmd_set_edca_params *cmd;
  2319. int rc;
  2320. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2321. if (cmd == NULL)
  2322. return -ENOMEM;
  2323. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  2324. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2325. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  2326. cmd->txop = cpu_to_le16(txop);
  2327. if (priv->ap_fw) {
  2328. cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
  2329. cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
  2330. cmd->ap.aifs = aifs;
  2331. cmd->ap.txq = qnum;
  2332. } else {
  2333. cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
  2334. cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
  2335. cmd->sta.aifs = aifs;
  2336. cmd->sta.txq = qnum;
  2337. }
  2338. rc = mwl8k_post_cmd(hw, &cmd->header);
  2339. kfree(cmd);
  2340. return rc;
  2341. }
  2342. /*
  2343. * CMD_SET_WMM_MODE.
  2344. */
  2345. struct mwl8k_cmd_set_wmm_mode {
  2346. struct mwl8k_cmd_pkt header;
  2347. __le16 action;
  2348. } __packed;
  2349. static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
  2350. {
  2351. struct mwl8k_priv *priv = hw->priv;
  2352. struct mwl8k_cmd_set_wmm_mode *cmd;
  2353. int rc;
  2354. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2355. if (cmd == NULL)
  2356. return -ENOMEM;
  2357. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  2358. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2359. cmd->action = cpu_to_le16(!!enable);
  2360. rc = mwl8k_post_cmd(hw, &cmd->header);
  2361. kfree(cmd);
  2362. if (!rc)
  2363. priv->wmm_enabled = enable;
  2364. return rc;
  2365. }
  2366. /*
  2367. * CMD_MIMO_CONFIG.
  2368. */
  2369. struct mwl8k_cmd_mimo_config {
  2370. struct mwl8k_cmd_pkt header;
  2371. __le32 action;
  2372. __u8 rx_antenna_map;
  2373. __u8 tx_antenna_map;
  2374. } __packed;
  2375. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  2376. {
  2377. struct mwl8k_cmd_mimo_config *cmd;
  2378. int rc;
  2379. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2380. if (cmd == NULL)
  2381. return -ENOMEM;
  2382. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  2383. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2384. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  2385. cmd->rx_antenna_map = rx;
  2386. cmd->tx_antenna_map = tx;
  2387. rc = mwl8k_post_cmd(hw, &cmd->header);
  2388. kfree(cmd);
  2389. return rc;
  2390. }
  2391. /*
  2392. * CMD_USE_FIXED_RATE (STA version).
  2393. */
  2394. struct mwl8k_cmd_use_fixed_rate_sta {
  2395. struct mwl8k_cmd_pkt header;
  2396. __le32 action;
  2397. __le32 allow_rate_drop;
  2398. __le32 num_rates;
  2399. struct {
  2400. __le32 is_ht_rate;
  2401. __le32 enable_retry;
  2402. __le32 rate;
  2403. __le32 retry_count;
  2404. } rate_entry[8];
  2405. __le32 rate_type;
  2406. __le32 reserved1;
  2407. __le32 reserved2;
  2408. } __packed;
  2409. #define MWL8K_USE_AUTO_RATE 0x0002
  2410. #define MWL8K_UCAST_RATE 0
  2411. static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
  2412. {
  2413. struct mwl8k_cmd_use_fixed_rate_sta *cmd;
  2414. int rc;
  2415. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2416. if (cmd == NULL)
  2417. return -ENOMEM;
  2418. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2419. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2420. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2421. cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
  2422. rc = mwl8k_post_cmd(hw, &cmd->header);
  2423. kfree(cmd);
  2424. return rc;
  2425. }
  2426. /*
  2427. * CMD_USE_FIXED_RATE (AP version).
  2428. */
  2429. struct mwl8k_cmd_use_fixed_rate_ap {
  2430. struct mwl8k_cmd_pkt header;
  2431. __le32 action;
  2432. __le32 allow_rate_drop;
  2433. __le32 num_rates;
  2434. struct mwl8k_rate_entry_ap {
  2435. __le32 is_ht_rate;
  2436. __le32 enable_retry;
  2437. __le32 rate;
  2438. __le32 retry_count;
  2439. } rate_entry[4];
  2440. u8 multicast_rate;
  2441. u8 multicast_rate_type;
  2442. u8 management_rate;
  2443. } __packed;
  2444. static int
  2445. mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
  2446. {
  2447. struct mwl8k_cmd_use_fixed_rate_ap *cmd;
  2448. int rc;
  2449. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2450. if (cmd == NULL)
  2451. return -ENOMEM;
  2452. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2453. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2454. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2455. cmd->multicast_rate = mcast;
  2456. cmd->management_rate = mgmt;
  2457. rc = mwl8k_post_cmd(hw, &cmd->header);
  2458. kfree(cmd);
  2459. return rc;
  2460. }
  2461. /*
  2462. * CMD_ENABLE_SNIFFER.
  2463. */
  2464. struct mwl8k_cmd_enable_sniffer {
  2465. struct mwl8k_cmd_pkt header;
  2466. __le32 action;
  2467. } __packed;
  2468. static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  2469. {
  2470. struct mwl8k_cmd_enable_sniffer *cmd;
  2471. int rc;
  2472. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2473. if (cmd == NULL)
  2474. return -ENOMEM;
  2475. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  2476. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2477. cmd->action = cpu_to_le32(!!enable);
  2478. rc = mwl8k_post_cmd(hw, &cmd->header);
  2479. kfree(cmd);
  2480. return rc;
  2481. }
  2482. /*
  2483. * CMD_SET_MAC_ADDR.
  2484. */
  2485. struct mwl8k_cmd_set_mac_addr {
  2486. struct mwl8k_cmd_pkt header;
  2487. union {
  2488. struct {
  2489. __le16 mac_type;
  2490. __u8 mac_addr[ETH_ALEN];
  2491. } mbss;
  2492. __u8 mac_addr[ETH_ALEN];
  2493. };
  2494. } __packed;
  2495. #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
  2496. #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
  2497. #define MWL8K_MAC_TYPE_PRIMARY_AP 2
  2498. #define MWL8K_MAC_TYPE_SECONDARY_AP 3
  2499. static int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
  2500. struct ieee80211_vif *vif, u8 *mac)
  2501. {
  2502. struct mwl8k_priv *priv = hw->priv;
  2503. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2504. struct mwl8k_cmd_set_mac_addr *cmd;
  2505. int mac_type;
  2506. int rc;
  2507. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2508. if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
  2509. if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
  2510. mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
  2511. else
  2512. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2513. } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
  2514. if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
  2515. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2516. else
  2517. mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
  2518. }
  2519. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2520. if (cmd == NULL)
  2521. return -ENOMEM;
  2522. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
  2523. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2524. if (priv->ap_fw) {
  2525. cmd->mbss.mac_type = cpu_to_le16(mac_type);
  2526. memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
  2527. } else {
  2528. memcpy(cmd->mac_addr, mac, ETH_ALEN);
  2529. }
  2530. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2531. kfree(cmd);
  2532. return rc;
  2533. }
  2534. /*
  2535. * CMD_SET_RATEADAPT_MODE.
  2536. */
  2537. struct mwl8k_cmd_set_rate_adapt_mode {
  2538. struct mwl8k_cmd_pkt header;
  2539. __le16 action;
  2540. __le16 mode;
  2541. } __packed;
  2542. static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
  2543. {
  2544. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  2545. int rc;
  2546. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2547. if (cmd == NULL)
  2548. return -ENOMEM;
  2549. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  2550. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2551. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2552. cmd->mode = cpu_to_le16(mode);
  2553. rc = mwl8k_post_cmd(hw, &cmd->header);
  2554. kfree(cmd);
  2555. return rc;
  2556. }
  2557. /*
  2558. * CMD_BSS_START.
  2559. */
  2560. struct mwl8k_cmd_bss_start {
  2561. struct mwl8k_cmd_pkt header;
  2562. __le32 enable;
  2563. } __packed;
  2564. static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
  2565. struct ieee80211_vif *vif, int enable)
  2566. {
  2567. struct mwl8k_cmd_bss_start *cmd;
  2568. int rc;
  2569. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2570. if (cmd == NULL)
  2571. return -ENOMEM;
  2572. cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
  2573. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2574. cmd->enable = cpu_to_le32(enable);
  2575. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2576. kfree(cmd);
  2577. return rc;
  2578. }
  2579. /*
  2580. * CMD_SET_NEW_STN.
  2581. */
  2582. struct mwl8k_cmd_set_new_stn {
  2583. struct mwl8k_cmd_pkt header;
  2584. __le16 aid;
  2585. __u8 mac_addr[6];
  2586. __le16 stn_id;
  2587. __le16 action;
  2588. __le16 rsvd;
  2589. __le32 legacy_rates;
  2590. __u8 ht_rates[4];
  2591. __le16 cap_info;
  2592. __le16 ht_capabilities_info;
  2593. __u8 mac_ht_param_info;
  2594. __u8 rev;
  2595. __u8 control_channel;
  2596. __u8 add_channel;
  2597. __le16 op_mode;
  2598. __le16 stbc;
  2599. __u8 add_qos_info;
  2600. __u8 is_qos_sta;
  2601. __le32 fw_sta_ptr;
  2602. } __packed;
  2603. #define MWL8K_STA_ACTION_ADD 0
  2604. #define MWL8K_STA_ACTION_REMOVE 2
  2605. static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
  2606. struct ieee80211_vif *vif,
  2607. struct ieee80211_sta *sta)
  2608. {
  2609. struct mwl8k_cmd_set_new_stn *cmd;
  2610. u32 rates;
  2611. int rc;
  2612. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2613. if (cmd == NULL)
  2614. return -ENOMEM;
  2615. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  2616. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2617. cmd->aid = cpu_to_le16(sta->aid);
  2618. memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
  2619. cmd->stn_id = cpu_to_le16(sta->aid);
  2620. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
  2621. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  2622. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  2623. else
  2624. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  2625. cmd->legacy_rates = cpu_to_le32(rates);
  2626. if (sta->ht_cap.ht_supported) {
  2627. cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
  2628. cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
  2629. cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
  2630. cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
  2631. cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
  2632. cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
  2633. ((sta->ht_cap.ampdu_density & 7) << 2);
  2634. cmd->is_qos_sta = 1;
  2635. }
  2636. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2637. kfree(cmd);
  2638. return rc;
  2639. }
  2640. static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
  2641. struct ieee80211_vif *vif)
  2642. {
  2643. struct mwl8k_cmd_set_new_stn *cmd;
  2644. int rc;
  2645. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2646. if (cmd == NULL)
  2647. return -ENOMEM;
  2648. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  2649. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2650. memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
  2651. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2652. kfree(cmd);
  2653. return rc;
  2654. }
  2655. static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
  2656. struct ieee80211_vif *vif, u8 *addr)
  2657. {
  2658. struct mwl8k_cmd_set_new_stn *cmd;
  2659. int rc;
  2660. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2661. if (cmd == NULL)
  2662. return -ENOMEM;
  2663. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  2664. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2665. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  2666. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
  2667. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2668. kfree(cmd);
  2669. return rc;
  2670. }
  2671. /*
  2672. * CMD_UPDATE_ENCRYPTION.
  2673. */
  2674. #define MAX_ENCR_KEY_LENGTH 16
  2675. #define MIC_KEY_LENGTH 8
  2676. struct mwl8k_cmd_update_encryption {
  2677. struct mwl8k_cmd_pkt header;
  2678. __le32 action;
  2679. __le32 reserved;
  2680. __u8 mac_addr[6];
  2681. __u8 encr_type;
  2682. } __attribute__((packed));
  2683. struct mwl8k_cmd_set_key {
  2684. struct mwl8k_cmd_pkt header;
  2685. __le32 action;
  2686. __le32 reserved;
  2687. __le16 length;
  2688. __le16 key_type_id;
  2689. __le32 key_info;
  2690. __le32 key_id;
  2691. __le16 key_len;
  2692. __u8 key_material[MAX_ENCR_KEY_LENGTH];
  2693. __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
  2694. __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
  2695. __le16 tkip_rsc_low;
  2696. __le32 tkip_rsc_high;
  2697. __le16 tkip_tsc_low;
  2698. __le32 tkip_tsc_high;
  2699. __u8 mac_addr[6];
  2700. } __attribute__((packed));
  2701. enum {
  2702. MWL8K_ENCR_ENABLE,
  2703. MWL8K_ENCR_SET_KEY,
  2704. MWL8K_ENCR_REMOVE_KEY,
  2705. MWL8K_ENCR_SET_GROUP_KEY,
  2706. };
  2707. #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
  2708. #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
  2709. #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
  2710. #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
  2711. #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
  2712. enum {
  2713. MWL8K_ALG_WEP,
  2714. MWL8K_ALG_TKIP,
  2715. MWL8K_ALG_CCMP,
  2716. };
  2717. #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
  2718. #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
  2719. #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
  2720. #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
  2721. #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
  2722. static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
  2723. struct ieee80211_vif *vif,
  2724. u8 *addr,
  2725. u8 encr_type)
  2726. {
  2727. struct mwl8k_cmd_update_encryption *cmd;
  2728. int rc;
  2729. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2730. if (cmd == NULL)
  2731. return -ENOMEM;
  2732. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  2733. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2734. cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
  2735. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  2736. cmd->encr_type = encr_type;
  2737. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2738. kfree(cmd);
  2739. return rc;
  2740. }
  2741. static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
  2742. u8 *addr,
  2743. struct ieee80211_key_conf *key)
  2744. {
  2745. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  2746. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2747. cmd->length = cpu_to_le16(sizeof(*cmd) -
  2748. offsetof(struct mwl8k_cmd_set_key, length));
  2749. cmd->key_id = cpu_to_le32(key->keyidx);
  2750. cmd->key_len = cpu_to_le16(key->keylen);
  2751. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  2752. switch (key->cipher) {
  2753. case WLAN_CIPHER_SUITE_WEP40:
  2754. case WLAN_CIPHER_SUITE_WEP104:
  2755. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
  2756. if (key->keyidx == 0)
  2757. cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
  2758. break;
  2759. case WLAN_CIPHER_SUITE_TKIP:
  2760. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
  2761. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  2762. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  2763. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  2764. cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
  2765. | MWL8K_KEY_FLAG_TSC_VALID);
  2766. break;
  2767. case WLAN_CIPHER_SUITE_CCMP:
  2768. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
  2769. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  2770. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  2771. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  2772. break;
  2773. default:
  2774. return -ENOTSUPP;
  2775. }
  2776. return 0;
  2777. }
  2778. static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
  2779. struct ieee80211_vif *vif,
  2780. u8 *addr,
  2781. struct ieee80211_key_conf *key)
  2782. {
  2783. struct mwl8k_cmd_set_key *cmd;
  2784. int rc;
  2785. int keymlen;
  2786. u32 action;
  2787. u8 idx;
  2788. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2789. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2790. if (cmd == NULL)
  2791. return -ENOMEM;
  2792. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  2793. if (rc < 0)
  2794. goto done;
  2795. idx = key->keyidx;
  2796. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  2797. action = MWL8K_ENCR_SET_KEY;
  2798. else
  2799. action = MWL8K_ENCR_SET_GROUP_KEY;
  2800. switch (key->cipher) {
  2801. case WLAN_CIPHER_SUITE_WEP40:
  2802. case WLAN_CIPHER_SUITE_WEP104:
  2803. if (!mwl8k_vif->wep_key_conf[idx].enabled) {
  2804. memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
  2805. sizeof(*key) + key->keylen);
  2806. mwl8k_vif->wep_key_conf[idx].enabled = 1;
  2807. }
  2808. keymlen = 0;
  2809. action = MWL8K_ENCR_SET_KEY;
  2810. break;
  2811. case WLAN_CIPHER_SUITE_TKIP:
  2812. keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
  2813. break;
  2814. case WLAN_CIPHER_SUITE_CCMP:
  2815. keymlen = key->keylen;
  2816. break;
  2817. default:
  2818. rc = -ENOTSUPP;
  2819. goto done;
  2820. }
  2821. memcpy(cmd->key_material, key->key, keymlen);
  2822. cmd->action = cpu_to_le32(action);
  2823. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2824. done:
  2825. kfree(cmd);
  2826. return rc;
  2827. }
  2828. static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
  2829. struct ieee80211_vif *vif,
  2830. u8 *addr,
  2831. struct ieee80211_key_conf *key)
  2832. {
  2833. struct mwl8k_cmd_set_key *cmd;
  2834. int rc;
  2835. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2836. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2837. if (cmd == NULL)
  2838. return -ENOMEM;
  2839. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  2840. if (rc < 0)
  2841. goto done;
  2842. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2843. WLAN_CIPHER_SUITE_WEP104)
  2844. mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
  2845. cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
  2846. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2847. done:
  2848. kfree(cmd);
  2849. return rc;
  2850. }
  2851. static int mwl8k_set_key(struct ieee80211_hw *hw,
  2852. enum set_key_cmd cmd_param,
  2853. struct ieee80211_vif *vif,
  2854. struct ieee80211_sta *sta,
  2855. struct ieee80211_key_conf *key)
  2856. {
  2857. int rc = 0;
  2858. u8 encr_type;
  2859. u8 *addr;
  2860. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2861. if (vif->type == NL80211_IFTYPE_STATION)
  2862. return -EOPNOTSUPP;
  2863. if (sta == NULL)
  2864. addr = hw->wiphy->perm_addr;
  2865. else
  2866. addr = sta->addr;
  2867. if (cmd_param == SET_KEY) {
  2868. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2869. rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
  2870. if (rc)
  2871. goto out;
  2872. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
  2873. || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
  2874. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
  2875. else
  2876. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
  2877. rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
  2878. encr_type);
  2879. if (rc)
  2880. goto out;
  2881. mwl8k_vif->is_hw_crypto_enabled = true;
  2882. } else {
  2883. rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
  2884. if (rc)
  2885. goto out;
  2886. mwl8k_vif->is_hw_crypto_enabled = false;
  2887. }
  2888. out:
  2889. return rc;
  2890. }
  2891. /*
  2892. * CMD_UPDATE_STADB.
  2893. */
  2894. struct ewc_ht_info {
  2895. __le16 control1;
  2896. __le16 control2;
  2897. __le16 control3;
  2898. } __packed;
  2899. struct peer_capability_info {
  2900. /* Peer type - AP vs. STA. */
  2901. __u8 peer_type;
  2902. /* Basic 802.11 capabilities from assoc resp. */
  2903. __le16 basic_caps;
  2904. /* Set if peer supports 802.11n high throughput (HT). */
  2905. __u8 ht_support;
  2906. /* Valid if HT is supported. */
  2907. __le16 ht_caps;
  2908. __u8 extended_ht_caps;
  2909. struct ewc_ht_info ewc_info;
  2910. /* Legacy rate table. Intersection of our rates and peer rates. */
  2911. __u8 legacy_rates[12];
  2912. /* HT rate table. Intersection of our rates and peer rates. */
  2913. __u8 ht_rates[16];
  2914. __u8 pad[16];
  2915. /* If set, interoperability mode, no proprietary extensions. */
  2916. __u8 interop;
  2917. __u8 pad2;
  2918. __u8 station_id;
  2919. __le16 amsdu_enabled;
  2920. } __packed;
  2921. struct mwl8k_cmd_update_stadb {
  2922. struct mwl8k_cmd_pkt header;
  2923. /* See STADB_ACTION_TYPE */
  2924. __le32 action;
  2925. /* Peer MAC address */
  2926. __u8 peer_addr[ETH_ALEN];
  2927. __le32 reserved;
  2928. /* Peer info - valid during add/update. */
  2929. struct peer_capability_info peer_info;
  2930. } __packed;
  2931. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  2932. #define MWL8K_STA_DB_DEL_ENTRY 2
  2933. /* Peer Entry flags - used to define the type of the peer node */
  2934. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  2935. static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
  2936. struct ieee80211_vif *vif,
  2937. struct ieee80211_sta *sta)
  2938. {
  2939. struct mwl8k_cmd_update_stadb *cmd;
  2940. struct peer_capability_info *p;
  2941. u32 rates;
  2942. int rc;
  2943. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2944. if (cmd == NULL)
  2945. return -ENOMEM;
  2946. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  2947. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2948. cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
  2949. memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
  2950. p = &cmd->peer_info;
  2951. p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  2952. p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
  2953. p->ht_support = sta->ht_cap.ht_supported;
  2954. p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
  2955. p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
  2956. ((sta->ht_cap.ampdu_density & 7) << 2);
  2957. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  2958. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  2959. else
  2960. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  2961. legacy_rate_mask_to_array(p->legacy_rates, rates);
  2962. memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
  2963. p->interop = 1;
  2964. p->amsdu_enabled = 0;
  2965. rc = mwl8k_post_cmd(hw, &cmd->header);
  2966. kfree(cmd);
  2967. return rc ? rc : p->station_id;
  2968. }
  2969. static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
  2970. struct ieee80211_vif *vif, u8 *addr)
  2971. {
  2972. struct mwl8k_cmd_update_stadb *cmd;
  2973. int rc;
  2974. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2975. if (cmd == NULL)
  2976. return -ENOMEM;
  2977. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  2978. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2979. cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
  2980. memcpy(cmd->peer_addr, addr, ETH_ALEN);
  2981. rc = mwl8k_post_cmd(hw, &cmd->header);
  2982. kfree(cmd);
  2983. return rc;
  2984. }
  2985. /*
  2986. * Interrupt handling.
  2987. */
  2988. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  2989. {
  2990. struct ieee80211_hw *hw = dev_id;
  2991. struct mwl8k_priv *priv = hw->priv;
  2992. u32 status;
  2993. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  2994. if (!status)
  2995. return IRQ_NONE;
  2996. if (status & MWL8K_A2H_INT_TX_DONE) {
  2997. status &= ~MWL8K_A2H_INT_TX_DONE;
  2998. tasklet_schedule(&priv->poll_tx_task);
  2999. }
  3000. if (status & MWL8K_A2H_INT_RX_READY) {
  3001. status &= ~MWL8K_A2H_INT_RX_READY;
  3002. tasklet_schedule(&priv->poll_rx_task);
  3003. }
  3004. if (status)
  3005. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3006. if (status & MWL8K_A2H_INT_OPC_DONE) {
  3007. if (priv->hostcmd_wait != NULL)
  3008. complete(priv->hostcmd_wait);
  3009. }
  3010. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  3011. if (!mutex_is_locked(&priv->fw_mutex) &&
  3012. priv->radio_on && priv->pending_tx_pkts)
  3013. mwl8k_tx_start(priv);
  3014. }
  3015. return IRQ_HANDLED;
  3016. }
  3017. static void mwl8k_tx_poll(unsigned long data)
  3018. {
  3019. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3020. struct mwl8k_priv *priv = hw->priv;
  3021. int limit;
  3022. int i;
  3023. limit = 32;
  3024. spin_lock_bh(&priv->tx_lock);
  3025. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3026. limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
  3027. if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
  3028. complete(priv->tx_wait);
  3029. priv->tx_wait = NULL;
  3030. }
  3031. spin_unlock_bh(&priv->tx_lock);
  3032. if (limit) {
  3033. writel(~MWL8K_A2H_INT_TX_DONE,
  3034. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3035. } else {
  3036. tasklet_schedule(&priv->poll_tx_task);
  3037. }
  3038. }
  3039. static void mwl8k_rx_poll(unsigned long data)
  3040. {
  3041. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3042. struct mwl8k_priv *priv = hw->priv;
  3043. int limit;
  3044. limit = 32;
  3045. limit -= rxq_process(hw, 0, limit);
  3046. limit -= rxq_refill(hw, 0, limit);
  3047. if (limit) {
  3048. writel(~MWL8K_A2H_INT_RX_READY,
  3049. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3050. } else {
  3051. tasklet_schedule(&priv->poll_rx_task);
  3052. }
  3053. }
  3054. /*
  3055. * Core driver operations.
  3056. */
  3057. static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3058. {
  3059. struct mwl8k_priv *priv = hw->priv;
  3060. int index = skb_get_queue_mapping(skb);
  3061. int rc;
  3062. if (!priv->radio_on) {
  3063. wiphy_debug(hw->wiphy,
  3064. "dropped TX frame since radio disabled\n");
  3065. dev_kfree_skb(skb);
  3066. return NETDEV_TX_OK;
  3067. }
  3068. rc = mwl8k_txq_xmit(hw, index, skb);
  3069. return rc;
  3070. }
  3071. static int mwl8k_start(struct ieee80211_hw *hw)
  3072. {
  3073. struct mwl8k_priv *priv = hw->priv;
  3074. int rc;
  3075. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3076. IRQF_SHARED, MWL8K_NAME, hw);
  3077. if (rc) {
  3078. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3079. return -EIO;
  3080. }
  3081. /* Enable TX reclaim and RX tasklets. */
  3082. tasklet_enable(&priv->poll_tx_task);
  3083. tasklet_enable(&priv->poll_rx_task);
  3084. /* Enable interrupts */
  3085. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3086. rc = mwl8k_fw_lock(hw);
  3087. if (!rc) {
  3088. rc = mwl8k_cmd_radio_enable(hw);
  3089. if (!priv->ap_fw) {
  3090. if (!rc)
  3091. rc = mwl8k_cmd_enable_sniffer(hw, 0);
  3092. if (!rc)
  3093. rc = mwl8k_cmd_set_pre_scan(hw);
  3094. if (!rc)
  3095. rc = mwl8k_cmd_set_post_scan(hw,
  3096. "\x00\x00\x00\x00\x00\x00");
  3097. }
  3098. if (!rc)
  3099. rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
  3100. if (!rc)
  3101. rc = mwl8k_cmd_set_wmm_mode(hw, 0);
  3102. mwl8k_fw_unlock(hw);
  3103. }
  3104. if (rc) {
  3105. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3106. free_irq(priv->pdev->irq, hw);
  3107. tasklet_disable(&priv->poll_tx_task);
  3108. tasklet_disable(&priv->poll_rx_task);
  3109. }
  3110. return rc;
  3111. }
  3112. static void mwl8k_stop(struct ieee80211_hw *hw)
  3113. {
  3114. struct mwl8k_priv *priv = hw->priv;
  3115. int i;
  3116. mwl8k_cmd_radio_disable(hw);
  3117. ieee80211_stop_queues(hw);
  3118. /* Disable interrupts */
  3119. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3120. free_irq(priv->pdev->irq, hw);
  3121. /* Stop finalize join worker */
  3122. cancel_work_sync(&priv->finalize_join_worker);
  3123. if (priv->beacon_skb != NULL)
  3124. dev_kfree_skb(priv->beacon_skb);
  3125. /* Stop TX reclaim and RX tasklets. */
  3126. tasklet_disable(&priv->poll_tx_task);
  3127. tasklet_disable(&priv->poll_rx_task);
  3128. /* Return all skbs to mac80211 */
  3129. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3130. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  3131. }
  3132. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
  3133. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  3134. struct ieee80211_vif *vif)
  3135. {
  3136. struct mwl8k_priv *priv = hw->priv;
  3137. struct mwl8k_vif *mwl8k_vif;
  3138. u32 macids_supported;
  3139. int macid, rc;
  3140. struct mwl8k_device_info *di;
  3141. /*
  3142. * Reject interface creation if sniffer mode is active, as
  3143. * STA operation is mutually exclusive with hardware sniffer
  3144. * mode. (Sniffer mode is only used on STA firmware.)
  3145. */
  3146. if (priv->sniffer_enabled) {
  3147. wiphy_info(hw->wiphy,
  3148. "unable to create STA interface because sniffer mode is enabled\n");
  3149. return -EINVAL;
  3150. }
  3151. di = priv->device_info;
  3152. switch (vif->type) {
  3153. case NL80211_IFTYPE_AP:
  3154. if (!priv->ap_fw && di->fw_image_ap) {
  3155. /* we must load the ap fw to meet this request */
  3156. if (!list_empty(&priv->vif_list))
  3157. return -EBUSY;
  3158. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3159. if (rc)
  3160. return rc;
  3161. }
  3162. macids_supported = priv->ap_macids_supported;
  3163. break;
  3164. case NL80211_IFTYPE_STATION:
  3165. if (priv->ap_fw && di->fw_image_sta) {
  3166. /* we must load the sta fw to meet this request */
  3167. if (!list_empty(&priv->vif_list))
  3168. return -EBUSY;
  3169. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  3170. if (rc)
  3171. return rc;
  3172. }
  3173. macids_supported = priv->sta_macids_supported;
  3174. break;
  3175. default:
  3176. return -EINVAL;
  3177. }
  3178. macid = ffs(macids_supported & ~priv->macids_used);
  3179. if (!macid--)
  3180. return -EBUSY;
  3181. /* Setup driver private area. */
  3182. mwl8k_vif = MWL8K_VIF(vif);
  3183. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  3184. mwl8k_vif->vif = vif;
  3185. mwl8k_vif->macid = macid;
  3186. mwl8k_vif->seqno = 0;
  3187. memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
  3188. mwl8k_vif->is_hw_crypto_enabled = false;
  3189. /* Set the mac address. */
  3190. mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
  3191. if (priv->ap_fw)
  3192. mwl8k_cmd_set_new_stn_add_self(hw, vif);
  3193. priv->macids_used |= 1 << mwl8k_vif->macid;
  3194. list_add_tail(&mwl8k_vif->list, &priv->vif_list);
  3195. return 0;
  3196. }
  3197. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  3198. struct ieee80211_vif *vif)
  3199. {
  3200. struct mwl8k_priv *priv = hw->priv;
  3201. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3202. if (priv->ap_fw)
  3203. mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
  3204. mwl8k_cmd_set_mac_addr(hw, vif, "\x00\x00\x00\x00\x00\x00");
  3205. priv->macids_used &= ~(1 << mwl8k_vif->macid);
  3206. list_del(&mwl8k_vif->list);
  3207. }
  3208. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  3209. {
  3210. struct ieee80211_conf *conf = &hw->conf;
  3211. struct mwl8k_priv *priv = hw->priv;
  3212. int rc;
  3213. if (conf->flags & IEEE80211_CONF_IDLE) {
  3214. mwl8k_cmd_radio_disable(hw);
  3215. return 0;
  3216. }
  3217. rc = mwl8k_fw_lock(hw);
  3218. if (rc)
  3219. return rc;
  3220. rc = mwl8k_cmd_radio_enable(hw);
  3221. if (rc)
  3222. goto out;
  3223. rc = mwl8k_cmd_set_rf_channel(hw, conf);
  3224. if (rc)
  3225. goto out;
  3226. if (conf->power_level > 18)
  3227. conf->power_level = 18;
  3228. if (priv->ap_fw) {
  3229. rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
  3230. if (rc)
  3231. goto out;
  3232. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
  3233. if (!rc)
  3234. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
  3235. } else {
  3236. rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
  3237. if (rc)
  3238. goto out;
  3239. rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
  3240. }
  3241. out:
  3242. mwl8k_fw_unlock(hw);
  3243. return rc;
  3244. }
  3245. static void
  3246. mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3247. struct ieee80211_bss_conf *info, u32 changed)
  3248. {
  3249. struct mwl8k_priv *priv = hw->priv;
  3250. u32 ap_legacy_rates;
  3251. u8 ap_mcs_rates[16];
  3252. int rc;
  3253. if (mwl8k_fw_lock(hw))
  3254. return;
  3255. /*
  3256. * No need to capture a beacon if we're no longer associated.
  3257. */
  3258. if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
  3259. priv->capture_beacon = false;
  3260. /*
  3261. * Get the AP's legacy and MCS rates.
  3262. */
  3263. if (vif->bss_conf.assoc) {
  3264. struct ieee80211_sta *ap;
  3265. rcu_read_lock();
  3266. ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  3267. if (ap == NULL) {
  3268. rcu_read_unlock();
  3269. goto out;
  3270. }
  3271. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ) {
  3272. ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
  3273. } else {
  3274. ap_legacy_rates =
  3275. ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3276. }
  3277. memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
  3278. rcu_read_unlock();
  3279. }
  3280. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc) {
  3281. rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
  3282. if (rc)
  3283. goto out;
  3284. rc = mwl8k_cmd_use_fixed_rate_sta(hw);
  3285. if (rc)
  3286. goto out;
  3287. }
  3288. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3289. rc = mwl8k_set_radio_preamble(hw,
  3290. vif->bss_conf.use_short_preamble);
  3291. if (rc)
  3292. goto out;
  3293. }
  3294. if (changed & BSS_CHANGED_ERP_SLOT) {
  3295. rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
  3296. if (rc)
  3297. goto out;
  3298. }
  3299. if (vif->bss_conf.assoc &&
  3300. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
  3301. BSS_CHANGED_HT))) {
  3302. rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
  3303. if (rc)
  3304. goto out;
  3305. }
  3306. if (vif->bss_conf.assoc &&
  3307. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
  3308. /*
  3309. * Finalize the join. Tell rx handler to process
  3310. * next beacon from our BSSID.
  3311. */
  3312. memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
  3313. priv->capture_beacon = true;
  3314. }
  3315. out:
  3316. mwl8k_fw_unlock(hw);
  3317. }
  3318. static void
  3319. mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3320. struct ieee80211_bss_conf *info, u32 changed)
  3321. {
  3322. int rc;
  3323. if (mwl8k_fw_lock(hw))
  3324. return;
  3325. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  3326. rc = mwl8k_set_radio_preamble(hw,
  3327. vif->bss_conf.use_short_preamble);
  3328. if (rc)
  3329. goto out;
  3330. }
  3331. if (changed & BSS_CHANGED_BASIC_RATES) {
  3332. int idx;
  3333. int rate;
  3334. /*
  3335. * Use lowest supported basic rate for multicasts
  3336. * and management frames (such as probe responses --
  3337. * beacons will always go out at 1 Mb/s).
  3338. */
  3339. idx = ffs(vif->bss_conf.basic_rates);
  3340. if (idx)
  3341. idx--;
  3342. if (hw->conf.channel->band == IEEE80211_BAND_2GHZ)
  3343. rate = mwl8k_rates_24[idx].hw_value;
  3344. else
  3345. rate = mwl8k_rates_50[idx].hw_value;
  3346. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  3347. }
  3348. if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
  3349. struct sk_buff *skb;
  3350. skb = ieee80211_beacon_get(hw, vif);
  3351. if (skb != NULL) {
  3352. mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
  3353. kfree_skb(skb);
  3354. }
  3355. }
  3356. if (changed & BSS_CHANGED_BEACON_ENABLED)
  3357. mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
  3358. out:
  3359. mwl8k_fw_unlock(hw);
  3360. }
  3361. static void
  3362. mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3363. struct ieee80211_bss_conf *info, u32 changed)
  3364. {
  3365. struct mwl8k_priv *priv = hw->priv;
  3366. if (!priv->ap_fw)
  3367. mwl8k_bss_info_changed_sta(hw, vif, info, changed);
  3368. else
  3369. mwl8k_bss_info_changed_ap(hw, vif, info, changed);
  3370. }
  3371. static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
  3372. struct netdev_hw_addr_list *mc_list)
  3373. {
  3374. struct mwl8k_cmd_pkt *cmd;
  3375. /*
  3376. * Synthesize and return a command packet that programs the
  3377. * hardware multicast address filter. At this point we don't
  3378. * know whether FIF_ALLMULTI is being requested, but if it is,
  3379. * we'll end up throwing this packet away and creating a new
  3380. * one in mwl8k_configure_filter().
  3381. */
  3382. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
  3383. return (unsigned long)cmd;
  3384. }
  3385. static int
  3386. mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
  3387. unsigned int changed_flags,
  3388. unsigned int *total_flags)
  3389. {
  3390. struct mwl8k_priv *priv = hw->priv;
  3391. /*
  3392. * Hardware sniffer mode is mutually exclusive with STA
  3393. * operation, so refuse to enable sniffer mode if a STA
  3394. * interface is active.
  3395. */
  3396. if (!list_empty(&priv->vif_list)) {
  3397. if (net_ratelimit())
  3398. wiphy_info(hw->wiphy,
  3399. "not enabling sniffer mode because STA interface is active\n");
  3400. return 0;
  3401. }
  3402. if (!priv->sniffer_enabled) {
  3403. if (mwl8k_cmd_enable_sniffer(hw, 1))
  3404. return 0;
  3405. priv->sniffer_enabled = true;
  3406. }
  3407. *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
  3408. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
  3409. FIF_OTHER_BSS;
  3410. return 1;
  3411. }
  3412. static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
  3413. {
  3414. if (!list_empty(&priv->vif_list))
  3415. return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
  3416. return NULL;
  3417. }
  3418. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  3419. unsigned int changed_flags,
  3420. unsigned int *total_flags,
  3421. u64 multicast)
  3422. {
  3423. struct mwl8k_priv *priv = hw->priv;
  3424. struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
  3425. /*
  3426. * AP firmware doesn't allow fine-grained control over
  3427. * the receive filter.
  3428. */
  3429. if (priv->ap_fw) {
  3430. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  3431. kfree(cmd);
  3432. return;
  3433. }
  3434. /*
  3435. * Enable hardware sniffer mode if FIF_CONTROL or
  3436. * FIF_OTHER_BSS is requested.
  3437. */
  3438. if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
  3439. mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
  3440. kfree(cmd);
  3441. return;
  3442. }
  3443. /* Clear unsupported feature flags */
  3444. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  3445. if (mwl8k_fw_lock(hw)) {
  3446. kfree(cmd);
  3447. return;
  3448. }
  3449. if (priv->sniffer_enabled) {
  3450. mwl8k_cmd_enable_sniffer(hw, 0);
  3451. priv->sniffer_enabled = false;
  3452. }
  3453. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  3454. if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
  3455. /*
  3456. * Disable the BSS filter.
  3457. */
  3458. mwl8k_cmd_set_pre_scan(hw);
  3459. } else {
  3460. struct mwl8k_vif *mwl8k_vif;
  3461. const u8 *bssid;
  3462. /*
  3463. * Enable the BSS filter.
  3464. *
  3465. * If there is an active STA interface, use that
  3466. * interface's BSSID, otherwise use a dummy one
  3467. * (where the OUI part needs to be nonzero for
  3468. * the BSSID to be accepted by POST_SCAN).
  3469. */
  3470. mwl8k_vif = mwl8k_first_vif(priv);
  3471. if (mwl8k_vif != NULL)
  3472. bssid = mwl8k_vif->vif->bss_conf.bssid;
  3473. else
  3474. bssid = "\x01\x00\x00\x00\x00\x00";
  3475. mwl8k_cmd_set_post_scan(hw, bssid);
  3476. }
  3477. }
  3478. /*
  3479. * If FIF_ALLMULTI is being requested, throw away the command
  3480. * packet that ->prepare_multicast() built and replace it with
  3481. * a command packet that enables reception of all multicast
  3482. * packets.
  3483. */
  3484. if (*total_flags & FIF_ALLMULTI) {
  3485. kfree(cmd);
  3486. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
  3487. }
  3488. if (cmd != NULL) {
  3489. mwl8k_post_cmd(hw, cmd);
  3490. kfree(cmd);
  3491. }
  3492. mwl8k_fw_unlock(hw);
  3493. }
  3494. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  3495. {
  3496. return mwl8k_cmd_set_rts_threshold(hw, value);
  3497. }
  3498. static int mwl8k_sta_remove(struct ieee80211_hw *hw,
  3499. struct ieee80211_vif *vif,
  3500. struct ieee80211_sta *sta)
  3501. {
  3502. struct mwl8k_priv *priv = hw->priv;
  3503. if (priv->ap_fw)
  3504. return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
  3505. else
  3506. return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
  3507. }
  3508. static int mwl8k_sta_add(struct ieee80211_hw *hw,
  3509. struct ieee80211_vif *vif,
  3510. struct ieee80211_sta *sta)
  3511. {
  3512. struct mwl8k_priv *priv = hw->priv;
  3513. int ret;
  3514. int i;
  3515. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3516. struct ieee80211_key_conf *key;
  3517. if (!priv->ap_fw) {
  3518. ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
  3519. if (ret >= 0) {
  3520. MWL8K_STA(sta)->peer_id = ret;
  3521. ret = 0;
  3522. }
  3523. } else {
  3524. ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
  3525. }
  3526. for (i = 0; i < NUM_WEP_KEYS; i++) {
  3527. key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
  3528. if (mwl8k_vif->wep_key_conf[i].enabled)
  3529. mwl8k_set_key(hw, SET_KEY, vif, sta, key);
  3530. }
  3531. return ret;
  3532. }
  3533. static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3534. const struct ieee80211_tx_queue_params *params)
  3535. {
  3536. struct mwl8k_priv *priv = hw->priv;
  3537. int rc;
  3538. rc = mwl8k_fw_lock(hw);
  3539. if (!rc) {
  3540. BUG_ON(queue > MWL8K_TX_QUEUES - 1);
  3541. memcpy(&priv->wmm_params[queue], params, sizeof(*params));
  3542. if (!priv->wmm_enabled)
  3543. rc = mwl8k_cmd_set_wmm_mode(hw, 1);
  3544. if (!rc)
  3545. rc = mwl8k_cmd_set_edca_params(hw, queue,
  3546. params->cw_min,
  3547. params->cw_max,
  3548. params->aifs,
  3549. params->txop);
  3550. mwl8k_fw_unlock(hw);
  3551. }
  3552. return rc;
  3553. }
  3554. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  3555. struct ieee80211_low_level_stats *stats)
  3556. {
  3557. return mwl8k_cmd_get_stat(hw, stats);
  3558. }
  3559. static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
  3560. struct survey_info *survey)
  3561. {
  3562. struct mwl8k_priv *priv = hw->priv;
  3563. struct ieee80211_conf *conf = &hw->conf;
  3564. if (idx != 0)
  3565. return -ENOENT;
  3566. survey->channel = conf->channel;
  3567. survey->filled = SURVEY_INFO_NOISE_DBM;
  3568. survey->noise = priv->noise;
  3569. return 0;
  3570. }
  3571. static int
  3572. mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3573. enum ieee80211_ampdu_mlme_action action,
  3574. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  3575. u8 buf_size)
  3576. {
  3577. switch (action) {
  3578. case IEEE80211_AMPDU_RX_START:
  3579. case IEEE80211_AMPDU_RX_STOP:
  3580. if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  3581. return -ENOTSUPP;
  3582. return 0;
  3583. default:
  3584. return -ENOTSUPP;
  3585. }
  3586. }
  3587. static const struct ieee80211_ops mwl8k_ops = {
  3588. .tx = mwl8k_tx,
  3589. .start = mwl8k_start,
  3590. .stop = mwl8k_stop,
  3591. .add_interface = mwl8k_add_interface,
  3592. .remove_interface = mwl8k_remove_interface,
  3593. .config = mwl8k_config,
  3594. .bss_info_changed = mwl8k_bss_info_changed,
  3595. .prepare_multicast = mwl8k_prepare_multicast,
  3596. .configure_filter = mwl8k_configure_filter,
  3597. .set_key = mwl8k_set_key,
  3598. .set_rts_threshold = mwl8k_set_rts_threshold,
  3599. .sta_add = mwl8k_sta_add,
  3600. .sta_remove = mwl8k_sta_remove,
  3601. .conf_tx = mwl8k_conf_tx,
  3602. .get_stats = mwl8k_get_stats,
  3603. .get_survey = mwl8k_get_survey,
  3604. .ampdu_action = mwl8k_ampdu_action,
  3605. };
  3606. static void mwl8k_finalize_join_worker(struct work_struct *work)
  3607. {
  3608. struct mwl8k_priv *priv =
  3609. container_of(work, struct mwl8k_priv, finalize_join_worker);
  3610. struct sk_buff *skb = priv->beacon_skb;
  3611. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  3612. int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  3613. const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
  3614. mgmt->u.beacon.variable, len);
  3615. int dtim_period = 1;
  3616. if (tim && tim[1] >= 2)
  3617. dtim_period = tim[3];
  3618. mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
  3619. dev_kfree_skb(skb);
  3620. priv->beacon_skb = NULL;
  3621. }
  3622. enum {
  3623. MWL8363 = 0,
  3624. MWL8687,
  3625. MWL8366,
  3626. };
  3627. #define MWL8K_8366_AP_FW_API 1
  3628. #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
  3629. #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
  3630. static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
  3631. [MWL8363] = {
  3632. .part_name = "88w8363",
  3633. .helper_image = "mwl8k/helper_8363.fw",
  3634. .fw_image_sta = "mwl8k/fmimage_8363.fw",
  3635. },
  3636. [MWL8687] = {
  3637. .part_name = "88w8687",
  3638. .helper_image = "mwl8k/helper_8687.fw",
  3639. .fw_image_sta = "mwl8k/fmimage_8687.fw",
  3640. },
  3641. [MWL8366] = {
  3642. .part_name = "88w8366",
  3643. .helper_image = "mwl8k/helper_8366.fw",
  3644. .fw_image_sta = "mwl8k/fmimage_8366.fw",
  3645. .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
  3646. .fw_api_ap = MWL8K_8366_AP_FW_API,
  3647. .ap_rxd_ops = &rxd_8366_ap_ops,
  3648. },
  3649. };
  3650. MODULE_FIRMWARE("mwl8k/helper_8363.fw");
  3651. MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
  3652. MODULE_FIRMWARE("mwl8k/helper_8687.fw");
  3653. MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
  3654. MODULE_FIRMWARE("mwl8k/helper_8366.fw");
  3655. MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
  3656. MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
  3657. static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  3658. { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
  3659. { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
  3660. { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
  3661. { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
  3662. { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
  3663. { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
  3664. { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
  3665. { },
  3666. };
  3667. MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
  3668. static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
  3669. {
  3670. int rc;
  3671. printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
  3672. "Trying alternative firmware %s\n", pci_name(priv->pdev),
  3673. priv->fw_pref, priv->fw_alt);
  3674. rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
  3675. if (rc) {
  3676. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  3677. pci_name(priv->pdev), priv->fw_alt);
  3678. return rc;
  3679. }
  3680. return 0;
  3681. }
  3682. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
  3683. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
  3684. {
  3685. struct mwl8k_priv *priv = context;
  3686. struct mwl8k_device_info *di = priv->device_info;
  3687. int rc;
  3688. switch (priv->fw_state) {
  3689. case FW_STATE_INIT:
  3690. if (!fw) {
  3691. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  3692. pci_name(priv->pdev), di->helper_image);
  3693. goto fail;
  3694. }
  3695. priv->fw_helper = fw;
  3696. rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
  3697. true);
  3698. if (rc && priv->fw_alt) {
  3699. rc = mwl8k_request_alt_fw(priv);
  3700. if (rc)
  3701. goto fail;
  3702. priv->fw_state = FW_STATE_LOADING_ALT;
  3703. } else if (rc)
  3704. goto fail;
  3705. else
  3706. priv->fw_state = FW_STATE_LOADING_PREF;
  3707. break;
  3708. case FW_STATE_LOADING_PREF:
  3709. if (!fw) {
  3710. if (priv->fw_alt) {
  3711. rc = mwl8k_request_alt_fw(priv);
  3712. if (rc)
  3713. goto fail;
  3714. priv->fw_state = FW_STATE_LOADING_ALT;
  3715. } else
  3716. goto fail;
  3717. } else {
  3718. priv->fw_ucode = fw;
  3719. rc = mwl8k_firmware_load_success(priv);
  3720. if (rc)
  3721. goto fail;
  3722. else
  3723. complete(&priv->firmware_loading_complete);
  3724. }
  3725. break;
  3726. case FW_STATE_LOADING_ALT:
  3727. if (!fw) {
  3728. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  3729. pci_name(priv->pdev), di->helper_image);
  3730. goto fail;
  3731. }
  3732. priv->fw_ucode = fw;
  3733. rc = mwl8k_firmware_load_success(priv);
  3734. if (rc)
  3735. goto fail;
  3736. else
  3737. complete(&priv->firmware_loading_complete);
  3738. break;
  3739. default:
  3740. printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
  3741. MWL8K_NAME, priv->fw_state);
  3742. BUG_ON(1);
  3743. }
  3744. return;
  3745. fail:
  3746. priv->fw_state = FW_STATE_ERROR;
  3747. complete(&priv->firmware_loading_complete);
  3748. device_release_driver(&priv->pdev->dev);
  3749. mwl8k_release_firmware(priv);
  3750. }
  3751. static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
  3752. bool nowait)
  3753. {
  3754. struct mwl8k_priv *priv = hw->priv;
  3755. int rc;
  3756. /* Reset firmware and hardware */
  3757. mwl8k_hw_reset(priv);
  3758. /* Ask userland hotplug daemon for the device firmware */
  3759. rc = mwl8k_request_firmware(priv, fw_image, nowait);
  3760. if (rc) {
  3761. wiphy_err(hw->wiphy, "Firmware files not found\n");
  3762. return rc;
  3763. }
  3764. if (nowait)
  3765. return rc;
  3766. /* Load firmware into hardware */
  3767. rc = mwl8k_load_firmware(hw);
  3768. if (rc)
  3769. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  3770. /* Reclaim memory once firmware is successfully loaded */
  3771. mwl8k_release_firmware(priv);
  3772. return rc;
  3773. }
  3774. /* initialize hw after successfully loading a firmware image */
  3775. static int mwl8k_probe_hw(struct ieee80211_hw *hw)
  3776. {
  3777. struct mwl8k_priv *priv = hw->priv;
  3778. int rc = 0;
  3779. int i;
  3780. if (priv->ap_fw) {
  3781. priv->rxd_ops = priv->device_info->ap_rxd_ops;
  3782. if (priv->rxd_ops == NULL) {
  3783. wiphy_err(hw->wiphy,
  3784. "Driver does not have AP firmware image support for this hardware\n");
  3785. goto err_stop_firmware;
  3786. }
  3787. } else {
  3788. priv->rxd_ops = &rxd_sta_ops;
  3789. }
  3790. priv->sniffer_enabled = false;
  3791. priv->wmm_enabled = false;
  3792. priv->pending_tx_pkts = 0;
  3793. rc = mwl8k_rxq_init(hw, 0);
  3794. if (rc)
  3795. goto err_stop_firmware;
  3796. rxq_refill(hw, 0, INT_MAX);
  3797. for (i = 0; i < MWL8K_TX_QUEUES; i++) {
  3798. rc = mwl8k_txq_init(hw, i);
  3799. if (rc)
  3800. goto err_free_queues;
  3801. }
  3802. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3803. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3804. iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
  3805. priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
  3806. iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3807. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3808. IRQF_SHARED, MWL8K_NAME, hw);
  3809. if (rc) {
  3810. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3811. goto err_free_queues;
  3812. }
  3813. /*
  3814. * Temporarily enable interrupts. Initial firmware host
  3815. * commands use interrupts and avoid polling. Disable
  3816. * interrupts when done.
  3817. */
  3818. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3819. /* Get config data, mac addrs etc */
  3820. if (priv->ap_fw) {
  3821. rc = mwl8k_cmd_get_hw_spec_ap(hw);
  3822. if (!rc)
  3823. rc = mwl8k_cmd_set_hw_spec(hw);
  3824. } else {
  3825. rc = mwl8k_cmd_get_hw_spec_sta(hw);
  3826. }
  3827. if (rc) {
  3828. wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
  3829. goto err_free_irq;
  3830. }
  3831. /* Turn radio off */
  3832. rc = mwl8k_cmd_radio_disable(hw);
  3833. if (rc) {
  3834. wiphy_err(hw->wiphy, "Cannot disable\n");
  3835. goto err_free_irq;
  3836. }
  3837. /* Clear MAC address */
  3838. rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
  3839. if (rc) {
  3840. wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
  3841. goto err_free_irq;
  3842. }
  3843. /* Disable interrupts */
  3844. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3845. free_irq(priv->pdev->irq, hw);
  3846. wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
  3847. priv->device_info->part_name,
  3848. priv->hw_rev, hw->wiphy->perm_addr,
  3849. priv->ap_fw ? "AP" : "STA",
  3850. (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
  3851. (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
  3852. return 0;
  3853. err_free_irq:
  3854. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3855. free_irq(priv->pdev->irq, hw);
  3856. err_free_queues:
  3857. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3858. mwl8k_txq_deinit(hw, i);
  3859. mwl8k_rxq_deinit(hw, 0);
  3860. err_stop_firmware:
  3861. mwl8k_hw_reset(priv);
  3862. return rc;
  3863. }
  3864. /*
  3865. * invoke mwl8k_reload_firmware to change the firmware image after the device
  3866. * has already been registered
  3867. */
  3868. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
  3869. {
  3870. int i, rc = 0;
  3871. struct mwl8k_priv *priv = hw->priv;
  3872. mwl8k_stop(hw);
  3873. mwl8k_rxq_deinit(hw, 0);
  3874. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3875. mwl8k_txq_deinit(hw, i);
  3876. rc = mwl8k_init_firmware(hw, fw_image, false);
  3877. if (rc)
  3878. goto fail;
  3879. rc = mwl8k_probe_hw(hw);
  3880. if (rc)
  3881. goto fail;
  3882. rc = mwl8k_start(hw);
  3883. if (rc)
  3884. goto fail;
  3885. rc = mwl8k_config(hw, ~0);
  3886. if (rc)
  3887. goto fail;
  3888. for (i = 0; i < MWL8K_TX_QUEUES; i++) {
  3889. rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
  3890. if (rc)
  3891. goto fail;
  3892. }
  3893. return rc;
  3894. fail:
  3895. printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
  3896. return rc;
  3897. }
  3898. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
  3899. {
  3900. struct ieee80211_hw *hw = priv->hw;
  3901. int i, rc;
  3902. rc = mwl8k_load_firmware(hw);
  3903. mwl8k_release_firmware(priv);
  3904. if (rc) {
  3905. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  3906. return rc;
  3907. }
  3908. /*
  3909. * Extra headroom is the size of the required DMA header
  3910. * minus the size of the smallest 802.11 frame (CTS frame).
  3911. */
  3912. hw->extra_tx_headroom =
  3913. sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
  3914. hw->channel_change_time = 10;
  3915. hw->queues = MWL8K_TX_QUEUES;
  3916. /* Set rssi values to dBm */
  3917. hw->flags |= IEEE80211_HW_SIGNAL_DBM;
  3918. hw->vif_data_size = sizeof(struct mwl8k_vif);
  3919. hw->sta_data_size = sizeof(struct mwl8k_sta);
  3920. priv->macids_used = 0;
  3921. INIT_LIST_HEAD(&priv->vif_list);
  3922. /* Set default radio state and preamble */
  3923. priv->radio_on = 0;
  3924. priv->radio_short_preamble = 0;
  3925. /* Finalize join worker */
  3926. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  3927. /* TX reclaim and RX tasklets. */
  3928. tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
  3929. tasklet_disable(&priv->poll_tx_task);
  3930. tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
  3931. tasklet_disable(&priv->poll_rx_task);
  3932. /* Power management cookie */
  3933. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  3934. if (priv->cookie == NULL)
  3935. return -ENOMEM;
  3936. mutex_init(&priv->fw_mutex);
  3937. priv->fw_mutex_owner = NULL;
  3938. priv->fw_mutex_depth = 0;
  3939. priv->hostcmd_wait = NULL;
  3940. spin_lock_init(&priv->tx_lock);
  3941. priv->tx_wait = NULL;
  3942. rc = mwl8k_probe_hw(hw);
  3943. if (rc)
  3944. goto err_free_cookie;
  3945. hw->wiphy->interface_modes = 0;
  3946. if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
  3947. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
  3948. if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
  3949. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  3950. rc = ieee80211_register_hw(hw);
  3951. if (rc) {
  3952. wiphy_err(hw->wiphy, "Cannot register device\n");
  3953. goto err_unprobe_hw;
  3954. }
  3955. return 0;
  3956. err_unprobe_hw:
  3957. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3958. mwl8k_txq_deinit(hw, i);
  3959. mwl8k_rxq_deinit(hw, 0);
  3960. err_free_cookie:
  3961. if (priv->cookie != NULL)
  3962. pci_free_consistent(priv->pdev, 4,
  3963. priv->cookie, priv->cookie_dma);
  3964. return rc;
  3965. }
  3966. static int __devinit mwl8k_probe(struct pci_dev *pdev,
  3967. const struct pci_device_id *id)
  3968. {
  3969. static int printed_version;
  3970. struct ieee80211_hw *hw;
  3971. struct mwl8k_priv *priv;
  3972. struct mwl8k_device_info *di;
  3973. int rc;
  3974. if (!printed_version) {
  3975. printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
  3976. printed_version = 1;
  3977. }
  3978. rc = pci_enable_device(pdev);
  3979. if (rc) {
  3980. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  3981. MWL8K_NAME);
  3982. return rc;
  3983. }
  3984. rc = pci_request_regions(pdev, MWL8K_NAME);
  3985. if (rc) {
  3986. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  3987. MWL8K_NAME);
  3988. goto err_disable_device;
  3989. }
  3990. pci_set_master(pdev);
  3991. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  3992. if (hw == NULL) {
  3993. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  3994. rc = -ENOMEM;
  3995. goto err_free_reg;
  3996. }
  3997. SET_IEEE80211_DEV(hw, &pdev->dev);
  3998. pci_set_drvdata(pdev, hw);
  3999. priv = hw->priv;
  4000. priv->hw = hw;
  4001. priv->pdev = pdev;
  4002. priv->device_info = &mwl8k_info_tbl[id->driver_data];
  4003. priv->sram = pci_iomap(pdev, 0, 0x10000);
  4004. if (priv->sram == NULL) {
  4005. wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
  4006. goto err_iounmap;
  4007. }
  4008. /*
  4009. * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
  4010. * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
  4011. */
  4012. priv->regs = pci_iomap(pdev, 1, 0x10000);
  4013. if (priv->regs == NULL) {
  4014. priv->regs = pci_iomap(pdev, 2, 0x10000);
  4015. if (priv->regs == NULL) {
  4016. wiphy_err(hw->wiphy, "Cannot map device registers\n");
  4017. goto err_iounmap;
  4018. }
  4019. }
  4020. /*
  4021. * Choose the initial fw image depending on user input. If a second
  4022. * image is available, make it the alternative image that will be
  4023. * loaded if the first one fails.
  4024. */
  4025. init_completion(&priv->firmware_loading_complete);
  4026. di = priv->device_info;
  4027. if (ap_mode_default && di->fw_image_ap) {
  4028. priv->fw_pref = di->fw_image_ap;
  4029. priv->fw_alt = di->fw_image_sta;
  4030. } else if (!ap_mode_default && di->fw_image_sta) {
  4031. priv->fw_pref = di->fw_image_sta;
  4032. priv->fw_alt = di->fw_image_ap;
  4033. } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
  4034. printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
  4035. priv->fw_pref = di->fw_image_sta;
  4036. } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
  4037. printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
  4038. priv->fw_pref = di->fw_image_ap;
  4039. }
  4040. rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
  4041. if (rc)
  4042. goto err_stop_firmware;
  4043. return rc;
  4044. err_stop_firmware:
  4045. mwl8k_hw_reset(priv);
  4046. err_iounmap:
  4047. if (priv->regs != NULL)
  4048. pci_iounmap(pdev, priv->regs);
  4049. if (priv->sram != NULL)
  4050. pci_iounmap(pdev, priv->sram);
  4051. pci_set_drvdata(pdev, NULL);
  4052. ieee80211_free_hw(hw);
  4053. err_free_reg:
  4054. pci_release_regions(pdev);
  4055. err_disable_device:
  4056. pci_disable_device(pdev);
  4057. return rc;
  4058. }
  4059. static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
  4060. {
  4061. printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
  4062. }
  4063. static void __devexit mwl8k_remove(struct pci_dev *pdev)
  4064. {
  4065. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  4066. struct mwl8k_priv *priv;
  4067. int i;
  4068. if (hw == NULL)
  4069. return;
  4070. priv = hw->priv;
  4071. wait_for_completion(&priv->firmware_loading_complete);
  4072. if (priv->fw_state == FW_STATE_ERROR) {
  4073. mwl8k_hw_reset(priv);
  4074. goto unmap;
  4075. }
  4076. ieee80211_stop_queues(hw);
  4077. ieee80211_unregister_hw(hw);
  4078. /* Remove TX reclaim and RX tasklets. */
  4079. tasklet_kill(&priv->poll_tx_task);
  4080. tasklet_kill(&priv->poll_rx_task);
  4081. /* Stop hardware */
  4082. mwl8k_hw_reset(priv);
  4083. /* Return all skbs to mac80211 */
  4084. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  4085. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  4086. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  4087. mwl8k_txq_deinit(hw, i);
  4088. mwl8k_rxq_deinit(hw, 0);
  4089. pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
  4090. unmap:
  4091. pci_iounmap(pdev, priv->regs);
  4092. pci_iounmap(pdev, priv->sram);
  4093. pci_set_drvdata(pdev, NULL);
  4094. ieee80211_free_hw(hw);
  4095. pci_release_regions(pdev);
  4096. pci_disable_device(pdev);
  4097. }
  4098. static struct pci_driver mwl8k_driver = {
  4099. .name = MWL8K_NAME,
  4100. .id_table = mwl8k_pci_id_table,
  4101. .probe = mwl8k_probe,
  4102. .remove = __devexit_p(mwl8k_remove),
  4103. .shutdown = __devexit_p(mwl8k_shutdown),
  4104. };
  4105. static int __init mwl8k_init(void)
  4106. {
  4107. return pci_register_driver(&mwl8k_driver);
  4108. }
  4109. static void __exit mwl8k_exit(void)
  4110. {
  4111. pci_unregister_driver(&mwl8k_driver);
  4112. }
  4113. module_init(mwl8k_init);
  4114. module_exit(mwl8k_exit);
  4115. MODULE_DESCRIPTION(MWL8K_DESC);
  4116. MODULE_VERSION(MWL8K_VERSION);
  4117. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  4118. MODULE_LICENSE("GPL");