4965-mac.c 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/if_arp.h>
  44. #include <net/mac80211.h>
  45. #include <asm/div64.h>
  46. #define DRV_NAME "iwl4965"
  47. #include "iwl-eeprom.h"
  48. #include "iwl-dev.h"
  49. #include "iwl-core.h"
  50. #include "iwl-io.h"
  51. #include "iwl-helpers.h"
  52. #include "iwl-sta.h"
  53. #include "iwl-4965-calib.h"
  54. #include "iwl-4965.h"
  55. /******************************************************************************
  56. *
  57. * module boiler plate
  58. *
  59. ******************************************************************************/
  60. /*
  61. * module name, copyright, version, etc.
  62. */
  63. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux"
  64. #ifdef CONFIG_IWLEGACY_DEBUG
  65. #define VD "d"
  66. #else
  67. #define VD
  68. #endif
  69. #define DRV_VERSION IWLWIFI_VERSION VD
  70. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  71. MODULE_VERSION(DRV_VERSION);
  72. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  73. MODULE_LICENSE("GPL");
  74. MODULE_ALIAS("iwl4965");
  75. void il4965_check_abort_status(struct il_priv *il,
  76. u8 frame_count, u32 status)
  77. {
  78. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  79. IL_ERR("Tx flush command to flush out all frames\n");
  80. if (!test_bit(STATUS_EXIT_PENDING, &il->status))
  81. queue_work(il->workqueue, &il->tx_flush);
  82. }
  83. }
  84. /*
  85. * EEPROM
  86. */
  87. struct il_mod_params il4965_mod_params = {
  88. .amsdu_size_8K = 1,
  89. .restart_fw = 1,
  90. /* the rest are 0 by default */
  91. };
  92. void il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq)
  93. {
  94. unsigned long flags;
  95. int i;
  96. spin_lock_irqsave(&rxq->lock, flags);
  97. INIT_LIST_HEAD(&rxq->rx_free);
  98. INIT_LIST_HEAD(&rxq->rx_used);
  99. /* Fill the rx_used queue with _all_ of the Rx buffers */
  100. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  101. /* In the reset function, these buffers may have been allocated
  102. * to an SKB, so we need to unmap and free potential storage */
  103. if (rxq->pool[i].page != NULL) {
  104. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  105. PAGE_SIZE << il->hw_params.rx_page_order,
  106. PCI_DMA_FROMDEVICE);
  107. __il_free_pages(il, rxq->pool[i].page);
  108. rxq->pool[i].page = NULL;
  109. }
  110. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  111. }
  112. for (i = 0; i < RX_QUEUE_SIZE; i++)
  113. rxq->queue[i] = NULL;
  114. /* Set us so that we have processed and used all buffers, but have
  115. * not restocked the Rx queue with fresh buffers */
  116. rxq->read = rxq->write = 0;
  117. rxq->write_actual = 0;
  118. rxq->free_count = 0;
  119. spin_unlock_irqrestore(&rxq->lock, flags);
  120. }
  121. int il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
  122. {
  123. u32 rb_size;
  124. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  125. u32 rb_timeout = 0;
  126. if (il->cfg->mod_params->amsdu_size_8K)
  127. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  128. else
  129. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  130. /* Stop Rx DMA */
  131. il_wr(il, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  132. /* Reset driver's Rx queue write idx */
  133. il_wr(il, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  134. /* Tell device where to find RBD circular buffer in DRAM */
  135. il_wr(il, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  136. (u32)(rxq->bd_dma >> 8));
  137. /* Tell device where in DRAM to update its Rx status */
  138. il_wr(il, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  139. rxq->rb_stts_dma >> 4);
  140. /* Enable Rx DMA
  141. * Direct rx interrupts to hosts
  142. * Rx buffer size 4 or 8k
  143. * RB timeout 0x10
  144. * 256 RBDs
  145. */
  146. il_wr(il, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  147. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  148. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  149. FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  150. rb_size|
  151. (rb_timeout << FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS)|
  152. (rfdnlog << FH_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  153. /* Set interrupt coalescing timer to default (2048 usecs) */
  154. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_TIMEOUT_DEF);
  155. return 0;
  156. }
  157. static void il4965_set_pwr_vmain(struct il_priv *il)
  158. {
  159. /*
  160. * (for documentation purposes)
  161. * to set power to V_AUX, do:
  162. if (pci_pme_capable(il->pci_dev, PCI_D3cold))
  163. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  164. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  165. ~APMG_PS_CTRL_MSK_PWR_SRC);
  166. */
  167. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  168. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  169. ~APMG_PS_CTRL_MSK_PWR_SRC);
  170. }
  171. int il4965_hw_nic_init(struct il_priv *il)
  172. {
  173. unsigned long flags;
  174. struct il_rx_queue *rxq = &il->rxq;
  175. int ret;
  176. /* nic_init */
  177. spin_lock_irqsave(&il->lock, flags);
  178. il->cfg->ops->lib->apm_ops.init(il);
  179. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  180. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_CALIB_TIMEOUT_DEF);
  181. spin_unlock_irqrestore(&il->lock, flags);
  182. il4965_set_pwr_vmain(il);
  183. il->cfg->ops->lib->apm_ops.config(il);
  184. /* Allocate the RX queue, or reset if it is already allocated */
  185. if (!rxq->bd) {
  186. ret = il_rx_queue_alloc(il);
  187. if (ret) {
  188. IL_ERR("Unable to initialize Rx queue\n");
  189. return -ENOMEM;
  190. }
  191. } else
  192. il4965_rx_queue_reset(il, rxq);
  193. il4965_rx_replenish(il);
  194. il4965_rx_init(il, rxq);
  195. spin_lock_irqsave(&il->lock, flags);
  196. rxq->need_update = 1;
  197. il_rx_queue_update_write_ptr(il, rxq);
  198. spin_unlock_irqrestore(&il->lock, flags);
  199. /* Allocate or reset and init all Tx and Command queues */
  200. if (!il->txq) {
  201. ret = il4965_txq_ctx_alloc(il);
  202. if (ret)
  203. return ret;
  204. } else
  205. il4965_txq_ctx_reset(il);
  206. set_bit(STATUS_INIT, &il->status);
  207. return 0;
  208. }
  209. /**
  210. * il4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  211. */
  212. static inline __le32 il4965_dma_addr2rbd_ptr(struct il_priv *il,
  213. dma_addr_t dma_addr)
  214. {
  215. return cpu_to_le32((u32)(dma_addr >> 8));
  216. }
  217. /**
  218. * il4965_rx_queue_restock - refill RX queue from pre-allocated pool
  219. *
  220. * If there are slots in the RX queue that need to be restocked,
  221. * and we have free pre-allocated buffers, fill the ranks as much
  222. * as we can, pulling from rx_free.
  223. *
  224. * This moves the 'write' idx forward to catch up with 'processed', and
  225. * also updates the memory address in the firmware to reference the new
  226. * target buffer.
  227. */
  228. void il4965_rx_queue_restock(struct il_priv *il)
  229. {
  230. struct il_rx_queue *rxq = &il->rxq;
  231. struct list_head *element;
  232. struct il_rx_buf *rxb;
  233. unsigned long flags;
  234. spin_lock_irqsave(&rxq->lock, flags);
  235. while (il_rx_queue_space(rxq) > 0 && rxq->free_count) {
  236. /* The overwritten rxb must be a used one */
  237. rxb = rxq->queue[rxq->write];
  238. BUG_ON(rxb && rxb->page);
  239. /* Get next free Rx buffer, remove from free list */
  240. element = rxq->rx_free.next;
  241. rxb = list_entry(element, struct il_rx_buf, list);
  242. list_del(element);
  243. /* Point to Rx buffer via next RBD in circular buffer */
  244. rxq->bd[rxq->write] = il4965_dma_addr2rbd_ptr(il,
  245. rxb->page_dma);
  246. rxq->queue[rxq->write] = rxb;
  247. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  248. rxq->free_count--;
  249. }
  250. spin_unlock_irqrestore(&rxq->lock, flags);
  251. /* If the pre-allocated buffer pool is dropping low, schedule to
  252. * refill it */
  253. if (rxq->free_count <= RX_LOW_WATERMARK)
  254. queue_work(il->workqueue, &il->rx_replenish);
  255. /* If we've added more space for the firmware to place data, tell it.
  256. * Increment device's write pointer in multiples of 8. */
  257. if (rxq->write_actual != (rxq->write & ~0x7)) {
  258. spin_lock_irqsave(&rxq->lock, flags);
  259. rxq->need_update = 1;
  260. spin_unlock_irqrestore(&rxq->lock, flags);
  261. il_rx_queue_update_write_ptr(il, rxq);
  262. }
  263. }
  264. /**
  265. * il4965_rx_replenish - Move all used packet from rx_used to rx_free
  266. *
  267. * When moving to rx_free an SKB is allocated for the slot.
  268. *
  269. * Also restock the Rx queue via il_rx_queue_restock.
  270. * This is called as a scheduled work item (except for during initialization)
  271. */
  272. static void il4965_rx_allocate(struct il_priv *il, gfp_t priority)
  273. {
  274. struct il_rx_queue *rxq = &il->rxq;
  275. struct list_head *element;
  276. struct il_rx_buf *rxb;
  277. struct page *page;
  278. unsigned long flags;
  279. gfp_t gfp_mask = priority;
  280. while (1) {
  281. spin_lock_irqsave(&rxq->lock, flags);
  282. if (list_empty(&rxq->rx_used)) {
  283. spin_unlock_irqrestore(&rxq->lock, flags);
  284. return;
  285. }
  286. spin_unlock_irqrestore(&rxq->lock, flags);
  287. if (rxq->free_count > RX_LOW_WATERMARK)
  288. gfp_mask |= __GFP_NOWARN;
  289. if (il->hw_params.rx_page_order > 0)
  290. gfp_mask |= __GFP_COMP;
  291. /* Alloc a new receive buffer */
  292. page = alloc_pages(gfp_mask, il->hw_params.rx_page_order);
  293. if (!page) {
  294. if (net_ratelimit())
  295. D_INFO("alloc_pages failed, "
  296. "order: %d\n",
  297. il->hw_params.rx_page_order);
  298. if (rxq->free_count <= RX_LOW_WATERMARK &&
  299. net_ratelimit())
  300. IL_ERR(
  301. "Failed to alloc_pages with %s. "
  302. "Only %u free buffers remaining.\n",
  303. priority == GFP_ATOMIC ?
  304. "GFP_ATOMIC" : "GFP_KERNEL",
  305. rxq->free_count);
  306. /* We don't reschedule replenish work here -- we will
  307. * call the restock method and if it still needs
  308. * more buffers it will schedule replenish */
  309. return;
  310. }
  311. spin_lock_irqsave(&rxq->lock, flags);
  312. if (list_empty(&rxq->rx_used)) {
  313. spin_unlock_irqrestore(&rxq->lock, flags);
  314. __free_pages(page, il->hw_params.rx_page_order);
  315. return;
  316. }
  317. element = rxq->rx_used.next;
  318. rxb = list_entry(element, struct il_rx_buf, list);
  319. list_del(element);
  320. spin_unlock_irqrestore(&rxq->lock, flags);
  321. BUG_ON(rxb->page);
  322. rxb->page = page;
  323. /* Get physical address of the RB */
  324. rxb->page_dma = pci_map_page(il->pci_dev, page, 0,
  325. PAGE_SIZE << il->hw_params.rx_page_order,
  326. PCI_DMA_FROMDEVICE);
  327. /* dma address must be no more than 36 bits */
  328. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  329. /* and also 256 byte aligned! */
  330. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  331. spin_lock_irqsave(&rxq->lock, flags);
  332. list_add_tail(&rxb->list, &rxq->rx_free);
  333. rxq->free_count++;
  334. il->alloc_rxb_page++;
  335. spin_unlock_irqrestore(&rxq->lock, flags);
  336. }
  337. }
  338. void il4965_rx_replenish(struct il_priv *il)
  339. {
  340. unsigned long flags;
  341. il4965_rx_allocate(il, GFP_KERNEL);
  342. spin_lock_irqsave(&il->lock, flags);
  343. il4965_rx_queue_restock(il);
  344. spin_unlock_irqrestore(&il->lock, flags);
  345. }
  346. void il4965_rx_replenish_now(struct il_priv *il)
  347. {
  348. il4965_rx_allocate(il, GFP_ATOMIC);
  349. il4965_rx_queue_restock(il);
  350. }
  351. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  352. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  353. * This free routine walks the list of POOL entries and if SKB is set to
  354. * non NULL it is unmapped and freed
  355. */
  356. void il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq)
  357. {
  358. int i;
  359. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  360. if (rxq->pool[i].page != NULL) {
  361. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  362. PAGE_SIZE << il->hw_params.rx_page_order,
  363. PCI_DMA_FROMDEVICE);
  364. __il_free_pages(il, rxq->pool[i].page);
  365. rxq->pool[i].page = NULL;
  366. }
  367. }
  368. dma_free_coherent(&il->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  369. rxq->bd_dma);
  370. dma_free_coherent(&il->pci_dev->dev, sizeof(struct il_rb_status),
  371. rxq->rb_stts, rxq->rb_stts_dma);
  372. rxq->bd = NULL;
  373. rxq->rb_stts = NULL;
  374. }
  375. int il4965_rxq_stop(struct il_priv *il)
  376. {
  377. /* stop Rx DMA */
  378. il_wr(il, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  379. il_poll_bit(il, FH_MEM_RSSR_RX_STATUS_REG,
  380. FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  381. return 0;
  382. }
  383. int il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  384. {
  385. int idx = 0;
  386. int band_offset = 0;
  387. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  388. if (rate_n_flags & RATE_MCS_HT_MSK) {
  389. idx = (rate_n_flags & 0xff);
  390. return idx;
  391. /* Legacy rate format, search for match in table */
  392. } else {
  393. if (band == IEEE80211_BAND_5GHZ)
  394. band_offset = IL_FIRST_OFDM_RATE;
  395. for (idx = band_offset; idx < RATE_COUNT_LEGACY; idx++)
  396. if (il_rates[idx].plcp == (rate_n_flags & 0xFF))
  397. return idx - band_offset;
  398. }
  399. return -1;
  400. }
  401. static int il4965_calc_rssi(struct il_priv *il,
  402. struct il_rx_phy_res *rx_resp)
  403. {
  404. /* data from PHY/DSP regarding signal strength, etc.,
  405. * contents are always there, not configurable by host. */
  406. struct il4965_rx_non_cfg_phy *ncphy =
  407. (struct il4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  408. u32 agc = (le16_to_cpu(ncphy->agc_info) & IL49_AGC_DB_MASK)
  409. >> IL49_AGC_DB_POS;
  410. u32 valid_antennae =
  411. (le16_to_cpu(rx_resp->phy_flags) & IL49_RX_PHY_FLAGS_ANTENNAE_MASK)
  412. >> IL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
  413. u8 max_rssi = 0;
  414. u32 i;
  415. /* Find max rssi among 3 possible receivers.
  416. * These values are measured by the digital signal processor (DSP).
  417. * They should stay fairly constant even as the signal strength varies,
  418. * if the radio's automatic gain control (AGC) is working right.
  419. * AGC value (see below) will provide the "interesting" info. */
  420. for (i = 0; i < 3; i++)
  421. if (valid_antennae & (1 << i))
  422. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  423. D_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  424. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  425. max_rssi, agc);
  426. /* dBm = max_rssi dB - agc dB - constant.
  427. * Higher AGC (higher radio gain) means lower signal. */
  428. return max_rssi - agc - IL4965_RSSI_OFFSET;
  429. }
  430. static u32 il4965_translate_rx_status(struct il_priv *il, u32 decrypt_in)
  431. {
  432. u32 decrypt_out = 0;
  433. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  434. RX_RES_STATUS_STATION_FOUND)
  435. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  436. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  437. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  438. /* packet was not encrypted */
  439. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  440. RX_RES_STATUS_SEC_TYPE_NONE)
  441. return decrypt_out;
  442. /* packet was encrypted with unknown alg */
  443. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  444. RX_RES_STATUS_SEC_TYPE_ERR)
  445. return decrypt_out;
  446. /* decryption was not done in HW */
  447. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  448. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  449. return decrypt_out;
  450. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  451. case RX_RES_STATUS_SEC_TYPE_CCMP:
  452. /* alg is CCM: check MIC only */
  453. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  454. /* Bad MIC */
  455. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  456. else
  457. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  458. break;
  459. case RX_RES_STATUS_SEC_TYPE_TKIP:
  460. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  461. /* Bad TTAK */
  462. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  463. break;
  464. }
  465. /* fall through if TTAK OK */
  466. default:
  467. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  468. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  469. else
  470. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  471. break;
  472. }
  473. D_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
  474. decrypt_in, decrypt_out);
  475. return decrypt_out;
  476. }
  477. static void il4965_pass_packet_to_mac80211(struct il_priv *il,
  478. struct ieee80211_hdr *hdr,
  479. u16 len,
  480. u32 ampdu_status,
  481. struct il_rx_buf *rxb,
  482. struct ieee80211_rx_status *stats)
  483. {
  484. struct sk_buff *skb;
  485. __le16 fc = hdr->frame_control;
  486. /* We only process data packets if the interface is open */
  487. if (unlikely(!il->is_open)) {
  488. D_DROP(
  489. "Dropping packet while interface is not open.\n");
  490. return;
  491. }
  492. /* In case of HW accelerated crypto and bad decryption, drop */
  493. if (!il->cfg->mod_params->sw_crypto &&
  494. il_set_decrypted_flag(il, hdr, ampdu_status, stats))
  495. return;
  496. skb = dev_alloc_skb(128);
  497. if (!skb) {
  498. IL_ERR("dev_alloc_skb failed\n");
  499. return;
  500. }
  501. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  502. il_update_stats(il, false, fc, len);
  503. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  504. ieee80211_rx(il->hw, skb);
  505. il->alloc_rxb_page--;
  506. rxb->page = NULL;
  507. }
  508. /* Called for REPLY_RX (legacy ABG frames), or
  509. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  510. void il4965_rx_reply_rx(struct il_priv *il,
  511. struct il_rx_buf *rxb)
  512. {
  513. struct ieee80211_hdr *header;
  514. struct ieee80211_rx_status rx_status;
  515. struct il_rx_pkt *pkt = rxb_addr(rxb);
  516. struct il_rx_phy_res *phy_res;
  517. __le32 rx_pkt_status;
  518. struct il_rx_mpdu_res_start *amsdu;
  519. u32 len;
  520. u32 ampdu_status;
  521. u32 rate_n_flags;
  522. /**
  523. * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
  524. * REPLY_RX: physical layer info is in this buffer
  525. * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
  526. * command and cached in il->last_phy_res
  527. *
  528. * Here we set up local variables depending on which command is
  529. * received.
  530. */
  531. if (pkt->hdr.cmd == REPLY_RX) {
  532. phy_res = (struct il_rx_phy_res *)pkt->u.raw;
  533. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
  534. + phy_res->cfg_phy_cnt);
  535. len = le16_to_cpu(phy_res->byte_count);
  536. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
  537. phy_res->cfg_phy_cnt + len);
  538. ampdu_status = le32_to_cpu(rx_pkt_status);
  539. } else {
  540. if (!il->_4965.last_phy_res_valid) {
  541. IL_ERR("MPDU frame without cached PHY data\n");
  542. return;
  543. }
  544. phy_res = &il->_4965.last_phy_res;
  545. amsdu = (struct il_rx_mpdu_res_start *)pkt->u.raw;
  546. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  547. len = le16_to_cpu(amsdu->byte_count);
  548. rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
  549. ampdu_status = il4965_translate_rx_status(il,
  550. le32_to_cpu(rx_pkt_status));
  551. }
  552. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  553. D_DROP("dsp size out of range [0,20]: %d/n",
  554. phy_res->cfg_phy_cnt);
  555. return;
  556. }
  557. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  558. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  559. D_RX("Bad CRC or FIFO: 0x%08X.\n",
  560. le32_to_cpu(rx_pkt_status));
  561. return;
  562. }
  563. /* This will be used in several places later */
  564. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  565. /* rx_status carries information about the packet to mac80211 */
  566. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  567. rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  568. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  569. rx_status.freq =
  570. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  571. rx_status.band);
  572. rx_status.rate_idx =
  573. il4965_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  574. rx_status.flag = 0;
  575. /* TSF isn't reliable. In order to allow smooth user experience,
  576. * this W/A doesn't propagate it to the mac80211 */
  577. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
  578. il->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  579. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  580. rx_status.signal = il4965_calc_rssi(il, phy_res);
  581. il_dbg_log_rx_data_frame(il, len, header);
  582. D_STATS("Rssi %d, TSF %llu\n",
  583. rx_status.signal, (unsigned long long)rx_status.mactime);
  584. /*
  585. * "antenna number"
  586. *
  587. * It seems that the antenna field in the phy flags value
  588. * is actually a bit field. This is undefined by radiotap,
  589. * it wants an actual antenna number but I always get "7"
  590. * for most legacy frames I receive indicating that the
  591. * same frame was received on all three RX chains.
  592. *
  593. * I think this field should be removed in favor of a
  594. * new 802.11n radiotap field "RX chains" that is defined
  595. * as a bitmask.
  596. */
  597. rx_status.antenna =
  598. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
  599. >> RX_RES_PHY_FLAGS_ANTENNA_POS;
  600. /* set the preamble flag if appropriate */
  601. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  602. rx_status.flag |= RX_FLAG_SHORTPRE;
  603. /* Set up the HT phy flags */
  604. if (rate_n_flags & RATE_MCS_HT_MSK)
  605. rx_status.flag |= RX_FLAG_HT;
  606. if (rate_n_flags & RATE_MCS_HT40_MSK)
  607. rx_status.flag |= RX_FLAG_40MHZ;
  608. if (rate_n_flags & RATE_MCS_SGI_MSK)
  609. rx_status.flag |= RX_FLAG_SHORT_GI;
  610. il4965_pass_packet_to_mac80211(il, header, len, ampdu_status,
  611. rxb, &rx_status);
  612. }
  613. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  614. * This will be used later in il_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  615. void il4965_rx_reply_rx_phy(struct il_priv *il,
  616. struct il_rx_buf *rxb)
  617. {
  618. struct il_rx_pkt *pkt = rxb_addr(rxb);
  619. il->_4965.last_phy_res_valid = true;
  620. memcpy(&il->_4965.last_phy_res, pkt->u.raw,
  621. sizeof(struct il_rx_phy_res));
  622. }
  623. static int il4965_get_channels_for_scan(struct il_priv *il,
  624. struct ieee80211_vif *vif,
  625. enum ieee80211_band band,
  626. u8 is_active, u8 n_probes,
  627. struct il_scan_channel *scan_ch)
  628. {
  629. struct ieee80211_channel *chan;
  630. const struct ieee80211_supported_band *sband;
  631. const struct il_channel_info *ch_info;
  632. u16 passive_dwell = 0;
  633. u16 active_dwell = 0;
  634. int added, i;
  635. u16 channel;
  636. sband = il_get_hw_mode(il, band);
  637. if (!sband)
  638. return 0;
  639. active_dwell = il_get_active_dwell_time(il, band, n_probes);
  640. passive_dwell = il_get_passive_dwell_time(il, band, vif);
  641. if (passive_dwell <= active_dwell)
  642. passive_dwell = active_dwell + 1;
  643. for (i = 0, added = 0; i < il->scan_request->n_channels; i++) {
  644. chan = il->scan_request->channels[i];
  645. if (chan->band != band)
  646. continue;
  647. channel = chan->hw_value;
  648. scan_ch->channel = cpu_to_le16(channel);
  649. ch_info = il_get_channel_info(il, band, channel);
  650. if (!il_is_channel_valid(ch_info)) {
  651. D_SCAN(
  652. "Channel %d is INVALID for this band.\n",
  653. channel);
  654. continue;
  655. }
  656. if (!is_active || il_is_channel_passive(ch_info) ||
  657. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  658. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  659. else
  660. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  661. if (n_probes)
  662. scan_ch->type |= IL_SCAN_PROBE_MASK(n_probes);
  663. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  664. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  665. /* Set txpower levels to defaults */
  666. scan_ch->dsp_atten = 110;
  667. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  668. * power level:
  669. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  670. */
  671. if (band == IEEE80211_BAND_5GHZ)
  672. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  673. else
  674. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  675. D_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n",
  676. channel, le32_to_cpu(scan_ch->type),
  677. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  678. "ACTIVE" : "PASSIVE",
  679. (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ?
  680. active_dwell : passive_dwell);
  681. scan_ch++;
  682. added++;
  683. }
  684. D_SCAN("total channels to scan %d\n", added);
  685. return added;
  686. }
  687. int il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif)
  688. {
  689. struct il_host_cmd cmd = {
  690. .id = REPLY_SCAN_CMD,
  691. .len = sizeof(struct il_scan_cmd),
  692. .flags = CMD_SIZE_HUGE,
  693. };
  694. struct il_scan_cmd *scan;
  695. struct il_rxon_context *ctx = &il->ctx;
  696. u32 rate_flags = 0;
  697. u16 cmd_len;
  698. u16 rx_chain = 0;
  699. enum ieee80211_band band;
  700. u8 n_probes = 0;
  701. u8 rx_ant = il->hw_params.valid_rx_ant;
  702. u8 rate;
  703. bool is_active = false;
  704. int chan_mod;
  705. u8 active_chains;
  706. u8 scan_tx_antennas = il->hw_params.valid_tx_ant;
  707. int ret;
  708. lockdep_assert_held(&il->mutex);
  709. if (vif)
  710. ctx = il_rxon_ctx_from_vif(vif);
  711. if (!il->scan_cmd) {
  712. il->scan_cmd = kmalloc(sizeof(struct il_scan_cmd) +
  713. IL_MAX_SCAN_SIZE, GFP_KERNEL);
  714. if (!il->scan_cmd) {
  715. D_SCAN(
  716. "fail to allocate memory for scan\n");
  717. return -ENOMEM;
  718. }
  719. }
  720. scan = il->scan_cmd;
  721. memset(scan, 0, sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE);
  722. scan->quiet_plcp_th = IL_PLCP_QUIET_THRESH;
  723. scan->quiet_time = IL_ACTIVE_QUIET_TIME;
  724. if (il_is_any_associated(il)) {
  725. u16 interval;
  726. u32 extra;
  727. u32 suspend_time = 100;
  728. u32 scan_suspend_time = 100;
  729. D_INFO("Scanning while associated...\n");
  730. interval = vif->bss_conf.beacon_int;
  731. scan->suspend_time = 0;
  732. scan->max_out_time = cpu_to_le32(200 * 1024);
  733. if (!interval)
  734. interval = suspend_time;
  735. extra = (suspend_time / interval) << 22;
  736. scan_suspend_time = (extra |
  737. ((suspend_time % interval) * 1024));
  738. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  739. D_SCAN("suspend_time 0x%X beacon interval %d\n",
  740. scan_suspend_time, interval);
  741. }
  742. if (il->scan_request->n_ssids) {
  743. int i, p = 0;
  744. D_SCAN("Kicking off active scan\n");
  745. for (i = 0; i < il->scan_request->n_ssids; i++) {
  746. /* always does wildcard anyway */
  747. if (!il->scan_request->ssids[i].ssid_len)
  748. continue;
  749. scan->direct_scan[p].id = WLAN_EID_SSID;
  750. scan->direct_scan[p].len =
  751. il->scan_request->ssids[i].ssid_len;
  752. memcpy(scan->direct_scan[p].ssid,
  753. il->scan_request->ssids[i].ssid,
  754. il->scan_request->ssids[i].ssid_len);
  755. n_probes++;
  756. p++;
  757. }
  758. is_active = true;
  759. } else
  760. D_SCAN("Start passive scan.\n");
  761. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  762. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  763. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  764. switch (il->scan_band) {
  765. case IEEE80211_BAND_2GHZ:
  766. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  767. chan_mod = le32_to_cpu(
  768. il->ctx.active.flags &
  769. RXON_FLG_CHANNEL_MODE_MSK)
  770. >> RXON_FLG_CHANNEL_MODE_POS;
  771. if (chan_mod == CHANNEL_MODE_PURE_40) {
  772. rate = RATE_6M_PLCP;
  773. } else {
  774. rate = RATE_1M_PLCP;
  775. rate_flags = RATE_MCS_CCK_MSK;
  776. }
  777. break;
  778. case IEEE80211_BAND_5GHZ:
  779. rate = RATE_6M_PLCP;
  780. break;
  781. default:
  782. IL_WARN("Invalid scan band\n");
  783. return -EIO;
  784. }
  785. /*
  786. * If active scanning is requested but a certain channel is
  787. * marked passive, we can do active scanning if we detect
  788. * transmissions.
  789. *
  790. * There is an issue with some firmware versions that triggers
  791. * a sysassert on a "good CRC threshold" of zero (== disabled),
  792. * on a radar channel even though this means that we should NOT
  793. * send probes.
  794. *
  795. * The "good CRC threshold" is the number of frames that we
  796. * need to receive during our dwell time on a channel before
  797. * sending out probes -- setting this to a huge value will
  798. * mean we never reach it, but at the same time work around
  799. * the aforementioned issue. Thus use IL_GOOD_CRC_TH_NEVER
  800. * here instead of IL_GOOD_CRC_TH_DISABLED.
  801. */
  802. scan->good_CRC_th = is_active ? IL_GOOD_CRC_TH_DEFAULT :
  803. IL_GOOD_CRC_TH_NEVER;
  804. band = il->scan_band;
  805. if (il->cfg->scan_rx_antennas[band])
  806. rx_ant = il->cfg->scan_rx_antennas[band];
  807. il->scan_tx_ant[band] = il4965_toggle_tx_ant(il,
  808. il->scan_tx_ant[band],
  809. scan_tx_antennas);
  810. rate_flags |= il4965_ant_idx_to_flags(il->scan_tx_ant[band]);
  811. scan->tx_cmd.rate_n_flags = il4965_hw_set_rate_n_flags(rate, rate_flags);
  812. /* In power save mode use one chain, otherwise use all chains */
  813. if (test_bit(STATUS_POWER_PMI, &il->status)) {
  814. /* rx_ant has been set to all valid chains previously */
  815. active_chains = rx_ant &
  816. ((u8)(il->chain_noise_data.active_chains));
  817. if (!active_chains)
  818. active_chains = rx_ant;
  819. D_SCAN("chain_noise_data.active_chains: %u\n",
  820. il->chain_noise_data.active_chains);
  821. rx_ant = il4965_first_antenna(active_chains);
  822. }
  823. /* MIMO is not used here, but value is required */
  824. rx_chain |= il->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  825. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  826. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  827. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  828. scan->rx_chain = cpu_to_le16(rx_chain);
  829. cmd_len = il_fill_probe_req(il,
  830. (struct ieee80211_mgmt *)scan->data,
  831. vif->addr,
  832. il->scan_request->ie,
  833. il->scan_request->ie_len,
  834. IL_MAX_SCAN_SIZE - sizeof(*scan));
  835. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  836. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  837. RXON_FILTER_BCON_AWARE_MSK);
  838. scan->channel_count = il4965_get_channels_for_scan(il, vif, band,
  839. is_active, n_probes,
  840. (void *)&scan->data[cmd_len]);
  841. if (scan->channel_count == 0) {
  842. D_SCAN("channel count %d\n", scan->channel_count);
  843. return -EIO;
  844. }
  845. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  846. scan->channel_count * sizeof(struct il_scan_channel);
  847. cmd.data = scan;
  848. scan->len = cpu_to_le16(cmd.len);
  849. set_bit(STATUS_SCAN_HW, &il->status);
  850. ret = il_send_cmd_sync(il, &cmd);
  851. if (ret)
  852. clear_bit(STATUS_SCAN_HW, &il->status);
  853. return ret;
  854. }
  855. int il4965_manage_ibss_station(struct il_priv *il,
  856. struct ieee80211_vif *vif, bool add)
  857. {
  858. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  859. if (add)
  860. return il4965_add_bssid_station(il, vif_priv->ctx,
  861. vif->bss_conf.bssid,
  862. &vif_priv->ibss_bssid_sta_id);
  863. return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
  864. vif->bss_conf.bssid);
  865. }
  866. void il4965_free_tfds_in_queue(struct il_priv *il,
  867. int sta_id, int tid, int freed)
  868. {
  869. lockdep_assert_held(&il->sta_lock);
  870. if (il->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  871. il->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  872. else {
  873. D_TX("free more than tfds_in_queue (%u:%d)\n",
  874. il->stations[sta_id].tid[tid].tfds_in_queue,
  875. freed);
  876. il->stations[sta_id].tid[tid].tfds_in_queue = 0;
  877. }
  878. }
  879. #define IL_TX_QUEUE_MSK 0xfffff
  880. static bool il4965_is_single_rx_stream(struct il_priv *il)
  881. {
  882. return il->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  883. il->current_ht_config.single_chain_sufficient;
  884. }
  885. #define IL_NUM_RX_CHAINS_MULTIPLE 3
  886. #define IL_NUM_RX_CHAINS_SINGLE 2
  887. #define IL_NUM_IDLE_CHAINS_DUAL 2
  888. #define IL_NUM_IDLE_CHAINS_SINGLE 1
  889. /*
  890. * Determine how many receiver/antenna chains to use.
  891. *
  892. * More provides better reception via diversity. Fewer saves power
  893. * at the expense of throughput, but only when not in powersave to
  894. * start with.
  895. *
  896. * MIMO (dual stream) requires at least 2, but works better with 3.
  897. * This does not determine *which* chains to use, just how many.
  898. */
  899. static int il4965_get_active_rx_chain_count(struct il_priv *il)
  900. {
  901. /* # of Rx chains to use when expecting MIMO. */
  902. if (il4965_is_single_rx_stream(il))
  903. return IL_NUM_RX_CHAINS_SINGLE;
  904. else
  905. return IL_NUM_RX_CHAINS_MULTIPLE;
  906. }
  907. /*
  908. * When we are in power saving mode, unless device support spatial
  909. * multiplexing power save, use the active count for rx chain count.
  910. */
  911. static int
  912. il4965_get_idle_rx_chain_count(struct il_priv *il, int active_cnt)
  913. {
  914. /* # Rx chains when idling, depending on SMPS mode */
  915. switch (il->current_ht_config.smps) {
  916. case IEEE80211_SMPS_STATIC:
  917. case IEEE80211_SMPS_DYNAMIC:
  918. return IL_NUM_IDLE_CHAINS_SINGLE;
  919. case IEEE80211_SMPS_OFF:
  920. return active_cnt;
  921. default:
  922. WARN(1, "invalid SMPS mode %d",
  923. il->current_ht_config.smps);
  924. return active_cnt;
  925. }
  926. }
  927. /* up to 4 chains */
  928. static u8 il4965_count_chain_bitmap(u32 chain_bitmap)
  929. {
  930. u8 res;
  931. res = (chain_bitmap & BIT(0)) >> 0;
  932. res += (chain_bitmap & BIT(1)) >> 1;
  933. res += (chain_bitmap & BIT(2)) >> 2;
  934. res += (chain_bitmap & BIT(3)) >> 3;
  935. return res;
  936. }
  937. /**
  938. * il4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  939. *
  940. * Selects how many and which Rx receivers/antennas/chains to use.
  941. * This should not be used for scan command ... it puts data in wrong place.
  942. */
  943. void il4965_set_rxon_chain(struct il_priv *il, struct il_rxon_context *ctx)
  944. {
  945. bool is_single = il4965_is_single_rx_stream(il);
  946. bool is_cam = !test_bit(STATUS_POWER_PMI, &il->status);
  947. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  948. u32 active_chains;
  949. u16 rx_chain;
  950. /* Tell uCode which antennas are actually connected.
  951. * Before first association, we assume all antennas are connected.
  952. * Just after first association, il4965_chain_noise_calibration()
  953. * checks which antennas actually *are* connected. */
  954. if (il->chain_noise_data.active_chains)
  955. active_chains = il->chain_noise_data.active_chains;
  956. else
  957. active_chains = il->hw_params.valid_rx_ant;
  958. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  959. /* How many receivers should we use? */
  960. active_rx_cnt = il4965_get_active_rx_chain_count(il);
  961. idle_rx_cnt = il4965_get_idle_rx_chain_count(il, active_rx_cnt);
  962. /* correct rx chain count according hw settings
  963. * and chain noise calibration
  964. */
  965. valid_rx_cnt = il4965_count_chain_bitmap(active_chains);
  966. if (valid_rx_cnt < active_rx_cnt)
  967. active_rx_cnt = valid_rx_cnt;
  968. if (valid_rx_cnt < idle_rx_cnt)
  969. idle_rx_cnt = valid_rx_cnt;
  970. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  971. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  972. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  973. if (!is_single && active_rx_cnt >= IL_NUM_RX_CHAINS_SINGLE && is_cam)
  974. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  975. else
  976. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  977. D_ASSOC("rx_chain=0x%X active=%d idle=%d\n",
  978. ctx->staging.rx_chain,
  979. active_rx_cnt, idle_rx_cnt);
  980. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  981. active_rx_cnt < idle_rx_cnt);
  982. }
  983. u8 il4965_toggle_tx_ant(struct il_priv *il, u8 ant, u8 valid)
  984. {
  985. int i;
  986. u8 ind = ant;
  987. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  988. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  989. if (valid & BIT(ind))
  990. return ind;
  991. }
  992. return ant;
  993. }
  994. static const char *il4965_get_fh_string(int cmd)
  995. {
  996. switch (cmd) {
  997. IL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
  998. IL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
  999. IL_CMD(FH_RSCSR_CHNL0_WPTR);
  1000. IL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
  1001. IL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
  1002. IL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
  1003. IL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1004. IL_CMD(FH_TSSR_TX_STATUS_REG);
  1005. IL_CMD(FH_TSSR_TX_ERROR_REG);
  1006. default:
  1007. return "UNKNOWN";
  1008. }
  1009. }
  1010. int il4965_dump_fh(struct il_priv *il, char **buf, bool display)
  1011. {
  1012. int i;
  1013. #ifdef CONFIG_IWLEGACY_DEBUG
  1014. int pos = 0;
  1015. size_t bufsz = 0;
  1016. #endif
  1017. static const u32 fh_tbl[] = {
  1018. FH_RSCSR_CHNL0_STTS_WPTR_REG,
  1019. FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  1020. FH_RSCSR_CHNL0_WPTR,
  1021. FH_MEM_RCSR_CHNL0_CONFIG_REG,
  1022. FH_MEM_RSSR_SHARED_CTRL_REG,
  1023. FH_MEM_RSSR_RX_STATUS_REG,
  1024. FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1025. FH_TSSR_TX_STATUS_REG,
  1026. FH_TSSR_TX_ERROR_REG
  1027. };
  1028. #ifdef CONFIG_IWLEGACY_DEBUG
  1029. if (display) {
  1030. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1031. *buf = kmalloc(bufsz, GFP_KERNEL);
  1032. if (!*buf)
  1033. return -ENOMEM;
  1034. pos += scnprintf(*buf + pos, bufsz - pos,
  1035. "FH register values:\n");
  1036. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1037. pos += scnprintf(*buf + pos, bufsz - pos,
  1038. " %34s: 0X%08x\n",
  1039. il4965_get_fh_string(fh_tbl[i]),
  1040. il_rd(il, fh_tbl[i]));
  1041. }
  1042. return pos;
  1043. }
  1044. #endif
  1045. IL_ERR("FH register values:\n");
  1046. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1047. IL_ERR(" %34s: 0X%08x\n",
  1048. il4965_get_fh_string(fh_tbl[i]),
  1049. il_rd(il, fh_tbl[i]));
  1050. }
  1051. return 0;
  1052. }
  1053. void il4965_rx_missed_beacon_notif(struct il_priv *il,
  1054. struct il_rx_buf *rxb)
  1055. {
  1056. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1057. struct il_missed_beacon_notif *missed_beacon;
  1058. missed_beacon = &pkt->u.missed_beacon;
  1059. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  1060. il->missed_beacon_threshold) {
  1061. D_CALIB(
  1062. "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  1063. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  1064. le32_to_cpu(missed_beacon->total_missed_becons),
  1065. le32_to_cpu(missed_beacon->num_recvd_beacons),
  1066. le32_to_cpu(missed_beacon->num_expected_beacons));
  1067. if (!test_bit(STATUS_SCANNING, &il->status))
  1068. il4965_init_sensitivity(il);
  1069. }
  1070. }
  1071. /* Calculate noise level, based on measurements during network silence just
  1072. * before arriving beacon. This measurement can be done only if we know
  1073. * exactly when to expect beacons, therefore only when we're associated. */
  1074. static void il4965_rx_calc_noise(struct il_priv *il)
  1075. {
  1076. struct stats_rx_non_phy *rx_info;
  1077. int num_active_rx = 0;
  1078. int total_silence = 0;
  1079. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  1080. int last_rx_noise;
  1081. rx_info = &(il->_4965.stats.rx.general);
  1082. bcn_silence_a =
  1083. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  1084. bcn_silence_b =
  1085. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  1086. bcn_silence_c =
  1087. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  1088. if (bcn_silence_a) {
  1089. total_silence += bcn_silence_a;
  1090. num_active_rx++;
  1091. }
  1092. if (bcn_silence_b) {
  1093. total_silence += bcn_silence_b;
  1094. num_active_rx++;
  1095. }
  1096. if (bcn_silence_c) {
  1097. total_silence += bcn_silence_c;
  1098. num_active_rx++;
  1099. }
  1100. /* Average among active antennas */
  1101. if (num_active_rx)
  1102. last_rx_noise = (total_silence / num_active_rx) - 107;
  1103. else
  1104. last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE;
  1105. D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
  1106. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  1107. last_rx_noise);
  1108. }
  1109. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1110. /*
  1111. * based on the assumption of all stats counter are in DWORD
  1112. * FIXME: This function is for debugging, do not deal with
  1113. * the case of counters roll-over.
  1114. */
  1115. static void il4965_accumulative_stats(struct il_priv *il,
  1116. __le32 *stats)
  1117. {
  1118. int i, size;
  1119. __le32 *prev_stats;
  1120. u32 *accum_stats;
  1121. u32 *delta, *max_delta;
  1122. struct stats_general_common *general, *accum_general;
  1123. struct stats_tx *tx, *accum_tx;
  1124. prev_stats = (__le32 *)&il->_4965.stats;
  1125. accum_stats = (u32 *)&il->_4965.accum_stats;
  1126. size = sizeof(struct il_notif_stats);
  1127. general = &il->_4965.stats.general.common;
  1128. accum_general = &il->_4965.accum_stats.general.common;
  1129. tx = &il->_4965.stats.tx;
  1130. accum_tx = &il->_4965.accum_stats.tx;
  1131. delta = (u32 *)&il->_4965.delta_stats;
  1132. max_delta = (u32 *)&il->_4965.max_delta;
  1133. for (i = sizeof(__le32); i < size;
  1134. i += sizeof(__le32), stats++, prev_stats++, delta++,
  1135. max_delta++, accum_stats++) {
  1136. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  1137. *delta = (le32_to_cpu(*stats) -
  1138. le32_to_cpu(*prev_stats));
  1139. *accum_stats += *delta;
  1140. if (*delta > *max_delta)
  1141. *max_delta = *delta;
  1142. }
  1143. }
  1144. /* reset accumulative stats for "no-counter" type stats */
  1145. accum_general->temperature = general->temperature;
  1146. accum_general->ttl_timestamp = general->ttl_timestamp;
  1147. }
  1148. #endif
  1149. #define REG_RECALIB_PERIOD (60)
  1150. void il4965_rx_stats(struct il_priv *il,
  1151. struct il_rx_buf *rxb)
  1152. {
  1153. int change;
  1154. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1155. D_RX(
  1156. "Statistics notification received (%d vs %d).\n",
  1157. (int)sizeof(struct il_notif_stats),
  1158. le32_to_cpu(pkt->len_n_flags) &
  1159. FH_RSCSR_FRAME_SIZE_MSK);
  1160. change = ((il->_4965.stats.general.common.temperature !=
  1161. pkt->u.stats.general.common.temperature) ||
  1162. ((il->_4965.stats.flag &
  1163. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  1164. (pkt->u.stats.flag &
  1165. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  1166. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1167. il4965_accumulative_stats(il, (__le32 *)&pkt->u.stats);
  1168. #endif
  1169. /* TODO: reading some of stats is unneeded */
  1170. memcpy(&il->_4965.stats, &pkt->u.stats,
  1171. sizeof(il->_4965.stats));
  1172. set_bit(STATUS_STATISTICS, &il->status);
  1173. /* Reschedule the stats timer to occur in
  1174. * REG_RECALIB_PERIOD seconds to ensure we get a
  1175. * thermal update even if the uCode doesn't give
  1176. * us one */
  1177. mod_timer(&il->stats_periodic, jiffies +
  1178. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  1179. if (unlikely(!test_bit(STATUS_SCANNING, &il->status)) &&
  1180. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  1181. il4965_rx_calc_noise(il);
  1182. queue_work(il->workqueue, &il->run_time_calib_work);
  1183. }
  1184. if (il->cfg->ops->lib->temp_ops.temperature && change)
  1185. il->cfg->ops->lib->temp_ops.temperature(il);
  1186. }
  1187. void il4965_reply_stats(struct il_priv *il,
  1188. struct il_rx_buf *rxb)
  1189. {
  1190. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1191. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  1192. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1193. memset(&il->_4965.accum_stats, 0,
  1194. sizeof(struct il_notif_stats));
  1195. memset(&il->_4965.delta_stats, 0,
  1196. sizeof(struct il_notif_stats));
  1197. memset(&il->_4965.max_delta, 0,
  1198. sizeof(struct il_notif_stats));
  1199. #endif
  1200. D_RX("Statistics have been cleared\n");
  1201. }
  1202. il4965_rx_stats(il, rxb);
  1203. }
  1204. /*
  1205. * mac80211 queues, ACs, hardware queues, FIFOs.
  1206. *
  1207. * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
  1208. *
  1209. * Mac80211 uses the following numbers, which we get as from it
  1210. * by way of skb_get_queue_mapping(skb):
  1211. *
  1212. * VO 0
  1213. * VI 1
  1214. * BE 2
  1215. * BK 3
  1216. *
  1217. *
  1218. * Regular (not A-MPDU) frames are put into hardware queues corresponding
  1219. * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their
  1220. * own queue per aggregation session (RA/TID combination), such queues are
  1221. * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In
  1222. * order to map frames to the right queue, we also need an AC->hw queue
  1223. * mapping. This is implemented here.
  1224. *
  1225. * Due to the way hw queues are set up (by the hw specific modules like
  1226. * iwl-4965.c), the AC->hw queue mapping is the identity
  1227. * mapping.
  1228. */
  1229. static const u8 tid_to_ac[] = {
  1230. IEEE80211_AC_BE,
  1231. IEEE80211_AC_BK,
  1232. IEEE80211_AC_BK,
  1233. IEEE80211_AC_BE,
  1234. IEEE80211_AC_VI,
  1235. IEEE80211_AC_VI,
  1236. IEEE80211_AC_VO,
  1237. IEEE80211_AC_VO
  1238. };
  1239. static inline int il4965_get_ac_from_tid(u16 tid)
  1240. {
  1241. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1242. return tid_to_ac[tid];
  1243. /* no support for TIDs 8-15 yet */
  1244. return -EINVAL;
  1245. }
  1246. static inline int
  1247. il4965_get_fifo_from_tid(struct il_rxon_context *ctx, u16 tid)
  1248. {
  1249. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1250. return ctx->ac_to_fifo[tid_to_ac[tid]];
  1251. /* no support for TIDs 8-15 yet */
  1252. return -EINVAL;
  1253. }
  1254. /*
  1255. * handle build REPLY_TX command notification.
  1256. */
  1257. static void il4965_tx_cmd_build_basic(struct il_priv *il,
  1258. struct sk_buff *skb,
  1259. struct il_tx_cmd *tx_cmd,
  1260. struct ieee80211_tx_info *info,
  1261. struct ieee80211_hdr *hdr,
  1262. u8 std_id)
  1263. {
  1264. __le16 fc = hdr->frame_control;
  1265. __le32 tx_flags = tx_cmd->tx_flags;
  1266. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1267. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  1268. tx_flags |= TX_CMD_FLG_ACK_MSK;
  1269. if (ieee80211_is_mgmt(fc))
  1270. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1271. if (ieee80211_is_probe_resp(fc) &&
  1272. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  1273. tx_flags |= TX_CMD_FLG_TSF_MSK;
  1274. } else {
  1275. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  1276. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1277. }
  1278. if (ieee80211_is_back_req(fc))
  1279. tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
  1280. tx_cmd->sta_id = std_id;
  1281. if (ieee80211_has_morefrags(fc))
  1282. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  1283. if (ieee80211_is_data_qos(fc)) {
  1284. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1285. tx_cmd->tid_tspec = qc[0] & 0xf;
  1286. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  1287. } else {
  1288. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1289. }
  1290. il_tx_cmd_protection(il, info, fc, &tx_flags);
  1291. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  1292. if (ieee80211_is_mgmt(fc)) {
  1293. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  1294. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  1295. else
  1296. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  1297. } else {
  1298. tx_cmd->timeout.pm_frame_timeout = 0;
  1299. }
  1300. tx_cmd->driver_txop = 0;
  1301. tx_cmd->tx_flags = tx_flags;
  1302. tx_cmd->next_frame_len = 0;
  1303. }
  1304. #define RTS_DFAULT_RETRY_LIMIT 60
  1305. static void il4965_tx_cmd_build_rate(struct il_priv *il,
  1306. struct il_tx_cmd *tx_cmd,
  1307. struct ieee80211_tx_info *info,
  1308. __le16 fc)
  1309. {
  1310. u32 rate_flags;
  1311. int rate_idx;
  1312. u8 rts_retry_limit;
  1313. u8 data_retry_limit;
  1314. u8 rate_plcp;
  1315. /* Set retry limit on DATA packets and Probe Responses*/
  1316. if (ieee80211_is_probe_resp(fc))
  1317. data_retry_limit = 3;
  1318. else
  1319. data_retry_limit = IL4965_DEFAULT_TX_RETRY;
  1320. tx_cmd->data_retry_limit = data_retry_limit;
  1321. /* Set retry limit on RTS packets */
  1322. rts_retry_limit = RTS_DFAULT_RETRY_LIMIT;
  1323. if (data_retry_limit < rts_retry_limit)
  1324. rts_retry_limit = data_retry_limit;
  1325. tx_cmd->rts_retry_limit = rts_retry_limit;
  1326. /* DATA packets will use the uCode station table for rate/antenna
  1327. * selection */
  1328. if (ieee80211_is_data(fc)) {
  1329. tx_cmd->initial_rate_idx = 0;
  1330. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  1331. return;
  1332. }
  1333. /**
  1334. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  1335. * not really a TX rate. Thus, we use the lowest supported rate for
  1336. * this band. Also use the lowest supported rate if the stored rate
  1337. * idx is invalid.
  1338. */
  1339. rate_idx = info->control.rates[0].idx;
  1340. if ((info->control.rates[0].flags & IEEE80211_TX_RC_MCS) ||
  1341. rate_idx < 0 || rate_idx > RATE_COUNT_LEGACY)
  1342. rate_idx = rate_lowest_index(&il->bands[info->band],
  1343. info->control.sta);
  1344. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  1345. if (info->band == IEEE80211_BAND_5GHZ)
  1346. rate_idx += IL_FIRST_OFDM_RATE;
  1347. /* Get PLCP rate for tx_cmd->rate_n_flags */
  1348. rate_plcp = il_rates[rate_idx].plcp;
  1349. /* Zero out flags for this packet */
  1350. rate_flags = 0;
  1351. /* Set CCK flag as needed */
  1352. if (rate_idx >= IL_FIRST_CCK_RATE && rate_idx <= IL_LAST_CCK_RATE)
  1353. rate_flags |= RATE_MCS_CCK_MSK;
  1354. /* Set up antennas */
  1355. il->mgmt_tx_ant = il4965_toggle_tx_ant(il, il->mgmt_tx_ant,
  1356. il->hw_params.valid_tx_ant);
  1357. rate_flags |= il4965_ant_idx_to_flags(il->mgmt_tx_ant);
  1358. /* Set the rate in the TX cmd */
  1359. tx_cmd->rate_n_flags = il4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
  1360. }
  1361. static void il4965_tx_cmd_build_hwcrypto(struct il_priv *il,
  1362. struct ieee80211_tx_info *info,
  1363. struct il_tx_cmd *tx_cmd,
  1364. struct sk_buff *skb_frag,
  1365. int sta_id)
  1366. {
  1367. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  1368. switch (keyconf->cipher) {
  1369. case WLAN_CIPHER_SUITE_CCMP:
  1370. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  1371. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  1372. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1373. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  1374. D_TX("tx_cmd with AES hwcrypto\n");
  1375. break;
  1376. case WLAN_CIPHER_SUITE_TKIP:
  1377. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  1378. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  1379. D_TX("tx_cmd with tkip hwcrypto\n");
  1380. break;
  1381. case WLAN_CIPHER_SUITE_WEP104:
  1382. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  1383. /* fall through */
  1384. case WLAN_CIPHER_SUITE_WEP40:
  1385. tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP |
  1386. (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT);
  1387. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  1388. D_TX("Configuring packet for WEP encryption "
  1389. "with key %d\n", keyconf->keyidx);
  1390. break;
  1391. default:
  1392. IL_ERR("Unknown encode cipher %x\n", keyconf->cipher);
  1393. break;
  1394. }
  1395. }
  1396. /*
  1397. * start REPLY_TX command process
  1398. */
  1399. int il4965_tx_skb(struct il_priv *il, struct sk_buff *skb)
  1400. {
  1401. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1402. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1403. struct ieee80211_sta *sta = info->control.sta;
  1404. struct il_station_priv *sta_priv = NULL;
  1405. struct il_tx_queue *txq;
  1406. struct il_queue *q;
  1407. struct il_device_cmd *out_cmd;
  1408. struct il_cmd_meta *out_meta;
  1409. struct il_tx_cmd *tx_cmd;
  1410. struct il_rxon_context *ctx = &il->ctx;
  1411. int txq_id;
  1412. dma_addr_t phys_addr;
  1413. dma_addr_t txcmd_phys;
  1414. dma_addr_t scratch_phys;
  1415. u16 len, firstlen, secondlen;
  1416. u16 seq_number = 0;
  1417. __le16 fc;
  1418. u8 hdr_len;
  1419. u8 sta_id;
  1420. u8 wait_write_ptr = 0;
  1421. u8 tid = 0;
  1422. u8 *qc = NULL;
  1423. unsigned long flags;
  1424. bool is_agg = false;
  1425. if (info->control.vif)
  1426. ctx = il_rxon_ctx_from_vif(info->control.vif);
  1427. spin_lock_irqsave(&il->lock, flags);
  1428. if (il_is_rfkill(il)) {
  1429. D_DROP("Dropping - RF KILL\n");
  1430. goto drop_unlock;
  1431. }
  1432. fc = hdr->frame_control;
  1433. #ifdef CONFIG_IWLEGACY_DEBUG
  1434. if (ieee80211_is_auth(fc))
  1435. D_TX("Sending AUTH frame\n");
  1436. else if (ieee80211_is_assoc_req(fc))
  1437. D_TX("Sending ASSOC frame\n");
  1438. else if (ieee80211_is_reassoc_req(fc))
  1439. D_TX("Sending REASSOC frame\n");
  1440. #endif
  1441. hdr_len = ieee80211_hdrlen(fc);
  1442. /* For management frames use broadcast id to do not break aggregation */
  1443. if (!ieee80211_is_data(fc))
  1444. sta_id = ctx->bcast_sta_id;
  1445. else {
  1446. /* Find idx into station table for destination station */
  1447. sta_id = il_sta_id_or_broadcast(il, ctx, info->control.sta);
  1448. if (sta_id == IL_INVALID_STATION) {
  1449. D_DROP("Dropping - INVALID STATION: %pM\n",
  1450. hdr->addr1);
  1451. goto drop_unlock;
  1452. }
  1453. }
  1454. D_TX("station Id %d\n", sta_id);
  1455. if (sta)
  1456. sta_priv = (void *)sta->drv_priv;
  1457. if (sta_priv && sta_priv->asleep &&
  1458. (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) {
  1459. /*
  1460. * This sends an asynchronous command to the device,
  1461. * but we can rely on it being processed before the
  1462. * next frame is processed -- and the next frame to
  1463. * this station is the one that will consume this
  1464. * counter.
  1465. * For now set the counter to just 1 since we do not
  1466. * support uAPSD yet.
  1467. */
  1468. il4965_sta_modify_sleep_tx_count(il, sta_id, 1);
  1469. }
  1470. /*
  1471. * Send this frame after DTIM -- there's a special queue
  1472. * reserved for this for contexts that support AP mode.
  1473. */
  1474. if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
  1475. txq_id = ctx->mcast_queue;
  1476. /*
  1477. * The microcode will clear the more data
  1478. * bit in the last frame it transmits.
  1479. */
  1480. hdr->frame_control |=
  1481. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1482. } else
  1483. txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)];
  1484. /* irqs already disabled/saved above when locking il->lock */
  1485. spin_lock(&il->sta_lock);
  1486. if (ieee80211_is_data_qos(fc)) {
  1487. qc = ieee80211_get_qos_ctl(hdr);
  1488. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  1489. if (WARN_ON_ONCE(tid >= MAX_TID_COUNT)) {
  1490. spin_unlock(&il->sta_lock);
  1491. goto drop_unlock;
  1492. }
  1493. seq_number = il->stations[sta_id].tid[tid].seq_number;
  1494. seq_number &= IEEE80211_SCTL_SEQ;
  1495. hdr->seq_ctrl = hdr->seq_ctrl &
  1496. cpu_to_le16(IEEE80211_SCTL_FRAG);
  1497. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  1498. seq_number += 0x10;
  1499. /* aggregation is on for this <sta,tid> */
  1500. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  1501. il->stations[sta_id].tid[tid].agg.state == IL_AGG_ON) {
  1502. txq_id = il->stations[sta_id].tid[tid].agg.txq_id;
  1503. is_agg = true;
  1504. }
  1505. }
  1506. txq = &il->txq[txq_id];
  1507. q = &txq->q;
  1508. if (unlikely(il_queue_space(q) < q->high_mark)) {
  1509. spin_unlock(&il->sta_lock);
  1510. goto drop_unlock;
  1511. }
  1512. if (ieee80211_is_data_qos(fc)) {
  1513. il->stations[sta_id].tid[tid].tfds_in_queue++;
  1514. if (!ieee80211_has_morefrags(fc))
  1515. il->stations[sta_id].tid[tid].seq_number = seq_number;
  1516. }
  1517. spin_unlock(&il->sta_lock);
  1518. /* Set up driver data for this TFD */
  1519. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct il_tx_info));
  1520. txq->txb[q->write_ptr].skb = skb;
  1521. txq->txb[q->write_ptr].ctx = ctx;
  1522. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  1523. out_cmd = txq->cmd[q->write_ptr];
  1524. out_meta = &txq->meta[q->write_ptr];
  1525. tx_cmd = &out_cmd->cmd.tx;
  1526. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  1527. memset(tx_cmd, 0, sizeof(struct il_tx_cmd));
  1528. /*
  1529. * Set up the Tx-command (not MAC!) header.
  1530. * Store the chosen Tx queue and TFD idx within the sequence field;
  1531. * after Tx, uCode's Tx response will return this value so driver can
  1532. * locate the frame within the tx queue and do post-tx processing.
  1533. */
  1534. out_cmd->hdr.cmd = REPLY_TX;
  1535. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  1536. IDX_TO_SEQ(q->write_ptr)));
  1537. /* Copy MAC header from skb into command buffer */
  1538. memcpy(tx_cmd->hdr, hdr, hdr_len);
  1539. /* Total # bytes to be transmitted */
  1540. len = (u16)skb->len;
  1541. tx_cmd->len = cpu_to_le16(len);
  1542. if (info->control.hw_key)
  1543. il4965_tx_cmd_build_hwcrypto(il, info, tx_cmd, skb, sta_id);
  1544. /* TODO need this for burst mode later on */
  1545. il4965_tx_cmd_build_basic(il, skb, tx_cmd, info, hdr, sta_id);
  1546. il_dbg_log_tx_data_frame(il, len, hdr);
  1547. il4965_tx_cmd_build_rate(il, tx_cmd, info, fc);
  1548. il_update_stats(il, true, fc, len);
  1549. /*
  1550. * Use the first empty entry in this queue's command buffer array
  1551. * to contain the Tx command and MAC header concatenated together
  1552. * (payload data will be in another buffer).
  1553. * Size of this varies, due to varying MAC header length.
  1554. * If end is not dword aligned, we'll have 2 extra bytes at the end
  1555. * of the MAC header (device reads on dword boundaries).
  1556. * We'll tell device about this padding later.
  1557. */
  1558. len = sizeof(struct il_tx_cmd) +
  1559. sizeof(struct il_cmd_header) + hdr_len;
  1560. firstlen = (len + 3) & ~3;
  1561. /* Tell NIC about any 2-byte padding after MAC header */
  1562. if (firstlen != len)
  1563. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  1564. /* Physical address of this Tx command's header (not MAC header!),
  1565. * within command buffer array. */
  1566. txcmd_phys = pci_map_single(il->pci_dev,
  1567. &out_cmd->hdr, firstlen,
  1568. PCI_DMA_BIDIRECTIONAL);
  1569. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  1570. dma_unmap_len_set(out_meta, len, firstlen);
  1571. /* Add buffer containing Tx command and MAC(!) header to TFD's
  1572. * first entry */
  1573. il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq,
  1574. txcmd_phys, firstlen, 1, 0);
  1575. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  1576. txq->need_update = 1;
  1577. } else {
  1578. wait_write_ptr = 1;
  1579. txq->need_update = 0;
  1580. }
  1581. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  1582. * if any (802.11 null frames have no payload). */
  1583. secondlen = skb->len - hdr_len;
  1584. if (secondlen > 0) {
  1585. phys_addr = pci_map_single(il->pci_dev, skb->data + hdr_len,
  1586. secondlen, PCI_DMA_TODEVICE);
  1587. il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq,
  1588. phys_addr, secondlen,
  1589. 0, 0);
  1590. }
  1591. scratch_phys = txcmd_phys + sizeof(struct il_cmd_header) +
  1592. offsetof(struct il_tx_cmd, scratch);
  1593. /* take back ownership of DMA buffer to enable update */
  1594. pci_dma_sync_single_for_cpu(il->pci_dev, txcmd_phys,
  1595. firstlen, PCI_DMA_BIDIRECTIONAL);
  1596. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  1597. tx_cmd->dram_msb_ptr = il_get_dma_hi_addr(scratch_phys);
  1598. D_TX("sequence nr = 0X%x\n",
  1599. le16_to_cpu(out_cmd->hdr.sequence));
  1600. D_TX("tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  1601. il_print_hex_dump(il, IL_DL_TX, (u8 *)tx_cmd, sizeof(*tx_cmd));
  1602. il_print_hex_dump(il, IL_DL_TX, (u8 *)tx_cmd->hdr, hdr_len);
  1603. /* Set up entry for this TFD in Tx byte-count array */
  1604. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1605. il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq,
  1606. le16_to_cpu(tx_cmd->len));
  1607. pci_dma_sync_single_for_device(il->pci_dev, txcmd_phys,
  1608. firstlen, PCI_DMA_BIDIRECTIONAL);
  1609. /* Tell device the write idx *just past* this latest filled TFD */
  1610. q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd);
  1611. il_txq_update_write_ptr(il, txq);
  1612. spin_unlock_irqrestore(&il->lock, flags);
  1613. /*
  1614. * At this point the frame is "transmitted" successfully
  1615. * and we will get a TX status notification eventually,
  1616. * regardless of the value of ret. "ret" only indicates
  1617. * whether or not we should update the write pointer.
  1618. */
  1619. /*
  1620. * Avoid atomic ops if it isn't an associated client.
  1621. * Also, if this is a packet for aggregation, don't
  1622. * increase the counter because the ucode will stop
  1623. * aggregation queues when their respective station
  1624. * goes to sleep.
  1625. */
  1626. if (sta_priv && sta_priv->client && !is_agg)
  1627. atomic_inc(&sta_priv->pending_frames);
  1628. if (il_queue_space(q) < q->high_mark && il->mac80211_registered) {
  1629. if (wait_write_ptr) {
  1630. spin_lock_irqsave(&il->lock, flags);
  1631. txq->need_update = 1;
  1632. il_txq_update_write_ptr(il, txq);
  1633. spin_unlock_irqrestore(&il->lock, flags);
  1634. } else {
  1635. il_stop_queue(il, txq);
  1636. }
  1637. }
  1638. return 0;
  1639. drop_unlock:
  1640. spin_unlock_irqrestore(&il->lock, flags);
  1641. return -1;
  1642. }
  1643. static inline int il4965_alloc_dma_ptr(struct il_priv *il,
  1644. struct il_dma_ptr *ptr, size_t size)
  1645. {
  1646. ptr->addr = dma_alloc_coherent(&il->pci_dev->dev, size, &ptr->dma,
  1647. GFP_KERNEL);
  1648. if (!ptr->addr)
  1649. return -ENOMEM;
  1650. ptr->size = size;
  1651. return 0;
  1652. }
  1653. static inline void il4965_free_dma_ptr(struct il_priv *il,
  1654. struct il_dma_ptr *ptr)
  1655. {
  1656. if (unlikely(!ptr->addr))
  1657. return;
  1658. dma_free_coherent(&il->pci_dev->dev, ptr->size, ptr->addr, ptr->dma);
  1659. memset(ptr, 0, sizeof(*ptr));
  1660. }
  1661. /**
  1662. * il4965_hw_txq_ctx_free - Free TXQ Context
  1663. *
  1664. * Destroy all TX DMA queues and structures
  1665. */
  1666. void il4965_hw_txq_ctx_free(struct il_priv *il)
  1667. {
  1668. int txq_id;
  1669. /* Tx queues */
  1670. if (il->txq) {
  1671. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1672. if (txq_id == il->cmd_queue)
  1673. il_cmd_queue_free(il);
  1674. else
  1675. il_tx_queue_free(il, txq_id);
  1676. }
  1677. il4965_free_dma_ptr(il, &il->kw);
  1678. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1679. /* free tx queue structure */
  1680. il_txq_mem(il);
  1681. }
  1682. /**
  1683. * il4965_txq_ctx_alloc - allocate TX queue context
  1684. * Allocate all Tx DMA structures and initialize them
  1685. *
  1686. * @param il
  1687. * @return error code
  1688. */
  1689. int il4965_txq_ctx_alloc(struct il_priv *il)
  1690. {
  1691. int ret;
  1692. int txq_id, slots_num;
  1693. unsigned long flags;
  1694. /* Free all tx/cmd queues and keep-warm buffer */
  1695. il4965_hw_txq_ctx_free(il);
  1696. ret = il4965_alloc_dma_ptr(il, &il->scd_bc_tbls,
  1697. il->hw_params.scd_bc_tbls_size);
  1698. if (ret) {
  1699. IL_ERR("Scheduler BC Table allocation failed\n");
  1700. goto error_bc_tbls;
  1701. }
  1702. /* Alloc keep-warm buffer */
  1703. ret = il4965_alloc_dma_ptr(il, &il->kw, IL_KW_SIZE);
  1704. if (ret) {
  1705. IL_ERR("Keep Warm allocation failed\n");
  1706. goto error_kw;
  1707. }
  1708. /* allocate tx queue structure */
  1709. ret = il_alloc_txq_mem(il);
  1710. if (ret)
  1711. goto error;
  1712. spin_lock_irqsave(&il->lock, flags);
  1713. /* Turn off all Tx DMA fifos */
  1714. il4965_txq_set_sched(il, 0);
  1715. /* Tell NIC where to find the "keep warm" buffer */
  1716. il_wr(il, FH_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1717. spin_unlock_irqrestore(&il->lock, flags);
  1718. /* Alloc and init all Tx queues, including the command queue (#4/#9) */
  1719. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1720. slots_num = (txq_id == il->cmd_queue) ?
  1721. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1722. ret = il_tx_queue_init(il,
  1723. &il->txq[txq_id], slots_num,
  1724. txq_id);
  1725. if (ret) {
  1726. IL_ERR("Tx %d queue init failed\n", txq_id);
  1727. goto error;
  1728. }
  1729. }
  1730. return ret;
  1731. error:
  1732. il4965_hw_txq_ctx_free(il);
  1733. il4965_free_dma_ptr(il, &il->kw);
  1734. error_kw:
  1735. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1736. error_bc_tbls:
  1737. return ret;
  1738. }
  1739. void il4965_txq_ctx_reset(struct il_priv *il)
  1740. {
  1741. int txq_id, slots_num;
  1742. unsigned long flags;
  1743. spin_lock_irqsave(&il->lock, flags);
  1744. /* Turn off all Tx DMA fifos */
  1745. il4965_txq_set_sched(il, 0);
  1746. /* Tell NIC where to find the "keep warm" buffer */
  1747. il_wr(il, FH_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1748. spin_unlock_irqrestore(&il->lock, flags);
  1749. /* Alloc and init all Tx queues, including the command queue (#4) */
  1750. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1751. slots_num = txq_id == il->cmd_queue ?
  1752. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1753. il_tx_queue_reset(il, &il->txq[txq_id],
  1754. slots_num, txq_id);
  1755. }
  1756. }
  1757. /**
  1758. * il4965_txq_ctx_stop - Stop all Tx DMA channels
  1759. */
  1760. void il4965_txq_ctx_stop(struct il_priv *il)
  1761. {
  1762. int ch, txq_id;
  1763. unsigned long flags;
  1764. /* Turn off all Tx DMA fifos */
  1765. spin_lock_irqsave(&il->lock, flags);
  1766. il4965_txq_set_sched(il, 0);
  1767. /* Stop each Tx DMA channel, and wait for it to be idle */
  1768. for (ch = 0; ch < il->hw_params.dma_chnl_num; ch++) {
  1769. il_wr(il,
  1770. FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
  1771. if (il_poll_bit(il, FH_TSSR_TX_STATUS_REG,
  1772. FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch),
  1773. 1000))
  1774. IL_ERR("Failing on timeout while stopping"
  1775. " DMA channel %d [0x%08x]", ch,
  1776. il_rd(il,
  1777. FH_TSSR_TX_STATUS_REG));
  1778. }
  1779. spin_unlock_irqrestore(&il->lock, flags);
  1780. if (!il->txq)
  1781. return;
  1782. /* Unmap DMA from host system and free skb's */
  1783. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1784. if (txq_id == il->cmd_queue)
  1785. il_cmd_queue_unmap(il);
  1786. else
  1787. il_tx_queue_unmap(il, txq_id);
  1788. }
  1789. /*
  1790. * Find first available (lowest unused) Tx Queue, mark it "active".
  1791. * Called only when finding queue for aggregation.
  1792. * Should never return anything < 7, because they should already
  1793. * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
  1794. */
  1795. static int il4965_txq_ctx_activate_free(struct il_priv *il)
  1796. {
  1797. int txq_id;
  1798. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1799. if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk))
  1800. return txq_id;
  1801. return -1;
  1802. }
  1803. /**
  1804. * il4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  1805. */
  1806. static void il4965_tx_queue_stop_scheduler(struct il_priv *il,
  1807. u16 txq_id)
  1808. {
  1809. /* Simply stop the queue, but don't change any configuration;
  1810. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  1811. il_wr_prph(il,
  1812. IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  1813. (0 << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  1814. (1 << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  1815. }
  1816. /**
  1817. * il4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  1818. */
  1819. static int il4965_tx_queue_set_q2ratid(struct il_priv *il, u16 ra_tid,
  1820. u16 txq_id)
  1821. {
  1822. u32 tbl_dw_addr;
  1823. u32 tbl_dw;
  1824. u16 scd_q2ratid;
  1825. scd_q2ratid = ra_tid & IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  1826. tbl_dw_addr = il->scd_base_addr +
  1827. IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  1828. tbl_dw = il_read_targ_mem(il, tbl_dw_addr);
  1829. if (txq_id & 0x1)
  1830. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  1831. else
  1832. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  1833. il_write_targ_mem(il, tbl_dw_addr, tbl_dw);
  1834. return 0;
  1835. }
  1836. /**
  1837. * il4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  1838. *
  1839. * NOTE: txq_id must be greater than IL49_FIRST_AMPDU_QUEUE,
  1840. * i.e. it must be one of the higher queues used for aggregation
  1841. */
  1842. static int il4965_txq_agg_enable(struct il_priv *il, int txq_id,
  1843. int tx_fifo, int sta_id, int tid, u16 ssn_idx)
  1844. {
  1845. unsigned long flags;
  1846. u16 ra_tid;
  1847. int ret;
  1848. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1849. (IL49_FIRST_AMPDU_QUEUE +
  1850. il->cfg->base_params->num_of_ampdu_queues <= txq_id)) {
  1851. IL_WARN(
  1852. "queue number out of range: %d, must be %d to %d\n",
  1853. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1854. IL49_FIRST_AMPDU_QUEUE +
  1855. il->cfg->base_params->num_of_ampdu_queues - 1);
  1856. return -EINVAL;
  1857. }
  1858. ra_tid = BUILD_RAxTID(sta_id, tid);
  1859. /* Modify device's station table to Tx this TID */
  1860. ret = il4965_sta_tx_modify_enable_tid(il, sta_id, tid);
  1861. if (ret)
  1862. return ret;
  1863. spin_lock_irqsave(&il->lock, flags);
  1864. /* Stop this Tx queue before configuring it */
  1865. il4965_tx_queue_stop_scheduler(il, txq_id);
  1866. /* Map receiver-address / traffic-ID to this queue */
  1867. il4965_tx_queue_set_q2ratid(il, ra_tid, txq_id);
  1868. /* Set this queue as a chain-building queue */
  1869. il_set_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1870. /* Place first TFD at idx corresponding to start sequence number.
  1871. * Assumes that ssn_idx is valid (!= 0xFFF) */
  1872. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1873. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1874. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1875. /* Set up Tx win size and frame limit for this queue */
  1876. il_write_targ_mem(il,
  1877. il->scd_base_addr + IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  1878. (SCD_WIN_SIZE << IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1879. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1880. il_write_targ_mem(il, il->scd_base_addr +
  1881. IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  1882. (SCD_FRAME_LIMIT << IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
  1883. & IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1884. il_set_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1885. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  1886. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 1);
  1887. spin_unlock_irqrestore(&il->lock, flags);
  1888. return 0;
  1889. }
  1890. int il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif,
  1891. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  1892. {
  1893. int sta_id;
  1894. int tx_fifo;
  1895. int txq_id;
  1896. int ret;
  1897. unsigned long flags;
  1898. struct il_tid_data *tid_data;
  1899. tx_fifo = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid);
  1900. if (unlikely(tx_fifo < 0))
  1901. return tx_fifo;
  1902. IL_WARN("%s on ra = %pM tid = %d\n",
  1903. __func__, sta->addr, tid);
  1904. sta_id = il_sta_id(sta);
  1905. if (sta_id == IL_INVALID_STATION) {
  1906. IL_ERR("Start AGG on invalid station\n");
  1907. return -ENXIO;
  1908. }
  1909. if (unlikely(tid >= MAX_TID_COUNT))
  1910. return -EINVAL;
  1911. if (il->stations[sta_id].tid[tid].agg.state != IL_AGG_OFF) {
  1912. IL_ERR("Start AGG when state is not IL_AGG_OFF !\n");
  1913. return -ENXIO;
  1914. }
  1915. txq_id = il4965_txq_ctx_activate_free(il);
  1916. if (txq_id == -1) {
  1917. IL_ERR("No free aggregation queue available\n");
  1918. return -ENXIO;
  1919. }
  1920. spin_lock_irqsave(&il->sta_lock, flags);
  1921. tid_data = &il->stations[sta_id].tid[tid];
  1922. *ssn = SEQ_TO_SN(tid_data->seq_number);
  1923. tid_data->agg.txq_id = txq_id;
  1924. il_set_swq_id(&il->txq[txq_id],
  1925. il4965_get_ac_from_tid(tid), txq_id);
  1926. spin_unlock_irqrestore(&il->sta_lock, flags);
  1927. ret = il4965_txq_agg_enable(il, txq_id, tx_fifo,
  1928. sta_id, tid, *ssn);
  1929. if (ret)
  1930. return ret;
  1931. spin_lock_irqsave(&il->sta_lock, flags);
  1932. tid_data = &il->stations[sta_id].tid[tid];
  1933. if (tid_data->tfds_in_queue == 0) {
  1934. D_HT("HW queue is empty\n");
  1935. tid_data->agg.state = IL_AGG_ON;
  1936. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1937. } else {
  1938. D_HT(
  1939. "HW queue is NOT empty: %d packets in HW queue\n",
  1940. tid_data->tfds_in_queue);
  1941. tid_data->agg.state = IL_EMPTYING_HW_QUEUE_ADDBA;
  1942. }
  1943. spin_unlock_irqrestore(&il->sta_lock, flags);
  1944. return ret;
  1945. }
  1946. /**
  1947. * txq_id must be greater than IL49_FIRST_AMPDU_QUEUE
  1948. * il->lock must be held by the caller
  1949. */
  1950. static int il4965_txq_agg_disable(struct il_priv *il, u16 txq_id,
  1951. u16 ssn_idx, u8 tx_fifo)
  1952. {
  1953. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1954. (IL49_FIRST_AMPDU_QUEUE +
  1955. il->cfg->base_params->num_of_ampdu_queues <= txq_id)) {
  1956. IL_WARN(
  1957. "queue number out of range: %d, must be %d to %d\n",
  1958. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1959. IL49_FIRST_AMPDU_QUEUE +
  1960. il->cfg->base_params->num_of_ampdu_queues - 1);
  1961. return -EINVAL;
  1962. }
  1963. il4965_tx_queue_stop_scheduler(il, txq_id);
  1964. il_clear_bits_prph(il,
  1965. IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1966. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1967. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1968. /* supposes that ssn_idx is valid (!= 0xFFF) */
  1969. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1970. il_clear_bits_prph(il,
  1971. IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1972. il_txq_ctx_deactivate(il, txq_id);
  1973. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 0);
  1974. return 0;
  1975. }
  1976. int il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif,
  1977. struct ieee80211_sta *sta, u16 tid)
  1978. {
  1979. int tx_fifo_id, txq_id, sta_id, ssn;
  1980. struct il_tid_data *tid_data;
  1981. int write_ptr, read_ptr;
  1982. unsigned long flags;
  1983. tx_fifo_id = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid);
  1984. if (unlikely(tx_fifo_id < 0))
  1985. return tx_fifo_id;
  1986. sta_id = il_sta_id(sta);
  1987. if (sta_id == IL_INVALID_STATION) {
  1988. IL_ERR("Invalid station for AGG tid %d\n", tid);
  1989. return -ENXIO;
  1990. }
  1991. spin_lock_irqsave(&il->sta_lock, flags);
  1992. tid_data = &il->stations[sta_id].tid[tid];
  1993. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  1994. txq_id = tid_data->agg.txq_id;
  1995. switch (il->stations[sta_id].tid[tid].agg.state) {
  1996. case IL_EMPTYING_HW_QUEUE_ADDBA:
  1997. /*
  1998. * This can happen if the peer stops aggregation
  1999. * again before we've had a chance to drain the
  2000. * queue we selected previously, i.e. before the
  2001. * session was really started completely.
  2002. */
  2003. D_HT("AGG stop before setup done\n");
  2004. goto turn_off;
  2005. case IL_AGG_ON:
  2006. break;
  2007. default:
  2008. IL_WARN("Stopping AGG while state not ON or starting\n");
  2009. }
  2010. write_ptr = il->txq[txq_id].q.write_ptr;
  2011. read_ptr = il->txq[txq_id].q.read_ptr;
  2012. /* The queue is not empty */
  2013. if (write_ptr != read_ptr) {
  2014. D_HT("Stopping a non empty AGG HW QUEUE\n");
  2015. il->stations[sta_id].tid[tid].agg.state =
  2016. IL_EMPTYING_HW_QUEUE_DELBA;
  2017. spin_unlock_irqrestore(&il->sta_lock, flags);
  2018. return 0;
  2019. }
  2020. D_HT("HW queue is empty\n");
  2021. turn_off:
  2022. il->stations[sta_id].tid[tid].agg.state = IL_AGG_OFF;
  2023. /* do not restore/save irqs */
  2024. spin_unlock(&il->sta_lock);
  2025. spin_lock(&il->lock);
  2026. /*
  2027. * the only reason this call can fail is queue number out of range,
  2028. * which can happen if uCode is reloaded and all the station
  2029. * information are lost. if it is outside the range, there is no need
  2030. * to deactivate the uCode queue, just return "success" to allow
  2031. * mac80211 to clean up it own data.
  2032. */
  2033. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo_id);
  2034. spin_unlock_irqrestore(&il->lock, flags);
  2035. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2036. return 0;
  2037. }
  2038. int il4965_txq_check_empty(struct il_priv *il,
  2039. int sta_id, u8 tid, int txq_id)
  2040. {
  2041. struct il_queue *q = &il->txq[txq_id].q;
  2042. u8 *addr = il->stations[sta_id].sta.sta.addr;
  2043. struct il_tid_data *tid_data = &il->stations[sta_id].tid[tid];
  2044. struct il_rxon_context *ctx;
  2045. ctx = &il->ctx;
  2046. lockdep_assert_held(&il->sta_lock);
  2047. switch (il->stations[sta_id].tid[tid].agg.state) {
  2048. case IL_EMPTYING_HW_QUEUE_DELBA:
  2049. /* We are reclaiming the last packet of the */
  2050. /* aggregated HW queue */
  2051. if (txq_id == tid_data->agg.txq_id &&
  2052. q->read_ptr == q->write_ptr) {
  2053. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  2054. int tx_fifo = il4965_get_fifo_from_tid(ctx, tid);
  2055. D_HT(
  2056. "HW queue empty: continue DELBA flow\n");
  2057. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo);
  2058. tid_data->agg.state = IL_AGG_OFF;
  2059. ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
  2060. }
  2061. break;
  2062. case IL_EMPTYING_HW_QUEUE_ADDBA:
  2063. /* We are reclaiming the last packet of the queue */
  2064. if (tid_data->tfds_in_queue == 0) {
  2065. D_HT(
  2066. "HW queue empty: continue ADDBA flow\n");
  2067. tid_data->agg.state = IL_AGG_ON;
  2068. ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
  2069. }
  2070. break;
  2071. }
  2072. return 0;
  2073. }
  2074. static void il4965_non_agg_tx_status(struct il_priv *il,
  2075. struct il_rxon_context *ctx,
  2076. const u8 *addr1)
  2077. {
  2078. struct ieee80211_sta *sta;
  2079. struct il_station_priv *sta_priv;
  2080. rcu_read_lock();
  2081. sta = ieee80211_find_sta(ctx->vif, addr1);
  2082. if (sta) {
  2083. sta_priv = (void *)sta->drv_priv;
  2084. /* avoid atomic ops if this isn't a client */
  2085. if (sta_priv->client &&
  2086. atomic_dec_return(&sta_priv->pending_frames) == 0)
  2087. ieee80211_sta_block_awake(il->hw, sta, false);
  2088. }
  2089. rcu_read_unlock();
  2090. }
  2091. static void
  2092. il4965_tx_status(struct il_priv *il, struct il_tx_info *tx_info,
  2093. bool is_agg)
  2094. {
  2095. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx_info->skb->data;
  2096. if (!is_agg)
  2097. il4965_non_agg_tx_status(il, tx_info->ctx, hdr->addr1);
  2098. ieee80211_tx_status_irqsafe(il->hw, tx_info->skb);
  2099. }
  2100. int il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx)
  2101. {
  2102. struct il_tx_queue *txq = &il->txq[txq_id];
  2103. struct il_queue *q = &txq->q;
  2104. struct il_tx_info *tx_info;
  2105. int nfreed = 0;
  2106. struct ieee80211_hdr *hdr;
  2107. if (idx >= q->n_bd || il_queue_used(q, idx) == 0) {
  2108. IL_ERR("Read idx for DMA queue txq id (%d), idx %d, "
  2109. "is out of range [0-%d] %d %d.\n", txq_id,
  2110. idx, q->n_bd, q->write_ptr, q->read_ptr);
  2111. return 0;
  2112. }
  2113. for (idx = il_queue_inc_wrap(idx, q->n_bd);
  2114. q->read_ptr != idx;
  2115. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2116. tx_info = &txq->txb[txq->q.read_ptr];
  2117. if (WARN_ON_ONCE(tx_info->skb == NULL))
  2118. continue;
  2119. hdr = (struct ieee80211_hdr *)tx_info->skb->data;
  2120. if (ieee80211_is_data_qos(hdr->frame_control))
  2121. nfreed++;
  2122. il4965_tx_status(il, tx_info,
  2123. txq_id >= IL4965_FIRST_AMPDU_QUEUE);
  2124. tx_info->skb = NULL;
  2125. il->cfg->ops->lib->txq_free_tfd(il, txq);
  2126. }
  2127. return nfreed;
  2128. }
  2129. /**
  2130. * il4965_tx_status_reply_compressed_ba - Update tx status from block-ack
  2131. *
  2132. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  2133. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  2134. */
  2135. static int il4965_tx_status_reply_compressed_ba(struct il_priv *il,
  2136. struct il_ht_agg *agg,
  2137. struct il_compressed_ba_resp *ba_resp)
  2138. {
  2139. int i, sh, ack;
  2140. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  2141. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2142. int successes = 0;
  2143. struct ieee80211_tx_info *info;
  2144. u64 bitmap, sent_bitmap;
  2145. if (unlikely(!agg->wait_for_ba)) {
  2146. if (unlikely(ba_resp->bitmap))
  2147. IL_ERR("Received BA when not expected\n");
  2148. return -EINVAL;
  2149. }
  2150. /* Mark that the expected block-ack response arrived */
  2151. agg->wait_for_ba = 0;
  2152. D_TX_REPLY("BA %d %d\n", agg->start_idx,
  2153. ba_resp->seq_ctl);
  2154. /* Calculate shift to align block-ack bits with our Tx win bits */
  2155. sh = agg->start_idx - SEQ_TO_IDX(seq_ctl >> 4);
  2156. if (sh < 0) /* tbw something is wrong with indices */
  2157. sh += 0x100;
  2158. if (agg->frame_count > (64 - sh)) {
  2159. D_TX_REPLY("more frames than bitmap size");
  2160. return -1;
  2161. }
  2162. /* don't use 64-bit values for now */
  2163. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  2164. /* check for success or failure according to the
  2165. * transmitted bitmap and block-ack bitmap */
  2166. sent_bitmap = bitmap & agg->bitmap;
  2167. /* For each frame attempted in aggregation,
  2168. * update driver's record of tx frame's status. */
  2169. i = 0;
  2170. while (sent_bitmap) {
  2171. ack = sent_bitmap & 1ULL;
  2172. successes += ack;
  2173. D_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
  2174. ack ? "ACK" : "NACK", i,
  2175. (agg->start_idx + i) & 0xff,
  2176. agg->start_idx + i);
  2177. sent_bitmap >>= 1;
  2178. ++i;
  2179. }
  2180. D_TX_REPLY("Bitmap %llx\n",
  2181. (unsigned long long)bitmap);
  2182. info = IEEE80211_SKB_CB(il->txq[scd_flow].txb[agg->start_idx].skb);
  2183. memset(&info->status, 0, sizeof(info->status));
  2184. info->flags |= IEEE80211_TX_STAT_ACK;
  2185. info->flags |= IEEE80211_TX_STAT_AMPDU;
  2186. info->status.ampdu_ack_len = successes;
  2187. info->status.ampdu_len = agg->frame_count;
  2188. il4965_hwrate_to_tx_control(il, agg->rate_n_flags, info);
  2189. return 0;
  2190. }
  2191. /**
  2192. * translate ucode response to mac80211 tx status control values
  2193. */
  2194. void il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags,
  2195. struct ieee80211_tx_info *info)
  2196. {
  2197. struct ieee80211_tx_rate *r = &info->control.rates[0];
  2198. info->antenna_sel_tx =
  2199. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  2200. if (rate_n_flags & RATE_MCS_HT_MSK)
  2201. r->flags |= IEEE80211_TX_RC_MCS;
  2202. if (rate_n_flags & RATE_MCS_GF_MSK)
  2203. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2204. if (rate_n_flags & RATE_MCS_HT40_MSK)
  2205. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2206. if (rate_n_flags & RATE_MCS_DUP_MSK)
  2207. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  2208. if (rate_n_flags & RATE_MCS_SGI_MSK)
  2209. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  2210. r->idx = il4965_hwrate_to_mac80211_idx(rate_n_flags, info->band);
  2211. }
  2212. /**
  2213. * il4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  2214. *
  2215. * Handles block-acknowledge notification from device, which reports success
  2216. * of frames sent via aggregation.
  2217. */
  2218. void il4965_rx_reply_compressed_ba(struct il_priv *il,
  2219. struct il_rx_buf *rxb)
  2220. {
  2221. struct il_rx_pkt *pkt = rxb_addr(rxb);
  2222. struct il_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  2223. struct il_tx_queue *txq = NULL;
  2224. struct il_ht_agg *agg;
  2225. int idx;
  2226. int sta_id;
  2227. int tid;
  2228. unsigned long flags;
  2229. /* "flow" corresponds to Tx queue */
  2230. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2231. /* "ssn" is start of block-ack Tx win, corresponds to idx
  2232. * (in Tx queue's circular buffer) of first TFD/frame in win */
  2233. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  2234. if (scd_flow >= il->hw_params.max_txq_num) {
  2235. IL_ERR(
  2236. "BUG_ON scd_flow is bigger than number of queues\n");
  2237. return;
  2238. }
  2239. txq = &il->txq[scd_flow];
  2240. sta_id = ba_resp->sta_id;
  2241. tid = ba_resp->tid;
  2242. agg = &il->stations[sta_id].tid[tid].agg;
  2243. if (unlikely(agg->txq_id != scd_flow)) {
  2244. /*
  2245. * FIXME: this is a uCode bug which need to be addressed,
  2246. * log the information and return for now!
  2247. * since it is possible happen very often and in order
  2248. * not to fill the syslog, don't enable the logging by default
  2249. */
  2250. D_TX_REPLY(
  2251. "BA scd_flow %d does not match txq_id %d\n",
  2252. scd_flow, agg->txq_id);
  2253. return;
  2254. }
  2255. /* Find idx just before block-ack win */
  2256. idx = il_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  2257. spin_lock_irqsave(&il->sta_lock, flags);
  2258. D_TX_REPLY("REPLY_COMPRESSED_BA [%d] Received from %pM, "
  2259. "sta_id = %d\n",
  2260. agg->wait_for_ba,
  2261. (u8 *) &ba_resp->sta_addr_lo32,
  2262. ba_resp->sta_id);
  2263. D_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx,"
  2264. "scd_flow = "
  2265. "%d, scd_ssn = %d\n",
  2266. ba_resp->tid,
  2267. ba_resp->seq_ctl,
  2268. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  2269. ba_resp->scd_flow,
  2270. ba_resp->scd_ssn);
  2271. D_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx\n",
  2272. agg->start_idx,
  2273. (unsigned long long)agg->bitmap);
  2274. /* Update driver's record of ACK vs. not for each frame in win */
  2275. il4965_tx_status_reply_compressed_ba(il, agg, ba_resp);
  2276. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  2277. * block-ack win (we assume that they've been successfully
  2278. * transmitted ... if not, it's too late anyway). */
  2279. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  2280. /* calculate mac80211 ampdu sw queue to wake */
  2281. int freed = il4965_tx_queue_reclaim(il, scd_flow, idx);
  2282. il4965_free_tfds_in_queue(il, sta_id, tid, freed);
  2283. if (il_queue_space(&txq->q) > txq->q.low_mark &&
  2284. il->mac80211_registered &&
  2285. agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
  2286. il_wake_queue(il, txq);
  2287. il4965_txq_check_empty(il, sta_id, tid, scd_flow);
  2288. }
  2289. spin_unlock_irqrestore(&il->sta_lock, flags);
  2290. }
  2291. #ifdef CONFIG_IWLEGACY_DEBUG
  2292. const char *il4965_get_tx_fail_reason(u32 status)
  2293. {
  2294. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  2295. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  2296. switch (status & TX_STATUS_MSK) {
  2297. case TX_STATUS_SUCCESS:
  2298. return "SUCCESS";
  2299. TX_STATUS_POSTPONE(DELAY);
  2300. TX_STATUS_POSTPONE(FEW_BYTES);
  2301. TX_STATUS_POSTPONE(QUIET_PERIOD);
  2302. TX_STATUS_POSTPONE(CALC_TTAK);
  2303. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  2304. TX_STATUS_FAIL(SHORT_LIMIT);
  2305. TX_STATUS_FAIL(LONG_LIMIT);
  2306. TX_STATUS_FAIL(FIFO_UNDERRUN);
  2307. TX_STATUS_FAIL(DRAIN_FLOW);
  2308. TX_STATUS_FAIL(RFKILL_FLUSH);
  2309. TX_STATUS_FAIL(LIFE_EXPIRE);
  2310. TX_STATUS_FAIL(DEST_PS);
  2311. TX_STATUS_FAIL(HOST_ABORTED);
  2312. TX_STATUS_FAIL(BT_RETRY);
  2313. TX_STATUS_FAIL(STA_INVALID);
  2314. TX_STATUS_FAIL(FRAG_DROPPED);
  2315. TX_STATUS_FAIL(TID_DISABLE);
  2316. TX_STATUS_FAIL(FIFO_FLUSHED);
  2317. TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
  2318. TX_STATUS_FAIL(PASSIVE_NO_RX);
  2319. TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
  2320. }
  2321. return "UNKNOWN";
  2322. #undef TX_STATUS_FAIL
  2323. #undef TX_STATUS_POSTPONE
  2324. }
  2325. #endif /* CONFIG_IWLEGACY_DEBUG */
  2326. static struct il_link_quality_cmd *
  2327. il4965_sta_alloc_lq(struct il_priv *il, u8 sta_id)
  2328. {
  2329. int i, r;
  2330. struct il_link_quality_cmd *link_cmd;
  2331. u32 rate_flags = 0;
  2332. __le32 rate_n_flags;
  2333. link_cmd = kzalloc(sizeof(struct il_link_quality_cmd), GFP_KERNEL);
  2334. if (!link_cmd) {
  2335. IL_ERR("Unable to allocate memory for LQ cmd.\n");
  2336. return NULL;
  2337. }
  2338. /* Set up the rate scaling to start at selected rate, fall back
  2339. * all the way down to 1M in IEEE order, and then spin on 1M */
  2340. if (il->band == IEEE80211_BAND_5GHZ)
  2341. r = RATE_6M_IDX;
  2342. else
  2343. r = RATE_1M_IDX;
  2344. if (r >= IL_FIRST_CCK_RATE && r <= IL_LAST_CCK_RATE)
  2345. rate_flags |= RATE_MCS_CCK_MSK;
  2346. rate_flags |= il4965_first_antenna(il->hw_params.valid_tx_ant) <<
  2347. RATE_MCS_ANT_POS;
  2348. rate_n_flags = il4965_hw_set_rate_n_flags(il_rates[r].plcp,
  2349. rate_flags);
  2350. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  2351. link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
  2352. link_cmd->general_params.single_stream_ant_msk =
  2353. il4965_first_antenna(il->hw_params.valid_tx_ant);
  2354. link_cmd->general_params.dual_stream_ant_msk =
  2355. il->hw_params.valid_tx_ant &
  2356. ~il4965_first_antenna(il->hw_params.valid_tx_ant);
  2357. if (!link_cmd->general_params.dual_stream_ant_msk) {
  2358. link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
  2359. } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) {
  2360. link_cmd->general_params.dual_stream_ant_msk =
  2361. il->hw_params.valid_tx_ant;
  2362. }
  2363. link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2364. link_cmd->agg_params.agg_time_limit =
  2365. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2366. link_cmd->sta_id = sta_id;
  2367. return link_cmd;
  2368. }
  2369. /*
  2370. * il4965_add_bssid_station - Add the special IBSS BSSID station
  2371. *
  2372. * Function sleeps.
  2373. */
  2374. int
  2375. il4965_add_bssid_station(struct il_priv *il, struct il_rxon_context *ctx,
  2376. const u8 *addr, u8 *sta_id_r)
  2377. {
  2378. int ret;
  2379. u8 sta_id;
  2380. struct il_link_quality_cmd *link_cmd;
  2381. unsigned long flags;
  2382. if (sta_id_r)
  2383. *sta_id_r = IL_INVALID_STATION;
  2384. ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id);
  2385. if (ret) {
  2386. IL_ERR("Unable to add station %pM\n", addr);
  2387. return ret;
  2388. }
  2389. if (sta_id_r)
  2390. *sta_id_r = sta_id;
  2391. spin_lock_irqsave(&il->sta_lock, flags);
  2392. il->stations[sta_id].used |= IL_STA_LOCAL;
  2393. spin_unlock_irqrestore(&il->sta_lock, flags);
  2394. /* Set up default rate scaling table in device's station table */
  2395. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2396. if (!link_cmd) {
  2397. IL_ERR(
  2398. "Unable to initialize rate scaling for station %pM.\n",
  2399. addr);
  2400. return -ENOMEM;
  2401. }
  2402. ret = il_send_lq_cmd(il, ctx, link_cmd, CMD_SYNC, true);
  2403. if (ret)
  2404. IL_ERR("Link quality command failed (%d)\n", ret);
  2405. spin_lock_irqsave(&il->sta_lock, flags);
  2406. il->stations[sta_id].lq = link_cmd;
  2407. spin_unlock_irqrestore(&il->sta_lock, flags);
  2408. return 0;
  2409. }
  2410. static int il4965_static_wepkey_cmd(struct il_priv *il,
  2411. struct il_rxon_context *ctx,
  2412. bool send_if_empty)
  2413. {
  2414. int i, not_empty = 0;
  2415. u8 buff[sizeof(struct il_wep_cmd) +
  2416. sizeof(struct il_wep_key) * WEP_KEYS_MAX];
  2417. struct il_wep_cmd *wep_cmd = (struct il_wep_cmd *)buff;
  2418. size_t cmd_size = sizeof(struct il_wep_cmd);
  2419. struct il_host_cmd cmd = {
  2420. .id = ctx->wep_key_cmd,
  2421. .data = wep_cmd,
  2422. .flags = CMD_SYNC,
  2423. };
  2424. might_sleep();
  2425. memset(wep_cmd, 0, cmd_size +
  2426. (sizeof(struct il_wep_key) * WEP_KEYS_MAX));
  2427. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  2428. wep_cmd->key[i].key_idx = i;
  2429. if (ctx->wep_keys[i].key_size) {
  2430. wep_cmd->key[i].key_offset = i;
  2431. not_empty = 1;
  2432. } else {
  2433. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  2434. }
  2435. wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
  2436. memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
  2437. ctx->wep_keys[i].key_size);
  2438. }
  2439. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  2440. wep_cmd->num_keys = WEP_KEYS_MAX;
  2441. cmd_size += sizeof(struct il_wep_key) * WEP_KEYS_MAX;
  2442. cmd.len = cmd_size;
  2443. if (not_empty || send_if_empty)
  2444. return il_send_cmd(il, &cmd);
  2445. else
  2446. return 0;
  2447. }
  2448. int il4965_restore_default_wep_keys(struct il_priv *il,
  2449. struct il_rxon_context *ctx)
  2450. {
  2451. lockdep_assert_held(&il->mutex);
  2452. return il4965_static_wepkey_cmd(il, ctx, false);
  2453. }
  2454. int il4965_remove_default_wep_key(struct il_priv *il,
  2455. struct il_rxon_context *ctx,
  2456. struct ieee80211_key_conf *keyconf)
  2457. {
  2458. int ret;
  2459. lockdep_assert_held(&il->mutex);
  2460. D_WEP("Removing default WEP key: idx=%d\n",
  2461. keyconf->keyidx);
  2462. memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
  2463. if (il_is_rfkill(il)) {
  2464. D_WEP(
  2465. "Not sending REPLY_WEPKEY command due to RFKILL.\n");
  2466. /* but keys in device are clear anyway so return success */
  2467. return 0;
  2468. }
  2469. ret = il4965_static_wepkey_cmd(il, ctx, 1);
  2470. D_WEP("Remove default WEP key: idx=%d ret=%d\n",
  2471. keyconf->keyidx, ret);
  2472. return ret;
  2473. }
  2474. int il4965_set_default_wep_key(struct il_priv *il,
  2475. struct il_rxon_context *ctx,
  2476. struct ieee80211_key_conf *keyconf)
  2477. {
  2478. int ret;
  2479. lockdep_assert_held(&il->mutex);
  2480. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  2481. keyconf->keylen != WEP_KEY_LEN_64) {
  2482. D_WEP("Bad WEP key length %d\n", keyconf->keylen);
  2483. return -EINVAL;
  2484. }
  2485. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2486. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  2487. il->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
  2488. ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  2489. memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
  2490. keyconf->keylen);
  2491. ret = il4965_static_wepkey_cmd(il, ctx, false);
  2492. D_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
  2493. keyconf->keylen, keyconf->keyidx, ret);
  2494. return ret;
  2495. }
  2496. static int il4965_set_wep_dynamic_key_info(struct il_priv *il,
  2497. struct il_rxon_context *ctx,
  2498. struct ieee80211_key_conf *keyconf,
  2499. u8 sta_id)
  2500. {
  2501. unsigned long flags;
  2502. __le16 key_flags = 0;
  2503. struct il_addsta_cmd sta_cmd;
  2504. lockdep_assert_held(&il->mutex);
  2505. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2506. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  2507. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2508. key_flags &= ~STA_KEY_FLG_INVALID;
  2509. if (keyconf->keylen == WEP_KEY_LEN_128)
  2510. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  2511. if (sta_id == ctx->bcast_sta_id)
  2512. key_flags |= STA_KEY_MULTICAST_MSK;
  2513. spin_lock_irqsave(&il->sta_lock, flags);
  2514. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2515. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2516. il->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  2517. memcpy(il->stations[sta_id].keyinfo.key,
  2518. keyconf->key, keyconf->keylen);
  2519. memcpy(&il->stations[sta_id].sta.key.key[3],
  2520. keyconf->key, keyconf->keylen);
  2521. if ((il->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  2522. == STA_KEY_FLG_NO_ENC)
  2523. il->stations[sta_id].sta.key.key_offset =
  2524. il_get_free_ucode_key_idx(il);
  2525. /* else, we are overriding an existing key => no need to allocated room
  2526. * in uCode. */
  2527. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2528. "no space for a new key");
  2529. il->stations[sta_id].sta.key.key_flags = key_flags;
  2530. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2531. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2532. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2533. sizeof(struct il_addsta_cmd));
  2534. spin_unlock_irqrestore(&il->sta_lock, flags);
  2535. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2536. }
  2537. static int il4965_set_ccmp_dynamic_key_info(struct il_priv *il,
  2538. struct il_rxon_context *ctx,
  2539. struct ieee80211_key_conf *keyconf,
  2540. u8 sta_id)
  2541. {
  2542. unsigned long flags;
  2543. __le16 key_flags = 0;
  2544. struct il_addsta_cmd sta_cmd;
  2545. lockdep_assert_held(&il->mutex);
  2546. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  2547. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2548. key_flags &= ~STA_KEY_FLG_INVALID;
  2549. if (sta_id == ctx->bcast_sta_id)
  2550. key_flags |= STA_KEY_MULTICAST_MSK;
  2551. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2552. spin_lock_irqsave(&il->sta_lock, flags);
  2553. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2554. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2555. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key,
  2556. keyconf->keylen);
  2557. memcpy(il->stations[sta_id].sta.key.key, keyconf->key,
  2558. keyconf->keylen);
  2559. if ((il->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  2560. == STA_KEY_FLG_NO_ENC)
  2561. il->stations[sta_id].sta.key.key_offset =
  2562. il_get_free_ucode_key_idx(il);
  2563. /* else, we are overriding an existing key => no need to allocated room
  2564. * in uCode. */
  2565. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2566. "no space for a new key");
  2567. il->stations[sta_id].sta.key.key_flags = key_flags;
  2568. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2569. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2570. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2571. sizeof(struct il_addsta_cmd));
  2572. spin_unlock_irqrestore(&il->sta_lock, flags);
  2573. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2574. }
  2575. static int il4965_set_tkip_dynamic_key_info(struct il_priv *il,
  2576. struct il_rxon_context *ctx,
  2577. struct ieee80211_key_conf *keyconf,
  2578. u8 sta_id)
  2579. {
  2580. unsigned long flags;
  2581. int ret = 0;
  2582. __le16 key_flags = 0;
  2583. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  2584. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2585. key_flags &= ~STA_KEY_FLG_INVALID;
  2586. if (sta_id == ctx->bcast_sta_id)
  2587. key_flags |= STA_KEY_MULTICAST_MSK;
  2588. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2589. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2590. spin_lock_irqsave(&il->sta_lock, flags);
  2591. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2592. il->stations[sta_id].keyinfo.keylen = 16;
  2593. if ((il->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  2594. == STA_KEY_FLG_NO_ENC)
  2595. il->stations[sta_id].sta.key.key_offset =
  2596. il_get_free_ucode_key_idx(il);
  2597. /* else, we are overriding an existing key => no need to allocated room
  2598. * in uCode. */
  2599. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2600. "no space for a new key");
  2601. il->stations[sta_id].sta.key.key_flags = key_flags;
  2602. /* This copy is acutally not needed: we get the key with each TX */
  2603. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, 16);
  2604. memcpy(il->stations[sta_id].sta.key.key, keyconf->key, 16);
  2605. spin_unlock_irqrestore(&il->sta_lock, flags);
  2606. return ret;
  2607. }
  2608. void il4965_update_tkip_key(struct il_priv *il,
  2609. struct il_rxon_context *ctx,
  2610. struct ieee80211_key_conf *keyconf,
  2611. struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
  2612. {
  2613. u8 sta_id;
  2614. unsigned long flags;
  2615. int i;
  2616. if (il_scan_cancel(il)) {
  2617. /* cancel scan failed, just live w/ bad key and rely
  2618. briefly on SW decryption */
  2619. return;
  2620. }
  2621. sta_id = il_sta_id_or_broadcast(il, ctx, sta);
  2622. if (sta_id == IL_INVALID_STATION)
  2623. return;
  2624. spin_lock_irqsave(&il->sta_lock, flags);
  2625. il->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  2626. for (i = 0; i < 5; i++)
  2627. il->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  2628. cpu_to_le16(phase1key[i]);
  2629. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2630. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2631. il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC);
  2632. spin_unlock_irqrestore(&il->sta_lock, flags);
  2633. }
  2634. int il4965_remove_dynamic_key(struct il_priv *il,
  2635. struct il_rxon_context *ctx,
  2636. struct ieee80211_key_conf *keyconf,
  2637. u8 sta_id)
  2638. {
  2639. unsigned long flags;
  2640. u16 key_flags;
  2641. u8 keyidx;
  2642. struct il_addsta_cmd sta_cmd;
  2643. lockdep_assert_held(&il->mutex);
  2644. ctx->key_mapping_keys--;
  2645. spin_lock_irqsave(&il->sta_lock, flags);
  2646. key_flags = le16_to_cpu(il->stations[sta_id].sta.key.key_flags);
  2647. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  2648. D_WEP("Remove dynamic key: idx=%d sta=%d\n",
  2649. keyconf->keyidx, sta_id);
  2650. if (keyconf->keyidx != keyidx) {
  2651. /* We need to remove a key with idx different that the one
  2652. * in the uCode. This means that the key we need to remove has
  2653. * been replaced by another one with different idx.
  2654. * Don't do anything and return ok
  2655. */
  2656. spin_unlock_irqrestore(&il->sta_lock, flags);
  2657. return 0;
  2658. }
  2659. if (il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  2660. IL_WARN("Removing wrong key %d 0x%x\n",
  2661. keyconf->keyidx, key_flags);
  2662. spin_unlock_irqrestore(&il->sta_lock, flags);
  2663. return 0;
  2664. }
  2665. if (!test_and_clear_bit(il->stations[sta_id].sta.key.key_offset,
  2666. &il->ucode_key_table))
  2667. IL_ERR("idx %d not used in uCode key table.\n",
  2668. il->stations[sta_id].sta.key.key_offset);
  2669. memset(&il->stations[sta_id].keyinfo, 0,
  2670. sizeof(struct il_hw_key));
  2671. memset(&il->stations[sta_id].sta.key, 0,
  2672. sizeof(struct il4965_keyinfo));
  2673. il->stations[sta_id].sta.key.key_flags =
  2674. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  2675. il->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  2676. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2677. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2678. if (il_is_rfkill(il)) {
  2679. D_WEP(
  2680. "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
  2681. spin_unlock_irqrestore(&il->sta_lock, flags);
  2682. return 0;
  2683. }
  2684. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2685. sizeof(struct il_addsta_cmd));
  2686. spin_unlock_irqrestore(&il->sta_lock, flags);
  2687. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2688. }
  2689. int il4965_set_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx,
  2690. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2691. {
  2692. int ret;
  2693. lockdep_assert_held(&il->mutex);
  2694. ctx->key_mapping_keys++;
  2695. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  2696. switch (keyconf->cipher) {
  2697. case WLAN_CIPHER_SUITE_CCMP:
  2698. ret = il4965_set_ccmp_dynamic_key_info(il, ctx,
  2699. keyconf, sta_id);
  2700. break;
  2701. case WLAN_CIPHER_SUITE_TKIP:
  2702. ret = il4965_set_tkip_dynamic_key_info(il, ctx,
  2703. keyconf, sta_id);
  2704. break;
  2705. case WLAN_CIPHER_SUITE_WEP40:
  2706. case WLAN_CIPHER_SUITE_WEP104:
  2707. ret = il4965_set_wep_dynamic_key_info(il, ctx,
  2708. keyconf, sta_id);
  2709. break;
  2710. default:
  2711. IL_ERR(
  2712. "Unknown alg: %s cipher = %x\n", __func__,
  2713. keyconf->cipher);
  2714. ret = -EINVAL;
  2715. }
  2716. D_WEP(
  2717. "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
  2718. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  2719. sta_id, ret);
  2720. return ret;
  2721. }
  2722. /**
  2723. * il4965_alloc_bcast_station - add broadcast station into driver's station table.
  2724. *
  2725. * This adds the broadcast station into the driver's station table
  2726. * and marks it driver active, so that it will be restored to the
  2727. * device at the next best time.
  2728. */
  2729. int il4965_alloc_bcast_station(struct il_priv *il,
  2730. struct il_rxon_context *ctx)
  2731. {
  2732. struct il_link_quality_cmd *link_cmd;
  2733. unsigned long flags;
  2734. u8 sta_id;
  2735. spin_lock_irqsave(&il->sta_lock, flags);
  2736. sta_id = il_prep_station(il, ctx, il_bcast_addr,
  2737. false, NULL);
  2738. if (sta_id == IL_INVALID_STATION) {
  2739. IL_ERR("Unable to prepare broadcast station\n");
  2740. spin_unlock_irqrestore(&il->sta_lock, flags);
  2741. return -EINVAL;
  2742. }
  2743. il->stations[sta_id].used |= IL_STA_DRIVER_ACTIVE;
  2744. il->stations[sta_id].used |= IL_STA_BCAST;
  2745. spin_unlock_irqrestore(&il->sta_lock, flags);
  2746. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2747. if (!link_cmd) {
  2748. IL_ERR(
  2749. "Unable to initialize rate scaling for bcast station.\n");
  2750. return -ENOMEM;
  2751. }
  2752. spin_lock_irqsave(&il->sta_lock, flags);
  2753. il->stations[sta_id].lq = link_cmd;
  2754. spin_unlock_irqrestore(&il->sta_lock, flags);
  2755. return 0;
  2756. }
  2757. /**
  2758. * il4965_update_bcast_station - update broadcast station's LQ command
  2759. *
  2760. * Only used by iwl4965. Placed here to have all bcast station management
  2761. * code together.
  2762. */
  2763. static int il4965_update_bcast_station(struct il_priv *il,
  2764. struct il_rxon_context *ctx)
  2765. {
  2766. unsigned long flags;
  2767. struct il_link_quality_cmd *link_cmd;
  2768. u8 sta_id = ctx->bcast_sta_id;
  2769. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2770. if (!link_cmd) {
  2771. IL_ERR(
  2772. "Unable to initialize rate scaling for bcast station.\n");
  2773. return -ENOMEM;
  2774. }
  2775. spin_lock_irqsave(&il->sta_lock, flags);
  2776. if (il->stations[sta_id].lq)
  2777. kfree(il->stations[sta_id].lq);
  2778. else
  2779. D_INFO(
  2780. "Bcast station rate scaling has not been initialized yet.\n");
  2781. il->stations[sta_id].lq = link_cmd;
  2782. spin_unlock_irqrestore(&il->sta_lock, flags);
  2783. return 0;
  2784. }
  2785. int il4965_update_bcast_stations(struct il_priv *il)
  2786. {
  2787. return il4965_update_bcast_station(il, &il->ctx);
  2788. }
  2789. /**
  2790. * il4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  2791. */
  2792. int il4965_sta_tx_modify_enable_tid(struct il_priv *il, int sta_id, int tid)
  2793. {
  2794. unsigned long flags;
  2795. struct il_addsta_cmd sta_cmd;
  2796. lockdep_assert_held(&il->mutex);
  2797. /* Remove "disable" flag, to enable Tx for this TID */
  2798. spin_lock_irqsave(&il->sta_lock, flags);
  2799. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  2800. il->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  2801. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2802. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2803. sizeof(struct il_addsta_cmd));
  2804. spin_unlock_irqrestore(&il->sta_lock, flags);
  2805. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2806. }
  2807. int il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta,
  2808. int tid, u16 ssn)
  2809. {
  2810. unsigned long flags;
  2811. int sta_id;
  2812. struct il_addsta_cmd sta_cmd;
  2813. lockdep_assert_held(&il->mutex);
  2814. sta_id = il_sta_id(sta);
  2815. if (sta_id == IL_INVALID_STATION)
  2816. return -ENXIO;
  2817. spin_lock_irqsave(&il->sta_lock, flags);
  2818. il->stations[sta_id].sta.station_flags_msk = 0;
  2819. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  2820. il->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  2821. il->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  2822. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2823. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2824. sizeof(struct il_addsta_cmd));
  2825. spin_unlock_irqrestore(&il->sta_lock, flags);
  2826. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2827. }
  2828. int il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta,
  2829. int tid)
  2830. {
  2831. unsigned long flags;
  2832. int sta_id;
  2833. struct il_addsta_cmd sta_cmd;
  2834. lockdep_assert_held(&il->mutex);
  2835. sta_id = il_sta_id(sta);
  2836. if (sta_id == IL_INVALID_STATION) {
  2837. IL_ERR("Invalid station for AGG tid %d\n", tid);
  2838. return -ENXIO;
  2839. }
  2840. spin_lock_irqsave(&il->sta_lock, flags);
  2841. il->stations[sta_id].sta.station_flags_msk = 0;
  2842. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  2843. il->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  2844. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2845. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2846. sizeof(struct il_addsta_cmd));
  2847. spin_unlock_irqrestore(&il->sta_lock, flags);
  2848. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2849. }
  2850. void
  2851. il4965_sta_modify_sleep_tx_count(struct il_priv *il, int sta_id, int cnt)
  2852. {
  2853. unsigned long flags;
  2854. spin_lock_irqsave(&il->sta_lock, flags);
  2855. il->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  2856. il->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  2857. il->stations[sta_id].sta.sta.modify_mask =
  2858. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  2859. il->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  2860. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2861. il_send_add_sta(il,
  2862. &il->stations[sta_id].sta, CMD_ASYNC);
  2863. spin_unlock_irqrestore(&il->sta_lock, flags);
  2864. }
  2865. void il4965_update_chain_flags(struct il_priv *il)
  2866. {
  2867. if (il->cfg->ops->hcmd->set_rxon_chain) {
  2868. il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx);
  2869. if (il->ctx.active.rx_chain != il->ctx.staging.rx_chain)
  2870. il_commit_rxon(il, &il->ctx);
  2871. }
  2872. }
  2873. static void il4965_clear_free_frames(struct il_priv *il)
  2874. {
  2875. struct list_head *element;
  2876. D_INFO("%d frames on pre-allocated heap on clear.\n",
  2877. il->frames_count);
  2878. while (!list_empty(&il->free_frames)) {
  2879. element = il->free_frames.next;
  2880. list_del(element);
  2881. kfree(list_entry(element, struct il_frame, list));
  2882. il->frames_count--;
  2883. }
  2884. if (il->frames_count) {
  2885. IL_WARN("%d frames still in use. Did we lose one?\n",
  2886. il->frames_count);
  2887. il->frames_count = 0;
  2888. }
  2889. }
  2890. static struct il_frame *il4965_get_free_frame(struct il_priv *il)
  2891. {
  2892. struct il_frame *frame;
  2893. struct list_head *element;
  2894. if (list_empty(&il->free_frames)) {
  2895. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  2896. if (!frame) {
  2897. IL_ERR("Could not allocate frame!\n");
  2898. return NULL;
  2899. }
  2900. il->frames_count++;
  2901. return frame;
  2902. }
  2903. element = il->free_frames.next;
  2904. list_del(element);
  2905. return list_entry(element, struct il_frame, list);
  2906. }
  2907. static void il4965_free_frame(struct il_priv *il, struct il_frame *frame)
  2908. {
  2909. memset(frame, 0, sizeof(*frame));
  2910. list_add(&frame->list, &il->free_frames);
  2911. }
  2912. static u32 il4965_fill_beacon_frame(struct il_priv *il,
  2913. struct ieee80211_hdr *hdr,
  2914. int left)
  2915. {
  2916. lockdep_assert_held(&il->mutex);
  2917. if (!il->beacon_skb)
  2918. return 0;
  2919. if (il->beacon_skb->len > left)
  2920. return 0;
  2921. memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len);
  2922. return il->beacon_skb->len;
  2923. }
  2924. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  2925. static void il4965_set_beacon_tim(struct il_priv *il,
  2926. struct il_tx_beacon_cmd *tx_beacon_cmd,
  2927. u8 *beacon, u32 frame_size)
  2928. {
  2929. u16 tim_idx;
  2930. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  2931. /*
  2932. * The idx is relative to frame start but we start looking at the
  2933. * variable-length part of the beacon.
  2934. */
  2935. tim_idx = mgmt->u.beacon.variable - beacon;
  2936. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  2937. while ((tim_idx < (frame_size - 2)) &&
  2938. (beacon[tim_idx] != WLAN_EID_TIM))
  2939. tim_idx += beacon[tim_idx+1] + 2;
  2940. /* If TIM field was found, set variables */
  2941. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  2942. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  2943. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  2944. } else
  2945. IL_WARN("Unable to find TIM Element in beacon\n");
  2946. }
  2947. static unsigned int il4965_hw_get_beacon_cmd(struct il_priv *il,
  2948. struct il_frame *frame)
  2949. {
  2950. struct il_tx_beacon_cmd *tx_beacon_cmd;
  2951. u32 frame_size;
  2952. u32 rate_flags;
  2953. u32 rate;
  2954. /*
  2955. * We have to set up the TX command, the TX Beacon command, and the
  2956. * beacon contents.
  2957. */
  2958. lockdep_assert_held(&il->mutex);
  2959. if (!il->beacon_ctx) {
  2960. IL_ERR("trying to build beacon w/o beacon context!\n");
  2961. return 0;
  2962. }
  2963. /* Initialize memory */
  2964. tx_beacon_cmd = &frame->u.beacon;
  2965. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2966. /* Set up TX beacon contents */
  2967. frame_size = il4965_fill_beacon_frame(il, tx_beacon_cmd->frame,
  2968. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2969. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  2970. return 0;
  2971. if (!frame_size)
  2972. return 0;
  2973. /* Set up TX command fields */
  2974. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  2975. tx_beacon_cmd->tx.sta_id = il->beacon_ctx->bcast_sta_id;
  2976. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2977. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  2978. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  2979. /* Set up TX beacon command fields */
  2980. il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
  2981. frame_size);
  2982. /* Set up packet rate and flags */
  2983. rate = il_get_lowest_plcp(il, il->beacon_ctx);
  2984. il->mgmt_tx_ant = il4965_toggle_tx_ant(il, il->mgmt_tx_ant,
  2985. il->hw_params.valid_tx_ant);
  2986. rate_flags = il4965_ant_idx_to_flags(il->mgmt_tx_ant);
  2987. if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE))
  2988. rate_flags |= RATE_MCS_CCK_MSK;
  2989. tx_beacon_cmd->tx.rate_n_flags = il4965_hw_set_rate_n_flags(rate,
  2990. rate_flags);
  2991. return sizeof(*tx_beacon_cmd) + frame_size;
  2992. }
  2993. int il4965_send_beacon_cmd(struct il_priv *il)
  2994. {
  2995. struct il_frame *frame;
  2996. unsigned int frame_size;
  2997. int rc;
  2998. frame = il4965_get_free_frame(il);
  2999. if (!frame) {
  3000. IL_ERR("Could not obtain free frame buffer for beacon "
  3001. "command.\n");
  3002. return -ENOMEM;
  3003. }
  3004. frame_size = il4965_hw_get_beacon_cmd(il, frame);
  3005. if (!frame_size) {
  3006. IL_ERR("Error configuring the beacon command\n");
  3007. il4965_free_frame(il, frame);
  3008. return -EINVAL;
  3009. }
  3010. rc = il_send_cmd_pdu(il, REPLY_TX_BEACON, frame_size,
  3011. &frame->u.cmd[0]);
  3012. il4965_free_frame(il, frame);
  3013. return rc;
  3014. }
  3015. static inline dma_addr_t il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx)
  3016. {
  3017. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3018. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  3019. if (sizeof(dma_addr_t) > sizeof(u32))
  3020. addr |=
  3021. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  3022. return addr;
  3023. }
  3024. static inline u16 il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx)
  3025. {
  3026. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3027. return le16_to_cpu(tb->hi_n_len) >> 4;
  3028. }
  3029. static inline void il4965_tfd_set_tb(struct il_tfd *tfd, u8 idx,
  3030. dma_addr_t addr, u16 len)
  3031. {
  3032. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3033. u16 hi_n_len = len << 4;
  3034. put_unaligned_le32(addr, &tb->lo);
  3035. if (sizeof(dma_addr_t) > sizeof(u32))
  3036. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  3037. tb->hi_n_len = cpu_to_le16(hi_n_len);
  3038. tfd->num_tbs = idx + 1;
  3039. }
  3040. static inline u8 il4965_tfd_get_num_tbs(struct il_tfd *tfd)
  3041. {
  3042. return tfd->num_tbs & 0x1f;
  3043. }
  3044. /**
  3045. * il4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  3046. * @il - driver ilate data
  3047. * @txq - tx queue
  3048. *
  3049. * Does NOT advance any TFD circular buffer read/write idxes
  3050. * Does NOT free the TFD itself (which is within circular buffer)
  3051. */
  3052. void il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
  3053. {
  3054. struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds;
  3055. struct il_tfd *tfd;
  3056. struct pci_dev *dev = il->pci_dev;
  3057. int idx = txq->q.read_ptr;
  3058. int i;
  3059. int num_tbs;
  3060. tfd = &tfd_tmp[idx];
  3061. /* Sanity check on number of chunks */
  3062. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3063. if (num_tbs >= IL_NUM_OF_TBS) {
  3064. IL_ERR("Too many chunks: %i\n", num_tbs);
  3065. /* @todo issue fatal error, it is quite serious situation */
  3066. return;
  3067. }
  3068. /* Unmap tx_cmd */
  3069. if (num_tbs)
  3070. pci_unmap_single(dev,
  3071. dma_unmap_addr(&txq->meta[idx], mapping),
  3072. dma_unmap_len(&txq->meta[idx], len),
  3073. PCI_DMA_BIDIRECTIONAL);
  3074. /* Unmap chunks, if any. */
  3075. for (i = 1; i < num_tbs; i++)
  3076. pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i),
  3077. il4965_tfd_tb_get_len(tfd, i),
  3078. PCI_DMA_TODEVICE);
  3079. /* free SKB */
  3080. if (txq->txb) {
  3081. struct sk_buff *skb;
  3082. skb = txq->txb[txq->q.read_ptr].skb;
  3083. /* can be called from irqs-disabled context */
  3084. if (skb) {
  3085. dev_kfree_skb_any(skb);
  3086. txq->txb[txq->q.read_ptr].skb = NULL;
  3087. }
  3088. }
  3089. }
  3090. int il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il,
  3091. struct il_tx_queue *txq,
  3092. dma_addr_t addr, u16 len,
  3093. u8 reset, u8 pad)
  3094. {
  3095. struct il_queue *q;
  3096. struct il_tfd *tfd, *tfd_tmp;
  3097. u32 num_tbs;
  3098. q = &txq->q;
  3099. tfd_tmp = (struct il_tfd *)txq->tfds;
  3100. tfd = &tfd_tmp[q->write_ptr];
  3101. if (reset)
  3102. memset(tfd, 0, sizeof(*tfd));
  3103. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3104. /* Each TFD can point to a maximum 20 Tx buffers */
  3105. if (num_tbs >= IL_NUM_OF_TBS) {
  3106. IL_ERR("Error can not send more than %d chunks\n",
  3107. IL_NUM_OF_TBS);
  3108. return -EINVAL;
  3109. }
  3110. BUG_ON(addr & ~DMA_BIT_MASK(36));
  3111. if (unlikely(addr & ~IL_TX_DMA_MASK))
  3112. IL_ERR("Unaligned address = %llx\n",
  3113. (unsigned long long)addr);
  3114. il4965_tfd_set_tb(tfd, num_tbs, addr, len);
  3115. return 0;
  3116. }
  3117. /*
  3118. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  3119. * given Tx queue, and enable the DMA channel used for that queue.
  3120. *
  3121. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  3122. * channels supported in hardware.
  3123. */
  3124. int il4965_hw_tx_queue_init(struct il_priv *il,
  3125. struct il_tx_queue *txq)
  3126. {
  3127. int txq_id = txq->q.id;
  3128. /* Circular buffer (TFD queue in DRAM) physical base address */
  3129. il_wr(il, FH_MEM_CBBC_QUEUE(txq_id),
  3130. txq->q.dma_addr >> 8);
  3131. return 0;
  3132. }
  3133. /******************************************************************************
  3134. *
  3135. * Generic RX handler implementations
  3136. *
  3137. ******************************************************************************/
  3138. static void il4965_rx_reply_alive(struct il_priv *il,
  3139. struct il_rx_buf *rxb)
  3140. {
  3141. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3142. struct il_alive_resp *palive;
  3143. struct delayed_work *pwork;
  3144. palive = &pkt->u.alive_frame;
  3145. D_INFO("Alive ucode status 0x%08X revision "
  3146. "0x%01X 0x%01X\n",
  3147. palive->is_valid, palive->ver_type,
  3148. palive->ver_subtype);
  3149. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  3150. D_INFO("Initialization Alive received.\n");
  3151. memcpy(&il->card_alive_init,
  3152. &pkt->u.alive_frame,
  3153. sizeof(struct il_init_alive_resp));
  3154. pwork = &il->init_alive_start;
  3155. } else {
  3156. D_INFO("Runtime Alive received.\n");
  3157. memcpy(&il->card_alive, &pkt->u.alive_frame,
  3158. sizeof(struct il_alive_resp));
  3159. pwork = &il->alive_start;
  3160. }
  3161. /* We delay the ALIVE response by 5ms to
  3162. * give the HW RF Kill time to activate... */
  3163. if (palive->is_valid == UCODE_VALID_OK)
  3164. queue_delayed_work(il->workqueue, pwork,
  3165. msecs_to_jiffies(5));
  3166. else
  3167. IL_WARN("uCode did not respond OK.\n");
  3168. }
  3169. /**
  3170. * il4965_bg_stats_periodic - Timer callback to queue stats
  3171. *
  3172. * This callback is provided in order to send a stats request.
  3173. *
  3174. * This timer function is continually reset to execute within
  3175. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  3176. * was received. We need to ensure we receive the stats in order
  3177. * to update the temperature used for calibrating the TXPOWER.
  3178. */
  3179. static void il4965_bg_stats_periodic(unsigned long data)
  3180. {
  3181. struct il_priv *il = (struct il_priv *)data;
  3182. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  3183. return;
  3184. /* dont send host command if rf-kill is on */
  3185. if (!il_is_ready_rf(il))
  3186. return;
  3187. il_send_stats_request(il, CMD_ASYNC, false);
  3188. }
  3189. static void il4965_rx_beacon_notif(struct il_priv *il,
  3190. struct il_rx_buf *rxb)
  3191. {
  3192. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3193. struct il4965_beacon_notif *beacon =
  3194. (struct il4965_beacon_notif *)pkt->u.raw;
  3195. #ifdef CONFIG_IWLEGACY_DEBUG
  3196. u8 rate = il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  3197. D_RX("beacon status %x retries %d iss %d "
  3198. "tsf %d %d rate %d\n",
  3199. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  3200. beacon->beacon_notify_hdr.failure_frame,
  3201. le32_to_cpu(beacon->ibss_mgr_status),
  3202. le32_to_cpu(beacon->high_tsf),
  3203. le32_to_cpu(beacon->low_tsf), rate);
  3204. #endif
  3205. il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  3206. }
  3207. static void il4965_perform_ct_kill_task(struct il_priv *il)
  3208. {
  3209. unsigned long flags;
  3210. D_POWER("Stop all queues\n");
  3211. if (il->mac80211_registered)
  3212. ieee80211_stop_queues(il->hw);
  3213. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3214. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  3215. _il_rd(il, CSR_UCODE_DRV_GP1);
  3216. spin_lock_irqsave(&il->reg_lock, flags);
  3217. if (!_il_grab_nic_access(il))
  3218. _il_release_nic_access(il);
  3219. spin_unlock_irqrestore(&il->reg_lock, flags);
  3220. }
  3221. /* Handle notification from uCode that card's power state is changing
  3222. * due to software, hardware, or critical temperature RFKILL */
  3223. static void il4965_rx_card_state_notif(struct il_priv *il,
  3224. struct il_rx_buf *rxb)
  3225. {
  3226. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3227. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  3228. unsigned long status = il->status;
  3229. D_RF_KILL("Card state received: HW:%s SW:%s CT:%s\n",
  3230. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  3231. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  3232. (flags & CT_CARD_DISABLED) ?
  3233. "Reached" : "Not reached");
  3234. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  3235. CT_CARD_DISABLED)) {
  3236. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3237. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3238. il_wr(il, HBUS_TARG_MBX_C,
  3239. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3240. if (!(flags & RXON_CARD_DISABLED)) {
  3241. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  3242. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3243. il_wr(il, HBUS_TARG_MBX_C,
  3244. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3245. }
  3246. }
  3247. if (flags & CT_CARD_DISABLED)
  3248. il4965_perform_ct_kill_task(il);
  3249. if (flags & HW_CARD_DISABLED)
  3250. set_bit(STATUS_RF_KILL_HW, &il->status);
  3251. else
  3252. clear_bit(STATUS_RF_KILL_HW, &il->status);
  3253. if (!(flags & RXON_CARD_DISABLED))
  3254. il_scan_cancel(il);
  3255. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  3256. test_bit(STATUS_RF_KILL_HW, &il->status)))
  3257. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  3258. test_bit(STATUS_RF_KILL_HW, &il->status));
  3259. else
  3260. wake_up(&il->wait_command_queue);
  3261. }
  3262. /**
  3263. * il4965_setup_rx_handlers - Initialize Rx handler callbacks
  3264. *
  3265. * Setup the RX handlers for each of the reply types sent from the uCode
  3266. * to the host.
  3267. *
  3268. * This function chains into the hardware specific files for them to setup
  3269. * any hardware specific handlers as well.
  3270. */
  3271. static void il4965_setup_rx_handlers(struct il_priv *il)
  3272. {
  3273. il->rx_handlers[REPLY_ALIVE] = il4965_rx_reply_alive;
  3274. il->rx_handlers[REPLY_ERROR] = il_rx_reply_error;
  3275. il->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = il_rx_csa;
  3276. il->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  3277. il_rx_spectrum_measure_notif;
  3278. il->rx_handlers[PM_SLEEP_NOTIFICATION] = il_rx_pm_sleep_notif;
  3279. il->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  3280. il_rx_pm_debug_stats_notif;
  3281. il->rx_handlers[BEACON_NOTIFICATION] = il4965_rx_beacon_notif;
  3282. /*
  3283. * The same handler is used for both the REPLY to a discrete
  3284. * stats request from the host as well as for the periodic
  3285. * stats notifications (after received beacons) from the uCode.
  3286. */
  3287. il->rx_handlers[REPLY_STATISTICS_CMD] = il4965_reply_stats;
  3288. il->rx_handlers[STATISTICS_NOTIFICATION] = il4965_rx_stats;
  3289. il_setup_rx_scan_handlers(il);
  3290. /* status change handler */
  3291. il->rx_handlers[CARD_STATE_NOTIFICATION] =
  3292. il4965_rx_card_state_notif;
  3293. il->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  3294. il4965_rx_missed_beacon_notif;
  3295. /* Rx handlers */
  3296. il->rx_handlers[REPLY_RX_PHY_CMD] = il4965_rx_reply_rx_phy;
  3297. il->rx_handlers[REPLY_RX_MPDU_CMD] = il4965_rx_reply_rx;
  3298. /* block ack */
  3299. il->rx_handlers[REPLY_COMPRESSED_BA] = il4965_rx_reply_compressed_ba;
  3300. /* Set up hardware specific Rx handlers */
  3301. il->cfg->ops->lib->rx_handler_setup(il);
  3302. }
  3303. /**
  3304. * il4965_rx_handle - Main entry function for receiving responses from uCode
  3305. *
  3306. * Uses the il->rx_handlers callback function array to invoke
  3307. * the appropriate handlers, including command responses,
  3308. * frame-received notifications, and other notifications.
  3309. */
  3310. void il4965_rx_handle(struct il_priv *il)
  3311. {
  3312. struct il_rx_buf *rxb;
  3313. struct il_rx_pkt *pkt;
  3314. struct il_rx_queue *rxq = &il->rxq;
  3315. u32 r, i;
  3316. int reclaim;
  3317. unsigned long flags;
  3318. u8 fill_rx = 0;
  3319. u32 count = 8;
  3320. int total_empty;
  3321. /* uCode's read idx (stored in shared DRAM) indicates the last Rx
  3322. * buffer that the driver may process (last buffer filled by ucode). */
  3323. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  3324. i = rxq->read;
  3325. /* Rx interrupt, but nothing sent from uCode */
  3326. if (i == r)
  3327. D_RX("r = %d, i = %d\n", r, i);
  3328. /* calculate total frames need to be restock after handling RX */
  3329. total_empty = r - rxq->write_actual;
  3330. if (total_empty < 0)
  3331. total_empty += RX_QUEUE_SIZE;
  3332. if (total_empty > (RX_QUEUE_SIZE / 2))
  3333. fill_rx = 1;
  3334. while (i != r) {
  3335. int len;
  3336. rxb = rxq->queue[i];
  3337. /* If an RXB doesn't have a Rx queue slot associated with it,
  3338. * then a bug has been introduced in the queue refilling
  3339. * routines -- catch it here */
  3340. BUG_ON(rxb == NULL);
  3341. rxq->queue[i] = NULL;
  3342. pci_unmap_page(il->pci_dev, rxb->page_dma,
  3343. PAGE_SIZE << il->hw_params.rx_page_order,
  3344. PCI_DMA_FROMDEVICE);
  3345. pkt = rxb_addr(rxb);
  3346. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  3347. len += sizeof(u32); /* account for status word */
  3348. /* Reclaim a command buffer only if this packet is a response
  3349. * to a (driver-originated) command.
  3350. * If the packet (e.g. Rx frame) originated from uCode,
  3351. * there is no command buffer to reclaim.
  3352. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3353. * but apparently a few don't get set; catch them here. */
  3354. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3355. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  3356. (pkt->hdr.cmd != REPLY_RX) &&
  3357. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  3358. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  3359. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  3360. (pkt->hdr.cmd != REPLY_TX);
  3361. /* Based on type of command response or notification,
  3362. * handle those that need handling via function in
  3363. * rx_handlers table. See il4965_setup_rx_handlers() */
  3364. if (il->rx_handlers[pkt->hdr.cmd]) {
  3365. D_RX("r = %d, i = %d, %s, 0x%02x\n", r,
  3366. i, il_get_cmd_string(pkt->hdr.cmd),
  3367. pkt->hdr.cmd);
  3368. il->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  3369. il->rx_handlers[pkt->hdr.cmd] (il, rxb);
  3370. } else {
  3371. /* No handling needed */
  3372. D_RX(
  3373. "r %d i %d No handler needed for %s, 0x%02x\n",
  3374. r, i, il_get_cmd_string(pkt->hdr.cmd),
  3375. pkt->hdr.cmd);
  3376. }
  3377. /*
  3378. * XXX: After here, we should always check rxb->page
  3379. * against NULL before touching it or its virtual
  3380. * memory (pkt). Because some rx_handler might have
  3381. * already taken or freed the pages.
  3382. */
  3383. if (reclaim) {
  3384. /* Invoke any callbacks, transfer the buffer to caller,
  3385. * and fire off the (possibly) blocking il_send_cmd()
  3386. * as we reclaim the driver command queue */
  3387. if (rxb->page)
  3388. il_tx_cmd_complete(il, rxb);
  3389. else
  3390. IL_WARN("Claim null rxb?\n");
  3391. }
  3392. /* Reuse the page if possible. For notification packets and
  3393. * SKBs that fail to Rx correctly, add them back into the
  3394. * rx_free list for reuse later. */
  3395. spin_lock_irqsave(&rxq->lock, flags);
  3396. if (rxb->page != NULL) {
  3397. rxb->page_dma = pci_map_page(il->pci_dev, rxb->page,
  3398. 0, PAGE_SIZE << il->hw_params.rx_page_order,
  3399. PCI_DMA_FROMDEVICE);
  3400. list_add_tail(&rxb->list, &rxq->rx_free);
  3401. rxq->free_count++;
  3402. } else
  3403. list_add_tail(&rxb->list, &rxq->rx_used);
  3404. spin_unlock_irqrestore(&rxq->lock, flags);
  3405. i = (i + 1) & RX_QUEUE_MASK;
  3406. /* If there are a lot of unused frames,
  3407. * restock the Rx queue so ucode wont assert. */
  3408. if (fill_rx) {
  3409. count++;
  3410. if (count >= 8) {
  3411. rxq->read = i;
  3412. il4965_rx_replenish_now(il);
  3413. count = 0;
  3414. }
  3415. }
  3416. }
  3417. /* Backtrack one entry */
  3418. rxq->read = i;
  3419. if (fill_rx)
  3420. il4965_rx_replenish_now(il);
  3421. else
  3422. il4965_rx_queue_restock(il);
  3423. }
  3424. /* call this function to flush any scheduled tasklet */
  3425. static inline void il4965_synchronize_irq(struct il_priv *il)
  3426. {
  3427. /* wait to make sure we flush pending tasklet*/
  3428. synchronize_irq(il->pci_dev->irq);
  3429. tasklet_kill(&il->irq_tasklet);
  3430. }
  3431. static void il4965_irq_tasklet(struct il_priv *il)
  3432. {
  3433. u32 inta, handled = 0;
  3434. u32 inta_fh;
  3435. unsigned long flags;
  3436. u32 i;
  3437. #ifdef CONFIG_IWLEGACY_DEBUG
  3438. u32 inta_mask;
  3439. #endif
  3440. spin_lock_irqsave(&il->lock, flags);
  3441. /* Ack/clear/reset pending uCode interrupts.
  3442. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  3443. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  3444. inta = _il_rd(il, CSR_INT);
  3445. _il_wr(il, CSR_INT, inta);
  3446. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  3447. * Any new interrupts that happen after this, either while we're
  3448. * in this tasklet, or later, will show up in next ISR/tasklet. */
  3449. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3450. _il_wr(il, CSR_FH_INT_STATUS, inta_fh);
  3451. #ifdef CONFIG_IWLEGACY_DEBUG
  3452. if (il_get_debug_level(il) & IL_DL_ISR) {
  3453. /* just for debug */
  3454. inta_mask = _il_rd(il, CSR_INT_MASK);
  3455. D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  3456. inta, inta_mask, inta_fh);
  3457. }
  3458. #endif
  3459. spin_unlock_irqrestore(&il->lock, flags);
  3460. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  3461. * atomic, make sure that inta covers all the interrupts that
  3462. * we've discovered, even if FH interrupt came in just after
  3463. * reading CSR_INT. */
  3464. if (inta_fh & CSR49_FH_INT_RX_MASK)
  3465. inta |= CSR_INT_BIT_FH_RX;
  3466. if (inta_fh & CSR49_FH_INT_TX_MASK)
  3467. inta |= CSR_INT_BIT_FH_TX;
  3468. /* Now service all interrupt bits discovered above. */
  3469. if (inta & CSR_INT_BIT_HW_ERR) {
  3470. IL_ERR("Hardware error detected. Restarting.\n");
  3471. /* Tell the device to stop sending interrupts */
  3472. il_disable_interrupts(il);
  3473. il->isr_stats.hw++;
  3474. il_irq_handle_error(il);
  3475. handled |= CSR_INT_BIT_HW_ERR;
  3476. return;
  3477. }
  3478. #ifdef CONFIG_IWLEGACY_DEBUG
  3479. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3480. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  3481. if (inta & CSR_INT_BIT_SCD) {
  3482. D_ISR("Scheduler finished to transmit "
  3483. "the frame/frames.\n");
  3484. il->isr_stats.sch++;
  3485. }
  3486. /* Alive notification via Rx interrupt will do the real work */
  3487. if (inta & CSR_INT_BIT_ALIVE) {
  3488. D_ISR("Alive interrupt\n");
  3489. il->isr_stats.alive++;
  3490. }
  3491. }
  3492. #endif
  3493. /* Safely ignore these bits for debug checks below */
  3494. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  3495. /* HW RF KILL switch toggled */
  3496. if (inta & CSR_INT_BIT_RF_KILL) {
  3497. int hw_rf_kill = 0;
  3498. if (!(_il_rd(il, CSR_GP_CNTRL) &
  3499. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  3500. hw_rf_kill = 1;
  3501. IL_WARN("RF_KILL bit toggled to %s.\n",
  3502. hw_rf_kill ? "disable radio" : "enable radio");
  3503. il->isr_stats.rfkill++;
  3504. /* driver only loads ucode once setting the interface up.
  3505. * the driver allows loading the ucode even if the radio
  3506. * is killed. Hence update the killswitch state here. The
  3507. * rfkill handler will care about restarting if needed.
  3508. */
  3509. if (!test_bit(STATUS_ALIVE, &il->status)) {
  3510. if (hw_rf_kill)
  3511. set_bit(STATUS_RF_KILL_HW, &il->status);
  3512. else
  3513. clear_bit(STATUS_RF_KILL_HW, &il->status);
  3514. wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill);
  3515. }
  3516. handled |= CSR_INT_BIT_RF_KILL;
  3517. }
  3518. /* Chip got too hot and stopped itself */
  3519. if (inta & CSR_INT_BIT_CT_KILL) {
  3520. IL_ERR("Microcode CT kill error detected.\n");
  3521. il->isr_stats.ctkill++;
  3522. handled |= CSR_INT_BIT_CT_KILL;
  3523. }
  3524. /* Error detected by uCode */
  3525. if (inta & CSR_INT_BIT_SW_ERR) {
  3526. IL_ERR("Microcode SW error detected. "
  3527. " Restarting 0x%X.\n", inta);
  3528. il->isr_stats.sw++;
  3529. il_irq_handle_error(il);
  3530. handled |= CSR_INT_BIT_SW_ERR;
  3531. }
  3532. /*
  3533. * uCode wakes up after power-down sleep.
  3534. * Tell device about any new tx or host commands enqueued,
  3535. * and about any Rx buffers made available while asleep.
  3536. */
  3537. if (inta & CSR_INT_BIT_WAKEUP) {
  3538. D_ISR("Wakeup interrupt\n");
  3539. il_rx_queue_update_write_ptr(il, &il->rxq);
  3540. for (i = 0; i < il->hw_params.max_txq_num; i++)
  3541. il_txq_update_write_ptr(il, &il->txq[i]);
  3542. il->isr_stats.wakeup++;
  3543. handled |= CSR_INT_BIT_WAKEUP;
  3544. }
  3545. /* All uCode command responses, including Tx command responses,
  3546. * Rx "responses" (frame-received notification), and other
  3547. * notifications from uCode come through here*/
  3548. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  3549. il4965_rx_handle(il);
  3550. il->isr_stats.rx++;
  3551. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  3552. }
  3553. /* This "Tx" DMA channel is used only for loading uCode */
  3554. if (inta & CSR_INT_BIT_FH_TX) {
  3555. D_ISR("uCode load interrupt\n");
  3556. il->isr_stats.tx++;
  3557. handled |= CSR_INT_BIT_FH_TX;
  3558. /* Wake up uCode load routine, now that load is complete */
  3559. il->ucode_write_complete = 1;
  3560. wake_up(&il->wait_command_queue);
  3561. }
  3562. if (inta & ~handled) {
  3563. IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  3564. il->isr_stats.unhandled++;
  3565. }
  3566. if (inta & ~(il->inta_mask)) {
  3567. IL_WARN("Disabled INTA bits 0x%08x were pending\n",
  3568. inta & ~il->inta_mask);
  3569. IL_WARN(" with FH_INT = 0x%08x\n", inta_fh);
  3570. }
  3571. /* Re-enable all interrupts */
  3572. /* only Re-enable if disabled by irq */
  3573. if (test_bit(STATUS_INT_ENABLED, &il->status))
  3574. il_enable_interrupts(il);
  3575. /* Re-enable RF_KILL if it occurred */
  3576. else if (handled & CSR_INT_BIT_RF_KILL)
  3577. il_enable_rfkill_int(il);
  3578. #ifdef CONFIG_IWLEGACY_DEBUG
  3579. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3580. inta = _il_rd(il, CSR_INT);
  3581. inta_mask = _il_rd(il, CSR_INT_MASK);
  3582. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3583. D_ISR(
  3584. "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  3585. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  3586. }
  3587. #endif
  3588. }
  3589. /*****************************************************************************
  3590. *
  3591. * sysfs attributes
  3592. *
  3593. *****************************************************************************/
  3594. #ifdef CONFIG_IWLEGACY_DEBUG
  3595. /*
  3596. * The following adds a new attribute to the sysfs representation
  3597. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  3598. * used for controlling the debug level.
  3599. *
  3600. * See the level definitions in iwl for details.
  3601. *
  3602. * The debug_level being managed using sysfs below is a per device debug
  3603. * level that is used instead of the global debug level if it (the per
  3604. * device debug level) is set.
  3605. */
  3606. static ssize_t il4965_show_debug_level(struct device *d,
  3607. struct device_attribute *attr, char *buf)
  3608. {
  3609. struct il_priv *il = dev_get_drvdata(d);
  3610. return sprintf(buf, "0x%08X\n", il_get_debug_level(il));
  3611. }
  3612. static ssize_t il4965_store_debug_level(struct device *d,
  3613. struct device_attribute *attr,
  3614. const char *buf, size_t count)
  3615. {
  3616. struct il_priv *il = dev_get_drvdata(d);
  3617. unsigned long val;
  3618. int ret;
  3619. ret = strict_strtoul(buf, 0, &val);
  3620. if (ret)
  3621. IL_ERR("%s is not in hex or decimal form.\n", buf);
  3622. else {
  3623. il->debug_level = val;
  3624. if (il_alloc_traffic_mem(il))
  3625. IL_ERR(
  3626. "Not enough memory to generate traffic log\n");
  3627. }
  3628. return strnlen(buf, count);
  3629. }
  3630. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3631. il4965_show_debug_level, il4965_store_debug_level);
  3632. #endif /* CONFIG_IWLEGACY_DEBUG */
  3633. static ssize_t il4965_show_temperature(struct device *d,
  3634. struct device_attribute *attr, char *buf)
  3635. {
  3636. struct il_priv *il = dev_get_drvdata(d);
  3637. if (!il_is_alive(il))
  3638. return -EAGAIN;
  3639. return sprintf(buf, "%d\n", il->temperature);
  3640. }
  3641. static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL);
  3642. static ssize_t il4965_show_tx_power(struct device *d,
  3643. struct device_attribute *attr, char *buf)
  3644. {
  3645. struct il_priv *il = dev_get_drvdata(d);
  3646. if (!il_is_ready_rf(il))
  3647. return sprintf(buf, "off\n");
  3648. else
  3649. return sprintf(buf, "%d\n", il->tx_power_user_lmt);
  3650. }
  3651. static ssize_t il4965_store_tx_power(struct device *d,
  3652. struct device_attribute *attr,
  3653. const char *buf, size_t count)
  3654. {
  3655. struct il_priv *il = dev_get_drvdata(d);
  3656. unsigned long val;
  3657. int ret;
  3658. ret = strict_strtoul(buf, 10, &val);
  3659. if (ret)
  3660. IL_INFO("%s is not in decimal form.\n", buf);
  3661. else {
  3662. ret = il_set_tx_power(il, val, false);
  3663. if (ret)
  3664. IL_ERR("failed setting tx power (0x%d).\n",
  3665. ret);
  3666. else
  3667. ret = count;
  3668. }
  3669. return ret;
  3670. }
  3671. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO,
  3672. il4965_show_tx_power, il4965_store_tx_power);
  3673. static struct attribute *il_sysfs_entries[] = {
  3674. &dev_attr_temperature.attr,
  3675. &dev_attr_tx_power.attr,
  3676. #ifdef CONFIG_IWLEGACY_DEBUG
  3677. &dev_attr_debug_level.attr,
  3678. #endif
  3679. NULL
  3680. };
  3681. static struct attribute_group il_attribute_group = {
  3682. .name = NULL, /* put in device directory */
  3683. .attrs = il_sysfs_entries,
  3684. };
  3685. /******************************************************************************
  3686. *
  3687. * uCode download functions
  3688. *
  3689. ******************************************************************************/
  3690. static void il4965_dealloc_ucode_pci(struct il_priv *il)
  3691. {
  3692. il_free_fw_desc(il->pci_dev, &il->ucode_code);
  3693. il_free_fw_desc(il->pci_dev, &il->ucode_data);
  3694. il_free_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3695. il_free_fw_desc(il->pci_dev, &il->ucode_init);
  3696. il_free_fw_desc(il->pci_dev, &il->ucode_init_data);
  3697. il_free_fw_desc(il->pci_dev, &il->ucode_boot);
  3698. }
  3699. static void il4965_nic_start(struct il_priv *il)
  3700. {
  3701. /* Remove all resets to allow NIC to operate */
  3702. _il_wr(il, CSR_RESET, 0);
  3703. }
  3704. static void il4965_ucode_callback(const struct firmware *ucode_raw,
  3705. void *context);
  3706. static int il4965_mac_setup_register(struct il_priv *il,
  3707. u32 max_probe_length);
  3708. static int __must_check il4965_request_firmware(struct il_priv *il, bool first)
  3709. {
  3710. const char *name_pre = il->cfg->fw_name_pre;
  3711. char tag[8];
  3712. if (first) {
  3713. il->fw_idx = il->cfg->ucode_api_max;
  3714. sprintf(tag, "%d", il->fw_idx);
  3715. } else {
  3716. il->fw_idx--;
  3717. sprintf(tag, "%d", il->fw_idx);
  3718. }
  3719. if (il->fw_idx < il->cfg->ucode_api_min) {
  3720. IL_ERR("no suitable firmware found!\n");
  3721. return -ENOENT;
  3722. }
  3723. sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  3724. D_INFO("attempting to load firmware '%s'\n",
  3725. il->firmware_name);
  3726. return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name,
  3727. &il->pci_dev->dev, GFP_KERNEL, il,
  3728. il4965_ucode_callback);
  3729. }
  3730. struct il4965_firmware_pieces {
  3731. const void *inst, *data, *init, *init_data, *boot;
  3732. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  3733. };
  3734. static int il4965_load_firmware(struct il_priv *il,
  3735. const struct firmware *ucode_raw,
  3736. struct il4965_firmware_pieces *pieces)
  3737. {
  3738. struct il_ucode_header *ucode = (void *)ucode_raw->data;
  3739. u32 api_ver, hdr_size;
  3740. const u8 *src;
  3741. il->ucode_ver = le32_to_cpu(ucode->ver);
  3742. api_ver = IL_UCODE_API(il->ucode_ver);
  3743. switch (api_ver) {
  3744. default:
  3745. case 0:
  3746. case 1:
  3747. case 2:
  3748. hdr_size = 24;
  3749. if (ucode_raw->size < hdr_size) {
  3750. IL_ERR("File size too small!\n");
  3751. return -EINVAL;
  3752. }
  3753. pieces->inst_size = le32_to_cpu(ucode->v1.inst_size);
  3754. pieces->data_size = le32_to_cpu(ucode->v1.data_size);
  3755. pieces->init_size = le32_to_cpu(ucode->v1.init_size);
  3756. pieces->init_data_size =
  3757. le32_to_cpu(ucode->v1.init_data_size);
  3758. pieces->boot_size = le32_to_cpu(ucode->v1.boot_size);
  3759. src = ucode->v1.data;
  3760. break;
  3761. }
  3762. /* Verify size of file vs. image size info in file's header */
  3763. if (ucode_raw->size != hdr_size + pieces->inst_size +
  3764. pieces->data_size + pieces->init_size +
  3765. pieces->init_data_size + pieces->boot_size) {
  3766. IL_ERR(
  3767. "uCode file size %d does not match expected size\n",
  3768. (int)ucode_raw->size);
  3769. return -EINVAL;
  3770. }
  3771. pieces->inst = src;
  3772. src += pieces->inst_size;
  3773. pieces->data = src;
  3774. src += pieces->data_size;
  3775. pieces->init = src;
  3776. src += pieces->init_size;
  3777. pieces->init_data = src;
  3778. src += pieces->init_data_size;
  3779. pieces->boot = src;
  3780. src += pieces->boot_size;
  3781. return 0;
  3782. }
  3783. /**
  3784. * il4965_ucode_callback - callback when firmware was loaded
  3785. *
  3786. * If loaded successfully, copies the firmware into buffers
  3787. * for the card to fetch (via DMA).
  3788. */
  3789. static void
  3790. il4965_ucode_callback(const struct firmware *ucode_raw, void *context)
  3791. {
  3792. struct il_priv *il = context;
  3793. struct il_ucode_header *ucode;
  3794. int err;
  3795. struct il4965_firmware_pieces pieces;
  3796. const unsigned int api_max = il->cfg->ucode_api_max;
  3797. const unsigned int api_min = il->cfg->ucode_api_min;
  3798. u32 api_ver;
  3799. u32 max_probe_length = 200;
  3800. u32 standard_phy_calibration_size =
  3801. IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  3802. memset(&pieces, 0, sizeof(pieces));
  3803. if (!ucode_raw) {
  3804. if (il->fw_idx <= il->cfg->ucode_api_max)
  3805. IL_ERR(
  3806. "request for firmware file '%s' failed.\n",
  3807. il->firmware_name);
  3808. goto try_again;
  3809. }
  3810. D_INFO("Loaded firmware file '%s' (%zd bytes).\n",
  3811. il->firmware_name, ucode_raw->size);
  3812. /* Make sure that we got at least the API version number */
  3813. if (ucode_raw->size < 4) {
  3814. IL_ERR("File size way too small!\n");
  3815. goto try_again;
  3816. }
  3817. /* Data from ucode file: header followed by uCode images */
  3818. ucode = (struct il_ucode_header *)ucode_raw->data;
  3819. err = il4965_load_firmware(il, ucode_raw, &pieces);
  3820. if (err)
  3821. goto try_again;
  3822. api_ver = IL_UCODE_API(il->ucode_ver);
  3823. /*
  3824. * api_ver should match the api version forming part of the
  3825. * firmware filename ... but we don't check for that and only rely
  3826. * on the API version read from firmware header from here on forward
  3827. */
  3828. if (api_ver < api_min || api_ver > api_max) {
  3829. IL_ERR(
  3830. "Driver unable to support your firmware API. "
  3831. "Driver supports v%u, firmware is v%u.\n",
  3832. api_max, api_ver);
  3833. goto try_again;
  3834. }
  3835. if (api_ver != api_max)
  3836. IL_ERR(
  3837. "Firmware has old API version. Expected v%u, "
  3838. "got v%u. New firmware can be obtained "
  3839. "from http://www.intellinuxwireless.org.\n",
  3840. api_max, api_ver);
  3841. IL_INFO("loaded firmware version %u.%u.%u.%u\n",
  3842. IL_UCODE_MAJOR(il->ucode_ver),
  3843. IL_UCODE_MINOR(il->ucode_ver),
  3844. IL_UCODE_API(il->ucode_ver),
  3845. IL_UCODE_SERIAL(il->ucode_ver));
  3846. snprintf(il->hw->wiphy->fw_version,
  3847. sizeof(il->hw->wiphy->fw_version),
  3848. "%u.%u.%u.%u",
  3849. IL_UCODE_MAJOR(il->ucode_ver),
  3850. IL_UCODE_MINOR(il->ucode_ver),
  3851. IL_UCODE_API(il->ucode_ver),
  3852. IL_UCODE_SERIAL(il->ucode_ver));
  3853. /*
  3854. * For any of the failures below (before allocating pci memory)
  3855. * we will try to load a version with a smaller API -- maybe the
  3856. * user just got a corrupted version of the latest API.
  3857. */
  3858. D_INFO("f/w package hdr ucode version raw = 0x%x\n",
  3859. il->ucode_ver);
  3860. D_INFO("f/w package hdr runtime inst size = %Zd\n",
  3861. pieces.inst_size);
  3862. D_INFO("f/w package hdr runtime data size = %Zd\n",
  3863. pieces.data_size);
  3864. D_INFO("f/w package hdr init inst size = %Zd\n",
  3865. pieces.init_size);
  3866. D_INFO("f/w package hdr init data size = %Zd\n",
  3867. pieces.init_data_size);
  3868. D_INFO("f/w package hdr boot inst size = %Zd\n",
  3869. pieces.boot_size);
  3870. /* Verify that uCode images will fit in card's SRAM */
  3871. if (pieces.inst_size > il->hw_params.max_inst_size) {
  3872. IL_ERR("uCode instr len %Zd too large to fit in\n",
  3873. pieces.inst_size);
  3874. goto try_again;
  3875. }
  3876. if (pieces.data_size > il->hw_params.max_data_size) {
  3877. IL_ERR("uCode data len %Zd too large to fit in\n",
  3878. pieces.data_size);
  3879. goto try_again;
  3880. }
  3881. if (pieces.init_size > il->hw_params.max_inst_size) {
  3882. IL_ERR("uCode init instr len %Zd too large to fit in\n",
  3883. pieces.init_size);
  3884. goto try_again;
  3885. }
  3886. if (pieces.init_data_size > il->hw_params.max_data_size) {
  3887. IL_ERR("uCode init data len %Zd too large to fit in\n",
  3888. pieces.init_data_size);
  3889. goto try_again;
  3890. }
  3891. if (pieces.boot_size > il->hw_params.max_bsm_size) {
  3892. IL_ERR("uCode boot instr len %Zd too large to fit in\n",
  3893. pieces.boot_size);
  3894. goto try_again;
  3895. }
  3896. /* Allocate ucode buffers for card's bus-master loading ... */
  3897. /* Runtime instructions and 2 copies of data:
  3898. * 1) unmodified from disk
  3899. * 2) backup cache for save/restore during power-downs */
  3900. il->ucode_code.len = pieces.inst_size;
  3901. il_alloc_fw_desc(il->pci_dev, &il->ucode_code);
  3902. il->ucode_data.len = pieces.data_size;
  3903. il_alloc_fw_desc(il->pci_dev, &il->ucode_data);
  3904. il->ucode_data_backup.len = pieces.data_size;
  3905. il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3906. if (!il->ucode_code.v_addr || !il->ucode_data.v_addr ||
  3907. !il->ucode_data_backup.v_addr)
  3908. goto err_pci_alloc;
  3909. /* Initialization instructions and data */
  3910. if (pieces.init_size && pieces.init_data_size) {
  3911. il->ucode_init.len = pieces.init_size;
  3912. il_alloc_fw_desc(il->pci_dev, &il->ucode_init);
  3913. il->ucode_init_data.len = pieces.init_data_size;
  3914. il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data);
  3915. if (!il->ucode_init.v_addr || !il->ucode_init_data.v_addr)
  3916. goto err_pci_alloc;
  3917. }
  3918. /* Bootstrap (instructions only, no data) */
  3919. if (pieces.boot_size) {
  3920. il->ucode_boot.len = pieces.boot_size;
  3921. il_alloc_fw_desc(il->pci_dev, &il->ucode_boot);
  3922. if (!il->ucode_boot.v_addr)
  3923. goto err_pci_alloc;
  3924. }
  3925. /* Now that we can no longer fail, copy information */
  3926. il->sta_key_max_num = STA_KEY_MAX_NUM;
  3927. /* Copy images into buffers for card's bus-master reads ... */
  3928. /* Runtime instructions (first block of data in file) */
  3929. D_INFO("Copying (but not loading) uCode instr len %Zd\n",
  3930. pieces.inst_size);
  3931. memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  3932. D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  3933. il->ucode_code.v_addr, (u32)il->ucode_code.p_addr);
  3934. /*
  3935. * Runtime data
  3936. * NOTE: Copy into backup buffer will be done in il_up()
  3937. */
  3938. D_INFO("Copying (but not loading) uCode data len %Zd\n",
  3939. pieces.data_size);
  3940. memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size);
  3941. memcpy(il->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  3942. /* Initialization instructions */
  3943. if (pieces.init_size) {
  3944. D_INFO(
  3945. "Copying (but not loading) init instr len %Zd\n",
  3946. pieces.init_size);
  3947. memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size);
  3948. }
  3949. /* Initialization data */
  3950. if (pieces.init_data_size) {
  3951. D_INFO(
  3952. "Copying (but not loading) init data len %Zd\n",
  3953. pieces.init_data_size);
  3954. memcpy(il->ucode_init_data.v_addr, pieces.init_data,
  3955. pieces.init_data_size);
  3956. }
  3957. /* Bootstrap instructions */
  3958. D_INFO("Copying (but not loading) boot instr len %Zd\n",
  3959. pieces.boot_size);
  3960. memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  3961. /*
  3962. * figure out the offset of chain noise reset and gain commands
  3963. * base on the size of standard phy calibration commands table size
  3964. */
  3965. il->_4965.phy_calib_chain_noise_reset_cmd =
  3966. standard_phy_calibration_size;
  3967. il->_4965.phy_calib_chain_noise_gain_cmd =
  3968. standard_phy_calibration_size + 1;
  3969. /**************************************************
  3970. * This is still part of probe() in a sense...
  3971. *
  3972. * 9. Setup and register with mac80211 and debugfs
  3973. **************************************************/
  3974. err = il4965_mac_setup_register(il, max_probe_length);
  3975. if (err)
  3976. goto out_unbind;
  3977. err = il_dbgfs_register(il, DRV_NAME);
  3978. if (err)
  3979. IL_ERR(
  3980. "failed to create debugfs files. Ignoring error: %d\n", err);
  3981. err = sysfs_create_group(&il->pci_dev->dev.kobj,
  3982. &il_attribute_group);
  3983. if (err) {
  3984. IL_ERR("failed to create sysfs device attributes\n");
  3985. goto out_unbind;
  3986. }
  3987. /* We have our copies now, allow OS release its copies */
  3988. release_firmware(ucode_raw);
  3989. complete(&il->_4965.firmware_loading_complete);
  3990. return;
  3991. try_again:
  3992. /* try next, if any */
  3993. if (il4965_request_firmware(il, false))
  3994. goto out_unbind;
  3995. release_firmware(ucode_raw);
  3996. return;
  3997. err_pci_alloc:
  3998. IL_ERR("failed to allocate pci memory\n");
  3999. il4965_dealloc_ucode_pci(il);
  4000. out_unbind:
  4001. complete(&il->_4965.firmware_loading_complete);
  4002. device_release_driver(&il->pci_dev->dev);
  4003. release_firmware(ucode_raw);
  4004. }
  4005. static const char * const desc_lookup_text[] = {
  4006. "OK",
  4007. "FAIL",
  4008. "BAD_PARAM",
  4009. "BAD_CHECKSUM",
  4010. "NMI_INTERRUPT_WDG",
  4011. "SYSASSERT",
  4012. "FATAL_ERROR",
  4013. "BAD_COMMAND",
  4014. "HW_ERROR_TUNE_LOCK",
  4015. "HW_ERROR_TEMPERATURE",
  4016. "ILLEGAL_CHAN_FREQ",
  4017. "VCC_NOT_STBL",
  4018. "FH_ERROR",
  4019. "NMI_INTERRUPT_HOST",
  4020. "NMI_INTERRUPT_ACTION_PT",
  4021. "NMI_INTERRUPT_UNKNOWN",
  4022. "UCODE_VERSION_MISMATCH",
  4023. "HW_ERROR_ABS_LOCK",
  4024. "HW_ERROR_CAL_LOCK_FAIL",
  4025. "NMI_INTERRUPT_INST_ACTION_PT",
  4026. "NMI_INTERRUPT_DATA_ACTION_PT",
  4027. "NMI_TRM_HW_ER",
  4028. "NMI_INTERRUPT_TRM",
  4029. "NMI_INTERRUPT_BREAK_POINT",
  4030. "DEBUG_0",
  4031. "DEBUG_1",
  4032. "DEBUG_2",
  4033. "DEBUG_3",
  4034. };
  4035. static struct { char *name; u8 num; } advanced_lookup[] = {
  4036. { "NMI_INTERRUPT_WDG", 0x34 },
  4037. { "SYSASSERT", 0x35 },
  4038. { "UCODE_VERSION_MISMATCH", 0x37 },
  4039. { "BAD_COMMAND", 0x38 },
  4040. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  4041. { "FATAL_ERROR", 0x3D },
  4042. { "NMI_TRM_HW_ERR", 0x46 },
  4043. { "NMI_INTERRUPT_TRM", 0x4C },
  4044. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  4045. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  4046. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  4047. { "NMI_INTERRUPT_HOST", 0x66 },
  4048. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  4049. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  4050. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  4051. { "ADVANCED_SYSASSERT", 0 },
  4052. };
  4053. static const char *il4965_desc_lookup(u32 num)
  4054. {
  4055. int i;
  4056. int max = ARRAY_SIZE(desc_lookup_text);
  4057. if (num < max)
  4058. return desc_lookup_text[num];
  4059. max = ARRAY_SIZE(advanced_lookup) - 1;
  4060. for (i = 0; i < max; i++) {
  4061. if (advanced_lookup[i].num == num)
  4062. break;
  4063. }
  4064. return advanced_lookup[i].name;
  4065. }
  4066. #define ERROR_START_OFFSET (1 * sizeof(u32))
  4067. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  4068. void il4965_dump_nic_error_log(struct il_priv *il)
  4069. {
  4070. u32 data2, line;
  4071. u32 desc, time, count, base, data1;
  4072. u32 blink1, blink2, ilink1, ilink2;
  4073. u32 pc, hcmd;
  4074. if (il->ucode_type == UCODE_INIT) {
  4075. base = le32_to_cpu(il->card_alive_init.error_event_table_ptr);
  4076. } else {
  4077. base = le32_to_cpu(il->card_alive.error_event_table_ptr);
  4078. }
  4079. if (!il->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  4080. IL_ERR(
  4081. "Not valid error log pointer 0x%08X for %s uCode\n",
  4082. base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT");
  4083. return;
  4084. }
  4085. count = il_read_targ_mem(il, base);
  4086. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  4087. IL_ERR("Start IWL Error Log Dump:\n");
  4088. IL_ERR("Status: 0x%08lX, count: %d\n",
  4089. il->status, count);
  4090. }
  4091. desc = il_read_targ_mem(il, base + 1 * sizeof(u32));
  4092. il->isr_stats.err_code = desc;
  4093. pc = il_read_targ_mem(il, base + 2 * sizeof(u32));
  4094. blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32));
  4095. blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32));
  4096. ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32));
  4097. ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32));
  4098. data1 = il_read_targ_mem(il, base + 7 * sizeof(u32));
  4099. data2 = il_read_targ_mem(il, base + 8 * sizeof(u32));
  4100. line = il_read_targ_mem(il, base + 9 * sizeof(u32));
  4101. time = il_read_targ_mem(il, base + 11 * sizeof(u32));
  4102. hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32));
  4103. IL_ERR("Desc Time "
  4104. "data1 data2 line\n");
  4105. IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  4106. il4965_desc_lookup(desc), desc, time, data1, data2, line);
  4107. IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n");
  4108. IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  4109. pc, blink1, blink2, ilink1, ilink2, hcmd);
  4110. }
  4111. static void il4965_rf_kill_ct_config(struct il_priv *il)
  4112. {
  4113. struct il_ct_kill_config cmd;
  4114. unsigned long flags;
  4115. int ret = 0;
  4116. spin_lock_irqsave(&il->lock, flags);
  4117. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  4118. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  4119. spin_unlock_irqrestore(&il->lock, flags);
  4120. cmd.critical_temperature_R =
  4121. cpu_to_le32(il->hw_params.ct_kill_threshold);
  4122. ret = il_send_cmd_pdu(il, REPLY_CT_KILL_CONFIG_CMD,
  4123. sizeof(cmd), &cmd);
  4124. if (ret)
  4125. IL_ERR("REPLY_CT_KILL_CONFIG_CMD failed\n");
  4126. else
  4127. D_INFO("REPLY_CT_KILL_CONFIG_CMD "
  4128. "succeeded, "
  4129. "critical temperature is %d\n",
  4130. il->hw_params.ct_kill_threshold);
  4131. }
  4132. static const s8 default_queue_to_tx_fifo[] = {
  4133. IL_TX_FIFO_VO,
  4134. IL_TX_FIFO_VI,
  4135. IL_TX_FIFO_BE,
  4136. IL_TX_FIFO_BK,
  4137. IL49_CMD_FIFO_NUM,
  4138. IL_TX_FIFO_UNUSED,
  4139. IL_TX_FIFO_UNUSED,
  4140. };
  4141. static int il4965_alive_notify(struct il_priv *il)
  4142. {
  4143. u32 a;
  4144. unsigned long flags;
  4145. int i, chan;
  4146. u32 reg_val;
  4147. spin_lock_irqsave(&il->lock, flags);
  4148. /* Clear 4965's internal Tx Scheduler data base */
  4149. il->scd_base_addr = il_rd_prph(il,
  4150. IL49_SCD_SRAM_BASE_ADDR);
  4151. a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET;
  4152. for (; a < il->scd_base_addr + IL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  4153. il_write_targ_mem(il, a, 0);
  4154. for (; a < il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  4155. il_write_targ_mem(il, a, 0);
  4156. for (; a < il->scd_base_addr +
  4157. IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num); a += 4)
  4158. il_write_targ_mem(il, a, 0);
  4159. /* Tel 4965 where to find Tx byte count tables */
  4160. il_wr_prph(il, IL49_SCD_DRAM_BASE_ADDR,
  4161. il->scd_bc_tbls.dma >> 10);
  4162. /* Enable DMA channel */
  4163. for (chan = 0; chan < FH49_TCSR_CHNL_NUM ; chan++)
  4164. il_wr(il,
  4165. FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  4166. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  4167. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  4168. /* Update FH chicken bits */
  4169. reg_val = il_rd(il, FH_TX_CHICKEN_BITS_REG);
  4170. il_wr(il, FH_TX_CHICKEN_BITS_REG,
  4171. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  4172. /* Disable chain mode for all queues */
  4173. il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0);
  4174. /* Initialize each Tx queue (including the command queue) */
  4175. for (i = 0; i < il->hw_params.max_txq_num; i++) {
  4176. /* TFD circular buffer read/write idxes */
  4177. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0);
  4178. il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8));
  4179. /* Max Tx Window size for Scheduler-ACK mode */
  4180. il_write_targ_mem(il, il->scd_base_addr +
  4181. IL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  4182. (SCD_WIN_SIZE <<
  4183. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  4184. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  4185. /* Frame limit */
  4186. il_write_targ_mem(il, il->scd_base_addr +
  4187. IL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  4188. sizeof(u32),
  4189. (SCD_FRAME_LIMIT <<
  4190. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  4191. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  4192. }
  4193. il_wr_prph(il, IL49_SCD_INTERRUPT_MASK,
  4194. (1 << il->hw_params.max_txq_num) - 1);
  4195. /* Activate all Tx DMA/FIFO channels */
  4196. il4965_txq_set_sched(il, IL_MASK(0, 6));
  4197. il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0);
  4198. /* make sure all queue are not stopped */
  4199. memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped));
  4200. for (i = 0; i < 4; i++)
  4201. atomic_set(&il->queue_stop_count[i], 0);
  4202. /* reset to 0 to enable all the queue first */
  4203. il->txq_ctx_active_msk = 0;
  4204. /* Map each Tx/cmd queue to its corresponding fifo */
  4205. BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
  4206. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  4207. int ac = default_queue_to_tx_fifo[i];
  4208. il_txq_ctx_activate(il, i);
  4209. if (ac == IL_TX_FIFO_UNUSED)
  4210. continue;
  4211. il4965_tx_queue_set_status(il, &il->txq[i], ac, 0);
  4212. }
  4213. spin_unlock_irqrestore(&il->lock, flags);
  4214. return 0;
  4215. }
  4216. /**
  4217. * il4965_alive_start - called after REPLY_ALIVE notification received
  4218. * from protocol/runtime uCode (initialization uCode's
  4219. * Alive gets handled by il_init_alive_start()).
  4220. */
  4221. static void il4965_alive_start(struct il_priv *il)
  4222. {
  4223. int ret = 0;
  4224. struct il_rxon_context *ctx = &il->ctx;
  4225. D_INFO("Runtime Alive received.\n");
  4226. if (il->card_alive.is_valid != UCODE_VALID_OK) {
  4227. /* We had an error bringing up the hardware, so take it
  4228. * all the way back down so we can try again */
  4229. D_INFO("Alive failed.\n");
  4230. goto restart;
  4231. }
  4232. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  4233. * This is a paranoid check, because we would not have gotten the
  4234. * "runtime" alive if code weren't properly loaded. */
  4235. if (il4965_verify_ucode(il)) {
  4236. /* Runtime instruction load was bad;
  4237. * take it all the way back down so we can try again */
  4238. D_INFO("Bad runtime uCode load.\n");
  4239. goto restart;
  4240. }
  4241. ret = il4965_alive_notify(il);
  4242. if (ret) {
  4243. IL_WARN(
  4244. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  4245. goto restart;
  4246. }
  4247. /* After the ALIVE response, we can send host commands to the uCode */
  4248. set_bit(STATUS_ALIVE, &il->status);
  4249. /* Enable watchdog to monitor the driver tx queues */
  4250. il_setup_watchdog(il);
  4251. if (il_is_rfkill(il))
  4252. return;
  4253. ieee80211_wake_queues(il->hw);
  4254. il->active_rate = RATES_MASK;
  4255. if (il_is_associated_ctx(ctx)) {
  4256. struct il_rxon_cmd *active_rxon =
  4257. (struct il_rxon_cmd *)&ctx->active;
  4258. /* apply any changes in staging */
  4259. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  4260. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4261. } else {
  4262. /* Initialize our rx_config data */
  4263. il_connection_init_rx_config(il, &il->ctx);
  4264. if (il->cfg->ops->hcmd->set_rxon_chain)
  4265. il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
  4266. }
  4267. /* Configure bluetooth coexistence if enabled */
  4268. il_send_bt_config(il);
  4269. il4965_reset_run_time_calib(il);
  4270. set_bit(STATUS_READY, &il->status);
  4271. /* Configure the adapter for unassociated operation */
  4272. il_commit_rxon(il, ctx);
  4273. /* At this point, the NIC is initialized and operational */
  4274. il4965_rf_kill_ct_config(il);
  4275. D_INFO("ALIVE processing complete.\n");
  4276. wake_up(&il->wait_command_queue);
  4277. il_power_update_mode(il, true);
  4278. D_INFO("Updated power mode\n");
  4279. return;
  4280. restart:
  4281. queue_work(il->workqueue, &il->restart);
  4282. }
  4283. static void il4965_cancel_deferred_work(struct il_priv *il);
  4284. static void __il4965_down(struct il_priv *il)
  4285. {
  4286. unsigned long flags;
  4287. int exit_pending;
  4288. D_INFO(DRV_NAME " is going down\n");
  4289. il_scan_cancel_timeout(il, 200);
  4290. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &il->status);
  4291. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  4292. * to prevent rearm timer */
  4293. del_timer_sync(&il->watchdog);
  4294. il_clear_ucode_stations(il, NULL);
  4295. il_dealloc_bcast_stations(il);
  4296. il_clear_driver_stations(il);
  4297. /* Unblock any waiting calls */
  4298. wake_up_all(&il->wait_command_queue);
  4299. /* Wipe out the EXIT_PENDING status bit if we are not actually
  4300. * exiting the module */
  4301. if (!exit_pending)
  4302. clear_bit(STATUS_EXIT_PENDING, &il->status);
  4303. /* stop and reset the on-board processor */
  4304. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  4305. /* tell the device to stop sending interrupts */
  4306. spin_lock_irqsave(&il->lock, flags);
  4307. il_disable_interrupts(il);
  4308. spin_unlock_irqrestore(&il->lock, flags);
  4309. il4965_synchronize_irq(il);
  4310. if (il->mac80211_registered)
  4311. ieee80211_stop_queues(il->hw);
  4312. /* If we have not previously called il_init() then
  4313. * clear all bits but the RF Kill bit and return */
  4314. if (!il_is_init(il)) {
  4315. il->status = test_bit(STATUS_RF_KILL_HW, &il->status) <<
  4316. STATUS_RF_KILL_HW |
  4317. test_bit(STATUS_GEO_CONFIGURED, &il->status) <<
  4318. STATUS_GEO_CONFIGURED |
  4319. test_bit(STATUS_EXIT_PENDING, &il->status) <<
  4320. STATUS_EXIT_PENDING;
  4321. goto exit;
  4322. }
  4323. /* ...otherwise clear out all the status bits but the RF Kill
  4324. * bit and continue taking the NIC down. */
  4325. il->status &= test_bit(STATUS_RF_KILL_HW, &il->status) <<
  4326. STATUS_RF_KILL_HW |
  4327. test_bit(STATUS_GEO_CONFIGURED, &il->status) <<
  4328. STATUS_GEO_CONFIGURED |
  4329. test_bit(STATUS_FW_ERROR, &il->status) <<
  4330. STATUS_FW_ERROR |
  4331. test_bit(STATUS_EXIT_PENDING, &il->status) <<
  4332. STATUS_EXIT_PENDING;
  4333. il4965_txq_ctx_stop(il);
  4334. il4965_rxq_stop(il);
  4335. /* Power-down device's busmaster DMA clocks */
  4336. il_wr_prph(il, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  4337. udelay(5);
  4338. /* Make sure (redundant) we've released our request to stay awake */
  4339. il_clear_bit(il, CSR_GP_CNTRL,
  4340. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  4341. /* Stop the device, and put it in low power state */
  4342. il_apm_stop(il);
  4343. exit:
  4344. memset(&il->card_alive, 0, sizeof(struct il_alive_resp));
  4345. dev_kfree_skb(il->beacon_skb);
  4346. il->beacon_skb = NULL;
  4347. /* clear out any free frames */
  4348. il4965_clear_free_frames(il);
  4349. }
  4350. static void il4965_down(struct il_priv *il)
  4351. {
  4352. mutex_lock(&il->mutex);
  4353. __il4965_down(il);
  4354. mutex_unlock(&il->mutex);
  4355. il4965_cancel_deferred_work(il);
  4356. }
  4357. #define HW_READY_TIMEOUT (50)
  4358. static int il4965_set_hw_ready(struct il_priv *il)
  4359. {
  4360. int ret = 0;
  4361. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  4362. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  4363. /* See if we got it */
  4364. ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4365. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  4366. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  4367. HW_READY_TIMEOUT);
  4368. if (ret != -ETIMEDOUT)
  4369. il->hw_ready = true;
  4370. else
  4371. il->hw_ready = false;
  4372. D_INFO("hardware %s\n",
  4373. (il->hw_ready == 1) ? "ready" : "not ready");
  4374. return ret;
  4375. }
  4376. static int il4965_prepare_card_hw(struct il_priv *il)
  4377. {
  4378. int ret = 0;
  4379. D_INFO("il4965_prepare_card_hw enter\n");
  4380. ret = il4965_set_hw_ready(il);
  4381. if (il->hw_ready)
  4382. return ret;
  4383. /* If HW is not ready, prepare the conditions to check again */
  4384. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  4385. CSR_HW_IF_CONFIG_REG_PREPARE);
  4386. ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4387. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  4388. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  4389. /* HW should be ready by now, check again. */
  4390. if (ret != -ETIMEDOUT)
  4391. il4965_set_hw_ready(il);
  4392. return ret;
  4393. }
  4394. #define MAX_HW_RESTARTS 5
  4395. static int __il4965_up(struct il_priv *il)
  4396. {
  4397. int i;
  4398. int ret;
  4399. if (test_bit(STATUS_EXIT_PENDING, &il->status)) {
  4400. IL_WARN("Exit pending; will not bring the NIC up\n");
  4401. return -EIO;
  4402. }
  4403. if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) {
  4404. IL_ERR("ucode not available for device bringup\n");
  4405. return -EIO;
  4406. }
  4407. ret = il4965_alloc_bcast_station(il, &il->ctx);
  4408. if (ret) {
  4409. il_dealloc_bcast_stations(il);
  4410. return ret;
  4411. }
  4412. il4965_prepare_card_hw(il);
  4413. if (!il->hw_ready) {
  4414. IL_WARN("Exit HW not ready\n");
  4415. return -EIO;
  4416. }
  4417. /* If platform's RF_KILL switch is NOT set to KILL */
  4418. if (_il_rd(il,
  4419. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  4420. clear_bit(STATUS_RF_KILL_HW, &il->status);
  4421. else
  4422. set_bit(STATUS_RF_KILL_HW, &il->status);
  4423. if (il_is_rfkill(il)) {
  4424. wiphy_rfkill_set_hw_state(il->hw->wiphy, true);
  4425. il_enable_interrupts(il);
  4426. IL_WARN("Radio disabled by HW RF Kill switch\n");
  4427. return 0;
  4428. }
  4429. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4430. /* must be initialised before il_hw_nic_init */
  4431. il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM;
  4432. ret = il4965_hw_nic_init(il);
  4433. if (ret) {
  4434. IL_ERR("Unable to init nic\n");
  4435. return ret;
  4436. }
  4437. /* make sure rfkill handshake bits are cleared */
  4438. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4439. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  4440. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  4441. /* clear (again), then enable host interrupts */
  4442. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4443. il_enable_interrupts(il);
  4444. /* really make sure rfkill handshake bits are cleared */
  4445. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4446. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4447. /* Copy original ucode data image from disk into backup cache.
  4448. * This will be used to initialize the on-board processor's
  4449. * data SRAM for a clean start when the runtime program first loads. */
  4450. memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr,
  4451. il->ucode_data.len);
  4452. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  4453. /* load bootstrap state machine,
  4454. * load bootstrap program into processor's memory,
  4455. * prepare to load the "initialize" uCode */
  4456. ret = il->cfg->ops->lib->load_ucode(il);
  4457. if (ret) {
  4458. IL_ERR("Unable to set up bootstrap uCode: %d\n",
  4459. ret);
  4460. continue;
  4461. }
  4462. /* start card; "initialize" will load runtime ucode */
  4463. il4965_nic_start(il);
  4464. D_INFO(DRV_NAME " is coming up\n");
  4465. return 0;
  4466. }
  4467. set_bit(STATUS_EXIT_PENDING, &il->status);
  4468. __il4965_down(il);
  4469. clear_bit(STATUS_EXIT_PENDING, &il->status);
  4470. /* tried to restart and config the device for as long as our
  4471. * patience could withstand */
  4472. IL_ERR("Unable to initialize device after %d attempts.\n", i);
  4473. return -EIO;
  4474. }
  4475. /*****************************************************************************
  4476. *
  4477. * Workqueue callbacks
  4478. *
  4479. *****************************************************************************/
  4480. static void il4965_bg_init_alive_start(struct work_struct *data)
  4481. {
  4482. struct il_priv *il =
  4483. container_of(data, struct il_priv, init_alive_start.work);
  4484. mutex_lock(&il->mutex);
  4485. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4486. goto out;
  4487. il->cfg->ops->lib->init_alive_start(il);
  4488. out:
  4489. mutex_unlock(&il->mutex);
  4490. }
  4491. static void il4965_bg_alive_start(struct work_struct *data)
  4492. {
  4493. struct il_priv *il =
  4494. container_of(data, struct il_priv, alive_start.work);
  4495. mutex_lock(&il->mutex);
  4496. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4497. goto out;
  4498. il4965_alive_start(il);
  4499. out:
  4500. mutex_unlock(&il->mutex);
  4501. }
  4502. static void il4965_bg_run_time_calib_work(struct work_struct *work)
  4503. {
  4504. struct il_priv *il = container_of(work, struct il_priv,
  4505. run_time_calib_work);
  4506. mutex_lock(&il->mutex);
  4507. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  4508. test_bit(STATUS_SCANNING, &il->status)) {
  4509. mutex_unlock(&il->mutex);
  4510. return;
  4511. }
  4512. if (il->start_calib) {
  4513. il4965_chain_noise_calibration(il,
  4514. (void *)&il->_4965.stats);
  4515. il4965_sensitivity_calibration(il,
  4516. (void *)&il->_4965.stats);
  4517. }
  4518. mutex_unlock(&il->mutex);
  4519. }
  4520. static void il4965_bg_restart(struct work_struct *data)
  4521. {
  4522. struct il_priv *il = container_of(data, struct il_priv, restart);
  4523. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4524. return;
  4525. if (test_and_clear_bit(STATUS_FW_ERROR, &il->status)) {
  4526. mutex_lock(&il->mutex);
  4527. il->ctx.vif = NULL;
  4528. il->is_open = 0;
  4529. __il4965_down(il);
  4530. mutex_unlock(&il->mutex);
  4531. il4965_cancel_deferred_work(il);
  4532. ieee80211_restart_hw(il->hw);
  4533. } else {
  4534. il4965_down(il);
  4535. mutex_lock(&il->mutex);
  4536. if (test_bit(STATUS_EXIT_PENDING, &il->status)) {
  4537. mutex_unlock(&il->mutex);
  4538. return;
  4539. }
  4540. __il4965_up(il);
  4541. mutex_unlock(&il->mutex);
  4542. }
  4543. }
  4544. static void il4965_bg_rx_replenish(struct work_struct *data)
  4545. {
  4546. struct il_priv *il =
  4547. container_of(data, struct il_priv, rx_replenish);
  4548. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4549. return;
  4550. mutex_lock(&il->mutex);
  4551. il4965_rx_replenish(il);
  4552. mutex_unlock(&il->mutex);
  4553. }
  4554. /*****************************************************************************
  4555. *
  4556. * mac80211 entry point functions
  4557. *
  4558. *****************************************************************************/
  4559. #define UCODE_READY_TIMEOUT (4 * HZ)
  4560. /*
  4561. * Not a mac80211 entry point function, but it fits in with all the
  4562. * other mac80211 functions grouped here.
  4563. */
  4564. static int il4965_mac_setup_register(struct il_priv *il,
  4565. u32 max_probe_length)
  4566. {
  4567. int ret;
  4568. struct ieee80211_hw *hw = il->hw;
  4569. hw->rate_control_algorithm = "iwl-4965-rs";
  4570. /* Tell mac80211 our characteristics */
  4571. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4572. IEEE80211_HW_AMPDU_AGGREGATION |
  4573. IEEE80211_HW_NEED_DTIM_PERIOD |
  4574. IEEE80211_HW_SPECTRUM_MGMT |
  4575. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  4576. if (il->cfg->sku & IL_SKU_N)
  4577. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  4578. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  4579. hw->sta_data_size = sizeof(struct il_station_priv);
  4580. hw->vif_data_size = sizeof(struct il_vif_priv);
  4581. hw->wiphy->interface_modes |= il->ctx.interface_modes;
  4582. hw->wiphy->interface_modes |= il->ctx.exclusive_interface_modes;
  4583. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  4584. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  4585. /*
  4586. * For now, disable PS by default because it affects
  4587. * RX performance significantly.
  4588. */
  4589. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4590. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  4591. /* we create the 802.11 header and a zero-length SSID element */
  4592. hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2;
  4593. /* Default value; 4 EDCA QOS priorities */
  4594. hw->queues = 4;
  4595. hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL;
  4596. if (il->bands[IEEE80211_BAND_2GHZ].n_channels)
  4597. il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4598. &il->bands[IEEE80211_BAND_2GHZ];
  4599. if (il->bands[IEEE80211_BAND_5GHZ].n_channels)
  4600. il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4601. &il->bands[IEEE80211_BAND_5GHZ];
  4602. il_leds_init(il);
  4603. ret = ieee80211_register_hw(il->hw);
  4604. if (ret) {
  4605. IL_ERR("Failed to register hw (error %d)\n", ret);
  4606. return ret;
  4607. }
  4608. il->mac80211_registered = 1;
  4609. return 0;
  4610. }
  4611. int il4965_mac_start(struct ieee80211_hw *hw)
  4612. {
  4613. struct il_priv *il = hw->priv;
  4614. int ret;
  4615. D_MAC80211("enter\n");
  4616. /* we should be verifying the device is ready to be opened */
  4617. mutex_lock(&il->mutex);
  4618. ret = __il4965_up(il);
  4619. mutex_unlock(&il->mutex);
  4620. if (ret)
  4621. return ret;
  4622. if (il_is_rfkill(il))
  4623. goto out;
  4624. D_INFO("Start UP work done.\n");
  4625. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  4626. * mac80211 will not be run successfully. */
  4627. ret = wait_event_timeout(il->wait_command_queue,
  4628. test_bit(STATUS_READY, &il->status),
  4629. UCODE_READY_TIMEOUT);
  4630. if (!ret) {
  4631. if (!test_bit(STATUS_READY, &il->status)) {
  4632. IL_ERR("START_ALIVE timeout after %dms.\n",
  4633. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  4634. return -ETIMEDOUT;
  4635. }
  4636. }
  4637. il4965_led_enable(il);
  4638. out:
  4639. il->is_open = 1;
  4640. D_MAC80211("leave\n");
  4641. return 0;
  4642. }
  4643. void il4965_mac_stop(struct ieee80211_hw *hw)
  4644. {
  4645. struct il_priv *il = hw->priv;
  4646. D_MAC80211("enter\n");
  4647. if (!il->is_open)
  4648. return;
  4649. il->is_open = 0;
  4650. il4965_down(il);
  4651. flush_workqueue(il->workqueue);
  4652. /* User space software may expect getting rfkill changes
  4653. * even if interface is down */
  4654. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4655. il_enable_rfkill_int(il);
  4656. D_MAC80211("leave\n");
  4657. }
  4658. void il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  4659. {
  4660. struct il_priv *il = hw->priv;
  4661. D_MACDUMP("enter\n");
  4662. D_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  4663. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  4664. if (il4965_tx_skb(il, skb))
  4665. dev_kfree_skb_any(skb);
  4666. D_MACDUMP("leave\n");
  4667. }
  4668. void il4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  4669. struct ieee80211_vif *vif,
  4670. struct ieee80211_key_conf *keyconf,
  4671. struct ieee80211_sta *sta,
  4672. u32 iv32, u16 *phase1key)
  4673. {
  4674. struct il_priv *il = hw->priv;
  4675. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4676. D_MAC80211("enter\n");
  4677. il4965_update_tkip_key(il, vif_priv->ctx, keyconf, sta,
  4678. iv32, phase1key);
  4679. D_MAC80211("leave\n");
  4680. }
  4681. int il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  4682. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  4683. struct ieee80211_key_conf *key)
  4684. {
  4685. struct il_priv *il = hw->priv;
  4686. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4687. struct il_rxon_context *ctx = vif_priv->ctx;
  4688. int ret;
  4689. u8 sta_id;
  4690. bool is_default_wep_key = false;
  4691. D_MAC80211("enter\n");
  4692. if (il->cfg->mod_params->sw_crypto) {
  4693. D_MAC80211("leave - hwcrypto disabled\n");
  4694. return -EOPNOTSUPP;
  4695. }
  4696. sta_id = il_sta_id_or_broadcast(il, vif_priv->ctx, sta);
  4697. if (sta_id == IL_INVALID_STATION)
  4698. return -EINVAL;
  4699. mutex_lock(&il->mutex);
  4700. il_scan_cancel_timeout(il, 100);
  4701. /*
  4702. * If we are getting WEP group key and we didn't receive any key mapping
  4703. * so far, we are in legacy wep mode (group key only), otherwise we are
  4704. * in 1X mode.
  4705. * In legacy wep mode, we use another host command to the uCode.
  4706. */
  4707. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  4708. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  4709. !sta) {
  4710. if (cmd == SET_KEY)
  4711. is_default_wep_key = !ctx->key_mapping_keys;
  4712. else
  4713. is_default_wep_key =
  4714. (key->hw_key_idx == HW_KEY_DEFAULT);
  4715. }
  4716. switch (cmd) {
  4717. case SET_KEY:
  4718. if (is_default_wep_key)
  4719. ret = il4965_set_default_wep_key(il,
  4720. vif_priv->ctx, key);
  4721. else
  4722. ret = il4965_set_dynamic_key(il, vif_priv->ctx,
  4723. key, sta_id);
  4724. D_MAC80211("enable hwcrypto key\n");
  4725. break;
  4726. case DISABLE_KEY:
  4727. if (is_default_wep_key)
  4728. ret = il4965_remove_default_wep_key(il, ctx, key);
  4729. else
  4730. ret = il4965_remove_dynamic_key(il, ctx,
  4731. key, sta_id);
  4732. D_MAC80211("disable hwcrypto key\n");
  4733. break;
  4734. default:
  4735. ret = -EINVAL;
  4736. }
  4737. mutex_unlock(&il->mutex);
  4738. D_MAC80211("leave\n");
  4739. return ret;
  4740. }
  4741. int il4965_mac_ampdu_action(struct ieee80211_hw *hw,
  4742. struct ieee80211_vif *vif,
  4743. enum ieee80211_ampdu_mlme_action action,
  4744. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4745. u8 buf_size)
  4746. {
  4747. struct il_priv *il = hw->priv;
  4748. int ret = -EINVAL;
  4749. D_HT("A-MPDU action on addr %pM tid %d\n",
  4750. sta->addr, tid);
  4751. if (!(il->cfg->sku & IL_SKU_N))
  4752. return -EACCES;
  4753. mutex_lock(&il->mutex);
  4754. switch (action) {
  4755. case IEEE80211_AMPDU_RX_START:
  4756. D_HT("start Rx\n");
  4757. ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn);
  4758. break;
  4759. case IEEE80211_AMPDU_RX_STOP:
  4760. D_HT("stop Rx\n");
  4761. ret = il4965_sta_rx_agg_stop(il, sta, tid);
  4762. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4763. ret = 0;
  4764. break;
  4765. case IEEE80211_AMPDU_TX_START:
  4766. D_HT("start Tx\n");
  4767. ret = il4965_tx_agg_start(il, vif, sta, tid, ssn);
  4768. break;
  4769. case IEEE80211_AMPDU_TX_STOP:
  4770. D_HT("stop Tx\n");
  4771. ret = il4965_tx_agg_stop(il, vif, sta, tid);
  4772. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  4773. ret = 0;
  4774. break;
  4775. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4776. ret = 0;
  4777. break;
  4778. }
  4779. mutex_unlock(&il->mutex);
  4780. return ret;
  4781. }
  4782. int il4965_mac_sta_add(struct ieee80211_hw *hw,
  4783. struct ieee80211_vif *vif,
  4784. struct ieee80211_sta *sta)
  4785. {
  4786. struct il_priv *il = hw->priv;
  4787. struct il_station_priv *sta_priv = (void *)sta->drv_priv;
  4788. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4789. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  4790. int ret;
  4791. u8 sta_id;
  4792. D_INFO("received request to add station %pM\n",
  4793. sta->addr);
  4794. mutex_lock(&il->mutex);
  4795. D_INFO("proceeding to add station %pM\n",
  4796. sta->addr);
  4797. sta_priv->common.sta_id = IL_INVALID_STATION;
  4798. atomic_set(&sta_priv->pending_frames, 0);
  4799. ret = il_add_station_common(il, vif_priv->ctx, sta->addr,
  4800. is_ap, sta, &sta_id);
  4801. if (ret) {
  4802. IL_ERR("Unable to add station %pM (%d)\n",
  4803. sta->addr, ret);
  4804. /* Should we return success if return code is EEXIST ? */
  4805. mutex_unlock(&il->mutex);
  4806. return ret;
  4807. }
  4808. sta_priv->common.sta_id = sta_id;
  4809. /* Initialize rate scaling */
  4810. D_INFO("Initializing rate scaling for station %pM\n",
  4811. sta->addr);
  4812. il4965_rs_rate_init(il, sta, sta_id);
  4813. mutex_unlock(&il->mutex);
  4814. return 0;
  4815. }
  4816. void il4965_mac_channel_switch(struct ieee80211_hw *hw,
  4817. struct ieee80211_channel_switch *ch_switch)
  4818. {
  4819. struct il_priv *il = hw->priv;
  4820. const struct il_channel_info *ch_info;
  4821. struct ieee80211_conf *conf = &hw->conf;
  4822. struct ieee80211_channel *channel = ch_switch->channel;
  4823. struct il_ht_config *ht_conf = &il->current_ht_config;
  4824. struct il_rxon_context *ctx = &il->ctx;
  4825. u16 ch;
  4826. D_MAC80211("enter\n");
  4827. mutex_lock(&il->mutex);
  4828. if (il_is_rfkill(il))
  4829. goto out;
  4830. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  4831. test_bit(STATUS_SCANNING, &il->status) ||
  4832. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status))
  4833. goto out;
  4834. if (!il_is_associated_ctx(ctx))
  4835. goto out;
  4836. if (!il->cfg->ops->lib->set_channel_switch)
  4837. goto out;
  4838. ch = channel->hw_value;
  4839. if (le16_to_cpu(ctx->active.channel) == ch)
  4840. goto out;
  4841. ch_info = il_get_channel_info(il, channel->band, ch);
  4842. if (!il_is_channel_valid(ch_info)) {
  4843. D_MAC80211("invalid channel\n");
  4844. goto out;
  4845. }
  4846. spin_lock_irq(&il->lock);
  4847. il->current_ht_config.smps = conf->smps_mode;
  4848. /* Configure HT40 channels */
  4849. ctx->ht.enabled = conf_is_ht(conf);
  4850. if (ctx->ht.enabled) {
  4851. if (conf_is_ht40_minus(conf)) {
  4852. ctx->ht.extension_chan_offset =
  4853. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  4854. ctx->ht.is_40mhz = true;
  4855. } else if (conf_is_ht40_plus(conf)) {
  4856. ctx->ht.extension_chan_offset =
  4857. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  4858. ctx->ht.is_40mhz = true;
  4859. } else {
  4860. ctx->ht.extension_chan_offset =
  4861. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  4862. ctx->ht.is_40mhz = false;
  4863. }
  4864. } else
  4865. ctx->ht.is_40mhz = false;
  4866. if ((le16_to_cpu(ctx->staging.channel) != ch))
  4867. ctx->staging.flags = 0;
  4868. il_set_rxon_channel(il, channel, ctx);
  4869. il_set_rxon_ht(il, ht_conf);
  4870. il_set_flags_for_band(il, ctx, channel->band, ctx->vif);
  4871. spin_unlock_irq(&il->lock);
  4872. il_set_rate(il);
  4873. /*
  4874. * at this point, staging_rxon has the
  4875. * configuration for channel switch
  4876. */
  4877. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status);
  4878. il->switch_channel = cpu_to_le16(ch);
  4879. if (il->cfg->ops->lib->set_channel_switch(il, ch_switch)) {
  4880. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status);
  4881. il->switch_channel = 0;
  4882. ieee80211_chswitch_done(ctx->vif, false);
  4883. }
  4884. out:
  4885. mutex_unlock(&il->mutex);
  4886. D_MAC80211("leave\n");
  4887. }
  4888. void il4965_configure_filter(struct ieee80211_hw *hw,
  4889. unsigned int changed_flags,
  4890. unsigned int *total_flags,
  4891. u64 multicast)
  4892. {
  4893. struct il_priv *il = hw->priv;
  4894. __le32 filter_or = 0, filter_nand = 0;
  4895. #define CHK(test, flag) do { \
  4896. if (*total_flags & (test)) \
  4897. filter_or |= (flag); \
  4898. else \
  4899. filter_nand |= (flag); \
  4900. } while (0)
  4901. D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
  4902. changed_flags, *total_flags);
  4903. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  4904. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  4905. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  4906. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  4907. #undef CHK
  4908. mutex_lock(&il->mutex);
  4909. il->ctx.staging.filter_flags &= ~filter_nand;
  4910. il->ctx.staging.filter_flags |= filter_or;
  4911. /*
  4912. * Not committing directly because hardware can perform a scan,
  4913. * but we'll eventually commit the filter flags change anyway.
  4914. */
  4915. mutex_unlock(&il->mutex);
  4916. /*
  4917. * Receiving all multicast frames is always enabled by the
  4918. * default flags setup in il_connection_init_rx_config()
  4919. * since we currently do not support programming multicast
  4920. * filters into the device.
  4921. */
  4922. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  4923. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  4924. }
  4925. /*****************************************************************************
  4926. *
  4927. * driver setup and teardown
  4928. *
  4929. *****************************************************************************/
  4930. static void il4965_bg_txpower_work(struct work_struct *work)
  4931. {
  4932. struct il_priv *il = container_of(work, struct il_priv,
  4933. txpower_work);
  4934. mutex_lock(&il->mutex);
  4935. /* If a scan happened to start before we got here
  4936. * then just return; the stats notification will
  4937. * kick off another scheduled work to compensate for
  4938. * any temperature delta we missed here. */
  4939. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  4940. test_bit(STATUS_SCANNING, &il->status))
  4941. goto out;
  4942. /* Regardless of if we are associated, we must reconfigure the
  4943. * TX power since frames can be sent on non-radar channels while
  4944. * not associated */
  4945. il->cfg->ops->lib->send_tx_power(il);
  4946. /* Update last_temperature to keep is_calib_needed from running
  4947. * when it isn't needed... */
  4948. il->last_temperature = il->temperature;
  4949. out:
  4950. mutex_unlock(&il->mutex);
  4951. }
  4952. static void il4965_setup_deferred_work(struct il_priv *il)
  4953. {
  4954. il->workqueue = create_singlethread_workqueue(DRV_NAME);
  4955. init_waitqueue_head(&il->wait_command_queue);
  4956. INIT_WORK(&il->restart, il4965_bg_restart);
  4957. INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish);
  4958. INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work);
  4959. INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start);
  4960. INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start);
  4961. il_setup_scan_deferred_work(il);
  4962. INIT_WORK(&il->txpower_work, il4965_bg_txpower_work);
  4963. init_timer(&il->stats_periodic);
  4964. il->stats_periodic.data = (unsigned long)il;
  4965. il->stats_periodic.function = il4965_bg_stats_periodic;
  4966. init_timer(&il->watchdog);
  4967. il->watchdog.data = (unsigned long)il;
  4968. il->watchdog.function = il_bg_watchdog;
  4969. tasklet_init(&il->irq_tasklet, (void (*)(unsigned long))
  4970. il4965_irq_tasklet, (unsigned long)il);
  4971. }
  4972. static void il4965_cancel_deferred_work(struct il_priv *il)
  4973. {
  4974. cancel_work_sync(&il->txpower_work);
  4975. cancel_delayed_work_sync(&il->init_alive_start);
  4976. cancel_delayed_work(&il->alive_start);
  4977. cancel_work_sync(&il->run_time_calib_work);
  4978. il_cancel_scan_deferred_work(il);
  4979. del_timer_sync(&il->stats_periodic);
  4980. }
  4981. static void il4965_init_hw_rates(struct il_priv *il,
  4982. struct ieee80211_rate *rates)
  4983. {
  4984. int i;
  4985. for (i = 0; i < RATE_COUNT_LEGACY; i++) {
  4986. rates[i].bitrate = il_rates[i].ieee * 5;
  4987. rates[i].hw_value = i; /* Rate scaling will work on idxes */
  4988. rates[i].hw_value_short = i;
  4989. rates[i].flags = 0;
  4990. if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) {
  4991. /*
  4992. * If CCK != 1M then set short preamble rate flag.
  4993. */
  4994. rates[i].flags |=
  4995. (il_rates[i].plcp == RATE_1M_PLCP) ?
  4996. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  4997. }
  4998. }
  4999. }
  5000. /*
  5001. * Acquire il->lock before calling this function !
  5002. */
  5003. void il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx)
  5004. {
  5005. il_wr(il, HBUS_TARG_WRPTR,
  5006. (idx & 0xff) | (txq_id << 8));
  5007. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx);
  5008. }
  5009. void il4965_tx_queue_set_status(struct il_priv *il,
  5010. struct il_tx_queue *txq,
  5011. int tx_fifo_id, int scd_retry)
  5012. {
  5013. int txq_id = txq->q.id;
  5014. /* Find out whether to activate Tx queue */
  5015. int active = test_bit(txq_id, &il->txq_ctx_active_msk) ? 1 : 0;
  5016. /* Set up and activate */
  5017. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  5018. (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  5019. (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  5020. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  5021. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  5022. IL49_SCD_QUEUE_STTS_REG_MSK);
  5023. txq->sched_retry = scd_retry;
  5024. D_INFO("%s %s Queue %d on AC %d\n",
  5025. active ? "Activate" : "Deactivate",
  5026. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  5027. }
  5028. static int il4965_init_drv(struct il_priv *il)
  5029. {
  5030. int ret;
  5031. spin_lock_init(&il->sta_lock);
  5032. spin_lock_init(&il->hcmd_lock);
  5033. INIT_LIST_HEAD(&il->free_frames);
  5034. mutex_init(&il->mutex);
  5035. il->ieee_channels = NULL;
  5036. il->ieee_rates = NULL;
  5037. il->band = IEEE80211_BAND_2GHZ;
  5038. il->iw_mode = NL80211_IFTYPE_STATION;
  5039. il->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  5040. il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
  5041. /* initialize force reset */
  5042. il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD;
  5043. /* Choose which receivers/antennas to use */
  5044. if (il->cfg->ops->hcmd->set_rxon_chain)
  5045. il->cfg->ops->hcmd->set_rxon_chain(il,
  5046. &il->ctx);
  5047. il_init_scan_params(il);
  5048. ret = il_init_channel_map(il);
  5049. if (ret) {
  5050. IL_ERR("initializing regulatory failed: %d\n", ret);
  5051. goto err;
  5052. }
  5053. ret = il_init_geos(il);
  5054. if (ret) {
  5055. IL_ERR("initializing geos failed: %d\n", ret);
  5056. goto err_free_channel_map;
  5057. }
  5058. il4965_init_hw_rates(il, il->ieee_rates);
  5059. return 0;
  5060. err_free_channel_map:
  5061. il_free_channel_map(il);
  5062. err:
  5063. return ret;
  5064. }
  5065. static void il4965_uninit_drv(struct il_priv *il)
  5066. {
  5067. il4965_calib_free_results(il);
  5068. il_free_geos(il);
  5069. il_free_channel_map(il);
  5070. kfree(il->scan_cmd);
  5071. }
  5072. static void il4965_hw_detect(struct il_priv *il)
  5073. {
  5074. il->hw_rev = _il_rd(il, CSR_HW_REV);
  5075. il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG);
  5076. il->rev_id = il->pci_dev->revision;
  5077. D_INFO("HW Revision ID = 0x%X\n", il->rev_id);
  5078. }
  5079. static int il4965_set_hw_params(struct il_priv *il)
  5080. {
  5081. il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  5082. il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  5083. if (il->cfg->mod_params->amsdu_size_8K)
  5084. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_8K);
  5085. else
  5086. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_4K);
  5087. il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL;
  5088. if (il->cfg->mod_params->disable_11n)
  5089. il->cfg->sku &= ~IL_SKU_N;
  5090. /* Device-specific setup */
  5091. return il->cfg->ops->lib->set_hw_params(il);
  5092. }
  5093. static const u8 il4965_bss_ac_to_fifo[] = {
  5094. IL_TX_FIFO_VO,
  5095. IL_TX_FIFO_VI,
  5096. IL_TX_FIFO_BE,
  5097. IL_TX_FIFO_BK,
  5098. };
  5099. static const u8 il4965_bss_ac_to_queue[] = {
  5100. 0, 1, 2, 3,
  5101. };
  5102. static int
  5103. il4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5104. {
  5105. int err = 0;
  5106. struct il_priv *il;
  5107. struct ieee80211_hw *hw;
  5108. struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data);
  5109. unsigned long flags;
  5110. u16 pci_cmd;
  5111. /************************
  5112. * 1. Allocating HW data
  5113. ************************/
  5114. hw = il_alloc_all(cfg);
  5115. if (!hw) {
  5116. err = -ENOMEM;
  5117. goto out;
  5118. }
  5119. il = hw->priv;
  5120. /* At this point both hw and il are allocated. */
  5121. il->ctx.ctxid = 0;
  5122. il->ctx.always_active = true;
  5123. il->ctx.is_active = true;
  5124. il->ctx.rxon_cmd = REPLY_RXON;
  5125. il->ctx.rxon_timing_cmd = REPLY_RXON_TIMING;
  5126. il->ctx.rxon_assoc_cmd = REPLY_RXON_ASSOC;
  5127. il->ctx.qos_cmd = REPLY_QOS_PARAM;
  5128. il->ctx.ap_sta_id = IL_AP_ID;
  5129. il->ctx.wep_key_cmd = REPLY_WEPKEY;
  5130. il->ctx.ac_to_fifo = il4965_bss_ac_to_fifo;
  5131. il->ctx.ac_to_queue = il4965_bss_ac_to_queue;
  5132. il->ctx.exclusive_interface_modes =
  5133. BIT(NL80211_IFTYPE_ADHOC);
  5134. il->ctx.interface_modes =
  5135. BIT(NL80211_IFTYPE_STATION);
  5136. il->ctx.ap_devtype = RXON_DEV_TYPE_AP;
  5137. il->ctx.ibss_devtype = RXON_DEV_TYPE_IBSS;
  5138. il->ctx.station_devtype = RXON_DEV_TYPE_ESS;
  5139. il->ctx.unused_devtype = RXON_DEV_TYPE_ESS;
  5140. SET_IEEE80211_DEV(hw, &pdev->dev);
  5141. D_INFO("*** LOAD DRIVER ***\n");
  5142. il->cfg = cfg;
  5143. il->pci_dev = pdev;
  5144. il->inta_mask = CSR_INI_SET_MASK;
  5145. if (il_alloc_traffic_mem(il))
  5146. IL_ERR("Not enough memory to generate traffic log\n");
  5147. /**************************
  5148. * 2. Initializing PCI bus
  5149. **************************/
  5150. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  5151. PCIE_LINK_STATE_CLKPM);
  5152. if (pci_enable_device(pdev)) {
  5153. err = -ENODEV;
  5154. goto out_ieee80211_free_hw;
  5155. }
  5156. pci_set_master(pdev);
  5157. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  5158. if (!err)
  5159. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  5160. if (err) {
  5161. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  5162. if (!err)
  5163. err = pci_set_consistent_dma_mask(pdev,
  5164. DMA_BIT_MASK(32));
  5165. /* both attempts failed: */
  5166. if (err) {
  5167. IL_WARN("No suitable DMA available.\n");
  5168. goto out_pci_disable_device;
  5169. }
  5170. }
  5171. err = pci_request_regions(pdev, DRV_NAME);
  5172. if (err)
  5173. goto out_pci_disable_device;
  5174. pci_set_drvdata(pdev, il);
  5175. /***********************
  5176. * 3. Read REV register
  5177. ***********************/
  5178. il->hw_base = pci_iomap(pdev, 0, 0);
  5179. if (!il->hw_base) {
  5180. err = -ENODEV;
  5181. goto out_pci_release_regions;
  5182. }
  5183. D_INFO("pci_resource_len = 0x%08llx\n",
  5184. (unsigned long long) pci_resource_len(pdev, 0));
  5185. D_INFO("pci_resource_base = %p\n", il->hw_base);
  5186. /* these spin locks will be used in apm_ops.init and EEPROM access
  5187. * we should init now
  5188. */
  5189. spin_lock_init(&il->reg_lock);
  5190. spin_lock_init(&il->lock);
  5191. /*
  5192. * stop and reset the on-board processor just in case it is in a
  5193. * strange state ... like being left stranded by a primary kernel
  5194. * and this is now the kdump kernel trying to start up
  5195. */
  5196. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  5197. il4965_hw_detect(il);
  5198. IL_INFO("Detected %s, REV=0x%X\n",
  5199. il->cfg->name, il->hw_rev);
  5200. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5201. * PCI Tx retries from interfering with C3 CPU state */
  5202. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  5203. il4965_prepare_card_hw(il);
  5204. if (!il->hw_ready) {
  5205. IL_WARN("Failed, HW not ready\n");
  5206. goto out_iounmap;
  5207. }
  5208. /*****************
  5209. * 4. Read EEPROM
  5210. *****************/
  5211. /* Read the EEPROM */
  5212. err = il_eeprom_init(il);
  5213. if (err) {
  5214. IL_ERR("Unable to init EEPROM\n");
  5215. goto out_iounmap;
  5216. }
  5217. err = il4965_eeprom_check_version(il);
  5218. if (err)
  5219. goto out_free_eeprom;
  5220. if (err)
  5221. goto out_free_eeprom;
  5222. /* extract MAC Address */
  5223. il4965_eeprom_get_mac(il, il->addresses[0].addr);
  5224. D_INFO("MAC address: %pM\n", il->addresses[0].addr);
  5225. il->hw->wiphy->addresses = il->addresses;
  5226. il->hw->wiphy->n_addresses = 1;
  5227. /************************
  5228. * 5. Setup HW constants
  5229. ************************/
  5230. if (il4965_set_hw_params(il)) {
  5231. IL_ERR("failed to set hw parameters\n");
  5232. goto out_free_eeprom;
  5233. }
  5234. /*******************
  5235. * 6. Setup il
  5236. *******************/
  5237. err = il4965_init_drv(il);
  5238. if (err)
  5239. goto out_free_eeprom;
  5240. /* At this point both hw and il are initialized. */
  5241. /********************
  5242. * 7. Setup services
  5243. ********************/
  5244. spin_lock_irqsave(&il->lock, flags);
  5245. il_disable_interrupts(il);
  5246. spin_unlock_irqrestore(&il->lock, flags);
  5247. pci_enable_msi(il->pci_dev);
  5248. err = request_irq(il->pci_dev->irq, il_isr,
  5249. IRQF_SHARED, DRV_NAME, il);
  5250. if (err) {
  5251. IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq);
  5252. goto out_disable_msi;
  5253. }
  5254. il4965_setup_deferred_work(il);
  5255. il4965_setup_rx_handlers(il);
  5256. /*********************************************
  5257. * 8. Enable interrupts and read RFKILL state
  5258. *********************************************/
  5259. /* enable rfkill interrupt: hw bug w/a */
  5260. pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd);
  5261. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  5262. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  5263. pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd);
  5264. }
  5265. il_enable_rfkill_int(il);
  5266. /* If platform's RF_KILL switch is NOT set to KILL */
  5267. if (_il_rd(il, CSR_GP_CNTRL) &
  5268. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  5269. clear_bit(STATUS_RF_KILL_HW, &il->status);
  5270. else
  5271. set_bit(STATUS_RF_KILL_HW, &il->status);
  5272. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  5273. test_bit(STATUS_RF_KILL_HW, &il->status));
  5274. il_power_initialize(il);
  5275. init_completion(&il->_4965.firmware_loading_complete);
  5276. err = il4965_request_firmware(il, true);
  5277. if (err)
  5278. goto out_destroy_workqueue;
  5279. return 0;
  5280. out_destroy_workqueue:
  5281. destroy_workqueue(il->workqueue);
  5282. il->workqueue = NULL;
  5283. free_irq(il->pci_dev->irq, il);
  5284. out_disable_msi:
  5285. pci_disable_msi(il->pci_dev);
  5286. il4965_uninit_drv(il);
  5287. out_free_eeprom:
  5288. il_eeprom_free(il);
  5289. out_iounmap:
  5290. pci_iounmap(pdev, il->hw_base);
  5291. out_pci_release_regions:
  5292. pci_set_drvdata(pdev, NULL);
  5293. pci_release_regions(pdev);
  5294. out_pci_disable_device:
  5295. pci_disable_device(pdev);
  5296. out_ieee80211_free_hw:
  5297. il_free_traffic_mem(il);
  5298. ieee80211_free_hw(il->hw);
  5299. out:
  5300. return err;
  5301. }
  5302. static void __devexit il4965_pci_remove(struct pci_dev *pdev)
  5303. {
  5304. struct il_priv *il = pci_get_drvdata(pdev);
  5305. unsigned long flags;
  5306. if (!il)
  5307. return;
  5308. wait_for_completion(&il->_4965.firmware_loading_complete);
  5309. D_INFO("*** UNLOAD DRIVER ***\n");
  5310. il_dbgfs_unregister(il);
  5311. sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group);
  5312. /* ieee80211_unregister_hw call wil cause il_mac_stop to
  5313. * to be called and il4965_down since we are removing the device
  5314. * we need to set STATUS_EXIT_PENDING bit.
  5315. */
  5316. set_bit(STATUS_EXIT_PENDING, &il->status);
  5317. il_leds_exit(il);
  5318. if (il->mac80211_registered) {
  5319. ieee80211_unregister_hw(il->hw);
  5320. il->mac80211_registered = 0;
  5321. } else {
  5322. il4965_down(il);
  5323. }
  5324. /*
  5325. * Make sure device is reset to low power before unloading driver.
  5326. * This may be redundant with il4965_down(), but there are paths to
  5327. * run il4965_down() without calling apm_ops.stop(), and there are
  5328. * paths to avoid running il4965_down() at all before leaving driver.
  5329. * This (inexpensive) call *makes sure* device is reset.
  5330. */
  5331. il_apm_stop(il);
  5332. /* make sure we flush any pending irq or
  5333. * tasklet for the driver
  5334. */
  5335. spin_lock_irqsave(&il->lock, flags);
  5336. il_disable_interrupts(il);
  5337. spin_unlock_irqrestore(&il->lock, flags);
  5338. il4965_synchronize_irq(il);
  5339. il4965_dealloc_ucode_pci(il);
  5340. if (il->rxq.bd)
  5341. il4965_rx_queue_free(il, &il->rxq);
  5342. il4965_hw_txq_ctx_free(il);
  5343. il_eeprom_free(il);
  5344. /*netif_stop_queue(dev); */
  5345. flush_workqueue(il->workqueue);
  5346. /* ieee80211_unregister_hw calls il_mac_stop, which flushes
  5347. * il->workqueue... so we can't take down the workqueue
  5348. * until now... */
  5349. destroy_workqueue(il->workqueue);
  5350. il->workqueue = NULL;
  5351. il_free_traffic_mem(il);
  5352. free_irq(il->pci_dev->irq, il);
  5353. pci_disable_msi(il->pci_dev);
  5354. pci_iounmap(pdev, il->hw_base);
  5355. pci_release_regions(pdev);
  5356. pci_disable_device(pdev);
  5357. pci_set_drvdata(pdev, NULL);
  5358. il4965_uninit_drv(il);
  5359. dev_kfree_skb(il->beacon_skb);
  5360. ieee80211_free_hw(il->hw);
  5361. }
  5362. /*
  5363. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  5364. * must be called under il->lock and mac access
  5365. */
  5366. void il4965_txq_set_sched(struct il_priv *il, u32 mask)
  5367. {
  5368. il_wr_prph(il, IL49_SCD_TXFACT, mask);
  5369. }
  5370. /*****************************************************************************
  5371. *
  5372. * driver and module entry point
  5373. *
  5374. *****************************************************************************/
  5375. /* Hardware specific file defines the PCI IDs table for that hardware module */
  5376. static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = {
  5377. {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)},
  5378. {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)},
  5379. {0}
  5380. };
  5381. MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids);
  5382. static struct pci_driver il4965_driver = {
  5383. .name = DRV_NAME,
  5384. .id_table = il4965_hw_card_ids,
  5385. .probe = il4965_pci_probe,
  5386. .remove = __devexit_p(il4965_pci_remove),
  5387. .driver.pm = IL_LEGACY_PM_OPS,
  5388. };
  5389. static int __init il4965_init(void)
  5390. {
  5391. int ret;
  5392. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  5393. pr_info(DRV_COPYRIGHT "\n");
  5394. ret = il4965_rate_control_register();
  5395. if (ret) {
  5396. pr_err("Unable to register rate control algorithm: %d\n", ret);
  5397. return ret;
  5398. }
  5399. ret = pci_register_driver(&il4965_driver);
  5400. if (ret) {
  5401. pr_err("Unable to initialize PCI module\n");
  5402. goto error_register;
  5403. }
  5404. return ret;
  5405. error_register:
  5406. il4965_rate_control_unregister();
  5407. return ret;
  5408. }
  5409. static void __exit il4965_exit(void)
  5410. {
  5411. pci_unregister_driver(&il4965_driver);
  5412. il4965_rate_control_unregister();
  5413. }
  5414. module_exit(il4965_exit);
  5415. module_init(il4965_init);
  5416. #ifdef CONFIG_IWLEGACY_DEBUG
  5417. module_param_named(debug, il_debug_level, uint, S_IRUGO | S_IWUSR);
  5418. MODULE_PARM_DESC(debug, "debug output mask");
  5419. #endif
  5420. module_param_named(swcrypto, il4965_mod_params.sw_crypto, int, S_IRUGO);
  5421. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  5422. module_param_named(queues_num, il4965_mod_params.num_of_queues, int, S_IRUGO);
  5423. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  5424. module_param_named(11n_disable, il4965_mod_params.disable_11n, int, S_IRUGO);
  5425. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  5426. module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K,
  5427. int, S_IRUGO);
  5428. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  5429. module_param_named(fw_restart, il4965_mod_params.restart_fw, int, S_IRUGO);
  5430. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");